fix(core): drain stderr stream unconditionally for StdioClientTransport#25893
fix(core): drain stderr stream unconditionally for StdioClientTransport#25893spencer426 wants to merge 5 commits into
Conversation
Summary of ChangesHello, 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 issue where the Gemini CLI would hang when interacting with MCP servers that output to stderr. By ensuring the stderr stream is always consumed, the CLI avoids buffer overflows that lead to deadlocks. The implementation improves robustness by using duck-typing to handle transport wrappers, ensuring compatibility across different transport configurations. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
|
Hi @spencer426, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Size Change: +75 B (0%) Total Size: 33.7 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request modifies the createTransport function in mcp-client.ts to unconditionally attach a 'data' listener to the stderr stream of MCP transports. This is a critical fix to prevent processes from hanging when the stderr buffer fills up, regardless of whether debugMode is active. The actual logging of stderr output remains conditional on the debugMode flag. The PR also includes a new unit test to verify that the listener is correctly attached during transport creation. I have no feedback to provide as the implementation correctly addresses the issue and includes appropriate test coverage.
🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
|
This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
This PR fixes a bug where Gemini CLI hangs indefinitely when communicating with MCP servers that write to
stderrin normal mode (non-debug). The unconsumed output fills the OS pipe buffer and causes the server process to deadlock.Details
When
debugModewas false, the CLI was spawning the MCP server withstderr: 'pipe'viaStdioClientTransport, but failed to attach adatalistener to it. By unconditionally attaching a data listener (and conditionally logging based ondebugMode), the stream is always properly drained, avoiding the deadlock.I replaced the fragile
instanceof StdioClientTransportwith a duck-type check (typeof streamTransport.stderr.on === 'function') and successfully mocked this check inmcp-client.test.tsto ensure it is covered by the test suite.Related Issues
Fixes google-gemini/maintainers-gemini-cli#1632
How to Validate
npm startstderr.npm test -w @google/gemini-cli-core -- src/tools/mcp-client.test.tsto ensure the new tests and existing suite pass.Pre-Merge Checklist