WorkflowAgent: a stream part over 10 MiB (e.g. a code_interpreter result) fails doStreamStep; no hook to trim parts before the writable
Summary
On Vercel World, one ModelCallStreamPart over 10 MiB fails the whole model step of a WorkflowAgent. doStreamStep writes every part it receives to the writable unchanged. When a part is large, the durable stream write is rejected, and there is no hook to shrink or omit the part first.
In our case the large parts are provider-executed tool results: an OpenAI code_interpreter result of 14–18 MB, returned while the model works on a large file in its container.
Observed
The step fails with FatalError. Its cause is a rejected stream write:
PUT https://vercel-workflow.com/api/v2/runs/<run>/stream/<stream> → 400
{"error":"bad-request","message":"… size 17909807 exceeds maximum allowed size of 10485760 bytes"}doStreamStep has maxRetries: 0, so the run surfaces this as a failed model call. The step's own data would have been fine; only the trace write is over the limit.
Where
src/do-stream-step.ts: inside thefor await (const part of modelStream)loop, every part excepttool-approval-requestgoes toawait writer.write(part)as is.tool-resultparts withproviderExecuted: trueare included.src/workflow-agent.ts:experimental_transformis declared on the stream options ("Optional stream transformations"), but as far as we can see it is never applied, so it can't be used to trim parts before they reach the writable.
Both points are the same in 2.0.17 (which we run) and in 2.0.53.
Expected
Any of these would work for us:
- Apply
experimental_transform(or a similar per-part hook) before parts reach thewritable. - Keep an oversized part out of the UI stream, for example by replacing its
outputwith a marker, while the step result keeps the full part for the conversation. - Split parts over the World's chunk limit.
Workaround we use
A pnpm patch of dist/index.js: before writer.write(part), a part whose approximate serialized size is over 4 MiB is replaced. For a tool-result or tool-error, the output (or error) becomes { type: 'omitted', reason: 'too_large_for_trace' }; any other part is skipped. The step's aggregates keep the full part.
Versions
@ai-sdk/workflow2.0.17 (also checked 2.0.53)workflow5.0.0-beta.42, Vercel World- Model: an OpenAI Responses model through the AI Gateway, with the provider-executed
code_interpretertool
Source: vercel/ai