Skip to main content
← Back to list
01Issue
BugShippedSwamp CLIPublic
Assigneeszack

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 in resolveCompletedRunOutputs, which returns undefined, so every step of the run comes back with no attributes and no outputs, and no attributesOmitted / outputsPartial markers. Exit code 0, stderr empty. The data involved is tiny (about 10 KB).
  • swamp workflow history get <parent> --json: crashes with Maximum call stack size exceeded, stack in walk.

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

  1. 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).
  2. Workflow wfdeep: one model_method step running that method with N = 3500.
  3. Workflow wfp_deep: step c1 of type: workflow running wfdeep, then a tail step that writes two small resources.
  4. swamp workflow run wfp_deep --json → exit 0; c1 has no outputs, tail's artifacts have no attributes, and there are no omission markers. On main: c1.outputs present and tail attributes inlined.
  5. swamp workflow history get wfp_deep --json → exit 1, Maximum call stack size exceeded (main: succeeds).
  6. 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 any RangeError from measuring as a refusal of that child step (mark it), rather than letting it reach the catch-all.
  • In writeJsonValue, try JSON.stringify(value, null, 2) first and stream only when it throws RangeError. That keeps normal output byte-identical and keeps deep values on V8's native path. Related: writeJsonValue also 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.

02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 5 MOREREVIEW+ 6 MOREPR_LINKED+ 2 MORESESSION_SUMMARIZED

Shipped

11/6/2026, 8:49:00 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
zack assigned zack11/6/2026, 8:06:42 PM

Sign in to post a ripple.