fix(core): handle AbortError when ESC cancels tool execution#20863
fix(core): handle AbortError when ESC cancels tool execution#20863Adib234 merged 4 commits intogoogle-gemini:mainfrom
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 enhances the user experience by gracefully handling Highlights
Changelog
Activity
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
|
|
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. |
There was a problem hiding this comment.
Code Review
This pull request correctly handles AbortError during tool execution, treating it as a cancellation to prevent unhandled exception stack traces from being shown to the user. The changes are implemented in the central ToolExecutor for generic handling, and specifically within the google_web_search tool for a more tailored cancellation message. The implementation is sound, but there is a small area for improvement regarding code duplication, as noted in the specific comment, which also aligns with best practices for consistent cancellation handling.
| const isAbortError = | ||
| executionError instanceof Error && | ||
| executionError.name === 'AbortError'; |
There was a problem hiding this comment.
This logic for identifying an AbortError is also used in packages/core/src/tools/web-search.ts. To improve maintainability and promote code reuse, consider extracting this check into a shared utility function (e.g., in packages/core/src/utils/errors.ts). This would prevent potential inconsistencies if the definition of an abort error needs to be updated in the future.
References
- Asynchronous operations that can be cancelled by the user should accept and propagate an
AbortSignalto ensure cancellability and prevent dangling processes or network requests. Consistent identification ofAbortErroris crucial for robust cancellation handling across the repository. - Asynchronous operations waiting for user input via the MessageBus should rely on the provided AbortSignal for cancellation, rather than implementing a separate timeout, to maintain consistency with existing patterns. Centralizing
AbortErroridentification supports consistent cancellation logic.
|
Can we add some tests for this and resolve the merge conflicts? |
Yes, on it edit: @Adib234 Ive added the tests and resolved the merge conflicts, please take a look.. |
17d0adb to
d215beb
Compare
When a user presses ESC to cancel an in-flight tool call (e.g. google_web_search), the underlying request can reject with AbortError. Treat AbortError as a normal cancellation so the CLI returns to the prompt without surfacing a raw stack trace. Fixes google-gemini#20839
Add a shared isAbortError() helper in utils/errors and use it in the tool executor and google_web_search to avoid duplicated AbortError checks.
a579599 to
5605526
Compare
|
hey @Adib234, fixed the linting error, can you run the ci again? |
When a user presses ESC to cancel an in-flight tool call (e.g. google_web_search), the underlying request can reject with AbortError. Treat AbortError as a normal cancellation so the CLI returns to the prompt without surfacing a raw stack trace.
Fixes #20839
Summary
AbortErrorduring tool execution as a normal cancellation so the CLI shows a clean “Request cancelled” message and returns to the prompt without a stack trace.Details
AbortErrorthrown during tool execution as cancellation (instead of an unhandled exception/error result).google_web_searchreturns a clean cancelled result when the abort is caught within the tool.Related Issues
Fixes #20839
How to Validate
npm run build --workspace=@google/gemini-cli-devtoolsnpm run buildnpm run startgoogle_web_search).ESCto cancel.AbortErrorstack trace is printed.Pre-Merge Checklist