Skip to content

fix(cli): resolve input handling flaws and add emergency abort#27415

Open
KoushikAD1234 wants to merge 1 commit into
google-gemini:mainfrom
KoushikAD1234:fix/input-handling-safety-18087
Open

fix(cli): resolve input handling flaws and add emergency abort#27415
KoushikAD1234 wants to merge 1 commit into
google-gemini:mainfrom
KoushikAD1234:fix/input-handling-safety-18087

Conversation

@KoushikAD1234
Copy link
Copy Markdown

Summary

This PR resolves a safety-critical issue where users on touch interfaces (like Termux on Android) were unable to interrupt or stop the AI agent due to inequitable keybindings and input race conditions. It introduces a dedicated "Emergency Abort" mechanism and optimizes mouse handling for mobile environments.

Details

  • Emergency Abort: Introduced a "Raw" listener for Ctrl+C (\x03) that bypasses the standard input parser. This ensures that the interrupt signal is captured even if the UI thread or mouse parser is busy/locked.
  • New Keybindings: Added F10 as a deterministic, single-key abort signal, which is much more reliable on mobile virtual keyboards than multi-key combinations.
  • Mouse/ESC Race Condition: Fixed a conflict where mouse reporting escape sequences would "swallow" the ESC key byte (\x1b), leading to terminal freezes.
  • Mobile Optimization: Mouse tracking is now disabled by default in touch-oriented environments (detected via TERMUX_VERSION, etc.) to prevent input flood corruption, while remaining enabled for desktop users.
  • Suspension Safety: Updated useSuspend to properly restore terminal modes based on the new ui.mouseEvents settings.

Related Issues

Fixes #18087

How to Validate

  1. Mobile/Termux Simulation:

    • Run the CLI with TERMUX_VERSION=0.118.0.
    • Verify that mouse tracking is disabled by default.
    • Start a long-running prompt and verify that pressing Ctrl+C (once) or F10 immediately stops the agent.
  2. Desktop Validation:

    • Verify that mouse tracking still works as expected in the alternate buffer.
    • Verify that Ctrl+C once aborts a running request, while a second press (when idle) triggers the quit logic.
  3. Settings Test:

    • Change ui.mouseEvents to enabled or disabled in settings.json and verify the behavior overrides the auto-detection.

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)
    • Linux (Termux/Mobile simulation)

@KoushikAD1234 KoushikAD1234 requested review from a team as code owners May 24, 2026 15:22
@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 in the CLI, particularly for users on touch-based interfaces. It introduces a robust emergency abort mechanism and provides granular control over terminal mouse tracking to prevent input corruption and terminal freezes, significantly improving the experience on mobile environments.

Highlights

  • Emergency Abort: Added a raw listener for Ctrl+C and a new F10 keybinding to ensure AI agent tasks can be reliably interrupted even when the UI thread is busy.
  • Mouse Event Control: Introduced the ui.mouseEvents setting to allow users to toggle mouse tracking, with automatic detection to disable it in touch-oriented environments like Termux.
  • Stability Improvements: Resolved race conditions between mouse reporting and the ESC key, and updated suspension logic to ensure terminal modes are correctly restored.
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.

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 introduces a new configuration setting, "ui.mouseEvents", which allows users to control terminal mouse tracking. It defaults to "auto", which automatically disables mouse tracking in touch-oriented environments like Termux to prevent interference. Additionally, the PR implements an "Emergency Abort" feature, allowing users to cancel ongoing requests using Ctrl+C or F10 without exiting the CLI. This includes updates to the settings schema, documentation, event handling, and comprehensive test coverage for the new logic. I have no feedback to provide.

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

@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 May 24, 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.

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

1 participant