Conversation
…eaming When Gemini emits multiple parallel functionCall parts across separate SSE chunks, each chunk contains a single candidate with parts[0]. Previously, call_key only hashed (part_index, name, thought_signature), causing separate parallel tool calls with the same name (e.g. search_files) to map to the same slot index 0. The streaming accumulator concatenated their argument strings into invalid JSON, which failed parsing and misclassified the turn as 'Response truncated due to output length limit'. Use functionCall.id in call_key when present (Gemini 3+), and include args in fallback call_key for legacy models without IDs, ensuring each parallel tool call gets its own distinct slot index.
Contributor
Duplicate of #75528, which already fixes provider-ID slot identity and the id-less fallback while preserving incremental argument continuations. |
This was referenced Sep 4, 2026
Open
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 an issue where Gemini 3.x / 2.5 streaming responses containing multiple parallel tool calls with the same tool name (e.g. 3 parallel
search_filescalls) collided into slot index 0.Problem & Root Cause
When Gemini emits parallel tool calls across separate SSE events in
streamGenerateContent?alt=sse, each SSE event chunk delivers a single candidate withparts[0](part_index == 0).In
translate_stream_event(),call_keypreviously hashed only:When Gemini streamed consecutive parallel tool calls of the same name,
call_keywas identical across chunks, mapping every tool call to the same slot (index: 0). The streaming accumulator (chat_completion_helpers.py:tool_calls_acc) appended arguments into one string:{"pattern": "*a*"}{"pattern": "*b*"}{"pattern": "*c*"}Because the resulting string was invalid concatenated JSON, argument parsing failed and the loop exhausted retries, ultimately misdiagnosing the turn as:
Response truncated due to output length limitSolution
functionCall.idincall_key(f"id:{fc_id}") when present (standard in Gemini 3+).argsin the fallbackcall_keyso different calls atpart_index == 0receive distinct slot indices.Verification
Ran full test suite:
pytest tests/agent/test_gemini_native_adapter.py(31/31 passed)pytest tests/agent/test_gemini_*.py tests/hermes_cli/test_gemini_*.py(78/78 passed)