Skip to content

fix(gemini): key streaming tool call slots on explicit id to prevent argument collisions - #101654

Closed
blyndcide wants to merge 1 commit into
NousResearch:mainfrom
blyndcide:fix/gemini-stream-tool-call-id-collision
Closed

blyndcide wants to merge 1 commit into
NousResearch:mainfrom
blyndcide:fix/gemini-stream-tool-call-id-collision

Conversation

@blyndcide

Copy link
Copy Markdown

Summary

  • Fixes an issue in agent/gemini_native_adapter.py where parallel streaming tool calls from Gemini 3+ models collide on the same tool slot index.
  • Gemini 3+ emits parallel tool calls in separate SSE chunks, each with part_index=0 and a unique id (e.g. call_1, call_2). Previously, translate_stream_event keyed slot indices on (part_index, name, thought_signature) and ignored fc["id"]. When multiple parallel calls shared the same tool name, they were assigned the same slot index and their JSON argument strings were concatenated, triggering unparseable JSON and repeated max-token retries.
  • Key tool call slots on fc["id"], falling back to part index / signature when IDs are absent.

Test Plan

  • Added test_translate_stream_event_multiple_calls_same_name in tests/agent/test_gemini_native_adapter.py verifying multiple tool calls with the same function name across stream chunks maintain distinct slot indices and uncorrupted JSON payloads.

…argument collisions

When Gemini 3+ streams parallel tool calls, it emits each tool call as a separate
SSE event with its own explicit ID, but with part_index=0 in each single-part event.
translate_stream_event previously keyed tool call slots only on
(part_index, name, thought_signature). When multiple tool calls had the same function
name (e.g. parallel skill_view or tool_call invocations), they collided on the same slot
index, concatenating JSON argument payloads. Downstream JSON parse errors then triggered
repeated retries that misdiagnosed the malformed JSON as output truncation.

Key the slot on fc['id'] whenever present so each parallel tool call retains its own
distinct index and argument stream.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/gemini Google Gemini (AI Studio, Cloud Code) P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Sep 2, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Duplicate of #75528: both key Gemini 3 streaming slots by the provider call ID. #75528 also retains the id-less continuation-safe fallback.

@kshitijk4poor

Copy link
Copy Markdown
Contributor

The Gemini parallel tool-call slot collision is landing via #111686 (salvage of #75528 by @jmiguellucas, co-credited to the first submitter @cdbartholomew #24676; armed to auto-merge on green): Gemini 3 ids are the slot identity, no-id calls disambiguate by value with reachable key#N slots for resends. Closing this one as a duplicate — thank you for the fix; if #111686 does not merge I'll reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/gemini Google Gemini (AI Studio, Cloud Code) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants