fix: return UnsupportedOperationError (-32004) when streaming is not supported - #1041
fix: return UnsupportedOperationError (-32004) when streaming is not supported#1041ez-lbz wants to merge 2 commits into
Conversation
kabir
left a comment
There was a problem hiding this comment.
Hi @ez-lbz thanks! A few small issues.
Also, there is a pre-existing spec mismatch on gRPC status code. The A2A spec table (section 5.4) maps UnsupportedOperationError to gRPC FAILED_PRECONDITION, but A2AErrorCodes.UNSUPPORTED_OPERATION in this SDK maps it to UNIMPLEMENTED.
The PR's test correctly asserts UNIMPLEMENTED based on the SDK's current mapping, so this is consistent internally — but the SDK itself diverges from the spec on this particular gRPC status. This is not introduced by this PR, just something Claude found.
I've opened #1051 to address this latter part.
So if you just add the strings to the error constructor calls we should be good :-)
| StreamObserver<org.a2aproject.sdk.grpc.StreamResponse> responseObserver) { | ||
| if (!getAgentCardInternal().capabilities().streaming()) { | ||
| handleError(responseObserver, new InvalidRequestError()); | ||
| handleError(responseObserver, new UnsupportedOperationError()); |
There was a problem hiding this comment.
Maybe here pass in "Streaming is not supported by the agent" like for the other transports?
| StreamObserver<org.a2aproject.sdk.grpc.StreamResponse> responseObserver) { | ||
| if (!getAgentCardInternal().capabilities().streaming()) { | ||
| handleError(responseObserver, new InvalidRequestError()); | ||
| handleError(responseObserver, new UnsupportedOperationError()); |
There was a problem hiding this comment.
Maybe here pass in "Streaming is not supported by the agent" like for the other transports?
…orts The JSON-RPC and REST transports report 'Streaming is not supported by the agent' when the agent card does not advertise streaming; the gRPC transport used the bare default message. Use the same message in sendStreamingMessage and subscribeToTask.
|
Thanks! Both gRPC error constructors now pass the same |
What changed
1. Streaming-not-supported now returns
UnsupportedOperationError(-32004) instead ofInvalidRequestError(-32600)Problem: When the agent card does not advertise
streaming()capability, the JSON-RPC, gRPC, and REST handlers rejected streaming calls withInvalidRequestError(code -32600, "invalid request"), while other SDKs returnUnsupportedOperationError(code -32004, "operation not supported"). -32600 is the wrong semantic for a valid-but-unavailable operation and diverges from the other SDKs.Fix (transport/jsonrpc/src/main/java/org/a2aproject/sdk/transport/jsonrpc/handler/JSONRPCHandler.java):
onMessageSendStreamandonSubscribeToTasknow emitnew UnsupportedOperationError(null, "Streaming is not supported by the agent", null)(message preserved, code now -32004). Removed the now-unusedInvalidRequestErrorimport.Fix (transport/grpc/src/main/java/org/a2aproject/sdk/transport/grpc/handler/GrpcHandler.java):
sendStreamingMessageandsubscribeToTasknow callhandleError(responseObserver, new UnsupportedOperationError()); the gRPC status therefore maps fromINVALID_ARGUMENTtoUNIMPLEMENTED. Updated the method javadoc accordingly.Fix (transport/rest/src/main/java/org/a2aproject/sdk/transport/rest/handler/RestHandler.java):
sendStreamingMessageandsubscribeToTasknow build the error response withnew UnsupportedOperationError(null, "Streaming is not supported by the agent", null). HTTP status stays 400; the error reason changes fromINVALID_REQUESTtoUNSUPPORTED_OPERATION(viaA2AErrorCodes.UNSUPPORTED_OPERATION).Fix (tests updated in lockstep):
JSONRPCHandlerTest(testStreamingNotSupportedErrorOnSendMessageStream,testStreamingNotSupportedErrorOnSubscribeToTask): assertUnsupportedOperationErrorinstead ofInvalidRequestError.GrpcHandlerTest(testStreamingNotSupportedError,testStreamingNotSupportedErrorOnSubscribeToTask): assert gRPCStatus.Code.UNIMPLEMENTEDinstead ofINVALID_ARGUMENT.RestHandlerTest(testSendStreamingMessageNotSupported): assert reasonUNSUPPORTED_OPERATIONinstead ofINVALID_REQUEST.Behavior change: the JSON-RPC error code for streaming-not-supported changes from -32600 to -32004; the gRPC status changes from INVALID_ARGUMENT to UNIMPLEMENTED; the REST error reason changes from INVALID_REQUEST to UNSUPPORTED_OPERATION (HTTP status remains 400). The error message is unchanged.
Note: the
compat-0.3module (legacy 0.3-spec compatibility shim) has its own copies of the handlers withInvalidRequestErrorfor this path; it was intentionally left unchanged as it is outside the scope of the current transports.Testing
mvn -pl transport/jsonrpc,transport/grpc,transport/rest test— 124 tests run, 0 failures, 1 skipped (BUILD SUCCESS): JSON-RPC 48 (1 skipped), gRPC 40, REST 36.