From 6e03b117c85c6fc99f5e769d2bbcf49bdc11ce22 Mon Sep 17 00:00:00 2001 From: "logic.wu0" <605524858@qq.com> Date: Thu, 18 Jun 2026 21:15:29 +0800 Subject: [PATCH] fix(net): honour system proxy env vars in aiohttp sessions new_client_session() created aiohttp.ClientSession without trust_env=True, so aiohttp ignored HTTP_PROXY/HTTPS_PROXY/NO_PROXY from the environment. Behind a proxy, FetchURL/WebSearch (and every other caller of this helper) failed to reach the network even though curl worked. Set trust_env=True so all outbound requests honour the system proxy. Fixes #2455 --- src/kimi_cli/utils/aiohttp.py | 3 +++ tests/utils/test_aiohttp_timeout.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/kimi_cli/utils/aiohttp.py b/src/kimi_cli/utils/aiohttp.py index bff269076..f793509bd 100644 --- a/src/kimi_cli/utils/aiohttp.py +++ b/src/kimi_cli/utils/aiohttp.py @@ -21,4 +21,7 @@ def new_client_session( return aiohttp.ClientSession( connector=aiohttp.TCPConnector(ssl=_ssl_context), timeout=timeout or _DEFAULT_TIMEOUT, + # Honour HTTP_PROXY/HTTPS_PROXY (and NO_PROXY) from the environment, like + # curl does. aiohttp ignores them unless trust_env is set. + trust_env=True, ) diff --git a/tests/utils/test_aiohttp_timeout.py b/tests/utils/test_aiohttp_timeout.py index cfaf42909..d7dfa8db2 100644 --- a/tests/utils/test_aiohttp_timeout.py +++ b/tests/utils/test_aiohttp_timeout.py @@ -17,6 +17,16 @@ async def test_default_session_has_timeout(): assert session.timeout.sock_connect == 15 +async def test_session_trusts_env_for_proxy(): + """new_client_session() must honour HTTP(S)_PROXY env vars (trust_env=True). + + Without this, tools like FetchURL/WebSearch can't reach the network behind a + proxy even though curl can. See #2455. + """ + async with new_client_session() as session: + assert session.trust_env is True + + async def test_custom_timeout_override(): """Callers can override the default timeout.""" import aiohttp