Skip to content

[Bug]: Gemini function calls without IDs can merge and skip tool execution #3980

Closed

Description

@yyytttwww888-beep

Describe the bug

Gemini function calls without an explicit ID can collide inside GeminiResponseParser, causing separate tool calls to be merged and rejected before execution. A request to look up Tokyo and Paris weather can therefore execute neither lookup, even though both function calls contain valid arguments.

Reproduced on 2.1.0-SNAPSHOT, main f9d717ec56201404067d26b55f4308c3ef69ef16.

To reproduce

  1. Construct a Google GenAI GenerateContentResponse containing these two parts:

    [
      {"functionCall":{"name":"get_weather","args":{"city":"Tokyo"}}},
      {"functionCall":{"name":"get_weather","args":{"city":"Paris"}}}
    ]
  2. Pass the response through GeminiResponseParser.parseResponse() and ReasoningContext.processChunk(), as the normal model/agent path does. Repeat the pair in a short loop to exercise the clock collision.

  3. Inspect buildFinalMessage().getContentBlocks(ToolUseBlock.class), or execute the response through a ReActAgent with a recording get_weather tool.

Expected: two independent calls with their original arguments; both tools execute.

Observed in the local fixture: 99 of 100 parser/accumulator attempts collapsed the two calls into one malformed call. In 20 agent runs, the tool was invoked zero times in every run. These are local reproduction counts, not production failure rates. Supplying distinct provider IDs makes both controls pass.

No provider API access is needed: the fixture uses the real SDK response types, parser, accumulator and Agent, with a local model fixture.

Cause

GeminiResponseParser.parseToolCall() falls back to:

functionCall.id().orElse("tool_call_" + System.currentTimeMillis())

Calls parsed in the same millisecond receive the same ID. ToolCallsAccumulator then treats them as fragments of one call and concatenates their JSON arguments into {"city":"Tokyo"}{"city":"Paris"}. The malformed-arguments guard correctly refuses to execute that corrupted call and sends an error result to the next reasoning step.

The provider's FunctionCall.id is optional in the Google API, so these are valid inputs. Both streaming and non-streaming Gemini paths use this parser.

Proposed change

Generate a unique fallback ID for each independent local function call while retaining provider-supplied IDs. Add parser/accumulator and actual Agent execution regressions, including the distinct-provider-ID control. I am preparing this focused fix.

Activity

  1. added a commit that references this issue on Nov 6, 2026
    a732224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions