Skip to content

fix: fix error handling for gRPC and SSE streaming#879

Merged
guglielmo-san merged 13 commits into1.0-devfrom
ishymko/rest-errors
Mar 20, 2026
Merged

fix: fix error handling for gRPC and SSE streaming#879
guglielmo-san merged 13 commits into1.0-devfrom
ishymko/rest-errors

Conversation

@ishymko
Copy link
Member

@ishymko ishymko commented Mar 20, 2026

Reproduced in test_client_server_integration.py.

gRPC

validate_async_generator decorator was applied on top of the method above A2A error handling. Compat handler was already refactored in a way which made it possible to apply it on a nested function. It was done there and v1 handler was refactored in the same way.

SSE streaming

Iterator wrapped into validate_async_generator is assigned to EventSourceResponse and is returned from the method, so when it throws rest_stream_error_handler has no effect on it.

async def event_generator(
stream: AsyncIterable[Any],
) -> AsyncIterator[str]:
async for item in stream:
yield json.dumps(item)
return EventSourceResponse(
event_generator(method(request, call_context))
)

Instead of throwing on the first iteration, throw on the method invocation itself to avoid more sophisticated error handling (i.e. reading one item to trigger error) by removing separate handling for async generator.

Client-level handling is also updated to properly handle non-200 status code for streaming and non-streaming response in case of JSON-RPC error.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 refactors the gRPC request handling mechanism to centralize error management and context building. By introducing generic helper methods for unary and streaming calls, it standardizes how errors are caught and processed across all gRPC endpoints. This change improves code maintainability and ensures consistent error responses, while also enhancing test coverage for various error conditions.

Highlights

  • Centralized gRPC Error Handling: Introduced new _handle_unary and _handle_stream helper methods in GrpcHandler to centralize error handling, context building, and metadata setting for all gRPC service methods. This significantly reduces boilerplate and improves consistency.
  • Decorator Relocation for A2A Compat Handler: Moved @validate_async_generator and @validate decorators from the main gRPC service methods to their nested _handler functions within CompatGrpcHandler. This ensures validation occurs at the correct stage of the request lifecycle.
  • Refactored gRPC Service Methods: All individual gRPC service methods in GrpcHandler were refactored to utilize the new _handle_unary or _handle_stream helper methods, streamlining their implementation and error management.
  • Expanded Integration Tests: Added new fixtures and integration tests to cover error handling scenarios, including UnsupportedOperationError for disabled streaming and push notifications, and VersionNotSupportedError, ensuring robust error propagation.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request effectively refactors the gRPC handlers to centralize error handling and context management, improving code organization and reducing duplication. The changes in src/a2a/compat/v0_3/grpc_handler.py correctly move validation decorators to nested functions, aligning with the new error handling strategy. The addition of new fixtures and integration tests in tests/integration/test_client_server_integration.py demonstrates a commitment to robust testing, particularly for the new error handling and compatibility features. The overall direction of the changes is positive for maintainability and reliability.

@ishymko ishymko force-pushed the ishymko/rest-errors branch from 852df79 to f0acbd8 Compare March 20, 2026 10:47
@ishymko ishymko force-pushed the ishymko/rest-errors branch from f0acbd8 to 7236d8c Compare March 20, 2026 10:47
@ishymko ishymko force-pushed the ishymko/rest-errors branch from 2f3b48f to a84f89e Compare March 20, 2026 11:21
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/client/transports/grpc.py 88.46% 89.23% 🟢 +0.77%
src/a2a/client/transports/http_helpers.py 95.65% 94.64% 🔴 -1.01%
src/a2a/client/transports/jsonrpc.py 83.92% 86.71% 🟢 +2.80%
src/a2a/compat/v0_3/grpc_handler.py 95.52% 97.01% 🟢 +1.49%
src/a2a/compat/v0_3/grpc_transport.py 41.84% 59.57% 🟢 +17.73%
src/a2a/server/request_handlers/grpc_handler.py 81.55% 94.48% 🟢 +12.93%
src/a2a/utils/helpers.py 97.42% 97.19% 🔴 -0.23%
Total 90.77% 91.45% 🟢 +0.68%

Generated by coverage-comment.yml

@ishymko
Copy link
Member Author

ishymko commented Mar 20, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors error handling for gRPC and SSE streaming. The gRPC handler refactoring significantly improves code clarity and maintainability by centralizing error handling. The SSE error handling improvements in http_helpers.py are also a good addition for robustness.

However, there is a critical issue introduced by replacing @validate_async_generator with @validate on async generator methods. The current @validate decorator is not designed to handle async generators and will cause a TypeError at runtime. This affects gRPC, REST, and JSON-RPC streaming handlers. I've left a detailed comment on this issue. Additionally, the new integration tests for this feature are incomplete as they only test the failure path, which masks this bug.

@ishymko ishymko marked this pull request as ready for review March 20, 2026 12:36
@ishymko ishymko requested a review from a team as a code owner March 20, 2026 12:36
@guglielmo-san guglielmo-san merged commit 2b323d0 into 1.0-dev Mar 20, 2026
14 checks passed
@guglielmo-san guglielmo-san deleted the ishymko/rest-errors branch March 20, 2026 13:10
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.

2 participants