Repository navigation
Speed up Markdown document discovery with bundled ripgrep - #23306
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes
- Bundled-ripgrep Markdown discovery —
listMarkdownDocumentsnow spawns Orca's bundledrg(--files --hidden --no-ignore --no-config --null --path-separator /with directory globs**,!**/.*/,**/.github/,!**/node_modules/) and parses NUL-delimited stdout, replacing the serialreaddirwalk. Errors/timeouts reject instead of returning partial results. - WSL routing at both local call sites —
fs:listMarkdownDocumentsand runtimelistRuntimeMarkdownDocumentsnow pass the registered worktree's local git options (distro) into discovery; SSH keeps the existingprovider.listFilespath. - Test rework —
filesystem-markdown-document-listing.test.tsbecomes a routing/authorization test over a mocked discovery function, with real-binary inclusion/symlink/newline fixtures and a mock lifecycle suite added.
The inclusion semantics look faithful to the removed walker, and the ./-prefix parser is safe for WSL/Windows because the search target stays explicit ..
ℹ️ The new fast path has no document or metadata cap
The documents array grows without a bound: the only limit is a 1 MB per-path cap (16× the shared MARKDOWN_DOCUMENT_LISTING_MAX_PATH_BYTES), and there is no count or metadata cap. The repo already defines MARKDOWN_DOCUMENT_LISTING_MAX_DOCUMENTS (20k), ..._MAX_METADATA_BYTES (8 MB), ..._MAX_VISITED_ENTRIES (100k) and a path cap in src/shared/markdown-document-listing-limits.ts, but nothing in production consumes them — the one implementation that did, discoverMarkdownRelativePaths, has had no non-test caller since before this PR. This is not a regression (the removed walker was equally uncapped), but this new listing is the natural place to wire the existing budget, since a pathological workspace now streams an unbounded MarkdownDocument[] through IPC into the renderer's document index.
Technical details
# Wire the existing Markdown listing budget into the ripgrep path
## Affected sites
- `src/main/ipc/markdown-documents.ts:97` — `MAX_MARKDOWN_PATH_BYTES = 1024 * 1024` is local to this file and larger than `MARKDOWN_DOCUMENT_LISTING_MAX_PATH_BYTES` (64 KB).
- `src/main/ipc/markdown-documents.ts:132` / `:188` — `documents` is pushed to with no count/metadata check.
- `src/shared/markdown-document-listing-limits.ts` — `createMarkdownDocumentListingBudget`, `retainMarkdownDocument`, `MarkdownDocumentListingCapacityError`.
- `src/shared/node-markdown-document-discovery.ts` — the only consumer of those helpers; test-only caller.
## Required outcome
- A workspace with more Markdown files than the shared limit (or more retained metadata than 8 MB) fails with `MarkdownDocumentListingCapacityError` rather than returning an unbounded list.
## Suggested approach
- Track a `createMarkdownDocumentListingBudget()` in the stdout loop and call `retainMarkdownDocument(...)` per accepted path; let the typed error propagate (the renderer's `isMarkdownDocumentListingCapacityError` already recognizes it).
- Either reuse the shared path limit or document why this call site needs a different one.
## Open questions for the human
- Is the shared limits module intended to apply to the local/desktop path, or only to a remote provider that has been removed? If the latter, the module and its test are dead and could be deleted instead.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| resolveListing(documents.sort((a, b) => a.relativePath.localeCompare(b.relativePath))) | ||
| } | ||
| } | ||
| const onError = (error: Error): void => finish(error) |
There was a problem hiding this comment.
This local rg call site skips the repo's established ripgrep failure classification. A spawn error is rejected verbatim, so a damaged/missing bundled binary surfaces a raw spawn …/rg ENOENT and a natively moved/missing workspace reports the binary path rather than a named "Search root is not reachable". listQuickOpenFiles and fs:search classify through classifySynchronousRipgrepSpawnFailure / isRipgrepUnavailableExit and reject with bundledRipgrepUnavailableError(); here the renderer (useMarkdownDocuments) swallows the rejection into an empty list plus a console error.
Technical details
# Use the shared ripgrep failure classification
## Affected sites
- `src/main/ipc/markdown-documents.ts:103` — `spawnBundledRipgrep(...)` is called outside a try/catch, so a synchronous `ENOTDIR`/transient launch failure rejects with the raw errno.
- `src/main/ipc/markdown-documents.ts:169` — `onError` rejects with the raw spawn error; no `RipgrepUnavailableError` mapping.
- `src/main/ipc/markdown-documents.ts:200` — non-0/1 exits (including launcher exit 127 and `isRipgrepUnavailableExit`) become a generic `Markdown document listing failed (code)`.
- Reference call sites: `src/main/ipc/filesystem-list-files.ts:159` and `src/main/ipc/filesystem/filesystem-search-handlers.ts:146`.
## Required outcome
- A spawn failure distinguishes "bundled rg could not start" from "search root unreachable", matching the other two local `rg` call sites.
## Suggested approach
- Wrap the spawn in try/catch and route the caught error through `classifySynchronousRipgrepSpawnFailure(error, rootPath)`.
- In `onError`/`onClose`, reuse `isRipgrepUnavailableExit(child, code, signal, { classifyNativeLauncherExit: true })` → `bundledRipgrepUnavailableError()`, and `isRipgrepSpawnCwdUsable` for the pid-less ENOENT case, as `filesystem-search-handlers.ts` does.|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Markdown listing appears mergeable after normal CI checks. No actionable behavior regression was established. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new listing path remains tied to the selected workspace, while SSH listings stay on their existing provider path. No introduced security concern was established, but the new process and WSL execution paths leave some runtime behavior unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |

ELI5
The Markdown document list refreshes when users open, switch, or save documents. Discovering that list now takes about 31 ms instead of 85 ms on this Orca checkout, while returning the same 280 documents.
What Changed
Replace the serial directory walk with one streamed invocation of Orca's bundled ripgrep. Keep the existing Markdown extensions, sorting, ignored-file visibility, hidden-directory exclusions, and symlink policy. NUL-separated paths preserve filenames containing line breaks, and errors or timeouts reject the listing instead of returning partial results.
Desktop and runtime callers pass the workspace's WSL routing options. SSH requests continue through their existing filesystem provider. The old local directory walker is removed.
Why
The existing bundled binary parallelizes directory traversal without adding another dependency, cache, or watcher. Quick Open's filtering policy differs from Markdown discovery, so its listing cannot be substituted directly. Directory-only pruning plus the existing extension predicate preserves the document set.
Seven measured runs after warmup on macOS arm64, comparing the original walker with the new production function:
This trades a small fixed process-startup cost for faster whole-repository refreshes. These are local warm-filesystem measurements, not Windows/WSL/SSH performance claims.
Linked Issue
N/A — maintainer-initiated performance audit.
Visual Proof
N/A — backend discovery change; rendered document contents and ordering are preserved. Before/after timings are above.
Testing
pnpm tc:nodepassed.pnpm run check:code-quality:changedpassed.Review
An adversarial sub-agent evaluated the proposal and benchmark before implementation. An independent post-implementation review also compared the old walker with real ripgrep across 64 directory combinations and found identical results.
Agent skill upstream boundary
Notes
The listing has a 15-second timeout and a bounded incomplete-path buffer. It streams non-Markdown filenames without retaining them. No RPC shape changes or new dependencies.
Checklist