Skip to content

fix(cli): ensure Ctrl+C emergency abort reaches cancellation handler during active operations - #29586

Merged
DavidAPierce merged 1 commit into
google-gemini:mainfrom
urielefrenvirtusa:b_561556027
Oct 1, 2026
Merged

DavidAPierce merged 1 commit into
google-gemini:mainfrom
urielefrenvirtusa:b_561556027

Conversation

@urielefrenvirtusa

@urielefrenvirtusa urielefrenvirtusa commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes critical input handling flaws where emergency stop (Ctrl+C) could be swallowed or corrupted during active operations, denying users the ability to interrupt running agents or streams (b/561556027).

Details

  1. Ctrl+C Propagation During Active Operations: In InputPrompt.tsx, buffer.handleInput(key) was matching Command.CLEAR_INPUT and returning true when text was present in the prompt buffer, prematurely terminating keypress broadcasting before AppContainer.tsx could call cancelOngoingRequest(). We now allow Command.QUIT (Ctrl+C) to propagate when isGenerating is true so that ongoing requests are immediately cancelled.
  2. SGR Mouse Parser Timeout & Interrupt Safety: In KeypressContext.tsx, while (ch === '' || ch === ';' || ...) unconditionally appended incoming characters to the mouse sequence. During timeouts or broken sequences, incoming control keys like \x03 (Ctrl+C) were appended to sequence (\x1b[<0;10;\x03) and emitted as { name: 'undefined', ctrl: false }. We now avoid appending non-mouse characters to the sequence and immediately dispatch \x03 as a clean { name: 'c', ctrl: true } keypress event.
  3. Comprehensive Test Coverage:
    • Added packages/cli/src/ui/emergency-stop.test.tsx verifying Ctrl+C propagation during generation and SGR mouse timeout interrupt handling.
    • Added unit test in packages/cli/src/ui/components/InputPrompt.test.tsx verifying Ctrl+C reaches global cancellation handlers during Responding state even with buffer text.
    • Added unit tests in packages/cli/src/ui/contexts/KeypressContext.test.tsx verifying SGR mouse timeout handling and complete sequence filtering.

Related Issues

Fixes #18087

How to Validate

  1. Run the test suites:
    npm test -w @google/gemini-cli -- src/ui/emergency-stop.test.tsx src/ui/contexts/KeypressContext.test.tsx src/ui/components/InputPrompt.test.tsx
  2. Verify typechecking and linting:
    npm run typecheck && npm run lint
  3. Interactive verification:
    • Start the CLI with npm run start.
    • Submit a prompt that executes a long-running tool command (e.g. sleep 30).
    • Type text into the prompt box while the tool is executing.
    • Press Ctrl+C. Verify that the operation cancels immediately and the prompt clears.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

…during active operations

- In InputPrompt, do not swallow Ctrl+C as CLEAR_INPUT when isGenerating is true, allowing the cancellation signal to propagate to AppContainer
- In KeypressContext, do not append non-mouse characters during SGR mouse sequence parsing, and dispatch \x03 immediately as a Ctrl+C keypress if received mid-sequence
- Add comprehensive regression tests in InputPrompt.test.tsx, KeypressContext.test.tsx, and emergency-stop.test.tsx

Fixes b/561556027
@urielefrenvirtusa
urielefrenvirtusa requested a review from a team as a code owner September 30, 2026 23:24
@github-actions github-actions Bot added the size/m A medium sized PR label Sep 30, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 249
  • Additions: +248
  • Deletions: -1
  • Files changed: 5

@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 addresses critical input handling issues where emergency stop commands (Ctrl+C) were occasionally ignored or corrupted during active operations. By refining the key propagation logic in the input prompt and improving the robustness of the SGR mouse sequence parser, the changes ensure that users can reliably interrupt ongoing requests or streams regardless of the current UI state.

Highlights

  • Ctrl+C Propagation: Modified InputPrompt to allow Ctrl+C (QUIT) to propagate to global cancellation handlers during active generation, preventing it from being swallowed by the input buffer.
  • SGR Mouse Parser Robustness: Updated the SGR mouse sequence parser to avoid appending non-mouse characters and to explicitly handle Ctrl+C interrupts, ensuring they are dispatched correctly even during timeouts or broken sequences.
  • Test Coverage: Added comprehensive test suites, including a new emergency-stop test file, to verify Ctrl+C propagation and SGR mouse sequence handling under various conditions.
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 the 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 counterproductive. 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. ↩

@urielefrenvirtusa

Copy link
Copy Markdown
Contributor Author

/Gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 fixes for emergency stop (Ctrl+C) handling and input processing in the CLI. Specifically, it prevents the text buffer from swallowing Ctrl+C as a clear-input command while a response is being generated, allowing the cancellation signal to propagate. It also fixes an issue where incomplete SGR mouse sequences could hijack subsequent keypresses by ensuring that Ctrl+C is correctly processed and emitted even during a sequence timeout. Comprehensive unit tests have been added to verify these fixes. There are no review comments to address, and I have no additional feedback to provide.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 issues with emergency stop handling (Ctrl+C) in the CLI. It prevents incomplete SGR mouse sequences from trapping subsequent keypresses by ensuring that a Ctrl+C byte received during SGR parsing is correctly emitted. It also ensures that Ctrl+C is not swallowed by the text buffer during generation, allowing it to propagate and cancel ongoing operations. New test suites have been added to verify these fixes. I have no additional feedback to provide as there are no review comments.

@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 Sep 30, 2026
@DavidAPierce
DavidAPierce added this pull request to the merge queue Oct 1, 2026
Merged via the queue into google-gemini:main with commit 5b71659 Oct 1, 2026
34 checks passed
@urielefrenvirtusa
urielefrenvirtusa deleted the b_561556027 branch October 1, 2026 18:19
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. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Safety Critical] Input Handling Flaws deny 'Emergency Stop' on Touch Interfaces (Inequitable Keybindings)

2 participants