Skip to content

fix(adk): support A2A task cancellation - #2593

Open
erauner12 wants to merge 1 commit into
kagent-dev:release/v0.10.xfrom
erauner12:fix/a2a-cancel-2096
Open

fix(adk): support A2A task cancellation#2593
erauner12 wants to merge 1 commit into
kagent-dev:release/v0.10.xfrom
erauner12:fix/a2a-cancel-2096

Conversation

@erauner12

Copy link
Copy Markdown
Contributor

Summary

  • publish the canonical A2A canceled task event through TaskUpdater
  • preserve the canceled result when the request handler stops the active producer
  • keep unrelated execution cancellation on the existing failed-status path
  • cover exact task/context identity, handler persistence, queue-tap misses, and cancellation ordering

Testing

  • uv run pytest packages/kagent-adk/tests/unittests/test_agent_executor_cancel.py -q — 7 passed
  • uv run pytest packages/kagent-adk/tests -q — 399 passed, 1 skipped
  • uv run ruff check packages/kagent-adk/src/kagent/adk/_agent_executor.py packages/kagent-adk/tests/unittests/test_agent_executor_cancel.py
  • uv run ruff format --check packages/kagent-adk/src/kagent/adk/_agent_executor.py packages/kagent-adk/tests/unittests/test_agent_executor_cancel.py
  • git diff --check upstream/release/v0.10.x...HEAD

Addresses #2096 for the release/v0.10.x line. A separate forward fix is still required for the newer executor on main.

Signed-off-by: Evan Rauner <raunerevan@gmail.com>
@erauner12
erauner12 requested a review from a team as a code owner August 27, 2026 03:18
Copilot AI lite review requested due to automatic review settings August 27, 2026 03:18
@github-actions github-actions Bot added the bug Something isn't working label Aug 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Python ADK A2A executor to support canonical task cancellation semantics, ensuring explicit A2A cancels publish a terminal canceled status (via TaskUpdater) and that explicit cancellation is not incorrectly converted into a failed terminal state when the request handler cancels the producer task.

Changes:

  • Implement A2aAgentExecutor.cancel(...) to publish a canonical A2A canceled task update via TaskUpdater.
  • Preserve the explicit-cancel terminal state by suppressing the existing “CancelledError ⇒ failed status” path when the cancellation originated from an explicit A2A cancel request.
  • Add unit tests covering task/context identity requirements, handler ordering (publish canceled before producer cancel), queue-tap miss behavior, and explicit vs unrelated execution cancellation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/packages/kagent-adk/src/kagent/adk/_agent_executor.py Implements canonical cancellation event publishing and distinguishes explicit A2A cancellation from unrelated CancelledError to avoid emitting failed.
python/packages/kagent-adk/tests/unittests/test_agent_executor_cancel.py Adds targeted unit tests validating cancellation event semantics, persistence behavior, and ordering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +157 to +161
@staticmethod
def _was_explicitly_canceled(event_queue: EventQueue) -> bool:
"""Check this execution queue and its handler-created cancellation taps."""
queues = (event_queue, *getattr(event_queue, "_children", ()))
return any(getattr(queue, _EXPLICIT_A2A_CANCELLATION_ATTR, False) for queue in queues)
Comment on lines 263 to +266
except asyncio.CancelledError as e:
logger.error("A2A request execution was cancelled", exc_info=True)
error_message = str(e) or "A2A request execution was cancelled."
await self._publish_failed_status_event(context, event_queue, error_message)
if self._was_explicitly_canceled(event_queue):
logger.info("A2A request execution stopped after explicit cancellation")
else:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants