Skip to content

fix(cli): hard-exit on Node 25.x instead of soft warning + cryptic crash#149

Merged
colbymchenry merged 1 commit into
mainfrom
fix/node25-hard-exit
May 8, 2026
Merged

fix(cli): hard-exit on Node 25.x instead of soft warning + cryptic crash#149
colbymchenry merged 1 commit into
mainfrom
fix/node25-hard-exit

Conversation

@colbymchenry
Copy link
Copy Markdown
Owner

Summary

What changed

Before After
console.warn yellow line, init continues, OOM crash mid-indexing Bordered banner, exit(1) before any WASM work
No way to know what Fatal process out of memory: Zone means Banner names the V8 turboshaft bug, embeds the detected Node version, links to #81
No escape hatch CODEGRAPH_ALLOW_UNSAFE_NODE=1 restores the warn-and-continue behavior

Banner content (verified by 5 unit tests so future edits can't silently strip the recovery commands or override hint):

────────────────────────────────────────────────────────────────────────
[CodeGraph] Unsupported Node.js version: 25.9.0
────────────────────────────────────────────────────────────────────────
Node.js 25.x has a V8 WASM JIT (turboshaft) Zone allocator bug that
crashes with `Fatal process out of memory: Zone` when CodeGraph
compiles tree-sitter grammars. CodeGraph WILL crash on this Node
version mid-indexing. See https://github.com/colbymchenry/codegraph/issues/81

Fix: install Node.js 22 LTS:
  nvm install 22 && nvm use 22                          # nvm
  brew install node@22 && brew link --overwrite --force node@22  # Homebrew

To override (NOT recommended — you will likely OOM):
  CODEGRAPH_ALLOW_UNSAFE_NODE=1 codegraph ...
────────────────────────────────────────────────────────────────────────

The banner builder lives in a new src/bin/node-version-check.ts so it's importable from tests without dragging in CLI bootstrap side-effects.

Test plan

  • npm test — 514/514 passing (was 509; +5 new tests pin the banner content)
  • Hard-exit verified: temporarily flipped the threshold to 22 in dist/, ran node dist/bin/codegraph.js status on Node 22.20.0 → banner printed, exit code 1, no further work happened
  • Override verified: same setup with CODEGRAPH_ALLOW_UNSAFE_NODE=1 → banner printed, CLI continued and ran the status command normally
  • No-op on supported Node verified: full test suite ran on Node 22 with the threshold at 25 (default), nothing fires

🤖 Generated with Claude Code

The Node 25.x V8 turboshaft WASM JIT Zone allocator bug
(#81) reliably crashes
CodeGraph mid-indexing with `Fatal process out of memory: Zone` when
tree-sitter grammars get JIT-compiled. We already had:

- `engines: "node": ">=18.0.0 <25.0.0"` in package.json
- Lazy grammar loading (#61)
- A startup `console.warn` when Node 25+ is detected

But the recurring duplicates (#54, #81, #140, plus comments from
multiple unique users) show those defenses aren't enough:

- npm `engines` is a soft warning by default, so `npm install -g`
  doesn't block.
- The startup `console.warn` is a single yellow line that scrolls
  off-screen before the OOM 30 seconds later, so users connect the
  crash to "CodeGraph is broken" rather than "I'm on the wrong Node
  version" and file a fresh issue.

This patch turns the soft warning into a hard exit. On Node 25+ we
print a bordered banner that names the V8 root cause, embeds the
detected version, gives Node 22 LTS install commands (nvm + Homebrew),
and links to #81 — then exit(1) BEFORE any tree-sitter import
triggers WASM JIT. The previous behaviour is preserved behind
`CODEGRAPH_ALLOW_UNSAFE_NODE=1` for anyone who patched V8 themselves
or wants to test a future Node 25 fix.

The banner builder is extracted to `src/bin/node-version-check.ts` so
the test can import it without triggering CLI bootstrap. Five unit
tests pin the version interpolation, root-cause explanation, recovery
commands (nvm + brew), override env var, and #81 link — these are
load-bearing and shouldn't get edited away silently.

Suite: 509 → 514, all passing. Verified both paths manually by
flipping the threshold to 22 in dist and running on Node 22.20.0:
without the env var the CLI prints the banner and exits 1; with
`CODEGRAPH_ALLOW_UNSAFE_NODE=1` it prints the banner and continues.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant