Skip to content

HTTP+JSON CancelTask returns 409 Conflict instead of 400 Bad Request for TaskNotCancelableError #1298

Open

Description

@jmesnil

Summary

When canceling a task that is already in a terminal state (TASK_STATE_COMPLETED), the HTTP+JSON transport returns 409 Conflict instead of 400 Bad Request as required by the A2A specification's error mapping table.

Requirement

Specification

CancelTask MUST return TaskNotCancelableError when the task is not in a cancelable state (already completed, failed, or canceled).

The error mapping table in section 3.3.2 specifies:

Error Name JSON-RPC gRPC HTTP
TaskNotCancelableError -32002 FAILED_PRECONDITION 400 Bad Request

Expected behavior

The HTTP+JSON transport should return HTTP status 400 Bad Request with an AIP-193 error body containing "code": 400 and an ErrorInfo detail with "reason": "TASK_NOT_CANCELABLE".

Actual behavior

The SUT returns HTTP 409 Conflict with "code": 409 and "status": "FAILED_PRECONDITION":

{
  "error": {
    "code": 409,
    "status": "FAILED_PRECONDITION",
    "message": "Task cannot be canceled - current state: TASK_STATE_COMPLETED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "TASK_NOT_CANCELABLE",
        "domain": "a2a-protocol.org",
        "metadata": {}
      }
    ]
  }
}

Note: The reason and error structure are correct — only the HTTP status code is wrong.

Reproducer

# 1. Create a task that completes immediately
TASK_ID=$(curl -s -X POST "http://localhost:9999/message:send" \
  -H "Content-Type: application/json" \
  -H "A2A-Version: 1.0" \
  -d '{"message":{"role":"ROLE_USER","parts":[{"text":"TCK prerequisite task creation"}],"messageId":"tck-complete-task-repro"},"configuration":{"acceptedOutputModes":["text"]}}' \
  | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['task']['id'])")

# 2. Verify the task is completed
curl -s -X GET "http://localhost:9999/tasks/$TASK_ID" \
  -H "A2A-Version: 1.0" \
  | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['status']['state'])"
# → TASK_STATE_COMPLETED

# 3. Attempt to cancel the completed task (expect 400, get 409)
curl -s -w "\nHTTP Status: %{http_code}\n" -X POST "http://localhost:9999/tasks/$TASK_ID:cancel" \
  -H "A2A-Version: 1.0"
# → HTTP Status: 409 (should be 400)

TCK test

tests/compatibility/core_operations/test_task_lifecycle.py::TestCancelTask::test_cancel_terminal_task_returns_error[http_json]

Activity

  1. ravismash commented on Nov 7, 2026

    @ravismash

    I'd like to take this.

    TASK_NOT_CANCELABLE is mapped to 409 in A2AErrorCodes. Comparing the rest of that enum with the table in section 5.4 of the spec (v1.0.1, same in v1.1.0-rc), I found five more differences:

    Error Code today (gRPC / HTTP) Spec (gRPC / HTTP)
    TaskNotCancelableError FAILED_PRECONDITION / 409 FAILED_PRECONDITION / 400
    PushNotificationNotSupportedError UNIMPLEMENTED / 400 FAILED_PRECONDITION / 400
    UnsupportedOperationError UNIMPLEMENTED / 400 FAILED_PRECONDITION / 400
    ContentTypeNotSupportedError INVALID_ARGUMENT / 415 INVALID_ARGUMENT / 400
    InvalidAgentResponseError INTERNAL / 502 INTERNAL / 500
    VersionNotSupportedError UNIMPLEMENTED / 400 FAILED_PRECONDITION / 400

    For the gRPC ones, GrpcErrorMapper already reads the ErrorInfo reason first, so clients of this SDK would keep working. Only its status-code fallback (UNIMPLEMENTED → UnsupportedOperationError) is affected, and it could stay as is for older servers.

    Should I fix only the 409 here, as the issue describes, or align the whole table in one PR (or the HTTP codes here and the gRPC codes in a follow-up)? Some of these may be deliberate, so I'd rather check first.

  2. kabir commented on Nov 9, 2026

    @kabir
    Collaborator

    Hi, we support version 1.0 of the spec. The 1.0.1 release didn't seem to be properly published (the last version on the site is shown as 1.1.0) , and the A2A-version header is 1.0 in both 1.0 and 1.0.1, so there is no way to distinguish between 1.0.0 and 1.0.1. So we're stuck on 1.0. It doesn't make sense to use 1.0.1 error mappings when we can't distinguish the exact protocol used.

    For 1.1.0 we will support this quickly after it is added, but probably add some kind of compat layer to support that along with 1.0.

  3. ravismash commented on Nov 9, 2026

    @ravismash

    Thanks, that makes sense. I diffed the spec tags: the current A2AErrorCodes matches the v1.0.0 table exactly, and all six rows I listed were changed in v1.0.1 (they stay the same in v1.1.0-rc). So this is a 1.0 vs 1.0.1 difference rather than a bug against 1.0, and the TCK test is checking the newer codes.

    When 1.1 support starts, I'd be glad to take the error-mapping part of the compat layer: choose the HTTP and gRPC codes from the version VersionRouter resolves, so A2A-Version: 1.0 keeps today's codes and 1.1 gets the new table, with tests for both versions. Should I wait for a 1.1 tracking issue, or is this one the place to hang it on?

  4. kabir commented on Nov 9, 2026

    @kabir
    Collaborator

    I've opened #1303, and done some preliminary investigation into how to do this in the branch linked from the issue. Note this is just me putting an agent onto it. I've not evaluated yet what it said. I will get back to this later this week

  5. ravismash commented on Nov 9, 2026

    @ravismash

    Thanks, that makes sense. I diffed the spec tags: the current A2AErrorCodes matches the v1.0.0 table exactly, and all six rows I listed were changed in v1.0.1 (they stay the same in v1.1.0-rc). So this is a 1.0 vs 1.0.1 difference rather than a bug against 1.0, and the TCK test is checking the newer codes.

    When 1.1 support starts, I'd be glad to take the error-mapping part of the compat layer: choose the HTTP and gRPC codes from the version VersionRouter resolves, so A2A-Version: 1.0 keeps today's codes and 1.1 gets the new table, with tests for both versions. Should I wait for a 1.1 tracking issue, or is this one the place to hang it on?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions