Skip to content

fix(a2a): publish canceled status before re-raising CancelledError - #8422

Open
xuilen wants to merge 1 commit into
google:mainfrom
xuilen:fix/a2a-cancelled-error-terminal-state
Open

xuilen wants to merge 1 commit into
google:mainfrom
xuilen:fix/a2a-cancelled-error-terminal-state

Conversation

@xuilen

@xuilen xuilen commented Nov 28, 2026

Copy link
Copy Markdown

Closes #8417

Summary

When runner.run_async raises asyncio.CancelledError on its own (without an A2A cancel request), _consume_runner_with_abort re-raises it. Because neither A2aAgentExecutor.execute nor ExecutorImpl.execute caught asyncio.CancelledError, no terminal status event was published before the error exited execute(), leaving the task stuck in TASK_STATE_WORKING.

Changes

  • src/google/adk/a2a/executor/a2a_agent_executor.py & src/google/adk/a2a/executor/a2a_agent_executor_impl.py:
    • Catch asyncio.CancelledError in execute(), publish a terminal TASK_STATE_CANCELED status via _enqueue_canceled_task_event when not active_run.terminal_cancel_emitted, mark active_run.terminal_cancel_emitted = True, and re-raise asyncio.CancelledError to preserve cancellation propagation.
  • tests/unittests/a2a/executor/test_a2a_agent_executor.py & tests/unittests/a2a/executor/test_a2a_agent_executor_impl.py:
    • Assert that the last enqueued status on CancelledError is _compat.TS_CANCELED (and never _compat.TS_FAILED) for both converter and runner cancellation sources.

Testing

  • pytest tests/unittests/a2a/executor/test_a2a_agent_executor.py tests/unittests/a2a/executor/test_a2a_agent_executor_impl.py: 92 passed, 0 failed.
  • ruff check: passed.

@google-cla

google-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

a2a: a CancelledError from runner.run_async now leaves the task in TASK_STATE_WORKING

1 participant