Skip to content

fix(search): cap child-process stdout to prevent main-process OOM#225

Merged
khang859 merged 1 commit into
mainfrom
fleet-glad-mast-pine
Jun 9, 2026
Merged

fix(search): cap child-process stdout to prevent main-process OOM#225
khang859 merged 1 commit into
mainfrom
fleet-glad-mast-pine

Conversation

@khang859

@khang859 khang859 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes a main-process crash (V8 heap OOM, presented as a 120s "hang" in macOS stackshot reports) caused by file-search.ts, file-grep.ts, and recent-images.ts buffering unbounded mdfind/rg/grep stdout into one string and splitting it on newlines — on big Spotlight indexes this reaches hundreds of MB and the split's cons-string flatten exhausts the heap
  • Adds captureBoundedStdout() (src/main/bounded-stdout.ts): accumulates child stdout and SIGTERMs the process once 8M chars are buffered, keeping the truncated prefix; applied to all five spawn sites (incl. fallbacks)
  • Caps recent-images recursive readdir collection at 1000 paths; adds a learnings doc covering the root cause and how to re-symbolicate stripped Electron stackshots with breakpad symbols

Test plan

  • npm run typecheck passes
  • npx eslint clean on all touched files
  • Full vitest run: 977 passed, 0 failed (includes 3 new tests for truncation/kill behavior in src/main/__tests__/bounded-stdout.test.ts)
  • Manual: open the file-search overlay and type short queries in a large home directory; memory stays bounded and results still appear

🤖 Generated with Claude Code

file-search, file-grep, and recent-images buffered unbounded
mdfind/rg/grep stdout into a single string and split it on newlines.
On machines with huge Spotlight indexes this accumulated hundreds of
MB, and the split's cons-string flatten exhausted the V8 heap,
crashing the main process (presented as a 120s hang in macOS
stackshot reports).

Add captureBoundedStdout(), which SIGTERMs the child once 8M chars
are buffered and keeps the truncated prefix, and apply it to all five
spawn sites. Also cap recent-images' recursive readdir path collection
at 1000 entries. Root-cause analysis is documented in
docs/learnings/main-process-oom-unbounded-search-stdout.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@khang859 khang859 merged commit 7d7279c into main Jun 9, 2026
1 check passed
@khang859 khang859 deleted the fleet-glad-mast-pine branch June 9, 2026 19:34
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