Skip to content

fix(jsonrpc): don't open a stream when streaming is not supported - #1356

Merged
kabir merged 2 commits into
a2aproject:mainfrom
Shay-Deng:fix/jsonrpc-streaming-capability-error
Nov 25, 2026
Merged

kabir merged 2 commits into
a2aproject:mainfrom
Shay-Deng:fix/jsonrpc-streaming-capability-error

Conversation

@Shay-Deng

Copy link
Copy Markdown
Contributor

Description

When the agent card doesn't support streaming, a JSON-RPC SendStreamingMessage or SubscribeToTask gets HTTP 200 with an SSE stream whose only event is the error:

HTTP/1.1 200 OK
content-type: text/event-stream

: SSE stream started

data: {"jsonrpc":"2.0","id":"s1","error":{"code":-32004,"message":"Streaming is not supported by the agent",...}}

Section 3.3.4 says these calls MUST return UnsupportedOperationError. In #791, the same question came up for SubscribeToTask on a terminal task, and the conclusion was that a StreamResponse can't carry an error, so an error known up front has to come back without opening a stream. RestHandler already does this for the capability check, and the gRPC binding passes the same check. JSON-RPC is the only binding here that still opens the stream.

It shows up as ACTS CORE-CAP-002 (SHOULD), the only failure in the a2a-java nightly: expected an error, but the stream opened and produced 1 event(s), on JSON-RPC only.

Changes:

  • JSONRPCHandler.onMessageSendStream / onSubscribeToTask throw the UnsupportedOperationError from the streaming preflight instead of wrapping it in a one-item publisher. Other preflight errors still go into the stream, which matches RestHandler, where only UnsupportedOperationError is caught and returned as a plain response.
  • A2AServerRoutes.processStreamingRequest no longer turns an error thrown by the handler into a stream item. The error reaches invokeJSONRPCHandler, which writes the usual JSON-RPC error response.
  • invokeJSONRPCHandler now uses the request id for an A2AError thrown after the request was parsed. It used new A2AErrorResponse(e), so the id was null; that already applied to errors from authorizeTaskAccess on the streaming path. Errors thrown while parsing still have a null id.

With the change:

HTTP/1.1 200 OK
content-type: application/json

{"jsonrpc":"2.0","id":"s1","error":{"code":-32004,"message":"Streaming is not supported by the agent",...}}

Tests:

  • JSONRPCHandlerTest: testStreamingNotSupportedError, testStreamingNotSupportedErrorOnSubscribeToTask and capabilityErrorsRetainStreamingMessageAndPushErrorType expected the error as the first stream item. They now expect it to be thrown, with the same error type and message.
  • A2AServerRoutesTest: two new tests, one for SendStreamingMessage and one for SubscribeToTask. When the handler throws UnsupportedOperationError, the route answers with a plain JSON-RPC error that keeps the request id.
  • On main these 5 tests fail; with this change they pass.
  • capabilityErrorsRetainStreamingMessageAndPushErrorType came in with refactor!: centralize server validation #1213. If keeping the JSON-RPC capability error inside the stream was intended there, I'm happy to rework this.

Testing:

  • mvn install (JDK 21) for transport/jsonrpc, reference/jsonrpc and reference/multiversion-jsonrpc, after installing their dependencies: 73 tests in transport/jsonrpc (1 skipped, as on main) and 239 in reference/jsonrpc, including the Quarkus JSON-RPC tests. All pass.

  • Full ACTS corpus from a2a-itk main (604239c), all three bindings, against the itk/ agent built from main and from this branch. I ran the agent myself and passed it with --sut-url, plus a second instance with ITK_ACTS_REDUCED_CAPABILITIES=1 as --reduced-sut-url. Of 283 results, the only change is CORE-CAP-002 on JSON-RPC, from fail to pass. The 7 skipped SEC-AUTH-* results are the same on both runs, because I didn't start an ITK_ACTS_AUTH instance.

  • Follow the CONTRIBUTING Guide.

  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.

  • Ensure the tests pass

  • Appropriate READMEs were updated (if necessary)

AI assistance: developed with help from Claude Code. I reviewed the change, and the checks listed under Testing were run locally.

When the agent card does not support streaming, SendStreamingMessage
and SubscribeToTask over JSON-RPC answered HTTP 200 with an SSE stream
whose only event was the UnsupportedOperationError. RestHandler already
returns that error as a plain response, and as discussed in a2aproject#791, a
StreamResponse cannot carry an error, so an error known before any event
exists is returned without opening a stream.

JSONRPCHandler now throws the preflight UnsupportedOperationError, and
A2AServerRoutes lets an error thrown by the handler propagate, so it is
written as an ordinary JSON-RPC error response that keeps the request
id. Other preflight errors are still sent inside the stream, as in
RestHandler.
@Shay-Deng

Copy link
Copy Markdown
Contributor Author

The build (ubuntu-latest, 25) failure is in V03ResponseIdProbeTest.validatesPreStreamJsonErrors (compat-0.3 client), which this PR doesn't touch. It passed 15 times in a row locally on this branch. The other three build jobs were cancelled when that one failed. Could the failed jobs be re-run when convenient? Thanks!

@kabir

kabir commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Rerunning now!

@redhat-chai-bot redhat-chai-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, well-scoped fix. The JSON-RPC binding was the last transport to open a stream before reporting UnsupportedOperationError — the REST handler already returns a plain error response, and gRPC does the equivalent. Aligning all three transports and fixing the ACTS CORE-CAP-002 conformance failure makes sense.

What I like:

  • Selective re-throw design. Only UnsupportedOperationError escapes the handler as a thrown exception; other A2AError subtypes from preflight() are still wrapped in a one-item stream. That's the right call — "this operation is fundamentally unsupported" is categorically different from a runtime failure that happens to occur during preflight, and it matches how RestHandler already treats it.
  • Request-ID fix. The invokeJSONRPCHandler change to preserve the request ID in the A2AErrorResponse is a good bonus — previously any A2AError thrown after successful request parsing would produce a null ID, which breaks the JSON-RPC contract (id MUST echo the request ID on error responses that correlate to a request).
  • Test quality. The route-level tests in A2AServerRoutesTest verify the full HTTP response shape (content-type application/json, correct ID, correct error code/message), and the handler-level tests in JSONRPCHandlerTest are dramatically simplified by switching from verbose Flow.Subscriber boilerplate to assertThrows. Net -9 lines despite adding new test coverage.

Minor observations — no changes needed:

  • In processStreamingRequest, removing the try-catch means that any A2AError thrown by onMessageSendStream / onSubscribeToTask would now propagate up to invokeJSONRPCHandler as a plain error. That's safe today because both methods only re-throw UnsupportedOperationError and catch everything else internally. If a future change to those methods introduces a new thrown A2AError after preflight(), it would also bypass the stream. Worth keeping in mind, but not a problem here — the comment in the diff documents the design intent clearly.
  • The throws A2AError on the method signatures is a contract change. Since JSONRPCHandler is an internal SDK class (not part of the public SPI), this shouldn't break downstream consumers — just noting it for the changelog.

Looks good overall. The CI re-run is in progress (10/14 checks passed, 4 builds running); the previous failure was an unrelated flaky test in V03ResponseIdProbeTest.


Chai persona: A2A Java SDK

AI-generated. Review for accuracy.

SendStreamingMessageRequest request, ServerCallContext context) {
SendStreamingMessageRequest request, ServerCallContext context) throws A2AError {
String tenant = request.getParams() != null ? request.getParams().tenant() : null;
EffectiveAgentCard effective;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean separation: UnsupportedOperationError is re-thrown to avoid opening a stream, while other A2AError subtypes stay as stream items. This matches RestHandler's behavior where only UnsupportedOperationError is caught and returned as a plain response.

Nit: the catch (Throwable throwable) on line 325 is new to this method — it wasn't there before the refactor. That's fine (defensive), but the existing onSubscribeToTask doesn't have the same Throwable catch for preflight. Intentional asymmetry, or just not needed there because onSubscribeToTask's preflight was already structured with a try-catch?


Chai persona: A2A Java SDK

AI-generated. Review for accuracy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for re-running the jobs, @kabir! I looked into this one.

The catch (Throwable) here isn't new: on main, preflight sits inside this method's single try, which already ends with catch (Throwable). I only split preflight into its own try so that UnsupportedOperationError can be rethrown, and kept that catch.

The asymmetry was already there in onSubscribeToTask, whose preflight try catches only A2AError. It's the only preflight call in JSONRPCHandler without a catch (Throwable), and RestHandler has one around preflight in both sendStreamingMessage and subscribeToTask. So when preflight throws something else, for example the IllegalStateException from AgentCardValidator when the card lists a transport that isn't on the classpath, SendStreamingMessage gets an InternalError inside the stream with the request id, while SubscribeToTask falls through to the catch (Throwable) in A2AServerRoutes.invokeJSONRPCHandler and gets a plain InternalError with "id": null.

I pushed d1b2958, which adds the same catch (Throwable) to onSubscribeToTask, plus a test that both streaming methods return an InternalError with the request id when no agent card is configured. If you'd rather keep this PR to the capability error, I'm happy to drop that commit and open it separately.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch — you're right that the catch (Throwable) was already there on main inside the single try; splitting it out just made it more visible. My mistake calling it new.

And nice find on the real asymmetry in onSubscribeToTask. The IllegalStateException from AgentCardValidator is a good concrete example — SendStreamingMessage would surface it as an InternalError with the request ID in the stream, while SubscribeToTask would let it escape to invokeJSONRPCHandler with a null ID. Adding the matching catch (Throwable) there makes sense to me, and including it in this PR keeps the two methods consistent in one diff.


Chai persona: A2A Java SDK

AI-generated. Review for accuracy.

} catch (A2AError e) {
error = new A2AErrorResponse(e);
error = request == null ? new A2AErrorResponse(e) : new A2AErrorResponse(request.getId(), e);
} catch (InvalidParamsJsonMappingException e) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix. Before this, any A2AError thrown after the request was successfully parsed would produce a null ID in the response — the ternary handles both the parsing-failure case (request is null → null ID) and the handler-failure case (request parsed → echo the ID) correctly.


Chai persona: A2A Java SDK

AI-generated. Review for accuracy.

@kabir kabir left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shay-Deng Would you be able to look at the nitpick the bot mentions in JSONRPCHandler?

onMessageSendStream reports an unexpected exception from preflight as
an InternalError inside the stream, and RestHandler does the same for
both streaming methods. onSubscribeToTask only caught A2AError there,
so such an exception escaped the handler and the route answered with a
plain InternalError without the request id. Catch Throwable there too.

@redhat-chai-bot redhat-chai-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after d1b2958. The follow-up commit adds the matching catch (Throwable) to onSubscribeToTask's preflight try, plus testNoCardAtAllStreamsInternalErrorForBothStreamingMethods covering both methods. The two streaming handlers are now symmetric in their error handling — both treat UnsupportedOperationError as a re-throw and wrap everything else (A2AError, Throwable) as a stream item with the request ID.

CI is all green (14/14), mergeable, and the previous feedback is addressed. Looks good to me.


Chai persona: A2A Java SDK

AI-generated. Review for accuracy.

@kabir
kabir merged commit ad428e4 into a2aproject:main Nov 25, 2026
14 checks passed
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.

3 participants