Skip to content

Conversation

@ppgranger
Copy link

Summary

Fix infinite loop when selecting "Modify with external editor" without a configured or available editor. Users were stuck in an
endless loop with no feedback when attempting to use the external editor feature. This fix adds proper editor detection,
auto-fallback, and clear error messages.

Details

Root cause: In both confirmation.ts and coreToolScheduler.ts, when getPreferredEditor() returned undefined, the code
silently returned without changing the loop outcome variable, causing the confirmation loop to repeat indefinitely.

Solution:

  • Added detectFirstAvailableEditor() - auto-detects available editors, prioritizing terminal editors (vim, neovim, emacs, helix)
    that work in sandbox mode
  • Added resolveEditor() - comprehensive editor resolution that validates availability, auto-detects fallbacks, and provides
    specific error messages
  • Updated confirmation.ts to check editor resolution result and break the loop with user feedback when unavailable
  • Updated coreToolScheduler.ts to cancel the operation cleanly with error feedback when no editor is available

Error messages now explain exactly what went wrong:

  • "Vim is configured as your preferred editor but is not installed. Please install it or run /editor to choose a different editor."
  • "VS Code cannot be used in sandbox mode. Please run /editor to choose a terminal-based editor."
  • "No external editor is configured or available. Please run /editor to set your preferred editor."

Related Issues

Fixes #7669

How to Validate

  1. No editor configured:

    • Clear editor preference: run /editor and select "None"
    • Trigger a file edit that requires confirmation
    • Select "Modify with external editor"
    • Expected: If vim/neovim/emacs/helix is installed, it should auto-detect and open. Otherwise, an error message should
      appear and the operation should cancel (no infinite loop)
  2. Editor configured but not installed:

    • Set editor to one that's not installed (e.g., configure "zed" when Zed is not installed)
    • Trigger a file edit confirmation
    • Select "Modify with external editor"
    • Expected: Error message "Zed is configured as your preferred editor but is not installed..." and operation cancels
  3. GUI editor in sandbox mode:

    • Run gemini-cli in sandbox mode
    • Configure a GUI editor (vscode, cursor, etc.)
    • Trigger a file edit confirmation
    • Select "Modify with external editor"
    • Expected: Error message about sandbox mode and suggestion to use terminal editor
  4. Working editor:

    • Configure an installed editor (e.g., vim)
    • Trigger a file edit confirmation
    • Select "Modify with external editor"
    • Expected: Editor opens with diff view
  5. Run tests:

    cd packages/core                                                                                                                
    npm run test -- --run src/utils/editor.test.ts                                                                                  
    Expected: All 130 tests pass (119 original + 11 new)                                                                            
    

Pre-Merge Checklist

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

…oogle-gemini#7669)

This fix addresses the infinite loop issue reported in google-gemini#7669 where selecting
"Modify with external editor" would loop indefinitely when no editor was
configured or available.

Root cause: When getPreferredEditor() returned undefined, the code silently
returned without changing the outcome, causing the while loop to repeat.

Changes:
- Add detectFirstAvailableEditor() to auto-detect available editors
- Add resolveEditor() to handle editor resolution with proper error messages
- Update confirmation.ts to break the loop and show error when editor unavailable
- Update coreToolScheduler.ts to cancel operation with feedback when editor unavailable
- Add 11 new tests for the new editor resolution functions

The fix:
1. Properly validates editor availability before attempting to use it
2. Auto-detects an available editor if none is configured
3. Provides clear error messages explaining why the editor cannot be used
4. Breaks the loop gracefully instead of looping infinitely
@ppgranger ppgranger requested a review from a team as a code owner January 24, 2026 18:03
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ppgranger, 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 critical user experience issue where attempting to modify content with an external editor, without a valid editor configured or available, would lead to an infinite loop. The changes introduce a comprehensive editor detection and resolution system, ensuring that users receive clear feedback and the operation is gracefully cancelled instead of getting stuck.

Highlights

  • Infinite Loop Resolution: Resolved an infinite loop that occurred when attempting to 'Modify with external editor' without a properly configured or available editor, ensuring a graceful exit and user feedback.
  • Robust Editor Resolution: Introduced a new resolveEditor function that intelligently validates the preferred editor, auto-detects available editors (prioritizing terminal editors for sandbox compatibility), and generates clear, actionable error messages for various failure scenarios.
  • Enhanced User Feedback: Implemented specific error messages that explain why an editor cannot be used (e.g., not installed, sandbox mode incompatibility), guiding users on how to resolve the issue.
  • Integration and Error Handling: Integrated the new editor resolution logic into coreToolScheduler.ts and confirmation.ts to prevent silent failures, emit user-friendly error feedback, and ensure operations are cleanly cancelled when an editor is unavailable.
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 effectively resolves a critical infinite loop bug that occurred when attempting to use an external editor without one being configured or available. The introduction of the resolveEditor utility is a robust solution that properly detects available editors, provides clear user feedback on failure, and gracefully cancels the operation. The changes are well-implemented across coreToolScheduler.ts and confirmation.ts, and the new logic is thoroughly covered by unit tests.

I have one suggestion regarding the use of synchronous process execution, which could be refactored to be asynchronous to better align with project conventions for non-blocking operations.

@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Jan 24, 2026
Replace synchronous execSync calls with async alternatives in editor
detection functions to prevent blocking the Node.js event loop.

Changes:
- Add commandExistsAsync using promisified exec
- Add checkHasEditorTypeAsync, isEditorAvailableAsync,
  detectFirstAvailableEditorAsync, and resolveEditorAsync
- Update confirmation.ts and coreToolScheduler.ts to use
  resolveEditorAsync
- Mark synchronous resolveEditor as deprecated
- Add comprehensive tests for all async functions

The synchronous versions are kept for UI components that require
synchronous execution (useEditorSettings, editorSettingsManager).
Extract the platform-specific command construction into
getCommandExistsCmd() to avoid duplication between commandExists
and commandExistsAsync.
@ppgranger
Copy link
Author

Small commit : extracted the platform-specific command construction (where.exe on Windows, command -v elsewhere) into a shared getCommandExistsCmd() helper function to remove duplication between commandExists and commandExistsAsync.

@gemini-cli
Copy link
Contributor

gemini-cli bot commented Jan 27, 2026

Hi there! Thank you for your contribution to Gemini CLI. We really appreciate the time and effort you've put into this pull request.

To keep our backlog manageable and ensure we're focusing on current priorities, we are closing pull requests that haven't seen maintainer activity for 30 days. Currently, the team is prioritizing work associated with 🔒 maintainer only or help wanted issues.

If you believe this change is still critical, please feel free to comment with updated details. Otherwise, we encourage contributors to focus on open issues labeled as help wanted. Thank you for your understanding!

@gemini-cli gemini-cli bot closed this Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modify with external editor not working

3 participants