Repository navigation
fix(a2a): close the runtime when a run ends - #5082
Merged
Merged
Conversation
serve a2a creates a runtime per run but never closed it. Background agents started with run_background_agent ignore the request's cancellation on purpose, and only Runtime.Close stops them, so they kept running after the task finished. No later request could reach them, since each one gets a new runtime. Close the runtime where every run already ends: once its stream is cancelled and drained. Signed-off-by: Trung Nguyen <trung.nguyen@docker.com>
trungutt
marked this pull request as ready for review
December 1, 2026 09:37
aheritier
requested changes
Dec 1, 2026
aheritier
left a comment
Collaborator
There was a problem hiding this comment.
One blocking issue: a background worker’s cleanup can make an otherwise successful A2A request time out.
aheritier
marked this pull request as draft
December 1, 2026 11:15
Collaborator
|
Please move this PR back to ready for review once the requested feedback has been addressed. |
Runtime.Close cancels background agents and then waits for them, and a cancelled agent still runs its session_end hooks with cancellation stripped. Closing synchronously when a run ended therefore held the iterator open, and ADK only publishes COMPLETED once it returns: a slow cleanup could make a blocking call hit its deadline although the answer was ready. Close the runtime in the background instead, counted by the registry as live until Close returns, so server shutdown still waits for it within its existing bound. Signed-off-by: Trung Nguyen <trung.nguyen@docker.com>
trungutt
marked this pull request as ready for review
December 1, 2026 12:15
dgageot
approved these changes
Dec 1, 2026
trungutt
enabled auto-merge
December 1, 2026 14:22
aheritier
approved these changes
Dec 1, 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.
serve a2acreates a new runtime for every run and never closes it.Background agents started with
run_background_agentdeliberately ignore the request's cancellation, and onlyRuntime.Closestops them. So once an A2A task finished, they kept running: still calling models and using tools, with results nobody can reach. Each request gets a new runtime, so no later request can see or stop them.Every run, whether it finishes, fails, is cancelled, or is a parked approval that gets abandoned, already ends in one place: when its stream is cancelled and drained. The runtime is now closed there too, the same way
serve apiand ACP close theirs.