fix(ai): prevent duplicate tool parts when model calls unavailable tool#12556
Open
gdaybrice wants to merge 1 commit intovercel:mainfrom
Open
fix(ai): prevent duplicate tool parts when model calls unavailable tool#12556gdaybrice wants to merge 1 commit intovercel:mainfrom
gdaybrice wants to merge 1 commit intovercel:mainfrom
Conversation
45186a0 to
d0eaf3a
Compare
When a model calls a tool that isn't in the available tools list, the
streaming pipeline can create two UI parts with the same toolCallId:
1. tool-input-start arrives without a dynamic flag, creating a static
tool-{name} part
2. tool-input-error arrives with dynamic: true (set by parseToolCall
for NoSuchToolError), calling updateDynamicToolPart which doesn't
find the existing static part and creates a new dynamic-tool part
This causes issues when the message is later sent back to providers
like Amazon Bedrock that validate toolUse ID uniqueness within a
single message.
The fix checks for an existing part before deciding which update
function to call, ensuring the original part type is preserved.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d0eaf3a to
8c550fc
Compare
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
toolCallId— a statictool-{name}part and adynamic-toolparttool-input-startarrives without adynamicflag (creating a static part), thentool-input-errorarrives withdynamic: true(fromparseToolCall'sNoSuchToolErrorhandling) and creates a new dynamic part instead of updating the existing oneReproduction
toolCallId— onetool-{name}and onedynamic-toolconvertToModelMessagesconverts both intotool-callcontent partsgroupIntoBlocksmerges them into one message, and Bedrock rejects it: