fix(live): stop retired streaming tools from writing into a new agent run

Aperta
#8,302 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@surajksharma07 ci sta già lavorando.

Dal 23/11/2026.

  • #8303 di @he-yufeng — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
ai, backend

Direzione di ricerca

Start with stop_background_tool_tasks() and _run_streaming_tool(), then trace how ActiveBackgroundTool registry entries relate to the shared LiveRequestQueue during Runner.run_live transfers. Reproduce with the mock Live connection. Done when a tool that ignores cancellation and yields after its entry is retired sends nothing to the model or user event path, and a late finally cannot remove a newer entry with the same function-call id. A linked pull request (#8303) already exists, so check it first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

stop_background_tool_tasks() gives a background tool one second to stop, then retires its registry entry even if the tool ignored cancellation. That best-effort lifecycle is useful, but retirement currently does not fence the tool's output path.

A streaming tool can swallow CancelledError, wait until its registry entry has been cleared, and then yield another result. _run_streaming_tool() still sends that result to the shared LiveRequestQueue. An Event yielded at the same point can still be enqueued as a user-facing message. During agent transfer, the old call can therefore write into the next agent's stream.

This is a remaining case after #7006. Ordinary cooperative cancellation stops the tool before the transfer delay; this report covers a tool that deliberately ignores the first cancellation and produces output only after retirement.

Reproduction

The regression uses the real Runner.run_live, an in-memory LiveRequestQueue, and the existing mock Live connection:

  1. The root agent starts a streaming tool and transfers to a subagent.
  2. The tool ignores its first cancellation.
  3. The shutdown timeout expires and the registry is cleared.
  4. The tool yields {"late": True} during the transfer delay.

On current main (2b90353cd2f1ee0a8a52262a7843333b6f7d2c8d), late_stream reaches the model connection after transfer. A second direct reproduction shows a retired tool yielding Event(message="stale") into the user event path.

Expected

Use the existing ActiveBackgroundTool entry as the call's ownership token. Once that exact entry is no longer registered, the call must stop producing model responses and user events. A late finally block must not remove a newer entry with the same function-call id. The existing one-second best-effort cancellation policy and normal output from a still-current tool should stay unchanged. No real Gemini Live endpoint is needed to verify the ADK-owned task, registry, and queue behavior.

Lingua principale
Python
Stelle
22.3k
Fork
4.4k
Merge medio
1g 2h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/adk-python

Tutte le issue di google/adk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.