Repository navigation
perf(workflow): reduce doStreamStep step-boundary payload - #16434
Merged
Merged
Conversation
doStreamStep built the full StepResult inside the step and also returned a per-chunk snapshot array, serializing both into the durable event log on every step. The iterator never read the chunk array, and StepResult carries redundant copies (content, duplicate tool-call lists, reasoningText, the always-empty *ToolResults arrays). The step now returns only the minimal raw aggregates needed to rebuild the StepResult (text, reasoning, responseMetadata, warnings) alongside the existing finish/toolCalls; the iterator reconstructs the full StepResult via buildStepResult outside the boundary. The user-facing StepResult shape is unchanged. runtimeContext/toolsContext/stepNumber no longer cross the boundary — the iterator applies them during reconstruction. Ported from vercel/workflow#1932. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gr2m
approved these changes
Jul 6, 2026
gr2m
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed: the payload reduction is a faithful field-for-field move of the StepResult construction out of the step boundary, the dropped chunks array was dead payload, and doStreamStep is internal-only. Replay compat across the shape change is acceptable while the package is experimental.
Contributor
|
🚀 Published in:
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port of vercel/workflow#1932 to
@ai-sdk/workflow.doStreamStepbuilt the fullStepResultinside the step and also returned a per-chunk snapshot array. Both were serialized into the durable event log on every step. But:StepResultcarries redundant copies of data:content(=text+ tool calls), the duplicatetoolCalls/dynamicToolCallslists,reasoningText(= joinedreasoning), and the always-empty*ToolResultsarrays.Change
The step now returns only the minimal raw aggregates needed to rebuild the
StepResult—text,reasoning,responseMetadata,warnings— alongside the existingfinishandtoolCalls. The iterator reconstructs the fullStepResultvia a newbuildStepResulthelper outside the step boundary.StepResult(yielded steps,onStepEnd, telemetry) is byte-for-byte the same shape; only the durable event-log payload shrinks.runtimeContext/toolsContext/stepNumberno longer cross the boundary either — the iterator already holds them and applies them during reconstruction.Tests
stream-text-iterator.test.tsmocks updated to the new{ toolCalls, finish, raw, providerExecutedToolResults }shape; the contexts test now asserts the contexts are applied to the reconstructed step and yield value (rather than passed across the boundary).workflow-agenttests exercise the realdoStreamStep→buildStepResultpath and pass unchanged, confirming the reconstruction is faithful.pnpm --filter @ai-sdk/workflow build && testpass (node + edge).Related
@workflow/aicopy)Opened as a draft — this is an AI-assisted port. The two copies of this package have diverged (vercel/ai's
doStreamStepisstreamModelCall-based and built theStepResultinline, with no separatechunksToStep), so this applies the same optimization rather than cherry-picking the diff; please review the adaptation before merge.🤖 Generated with Claude Code