Skip to content

Conversation

Blackoutta
Copy link
Contributor

@Blackoutta Blackoutta commented Aug 15, 2025

TLDR

Fixes #6307

Summary

This PR resolves connection issues between the Gemini CLI and IDE companion extension when running in proxy-configured environments by implementing proper proxy handling with support for NO_PROXY configuration.

Screenshot after the fix

image image

Changes Made

  • Added EnvHttpProxyAgent from the undici library to handle proxy configuration
  • Created a new createProxyAwareFetch() method that configures proxy-aware HTTP client
  • Updated IDE connection establishment to use the proxy-aware fetch implementation
  • Configured automatic bypass of proxy for localhost connections (matching common NO_PROXY patterns)
  • Enhanced error handling for connection failures with more informative messages

Technical Details

Proxy Configuration

private createProxyAwareFetch() {
  // ignore proxy for 'localhost' by default to allow connecting to the ide mcp server
  const agent = new EnvHttpProxyAgent({
    noProxy: "localhost"
  });
  
  return async (url: string | URL, init?: RequestInit): Promise<Response> => {
    // Implementation details...
  };
}

Connection Establishment Updates

Updated the establishConnection method to use the new proxy-aware fetch:

transport = new StreamableHTTPClientTransport(
  new URL(`http://${getIdeServerHost()}:${port}/mcp`),
  {
    fetch: this.createProxyAwareFetch()
  });

Benefits

  • Corporate Environment Compatibility: Users can now use IDE integration features in proxy-restricted environments
  • Proper Proxy Respect: NO_PROXY environment variable settings are properly honored
  • Default Safety: Localhost connections automatically bypass proxy routing
  • Backward Compatibility: No impact on users in non-proxy environments
  • Better Error Handling: Enhanced error messages when connections fail

Testing

  • ✅ Verified functionality in non-proxy environments (no regression)
  • ✅ Verified functionality with HTTP_PROXY configured
  • ✅ Verified functionality with HTTPS_PROXY configured
  • ✅ Verified NO_PROXY settings are properly respected
  • ✅ Verified localhost connections bypass proxy routing

Breaking Changes

None - this change is fully backward compatible.

Dive Deeper

Reviewer Test Plan

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

@Blackoutta Blackoutta requested a review from a team as a code owner August 15, 2025 08:18
Copy link

google-cla bot commented Aug 15, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
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.

Summary of Changes

Hello @Blackoutta, 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 critical connection issues between the Gemini CLI and its IDE companion extension, specifically in environments configured with HTTP/HTTPS proxies. The core of the solution involves implementing proper proxy handling, including support for the NO_PROXY environment variable and automatic bypass for localhost connections. This ensures that users in corporate or restricted network settings can seamlessly utilize IDE integration features, improving compatibility and user experience without impacting non-proxy environments.

Highlights

  • Proxy Agent Integration: The EnvHttpProxyAgent from the undici library has been integrated to provide robust and environment-aware proxy management.
  • Proxy-Aware Fetch Implementation: A new method, createProxyAwareFetch(), has been implemented to configure an HTTP client that respects system-wide proxy settings.
  • IDE Connection Update: The process for establishing a connection with the IDE companion extension has been updated to leverage the new proxy-aware fetch mechanism.
  • Localhost Bypass: The system is now configured to automatically bypass proxy routing for connections to localhost, aligning with standard NO_PROXY patterns.
  • Enhanced Error Handling: Error messages for connection failures have been improved to provide clearer and more actionable feedback to the user.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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
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 effectively addresses connection issues in proxy environments by integrating undici's EnvHttpProxyAgent. The approach of using a proxy-aware fetch implementation is sound. My review includes one high-severity suggestion to improve type safety and prevent potential runtime errors by replacing an unsafe type cast with proper Response object construction, enhancing the overall robustness of the solution.

@Blackoutta Blackoutta force-pushed the fix-ide-conn-via-http-proxy branch from b83f39f to a3aac89 Compare August 15, 2025 08:40
@Blackoutta
Copy link
Contributor Author

/gemini review

Copy link
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 adds proxy support for IDE connections, which is a great improvement for users in corporate environments. The implementation correctly uses undici's EnvHttpProxyAgent. However, I've identified a critical issue where the current implementation overrides the user's NO_PROXY environment variable, and a high-severity performance issue due to repeated dynamic imports. My review includes a single comment with a code suggestion that addresses both of these issues to make the proxy handling more robust and efficient.

@Blackoutta
Copy link
Contributor Author

/gemini review

Copy link
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 introduces proxy support for the IDE companion connection by using undici's EnvHttpProxyAgent. The changes are well-structured, adding a createProxyAwareFetch method to encapsulate the proxy logic and updating the connection establishment to use it. The error handling for connection failures has also been improved. My review includes one suggestion to simplify the implementation in createProxyAwareFetch for better performance and maintainability.

@Blackoutta Blackoutta force-pushed the fix-ide-conn-via-http-proxy branch from 38f8da6 to 7f6b9e5 Compare August 15, 2025 14:47
@Blackoutta
Copy link
Contributor Author

Hi @jacob314 , just a gentle ping to see if you’ve had a chance to look at this PR. Happy to address any feedback—thanks again for your time :)

Copy link

@Amnat-auyana1998 Amnat-auyana1998 left a comment

Choose a reason for hiding this comment

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

@Blackoutta
Copy link
Contributor Author

Hi @Amnat-auyana1998, thank you for reviewing, happy to help, let me know if there is anything I can do :)

Copy link
Collaborator

@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.

please add a test for this to avoid regressions. Aside from that change looks good to approve. Thanks for the bug fix!

`Failed to connect to IDE companion extension for ${this.currentIdeDisplayName}. Please ensure the extension is running and try restarting your terminal. To install the extension, run /ide install.`,
true,
);
logger.debug('Failed to connect to IDE companion extension. Error:\n', _error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we already log an error at line 428. Is this extra log message needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, jacob, thanks for reviewing! I needed the raw error object '_error' when I was debugging for the issue, I'll remove these two lines in my next commit, which is adding tests ;)

@Blackoutta Blackoutta force-pushed the fix-ide-conn-via-http-proxy branch from e60bfdf to a357302 Compare August 19, 2025 03:13
@Blackoutta Blackoutta requested a review from jacob314 August 19, 2025 03:14
@Blackoutta Blackoutta force-pushed the fix-ide-conn-via-http-proxy branch from 57bb770 to 9c7a6fa Compare August 19, 2025 03:15
@Blackoutta
Copy link
Contributor Author

Blackoutta commented Aug 19, 2025

Hi @jacob314,
I've gone ahead and added a new integration test and included a quality-of-life update to .vscode/launch.json that enables one-click execution of individual test files.
When you have a moment, could you take a look? Thanks!

…add one-click integration test debug cmd in .vscode/launch.json;
@Blackoutta Blackoutta force-pushed the fix-ide-conn-via-http-proxy branch from c2af554 to 0e2e2a6 Compare August 19, 2025 03:40
Copy link
Collaborator

@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.

lgtm

@jacob314 jacob314 enabled auto-merge August 20, 2025 00:22
@jacob314 jacob314 added this pull request to the merge queue Aug 20, 2025
Merged via the queue into google-gemini:main with commit d587c6f Aug 20, 2025
18 checks passed
thacio added a commit to thacio/auditaria that referenced this pull request Aug 20, 2025
agarwalravikant pushed a commit to agarwalravikant/gemini-cli that referenced this pull request Aug 20, 2025
acoliver pushed a commit to acoliver/llxprt-code that referenced this pull request Aug 20, 2025
JeongJaeSoon pushed a commit to JeongJaeSoon/gemini-cli that referenced this pull request Aug 21, 2025
Copy link

@Amnat-auyana1998 Amnat-auyana1998 left a comment

Choose a reason for hiding this comment

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

@Blackoutta Please Let me try it.I'll come back and review it for you later.

Gosling-dude pushed a commit to Gosling-dude/gemini-cli that referenced this pull request Aug 23, 2025
involvex pushed a commit to involvex/gemini-cli that referenced this pull request Sep 11, 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.

[IDE integration] Missing NO_PROXY Support Breaks IDE Companion Connections
3 participants