fix(google): scope Gemini tool-call id→name resolution per turn (#45)#54
Draft
TYRMars wants to merge 1 commit into
Draft
fix(google): scope Gemini tool-call id→name resolution per turn (#45)#54TYRMars wants to merge 1 commit into
TYRMars wants to merge 1 commit into
Conversation
Gemini synthesises tool-call ids as `gem_<index>` where the index restarts at 0 every turn, so ids collide across turns of a multi-turn conversation. `GoogleRequest::from_request` built a conversation-wide, last-writer-wins `id_to_name` map, so a later turn's `gem_0` shadowed an earlier turn's `gem_0`. Because Gemini matches `functionResponse` to `functionCall` by name (no ids on the wire), turn 1's tool reply was sent with the wrong function name, causing cryptic 400s or wrong-tool attribution on any conversation using tools across more than one turn. Resolve each tool reply against the most recent assistant turn's tool-calls instead. Ids are unique within a turn, so this is collision-proof, and unlike a minting-side change it also repairs already-persisted conversations whose stored ids already collide. Fixes #45
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 #45 — Gemini's per-turn
gem_<index>tool-call ids collide across turns, corrupting multi-turn tool-result pairing.GoogleProvidersynthesises tool-call ids asgem_<index>where the index restarts at0every turn.GoogleRequest::from_requestbuilt a conversation-wide, last-writer-winsid_to_namemap, so a later turn'sgem_0shadowed an earlier turn'sgem_0. Since Gemini matchesfunctionResponse↔functionCallby name (no ids on the wire), turn 1's tool reply was sent with the wrong function name → cryptic Gemini400s or wrong-tool attribution on any conversation that uses tools across more than one turn.Fix
Resolve each tool reply against the most recent assistant turn's tool-calls instead of a global map. The id→name scope is rebuilt (cleared + repopulated) at every assistant message in
from_request's contents pass.Ids are unique within a turn, so this is collision-proof. Chosen over a minting-side change (making ids globally unique) because:
Tests
convert_tool_results_resolve_name_per_turn_despite_colliding_idsbuilds a two-turn conversation where both turns emitgem_0for different tools (fs.readthencode.grep) and asserts eachfunctionResponseresolves to the correct name.google::tests pass;cargo clippy -p harness-llm --all-targets -- -D warningsclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01Bztt9AbeP1uxDN5oh4QJMR
Generated by Claude Code