Skip to content

fix: remove zombie registry entries when ActiveTask start fails - #1179

Open
ez-lbz wants to merge 2 commits into
a2aproject:mainfrom
ez-lbz:fix/active-task-registry-cleanup
Open

fix: remove zombie registry entries when ActiveTask start fails#1179
ez-lbz wants to merge 2 commits into
a2aproject:mainfrom
ez-lbz:fix/active-task-registry-cleanup

Conversation

@ez-lbz

@ez-lbz ez-lbz commented Aug 10, 2026

Copy link
Copy Markdown

What changed

1. Remove registry entries synchronously when ActiveTask.start() fails

Problem: ActiveTaskRegistry.get_or_create() (src/a2a/server/agent_execution/active_task_registry.py) inserts the ActiveTask into _active_tasks before calling start(). If start() raises (e.g. the task is already in a terminal state), the only cleanup was the fire-and-forget asyncio.create_task(self._remove_task(...)) scheduled via _on_active_task_cleanup inside ActiveTask.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 concurrent get_or_create could return the half-started task.

Fix (src/a2a/server/agent_execution/active_task_registry.py):

  • Wrapped the start() call in get_or_create() with try/except; on any failure the entry is removed synchronously under _lock before the exception propagates.
  • The removal is idempotent (pop), so the fire-and-forget cleanup task scheduled by ActiveTask.start() remains harmless if it runs later.

Testing

  • ./.venv/Scripts/python -m pytest tests/server/agent_execution/test_active_task_registry.py -q6 passed (includes new test_get_or_create_failed_start_removes_zombie_entry, which seeds a completed task so start() raises InvalidParamsError, then asserts the registry no longer contains the task).
  • ./.venv/Scripts/python -m pytest tests/server/agent_execution/ -q73 passed.
  • ./.venv/Scripts/python -m pytest tests/server/request_handlers/test_default_request_handler_v2.py -q59 passed (registry consumers unaffected).
  • ./.venv/Scripts/python -m ruff check on modified files: clean.
  • Behavior change: none for the success path; on a failed start() the registry is now guaranteed not to retain the task.

@ez-lbz
ez-lbz requested a review from a team as a code owner August 10, 2026 16:09
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant