fix: return UnsupportedOperationError (-32004) when streaming is not supported - #1041
Open
ez-lbz wants to merge 1 commit into
Open
fix: return UnsupportedOperationError (-32004) when streaming is not supported#1041ez-lbz wants to merge 1 commit into
ez-lbz wants to merge 1 commit into
Conversation
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.
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.