Skip to content

Speed up Markdown document discovery with bundled ripgrep - #23306

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ripgrep-opportunities
Sep 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ripgrep-opportunities

Conversation

@nwparker

@nwparker nwparker commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299 $\color{#cf222e}{\Huge{\mathbf{−}}}$​79 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​220
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​141 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115

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:

Dataset Original Bundled ripgrep
Orca checkout, same 280 documents 85.1 ms 31.2 ms
Tiny folder, 10 documents 0.06 ms 5.0 ms

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

  • Manually benchmarked the production discovery function on this macOS checkout.
  • Automated tests added/updated: 46 focused tests passed across Markdown discovery, IPC/runtime routing, bundled spawn, and the bare-ripgrep boundary.
  • Real bundled-binary fixtures cover hidden paths, ignore files, rg configuration, extension case, symlinks, empty/missing roots, Unicode, spaces, and newline filenames.
  • Lifecycle tests cover split Unicode/NUL records, incomplete paths, traversal errors after partial output, spawn and pipe failures, timeout cleanup, and WSL missing-cwd handling.
  • pnpm tc:node passed.
  • pnpm run check:code-quality:changed passed.
  • Windows/WSL and SSH routing are covered by automated contracts; no real Windows, WSL, or SSH host run was performed. Full suite and packaging remain for CI.

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

  • Not applicable; no upstream agent-skill implementation copied.

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

  • This PR is small and focused.
  • Explained the behavior, mechanism, and tradeoff.
  • Visual proof is N/A with reason.
  • Self-reviewed for correctness, security, and performance.
  • Cross-platform, SSH/remote, folder-workspace, and path handling considered.
  • Focused tests, Node typecheck, and changed-code quality pass; CI covers broader checks.

@pullfrog pullfrog 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.

ℹ️ No critical issues — minor suggestions inline.

Reviewed changes

  • Bundled-ripgrep Markdown discovery — listMarkdownDocuments now spawns Orca's bundled rg (--files --hidden --no-ignore --no-config --null --path-separator / with directory globs **, !**/.*/, **/.github/, !**/node_modules/) and parses NUL-delimited stdout, replacing the serial readdir walk. Errors/timeouts reject instead of returning partial results.
  • WSL routing at both local call sites — fs:listMarkdownDocuments and runtime listRuntimeMarkdownDocuments now pass the registered worktree's local git options (distro) into discovery; SSH keeps the existing provider.listFiles path.
  • Test rework — filesystem-markdown-document-listing.test.ts becomes 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

resolveListing(documents.sort((a, b) => a.relativePath.localeCompare(b.relativePath)))
}
}
const onError = (error: Error): void => finish(error)

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.

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.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 299628dc-84a0-4cd1-ab09-aa99b2d75eb7

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb1ade and 85d97fa.

📒 Files selected for processing (7)
  • src/main/ipc/filesystem-markdown-document-listing.test.ts
  • src/main/ipc/filesystem/filesystem-read-handlers.ts
  • src/main/ipc/markdown-documents-ripgrep-real.test.ts
  • src/main/ipc/markdown-documents-ripgrep.test.ts
  • src/main/ipc/markdown-documents.ts
  • src/main/runtime/runtime-file-commands-search-runtime-files.ts
  • src/main/runtime/runtime-file-target-execution-host.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

listMarkdownDocuments now uses bundled ripgrep instead of recursive directory traversal. It validates, filters, and sorts the returned Markdown paths, and rejects on specified process, stream, path, and timeout errors. Local runtime and filesystem IPC callers now pass options for the registered worktree. Tests cover ripgrep behavior, path handling, WSL options, and local versus remote listing calls.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 85d97

Markdown listing appears mergeable after normal CI checks. No actionable behavior regression was established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 85d97

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The newly spawned listing process is scoped by the resolved local worktree path, rather than an arbitrary root passed directly from the IPC request. SSH targets remain provider-owned.

Trust Boundaries and Controls

  • observed — Local process routing derives its WSL option from the registered worktree's repository settings. The process receives a workspace cwd and fixed listing arguments, and returned paths are checked before document construction.

Resilience and Maintainability Implications

  • observed — The listing rejects process and stream errors, incomplete records, oversized path records, and timeouts rather than exposing the documents collected before failure.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: using bundled ripgrep to improve Markdown document discovery speed.
Description check ✅ Passed The description covers the required sections, explains the user-facing change and implementation, documents the rationale and tradeoffs, identifies testing and platform coverage, and marks non-applica…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@nwparker
nwparker merged commit fb51e6c into main Sep 27, 2026
39 of 41 checks passed
@nwparker
nwparker deleted the nwparker/ripgrep-opportunities branch September 27, 2026 23:16
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.

1 participant