Skip to content

Commit b47c956

Browse files
colbymchenryclaude
andauthored
fix(cli): hard-exit on Node 25.x instead of soft warning + crash (#149)
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>
1 parent 55daeff commit b47c956

3 files changed

Lines changed: 93 additions & 11 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Pin the Node-25 block banner content. The banner replaced a soft
3+
* `console.warn` because the warning was scrolling off-screen before
4+
* the OOM crash 30 seconds later, generating duplicate bug reports
5+
* (#54, #81, #140). The recipe and override env var below are
6+
* load-bearing — if any of them get edited away, this test catches it.
7+
*/
8+
9+
import { describe, it, expect } from 'vitest';
10+
import { buildNode25BlockBanner } from '../src/bin/node-version-check';
11+
12+
describe('buildNode25BlockBanner', () => {
13+
it('embeds the reported Node version in the header', () => {
14+
expect(buildNode25BlockBanner('25.9.0')).toContain(
15+
'Unsupported Node.js version: 25.9.0'
16+
);
17+
});
18+
19+
it('names the V8 turboshaft WASM root cause and the OOM symptom', () => {
20+
const banner = buildNode25BlockBanner('25.7.0');
21+
expect(banner).toContain('V8 WASM JIT');
22+
expect(banner).toContain('turboshaft');
23+
expect(banner).toContain('Fatal process out of memory: Zone');
24+
});
25+
26+
it('points users to Node 22 LTS via nvm and Homebrew', () => {
27+
const banner = buildNode25BlockBanner('25.7.0');
28+
expect(banner).toContain('Node.js 22 LTS');
29+
expect(banner).toContain('nvm install 22');
30+
expect(banner).toContain('brew install node@22');
31+
});
32+
33+
it('documents the CODEGRAPH_ALLOW_UNSAFE_NODE override', () => {
34+
const banner = buildNode25BlockBanner('25.7.0');
35+
expect(banner).toContain('CODEGRAPH_ALLOW_UNSAFE_NODE=1');
36+
});
37+
38+
it('links to issue #81 for the root-cause writeup', () => {
39+
expect(buildNode25BlockBanner('25.7.0')).toContain(
40+
'github.com/colbymchenry/codegraph/issues/81'
41+
);
42+
});
43+
});

src/bin/codegraph.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import * as fs from 'fs';
2424
import { getCodeGraphDir, isInitialized } from '../directory';
2525
import { createShimmerProgress } from '../ui/shimmer-progress';
2626

27+
import { buildNode25BlockBanner } from './node-version-check';
28+
2729
// Lazy-load heavy modules (CodeGraph, runInstaller) to keep CLI startup fast.
2830
async function loadCodeGraph(): Promise<typeof import('../index')> {
2931
try {
@@ -44,20 +46,21 @@ async function loadCodeGraph(): Promise<typeof import('../index')> {
4446
const importESM = new Function('specifier', 'return import(specifier)') as
4547
(specifier: string) => Promise<typeof import('@clack/prompts')>;
4648

47-
// Warn about unsupported Node.js versions (Node 25+ has V8 turboshaft WASM bugs)
49+
// Block CodeGraph on Node.js 25.x — V8's turboshaft WASM JIT has a Zone
50+
// allocator bug that reliably crashes when compiling tree-sitter
51+
// grammars (see #54, #81, #140). The previous behaviour was a soft
52+
// console.warn that scrolls off-screen before the OOM crash 30 seconds
53+
// later, leading to a steady stream of "what is this OOM" reports.
54+
// Hard-exit before any WASM work; allow override via env var for users
55+
// who patched V8 themselves or want to test a future fix.
4856
const nodeVersion = process.versions.node;
4957
const nodeMajor = parseInt(nodeVersion.split('.')[0] ?? '0', 10);
5058
if (nodeMajor >= 25) {
51-
console.warn(
52-
'\x1b[33m⚠\x1b[0m CodeGraph may crash on Node.js %s due to a V8 WASM compiler bug in Node 25+.',
53-
nodeVersion
54-
);
55-
console.warn(
56-
' Please use Node.js 22 LTS instead: https://nodejs.org/en/download'
57-
);
58-
console.warn(
59-
' See: https://github.com/colbymchenry/codegraph/issues/81\n'
60-
);
59+
process.stderr.write(buildNode25BlockBanner(nodeVersion) + '\n');
60+
if (!process.env.CODEGRAPH_ALLOW_UNSAFE_NODE) {
61+
process.exit(1);
62+
}
63+
// Override active — banner shown for visibility, continuing.
6164
}
6265

6366
// Check if running with no arguments - run installer

src/bin/node-version-check.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Node.js version compatibility check.
3+
*
4+
* Node 25.x has a V8 turboshaft WASM JIT Zone allocator bug that
5+
* reliably crashes CodeGraph with `Fatal process out of memory: Zone`
6+
* during tree-sitter grammar compilation. This module owns the
7+
* user-facing banner shown before exit. Kept side-effect-free so it's
8+
* safe to import from tests without triggering CLI bootstrap.
9+
*/
10+
11+
/**
12+
* Build the bordered banner shown when CodeGraph detects an
13+
* unsupported Node.js major version (currently 25+). Pinned via unit
14+
* test so the recovery commands and override instructions can't be
15+
* silently stripped by future edits.
16+
*/
17+
export function buildNode25BlockBanner(nodeVersion: string): string {
18+
const sep = '─'.repeat(72);
19+
return [
20+
sep,
21+
`[CodeGraph] Unsupported Node.js version: ${nodeVersion}`,
22+
sep,
23+
'Node.js 25.x has a V8 WASM JIT (turboshaft) Zone allocator bug that',
24+
'crashes with `Fatal process out of memory: Zone` when CodeGraph',
25+
'compiles tree-sitter grammars. CodeGraph WILL crash on this Node',
26+
'version mid-indexing. See https://github.com/colbymchenry/codegraph/issues/81',
27+
'',
28+
'Fix: install Node.js 22 LTS:',
29+
' nvm install 22 && nvm use 22 # nvm',
30+
' brew install node@22 && brew link --overwrite --force node@22 # Homebrew',
31+
'',
32+
'To override (NOT recommended — you will likely OOM):',
33+
' CODEGRAPH_ALLOW_UNSAFE_NODE=1 codegraph ...',
34+
sep,
35+
].join('\n');
36+
}

0 commit comments

Comments
 (0)