#2856·ag-ui

[adk-middleware] Second of two parallel same-name client-tool calls is dropped under Gemini SSE streaming

Author: AntoineGlacetCreated Sep 29, 2026Updated Oct 1, 2026
Labelsbug

Summary

When Gemini streams two parallel calls to the same client-side (long-running) tool, ag_ui_adk emits only the first. The second never reaches the client, so the frontend never executes it and never returns its result. The session is then left holding an unanswered function call, and every later turn in the thread is rejected by the model.

Both HITL modes are affected: non-resumable (fire-and-forget) and resumable (ADKAgent.from_app + ResumabilityConfig).

Environment

  • ag-ui-adk 0.7.0, google-adk 2.8.0, google-genai 2.21.0
  • Gemini 3.x on Vertex AI, StreamingMode.SSE
  • A client tool (declared by the frontend through AGUIToolset) that the model calls twice in one turn, e.g. two excel_read calls for two ranges

Root cause

Gemini's SSE stream carries each parallel function call in its own partial chunk, then repeats all of them in the aggregated final response under the same ids. The replay guard added for #1168 and #1334 assumes the opposite:

Genuinely parallel same-name calls arrive as multiple parts of ONE event … a same-name reappearance in a LATER event is always a replay.

Two places act on that assumption, and each drops the second call independently.

1. EventTranslator.translate_lro_function_calls (event_translator.py, around lines 856–870)

The position counter is incremented only for calls that have not been emitted yet:

python
if getattr(fc, 'id', None) in lro_ids \
  and fc.id not in self.emitted_tool_call_ids:
    position = seen_in_event.get(fc.name, 0) + 1
    ...
    if position <= already_emitted:
        continue  # treated as a replay
  • Partial event #2: it holds [b] alone. b is position 1 and already_emitted is 1 (a), so b is suppressed.
  • Final event: it holds [a, b]. a is skipped by id without being counted, so b is position 1 again and is suppressed again.

2. ClientProxyTool.run_async (client_proxy_tool.py, around lines 300–315)

The id-match early return (tool_call_id in self._translator_emitted_tool_call_ids) does not advance _lro_finalized_by_name.

  • The proxy invocation for a returns on the id match and leaves finalized at 0.
  • The invocation for b then sees finalized (0) < len(emitted_partials) (1). It treats b as the twin of a's partial and suppresses it.

Reproduction (offline, deterministic)

python
import asyncio
from ag_ui_adk.event_translator import EventTranslator
from google.adk.events.event import Event
from google.genai import types

def call(call_id, a1):
    return types.Part(function_call=types.FunctionCall(id=call_id, name="excel_read", args={"range_address": a1}))

def event(parts, *, partial):
    return Event(author="assistant", invocation_id="inv-1", partial=partial,
                 content=types.Content(role="model", parts=parts),
                 long_running_tool_ids={p.function_call.id for p in parts})

async def main():
    translator = EventTranslator(client_tool_names={"excel_read"})
    stream = [  # Gemini SSE: one partial chunk per parallel call, then the aggregated final
        event([call("adk-a", "A1:B2")], partial=True),
        event([call("adk-b", "C1:D2")], partial=True),
        event([call("adk-a", "A1:B2"), call("adk-b", "C1:D2")], partial=False),
    ]
    emitted = []
    for e in stream:
        async for ev in translator.translate_lro_function_calls(e):
            if type(ev).__name__ == "ToolCallStartEvent":
                emitted.append(ev.tool_call_id)
    print(emitted)  # actual: ['adk-a']   expected: ['adk-a', 'adk-b']

asyncio.run(main())

Against real Gemini (gemini-3.8-flash on Vertex), a two-range excel_read prompt lost the second call in 3 of 3 runs, in both HITL modes. Answering only the one call that arrived produced the provider's 400 for an unanswered function call on the next request.

Proposed fix

Count calls that were already emitted (matched by id) in both positional counters:

  1. Translator: increment position for every same-name LRO call in the event, before the emitted_tool_call_ids check. The replay test then compares the new call's true position. With this change, the reproduction above emits ['adk-a', 'adk-b']. b is emitted from the final event, because its own partial chunk is still indistinguishable from a replay by position alone.
  2. ClientProxyTool: when the id-match early return fires, also advance _lro_finalized_by_name[self.name]. The next same-name invocation is then compared against the right partial.

A stronger fix could also emit b from its own partial chunk. That would mean telling a replay from a new call by content (name plus arguments) or by the partial→final id pairing, rather than by position across events.

Workaround we ship meanwhile

We subclass Gemini and remove function_call parts from partial responses, so every call first appears in the aggregated final response, which is one event. This keeps thinking, text and usage streaming. The cost is 14–624 ms per call (measured) before the pane sees it.

Related: #1168, #1334, #1355, #1920.