Skip to content

fix(agent): normalize socks:// env proxies for httpx/anthropic#13465

Closed
UNLINEARITY wants to merge 1 commit intoNousResearch:mainfrom
UNLINEARITY:fix/proxy-socks-env-normalization
Closed

fix(agent): normalize socks:// env proxies for httpx/anthropic#13465
UNLINEARITY wants to merge 1 commit intoNousResearch:mainfrom
UNLINEARITY:fix/proxy-socks-env-normalization

Conversation

@UNLINEARITY
Copy link
Copy Markdown

WSL2 / Clash-style setups often export ALL_PROXY=socks://127.0.0.1:PORT. httpx and the Anthropic SDK reject that alias and expect socks5://, so agent startup failed early with "Unknown scheme for proxy URL" before any provider request could proceed.

What does this PR do?

Normalizes socks://... proxy environment variables to socks5://... before Hermes hands them to httpx or the Anthropic SDK.

This fixes startup failures in WSL2 / Clash-style environments where
ALL_PROXY is commonly exported as socks://127.0.0.1:<port>/. httpx
rejects that alias with Unknown scheme for proxy URL, which caused Hermes to
fail during client initialization before any provider request could proceed.

The fix is centralized in shared proxy normalization helpers and then applied
to the main agent, auxiliary client validation, Anthropic client
initialization, and gateway proxy resolution so the same environment behaves
consistently across those paths.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Added shared proxy normalization helpers in utils.py:
  • normalize_proxy_url()
  • normalize_proxy_env_vars()
  • Updated run_agent.py so _get_proxy_from_env() normalizes socks://...
    to socks5://... before handing proxy URLs to httpx
  • Updated agent/auxiliary_client.py so proxy environment variables are
    normalized before validation
  • Updated agent/anthropic_adapter.py so Anthropic client initialization
    normalizes proxy env vars before constructing the SDK client
  • Updated gateway/platforms/base.py so gateway proxy resolution also
    normalizes socks://... proxy URLs
  • Added regression tests in:
  • tests/run_agent/test_create_openai_client_proxy_env.py
  • tests/agent/test_proxy_and_url_validation.py
  • tests/gateway/test_proxy_mode.py

How to Test

  1. Export a proxy using the alias form:
    export ALL_PROXY=socks://127.0.0.1:3067/
  2. Start the Hermes path that previously failed during client initialization
    and confirm it no longer raises:
    Unknown scheme for proxy URL URL('socks://127.0.0.1:3067/')
  3. Run:
    PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 /home/nonlinear/.hermes/hermes-agent/ venv/bin/pytest -o addopts='' -p pytest_asyncio. plugin tests/run_agent/ test_create_openai_client_proxy_env. py tests/agent/ test_proxy_and_url_validation. py tests/gateway/test_proxy_mode. py
    and confirm the targeted regression suite passes (39 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: Ubuntu 24.04, Windows 11

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

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

Bug

image

Fix

image

WSL2 / Clash-style setups often export ALL_PROXY=socks://127.0.0.1:PORT. httpx and the Anthropic SDK reject that alias and expect socks5://, so agent startup failed early with "Unknown scheme for proxy URL" before any provider request could proceed.

Add shared normalize_proxy_url()/normalize_proxy_env_vars() helpers in utils.py and route all proxy entry points through them:
  - run_agent._get_proxy_from_env
  - agent.auxiliary_client._validate_proxy_env_urls
  - agent.anthropic_adapter.build_anthropic_client
  - gateway.platforms.base.resolve_proxy_url

Regression coverage:
  - run_agent proxy env resolution
  - auxiliary proxy env normalization
  - gateway proxy URL resolution

Verified with:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 /home/nonlinear/.hermes/hermes-agent/venv/bin/pytest -o addopts='' -p pytest_asyncio.plugin tests/run_agent/test_create_openai_client_proxy_env.py tests/agent/test_proxy_and_url_validation.py tests/gateway/test_proxy_mode.py

39 passed.
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.

1 participant