From de4c43a4c89ea18a77b7e09baf7c5a62de2e1e89 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Sun, 14 Jun 2026 22:00:42 +0000 Subject: [PATCH] fix(cfg): raise the parse-worker stack limit for deep CFG recursion (#2195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- gitnexus/src/core/ingestion/workers/worker-pool.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gitnexus/src/core/ingestion/workers/worker-pool.ts b/gitnexus/src/core/ingestion/workers/worker-pool.ts index c46cf5a33..acdc0339d 100644 --- a/gitnexus/src/core/ingestion/workers/worker-pool.ts +++ b/gitnexus/src/core/ingestion/workers/worker-pool.ts @@ -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 => {