Repository navigation
Conversation
…l_id is reused When duplicate tool_call_ids occur across turns (or within a stream), tcID2Name is a global object populated across all messages where later occurrences overwrite earlier entries. While commit ea333e5 introduced _dupN suffixing to prevent Duplicate ID rejection from Google, functionResponse lookup still referenced the global tcID2Name[rawId]. If tool_call_ids were reused across different tools, earlier functionResponses received the later tool's name instead of the matching functionCall name, triggering Google 400 INVALID_ARGUMENT. This fix records the tool name directly in toolCallPairs ({ rawId, uniqueId, name }) and uses localName with fallback to tcID2Name, guaranteeing that functionCall and functionResponse names match within the turn. Added unit regression test.
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.
Problem
In multi-turn Agent conversations with extensive tool interactions, random or client-generated
tool_call_ids can occasionally collide across turns (or during multi-step execution).Commit
ea333e5gracefully introduced_dupNdeduplication and queuedtoolResponsesto resolve Google'sDuplicate function call ID400 error. However, when resolving the tool name forfunctionResponse, line 166 still relied on the global lookup:Because
tcID2Nameis built by scanning all messages inbody.messagesbeforehand, a later tool call that reuses the samerawIdfor a different tool will overwritetcID2Name[rawId].As a result:
functionCallemits the original tool name (e.g.read_file).functionResponseemits the overwritten tool name from the subsequent turn (e.g.patch_file).functionCall.name === functionResponse.nameand immediately returns:Solution
name: tc.function.namedirectly intoolCallPairsduring the assistant turn ({ rawId, uniqueId, name: tc.function.name }).functionResponse, prioritizelocalNamebefore falling back totcID2Name[rawId].tests/unit/gemini-duplicate-tool-call.test.jscovering cross-turn ID reuse with different tool names.Testing
preserves correct tool name in functionResponse when identical tool_call_id is reused for different tools.functionCallandfunctionResponseaccurately retain their respective per-turn tool names (read_file->read_file,patch_file->patch_file).