fix(ui): rebuild partialToolCalls on resume for input-streaming tool parts#14255
Open
giulio-leone wants to merge 1 commit intovercel:mainfrom
Open
fix(ui): rebuild partialToolCalls on resume for input-streaming tool parts#14255giulio-leone wants to merge 1 commit intovercel:mainfrom
giulio-leone wants to merge 1 commit intovercel:mainfrom
Conversation
…parts When createStreamingUIMessageState receives a lastMessage containing tool parts in input-streaming state, the partialToolCalls map was initialized as empty. This caused tool-input-delta chunks during resume to fail because the lookup for the existing tool call returned undefined. The fix reconstructs partialToolCalls entries from any existing input-streaming tool parts in the lastMessage, enabling resumed streams to continue appending deltas to in-progress tool calls. Fixes vercel#14027 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Fixes #14027
When
createStreamingUIMessageStatereceives alastMessagecontaining tool parts ininput-streamingstate (e.g. duringresumeStream()), thepartialToolCallsmap was initialized as{}. This caused subsequenttool-input-deltachunks to fail because the lookup for the existing tool call returnedundefined, throwing:Root Cause
createStreamingUIMessageStatenever reconstructedpartialToolCallsfrom existinginput-streamingtool parts in the providedlastMessage. Fresh streams work fine because they always start withtool-input-start, but resumed streams skip that chunk since the tool part already exists in the hydrated message.Fix
After constructing the message, iterate over any existing tool parts in
input-streamingstate and pre-populatepartialToolCallswith their current state (serialized input text, index, tool name, dynamic flag, title). This enables the stream processor to correctly handletool-input-deltachunks during resume.Changes
packages/ai/src/ui/process-ui-message-stream.ts— RebuildpartialToolCallsincreateStreamingUIMessageStatefrom existinginput-streamingtool partspackages/ai/src/ui/process-ui-message-stream.test.ts— Add regression tests for resuming both static and dynamic tool parts ininput-streamingstateTests
96/96 tests pass (
vitest run --config vitest.node.config.js src/ui/process-ui-message-stream.test.ts), including 2 new regression tests.