Skip to content

Bound search preview memory and stop canceled SSH scans - #25303

Merged
nwparker merged 1 commit into
mainfrom
nwparker/search-stream-followup
Oct 4, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/search-stream-followup

Conversation

@nwparker

@nwparker nwparker commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​396 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​395
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41 $\color{#cf222e}{\Huge{\mathbf{−}}}$​37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

ELI5

Long search results can keep far more memory alive than their tiny previews suggest, and canceling Quick Open over SSH can still start another scan. This bounds retained preview text and stops abandoned listing work.

What Changed

  • Copy clipped search previews with the existing string ownership function so a 500-character preview cannot retain a megabyte source line. Keep emoji intact at both edges and intersect highlights with the retained text, preserving original navigation coordinates.
  • Refuse new listing passes after settlement; stop failure diagnosis after cancellation, pass cancellation to running version probes, and handle diagnosis rejection. Remove the stderr pipe whose output was discarded.
  • Remove the session reader's separate byte scan for an object root; use the already-completed assembler result. Consolidate the duplicate preview-length constant.

Why

Reuse the existing string and cancellation mechanisms instead of introducing a cache, dependency patch, or another parser. Legacy remote fallbacks and session readers still have active callers and remain necessary.

Measurements on macOS arm64, Node 24.20.0, against this branch's main base; serial counterbalanced timings and fresh-process memory checks:

Case Before After
Retained heap: 32 previews from separate 1 MiB lines 32.02 MiB 0.047 MiB
2,000 short ASCII results 2.6 ms 2.6 ms
2,000 long ASCII results 8.7 ms 8.9 ms
2,000 long Unicode results 8.9 ms 9.7 ms
Dense 100,000-match record, retaining 2,000 results 68.7 ms 68.4 ms
Session with 20,000 messages 52.7 ms 52.5 ms

Copying trades bounded allocation for predictable retention: 2,000 matches sharing one short line retain about 2.16 MiB instead of 0.38 MiB. The small dense ingestion case takes 0.7 → 1.4 ms, and its fresh-process peak RSS rises about 6.7 MiB. Long ASCII result peak RSS rises about 4 MiB despite lower retained heap. This is a memory-lifetime fix, not a general speed claim.

Linked Issue

Follow-up to #25156 and #25202.

Visual Proof

N/A — this changes shared result preparation and subprocess lifecycle, without renderer changes. Real bundled-binary tests verify intact Unicode preview text, highlight ranges, and unchanged navigation coordinates; no rendered-app validation was performed.

Testing

  • Automated tests added/updated.
  • Manually tested rendered application behavior.

341 tests passed, 2 platform-specific tests skipped across 32 focused suites, covering real bundled search output, dense results, forced-GC retention, session contracts, remote lifecycle, Windows path handling, and listing cancellation. The new cancellation regressions were shown to fail before the fixes.

pnpm tc, pnpm run check:code-quality:changed, and pnpm run build:relay passed. Relay bundles built for all six targets; native Windows process-tree binaries are absent locally, so packaging/native Windows execution remains a CI check. Local tests and measurements ran on macOS; no live Windows, WSL, or SSH host validation is claimed.

Review

Adversarial sub-agent review before implementation and again on the fixes covered byte offsets, Unicode clipping, stream assembly, cancellation races, and memory ownership. Review found the Git fallback highlight intersection and diagnostic cancellation gaps; both now have regressions.

Agent skill upstream boundary

  • Not applicable; no skill sharing changes.

Notes

No dependency changes or patches. No wire format changes. Shared preview handling applies to native and remote searches, including folder workspaces. Cancellation stays on the execution host.

Checklist

  • This PR is small and focused
  • Explained behavior, mechanism, and approach
  • Visual validation scope stated
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • Focused tests, typechecks, changed-code lint, and relay build pass; full suite and packaging are for CI

@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59e87594-1848-424a-95b9-d6c8a3a88ec6
📥 Commits

Reviewing files that changed from the base of the PR and between b99d28e and ce13929.

📒 Files selected for processing (11)
  • src/main/ai-vault/session-document-stream-contract.test.ts
  • src/main/ai-vault/session-document-stream.ts
  • src/main/ripgrep/text-search-unicode-real.test.ts
  • src/relay/fs-handler-list-files-cancel.test.ts
  • src/relay/fs-handler-list-files-diagnosis-cancel.test.ts
  • src/relay/fs-handler-list-files.ts
  • src/shared/text-search-dense-matches.test.ts
  • src/shared/text-search-match-accumulator.ts
  • src/shared/text-search-snippet-boundaries.test.ts
  • src/shared/text-search-snippet-retention.test.ts
  • src/shared/text-search.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@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 new issues found.

Reviewed changes

  • Bounded search preview retention — clampLineContext now shifts the window off a split surrogate, clips via the reused sliceAtCodeUnitLimit, derives displayStart/displayMatchLength from the real window, and routes the retained snippet through the existing ownRetainedString so a ~500-char preview can no longer pin a megabyte source line.
  • Single preview-length constant — MAX_LINE_CONTENT_LENGTH relocated to text-search-match-accumulator.ts and re-exported from text-search.ts.
  • Relay listing cancellation — runPassOnce refuses to start the broader pass after settlement, the launch-failure diagnosis continuation checks passDone || done, the abort signal is forwarded into classifyRigrepLaunchFailure (so a running rg --version probe is killed and pending cwd checks bail), an unexpected diagnosis rejection is caught, and the always-discarded stderr pipe is dropped.
  • Session reader consolidation — the redundant first-byte object-root scan is replaced by assembler.current === record.

The new tests are genuine regression guards: the retention fixture retains ~32 MiB without ownership, the between-passes test spawns a second rg without the guard, the diagnosis tests hang or probe without the signal/guard, and the unicode tests assert exact columns and display slices against real bundled rg.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit f371532 into main Oct 4, 2026
59 checks passed
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