Repository navigation
fix(client): map invalid gRPC status details trailers to A2AClientError - #1551
Open
ShivamSharma43 wants to merge 2 commits into
Open
ShivamSharma43 wants to merge 2 commits into
ShivamSharma43 wants to merge 2 commits into
Conversation
`status_from_call` raises `ValueError` when the code or message in the `grpc-status-details-bin` trailer does not match the call's status, and protobuf raises `DecodeError` when the trailer bytes are not a valid `google.rpc.Status`. `_map_grpc_error` in the gRPC client and the v0.3 compat gRPC client called it without handling either, so callers got the raw parsing error instead of an `A2AClientError` chained to the `AioRpcError`. Log the invalid trailer and fall back to the generic `A2AClientError` mapping, as for a call without status details. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/client/transports/grpc.py | 93.75% | 93.92% | 🟢 +0.17% |
| src/a2a/compat/v0_3/grpc_transport.py | 88.27% | 88.55% | 🟢 +0.28% |
| Total | 94.27% | 94.27% | ⚪️ 0.00% |
Generated by coverage-comment.yml
This branch has not been deployed
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.
Description
_map_grpc_errorin the gRPC client (src/a2a/client/transports/grpc.py) and in the v0.3 compat gRPC client (src/a2a/compat/v0_3/grpc_transport.py) callsa2a.utils.grpc_status.status_from_callto read thegrpc-status-details-bintrailer. That call can raise:ValueErrorwhen the trailer'scodeormessagedoes not match the call's status code / details (status_from_callchecks both), andgoogle.protobuf.message.DecodeErrorwhen the trailer bytes are not a validgoogle.rpc.Status.Neither was handled, so the caller got the raw parsing error instead of an SDK error, and the original
AioRpcErrorwas lost from the chain. This can happen when something between client and server (a proxy or gateway) rewrites the status message or code but forwards the trailer, or when a server sends a malformed trailer.grpc-status-details-bintrailerA2AClientErrorValueError: Mismatched status code ...A2AClientError, chained to theAioRpcErrorValueError: Mismatched status message ...A2AClientError, chained to theAioRpcErrorgoogle.rpc.StatusDecodeError: Error parsing message ...A2AClientError, chained to theAioRpcErrorFix
In both
_map_grpc_errorfunctions,ValueErrorandDecodeErrorfromstatus_from_callare caught, logged at warning level with the traceback, and treated as "no status details", so the existing genericA2AClientError(f'gRPC Error {code}: {details}')path runs.status_from_callitself is not changed and stays strict; its existing tests intests/utils/test_grpc_status.pystill pass.Note: #1522 (open) also edits
_map_grpc_errorin the v0.3 compat transport. The compat change here is the same few lines wrapped around thestatus_from_callcall, so if that PR merges first, a rebase should be straightforward.Tests
test_grpc_invalid_status_details_raise_client_errorintests/client/transports/test_grpc_client.pyandtest_compat_grpc_error_invalid_status_details_stays_client_errorintests/compat/v0_3/test_grpc_transport.py, each parametrized over a mismatched code, a mismatched message, and malformed trailer bytes. They check thatA2AClientErroritself is raised (not a subclass) and that__cause__is the originalAioRpcError. All 6 fail on main (withValueError/DecodeError) and pass with the fix.pytest tests/client/transports/test_grpc_client.py tests/client/transports/test_grpc_error_metadata.py tests/compat/v0_3/test_grpc_transport.py tests/utils/test_grpc_status.py: 74 passed.ruff checkandruff format --checkpass on the changed files;ty checkpasses on the two changed source files.I did not run the full test suite.
This PR was prepared with AI assistance (Claude Code).
CONTRIBUTINGGuide.bash scripts/format.shfrom the repository root to format)🤖 Generated with Claude Code