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

未关闭
#8,302 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 3 天内回复

@surajksharma07 已经在做这个了。

开始于 2026年11月23日。

  • #8303 来自 @he-yufeng —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
ai, backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
22.3k
派生
4.4k
平均合并
1 天 2 小时
30 天内合并 PR
6

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/adk-python 的其他 Issue

查看 google/adk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。