fix(adk): support A2A task cancellation - #2593
Open
erauner12 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Evan Rauner <raunerevan@gmail.com>
Contributor
There was a problem hiding this comment.
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 A2Acanceledtask update viaTaskUpdater. - 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
canceledtask event throughTaskUpdaterTesting
uv run pytest packages/kagent-adk/tests/unittests/test_agent_executor_cancel.py -q— 7 passeduv run pytest packages/kagent-adk/tests -q— 399 passed, 1 skippeduv run ruff check packages/kagent-adk/src/kagent/adk/_agent_executor.py packages/kagent-adk/tests/unittests/test_agent_executor_cancel.pyuv run ruff format --check packages/kagent-adk/src/kagent/adk/_agent_executor.py packages/kagent-adk/tests/unittests/test_agent_executor_cancel.pygit diff --check upstream/release/v0.10.x...HEADAddresses #2096 for the
release/v0.10.xline. A separate forward fix is still required for the newer executor onmain.