Skip to content

fix(agent): honor HTTPS_PROXY when using custom httpx transport#12276

Closed
Atletico1999 wants to merge 1 commit into
NousResearch:mainfrom
Atletico1999:fix/httpx-custom-transport-honor-proxy
Closed

fix(agent): honor HTTPS_PROXY when using custom httpx transport#12276
Atletico1999 wants to merge 1 commit into
NousResearch:mainfrom
Atletico1999:fix/httpx-custom-transport-honor-proxy

Conversation

@Atletico1999

Copy link
Copy Markdown

Problem

_create_openai_client builds a custom httpx.Client with a pre-configured HTTPTransport(socket_options=...) to enable TCP keepalive. Passing a pre-built transport to httpx.Client disables httpx's automatic proxy discovery from HTTPS_PROXY / HTTP_PROXY env 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):

  • curl against the provider → ~5s, 200 OK
  • Plain openai.OpenAI(...).chat.completions.create(...) with the default client → works fine
  • hermes chat or gateway → every attempt hangs ~90s and fails APITimeoutError, 3 retries exhausted, eventually gives up

Fix

Forward HTTPS_PROXY / HTTP_PROXY (case-insensitive) to HTTPTransport(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.

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

Copy link
Copy Markdown
Contributor

Thanks @Atletico1999 — your approach was actually the most minimal of the four PRs that came in for this regression (proxy on HTTPTransport(proxy=...) directly).

Fixed on main via #12657 using an equivalent approach (proxy on Client(proxy=...) instead of HTTPTransport(...) — httpx routes them through the same proxy pool via _init_proxy_transport), plus tests and a reusable _get_proxy_from_env() helper.

Closing as superseded. Thanks for the fix!

@teknium1 teknium1 closed this Apr 19, 2026
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.

2 participants