Skip to content

fix(agent): preserve env proxies for custom httpx transports - #12781

Closed
oneXixi-666 wants to merge 1 commit into
NousResearch:mainfrom
oneXixi-666:fix/httpx-transport-proxy-env
Closed

fix(agent): preserve env proxies for custom httpx transports#12781
oneXixi-666 wants to merge 1 commit into
NousResearch:mainfrom
oneXixi-666:fix/httpx-transport-proxy-env

Conversation

@oneXixi-666

@oneXixi-666 oneXixi-666 commented Apr 20, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes OpenAI-compatible requests ignoring HTTPS_PROXY / HTTP_PROXY when Hermes injects a custom httpx.HTTPTransport for TCP keepalive socket options.

httpx normally reads environment proxies, but passing a custom transport bypasses that default behavior. This change preserves the existing keepalive transport while explicitly carrying the configured env proxy for non-local endpoints.

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • Added _resolve_httpx_env_proxy() to preserve HTTPS_PROXY / HTTP_PROXY for non-local endpoints.
  • Added _build_keepalive_http_transport() to keep keepalive transport construction encapsulated.
  • Updated OpenAI client construction to use the helper.
  • Added tests for proxy resolution and local endpoint exclusion.

How to Test

  1. Configure HTTPS_PROXY=http://127.0.0.1:7890 or HTTP_PROXY=http://127.0.0.1:7890.
  2. Use an OpenAI/Codex provider endpoint that requires the proxy.
  3. Run:
pytest tests/run_agent/test_create_openai_client_kwargs_isolation.py tests/run_agent/test_create_openai_client_reuse.py tests/agent/test_proxy_and_url_validation.py

Result locally:

19 passed

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Local targeted test output:

19 passed, 6 warnings

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to merged #12657 (same root cause). May already be partially fixed — verify against current main.

@alt-glitch

Copy link
Copy Markdown
Collaborator

May overlap with merged #12657.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for digging into this proxy regression and for the clean write-up — this is exactly the right fix direction. Unfortunately it's been superseded by an equivalent patch that was already merged before this PR was opened.

Automated hermes-sweeper review found:

  • _get_proxy_from_env() and _get_proxy_for_base_url() are live on main at run_agent.py lines 172–201 — same helpers this PR proposes under slightly different names.
  • _build_keepalive_http_client() already passes proxy=_get_proxy_for_base_url(base_url) alongside the custom HTTPTransport, the precise fix in this PR (run_agent.py line ~4833).
  • Commit 023208b17 (fix(agent): respect HTTP_PROXY/HTTPS_PROXY when using custom httpx transport) is the upstream implementation, cherry-picked from @heykb's PR fix(agent): respect HTTP_PROXY/HTTPS_PROXY when using custom httpx transport #12540 as part of the fix(agent): respect HTTP_PROXY/HTTPS_PROXY when using custom httpx transport #12657 salvage.
  • Regression tests covering HTTPS_PROXY forwarding and NO_PROXY exclusion are in tests/run_agent/test_create_openai_client_proxy_env.py (added in d48d6fadff6a).
  • Both shipped in release v2026.4.23 (2026-04-23).

The main-branch implementation also adds NO_PROXY awareness for local/loopback endpoints (via urllib.request.proxy_bypass_environment), which goes slightly beyond what this PR covers. Closing as already implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants