[Bugfix #680] Prevent V8 heap exhaustion in gemini consult#681
Merged
waleedkadous merged 1 commit intomainfrom Apr 18, 2026
Merged
Conversation
…rge PRs gemini-cli v0.37.x crashes on PR diffs >500KB due to V8 old-space exhaustion in the spawned subprocess. Two complementary mitigations: 1. Set NODE_OPTIONS=--max-old-space-size=8192 on the spawned env. This survives gemini-cli's internal relaunch and gives it enough heap to finish directory walks and buffer large responses. 2. Pipe the prompt via stdin instead of argv. Avoids ARG_MAX limits and prevents V8 from holding the prompt buffer twice (once in argv, once in the readStdin/prompt path). Adds 4 regression tests covering NODE_OPTIONS, stdio pipe mode, argv cleanliness, and preservation of a caller-supplied NODE_OPTIONS.
Contributor
Author
|
Excellent fix — thank you for the tight, well-scoped diagnosis and the two-pronged mitigation. Architect integration review: APPROVE (HIGH confidence, no critical issues). A couple of non-blocking notes for your awareness (no action needed):
Please merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #680
consult -m geminiwas crashing on PR diffs >500KB due to V8 old-spaceexhaustion in the spawned
gemini-clisubprocess. Truncated stdout causedJSON.parseto fail, and CMAP silently degraded to 2-way exactly when 3-waysignal mattered most (shannon PRs #642, #650, #568, #629).
Root Cause
gemini-cliv0.37.x runs out of its default V8 old-space (~1.7 GB) duringnon-interactive mode:
loadServerHierarchicalMemory/ JIT context walk (graceful-fs wrappingfs.readdir) produces theArrayUnshift+AfterScanDirframesadvanced.autoConfigureMemoryexists upstream but defaults OFFOnly gemini was affected because only gemini is shelled out and only gemini
parses JSON from a buffered child stdout. Codex and Claude run in-process.
Fix
packages/codev/src/commands/consult/index.ts— two complementary mitigations:--max-old-space-size=8192). Survivesgemini-cli's internal relaunch. Preserves any caller-supplied NODE_OPTIONS.
from holding the prompt buffer twice. EPIPE from an early child exit is
handled gracefully so we surface the underlying error, not the pipe close.
No changes to codex or claude paths (unaffected).
Test Plan
Gemini large-prompt crash mitigation (Bugfix #680))--max-old-space-size=8192stdio[0]is'pipe'(not'ignore')unrelated to this change (skeleton fallback — fail on
mainas well)consult -m gemini --prompt "What is 1+1?"returns
2in ~4s with the new stdin pathDiff Size
Net diff: 172 LOC (under 300).
CMAP Review
All three verdicts: APPROVE / CONFIDENCE: HIGH / KEY_ISSUES: None
Full review transcripts:
/tmp/bugfix-680-cmap-{gemini,codex,claude}.md