Skip to content

fix(core): avoid recursive scan when browsing directories in Open Project#31306

Open
ysm-dev wants to merge 1 commit into
anomalyco:devfrom
ysm-dev:fix/open-project-directory-scan
Open

fix(core): avoid recursive scan when browsing directories in Open Project#31306
ysm-dev wants to merge 1 commit into
anomalyco:devfrom
ysm-dev:fix/open-project-directory-scan

Conversation

@ysm-dev
Copy link
Copy Markdown
Contributor

@ysm-dev ysm-dev commented Jun 8, 2026

Issue for this PR

Closes #15334 (exact root cause; was folded into the memory megathread #20695). Related: #22655.

Type of change

  • Bug fix

What does this PR do?

The Open Project picker can browse any location the server can see, including non-project roots like /, /usr, /var, or a deep ~/projects/org/repo. For those, FileSystem.find fell through to a full recursive rg --files scan of the entire tree. That spawns many ripgrep processes, spikes CPU/memory (the linked issue saw 12 rg processes and a 350MB→7.9GB jump while "scanning entire /var" and "/usr"), and leaves the web "Open Project" modal stuck on Loading.

There was already a bounded, shallow (2-level) directory scan, but it only triggered for the exact home directory. This PR uses that same shallow listing for directory-type finds in non-project (global) locations. The picker only needs immediate folder names to let you browse, so nothing is lost. File search (@-mentions) inside real git projects is unchanged — it still uses the full recursive scan.

The change is two lines in packages/core/src/filesystem.ts: scan() gains a shallow flag, and find() sets it when type === "directory" and the location is global.

How did you verify your code works?

  • Added a regression test in packages/core/test/location-search.test.ts: it creates alpha/nested/deep + beta, then asserts a global type: "directory" find returns alpha, alpha/nested, and beta but not the third-level alpha/nested/deep (proving it stays shallow rather than recursing).
  • bun test test/location-search.test.ts from packages/core → 12 pass.
  • bun typecheck from packages/core → clean.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Note: this code was written with GPT-5.5.

…ject

The Open Project picker browses arbitrary, non-project locations (/, /usr, deep paths). For those, find() fell through to a full recursive rg --files scan, spawning many ripgrep processes and spiking CPU/memory while the web modal hung on Loading. The bounded shallow scan only triggered for the exact home directory. Use that shallow listing for directory-type finds in global locations; @-mention file search in real projects is unchanged.
@ysm-dev ysm-dev marked this pull request as ready for review June 8, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPU 100% and memory spike (350MB→7.9GB) when typing deep paths in Open Project dialog

1 participant