Skip to content

SubscribeToTask on terminal task returns error inside stream instead of direct error response (STREAM-SUB-003) #791

Closed

Description

@jmesnil

What happened?

Summary

When SubscribeToTask is called on a task in a terminal state, the SUT opens a stream and delivers the UnsupportedOperationError inside it instead of returning a direct error response. Since the server knows upfront that the task cannot be subscribed to, it should reject the request immediately.

Requirement

Specification

Errors:

  • UnsupportedOperationError: The operation is attempted on a task that is in a terminal state (completed, failed, canceled, or rejected).

And from Section 9.4.6:

Error: Returns UnsupportedOperationError if the task is in a terminal state (completed, failed, canceled, or rejected).

Expected behavior

When SubscribeToTask is called on a task already in a terminal state, the server should return an immediate error response (not open a stream), since it knows upfront that the subscription is invalid.

JSON-RPC — expected: Direct JSON-RPC error response:

{
  "jsonrpc": "2.0",
  "id": 3,
  "error": {
    "code": -32004,
    "message": "Cannot subscribe to task - task is in terminal state"
  }
}

HTTP+JSON — expected: 400 Bad Request with an error body (no SSE stream).

gRPC — expected: Immediate UNIMPLEMENTED status code without opening the stream.

Actual behavior

All three transports open a stream and deliver the error inside it:

JSON-RPC — actual: HTTP 200 with SSE stream containing error event:

: SSE stream started

data: {"jsonrpc":"2.0","id":3,"error":{"code":-32004,"message":"Cannot subscribe to task ... - task is in terminal state: TASK_STATE_COMPLETED"}}
id: 0

HTTP+JSON — actual: HTTP 200 with SSE stream containing error event:

: SSE stream started

data: {"error":{"code":400,"status":"UNIMPLEMENTED","message":"Cannot subscribe to task ... - task is in terminal state: TASK_STATE_COMPLETED","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"UNSUPPORTED_OPERATION","domain":"a2a-protocol.org","metadata":{}}]}}
id: 0

gRPC — actual: Stream opens, then terminates with UNIMPLEMENTED status during iteration:

grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
    status = StatusCode.UNIMPLEMENTED
    details = "Cannot subscribe to task ... - task is in terminal state: TASK_STATE_COMPLETED"
>

Reproducer

# Step 1: Create a task that completes immediately
curl -s -X POST http://localhost:9999 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc":"2.0","id":1,"method":"SendMessage",
    "params":{"message":{"role":"ROLE_USER","parts":[{"text":"TCK prerequisite"}],"messageId":"tck-complete-task-repro-001"}}
  }'
# Note the task ID from result.task.id

# Step 2: Verify the task is in a terminal state
TASK_ID="<task-id-from-step-1>"
curl -s -X POST http://localhost:9999 \
  -H "Content-Type: application/json" \
  -d "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"GetTask\",\"params\":{\"id\":\"$TASK_ID\"}}"
# Confirm status.state is TASK_STATE_COMPLETED

# Step 3: SubscribeToTask on the terminal task
# Expected: direct JSON-RPC error response with code -32004
# Actual: SSE stream opens (HTTP 200) and error is delivered as a stream event
curl -s -X POST http://localhost:9999 \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"SubscribeToTask\",\"params\":{\"id\":\"$TASK_ID\"}}"

TCK test

  • tests/compatibility/core_operations/test_task_lifecycle.py::TestSubscribeLifecycle::test_subscribe_rejects_terminal_task[grpc]
  • tests/compatibility/core_operations/test_task_lifecycle.py::TestSubscribeLifecycle::test_subscribe_rejects_terminal_task[jsonrpc]
  • tests/compatibility/core_operations/test_task_lifecycle.py::TestSubscribeLifecycle::test_subscribe_rejects_terminal_task[http_json]

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added this to the 1.0.0 milestone on Apr 13, 2026
  2. added theissue type on Apr 13, 2026
  3. added
    compatibility
    on Apr 13, 2026
  4. jmesnil commented on Apr 13, 2026

    @jmesnil
    ContributorAuthor

    This issue is a bit ambiguous. Currently the error is delivered by the event stream and not the HTTP response to the SubscribeToTask operation.
    It's not 100% clear from the spec where the error should be returned.
    I think returning the error in the HTTP response makes sense since the remote agent knows from the get go that it is not correct to subscribe to a terminal task.

  5. ehsavoie commented on Apr 13, 2026

    @ehsavoie
    Collaborator

    @jmesnil I'm wondering about this behaviour as for STREAM-SUB-004 you are expecting the TaskNotFound error to be in the stream

  6. jmesnil commented on Apr 13, 2026

    @jmesnil
    ContributorAuthor

    @ehsavoie what do you mean? The test for STREAM-SUB-004 is at https://github.com/a2aproject/a2a-tck/blob/1f9f4a21ac9bb53341a2292007b423f32c56d724/tests/compatibility/jsonrpc/test_sse_streaming.py#L172.
    It looks for either the error in the HTTP response or the event stream.
    Depending on the resolution of #791, the test for STREAM-SUB-004 would have to be updated to look for a consistent place for the error. I can also open a spec issue to clarify any ambiguity

  7. jmesnil commented on Apr 14, 2026

    @jmesnil
    ContributorAuthor

    Actually, the spec is not ambiguous about this.
    In https://a2a-protocol.org/latest/specification/#316-subscribe-to-task, it says that the output of SubscribeToTask is:

    • Stream Response object containing:
      - Initial response: Task object with current state
      - Stream of TaskStatusUpdateEvent and TaskArtifactUpdateEvent objects

    A StreamResponse can not contain an error. This means that the error MUST be returned by the HTTP response (and the stream is never open in that case)

  8. added 5 commits that reference this issue on Apr 15, 2026
    a3a2982
    12295da
    971569a
    60b9261
    cc27228
  9. added a commit that references this issue on Jun 19, 2026
    cef2cf8
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

    compatibility

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions