Skip to content

fix(grpc): keep status details and the gRPC code in client errors - #508

Merged
muscariello merged 1 commit into
a2aproject:mainfrom
gulldan:fix/grpc-client-error-mapping
Nov 6, 2026
Merged

muscariello merged 1 commit into
a2aproject:mainfrom
gulldan:fix/grpc-client-error-mapping

Conversation

@gulldan

@gulldan gulldan commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #507.

Problem

status_to_a2a_error built the client-side A2AError from the status code and message alone. The google.rpc.ErrorInfo and BadRequest details that a2a_error_to_status attaches on the server (reason, domain, metadata, field violations) and the google.protobuf.Struct details an a2a-go server sends 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.

Fix

  • Read the raw google.rpc.Status details and keep ErrorInfo, BadRequest and google.protobuf.Struct in A2AError::details as TypedDetails (error_info, bad_request, from_struct), in wire order. ErrorInfo without metadata is written without a metadata key, matching TypedDetail::error_info.
  • 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 next to error_reason / reason_to_error_code. 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, and the old loop let the later detail win. For the JSON-RPC and REST clients this changes nothing (their servers always send ErrorInfo last, so its reason already won); the reason lookup is protocol_error_code, shared with the gRPC decoder.
  • When neither the ErrorInfo reason nor the gRPC code maps to an A2A error, keep INTERNAL_ERROR but 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-domain ErrorInfo reason) keep their code; the message gains the folded violations when a BadRequest is present.

Not in this PR: a2a_error_to_status still encodes only ErrorInfo and BadRequest, so a custom detail set on a Rust server does not reach a gRPC client yet; encoding the rest as Struct, as a2a-go does, is a follow-up. RetryInfo and the other google.rpc detail types are still dropped on decode.

Tests

  • test_status_details_round_trip_to_a2a_error: ErrorInfo metadata and BadRequest field violations survive a2a_error_to_status → status_to_a2a_error, and the message carries the folded violation.
  • test_grpc_gives_the_same_error_as_the_jsonrpc_client: one A2AError (INTERNAL_ERROR + BadRequest) through a2a_error_to_status → status_to_a2a_error and through to_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_server in a2a-grpc/tests/e2e.rs: a TestHandler error with a BadRequest detail through a real tonic server and GrpcTransport.
  • test_unknown_status_maps_to_internal_error updated to the new message form.

On main the round-trip, parity, prefix and e2e tests fail (details are None; 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 in a2a/src/errors.rs (callers in a2a-client switched to a2a::a2a_error_from_details), and the gRPC e2e test. The server-side mapping is untouched.

🤖 Generated with Claude Code

@gulldan
gulldan requested a review from a team as a code owner November 5, 2026 10:12
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 ErrorInfo on an unmapped code (should keep both the details and the prefix), BadRequest alone, and one case through a real tonic client and server in a2a-grpc/tests/e2e.rs.
  • Add a line to the rustdoc of status_to_a2a_error describing the details and the prefix.
  • RetryInfo and the other google.rpc detail types are dropped too. Neither a2a-go nor this PR handles them, so that can wait for a separate issue.

@gulldan
gulldan force-pushed the fix/grpc-client-error-mapping branch 7 times, most recently from ae92900 to c54e255 Compare November 5, 2026 20:01
`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]>
@gulldan
gulldan force-pushed the fix/grpc-client-error-mapping branch from c54e255 to 6ceec0b Compare November 5, 2026 20:02
@gulldan

gulldan commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Both changes are in, as one commit rebased on main:

  1. a2a_error_from_details moved to the a2a crate next to error_reason / reason_to_error_code, and status_to_a2a_error calls it. While doing that I found the helper was order-dependent: it iterated the details in wire order, so a protocol ErrorInfo after a BadRequest overrode the INVALID_PARAMS promotion. The JSON-RPC and REST servers send ErrorInfo last and tonic puts it before BadRequest, so the same INTERNAL_ERROR + BadRequest error decoded to INTERNAL_ERROR over JSON-RPC/REST and INVALID_PARAMS over gRPC. The helper now picks the reason first (protocol_error_code, which the gRPC decoder also uses for the prefix decision) and applies the BadRequest promotion only when no reason gave a code. JSON-RPC and REST results are unchanged by this (their ErrorInfo already won). test_grpc_gives_the_same_error_as_the_jsonrpc_client pins the parity on exactly that error shape.
  2. typed_details reads the raw google.rpc.Status and turns ErrorInfo, BadRequest and google.protobuf.Struct into TypedDetails in wire order; test_struct_details_are_decoded_like_a2a_go_sends_them covers the Struct case. I kept the encoder as is and dropped "lossless" from the description; encoding the other details as Struct in a2a_error_to_status is a follow-up I can open after this lands.

Also added: the foreign-domain ErrorInfo on an unmapped code test, the BadRequest-alone test, an e2e case through a real tonic server (grpc_transport_decodes_error_details_from_a_real_server), and the rustdoc on status_to_a2a_error.

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@muscariello
muscariello added this pull request to the merge queue Nov 6, 2026
Merged via the queue into a2aproject:main with commit 8e72cd4 Nov 6, 2026
22 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 5, 2026
gulldan pushed a commit to gulldan/a2a-rs that referenced this pull request Nov 10, 2026
…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]>
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.

[Bug]: a2a-grpc client drops ErrorInfo/BadRequest details and the gRPC code of unmapped statuses

2 participants