fix(agent): honor HTTPS_PROXY when using custom httpx transport#12276
Closed
Atletico1999 wants to merge 1 commit into
Closed
fix(agent): honor HTTPS_PROXY when using custom httpx transport#12276Atletico1999 wants to merge 1 commit into
Atletico1999 wants to merge 1 commit into
Conversation
The OpenAI client was constructed with a custom httpx.Client(transport=HTTPTransport(socket_options=...)) to enable TCP keepalive. However, passing a pre-built transport to httpx.Client disables httpx's automatic proxy discovery from HTTPS_PROXY/HTTP_PROXY environment variables, so the agent silently bypasses the user's proxy. This is visible on WSL + Clash/V2Ray TUN-mode setups where the only working egress path is the local proxy (e.g. 127.0.0.1:7897): curl and the plain OpenAI SDK succeed in seconds, while Hermes hangs ~90s and fails with APITimeoutError on every attempt, retry-exhausts, and eventually gives up. Fix: read HTTPS_PROXY/HTTP_PROXY from env and forward it to HTTPTransport(proxy=...), preserving both the socket_options and the user's proxy configuration.
Contributor
|
Thanks @Atletico1999 — your approach was actually the most minimal of the four PRs that came in for this regression (proxy on Fixed on main via #12657 using an equivalent approach (proxy on Closing as superseded. Thanks for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_create_openai_clientbuilds a customhttpx.Clientwith a pre-configuredHTTPTransport(socket_options=...)to enable TCP keepalive. Passing a pre-built transport tohttpx.Clientdisables httpx's automatic proxy discovery fromHTTPS_PROXY/HTTP_PROXYenv vars — the agent then ignores the user's proxy and attempts a direct connection.Repro
On WSL2 with a Clash/V2Ray global-TUN proxy (
HTTPS_PROXY=http://127.0.0.1:7897):curlagainst the provider → ~5s, 200 OKopenai.OpenAI(...).chat.completions.create(...)with the default client → works finehermeschat or gateway → every attempt hangs ~90s and failsAPITimeoutError, 3 retries exhausted, eventually gives upFix
Forward
HTTPS_PROXY/HTTP_PROXY(case-insensitive) toHTTPTransport(proxy=...)when we build the transport ourselves. This restores parity with the default httpx behavior while keeping the TCP keepalive socket options intact.Verification
Same WSL environment, same model (qwen3-coder-plus on Alibaba DashScope) — time-to-first-token dropped from >90s (timeout) to ~3.6s.