Skip to content

Show nested sub-project files in file-explorer name search#6481

Merged
nwparker merged 3 commits into
mainfrom
brennanb2025/issue-5939-monorepo-file-search
Jun 29, 2026
Merged

Show nested sub-project files in file-explorer name search#6481
nwparker merged 3 commits into
mainfrom
brennanb2025/issue-5939-monorepo-file-search

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #5939

What changes

File-explorer name search now lists and matches files that live inside nested git sub-projects when the workspace root is a monorepo parent. Previously, typing any query at a monorepo-parent root returned no results for files inside the sub-projects.

What does not change: the normal (no-query) file tree, the ripgrep code path, and text/content search are untouched. This only fixes the file listing that feeds name search when the ripgrep-less git fallback is in use.

Root cause

Name search lists files via git ls-files when ripgrep is unavailable (Orca bundles no ripgrep, so this is the common path on a fresh macOS install). git ls-files does not recurse into nested git repositories: a committed gitlink surfaces as a single bare entry, an untracked embedded repo surfaces as a single directory entry, and a non-git root yields nothing. So files inside nested sub-projects were never enumerated and name search could not match them. The normal tree was unaffected because it lists directories with readdir. Opening the workspace directly on a sub-project worked because that sub-project is itself a git repo.

Approach

After the flat git ls-files pass, detect nested-repo entries and fill their subtrees with a bounded readdir walk, re-prefixed root-relative:

  • Nested-repo detection reads git's -s mode output, so a gitlink is identified by mode 160000 and an untracked embedded repo by its trailing slash. Ordinary files are classified from the same output and incur no extra lstat.
  • The readdir walk shares one file-count + deadline budget across all nested subtrees, prunes node_modules/blocklisted dirs, does not follow symlinks, and rejects on cap/deadline so a partial scan never reads as an empty result.
  • Non-git roots now use a whole-root walk instead of returning empty, and the git fallback rejects on failure/timeout instead of silently resolving empty.
  • Extracted into a shared module consumed by both the local main process and the SSH relay so the two cannot drift.

Relationship to the open folder-workspace PR

This is a different layer than the open PR #6170 (renderer-only: makes the file-list request fire for folder workspaces and recomputes SSH connectionId). That PR makes the listing request happen; this PR fixes what the backend listing returns. For a monorepo parent added as a git repo, the request already fires today, yet nested files are dropped — confirmed live before this fix. The two are complementary, not overlapping.

Design review

Design was reviewed through Brennan's PR process. The review redirected the original per-repo git ls-files recursion to reuse the relay's existing bounded readdir walk, fixed an aggregate-budget bug (per-call caps would not bound N subtrees), and required reject-on-failure semantics and main/relay parity.

Implementation and deviations

Implemented as designed. One refinement during the performance pass: the first cut lstat-ed every git entry to detect nested repos (an O(N) stat storm on large repos); switched detection to git's -s mode output, which a committed gitlink (160000) vs. an ordinary file can be told apart textually with zero stats for regular files. A committed gitlink has no trailing slash, so a slash-only gate would have missed it — the mode check is required.

Completeness verification

Read-only verification confirmed all design requirements and edge cases are implemented: detection variants (committed gitlink, untracked embedded, extensionless tracked file, un-checked-out gitlink), shared-budget bounding, final-path exclude/blocklist filtering, reject-vs-empty semantics, non-git-root walk on both paths, and SSH relay parity.

Headline behavior status

Implemented in production code (not scaffolding). Verified in the running app: at a monorepo-parent workspace, searching main shows packages/app/src/main.ts (a committed-gitlink sub-project) and searching lib shows packages/lib/src/lib.ts + package.json (an untracked embedded sub-project). The backend listing went from 5 entries (nested files dropped) to 7 (nested files present).

Performance

Audited before code review. Touched hot path: the ripgrep-less name-search file listing (fires once per search session, not per keystroke; never at startup). The only real concern — an lstat per git entry — was eliminated by reading -s mode output (zero stats for ordinary files; a deterministic test asserts no lstat for a regular-file list). The shared budget bounds aggregate work across all subtrees; no leaks, no busy loops, one cheap added git rev-parse per listing to gate the non-git-root walk.

Code review

Iterative two-reviewer loop ran to clean (2 rounds). Round 1 fixed a max-lines overflow (split the git fallback into a focused module rather than disabling the rule), two lint findings, and brought the relay's budget-error message into parity with the existing install-ripgrep guidance. Round 2: both reviewers clean.

Merge-confidence validation

Verdict: land. Function-level proof against a real git monorepo parent confirmed local and relay listFilesWithGit return identical results including nested files for both gitlink and untracked-embedded sub-projects; non-git root returns a whole-root walk. SSH reasoning: the relay change adds more entries to the same string[] with no transport/serialization change. Cross-platform: git ls-files emits forward slashes; the -s mode regex handles SHA-1 and SHA-256; Windows separators are normalized.

Accepted gaps: no live SSH-transport pass (transport layer unchanged; the changed logic is covered by the real-git function test and the full relay suite). Follow-up note: the local path could also wrap readdir budget-cap errors in the install-ripgrep guidance the relay now uses — narrow edge, falls back gracefully today.

Checks run

  • pnpm exec vitest run on the shared, main-IPC, and relay file-listing suites — green (shared/main scoped 59; relay 564; main IPC filesystem 207).
  • pnpm run typecheck:node — clean.
  • pnpm exec oxlint on all touched files — clean.
  • Live Electron validation with uncropped screenshots of name search resolving nested sub-project files (attached below).

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds shared Quick Open helpers for parsing git ls-files -s output, bounded readdir traversal, and nested-repo expansion. It updates Git argument construction to include stage mode, moves the main IPC Git fallback into a separate helper, and wires relay file listing to the shared expansion logic. Tests were added and updated across main, relay, and shared modules for nested repos, non-git roots, timeout and budget handling, and staged Git output.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed but misses required template sections like Screenshots, Testing checkboxes, Security Audit, and Notes. Restructure the PR description to match the template and add the missing sections, including screenshots/no visual change, testing checklist, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main user-visible change: nested sub-project files appear in file-explorer name search.
Linked Issues check ✅ Passed The PR addresses #5939 by making monorepo-parent name search include nested sub-project files and folders instead of returning empty results.
Out of Scope Changes check ✅ Passed The touched code and tests all support the nested-subproject file-listing fix; no unrelated feature changes stand out.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/shared/quick-open-readdir-walk.ts (1)

221-226: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Prune excluded prefixes in the nested readdir walk

The recursive walk still traverses excluded subtrees and only filters them at addFinalPath, so a large excluded nested repo can still burn the shared budget and fail with File listing exceeded or timed out. Pass translated nested-relative excludePathPrefixes into the recursive call so those subtrees are skipped during traversal.

src/main/ipc/filesystem-list-files-git-fallback.ts (1)

52-197: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Near-complete duplication of listFilesWithGit orchestration with the relay implementation.

runGitLsFiles, killSurvivors, and the Promise.all → expandQuickOpenGitFilesWithNestedRepos chain here mirror src/relay/fs-handler-git-fallback.ts almost line-for-line; the only real difference is gitSpawn(+wslDistro) vs spawn(+buildRelayCommandEnv) and the close-handling. Since the PR intent is to keep the two consistent, consider extracting the shared orchestration into a helper that takes a spawn factory, so the two copies cannot drift (see the related divergence noted in the relay file).


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 625f654b-4afa-4ffc-8e0d-c46370b70fc6

📥 Commits

Reviewing files that changed from the base of the PR and between 78519d8 and 73cc3cb.

📒 Files selected for processing (12)
  • src/main/ipc/filesystem-list-files-git-fallback-real.test.ts
  • src/main/ipc/filesystem-list-files-git-fallback.ts
  • src/main/ipc/filesystem-list-files.test.ts
  • src/main/ipc/filesystem-list-files.ts
  • src/relay/fs-handler-git-fallback.ts
  • src/relay/fs-handler-list-files-ignored.test.ts
  • src/relay/fs-handler-readdir-fallback.ts
  • src/relay/fs-handler.ts
  • src/shared/quick-open-filter.test.ts
  • src/shared/quick-open-filter.ts
  • src/shared/quick-open-readdir-walk.test.ts
  • src/shared/quick-open-readdir-walk.ts

Comment thread src/relay/fs-handler-git-fallback.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed:

  • Prune excluded prefixes in the nested readdir walk — fixed in 32f33a4. The nested walk now receives exclude prefixes rebased onto each nested repo, so excluded subtrees are pruned during traversal instead of being walked and filtered at the end (no longer burns the shared budget). Added a regression test where a large excluded nested subtree with a tiny budget still resolves to the kept file.
  • Reject non-zero git ls-files exits (relay) — fixed in d2124a5 (replied inline), with a regression test.

Not changing:

  • Main/relay listFilesWithGit duplication — the two orchestrations genuinely differ in process mechanics (gitSpawn + wslDistro vs spawn + relay env, and close handling) and predate this change; the new nested-repo fill logic is already shared via quick-open-readdir-walk.ts. Extracting a cross-process spawn-factory abstraction for the surrounding orchestration is a larger refactor beyond this fix's scope.

@nwparker nwparker force-pushed the brennanb2025/issue-5939-monorepo-file-search branch from d2124a5 to c391e1f Compare June 29, 2026 06:31
brennanb2025 and others added 3 commits June 28, 2026 23:44
When a workspace root is a monorepo parent containing nested git
sub-projects, the file-explorer name search returned no matches for
files inside those sub-projects. When ripgrep is unavailable, the
git ls-files fallback does not recurse into nested git repositories,
so their files were never listed.

After the flat git ls-files pass, detect nested-repo entries (gitlink
mode 160000, or untracked embedded repos with a trailing slash) and
fill their subtrees with a bounded readdir walk, re-prefixed
root-relative. Non-git roots now use a whole-root walk, and the
fallback rejects on failure/timeout instead of silently returning an
empty list. Applied to both the local main process and the SSH relay
via a shared module.

Detection reads git's -s mode output so ordinary files incur no extra
lstat. The readdir walk shares one file/deadline budget across all
nested subtrees.

Co-authored-by: Orca <help@stably.ai>
Rebase workspace-root-relative exclude prefixes onto each nested repo
before walking it, so excluded subtrees are skipped during traversal
instead of being walked and filtered afterward. A large excluded
nested subtree no longer burns the shared file/deadline budget.

Co-authored-by: Orca <help@stably.ai>
The relay git fallback resolved on a clean close even when git exited
non-zero, so it could expand a partial result set instead of surfacing
the failure. Reject on non-zero exit to match the main-process
fallback.

Co-authored-by: Orca <help@stably.ai>
@nwparker nwparker force-pushed the brennanb2025/issue-5939-monorepo-file-search branch from c391e1f to 65b7743 Compare June 29, 2026 06:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4cf9252e-fe5a-41bb-9d3a-1c48343e8107

📥 Commits

Reviewing files that changed from the base of the PR and between c391e1f and 65b7743.

📒 Files selected for processing (12)
  • src/main/ipc/filesystem-list-files-git-fallback-real.test.ts
  • src/main/ipc/filesystem-list-files-git-fallback.ts
  • src/main/ipc/filesystem-list-files.test.ts
  • src/main/ipc/filesystem-list-files.ts
  • src/relay/fs-handler-git-fallback.ts
  • src/relay/fs-handler-list-files-ignored.test.ts
  • src/relay/fs-handler-readdir-fallback.ts
  • src/relay/fs-handler.ts
  • src/shared/quick-open-filter.test.ts
  • src/shared/quick-open-filter.ts
  • src/shared/quick-open-readdir-walk.test.ts
  • src/shared/quick-open-readdir-walk.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/relay/fs-handler.ts
  • src/shared/quick-open-filter.test.ts
  • src/relay/fs-handler-readdir-fallback.ts
  • src/shared/quick-open-filter.ts
  • src/shared/quick-open-readdir-walk.test.ts
  • src/main/ipc/filesystem-list-files.ts
  • src/relay/fs-handler-git-fallback.ts
  • src/main/ipc/filesystem-list-files.test.ts
  • src/relay/fs-handler-list-files-ignored.test.ts

Comment on lines +238 to +244
const nestedFiles = await listQuickOpenFilesWithReaddir(joinRootRel(opts.rootPath, relPath), {
// Why: exclude prefixes are workspace-root-relative; rebase them onto the
// nested repo so the walk prunes excluded subtrees during traversal
// instead of burning the shared budget and filtering them at the end.
excludePathPrefixes: rebaseExcludePrefixesForNestedRepo(excludePathPrefixes, relPath),
budget
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Skip nested repos when the exclude covers their root.

rebaseExcludePrefixesForNestedRepo only prunes descendants like packages/app/src; excludes at or above the nested repo root, such as packages/app or packages, are dropped and the nested repo is still walked until final filtering. That can exhaust the shared budget on an excluded worktree.

Proposed fix
     if (kind === 'drop-placeholder') {
       continue
     }
 
+    // Why: rebasing only handles excludes inside the nested repo; an exclude
+    // can also cover the nested repo root itself.
+    if (shouldExcludeQuickOpenRelPath(relPath, excludePathPrefixes)) {
+      continue
+    }
+
     const nestedFiles = await listQuickOpenFilesWithReaddir(joinRootRel(opts.rootPath, relPath), {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const nestedFiles = await listQuickOpenFilesWithReaddir(joinRootRel(opts.rootPath, relPath), {
// Why: exclude prefixes are workspace-root-relative; rebase them onto the
// nested repo so the walk prunes excluded subtrees during traversal
// instead of burning the shared budget and filtering them at the end.
excludePathPrefixes: rebaseExcludePrefixesForNestedRepo(excludePathPrefixes, relPath),
budget
})
if (kind === 'drop-placeholder') {
continue
}
// Why: rebasing only handles excludes inside the nested repo; an exclude
// can also cover the nested repo root itself.
if (shouldExcludeQuickOpenRelPath(relPath, excludePathPrefixes)) {
continue
}
const nestedFiles = await listQuickOpenFilesWithReaddir(joinRootRel(opts.rootPath, relPath), {
// Why: exclude prefixes are workspace-root-relative; rebase them onto the
// nested repo so the walk prunes excluded subtrees during traversal
// instead of burning the shared budget and filtering them at the end.
excludePathPrefixes: rebaseExcludePrefixesForNestedRepo(excludePathPrefixes, relPath),
budget
})

@nwparker nwparker merged commit f8e8d5d into main Jun 29, 2026
1 check passed
@nwparker nwparker deleted the brennanb2025/issue-5939-monorepo-file-search branch June 29, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: File explorer name search returns no results when workspace root is a monorepo parent project

2 participants