Skip to content

fix: handle errors occurred in non-blocking sendMessage#187

Merged
guglielmo-san merged 43 commits intoa2aproject:mainfrom
guglielmo-san:test_hanging_promise_error
Nov 19, 2025
Merged

fix: handle errors occurred in non-blocking sendMessage#187
guglielmo-san merged 43 commits intoa2aproject:mainfrom
guglielmo-san:test_hanging_promise_error

Conversation

@guglielmo-san
Copy link
Member

@guglielmo-san guglielmo-san commented Nov 18, 2025

Description

This PR fixes the error of server crash in case of error in the event loop for non blocking event, if the first reply to the client has been already sent.
Two different error handling strategies are implemented based on the origin of the error:

  1. If the error originates from the pushNotification service, the loop is not interrupted, and the error is simply printed on the console error output
  2. If the error is originating from the ExecutionEventQueue or from a taskStore operation (resultManager interaction), the error is interrupting the loop.
    In the catch clause a TaskStatusUpdateEvent is generated, with taskStatus equal to "failed", if an already existing Task has been processed by the ResultManager. The new TaskStatusUpdateEvent is saved in the taskStore. If a new error occurs within this operation, it is simply printed on the console error output.

Fixes #186 🦕

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @guglielmo-san, 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 improves the stability and maintainability of the A2A SDK. It addresses a critical issue where server processes could crash due to unhandled errors in non-blocking event loops, ensuring that such failures are now gracefully managed and reported. Additionally, the integration of Prettier and an updated ESLint configuration enforces a consistent code style, making the codebase easier to read and contribute to.

Highlights

  • Code Formatting Standardization: Introduced Prettier configuration and updated ESLint to use eslint-plugin-prettier, ensuring consistent code formatting across the codebase and disabling conflicting ESLint rules.
  • Enhanced Error Handling for Non-Blocking Operations: Implemented a fix in the DefaultRequestHandler to prevent server crashes by robustly handling errors in the event loop for non-blocking calls. If an error occurs after the initial result is sent, a 'failed' status update is now correctly published to the task.
  • Dependency Updates: Updated package-lock.json and package.json to reflect the new Prettier and ESLint configurations, including the removal of eslint-plugin-unused-imports and the addition of eslint-plugin-prettier and prettier.
  • New Mock for Testing: Added a MockTaskStore to facilitate more comprehensive and isolated testing of server-side components.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/eslint.yml
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.

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

  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

This pull request introduces Prettier for code formatting and applies it across the entire codebase, which is a great step for consistency. It also seems to address a bug related to hanging promises. I've found a minor issue with an unused import in a new test mock file. Please see my comment for details.

@guglielmo-san
Copy link
Member Author

/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 addresses a critical issue where an error in the event loop for a non-blocking call could crash the server. The approach of catching the error and, if a response has already been sent, updating the task to a 'failed' state is correct.

However, the implementation of this fix introduces a new potential crash. If an error occurs after a message event (instead of a task event) has been sent, the code will attempt to access properties on an undefined object, leading to a TypeError. I've provided a critical review comment with a suggested fix to make the error handling more robust.

The other changes in this PR, including the addition of a new test case and stylistic updates to the types.ts file, are good.

@guglielmo-san
Copy link
Member Author

/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 effectively addresses a critical bug where the server could crash due to an unhandled promise rejection in non-blocking calls. The core change is in _processEvents, where the error handling logic is enhanced to catch errors that occur after an initial response has been sent. Instead of re-throwing the error, which caused the crash, the new logic updates the task's state to 'failed'. This is a robust solution that improves server stability. The addition of a targeted test case in default_request_handler.spec.ts is excellent, as it precisely simulates the failure scenario and verifies the fix. The overall changes are well-implemented and crucial for the reliability of non-blocking operations.

@guglielmo-san guglielmo-san changed the title fix: Test hanging promise error fix: Fix unhandled promise rejection Nov 18, 2025
@ishymko ishymko changed the title fix: Fix unhandled promise rejection fix: handle errors occurred in non-blocking sendMessage Nov 19, 2025
@guglielmo-san guglielmo-san enabled auto-merge (squash) November 19, 2025 10:45
@guglielmo-san guglielmo-san merged commit e55c0f4 into a2aproject:main Nov 19, 2025
5 checks passed
@guglielmo-san guglielmo-san deleted the test_hanging_promise_error branch November 19, 2025 10:48
ishymko added a commit that referenced this pull request Dec 10, 2025
🤖 I have created a release *beep* *boop*
---


## [0.3.6](v0.3.5...v0.3.6)
(2025-12-10)


### Features

* add support for extendedAgentCard on client side
([#234](#234))
([3073376](3073376))
* Add support for extension headers on client side
([#227](#227))
([8c57002](8c57002))
* implement client interceptors
([#223](#223))
([5694c22](5694c22))
* Implement extended card support on server side
([#197](#197))
([45014ac](45014ac))
* implement server http+json
([#142](#142))
([f20e662](f20e662))
* introduce AgentCardResolver
([#225](#225))
([ddaf7de](ddaf7de))
* introduce transport agnostic client
([#198](#198))
([94a9848](94a9848))
* server side support for extensions
([5ef7396](5ef7396))
* support authentication on server side
([#195](#195))
([9872d93](9872d93))


### Bug Fixes

* handle errors occurred in non-blocking sendMessage
([#187](#187))
([e55c0f4](e55c0f4))


### Miscellaneous Chores

* set version to 0.3.6
([#191](#191))
([3f8cea0](3f8cea0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Ivan Shymko <ishymko@google.com>
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]: Event loop will crash the server if the request is non blocking and a failure happens in a non first event

2 participants