Skip to content

Commit e5a93bc

Browse files
committed
According to A2A spec section 8.2, it should return -32002 (TaskNotCancelableError)
1 parent a3f7c08 commit e5a93bc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
MessageSendParams,
3737
Task,
3838
TaskIdParams,
39+
TaskNotCancelableError,
3940
TaskNotFoundError,
4041
TaskPushNotificationConfig,
4142
TaskQueryParams,
@@ -124,6 +125,14 @@ async def on_cancel_task(
124125
if not task:
125126
raise ServerError(error=TaskNotFoundError())
126127

128+
# Check if task is in a non-cancelable state (completed, canceled, failed, rejected)
129+
if task.status.state in TERMINAL_TASK_STATES:
130+
raise ServerError(
131+
error=TaskNotCancelableError(
132+
message=f'Task cannot be canceled - current state: {task.status.state}'
133+
)
134+
)
135+
127136
task_manager = TaskManager(
128137
task_id=task.id,
129138
context_id=task.context_id,

0 commit comments

Comments
 (0)