Skip to content

fix: harden CLI interrupt handling for shell mode and chat compression#21683

Closed
chrisjcthomas wants to merge 5 commits intogoogle-gemini:mainfrom
chrisjcthomas:fix/interrupt-handling
Closed

fix: harden CLI interrupt handling for shell mode and chat compression#21683
chrisjcthomas wants to merge 5 commits intogoogle-gemini:mainfrom
chrisjcthomas:fix/interrupt-handling

Conversation

@chrisjcthomas
Copy link
Copy Markdown
Contributor

@chrisjcthomas chrisjcthomas commented Mar 9, 2026

This PR improves how Gemini CLI handles user interruptions via Escape and Ctrl+C to ensure a more consistent and reliable user experience.

Improvements

  • Interrupt Handling (Shell Mode) (Bug: Pressing Escape in '!' shell mode cancels ongoing agent request instead of exiting shell mode #20615): Fixed a bug where pressing Escape while in shell mode (typing a ! command) would accidentally cancel ongoing background agent requests. Now, Escape correctly exits shell mode without affecting the agent.
  • Interrupt Handling (Compression): Threaded the abortSignal from the current turn into the ChatCompressionService. This ensures that when a user cancels a request (e.g., via Ctrl+C), any in-flight API calls for chat summarization/compression are also immediately aborted.

Verification

  • Manually verified that pressing Escape in shell mode no longer cancels background thoughts.
  • Verified that abortSignal is correctly passed from AppContainer through GeminiClient and LocalExecutor into the compression service.

Closes #20615

@chrisjcthomas chrisjcthomas requested review from a team as code owners March 9, 2026 09:33
@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 significantly enhances the robustness of the Gemini CLI's interrupt handling mechanisms. It addresses critical scenarios where user input, such as pressing "Escape" or "Ctrl+C", did not behave as expected, leading to unintended cancellations of background processes or API calls. The changes ensure a more predictable and reliable user experience by correctly propagating cancellation signals and refining input interpretations.

Highlights

  • Shell Mode Interrupts: Resolved an issue where pressing "Escape" in shell mode (when typing a "!" command) would inadvertently cancel ongoing background agent requests. "Escape" now correctly exits shell mode without affecting agent operations.
  • Chat Compression Interrupts: Integrated "abortSignal" into the "ChatCompressionService" to ensure that user cancellations (e.g., via "Ctrl+C") also immediately abort any in-flight API calls related to chat summarization or compression.
Changelog
  • docs/cli/sandbox.md
    • Updated a bullet point to clarify that adding to a custom Dockerfile for missing commands requires running from source code and is not available via npm installation.
  • docs/reference/configuration.md
    • Added a note explaining that building custom sandboxes from a Dockerfile is only supported when running the CLI from source, and provides guidance for npm installations.
  • packages/cli/src/ui/commands/compressCommand.ts
    • Modified the "tryCompressChat" call to pass "context.ui.abortSignal", enabling cancellation of compression requests.
  • packages/cli/src/ui/hooks/useGeminiStream.ts
    • Adjusted the "useKeypress" hook condition to include "!shellModeActive" when checking for the "escape" key, preventing unintended request cancellations while in shell mode.
  • packages/core/src/agents/local-executor.ts
    • Updated the "tryCompressChat" method signature to accept an optional "abortSignal".
    • Passed the "abortSignal" to the "tryCompressChat" call within the "execute" method.
    • Modified the internal call to "ChatCompressionService" to include the "abortSignal".
  • packages/core/src/core/client.ts
    • Updated the "tryCompressChat" method signature to accept an optional "abortSignal".
    • Passed the "abortSignal" to the "tryCompressChat" call within the "generateContentStream" method.
    • Modified the internal call to "ChatCompressionService" to include the "abortSignal".
  • packages/core/src/services/chatCompressionService.ts
    • Removed the fallback "new AbortController().signal" for "abortSignal" in "callModel" and "verifySummary" methods, ensuring the provided "abortSignal" is used directly.
Activity
  • Manually verified that pressing "Escape" in shell mode no longer cancels background thoughts.
  • Verified that "abortSignal" is correctly passed from "AppContainer" through "GeminiClient" and "LocalExecutor" into the compression service.
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
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 hardens interrupt handling in the CLI, which is a great improvement for user experience. The changes correctly propagate the abortSignal for chat compression and fix an issue with the Escape key in shell mode. I've identified a potential issue where the removal of a fallback for the abortSignal could make the chat compression service less robust, potentially hindering cancellability. My review includes suggestions to address this by ensuring AbortSignals are consistently propagated, aligning with best practices for asynchronous operations.

Note: Security Review did not run due to the size of the PR.

Comment thread packages/core/src/services/chatCompressionService.ts Outdated
Comment thread packages/core/src/services/chatCompressionService.ts Outdated
@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 9, 2026
Addresses gemini-code-assist review: restore the nullish coalescing
fallback (`?? new AbortController().signal`) to ensure `generateContent`
always receives a valid AbortSignal, even when `compress()` is called
without one.
Copy link
Copy Markdown
Contributor Author

@chrisjcthomas chrisjcthomas left a comment

Choose a reason for hiding this comment

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

Thanks for catching this! Both instances have been fixed in commit b133082 — the ?? new AbortController().signal fallback has been restored on both generateContent calls to ensure a valid AbortSignal is always provided, even when compress() is called without one.

@chrisjcthomas
Copy link
Copy Markdown
Contributor Author

@jkcinouye I cleaned up the stale Gemini review threads on this PR and updated the description to match the current scope. If you have a chance, I’d appreciate a review.

@chrisjcthomas
Copy link
Copy Markdown
Contributor Author

@g-samroberts adding you here as well since you had context on #21679. I cleaned up the stale Gemini review threads and updated the description to match the current scope; if you have a chance, I’d appreciate a review.

@spencer426
Copy link
Copy Markdown
Contributor

Thank you for your interest in contributing to the project! We are closing this PR as the issue was already fixed.

@spencer426 spencer426 closed this Apr 30, 2026
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.

Bug: Pressing Escape in '!' shell mode cancels ongoing agent request instead of exiting shell mode

2 participants