Repository navigation
fix(grpc): keep status details and the gRPC code in client errors - #508
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
muscariello
left a comment
There was a problem hiding this comment.
Thanks for this. The decode logic and the round-trip tests are solid, and keeping the gRPC <Code>: prefix only for statuses that nothing maps is the right call. Two changes before merging, both to make gRPC errors match what the JSON-RPC and REST clients and a2a-go already do.
1. Fold BadRequest violations into the message, as the other clients do
a2a_error_from_details (a2a-client/src/lib.rs) is what the JSON-RPC and REST clients run. It appends field: description for each violation to the message, and promotes INTERNAL_ERROR to INVALID_PARAMS when a BadRequest is present. With this PR the same server error reads invalid message over gRPC and invalid message: message.parts: at least one part is required over JSON-RPC and REST. Fixing that later would change the message text a second time.
Suggestion: move that helper into the a2a crate next to error_reason and reason_to_error_code (both clients and a2a-grpc already depend on a2a), and call it from status_to_a2a_error. test_status_details_round_trip_to_a2a_error then asserts the folded message, and a test that all three transports give the same message for one A2AError would pin the parity.
2. Decode google.protobuf.Struct details
a2a-go's gRPC server sends every typed detail other than ErrorInfo, BadRequest included, as a google.protobuf.Struct. Its client decodes ErrorInfo and every Struct (internal/grpcutil/errors.go, FromGRPCError). Details from a Go server therefore arrive as a Struct, which this PR drops. TypedDetail::from_struct and STRUCT_TYPE already model this, and a2a-pb already has from_proto_struct. Read the raw details as a google.rpc.Status and turn each Any of type google.protobuf.Struct into TypedDetail::from_struct.
The other half is a2a_error_to_status, which encodes only ErrorInfo and BadRequest, so a custom detail set on a Rust server never reaches a gRPC client. Encoding the rest as Struct, as a2a-go does, makes the round trip match. That can be a follow-up if you'd rather keep this PR on the client. In that case please drop "lossless" from the description, since it isn't true for those details yet.
Smaller, not blocking
- Tests: a foreign-domain
ErrorInfoon an unmapped code (should keep both the details and the prefix),BadRequestalone, and one case through a real tonic client and server ina2a-grpc/tests/e2e.rs. - Add a line to the rustdoc of
status_to_a2a_errordescribing the details and the prefix. RetryInfoand the othergoogle.rpcdetail types are dropped too. Neither a2a-go nor this PR handles them, so that can wait for a separate issue.
ae92900 to
c54e255
Compare
`status_to_a2a_error` built the client-side `A2AError` from the status code and message alone. The `google.rpc.ErrorInfo`, `BadRequest` and `google.protobuf.Struct` details a server attaches (reason, domain, metadata, field violations, a2a-go's custom details) were dropped, and a status with no A2A counterpart (UNAUTHENTICATED, PERMISSION_DENIED, UNAVAILABLE, ...) became a bare INTERNAL_ERROR whose message no longer said which gRPC code the server sent. Read the raw `google.rpc.Status` details into `A2AError::details` and build the error with `a2a_error_from_details`, the helper the JSON-RPC and REST clients already use, moved from a2a-client into the a2a crate: the protocol-domain ErrorInfo reason selects the code, BadRequest violations are folded into the message as `field: description`, and a BadRequest promotes a bare INTERNAL_ERROR to INVALID_PARAMS. The helper now gives the same answer whatever order the details arrive in (tonic puts ErrorInfo before BadRequest, the JSON-RPC and REST servers put it last). When no A2A error maps to the status, keep INTERNAL_ERROR and prefix the message with the gRPC code, the way the JSON-RPC and REST clients report an HTTP status they cannot map. Co-Authored-By: Claude Mythos 5.1 <[email protected]> Signed-off-by: gulldan <[email protected]>
c54e255 to
6ceec0b
Compare
|
Thanks for the review. Both changes are in, as one commit rebased on
Also added: the foreign-domain |
muscariello
left a comment
There was a problem hiding this comment.
Thanks, both changes are in and the parity test pins them. Approving.
Worth a line in the squash message: the shared helper now moves into a2a (two new public functions), and the ErrorInfo reason always wins over the BadRequest promotion. That only differs from before when an ErrorInfo with reason INTERNAL_ERROR arrives ahead of a BadRequest.
The server-side Struct encoding and the other google.rpc detail types are fine as follow-ups.
…a2aproject#516) The README and a comment said gRPC and SLIMRPC drop error details, so a failure the agent reports would be retried there until --timeout. The gRPC client keeps them since a2aproject#508, and a2acli speaks only JSON-RPC and REST: the SLIMRPC plugin belongs to the Go CLI, so neither applies. Signed-off-by: Luca Muscariello <[email protected]>
Fixes #507.
Problem
status_to_a2a_errorbuilt the client-sideA2AErrorfrom the status code and message alone. Thegoogle.rpc.ErrorInfoandBadRequestdetails thata2a_error_to_statusattaches on the server (reason, domain, metadata, field violations) and thegoogle.protobuf.Structdetails an a2a-go server sends were dropped, and a status with no A2A counterpart (UNAUTHENTICATED,PERMISSION_DENIED,UNAVAILABLE, ...) became a bareINTERNAL_ERRORwhose message no longer said which gRPC code the server sent.Fix
google.rpc.Statusdetails and keepErrorInfo,BadRequestandgoogle.protobuf.StructinA2AError::detailsasTypedDetails (error_info,bad_request,from_struct), in wire order.ErrorInfowithout metadata is written without ametadatakey, matchingTypedDetail::error_info.a2a_error_from_details, the helper the JSON-RPC and REST clients already use, moved froma2a-clientinto thea2acrate next toerror_reason/reason_to_error_code. The protocol-domainErrorInforeason selects the code,BadRequestviolations are folded into the message asfield: description, and aBadRequestpromotes a bareINTERNAL_ERRORtoINVALID_PARAMS. The helper now gives the same answer whatever order the details arrive in: tonic putsErrorInfobeforeBadRequest, the JSON-RPC and REST servers put it last, and the old loop let the later detail win. For the JSON-RPC and REST clients this changes nothing (their servers always sendErrorInfolast, so its reason already won); the reason lookup isprotocol_error_code, shared with the gRPC decoder.ErrorInforeason nor the gRPC code maps to an A2A error, keepINTERNAL_ERRORbut prefix the message with the gRPC code (gRPC Unauthenticated: no credentials), the way the JSON-RPC and REST clients report an HTTP status they cannot map (fix(client): report the HTTP status of a non-JSON-RPC error response #406).The mapped cases (
NOT_FOUND,FAILED_PRECONDITION,UNIMPLEMENTED,INVALID_ARGUMENT,INTERNAL, and any protocol-domainErrorInforeason) keep their code; the message gains the folded violations when aBadRequestis present.Not in this PR:
a2a_error_to_statusstill encodes onlyErrorInfoandBadRequest, so a custom detail set on a Rust server does not reach a gRPC client yet; encoding the rest asStruct, as a2a-go does, is a follow-up.RetryInfoand the othergoogle.rpcdetail types are still dropped on decode.Tests
test_status_details_round_trip_to_a2a_error:ErrorInfometadata andBadRequestfield violations survivea2a_error_to_status→status_to_a2a_error, and the message carries the folded violation.test_grpc_gives_the_same_error_as_the_jsonrpc_client: oneA2AError(INTERNAL_ERROR+BadRequest) througha2a_error_to_status→status_to_a2a_errorand throughto_jsonrpc_error→ the JSON-RPC client's decode gives the same code and message. The REST client runs the same helper on the same details.test_foreign_error_info_on_an_unmapped_code_keeps_the_detail_and_the_prefix,test_bad_request_alone_folds_into_the_message,test_struct_details_are_decoded_like_a2a_go_sends_them,test_error_info_without_metadata_round_trips_without_a_metadata_key,test_transport_status_names_its_grpc_code_in_the_message.grpc_transport_decodes_error_details_from_a_real_serverina2a-grpc/tests/e2e.rs: aTestHandlererror with aBadRequestdetail through a real tonic server andGrpcTransport.test_unknown_status_maps_to_internal_errorupdated to the new message form.On
mainthe round-trip, parity, prefix and e2e tests fail (details areNone; message"no credentials"). Full CI mirror (lockfile, check, fmt, clippy with-D warnings, tests): 949 tests pass. Patch coverage: 267 lines changed, 0 uncovered.Overlap
None known. Touches
a2a-grpc/src/errors.rs, the moved helper ina2a/src/errors.rs(callers ina2a-clientswitched toa2a::a2a_error_from_details), and the gRPC e2e test. The server-side mapping is untouched.🤖 Generated with Claude Code