fix(adk): stop forwarding backgrounded sub-agent events to the parent turn#1128
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alpha/10 #1128 +/- ##
===========================================
Coverage ? 81.84%
===========================================
Files ? 189
Lines ? 30578
Branches ? 0
===========================================
Hits ? 25028
Misses ? 3737
Partials ? 1813 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… turn A managed sub-agent run that is backgrounded (explicit run_in_background or auto-moved at the foreground deadline) runs detached and outlives the turn that launched it. It kept forwarding the inner agent's events to the parent turn's event generator, which the turn closes on end — injecting events into a stream the user has stopped watching, and racing a send against that close. Introduce a lifecycle signal (backgroundtask TaskInfo.Backgrounded) that closes when a task moves to the background, and an AgentTool option (WithAgentToolParentForwardUntil) that bounds parent forwarding by it. The subagent middleware wires the two together, so forwarding stops the moment a run detaches; foreground runs are unaffected. The gated path uses a non-panicking send by definition (it may outlive its consumer); the plain foreground path keeps a panicking send so an unexpected closed-generator send still surfaces. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
…ntation Make the two halves of AgentTool event forwarding read as a pair: the target (where inner events go) and the bound (how long they go there). - withAgentToolEventGenerator -> withAgentToolEventForwardTarget - withTypedAgentToolEventGenerator -> withTypedAgentToolEventForwardTarget - WithAgentToolParentForwardUntil -> WithAgentToolEventForwardUntil - agentToolOptions.gatedForward/forwardParentUntil -> eventForwardGated/eventForwardUntil Behavior is unchanged; this is a naming-only refactor. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
….ForwardGate Move the event-forwarding gate option to a self-documenting ForwardGate struct in internal/agenttool, replacing the split across agentToolOptions and the exported WithAgentToolEventForwardUntil. Also remove the AgentEvent type-specialization wrapper (withAgentToolEventForwardTarget) in favor of the generic withTypedAgentToolEventForwardTarget. Co-Authored-By: Claude <noreply@anthropic.com>
5b5414b to
b065dd3
Compare
shentongmartin
approved these changes
Jul 6, 2026
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.
Summary
run_in_background, or auto-moved to the background at the foreground deadline) runs detached and outlives the turn that launched it. It kept forwarding the inner agent's events to the parent turn's event generator, which the turn closes on end — injecting events into a stream the user has stopped watching, and racing a send against that close.backgroundtask.TaskInfo.Backgrounded(<-chan struct{}) that closes when a task moves to the background: before work starts for an explicitRunInBackgroundlaunch, and at the auto-background transition (detach). Foreground-completing runs never fire it.adk.WithAgentToolParentForwardUntil(done)that bounds parent forwarding by that signal. The subagent middleware wires the two together, so forwarding stops the moment a run detaches; foreground runs are unaffected.Design notes
Send, so a send on an unexpectedly-closed generator still surfaces as the bug it is.Test plan
go test -race ./adk/...(passes locally)golangci-lint run ./adk/...(0 issues locally)🤖 Generated with Claude Code