fix(agent): respect proxy env vars when transport is injected - #11666
Closed
a252937166 wants to merge 1 commit into
Closed
fix(agent): respect proxy env vars when transport is injected#11666a252937166 wants to merge 1 commit into
a252937166 wants to merge 1 commit into
Conversation
httpx.Client(transport=...) disables httpx's env-proxy autoconfig — proxies are a transport-layer concern and only apply when httpx constructs its own transport. _create_openai_client() injects a custom HTTPTransport to enable TCP keepalives, which silently bypasses HTTPS_PROXY / HTTP_PROXY / ALL_PROXY for every provider call. Users behind a mandatory proxy see APIConnectionError / APITimeoutError with no proxy actually in use, while curl and stock httpx work in the same shell. Read the standard proxy env vars and pass them to HTTPTransport(proxy=...) explicitly, preserving the keepalive socket options. When no proxy is set, proxy=None matches the httpx default — zero behavior change otherwise. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a252937166
force-pushed
the
fix/keepalive-transport-proxy-bypass
branch
from
April 17, 2026 15:37
fa9c206 to
e2776f2
Compare
Collaborator
Contributor
|
Thanks for the detailed write-up and for tracking down the httpx proxy bypass! This is a real bug and your diagnosis is correct. However, the same fix was already landed on
This is an automated hermes-sweeper review. Closing as already implemented on |
This was referenced Aug 3, 2026
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.
Summary
Fix a silent proxy bypass in
_create_openai_client. The customHTTPTransportused for TCP keepalives disables httpx's env-proxy autoconfig — every LLM provider call becomes a direct connection even whenHTTPS_PROXY/HTTP_PROXY/ALL_PROXYis set.Root cause
httpx.Clientonly reads proxy env vars when it constructs its own transport internally. Oncetransport=httpx.HTTPTransport(...)is passed explicitly — as the keepalive injection does — proxy resolution becomes the caller's responsibility. Nothing in_create_openai_clientwas reading the env, so proxies were silently dropped for every provider call.Impact
Users behind a mandatory proxy (corporate network, restricted egress, etc.) see:
APIConnectionError: Connection error.APITimeoutError: Request timed out.…while
curland stock httpx work in the same shell, andps eww $HERMES_PIDshowsHTTPS_PROXYis present in the agent's process env. Hard to diagnose because every surface-level check passes.Reproduction
The second call bypasses the proxy entirely and fails on any network where direct egress to the endpoint is blocked.
Fix
Read the standard proxy env vars (
HTTPS_PROXY>HTTP_PROXY>ALL_PROXY, both upper and lower case) and pass them toHTTPTransport(proxy=...). When no env var is set,proxy=Nonematches the httpx default — zero behavior change for users without a proxy.SOCKS URLs are skipped.
httpx.HTTPTransportdoes not acceptsocks5:///socks5h:///socks4://URLs without thehttpx-socksextra, and raising at client construction would regress users whose shell exportsALL_PROXY=socks5://...(common on macOS with Clash / ShadowsocksX, where the HTTP proxy env var is already the one that should be picked up). We filter SOCKS URLs out so the keepalive injection still succeeds and the HTTP proxy env var (if any) wins.Test plan
HTTPS_PROXYset in shell +~/.hermes/.env, hermes ignored it, chatgpt.com codex endpoint errored out withAPIConnectionError/APITimeoutErrorproxy=Nonepath (no env vars): behavior unchanged —HTTPTransport(proxy=None)is a no-op relative toHTTPTransport()socks5://…,socks5h://…,socks4://…,SOCKS5://…(all →None) andhttp://…,https://…,"",None(all passed through unchanged)pytest tests/run_agent/test_create_openai_client_reuse.py -vagainst the patched file — both pre-existing tests pass:test_second_create_does_not_wrap_closed_transport_from_firsttest_replace_primary_openai_client_survives_repeated_rebuildsPlatforms tested
🤖 Generated with Claude Code