Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4568,7 +4568,12 @@ def _create_openai_client(self, client_kwargs: dict, *, reason: str, shared: boo
# constructs a fresh one — no stale closed transport can be reused.
# Tests in ``tests/run_agent/test_create_openai_client_reuse.py`` and
# ``tests/run_agent/test_sequential_chats_live.py`` pin this invariant.
if "http_client" not in client_kwargs:
proxy_env_keys = (
"HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY",
"http_proxy", "https_proxy", "all_proxy",
)
has_proxy_env = any(os.getenv(key) for key in proxy_env_keys)
if "http_client" not in client_kwargs and not has_proxy_env:
try:
import httpx as _httpx
import socket as _socket
Expand Down
24 changes: 24 additions & 0 deletions tests/run_agent/test_create_openai_client_kwargs_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,27 @@ def test_create_openai_client_does_not_mutate_input_kwargs(mock_openai):
assert kwargs == snapshot, (
f"_create_openai_client mutated input kwargs; expected {snapshot}, got {kwargs}"
)


@patch("run_agent.OpenAI")
def test_create_openai_client_preserves_proxy_env_transport(mock_openai, monkeypatch):
mock_openai.return_value = MagicMock()
monkeypatch.setenv("https_proxy", "http://127.0.0.1:7897")
agent = AIAgent(
api_key="test-key",
base_url="https://chatgpt.com/backend-api/codex",
provider="openai-codex",
model="gpt-5.4",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)

kwargs = {
"api_key": "test-key",
"base_url": "https://chatgpt.com/backend-api/codex",
}

agent._create_openai_client(kwargs, reason="test", shared=False)

assert "http_client" not in mock_openai.call_args.kwargs