Skip to content

fix(cli): Prevent stdout/stderr patching for extension commands#13600

Merged
jacob314 merged 6 commits intomainfrom
cb/fixstdio
Nov 22, 2025
Merged

fix(cli): Prevent stdout/stderr patching for extension commands#13600
jacob314 merged 6 commits intomainfrom
cb/fixstdio

Conversation

@chrstnb
Copy link
Copy Markdown
Contributor

@chrstnb chrstnb commented Nov 21, 2025

Ended up refactoring so extension/MCP commands handle their own exiting

Details

Related Issues

How to Validate

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

The  function was being called unconditionally at the start of the CLI,
redirecting all  and  output to an event emitter. This caused
non-interactive commands, specifically , to hang
because their prompts were not being displayed to the user.

This commit modifies  to conditionally call  only when
the executed command is not an 'extensions' command. This ensures that
 and  function normally for extension commands, allowing
prompts to be displayed and user input to be handled correctly.
@chrstnb chrstnb requested a review from a team as a code owner November 21, 2025 17:24
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @chrstnb, 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 bug in the CLI where extension commands would become unresponsive because their standard output and error streams were being inappropriately redirected. The fix involves making the stream patching conditional, ensuring that extension commands can properly display prompts and receive user input, thereby restoring their intended interactive functionality.

Highlights

  • Fix for hanging extension commands: The pull request resolves an issue where non-interactive extension commands would hang due to unconditional redirection of stdout and stderr.
  • Conditional patchStdio() call: The patchStdio() function, which redirects output, is now only called if the executed command is not an 'extensions' command, preventing interference with interactive prompts.
  • Restored interactive behavior: This change ensures that stdout and stderr function normally for extension commands, allowing prompts to be displayed and user input to be handled correctly.
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
Copy Markdown
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 correctly identifies and fixes an issue where stdout/stderr patching caused extension commands to hang. The approach of conditionally patching stdio is sound. However, the implementation for detecting an extension command is too broad and could lead to false positives if a user's prompt contains the word 'extension'. My review provides a more robust implementation to prevent this potential bug.

Comment thread packages/cli/src/gemini.tsx Outdated
Comment on lines +282 to +283
const isExtensionsCommand =
process.argv.includes('extension') || process.argv.includes('extensions');
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

Using process.argv.includes() to detect an extension command is too broad and can lead to incorrect behavior. For example, a regular query like gemini "what is a chrome extension?" would be misidentified as an extension command. This would cause patchStdio() to be skipped, breaking the interactive UI rendering for that query.

To make this check more robust, you should specifically check the command argument, which is the third element in process.argv (i.e., process.argv[2]).

Suggested change
const isExtensionsCommand =
process.argv.includes('extension') || process.argv.includes('extensions');
const isExtensionsCommand = process.argv[2] === 'extension' || process.argv[2] === 'extensions';

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 21, 2025

Size Change: +388 B (0%)

Total Size: 21.1 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 21.1 MB +388 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

Comment thread packages/cli/src/gemini.tsx Outdated

const argv = await parseArguments(settings.merged);

if (
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.

where is extension command processing happening before this change? point is to not have a separate code path for it if you can avoid it. alternately if you can point me to where it is happening you can just create a shared helper for the initialization done early in runNonInteractive that makes stdout and stderr function normally now that we know the user is not interactive.

process.exit(0);
}

// If yargs handled --help/--version it will have exited; nothing to do here.
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.

great to have this removed! was quite magical.

describe: 'Manage MCP servers',
builder: (yargs: Argv) =>
yargs
.middleware(() => initializeOutputListenersAndFlush())
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.

nice!

Longer term this test should stop mocking Yargs. That is a silly thing to mock.
@jacob314 jacob314 enabled auto-merge November 21, 2025 22:26
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

Impressed by how simple the final solution for this was. Nice job!lgtm

@jacob314 jacob314 added this pull request to the merge queue Nov 22, 2025
Merged via the queue into main with commit bdf80ea Nov 22, 2025
22 checks passed
@jacob314 jacob314 deleted the cb/fixstdio branch November 22, 2025 02:09
thacio added a commit to thacio/auditaria that referenced this pull request Nov 23, 2025
werdnum pushed a commit to werdnum/gemini-cli that referenced this pull request Nov 24, 2025
mboshernitsan pushed a commit that referenced this pull request Nov 25, 2025
@chrstnb
Copy link
Copy Markdown
Contributor Author

chrstnb commented Nov 26, 2025

/patch stable

@github-actions
Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: stable
  • Commit: bdf80ea7c04652192ac663f92e99f8ab0366cd4e
  • Workflows Created: 1

🔗 Track Progress:

github-actions Bot pushed a commit that referenced this pull request Nov 26, 2025
@github-actions
Copy link
Copy Markdown

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #13861
  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.18.0
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.18.0-pr-13600

⏳ 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.18.1
  • NPM Tag: latest
  • Channel: stable
  • Dry Run: false

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

📝 What's Available:

🔗 Links:

danpalmer pushed a commit to danpalmer/gemini-cli that referenced this pull request Nov 29, 2025
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.

2 participants