From 0023f6d998137c812feee650d37f74b43d78b485 Mon Sep 17 00:00:00 2001 From: michaelxer Date: Tue, 16 Jun 2026 21:43:38 +0700 Subject: [PATCH] fix(providers): remove custom cloud httpx client, let SDK handle proxy defaults chengyongru reviewed #4367 and identified that the cloud branch created a bare httpx.AsyncClient that lacked the SDK's default settings (follow_redirects, connection pool limits). Since the SDK's DefaultAsyncHttpxClient already has trust_env=True and proper defaults, the simplest fix is to let http_client stay None for cloud endpoints. Also updated the test to match the new behavior (http_client is None). --- nanobot/providers/openai_compat_provider.py | 11 +++-------- tests/providers/test_openai_compat_timeout.py | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/nanobot/providers/openai_compat_provider.py b/nanobot/providers/openai_compat_provider.py index a3d3772c..5e2d7115 100644 --- a/nanobot/providers/openai_compat_provider.py +++ b/nanobot/providers/openai_compat_provider.py @@ -417,14 +417,9 @@ class OpenAICompatProvider(LLMProvider): timeout=timeout_s, transport=httpx.AsyncHTTPTransport(proxy=None, limits=_local_limits), ) - else: - # Cloud endpoints: respect proxy environment variables - # (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) so corporate - # or VPN proxies work without explicit configuration. - http_client = httpx.AsyncClient( - timeout=timeout_s, - trust_env=True, - ) + # else: http_client stays None → SDK creates DefaultAsyncHttpxClient + # which already reads proxy env vars via trust_env=True, has proper + # connection limits, and follows redirects. self._client = AsyncOpenAI( api_key=self._api_key_for_client, base_url=self._effective_base, diff --git a/tests/providers/test_openai_compat_timeout.py b/tests/providers/test_openai_compat_timeout.py index bf685158..519d22ec 100644 --- a/tests/providers/test_openai_compat_timeout.py +++ b/tests/providers/test_openai_compat_timeout.py @@ -16,10 +16,10 @@ async def test_openai_compat_provider_defers_sdk_client_until_first_use() -> Non kwargs = mock_async_openai.call_args.kwargs _assert_openai_compat_timeout(kwargs["timeout"]) - # Cloud endpoints get an httpx client with trust_env=True to respect - # proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY). - assert kwargs["http_client"] is not None - assert kwargs["http_client"]._trust_env is True + # Cloud endpoints pass http_client=None so the SDK creates its own + # DefaultAsyncHttpxClient, which already handles proxy env vars, + # connection limits, and redirects correctly. + assert kwargs["http_client"] is None async def test_openai_compat_provider_sets_timeout_on_local_http_client() -> None: