Skip to content

fix(core): honor http_proxy env vars via aiohttp trust_env=True#1896

Open
hao-cyber wants to merge 1 commit intoMoonshotAI:mainfrom
hao-cyber:fix/aiohttp-trust-env
Open

fix(core): honor http_proxy env vars via aiohttp trust_env=True#1896
hao-cyber wants to merge 1 commit intoMoonshotAI:mainfrom
hao-cyber:fix/aiohttp-trust-env

Conversation

@hao-cyber
Copy link
Copy Markdown

@hao-cyber hao-cyber commented Apr 15, 2026

Summary

new_client_session() constructs aiohttp.ClientSession without trust_env=True, so the standard http_proxy / https_proxy / NO_PROXY environment variables are ignored and every outbound request goes direct.

On setups where direct network access isn't available — e.g. a local HTTP proxy whose DNS only resolves for traffic routed through it — /login fails with:

Login failed: Cannot connect to host auth.kimi.com:443
ssl:default [nodename nor servname provided, or not known]

curl -x $http_proxy https://auth.kimi.com/ through the same proxy works fine, which confirms the issue is aiohttp-side, not a network / DNS / firewall problem.

Fix

One-line change in src/kimi_cli/utils/aiohttp.py: pass trust_env=True to aiohttp.ClientSession. With this, aiohttp calls urllib.request.getproxies() on each request and honors the standard env vars (both lower- and upper-case on Unix). No new dependencies, no behavior change for users without proxy env vars set.

Repro (before the fix)

  1. Run a local HTTP proxy on 127.0.0.1:7890 whose DNS only answers for traffic routed through it.
  2. export http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890.
  3. curl -I https://auth.kimi.com/ → succeeds (network path is fine).
  4. kimi/login → select any platform → DNS/connect failure as above.

After the fix, step 4 succeeds.

Notes

  • The brew-packaged kimi-cli 1.24.0 formula shipped with trust_env=True already applied (as a local patch downstream), so this looks like a regression on main.
  • Test plan: added test_session_trusts_proxy_env in tests/utils/test_aiohttp_timeout.py asserting session.trust_env is True. Existing timeout tests untouched.
  • Changelog: added an Unreleased entry under Core.

Open with Devin

new_client_session() constructed aiohttp.ClientSession without
trust_env=True, so http_proxy / https_proxy / NO_PROXY were ignored
and all outbound requests went direct. On setups where direct
network access is unavailable — e.g. a local HTTP proxy whose DNS
only resolves for traffic routed through it — /login fails with
"Cannot connect to host auth.kimi.com:443 [nodename nor servname
provided]" even though curl through the same proxy works.

Setting trust_env=True makes aiohttp call urllib.request.getproxies()
on each request and honor the standard proxy env vars (both lower-
and upper-case on Unix). No new dependencies; no behavior change for
users without proxy env vars set.

Note: brew-packaged kimi-cli 1.24.0 shipped with this fix already
applied locally, so this is a regression fix.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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