fix: release reference count on non-terminal exit to prevent stale registry entries#1079
Merged
Conversation
… registry entries Handles cases when producer finishes without reaching terminal task state.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors task cleanup by moving the reference count decrement logic from _handle_terminal_state to the end of the _run_producer method's finally block in active_task.py. It also extracts the ResumingAgent test helper to the module level and adds a new integration test for resuming tasks across RPC event loops. A critical issue was identified in _run_producer where the reference count decrement and cleanup could be skipped if the preceding asynchronous queue closures are cancelled or raise an exception, potentially leading to resource leaks. It is recommended to wrap the queue closures in a nested try...finally block to guarantee cleanup.
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/agent_execution/active_task.py | 95.96% | 95.92% | 🔴 -0.03% |
| Total | 93.07% | 93.07% | ⚪️ -0.00% |
Generated by coverage-comment.yml
sokoliva
approved these changes
May 26, 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.
Handles cases when producer finishes without reaching terminal task state, it's symmetrical to
ActiveTask.startwhere the counter is increased on producer and consumer creation.