Skip to content

fix(grpc): correct error code mapping and enforce A2A-Version validation - #1167

Open
avilleroy51 wants to merge 2 commits into
a2aproject:mainfrom
avilleroy51:fix/grpc-error-mapping-and-version-validation
Open

fix(grpc): correct error code mapping and enforce A2A-Version validation#1167
avilleroy51 wants to merge 2 commits into
a2aproject:mainfrom
avilleroy51:fix/grpc-error-mapping-and-version-validation

Conversation

@avilleroy51

Copy link
Copy Markdown

Summary

Fixes #1166 — two bugs in the gRPC transport, found while cross-checking grpc_handler.py against specification.md's normative error-code table and against the version-validation behavior already enforced on JSON-RPC/REST.

  1. Wrong error code mapping. PushNotificationNotSupportedError, UnsupportedOperationError and VersionNotSupportedError were mapped to FAILED_PRECONDITION in _ERROR_CODE_MAP. Per specification.md:1178-1192 (the normative A2A-error → gRPC-status table) all three should map to UNIMPLEMENTED.
  2. A2A-Version never validated on gRPC. JSON-RPC and REST dispatchers already enforce version compatibility via @validate_version(PROTOCOL_VERSION_1_0). The gRPC transport had no equivalent — DefaultGrpcServerCallContextBuilder.build() never exposed invocation_metadata() to the rest of the request-handling code, so there was no way for any check to see the caller's declared version. This adds state['headers'] (same shape the HTTP route builders already populate) and a single _validate_a2a_version() check applied where all 11 RPC methods funnel through _build_call_context, replicating validate_version's semantics (missing header ⇒ treated as 0.3; major version must match 1.0).

Test plan

  • tests/server/request_handlers/test_grpc_handler.py alone: 43/43 passed
  • Full suite (excluding tests/integration, tests/install_smoke, tests/compat — out of scope — and modules with pre-existing, unrelated ModuleNotFoundError: respx, opentelemetry, migrations): 997 passed, 0 failed
  • ruff check on both changed files: all checks passed
  • mock_grpc_context fixture now defaults invocation_metadata.return_value to a2a-version: 1.0 (same convention TestClient(..., headers={'A2A-Version': '1.0'}) already uses for JSON-RPC/REST tests)
  • The 2 pre-existing test_abort_context_error_mapping cases that asserted the old FAILED_PRECONDITION mapping updated to UNIMPLEMENTED
  • The 3 TestGrpcExtensions cases that override invocation_metadata updated to include ('a2a-version', '1.0')

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/request_handlers/grpc_handler.py 95.42% 89.20% 🔴 -6.22%
Total 93.00% 92.88% 🔴 -0.12%

Generated by coverage-comment.yml

Three gRPC error mappings diverged from specification.md:1178-1192 (the
normative error-code table): PushNotificationNotSupportedError,
UnsupportedOperationError and VersionNotSupportedError were mapped to
FAILED_PRECONDITION instead of UNIMPLEMENTED.

Separately, the gRPC transport never validated the A2A-Version header at
all — DefaultGrpcServerCallContextBuilder.build() didn't expose invocation
metadata to the rest of the request-handling code, unlike the JSON-RPC/REST
dispatchers which already enforce this via @validate_version. This adds
state['headers'] (mirroring the HTTP route builders) and a single
_validate_a2a_version() check applied at the one point all 11 RPC methods
funnel through, replicating the semantics of validate_version (missing
header treated as '0.3'; major version must match).

Fixes a2aproject#1166
@avilleroy51
avilleroy51 force-pushed the fix/grpc-error-mapping-and-version-validation branch from f9c0293 to 998b675 Compare August 6, 2026 18:09
@avilleroy51

Copy link
Copy Markdown
Author

Hi maintainers — checking in on this PR. It looks like no CI workflow has run yet on this commit (no check-suites registered), which is expected for a first-time external contributor — GitHub requires a maintainer to approve running workflows on fork PRs.

Could someone please approve the workflow run (or take a look) when you have a moment? Happy to address any feedback. Thanks!

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]: grpc_handler maps 3 A2A errors to FAILED_PRECONDITION instead of UNIMPLEMENTED, and doesn't validate A2A-Version at all

1 participant