fix: remove zombie registry entries when ActiveTask start fails - #1179
Open
ez-lbz wants to merge 2 commits into
Open
fix: remove zombie registry entries when ActiveTask start fails#1179ez-lbz wants to merge 2 commits into
ez-lbz wants to merge 2 commits into
Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/agent_execution/active_task_registry.py | 96.61% | 96.92% | 🟢 +0.31% |
| src/a2a/server/events/event_queue_v2.py | 91.79% | 91.28% | 🔴 -0.51% |
| src/a2a/utils/telemetry.py | 91.47% | 90.70% | 🔴 -0.78% |
| Total | 93.00% | 92.98% | 🔴 -0.02% |
Generated by coverage-comment.yml
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 changed
1. Remove registry entries synchronously when
ActiveTask.start()failsProblem:
ActiveTaskRegistry.get_or_create()(src/a2a/server/agent_execution/active_task_registry.py) inserts theActiveTaskinto_active_tasksbefore callingstart(). Ifstart()raises (e.g. the task is already in a terminal state), the only cleanup was the fire-and-forgetasyncio.create_task(self._remove_task(...))scheduled via_on_active_task_cleanupinsideActiveTask.start(). That cleanup runs asynchronously and may not execute before another request checks the registry, leaving a zombie entry for a task that never started — and a concurrentget_or_createcould return the half-started task.Fix (src/a2a/server/agent_execution/active_task_registry.py):
start()call inget_or_create()withtry/except; on any failure the entry is removed synchronously under_lockbefore the exception propagates.pop), so the fire-and-forget cleanup task scheduled byActiveTask.start()remains harmless if it runs later.Testing
./.venv/Scripts/python -m pytest tests/server/agent_execution/test_active_task_registry.py -q→ 6 passed (includes newtest_get_or_create_failed_start_removes_zombie_entry, which seeds a completed task sostart()raisesInvalidParamsError, then asserts the registry no longer contains the task)../.venv/Scripts/python -m pytest tests/server/agent_execution/ -q→ 73 passed../.venv/Scripts/python -m pytest tests/server/request_handlers/test_default_request_handler_v2.py -q→ 59 passed (registry consumers unaffected)../.venv/Scripts/python -m ruff checkon modified files: clean.start()the registry is now guaranteed not to retain the task.