fix(adk): avoid panic on closed agent tool event stream - #1241
Open
Slimzeo wants to merge 1 commit into
Open
Conversation
Slimzeo
force-pushed
the
fix-agent-tool-send
branch
from
September 2, 2026 17:10
2c1410c to
2ba0157
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
fix
Check the PR title.
(Optional) Translate the PR title into Chinese.
fix(adk): 避免 agent tool 向已关闭的事件流发送事件时触发 panic
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Agent-tool events can arrive after the parent event consumer closes its generator during cancellation.
InvokableRunforwarded these events throughSend, which panics when the generator is already closed.Use the existing non-panicking
trySendpath for this best-effort event forwarding, consistent with the existing chat-model event sender. A closed parent event stream does not stop the wrapped agent from completing and returning its final tool result.The regression test controls the relevant ordering without timing sleeps:
InvokableRuncompletes without panic and returns the final result.zh(optional):
取消过程中,agent tool 的事件可能在父级消费者关闭 generator 后到达。原先
InvokableRun使用Send转发事件,会在 generator 已关闭时触发 panic。本修改复用已有的非 panic
trySend路径,与 chat-model 事件发送逻辑保持一致。父级事件流关闭不会阻止被包装的 agent 完成执行并返回最终工具结果。Validation:
go test ./adk -run 'TestAgentTool_InvokableRun_(ParentGeneratorClosesWhileAgentRuns|FinalOnly)$' -count=100go test -race ./adk -run '^TestAgentTool_InvokableRun_ParentGeneratorClosesWhileAgentRuns$' -count=100go test ./adkgofmtgit diff --check(Optional) Which issue(s) this PR fixes:
Fixes #1236
(optional) The PR that updates user documentation:
Not required; this fix does not change public APIs, configuration, or user workflows.