Skip to content

fix(core): handle AbortError thrown during processTurn#21296

Merged
gsquared94 merged 2 commits intogoogle-gemini:mainfrom
MumuTW:fix-process-turn-aborterror-21122
Mar 6, 2026
Merged

fix(core): handle AbortError thrown during processTurn#21296
gsquared94 merged 2 commits intogoogle-gemini:mainfrom
MumuTW:fix-process-turn-aborterror-21122

Conversation

@MumuTW
Copy link
Contributor

@MumuTW MumuTW commented Mar 5, 2026

Summary

  • catch AbortError in GeminiClient.sendMessageStream() when thrown from async work inside processTurn
  • map that path to a graceful UserCancelled event instead of allowing the stream generator to throw
  • add a regression test that forces processTurn setup (loopDetector.turnStarted) to reject with AbortError

Why

Issue #21122 reports unhandled AbortError crashes during stream generation. Some aborts can surface from processTurn internals before Turn.run() has a chance to convert them into stream events. This patch handles that boundary safely.

Testing

  • pnpm -C packages/core test -- src/core/client.test.ts (failed in this environment because vitest is not installed in local workspace path)
  • pre-commit checks ran successfully during commit (prettier + eslint on changed files)

@MumuTW MumuTW requested a review from a team as a code owner March 5, 2026 18:36
@google-cla
Copy link

google-cla bot commented Mar 5, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 addresses an issue where unhandled AbortError exceptions could cause crashes during stream generation. It introduces robust error handling within the processTurn method to catch these errors and convert them into a UserCancelled event, preventing application instability and providing a more predictable termination for aborted operations.

Highlights

  • Error Handling: Implemented a catch block within processTurn to gracefully handle AbortError exceptions that may arise from asynchronous operations.
  • Event Mapping: Mapped caught AbortError instances to a GeminiEventType.UserCancelled event, ensuring a consistent and expected stream termination.
  • Regression Testing: Added a new regression test case to validate that processTurn correctly yields a UserCancelled event when an AbortError is thrown.
Changelog
  • packages/core/src/core/client.test.ts
    • Added a new test case to verify that sendMessageStream yields UserCancelled when processTurn throws an AbortError.
  • packages/core/src/core/client.ts
    • Imported isAbortError from ../utils/errors.js.
    • Wrapped the processTurn logic in a try-catch block to intercept AbortError and signal.aborted conditions.
    • Yielded GeminiEventType.UserCancelled and returned early if an AbortError is caught or the signal is aborted.
Activity
  • The author reported that local tests failed due to a missing dependency (vitest not installed in the local workspace path).
  • Pre-commit checks (prettier + eslint) ran successfully on changed files.
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 error handling for AbortError within the sendMessageStream method, wrapping the processTurn generator in a try...catch block to map AbortError to a UserCancelled event and prevent unhandled exceptions. A security audit confirmed that these changes are security-neutral and improve robustness by gracefully handling cancellations, with no high or critical security vulnerabilities identified. A new regression test has also been included to verify this behavior.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 5, 2026
@MumuTW MumuTW force-pushed the fix-process-turn-aborterror-21122 branch from 6f3ff7f to d20259a Compare March 5, 2026 23:37
Copy link
Contributor

@gsquared94 gsquared94 left a comment

Choose a reason for hiding this comment

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

I think this fix complements #21123

@gsquared94 gsquared94 enabled auto-merge March 6, 2026 06:10
@gsquared94 gsquared94 added this pull request to the merge queue Mar 6, 2026
Merged via the queue into google-gemini:main with commit 6691fac Mar 6, 2026
27 checks passed
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
…#21296)

Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
…#21296)

Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
…#21296)

Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
…#21296)

Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants