fix(core): robust workspace-based IDE connection discovery#18443
fix(core): robust workspace-based IDE connection discovery#18443ehedlund merged 10 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello @ehedlund, 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 significantly enhances the reliability of the Gemini CLI's IDE connection discovery, particularly in challenging environments like DevContainers and sandboxed systems. By moving away from a brittle PID-dependent method to a more flexible workspace-matching and process-aliveness-aware approach, it resolves common connection failures and ensures a more stable user experience. Highlights
Changelog
Activity
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. 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
|
There was a problem hiding this comment.
Code Review
This pull request significantly improves the robustness of IDE connection discovery by shifting from a strict PID-based method to a more flexible workspace-matching approach. This is a valuable change, especially for containerized and sandboxed development environments. My review highlights two critical areas for improvement to ensure the solution is fully robust. Firstly, the implementation for checking process aliveness on Windows is currently a no-op, which can lead to connection failures on that platform. Secondly, the new, more complex file sorting logic lacks sufficient automated tests to guarantee its correctness across different scenarios. Addressing these points will solidify the reliability of this new feature.
|
Can you please test on both windows & mac? I usually disable / re-enable the extension and then run CLI in an existing terminal to confirm the port file is being used (instead of falling back on stale env vars) |
|
@skeshive confirmed it's WAI on Mac, but I don't have a Windows machine to test on |
880af43
Summary
This PR improves the robustness of the IDE connection discovery mechanism in the Gemini CLI. It addresses common connection failures, especially in containerized (DevContainer) and sandboxed environments, by transitioning from a strict PID-based discovery to a PID-agnostic, workspace-matching approach.
Details
The previous implementation relied heavily on accurately traversing the process tree to find the parent IDE's PID. This was brittle because:
ptyhost), breaking the parent-child link.GEMINI_CLI_IDE_SERVER_PORT), forcing the CLI to fall back to filesystem discovery which then fails due to the PID mismatch.Changes:
getConnectionConfigFromFilenow scans the shared/tmp/gemini/ide/directory for any Gemini connection file if the specific PID match fails.process.cwd()). This ensures the CLI connects to the correct IDE window even if multiple are open.isPidAliveusingprocess.kill(pid, 0)to correctly filter out stale connection files from crashed or previous sessions.Related Issues
Fixes #13627
Fixes #13848
Fixes #15622
Fixes #18420
How to Validate
Manual Verification
The fix was verified locally by simulating the production failure:
999999) inIdeClient.getInstance()to ensure the strict PID-based discovery would fail.DEBUG=1 gemini /ide status.Automated Tests
Added a new test case in
packages/core/src/ide/ide-connection-utils.test.ts:should fall back to a different PID if it matches the current workspace: Mocks a scenario where the requested PID has no file, but a different PID file exists for the same workspace.Pre-Merge Checklist