Skip to content

workflows: structured-result artifacts lack an aggregate size cap; node limit does not stop traversal #111

Closed

Description

@tt-a1i

Description

Verified by read-only audit (seal/gpt-5.6-sol subagent, verdict: CONFIRMED).

persistWorkflowAgentResult (extensions/workflows/artifacts.ts:105-137) serializes the authoritative structured result with JSON.stringify(toSerializable(...), null, 2) using only maxDepth: 32, maxNodes: 100_000, maxStringBytes: 2 MiB — no aggregate byte cap.

Root cause analysis

  • serialization.ts:47-50 — maxNodes does not stop traversal: each visit() increments a counter, and after 100,000 nodes every subsequent value becomes a "[truncated: node limit]" marker — but containers are still fully iterated.
  • serialization.ts:74-78 — arrays use current.map(...) over the entire array even after the node limit; a flat array of length N produces output/work proportional to N, not min(N, 100k).
  • serialization.ts:97-110 — objects likewise enumerate every key after the limit; key names are uncapped (another unbounded-output path).
  • serialization.ts:119-140 — safeStringify() has an aggregate cap, but artifact persistence does not use it.
  • Upstream does not bound it either: runner.ts:178-205 (isJsonSchema()) limits only the schema definition (10k nodes/depth 24), not result dimensions; runner.ts:708-715 truncates assistant text to 64 KiB but leaves structured uncapped.

Worst case

  • Pre-node-limit content: ~100,000 strings × 2 MiB ≈ 200 GiB (theoretical ~1.1 TiB with JSON escaping expansion).
  • Post-node-limit markers: output is truly unbounded as a function of input array length.
  • Normalization + JSON.stringify also build the full representation in memory before the atomic disk write.

Provider response-token ceilings and voluntary schema maxItems/maxLength reduce practical exploitability but are not an artifact-layer guarantee.

Suggested fix

  • Enforce an aggregate byte/node cutoff during traversal and before JSON.stringify — fail explicitly or emit a clearly marked bounded artifact with recovery metadata.
  • Stop mapping entire collections once the aggregate limit is reached.
  • Consider requiring bounded result dimensions at schema admission, or capping structured early in runner.ts like the 64 KiB assistant-text cap.

Found by automated workflow audit (run wf_56028a5b018b).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions