Skip to content

Comments

fix: resolve infinite loop when using 'Modify with external editor'#17453

Merged
scidomino merged 16 commits intogoogle-gemini:mainfrom
ppgranger:fix/modify-with-external-editor-infinite-loop-7669
Feb 5, 2026
Merged

fix: resolve infinite loop when using 'Modify with external editor'#17453
scidomino merged 16 commits intogoogle-gemini:mainfrom
ppgranger:fix/modify-with-external-editor-infinite-loop-7669

Conversation

@ppgranger
Copy link
Contributor

@ppgranger ppgranger commented Jan 24, 2026

Summary

Fix infinite loop when selecting "Modify with external editor" without a configured or available editor. Also improve the user experience by prompting the user to select an editor interactively.

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 resolveEditorAsync() - validates availability of preferred editor and prompts the user to select an editor
  • Updated confirmation.ts to check editor resolution result and return to previous screen when unavailable

Related Issues

Fixes #7669

How to Validate

  1. Run npm run start in a workspace where preferredEditor is NOT set in settings.json.
  2. Ask Gemini to make a code change (e.g., "add a comment to README.md").
  3. When prompted to confirm, select Modify with Editor.
  4. Observe that the "choose an editor" dialog appeared.
  5. Hit Esc or choose "none" in the editor dialog.
  6. Observe that you are returned to the accept once / accept always prompt with an error message, instead of the turn being cancelled.
  7. Try again, but this time select an editor (e.g., vim).
  8. Observe that vim opens with the diff.

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
Contributor 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
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Jan 28, 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 28, 2026
@ppgranger
Copy link
Contributor Author

Hi @jackwotherspoon , I'm a bit confused regarding the status of the PR, gemini-cli still closing it every day ...

@bdmorgan bdmorgan reopened this Feb 1, 2026
@bdmorgan bdmorgan added 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 Feb 1, 2026
@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Feb 2, 2026
@ehedlund
Copy link
Contributor

ehedlund commented Feb 3, 2026

Hi @ppgranger, could you please fix the current build errors?

ppgranger and others added 2 commits February 4, 2026 13:56
Replace direct property access with 'in' operator to properly narrow the
union type, fixing TypeScript compilation error.
@ppgranger
Copy link
Contributor Author

Hi @ehedlund, done :)
P.

ehedlund and others added 5 commits February 4, 2026 14:00
- Fixes an infinite loop when using 'Modify with Editor' without a configured editor.
- Implements interactive editor selection via a UI dialog.
- Returns to the previous confirmation prompt if selection is cancelled or fails.
- Simplifies editor availability logic and removes deprecated sync functions.

Fixes google-gemini#7669
The test was timing out because resolveEditorAsync waits for an
EditorSelected event when no editor is available. Mock the function
to return 'vscode' directly.
@ehedlund ehedlund changed the title fix: resolve infinite loop when using 'Modify with external editor' (… fix: resolve infinite loop when using 'Modify with external editor' Feb 4, 2026
@ehedlund
Copy link
Contributor

ehedlund commented Feb 4, 2026

/gemini review

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

The pull request effectively resolves the infinite loop issue when using 'Modify with external editor' without a configured or available editor. The introduction of resolveEditorAsync() and the associated event-driven editor selection mechanism significantly improves the user experience by allowing interactive editor selection and providing clear feedback when an editor is unavailable. The changes are well-implemented, include appropriate error handling, and are supported by comprehensive tests for the new asynchronous editor resolution logic.

@ppgranger
Copy link
Contributor Author

Hi @ehedlund , any plan to merge this PR :)? Would like me to add something?

@ehedlund
Copy link
Contributor

ehedlund commented Feb 5, 2026

@ppgranger yes we plan to merge this, no action needed from you

- Remove redundant `success` field from ExternalModificationResult,
  check for error presence instead
- Rename checkHasEditorType to hasValidEditorCommand for clarity
- Run command existence checks in parallel in hasValidEditorCommandAsync
- Simplify JSDoc comment for isEditorAvailableAsync
@ppgranger ppgranger requested a review from scidomino February 5, 2026 19:32
ppgranger and others added 2 commits February 5, 2026 20:33
- Remove redundant `if (modResult.error)` check
- Update parallel implementation of `hasValidEditorCommandAsync` to short-circuit return true as soon as the first command is found to exist
@ppgranger
Copy link
Contributor Author

@scidomino @ehedlund
Just addressed PR review comment :)

@scidomino scidomino added this pull request to the merge queue Feb 5, 2026
Merged via the queue into google-gemini:main with commit 2498114 Feb 5, 2026
26 checks passed
@ppgranger ppgranger deleted the fix/modify-with-external-editor-infinite-loop-7669 branch February 5, 2026 21:36
sidwan02 pushed a commit to sidwan02/gemini-cli-gemma that referenced this pull request Feb 6, 2026
…oogle-gemini#17453)

Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
Co-authored-by: ehedlund <ehedlund@google.com>
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
…oogle-gemini#17453)

Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
Co-authored-by: ehedlund <ehedlund@google.com>
@Ignacioscript
Copy link

Did this issue finally get resolved?

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! 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. 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

6 participants