Skip to content

fix(client): map invalid gRPC status details trailers to A2AClientError - #1551

Open
ShivamSharma43 wants to merge 2 commits into
a2aproject:mainfrom
ShivamSharma43:fix/grpc-status-mismatch
Open

ShivamSharma43 wants to merge 2 commits into
a2aproject:mainfrom
ShivamSharma43:fix/grpc-status-mismatch

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

_map_grpc_error in 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) calls a2a.utils.grpc_status.status_from_call to read the grpc-status-details-bin trailer. That call can raise:

  • ValueError when the trailer's code or message does not match the call's status code / details (status_from_call checks both), and
  • google.protobuf.message.DecodeError when the trailer bytes are not a valid google.rpc.Status.

Neither was handled, so the caller got the raw parsing error instead of an SDK error, and the original AioRpcError was 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-bin trailer Before After
valid, matches the call mapped A2A error unchanged
absent A2AClientError unchanged
code differs from the call's code ValueError: Mismatched status code ... A2AClientError, chained to the AioRpcError
message differs from the call's details ValueError: Mismatched status message ... A2AClientError, chained to the AioRpcError
not a valid google.rpc.Status DecodeError: Error parsing message ... A2AClientError, chained to the AioRpcError

Fix

In both _map_grpc_error functions, ValueError and DecodeError from status_from_call are caught, logged at warning level with the traceback, and treated as "no status details", so the existing generic A2AClientError(f'gRPC Error {code}: {details}') path runs. status_from_call itself is not changed and stays strict; its existing tests in tests/utils/test_grpc_status.py still pass.

Note: #1522 (open) also edits _map_grpc_error in the v0.3 compat transport. The compat change here is the same few lines wrapped around the status_from_call call, so if that PR merges first, a rebase should be straightforward.

Tests

  • test_grpc_invalid_status_details_raise_client_error in tests/client/transports/test_grpc_client.py and test_compat_grpc_error_invalid_status_details_stays_client_error in tests/compat/v0_3/test_grpc_transport.py, each parametrized over a mismatched code, a mismatched message, and malformed trailer bytes. They check that A2AClientError itself is raised (not a subclass) and that __cause__ is the original AioRpcError. All 6 fail on main (with ValueError / 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 check and ruff format --check pass on the changed files; ty check passes on the two changed source files.

I did not run the full test suite.

This PR was prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

`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>
@ShivamSharma43
ShivamSharma43 requested a review from a team as a code owner November 29, 2026 12:46
Copilot AI balanced review requested due to automatic review settings November 29, 2026 12:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

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

@mykytanetipa mykytanetipa self-assigned this Nov 30, 2026

This branch has not been deployed

No deployments
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.

3 participants