Skip to content

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

In review

Description

@AkshayShah03

Describe the bug

Since 5096169, when runner.run_async raises asyncio.CancelledError on its own (no A2A cancel request, outer task not being cancelled), _consume_runner_with_abort re-raises it. Propagating it is the point of that commit, but neither executor publishes a terminal status before the error leaves execute(): A2aAgentExecutor.execute only handles Exception, and the new-impl executor does the same. The a2a-sdk request handler absorbs the CancelledError and closes the stream, so the client's last update is TASK_STATE_WORKING and the task store keeps the task in WORKING permanently.

Before 5096169 the error was swallowed, and since abort_signal had been set, the executor took the abort path and ended the task as TASK_STATE_CANCELED.

Repro: a real a2a-sdk 1.2.2 server and client in-process over ASGI (using the tests/unittests/a2a/integration helpers). The fake runner yields one partial event and then raises CancelledError:

async def run_async(**kwargs):
  yield Event(author="FakeAgent",
              content=types.Content(parts=[types.Part(text="partial")]),
              partial=True)
  raise asyncio.CancelledError()
                              client's last state    stored task state
50961696a~1 (all 4 combos)    TASK_STATE_CANCELED    TASK_STATE_CANCELED
50961696a / main (all 4)      TASK_STATE_WORKING     TASK_STATE_WORKING

"All 4 combos" means streaming on and off, legacy and new executor. A stray CancelledError like this can come from an anyio cancel scope (e.g. an MCP client session) or from awaiting a task that was cancelled elsewhere. The new tests in 5096169 check that the error propagates but not the task's final state.

Expected behavior

The task ends in a terminal state (canceled or failed) before the CancelledError is re-raised, as it did before.

Environment

main at 03725e8, a2a-sdk 1.2.2, Python 3.12.

I'm happy to send a PR with a test that checks the final task state.

Activity

  1. chelsealong commented on Nov 28, 2026

    @chelsealong
    Contributor

    May I work on this issue (#8417: a2a: a CancelledError from runner.runasync now leaves the task in TASKSTATEWORKING) and, if I can reproduce it, submit a focused fix with regression coverage? Please let me know if someone is already handling it or if you would prefer a different approach. I would use Codex assistance and disclose that in any PR.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions