Skip to content

Conversation

@medic-code
Copy link

TLDR

This PR introduces a configurable delay to the Ctrl+C exit mechanism. This prevents the application from accidentally terminating due to rapid, unintended double-presses or lag that interprets a single Ctrl + c as a double press, making the exit behaviour more robust and improving the user experience.

Dive Deeper

The root cause of the issue is that rapid, successive Ctrl+C presses can be registered as a valid double-press, causing an immediate and sometimes unintentional shutdown. This can be frustrating for users who did not intend to exit the application.

This change modifies the core process exit hook to check the time interval between two Ctrl+C signals. A new constant is introduced to define this minimum delay, ensuring that only deliberate double-presses trigger an exit. The implementation also includes updated tests to verify the new timing logic.

Specific code changes

  • Adds MIN_CTRL_C_INTERVAL_MS to define the minimum time (400ms) between two Ctrl+C presses for a deliberate exit.
  • Modifies the useEffect hook in AppContainer.tsx to check this interval before triggering a quit.
  • Updates AppContainer.test.tsx with new tests to verify the delay logic and removes an obsolete test case.

Reviewer Test Plan

  1. Verify all checks pass:

    npm run preflight
  2. Test the delay logic:

    • Run the CLI application.
    • Press Ctrl+C once. The "press again to exit" message should appear.
    • Immediately press Ctrl+C again (faster than the configured delay). The application should not exit.
    • Press Ctrl+C once, wait a moment (longer than the delay), and press Ctrl+C again. The application should exit as expected.

Testing Matrix

🍏 🪟 🐧
npm run
npx

Related Issues

Fixes #12421

Pre-Merge Checklist

  • ran npm run preflight without errors
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Updated relevant documentation and README (if needed)

Introduces a configurable delay for the Ctrl+C exit mechanism to prevent accidental application termination due to rapid, unintended double-presses.

- Adds  to define the minimum time between two Ctrl+C presses for a deliberate exit.
- Modifies the  hook in  to check this interval before triggering a quit.
- Updates  with new tests to verify the delay logic and removes an obsolete test case.
Adds `vi.resetAllMocks()` and `vi.restoreAllMocks()` to the test setup for `AppContainer.test.tsx`. This ensures the tests are run in a clean environment, resolving intermittent failures that occurred when run as part of the full `preflight` suite.
@medic-code medic-code requested a review from a team as a code owner November 8, 2025 19:56
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @medic-code, 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 application's exit mechanism by introducing a configurable delay for the Ctrl+C double-press action. The change aims to improve user experience and prevent unintentional application shutdowns that could occur due to rapid or accidental key presses. By requiring a minimum time interval between successive Ctrl+C signals, the system ensures that only deliberate attempts to quit the application are successful, making the overall behavior more robust and predictable.

Highlights

  • Configurable Ctrl+C Exit Delay: Introduces a configurable delay to the Ctrl+C double-press exit mechanism, preventing accidental application termination from rapid or unintended key presses.
  • New Constant for Delay: Adds a new constant, MIN_CTRL_C_INTERVAL_MS, set to 400ms, to define the minimum time required between two Ctrl+C presses for a deliberate exit.
  • Logic Update in AppContainer: Modifies the useEffect hook in AppContainer.tsx to incorporate the new delay logic, ensuring that the application only quits if the time between two Ctrl+C presses exceeds the defined interval.
  • Updated Test Suite: Updates AppContainer.test.tsx by removing an obsolete test case and adding new tests to specifically verify the functionality of the Ctrl+C delay logic under different timing 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 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
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 delay to the Ctrl+C exit mechanism to prevent accidental termination, which is a great improvement for the user experience. The implementation is logical and the accompanying tests correctly verify the new timing behavior. I have one suggestion to enhance the robustness of the timing logic by using a monotonic clock, which will make the feature more resilient to system time changes.

clearTimeout(ctrlCTimerRef.current);
ctrlCTimerRef.current = null;
}
const now = Date.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Date.now() is not guaranteed to be monotonic, meaning it can go backwards or jump if the system clock is adjusted. This could lead to unpredictable behavior in the double-press logic, such as preventing an exit even with a correct delay or causing an exit unexpectedly. For time interval measurements, it's safer to use a monotonic clock like performance.now() from Node's perf_hooks module. This ensures that time measurements always move forward, making the exit logic more robust.

You will need to add import { performance } from 'node:perf_hooks'; at the top of the file.

Suggested change
const now = Date.now();
const now = performance.now();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only exit if the second ctrl-C is at least X ms after the first

1 participant