fix: return UnsupportedOperationError when subscribing to terminal tasks#784
Open
kabir wants to merge 2 commits intoa2aproject:mainfrom
Open
fix: return UnsupportedOperationError when subscribing to terminal tasks#784kabir wants to merge 2 commits intoa2aproject:mainfrom
kabir wants to merge 2 commits intoa2aproject:mainfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java
Outdated
Show resolved
Hide resolved
…ultRequestHandler.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
ehsavoie
reviewed
Apr 8, 2026
| } catch (A2AError e) { | ||
| return ZeroPublisher.fromItems(new SendStreamingMessageResponse(request.getId(), e)); | ||
| // Let routing layer catch TaskNotFoundError and UnsupportedOperationError to wrap in SSE format | ||
| throw e; |
Collaborator
There was a problem hiding this comment.
Maybe this is a bit agressive if there is an internal error or something 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.
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:
DefaultRequestHandler checked terminal state AFTER queue operations began, causing errors to be delivered via SSE stream instead of immediately.
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:
Applied to HTTP+JSON, JSON-RPC, and gRPC transports.
Fixes #767