Skip to content

fix(cli): resolve hang on Enter keypress in interactive mode (#23297) - #29476

Open
elberthc-byte wants to merge 7 commits into
google-gemini:mainfrom
elberthc-byte:issue-23297-fix
Open

elberthc-byte wants to merge 7 commits into
google-gemini:mainfrom
elberthc-byte:issue-23297-fix

Conversation

@elberthc-byte

@elberthc-byte elberthc-byte commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where pressing Enter on tool confirmation prompts (such as file edit approvals) appears unresponsive when running Gemini CLI in an integrated terminal with IDE companion integration enabled (#23297).

This pull request decouples user confirmation event publication from IDE diff closing side-effects so that slow, delayed, or interrupted IDE companion connections cannot block MessageBus event dispatch or freeze interactive terminal input.

Details

Problem

When an edit tool requests user confirmation, ToolActionsContext.tsx was sequentially awaiting ideClient.resolveDiffFromCli(details.filePath, cliOutcome) before publishing TOOL_CONFIRMATION_RESPONSE to the MessageBus.

If the IDE companion connection experienced latency, socket disconnects, or header timeouts (UND_ERR_HEADERS_TIMEOUT), the 10-minute timeout on closeDiff or an unhandled rejection permanently blocked the confirmation dispatch. Because the scheduler never received the user's confirmation response, the CLI remained waiting on the approval prompt. Keyboard navigation (Up/Down arrow keys) still updated local UI state, but pressing Enter had no effect.

Implementation Logic (Surgical Fix)

  1. Decoupled Confirmation Dispatch (packages/cli/src/ui/contexts/ToolActionsContext.tsx):
    • Dispatches resolveDiffFromCli() asynchronously in the background using optional chaining and .catch(...) logging.
    • Publishes TOOL_CONFIRMATION_RESPONSE to MessageBus immediately upon pressing Enter, allowing the scheduler to advance and dismiss the prompt instantly.
  2. Fast Timeout for Closing Diffs (packages/core/src/ide/constants.ts & ide-client.ts):
    • Configured IDE_CLOSE_DIFF_TIMEOUT_MS = 5000 (5 seconds) specifically for closeDiff operations, preserving the 10-minute IDE_REQUEST_TIMEOUT_MS for human review during openDiff.
    • Safely claims and deletes the resolver in resolveDiffFromCli() before executing closeDiff to prevent tab-close notifications from racing with CLI approvals.
    • Wrapped closeDiff in a try/catch block to guarantee resolver cleanup even if the IDE companion connection aborts or times out.

Related Issues

Fixes #23297
Related to #24830

How to Validate

1. Automated Tests

Run the updated unit test suites in both packages/cli and packages/core:

# Verify non-blocking confirmation and rejection resilience in CLI
npm test -w @google/gemini-cli -- src/ui/contexts/ToolActionsContext.test.tsx

# Verify fast closeDiff timeout and error cleanup in core
npm test -w @google/gemini-cli-core -- src/ide/ide-client.test.ts

Expected output: All 37 tests pass (10 in CLI, 27 in core).

2. Full Workspace Build Verification

Clean and rebuild workspace packages:

npm run clean && npm run build

Expected output: Clean build completion across all packages and devtools client bundling without errors.

3. Manual Interactive Verification

  1. Launch Gemini CLI in an IDE integrated terminal with IDE mode active (/ide enable).
  2. Trigger an edit tool confirmation prompt (e.g. prompt Gemini to edit a file).
  3. With the diff open in the editor, press Enter on "Allow once".
  4. Expected: The prompt confirms immediately, dismisses from the terminal UI, and tool execution proceeds without delay.

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

@elberthc-byte
elberthc-byte requested a review from a team as a code owner September 24, 2026 06:13
@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 a UI hang in the Gemini CLI where pressing 'Enter' on confirmation prompts would become unresponsive due to synchronous waiting on IDE companion operations. By decoupling the confirmation event dispatch from the IDE diff closing process and implementing stricter, more resilient timeout handling, the CLI now remains responsive even when the IDE connection experiences latency or timeouts.

Highlights

  • Decoupled Confirmation Logic: The CLI now dispatches confirmation responses to the MessageBus immediately, preventing IDE companion latency from freezing the interactive terminal input.
  • Optimized Timeout Configuration: Introduced a dedicated 5-second timeout for closing diffs to ensure responsive UI behavior while maintaining longer timeouts for human-in-the-loop operations.
  • Improved Error Resilience: Added robust error handling and cleanup logic in the IDE client to ensure diff resolvers are properly cleared even if connection issues occur.
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. ↩

@github-actions github-actions Bot added the size/m A medium sized PR label Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 149
  • Additions: +139
  • Deletions: -10
  • Files changed: 5

@elberthc-byte

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 improves the robustness of the resolveDiffFromCli method by introducing a dedicated timeout (IDE_CLOSE_DIFF_TIMEOUT_MS) and adding error handling to prevent closeDiff failures from blocking the UI or message bus. Corresponding unit tests were added to verify that hanging or failing closeDiff calls are handled gracefully. I have no 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 improves the robustness of the IDE diff resolution process by preventing hanging or failing resolveDiffFromCli calls from blocking the CLI's message bus or tool confirmation flow. Specifically, resolveDiffFromCli is now called asynchronously and safely caught in ToolActionsProvider, the timeout for closing a diff has been reduced from 10 minutes to 5 seconds, and errors during closeDiff are caught and logged rather than throwing. Corresponding unit tests have been added to verify these non-blocking behaviors. I have no feedback to provide as there are no review comments to evaluate.

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality labels Sep 24, 2026
@elberthc-byte
elberthc-byte requested a review from a team as a code owner September 24, 2026 18:44
@github-actions github-actions Bot added the size/l A large sized PR label Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@elberthc-byte

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 improves the robustness of IDE diffing interactions by preventing hangs and unblocking the message bus when IDE client operations delay or fail. Key changes include wrapping IDE confirmation promises in races with timeouts, dynamically fetching the IdeClient instance, and handling errors gracefully during diff closure. Feedback on these changes highlights two critical issues: a potential resource leak where a setTimeout is not cleared after a Promise.race settles, and a concurrency bug in ide-client.ts where registering resolvers before acquiring the mutex can overwrite queued diffs on the same file path.

Comment thread packages/cli/src/ui/contexts/ToolActionsContext.tsx Outdated
Comment thread packages/core/src/ide/ide-client.ts Outdated
@elberthc-byte

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 ensures that diff resolution in the IDE client does not block or fail the main application flow. In ToolActionsProvider, resolveDiffFromCli is now called asynchronously without being awaited, with errors caught and logged. In IdeClient, the timeout for closing a diff is reduced to 5 seconds, and resolveDiffFromCli wraps closeDiff in a try-catch block to guarantee that the resolver is cleaned up and resolved even on failure. Comprehensive unit tests have been added to verify these robustness improvements. I have no feedback to provide as there are no review comments to evaluate.

@gemini-cli

gemini-cli Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

This branch is waiting to be deployed

1 waiting (outdated) deployment
eval-gate — 106124f6 Waiting Sep 24, 2026 by elberthc-byte via Evaluate Steering & Regressions #2054
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 priority/p1 Important and should be addressed in the near term. size/l A large sized PR size/m A medium sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why pressing Enter does nothing?

2 participants