Skip to content

fix(server): allow recovery after status event validation fails - #1365

Open
HowieYin wants to merge 3 commits into
a2aproject:mainfrom
HowieYin:fix/task-updater-event-validation
Open

HowieYin wants to merge 3 commits into
a2aproject:mainfrom
HowieYin:fix/task-updater-event-validation

Conversation

@HowieYin

@HowieYin HowieYin commented Oct 21, 2026 •

Copy link
Copy Markdown

Problem

TaskUpdater.update_status() sets the terminal flag before constructing the status event. An invalid timestamp, message, or metadata can then raise an exception before anything reaches the queue.

For example, after a COMPLETED update with an invalid timestamp, calling failed() to report the error raises a RuntimeError saying the task is already terminal. The updater never published the completion event.

Fix

Construct the complete TaskStatusUpdateEvent before setting the terminal flag, so a construction error leaves the updater able to report a failure. The flag is still set under the existing lock, before enqueueing.

Tests

  • Add recovery tests for invalid timestamps across all four terminal states and for invalid metadata.
  • Verify that DefaultRequestHandlerV2 returns and stores a FAILED task after the agent catches a status validation error.

Local validation on Python 3.10:

  • ./scripts/lint.sh passes (Ruff, formatting, and ty).
  • UV_OFFLINE=1 uv run pytest --cov=a2a --cov-report=term --cov-fail-under=88: 2,312 passed, 183 skipped, 3 xfailed, 1 xpassed, with 92.95% coverage.

The 183 skips are 182 PostgreSQL/MySQL tests without configured test databases and one SQLite row-lock test. The existing xfail/xpass cases reference #869. The first online runs hit the cross-version fixture's three-second startup timeout while uv downloaded or resolved legacy SDK dependencies; the full run passes with those dependencies cached and offline mode enabled.

GitHub CI for the updated commit is pending.

@HowieYin
HowieYin requested a review from a team as a code owner October 21, 2026 11:35
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/tasks/task_updater.py 94.83% 98.31% 🟢 +3.48%
Total 92.96% 92.98% 🟢 +0.02%

Generated by coverage-comment.yml

@Iwaniukooo11 Iwaniukooo11 self-assigned this Oct 21, 2026
@HowieYin HowieYin changed the title fix(server): validate events before marking tasks terminal fix(server): allow recovery after status event validation fails Oct 22, 2026
Comment thread tests/server/tasks/test_task_updater.py Outdated


@pytest.mark.asyncio
async def test_message_validation_failure_allows_terminal_retry(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove, it follows same path as test_timestamp_validation_failure_allows_terminal_retry, so it doesen't add useful coverage

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review! Removed both tests and the unused import.

Comment thread tests/server/tasks/test_task_updater.py Outdated


@pytest.mark.asyncio
async def test_legacy_partial_publish_cancellation_keeps_terminal_guard() -> (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test passes on main too, so it doesn't cover the change introduced here. Please remove it.

This branch has not been deployed

No deployments
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.

2 participants