Skip to content

fix(a2a): close the runtime when a run ends - #5082

Merged
trungutt merged 2 commits into
docker:mainfrom
trungutt:fix/a2a-close-runtime
Dec 1, 2026
Merged

trungutt merged 2 commits into
docker:mainfrom
trungutt:fix/a2a-close-runtime

Conversation

@trungutt

@trungutt trungutt commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

serve a2a creates a new runtime for every run and never closes it.

Background agents started with run_background_agent deliberately ignore the request's cancellation, and only Runtime.Close stops 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.

A2A request ──▶ new runtime ──▶ run_background_agent ──▶ worker starts
                    │
task finishes ──────┘  runtime dropped, never closed
                                           worker keeps running ✗

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 api and ACP close theirs.

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>
@aheritier aheritier added area/a2a Agent-to-Agent protocol, A2A server, inter-agent communication kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Dec 1, 2026
@trungutt
trungutt marked this pull request as ready for review December 1, 2026 09:37
@trungutt
trungutt requested a review from a team as a code owner December 1, 2026 09:37

@aheritier aheritier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocking issue: a background worker’s cleanup can make an otherwise successful A2A request time out.

Comment thread pkg/a2a/approval.go Resolved
@aheritier
aheritier marked this pull request as draft December 1, 2026 11:15
@aheritier

Copy link
Copy Markdown
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
trungutt marked this pull request as ready for review December 1, 2026 12:15
@trungutt
trungutt requested review from a team and aheritier December 1, 2026 12:16
@trungutt
trungutt enabled auto-merge December 1, 2026 14:22
@trungutt
trungutt added this pull request to the merge queue Dec 1, 2026
Merged via the queue into docker:main with commit 8e45b5b Dec 1, 2026
17 checks passed
@trungutt
trungutt deleted the fix/a2a-close-runtime branch December 1, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/a2a Agent-to-Agent protocol, A2A server, inter-agent communication kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants