Skip to content

fix bad fallback logic external editor logic#17166

Merged
scidomino merged 1 commit into
mainfrom
tomm_ctrl_x
Jan 21, 2026
Merged

fix bad fallback logic external editor logic#17166
scidomino merged 1 commit into
mainfrom
tomm_ctrl_x

Conversation

@scidomino

Copy link
Copy Markdown
Collaborator

Summary

Fix bad fallback logic for opening external editors.

Details

This was broken in #16556

How to Validate

hit ctrl-x without an editor configured.

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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @scidomino, 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 resolves a critical bug in the external editor selection process, ensuring that the CLI correctly prioritizes user-defined environment variables (VISUAL, EDITOR) before falling back to platform-specific default editors like notepad or vi. This fix prevents unintended editor choices and improves the user experience when interacting with external editing features.

Highlights

  • External Editor Fallback Logic: Corrects the conditional logic for determining the default external editor when VISUAL and EDITOR environment variables are not explicitly set.
  • Bug Fix: Addresses a bug where the platform-specific default editor (notepad for Windows, vi for others) was incorrectly applied even if the EDITOR environment variable was defined.
  • Prioritization: Ensures that process.env['VISUAL'] and process.env['EDITOR'] are checked first, with the platform-specific default acting as a true fallback.
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.

@scidomino scidomino marked this pull request as ready for review January 21, 2026 01:57
@scidomino scidomino requested a review from a team as a code owner January 21, 2026 01:57

@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 fixes a bug in the fallback logic for determining the external editor, specifically addressing an operator precedence issue that caused it to ignore the VISUAL and EDITOR environment variables. From a security perspective, no high or critical severity vulnerabilities were identified, and the changes do not introduce issues related to command injection, input sanitization, or access control. I've also provided a suggestion to improve robustness by handling cases where VISUAL or EDITOR are set to an empty or whitespace-only string, which could lead to application crashes.

Comment on lines 2244 to +2247
command =
(process.env['VISUAL'] ??
process.env['VISUAL'] ??
process.env['EDITOR'] ??
process.platform === 'win32')
? 'notepad'
: 'vi';
(process.platform === 'win32' ? 'notepad' : 'vi');

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.

high

While this change correctly fixes the operator precedence issue, it's still vulnerable to issues if VISUAL or EDITOR are set to an empty or whitespace-only string. The nullish coalescing operator (??) will resolve to such strings, which then causes spawn to fail.

To make this more robust, I suggest trimming the environment variables and using the logical OR (||) operator. This ensures that empty or whitespace-only values are treated as "unset", correctly falling back to the next option in the chain. This aligns with the general rule to 'trim the optional string and use the fallback if the result is empty'.

Suggested change
command =
(process.env['VISUAL'] ??
process.env['VISUAL'] ??
process.env['EDITOR'] ??
process.platform === 'win32')
? 'notepad'
: 'vi';
(process.platform === 'win32' ? 'notepad' : 'vi');
command =
process.env['VISUAL']?.trim() ||
process.env['EDITOR']?.trim() ||
(process.platform === 'win32' ? 'notepad' : 'vi');
References
  1. When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 23.2 MB

ℹ️ View Unchanged
Filename Size
./bundle/gemini.js 23.2 MB
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jan 21, 2026
@scidomino scidomino added this pull request to the merge queue Jan 21, 2026
Merged via the queue into main with commit 9866eb0 Jan 21, 2026
26 checks passed
@scidomino scidomino deleted the tomm_ctrl_x branch January 21, 2026 02:58
Thomas-Shephard pushed a commit to Thomas-Shephard/gemini-cli that referenced this pull request Jan 21, 2026
@scidomino

Copy link
Copy Markdown
Collaborator Author

/patch

@github-actions

Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: stable,preview
  • Commit: 9866eb0551a3d8709f0f52b46dd7f67d6c1b26cf
  • Workflows Created: 2

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

1 similar comment
@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions

Copy link
Copy Markdown

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #17419
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

🚀 Patch Release Started!

📋 Release Details:

  • Environment: prod
  • Channel: stable → publishing to npm tag latest
  • Version: v0.25.1
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.25.1-pr-17166

⏳ Status: The patch release is now running. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

Patch Release Complete!

📦 Release Details:

  • Version: 0.25.2
  • NPM Tag: latest
  • Channel: stable
  • Dry Run: false

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
@sripasg sripasg added the size/xs An extra small PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xs An extra small PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants