Relationships
#4488 Deeply nested resource content overflows the stack: nested workflow run summaries are silently erased, and history outputs --json leaves truncated JSON
Opened by zack · 11/6/2026· Shipped 11/6/2026
Summary
Two walkers added for swamp-club#4469 (commits 7e04652a5 and 9f5082868 on the issue-4469 branch) recurse once per nesting level of the JSON they walk. On deeply nested resource content they overflow the stack ("Maximum call stack size exceeded"), far below the depth swamp can store (about 5,000 levels) and below what JSON.stringify on main handles. main handles every case below.
1. A nested workflow step with deep content silently erases the run summary
RunAttributeBudget.resolveChild measures each child step's merged outputs with jsonByteLengthWithin (src/domain/models/resource_attribute_budget.ts, walk recursing at line 87). On deep content it throws RangeError.
swamp workflow run <parent> --json/workflow resume --json: the error reaches the catch-all inresolveCompletedRunOutputs, which returnsundefined, so every step of the run comes back with noattributesand nooutputs, and noattributesOmitted/outputsPartialmarkers. Exit code 0, stderr empty. The data involved is tiny (about 10 KB).swamp workflow history get <parent> --json: crashes withMaximum call stack size exceeded, stack inwalk.
Threshold measured: fine at 2,500 levels, fails at 3,500.
2. workflow history outputs --json overflows and leaves truncated JSON on stdout
prettyJsonChunks (src/presentation/output/json_stream.ts, the yield* recursion at line 48) overflows on deep content. The command exits 1 after writing a partial document to stdout (25 MB of invalid JSON for a 5,000-level value; main prints the full 50 MB). Threshold: fails somewhere between 1,000 and 2,500 levels.
Steps to reproduce
- A behavior whose method writes one resource nested N levels deep, e.g.
{ i: 0, tree: [[[ ... [0,1,2,...] ... ]]] }(N single-element arrays wrapping a short array of numbers). - Workflow
wfdeep: onemodel_methodstep running that method with N = 3500. - Workflow
wfp_deep: stepc1oftype: workflowrunningwfdeep, then atailstep that writes two small resources. swamp workflow run wfp_deep --json→ exit 0;c1has nooutputs,tail's artifacts have noattributes, and there are no omission markers. On main:c1.outputspresent andtailattributes inlined.swamp workflow history get wfp_deep --json→ exit 1,Maximum call stack size exceeded(main: succeeds).swamp workflow history outputs wfdeep --json(N = 2500 is enough) → exit 1, truncated JSON on stdout (main: succeeds).
Expected
Same as main: deep content resolves and prints, or at worst the affected child step is refused with outputsPartial: true and its records marked attributesOmitted, never a silent loss of the whole summary.
Suggested direction
- Make both walkers iterative (explicit stack) or depth-independent.
- In
resolveChild, treat anyRangeErrorfrom measuring as a refusal of that child step (mark it), rather than letting it reach the catch-all. - In
writeJsonValue, tryJSON.stringify(value, null, 2)first and stream only when it throwsRangeError. That keeps normal output byte-identical and keeps deep values on V8's native path. Related:writeJsonValuealso turns a broken pipe (... --json | head -c 100) into exit 1 plus a JSON error and stack on stderr, where main exits 0 quietly.
Environment
Linux, swamp built from the issue-4469 branch at 9f5082868, compared against origin/main 6392439c4.
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.