refactor(stdio): always patch stdout and use createWorkingStdio for clean output
Summary
- Refactor stdout handling to ensure consistent logging capture
- Rename
createInkStdio→createWorkingStdiofor clarity - Always call
patchStdio()and usecreateWorkingStdio()for clean output
Problem
When running gemini --experimental-acp as a subprocess, the CLI hangs because logging interferes with JSON-RPC communication.
Solution
Design pattern: Always patch stdout/stderr to capture logs, but provide createWorkingStdio() as a bypass mechanism for components that need clean output (JSON-RPC, UI rendering).
This is more robust than conditionally skipping patching because:
- Logging always works consistently
- Each component explicitly opts into clean output when needed
- No risk of logs corrupting JSON output in any mode
Changes
packages/core: RenamecreateInkStdio→createWorkingStdiopackages/cli/gemini.tsx: Always callpatchStdio(); usecreateWorkingStdio()for Inkpackages/cli/zedIntegration.ts: UsecreateWorkingStdio()for JSON outputpackages/cli/nonInteractiveCli.ts: UsecreateWorkingStdio()for JSON output
Test plan
- [x] All existing tests pass
- [x] Updated ACP mode test to expect
patchStdioto be called - [x] Fixed IDE detection test pollution from environment variables
Fixes #13913
Summary of Changes
Hello @allenhutchison, I'm Gemini Code Assist[^1]! 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 where the CLI, when operating in Agent Communication Protocol (ACP) mode as a subprocess, would fail to produce output and hang. The core of the fix involves preventing the CLI's standard I/O patching mechanism from interfering with the raw stdout required for JSON-RPC communication in ACP mode. By introducing an early check for the ACP flag, the system can now conditionally bypass this patching, ensuring seamless operation for integrations that rely on ACP.
Highlights
- Fix for ACP Mode Hanging: Resolved an issue where the CLI would hang indefinitely when run in Agent Communication Protocol (ACP) mode as a subprocess, particularly when integrated with tools like Zed.
- Early ACP Mode Detection: Implemented an early detection mechanism for the
--experimental-acpflag usingprocess.argv.includes('--experimental-acp')before standard argument parsing occurs. - Conditional Stdio Patching: Modified the
mainfunction to skippatchStdio()when ACP mode is detected, allowing raw stdout for JSON-RPC communication, which was previously being redirected by internal event handlers. - Comprehensive Unit Tests: Added new unit tests to verify the
isAcpModeFromArgs()function's behavior and to ensurepatchStdiois correctly skipped in ACP mode and called in normal operation.
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 :thumbsup: and :thumbsdown: 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.
[^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.
Size Change: +160 B (0%)
Total Size: 21.5 MB
ℹ️ View Unchanged
| Filename | Size | Change |
|---|---|---|
./bundle/gemini.js |
21.4 MB | +160 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 |
Thanks so much. I ran into this problem with neovim/avante and started to solve it before noticing your work. I have one glitch I'm investigating which might be something my side. Otherwise, looks good for things like permissions flow etc.
sorry to be clear I meant this fix works.. I just meant that gemini acp in general, the features I am using are around permissions flow, etc. :shipit:
I have an ACP fix waiting for this to be merged first https://github.com/google-gemini/gemini-cli/pull/14190
@allenhutchison Heads up - this fix wasn't included in v0.19.1.
The merge went to main but the v0.19.1 release was cut from release/v0.19.0 branch without cherry-picking this commit.
Tested v0.19.1 and ACP subprocess mode still hangs. See my comment on #13913 for details.
still stuck in loading... guess another weekend with no fix :(
PLEASE, this fix is entirely blocking Zed users for weeks!
/patch preview
✅ Patch workflow(s) dispatched successfully!
📋 Details:
- Channels:
preview - Commit:
828afe113ea8f33d698e7597f240e268588aec12 - Workflows Created: 1
🔗 Track Progress:
🚀 Patch PR Created!
📋 Patch Details:
- Environment:
prod - Channel:
preview→ will publish to npm tagpreview - Commit:
828afe113ea8f33d698e7597f240e268588aec12 - Hotfix Branch:
hotfix/v0.20.0-preview.1/0.20.0-preview.2/preview/cherry-pick-828afe1/pr-14159 - Hotfix PR: #14733
📝 Next Steps:
- Review and approve the hotfix PR: #14733
- Once merged, the patch release will automatically trigger
- You'll receive updates here when the release completes
🔗 Track Progress:
🚀 Patch Release Started!
📋 Release Details:
- Environment:
prod - Channel:
preview→ publishing to npm tagpreview - Version:
v0.20.0-preview.1 - Hotfix PR: Merged ✅
- Release Branch:
release/v0.20.0-preview.1-pr-14159
⏳ Status: The patch release is now running. You'll receive another update when it completes.
🔗 Track Progress:
❌ Patch Release Failed!
📋 Details:
- Version:
0.20.0-preview.2 - Channel:
preview - Error: The patch release workflow encountered an error
🔍 Next Steps:
- Check the workflow logs for detailed error information
- The maintainers have been notified via automatic issue creation
- You may need to retry the patch once the issue is resolved
🔗 Troubleshooting:
❌ Patch Release Failed!
📋 Details:
- Version:
0.20.0-preview.3 - Channel:
preview - Error: The patch release workflow encountered an error
🔍 Next Steps:
- Check the workflow logs for detailed error information
- The maintainers have been notified via automatic issue creation
- You may need to retry the patch once the issue is resolved
🔗 Troubleshooting:
❌ Patch Release Failed!
📋 Details:
- Version:
0.20.0-preview.3 - Channel:
preview - Error: The patch release workflow encountered an error
🔍 Next Steps:
- Check the workflow logs for detailed error information
- The maintainers have been notified via automatic issue creation
- You may need to retry the patch once the issue is resolved
🔗 Troubleshooting:
❌ Patch Release Failed!
📋 Details:
- Version:
0.20.0-preview.4 - Channel:
preview - Error: The patch release workflow encountered an error
🔍 Next Steps:
- Check the workflow logs for detailed error information
- The maintainers have been notified via automatic issue creation
- You may need to retry the patch once the issue is resolved
🔗 Troubleshooting:
has this fix been released in 0.20? it seems that the patch gh action failed
the fix seems to be released in 0.20
it has, thanks.