Skip to content

Google GenAI streaming traces overwrite parallel tool calls and merge unrelated parts #275

Closed

Description

@jabrailkhalil

Affected package

traceai-google-genai 0.1.2, main at 54421a6 (the same accumulator is present on dev).

What happens

Gemini response parts are ordered and have no index. The streaming accumulator treats them as indexed entries, defaults every part to index 0, and merges unrelated parts together.

With two parallel calls (weather(city="Paris") and time(zone="UTC")), the trace retains only time. Two calls to the same function also collapse. If text arrives alongside the tool calls, the merged part contains both text and function_call, and the text branch of attribute extraction hides the tool calls entirely. Repeated media parts are overwritten too. The chunks returned to the application still contain the correct calls; the exported trace is wrong.

Offline reproduction

from google.genai import types
from traceai_google_genai._stream import _ResponseAccumulator

acc = _ResponseAccumulator()
acc.process_chunk(types.GenerateContentResponse(candidates=[
    types.Candidate(index=0, content=types.Content(role="model", parts=[
        types.Part(function_call=types.FunctionCall(name="weather", args={"city": "Paris"})),
        types.Part(function_call=types.FunctionCall(name="time", args={"zone": "UTC"})),
    ]))
]))
print(acc._result()["candidates"][0]["content"]["parts"])
# Actual: [{'function_call': {'args': {'zone': 'UTC'}, 'name': 'time'}}]
# Expected: two distinct parts, retaining both calls and their own arguments.

I reproduced this with GenAI 1.8.0, 1.24.0, 1.75.0 and 2.31.0, including the real SDK's sync/async SSE parsing through an in-memory HTTP transport. No provider key or network call is needed. I have a patch that appends parts in order while keeping candidate indexing and concatenated message-text attributes intact.

Implementation and regression tests written with an OpenAI assistant under my supervision.

Activity

  1. nik13 commented on Nov 18, 2026

    @nik13
    Contributor

    Thanks for reporting the dropped stream parts and contributing #276. With the follow-up in #656, adjacent text fragments coalesce without overwriting distinct tool calls or multimedia parts. The Google GenAI 0.1.4 release explicitly includes these cases. Closing as fixed.

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