Repository navigation
fix(cli): ensure Ctrl+C emergency abort reaches cancellation handler during active operations - #29586
Conversation
…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
|
📊 PR Size: size/M
|
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 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
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 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 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
|
|
/Gemini review |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
Ctrl+CPropagation During Active Operations: InInputPrompt.tsx,buffer.handleInput(key)was matchingCommand.CLEAR_INPUTand returningtruewhen text was present in the prompt buffer, prematurely terminating keypress broadcasting beforeAppContainer.tsxcould callcancelOngoingRequest(). We now allowCommand.QUIT(Ctrl+C) to propagate whenisGeneratingis true so that ongoing requests are immediately cancelled.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 tosequence(\x1b[<0;10;\x03) and emitted as{ name: 'undefined', ctrl: false }. We now avoid appending non-mouse characters to the sequence and immediately dispatch\x03as a clean{ name: 'c', ctrl: true }keypress event.packages/cli/src/ui/emergency-stop.test.tsxverifying Ctrl+C propagation during generation and SGR mouse timeout interrupt handling.packages/cli/src/ui/components/InputPrompt.test.tsxverifying Ctrl+C reaches global cancellation handlers duringRespondingstate even with buffer text.packages/cli/src/ui/contexts/KeypressContext.test.tsxverifying SGR mouse timeout handling and complete sequence filtering.Related Issues
Fixes #18087
How to Validate
npm test -w @google/gemini-cli -- src/ui/emergency-stop.test.tsx src/ui/contexts/KeypressContext.test.tsx src/ui/components/InputPrompt.test.tsxnpm run typecheck && npm run lintnpm run start.sleep 30).Ctrl+C. Verify that the operation cancels immediately and the prompt clears.Pre-Merge Checklist