Skip to content

fix(telegram): pass proxy URL explicitly to HTTPXRequest when proxy env vars are set - #8981

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-72d7991d
Apr 13, 2026
Merged

fix(telegram): pass proxy URL explicitly to HTTPXRequest when proxy env vars are set#8981
teknium1 merged 1 commit into
mainfrom
hermes/hermes-72d7991d

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Salvaged from #8931 by @MaybeRichard.

When HTTPS_PROXY / HTTP_PROXY / ALL_PROXY env vars are set, the Telegram adapter correctly detects the proxy and skips the fallback-IP transport — but then creates HTTPXRequest without passing the proxy URL explicitly, relying on httpx's trust_env mechanism. This is unreliable for HTTP CONNECT proxies (e.g. Clash/ClashMac in fake-ip mode, common for users in China), causing intermittent httpx.ConnectError / ConnectTimeout failures.

Changes

  • Replaces the inline proxy_configured boolean (which checked env vars and discarded the result) with proxy_url = resolve_proxy_url() from gateway/platforms/base.py — the shared utility that already handles env vars + macOS system proxy detection
  • Restructures the transport selection into a clean 3-way branch:
    1. Fallback-IP transport — when fallback IPs exist, no proxy, not disabled
    2. Explicit proxy — when proxy detected, pass HTTPXRequest(proxy=proxy_url) directly
    3. Plain — no proxy, no fallback IPs (or disabled)
  • Also picks up macOS system proxy (scutil --proxy) for free via resolve_proxy_url(), matching how TelegramFallbackTransport already handles proxy

Test plan

  • Gateway test suite: 239 passed (4 pre-existing failures unrelated to proxy)
  • E2E verified: resolve_proxy_url() returns correct URL with env vars set, returns None without, priority order correct (HTTPS_PROXY > HTTP_PROXY > ALL_PROXY)
  • Compile check passed

Closes #8931

…nv vars are set

When HTTPS_PROXY / HTTP_PROXY / ALL_PROXY env vars are set (or macOS system proxy
is detected), pass the proxy URL explicitly via HTTPXRequest(proxy=proxy_url) instead
of relying on httpx's trust_env mechanism, which is unreliable for HTTP CONNECT
proxies (e.g. Clash / ClashMac in fake-ip mode).

Uses the shared resolve_proxy_url() from base.py (handles env vars + macOS system
proxy detection) instead of duplicating env var reading inline. Consolidates the
proxy_configured boolean into a single proxy_url = resolve_proxy_url() call that
serves as both the gate for skipping fallback-IP transport and the value passed
to HTTPXRequest.

Co-authored-by: Hermes Agent <hermes@nousresearch.com>
Salvaged from PR #8931 by MaybeRichard.
@teknium1
teknium1 merged commit 11e2e04 into main Apr 13, 2026
2 of 4 checks passed
@teknium1
teknium1 deleted the hermes/hermes-72d7991d branch April 13, 2026 11:45
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