fix: return UnsupportedOperationError when subscribing to terminal tasks by kabir · Pull Request #784 · a2aproject/a2a-java · GitHub
Skip to content

fix: return UnsupportedOperationError when subscribing to terminal tasks - #784

Merged
ehsavoie merged 2 commits into
a2aproject:mainfrom
kabir:issue-767
Apr 10, 2026
Merged

ehsavoie merged 2 commits into
a2aproject:mainfrom
kabir:issue-767

Conversation

@kabir

@kabir kabir commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Per A2A spec, attempting to subscribe to a task in a terminal state (completed, failed, canceled, rejected) must return UnsupportedOperationError.

The issue had two parts:

  1. DefaultRequestHandler checked terminal state AFTER queue operations began, causing errors to be delivered via SSE stream instead of immediately.

  2. For streaming endpoints (subscribeToTask), immediate errors must be wrapped in SSE format so the client's SSE parser can process them and deliver to the error handler callback. Previously they were sent as plain JSON/HTTP responses which the SSE parser couldn't handle.

Changes:

  • Move terminal state validation BEFORE queue operations in DefaultRequestHandler
  • Wrap all immediate errors in SSE format for JSON-RPC routing layer
  • Wrap all immediate errors in SSE format for REST transport
  • Add integration test to verify fix across all three transports

Applied to HTTP+JSON, JSON-RPC, and gRPC transports.

Fixes #767

Per A2A spec, attempting to subscribe to a task in a terminal state
(completed, failed, canceled, rejected) must return UnsupportedOperationError.

The issue had two parts:

1. DefaultRequestHandler checked terminal state AFTER queue operations began,
   causing errors to be delivered via SSE stream instead of immediately.

2. For streaming endpoints (subscribeToTask), immediate errors must be wrapped
   in SSE format so the client's SSE parser can process them and deliver to
   the error handler callback. Previously they were sent as plain JSON/HTTP
   responses which the SSE parser couldn't handle.

Changes:
- Move terminal state validation BEFORE queue operations in DefaultRequestHandler
- Wrap all immediate errors in SSE format for JSON-RPC routing layer
- Wrap all immediate errors in SSE format for REST transport
- Add integration test to verify fix across all three transports

Applied to HTTP+JSON, JSON-RPC, and gRPC transports.

Fixes a2aproject#767

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request improves error handling for streaming requests by ensuring that attempts to subscribe to tasks in terminal states result in an UnsupportedOperationError, as per the A2A specification. The changes include updates to the routing and handler layers to correctly propagate these errors as SSE events or JSON-RPC error responses, along with a new test case to verify the behavior. A review comment suggests using String.format() for error messages in DefaultRequestHandler.java to improve code consistency.

@ehsavoie
ehsavoie merged commit 8f31f87 into a2aproject:main Apr 10, 2026
13 of 14 checks passed
@ehsavoie

Copy link
Copy Markdown
Collaborator

salaboy pushed a commit to salaboy/a2a-java that referenced this pull request Jun 19, 2026
…sks (a2aproject#784)

Per A2A spec, attempting to subscribe to a task in a terminal state
(completed, failed, canceled, rejected) must return
UnsupportedOperationError.

The issue had two parts:

1. DefaultRequestHandler checked terminal state AFTER queue operations
began, causing errors to be delivered via SSE stream instead of
immediately.

2. For streaming endpoints (subscribeToTask), immediate errors must be
wrapped in SSE format so the client's SSE parser can process them and
deliver to the error handler callback. Previously they were sent as
plain JSON/HTTP responses which the SSE parser couldn't handle.

Changes:
- Move terminal state validation BEFORE queue operations in
DefaultRequestHandler
- Wrap all immediate errors in SSE format for JSON-RPC routing layer
- Wrap all immediate errors in SSE format for REST transport
- Add integration test to verify fix across all three transports

Applied to HTTP+JSON, JSON-RPC, and gRPC transports.

Fixes a2aproject#767

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SubscribeToTask on terminal task returns TaskNotFoundError instead of UnsupportedOperationError

2 participants