fix(cfg): raise the parse-worker stack limit for deep CFG recursion (#2195)

The CFG visitors build per-function control-flow graphs by recursive descent
over the tree-sitter AST, so deeply-nested source overflows the worker thread's
call stack (~1.5k nesting levels) — caught per-function (R4 try/catch) but the
function silently gets no PDG. A worker thread's stack is governed by
resourceLimits.stackSizeMb (Node default 4 MB); the main process's
--stack-size=4096 flag does NOT propagate to worker threads (confirmed by prior-
art research on Node worker_threads). Raise it to 16 MB, pushing the overflow
threshold to several-thousand nesting levels — far beyond any hand-written code,
so only machine-generated/obfuscated nesting can still hit it (and that stays a
caught per-function skip, never a crash). Complements a future proactive depth
guard. pipeline-pdg worker tests 30 passed, tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gergo Magyar 2026-06-14 22:00:42 +00:00
parent cda4cac27f
commit de4c43a4c8

View file

@ -912,6 +912,16 @@ export const createWorkerPool = (
new Worker(url, {
stderr: true,
workerData: workerStoreData,
// The CFG visitors build per-function control-flow graphs by RECURSIVE
// descent over the tree-sitter AST, so deeply-nested source overflows
// the worker thread's call stack. A worker's stack is governed by
// `resourceLimits.stackSizeMb` (Node default 4 MB) — the main process's
// `--stack-size` flag does NOT propagate to worker threads — so raise it
// here. This pushes the overflow threshold from ~1.5k to several-k
// nesting levels (far beyond any hand-written code); a deeper machine-
// generated nest is still caught per-function (buildFunctionCfg's R4
// try/catch) and only that function's PDG is skipped, never a crash.
resourceLimits: { stackSizeMb: 16 },
}));
/** Spawn + wire stderr capture in one step (used by all spawn sites). */
const spawnAndCapture = (url: URL): Worker => {