Skip to content

fix(weixin,wecom,matrix): respect system proxy via aiohttp trust_env - #8280

Closed
MaybeRichard wants to merge 1 commit into
NousResearch:mainfrom
MaybeRichard:fix/aiohttp-trust-env-proxy
Closed

fix(weixin,wecom,matrix): respect system proxy via aiohttp trust_env#8280
MaybeRichard wants to merge 1 commit into
NousResearch:mainfrom
MaybeRichard:fix/aiohttp-trust-env-proxy

Conversation

@MaybeRichard

Copy link
Copy Markdown
Contributor

Problem

aiohttp.ClientSession defaults to trust_env=False, which means it ignores HTTP_PROXY / HTTPS_PROXY environment variables. For users behind a proxy (e.g. Clash in fake-ip mode — common in China), DNS resolves to fake IPs that only work when traffic is routed through the proxy. Since aiohttp bypasses the proxy entirely, QR login and all subsequent API calls silently fail.

This is especially impactful for Weixin and WeCom, which are Chinese services almost exclusively accessed through a proxy in practice.

Fix

Added trust_env=True to all aiohttp.ClientSession instantiations that connect to external hosts:

File Locations Connects to
gateway/platforms/weixin.py 3 places Tencent iLink API
gateway/platforms/wecom.py 1 place WeCom WebSocket API
gateway/platforms/matrix.py 1 place External image URLs

WhatsApp sessions are intentionally excluded — they only connect to 127.0.0.1 (local bridge), where proxy routing is not needed.

httpx-based adapters (dingtalk, signal, wecom_callback) are unaffected — httpx already defaults to trust_env=True.

Impact

  • No behaviour change for users not using a proxy (trust_env=True is a no-op when no proxy env vars are set)
  • Fixes Weixin QR login and runtime API calls for proxy users
  • Consistent with how most HTTP clients (curl, requests, httpx) handle proxy settings by default

aiohttp.ClientSession defaults to trust_env=False, ignoring HTTP_PROXY/
HTTPS_PROXY env vars. This causes QR login and all API calls to fail for
users behind a proxy (e.g. Clash in fake-ip mode), which is common in
China where Weixin and WeCom are primarily used.

Added trust_env=True to all aiohttp.ClientSession instantiations that
connect to external hosts (weixin: 3 places, wecom: 1, matrix: 1).
WhatsApp sessions are excluded as they only connect to localhost.

httpx-based adapters (dingtalk, signal, wecom_callback) are unaffected
as httpx defaults to trust_env=True.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@teknium1

Copy link
Copy Markdown
Contributor

Cherry-picked with authorship preserved into PR #8680 (now merged). Thank you @MaybeRichard for the fix — proxy support is critical for the Chinese user base.

@teknium1 teknium1 closed this Apr 13, 2026
luigileap added a commit to luigileap/hermes-agent that referenced this pull request Apr 16, 2026
PR NousResearch#8280 (commit cac6178, "fix(gateway): propagate user identity
through process watcher pipeline") added an early-return guard in
`GatewayRunner._handle_message`:

    elif source.user_id is None:
        logger.debug("Ignoring message with no user_id from %s", ...)
        return None

This catches Telegram service messages, channel forwards, and
anonymous admin actions that previously triggered spurious pairing
flows.

`test_session_hygiene_messages_stay_in_originating_topic` built a
`SessionSource` without `user_id`, so after the guard landed the
handler returned `None` before reaching `_run_agent`, and the
assertion `assert result == "ok"` failed.

Set `user_id="795544298"` on the synthetic source — matching the
same numeric user already used as `TELEGRAM_HOME_CHANNEL` elsewhere
in the test — so the event looks like a normal authorised message
and the handler runs the agent path the test is meant to cover.
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