Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(providers): disable sync and async proxy routing

warren6185ec7dec2be25
diff --git a/.gitignore b/.gitignore
index a31a0cc64..3275b4e90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -109,5 +109,3 @@ desktop/electron/dist/
wiki/alpha-library/manifest.json
wiki/alpha-library/content/
bench_report.json
-
-.idea/*
diff --git a/agent/.env.example b/agent/.env.example
index 5afd52e1e..aa7d15746 100644
--- a/agent/.env.example
+++ b/agent/.env.example
@@ -128,6 +128,9 @@ OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
LANGCHAIN_TEMPERATURE=0.0
TIMEOUT_SECONDS=120
MAX_RETRIES=2
+# Ignore HTTP_PROXY/HTTPS_PROXY for OpenAI-compatible LLM requests only. The
+# explicit direct transports still honor SSL_CERT_FILE/SSL_CERT_DIR.
+# VIBE_TRADING_DISABLE_HTTP_PROXY=0
# Reasoning effort: none / low / medium / high / max. Two delivery paths:
# * Relays requiring opt-in (OpenRouter, Requesty) get extra_body.reasoning.effort.
diff --git a/agent/src/providers/llm.py b/agent/src/providers/llm.py
index d30d40821..264ab5013 100644
--- a/agent/src/providers/llm.py
+++ b/agent/src/providers/llm.py
@@ -41,6 +41,33 @@ try:
except ImportError:
httpx = None # type: ignore
+
+def _build_proxy_free_http_clients() -> tuple[Any, Any]:
+ """Build sync and async HTTPX clients that ignore proxy environment vars.
+
+ Supplying an explicit transport prevents ``httpx.Client`` from installing
+ proxy mounts discovered from HTTP(S)_PROXY. ``trust_env`` remains enabled
+ on the transports so SSL_CERT_FILE and SSL_CERT_DIR still work for private
+ certificate authorities.
+
+ Returns:
+ A ``(sync_client, async_client)`` pair for the OpenAI SDK.
+
+ Raises:
+ RuntimeError: If HTTPX is unavailable while proxy disabling is enabled.
+ """
+ if httpx is None:
+ raise RuntimeError(
+ "VIBE_TRADING_DISABLE_HTTP_PROXY requires the httpx package"
+ )
+ sync_transport = httpx.HTTPTransport(proxy=None, trust_env=True)
+ async_transport = httpx.AsyncHTTPTransport(proxy=None, trust_env=True)
+ return (
+ httpx.Client(transport=sync_transport),
+ httpx.AsyncClient(transport=async_transport),
+ )
+
+
_AMBIENT_OPENAI_HEADER_ENV_VARS = (
"OPENAI_CUSTOM_HEADERS",
"OPENAI_ORG_ID",
@@ -1100,7 +1127,8 @@ def build_llm(*, model_name: Optional[str] = None, callbacks: Any = None) -> Any
headers["User-Agent"] = custom_ua
_validate_explicit_headers(headers, source=f"{caps.name} provider configuration")
kwargs["default_headers"] = headers
- if get_env_config().llm.vibe_trading_disable_http_proxy and httpx is not None:
- kwargs["http_client"] = httpx.Client(proxy=None)
- kwargs["http_socket_options"] = ()
+ if get_env_config().llm.vibe_trading_disable_http_proxy:
+ sync_client, async_client = _build_proxy_free_http_clients()
+ kwargs["http_client"] = sync_client
+ kwargs["http_async_client"] = async_client
return ChatOpenAIWithReasoning(**kwargs)
diff --git a/agent/tests/test_env_schema.py b/agent/tests/test_env_schema.py
index 0d65991a4..3d93b860e 100644
--- a/agent/tests/test_env_schema.py
+++ b/agent/tests/test_env_schema.py
@@ -73,6 +73,7 @@ class TestEnvConfigDefaults:
assert c.llm.langchain_model_name == ""
assert c.llm.langchain_temperature == 0.0
assert c.llm.timeout_seconds == 120
+ assert c.llm.vibe_trading_disable_http_proxy is False
assert c.llm.max_retries == 2
assert c.llm.langchain_reasoning_effort == ""
assert c.llm.vibe_trading_deepseek_adapter == "auto"
diff --git a/agent/tests/test_llm.py b/agent/tests/test_llm.py
index 176cfb586..5aaf75697 100644
--- a/agent/tests/test_llm.py
+++ b/agent/tests/test_llm.py
@@ -511,6 +511,83 @@ class TestMinimaxTemperature:
assert captured["temperature"] == 0.7
+class TestDisableHttpProxy:
+ """The proxy opt-out must cover both OpenAI SDK execution paths."""
+
+ def test_build_llm_passes_sync_and_async_direct_clients(self) -> None:
+ import src.providers.llm as llm_mod
+
+ llm_mod._dotenv_loaded = True
+ captured: dict[str, object] = {}
+ sync_client = object()
+ async_client = object()
+
+ class _FakeChatOpenAI:
+ def __init__(self, **kwargs: object) -> None:
+ captured.update(kwargs)
+
+ env = {
+ "LANGCHAIN_PROVIDER": "openai",
+ "OPENAI_API_KEY": "sk-test",
+ "LANGCHAIN_MODEL_NAME": "gpt-4o-mini",
+ "VIBE_TRADING_DISABLE_HTTP_PROXY": "1",
+ }
+ with patch.dict(os.environ, env, clear=True):
+ with patch.object(
+ llm_mod,
+ "_build_proxy_free_http_clients",
+ return_value=(sync_client, async_client),
+ ) as build_clients:
+ with patch.object(llm_mod, "ChatOpenAIWithReasoning", _FakeChatOpenAI):
+ build_llm()
+
+ build_clients.assert_called_once_with()
+ assert captured["http_client"] is sync_client
+ assert captured["http_async_client"] is async_client
+ assert "http_socket_options" not in captured
+
+ def test_build_llm_leaves_default_transport_when_disabled(self) -> None:
+ import src.providers.llm as llm_mod
+
+ llm_mod._dotenv_loaded = True
+ captured: dict[str, object] = {}
+
+ class _FakeChatOpenAI:
+ def __init__(self, **kwargs: object) -> None:
+ captured.update(kwargs)
+
+ env = {
+ "LANGCHAIN_PROVIDER": "openai",
+ "OPENAI_API_KEY": "sk-test",
+ "LANGCHAIN_MODEL_NAME": "gpt-4o-mini",
+ "VIBE_TRADING_DISABLE_HTTP_PROXY": "0",
+ }
+ with patch.dict(os.environ, env, clear=True):
+ with patch.object(llm_mod, "ChatOpenAIWithReasoning", _FakeChatOpenAI):
+ build_llm()
+
+ assert "http_client" not in captured
+ assert "http_async_client" not in captured
+
+ def test_direct_clients_do_not_install_environment_proxy_mounts(self) -> None:
+ import asyncio
+ import src.providers.llm as llm_mod
+
+ env = {
+ "HTTP_PROXY": "http://proxy.invalid:8080",
+ "HTTPS_PROXY": "http://proxy.invalid:8080",
+ "ALL_PROXY": "socks5://proxy.invalid:1080",
+ }
+ with patch.dict(os.environ, env, clear=False):
+ sync_client, async_client = llm_mod._build_proxy_free_http_clients()
+ try:
+ assert sync_client._mounts == {}
+ assert async_client._mounts == {}
+ finally:
+ sync_client.close()
+ asyncio.run(async_client.aclose())
+
+
# ---------------------------------------------------------------------------
# Kimi K-series temperature forcing
# ---------------------------------------------------------------------------