Skip to content

fix: fix REST error handling#893

Merged
guglielmo-san merged 2 commits into1.0-devfrom
ishymko/rest-errors-handling
Mar 24, 2026
Merged

fix: fix REST error handling#893
guglielmo-san merged 2 commits into1.0-devfrom
ishymko/rest-errors-handling

Conversation

@ishymko
Copy link
Copy Markdown
Member

@ishymko ishymko commented Mar 24, 2026

Do one iteration to catch exceptions occurred beforehand to return an error instead of sending headers for SSE. Error handling during the execution is not defined in the spec: a2aproject/A2A#1262.

Do one iteration to catch exceptions occurred beforehand to return an error instead of sending headers for SSE. Error handling during the execution is not defined in the spec: a2aproject/A2A#1262.
@gemini-code-assist
Copy link
Copy Markdown
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 enhances the robustness of REST API streaming endpoints by addressing a critical error handling flaw. Previously, errors occurring early in a streaming request could lead to a broken client connection rather than a structured error response. The changes ensure that such errors are now properly intercepted and returned as standard JSON error messages, significantly improving the client experience and API reliability for streaming operations.

Highlights

  • Improved REST Streaming Error Handling: Modified the _handle_streaming_request function to eagerly fetch the first item from an asynchronous stream. This ensures that any errors occurring during the initial processing (e.g., validation, parsing) are caught before Server-Sent Events (SSE) headers are sent, allowing for a proper JSON error response instead of a broken stream.
  • New Integration Test for Streaming Errors: Added a comprehensive integration test, test_client_handles_a2a_errors_streaming, to verify that A2A errors raised by streaming handlers are correctly propagated to the client. This test covers various error types and streaming methods, ensuring robust error handling in streaming scenarios.
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
Copy Markdown
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 effectively addresses a key issue in REST streaming error handling by eagerly fetching the first event. This ensures that exceptions occurring before the stream begins are properly caught and returned as JSON errors instead of breaking the SSE connection. The implementation is clean and the addition of the test_client_handles_a2a_errors_streaming integration test provides excellent coverage for this new behavior. I've added one suggestion to further improve the robustness of the error handling for the first event.

@ishymko ishymko marked this pull request as ready for review March 24, 2026 10:32
@ishymko ishymko requested a review from a team as a code owner March 24, 2026 10:32
@github-actions
Copy link
Copy Markdown

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/apps/rest/rest_adapter.py 82.28% 83.53% 🟢 +1.25%
Total 91.38% 91.39% 🟢 +0.01%

Generated by coverage-comment.yml

@guglielmo-san guglielmo-san merged commit 405be3f into 1.0-dev Mar 24, 2026
12 checks passed
@guglielmo-san guglielmo-san deleted the ishymko/rest-errors-handling branch March 24, 2026 10:44
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