fix(ai): prevent duplicate tool parts in tool-input-available handler#13868
Open
pawaca wants to merge 1 commit intovercel:mainfrom
Open
fix(ai): prevent duplicate tool parts in tool-input-available handler#13868pawaca wants to merge 1 commit intovercel:mainfrom
pawaca wants to merge 1 commit intovercel:mainfrom
Conversation
Follow-up to vercel#12774: apply the same existing-part lookup pattern to the tool-input-available case so that a dynamic flag mismatch between tool-input-start and tool-input-available does not create a duplicate part. Closes vercel#12772
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
Follow-up to #12774 which fixed the same duplicate-part bug in the
tool-input-errorhandler.The
tool-input-availablehandler has the same bug: it useschunk.dynamicdirectly to decide whether to callupdateDynamicToolPartorupdateToolPart, without first checking if there's already an existing part for the sametoolCallId. This causes a duplicate when:tool-input-startcreates a statictool-{name}part (dynamic isundefined/false)tool-input-availablearrives withdynamic: true(fromparseToolCall'sNoSuchToolErrorcatch)updateDynamicToolPartdoesn't find an existingdynamic-toolpart, so it creates a new one — resulting in two parts for the sametoolCallIdReal-world impact: sessions become permanently broken when the model calls a non-existent tool, because the duplicate
tool_useIDs cause API rejection on every subsequent request.The fix applies the same pattern already used in the
tool-input-errorcase: look up the existing part bytoolCallIdand use its type to decide the update path, falling back tochunk.dynamiconly when no existing part is found.Closes #12772
Test plan
tool input available with dynamic flag mismatch(mirrors the existingtool input error with dynamic flag mismatchtest from fix(ai): Don't create duplicate tool parts when models call non-existent tools #12774)toolCallId(no duplicate)tool-input-startis preservedprocess-ui-message-stream.test.tscontinue to pass