Repository navigation
fix(ingest): stop spreading a child subtree into push in walkFilesystem - #315
Conversation
`out.push(...walkFilesystem(full, includes))` turns the child's array into push()'s argument list, and V8 caps that at roughly 128k. A single unignored subtree with more paths than that throws "Maximum call stack size exceeded" at trivial directory depth — the message is about the argument list, not recursion. Only the git-less path reaches this: when listGitFiles returns null the walker collects every non-dot file first and filters by language later, so any large cache, browser profile or dataset directory in a repo that was never `git init`-ed is fatal. Appending in a loop removes the cap without changing what is collected or in what order. Two tests, deliberately split: - a cheap one that pins the accumulation itself (a wide, deep subtree outside Git comes back flat and complete). It runs everywhere and would catch a botched loop, but it cannot reach the argument cap. - one that actually reproduces the crash with 150k files. It fails with "Maximum call stack size exceeded" on the previous code and passes with this one. CI also runs windows-latest, where creating that many files is far slower, so it is skipped there. Measured while writing this: on Node 22 a spread of 125k elements still succeeds and 150k throws, and `--stack-size` does not move the boundary — it is an argument-count limit, not stack depth.
🌱 graft blast radius1 area changed → 2 areas can be affected. 4 dependent symbols, depth 2. flowchart TB
A0(("Dependency Graph<br/>3 symbols"))
A1(("Context Discovery<br/>1 symbol"))
classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
class A0,A1 reached;
Who knows this code — 4 people across 3 areas
Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no All 4 dependent symbols, grouped by areaDependency Graph — 3 symbols in 3 files
Context Discovery — 1 symbol in 1 file
Test signal per changed area — 1 ✗Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.
Open the interactive graph → — click an area to see its dependent symbols at file:line. |
|
Can you merge this, please? We need the patch for our large non-git codebase, too 😅 |
* fix(init): keep machine-wide wiring when init omits a host init converges a repository by retracting every host not named in --agents, and that sweep also ran at machine-wide scope. So `graft init B --agents cursor` removed the user-level Claude hooks, shim and MCP entry and the Codex hooks that every other repository on the machine depends on. The init-time retract is now repository-only; `uninstall` still removes the machine-wide files. Ported from nishadherath/fork_Graft a241f6fb308d (MIT). Upstream issue trailhq/Trail-Code#482. Co-authored-by: Nishad Herath <[email protected]> * fix(cli-meta): start npm through the shell on Windows On Windows npm is the npm.cmd shim, which spawnSync cannot start without a shell, so `graft version` always read "unreachable", the update check stored nothing and `graft upgrade` failed with ENOENT. All npm calls now go through one helper that passes a joined command line to the shell on Windows (avoiding Node 24's DEP0190 warning) and spawns npm directly elsewhere. The tests put a fake npm first on PATH. Ported from ansidium/trail-code-se7en 4fa301e664a8 (MIT). Upstream issue trailhq/Trail-Code#487. Co-authored-by: ansidium <[email protected]> * fix: keep a --dir on another drive out of the repo's ignore files On Windows a --dir on another drive has no relative path, so relative() returns the absolute target. That passed the startsWith("..") outside-repo check and appended /C:/... to the repository's .gitignore and .ignore. Both writers now share repoRelativeDir, which rejects anything not strictly inside the root. Ported from nishadherath/fork_Graft 50122fbd500f (MIT). Upstream issue trailhq/Trail-Code#384. Co-authored-by: Nishad Herath <[email protected]> * fix(graph): re-parse a cached entry that holds a parse error A grammar abort is a process-global, run-dependent failure, but the extraction cache stores it as a per-file entry keyed on content hash and replays it on every later build. An untouched file then stays broken forever, and a whole language can drop out of a graph that still exits 0 with a success line. Let an entry carrying an error fall through to the parse path instead of being replayed. The entry is still persisted, so the freshness probe does not report the file as new on every query; it just never stands in for a result again. Re-parsing costs only files that produced no nodes, and a run that succeeds repairs the entry. Upstream issue trailhq/Trail-Code#312, PR trailhq/Trail-Code#317 (MIT). Cherry-picked from Ercaner1988/Graft 14c0bcd7d223d1cc92bcca3c5995adc236e497e8. * fix(ingest): stop spreading a child subtree into push in walkFilesystem `out.push(...walkFilesystem(full, includes))` turns the child's array into push()'s argument list, and V8 caps that at roughly 128k. A single unignored subtree with more paths than that throws "Maximum call stack size exceeded" at trivial directory depth — the message is about the argument list, not recursion. Only the git-less path reaches this: when listGitFiles returns null the walker collects every non-dot file first and filters by language later, so any large cache, browser profile or dataset directory in a repo that was never `git init`-ed is fatal. Appending in a loop removes the cap without changing what is collected or in what order. Two tests, deliberately split: - a cheap one that pins the accumulation itself (a wide, deep subtree outside Git comes back flat and complete). It runs everywhere and would catch a botched loop, but it cannot reach the argument cap. - one that actually reproduces the crash with 150k files. It fails with "Maximum call stack size exceeded" on the previous code and passes with this one. CI also runs windows-latest, where creating that many files is far slower, so it is skipped there. Measured while writing this: on Node 22 a spread of 125k elements still succeeds and 150k throws, and `--stack-size` does not move the boundary — it is an argument-count limit, not stack depth. Upstream issue trailhq/Trail-Code#314, PR trailhq/Trail-Code#315 (MIT). Cherry-picked from Ercaner1988/Graft 88a0442969adacc9353e36a85159c40fdd44a6e7. * test(ingest): run the argument-cap walker test on Windows The 150,000-file regression test for the walkFilesystem stack overflow was POSIX-only because creating the files is slow on Windows. It takes about 35 seconds there, fails with "Maximum call stack size exceeded" without the fix, and covers the platform graft is used on daily. * test(generic): expect a cached grammar failure to be re-parsed The re-parse fix for cached parse errors changes one assertion in the throwing-grammar test: an unchanged file whose last parse failed is now parsed again instead of replayed. The test's point still holds: the failure is cached as a failure, not an empty success, and the rebuild reports it again. * style(cli-meta): spawn npm with the repo's platform shell idiom Use one spawnSync call with `shell: win`, as signup.ts, cli.ts and shim-template.ts already do, and mark the PATH lookup of npm as intended for SonarCloud. Behaviour is unchanged: a joined command line through the shell on Windows, a direct spawn elsewhere. * style(cli-meta): mark the Windows npm shell spawn as reviewed for Semgrep The shell is required to start npm.cmd on Windows and every argument is a fixed token, so suppress the spawn-shell-true finding inline with that reason. --------- Co-authored-by: Ryan Duguid <[email protected]> Co-authored-by: Nishad Herath <[email protected]> Co-authored-by: ansidium <[email protected]> Co-authored-by: datrixlab <[email protected]> (cherry picked from commit 87663089946176a111f15b6c7f0e2b67b47af3bb)
What
walkFilesystemappends a child subtree withwhich makes the child array the argument list of
push(). V8 caps that at roughly 128k, so a single unignored subtree with more paths than that throwsRangeError: Maximum call stack size exceededat trivial directory depth — the message is about the argument list, not recursion depth.Appending in a loop removes the cap. Nothing else changes: same paths, same order.
Fixes #314
Why it only bites some repos
Only the git-less path reaches this. When
listGitFilesreturnsnullthe walker collects every non-dot file first and filters by language later, so any large cache, browser profile or dataset directory in a repo that was nevergit init-ed is fatal — while the same tree under Git is fine becausegit ls-filesrespects.gitignore. That is what makes it look nondeterministic across a fleet, as the reporter described.Tests
Two, deliberately split, because one of them cannot do the other's job:
walkDir collects a large nested subtree outside Git without dropping paths— a wide, deep subtree outside Git comes back flat and complete. Runs on every platform, ~40ms. It pins the accumulation and would catch a botched loop, but it cannot reach the argument cap, so it passes on the old code too. I am flagging that rather than presenting it as proof.walkDir survives a subtree larger than V8's argument limit (#314)— the real reproduction, 150k files. On the previous code it fails with exactlyMaximum call stack size exceeded; with this change it passes.Verified both directions: reverting only
src/ingest/fs.tsand re-running gives# pass 18 / # fail 1, and the one failure is test 2 with that message. With the fix,# pass 19 / # fail 0in 6.9s.The heavy test is skipped on Windows. CI runs
windows-latesttoo, and creating 150k files there is far slower than the ~2.5s it takes on Linux. If you would rather not pay even the Linux cost in CI, say so and I will drop test 2 and keep test 1 — the fix stands on its own either way.Measurements taken while writing this
--stack-sizedoes not move that boundary. I tried 500/200/100 with 2k–10k elements: all fine. It is an argument-count limit, not stack depth — worth knowing if anyone later tries to make the test cheaper by shrinking the stack.push(...)sites insrc/graph/build.ts(nodes,rawEdges) accumulate per file rather than per subtree, so they do not reach the cap. Left untouched to keep this focused.