feat: implement rich gRPC error details per A2A v1.0 spec#790
feat: implement rich gRPC error details per A2A v1.0 spec#790
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly upgrades the gRPC error handling within the A2A SDK by adopting a standardized, robust mechanism. It transitions from a fragile string-based error parsing approach to using strongly-typed binary metadata, which greatly improves the reliability and interoperability of error communication across the gRPC ecosystem. This change ensures compliance with the A2A v1.0 specification while carefully preserving compatibility with previous protocol versions. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
0562163 to
acc32c2
Compare
There was a problem hiding this comment.
Code Review
This pull request successfully implements rich gRPC error handling as per the A2A v1.0 specification, which is a great improvement for interoperability and robustness. However, the implementation of the abort_context function on the server side contains critical bugs (TypeError and AttributeError) that will cause the request handler to crash whenever an error occurs, leading to a denial of service for those requests. Additionally, metadata decoding lacks error handling for invalid UTF-8 sequences, which could also be exploited for a minor denial of service. While the overall changes are clean, well-structured, and include comprehensive tests, these critical security issues must be addressed to ensure the SDK fails securely and gracefully. There is also a minor suggestion to improve an existing test.
… error types and client-side parsing.
acc32c2 to
fdb156b
Compare
| InvalidParamsError: 'INVALID_PARAMS', | ||
| InvalidRequestError: 'INVALID_REQUEST', | ||
| MethodNotFoundError: 'METHOD_NOT_FOUND', | ||
| InternalError: 'INTERNAL_ERROR', |
There was a problem hiding this comment.
I believe those are JSON-RPC leftovers, we can keep A2A errors only here: https://a2a-protocol.org/latest/specification/#54-error-code-mappings.
| } | ||
|
|
||
|
|
||
| def _parse_rich_grpc_error( |
There was a problem hiding this comment.
Is it possible to use https://grpc.github.io/grpc/python/grpc_status.html here?
| """Sets the grpc errors appropriately in the context.""" | ||
| code = _ERROR_CODE_MAP.get(type(error)) | ||
|
|
||
| status_value = code.value if code else grpc.StatusCode.UNKNOWN.value |
There was a problem hiding this comment.
Is it possible to use https://grpc.github.io/grpc/python/grpc_status.html here?
| if isinstance(details, str) and ': ' in details: | ||
| error_type_name, error_message = details.split(': ', 1) | ||
| # TODO(#723): Resolving imports by name is temporary until proper error handling structure is added in #723. | ||
| # Leaving as fallback for errors that don't use the rich error details. | ||
| exception_cls = _A2A_ERROR_NAME_TO_CLS.get(error_type_name) | ||
| if exception_cls: | ||
| raise exception_cls(error_message) from e |
There was a problem hiding this comment.
This code was added in 1.0-dev branch and was never released (#761). It is safe to remove it.
Description
This PR implements standard gRPC rich error handling using google.rpc.Status and google.rpc.ErrorInfo, bringing the SDK's gRPC transport fully in line with the A2A v1.0 specification.
Previously, the gRPC server appended the exception name to the string message (e.g., "TaskNotFoundError: task not found"), and the client relied on string splitting to parse the error back into a domain exception. This approach was brittle and not interoperable with standard gRPC ecosystems (proxies, gateways, etc.).
This PR replaces the string-parsing heuristic with strongly-typed binary metadata (grpc-status-details-bin), while retaining backward compatibility for clients talking to older A2A v0.3 servers.
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.bash scripts/format.shfrom the repository root to format)Fixes #723 🦕