Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(provider): honor NANOBOT_STREAM_IDLE_TIMEOUT_S in Codex provider
yeounhyeokac8bef76f6c5
diff --git a/nanobot/providers/openai_codex_provider.py b/nanobot/providers/openai_codex_provider.pyindex dee66c073..c0afdf572 100644--- a/nanobot/providers/openai_codex_provider.py+++ b/nanobot/providers/openai_codex_provider.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport asyncioimport hashlibimport json+import osfrom collections.abc import Awaitable, Callablefrom typing import Any@@ -177,7 +178,8 @@ async def _request_codex(on_content_delta: Callable[[str], Awaitable[None]] | None = None,on_tool_call_delta: Callable[[dict[str, Any]], Awaitable[None]] | None = None,) -> tuple[str, list[ToolCallRequest], str]:- async with httpx.AsyncClient(timeout=60.0, verify=verify) as client:+ idle_timeout_s = int(os.environ.get("NANOBOT_STREAM_IDLE_TIMEOUT_S", "90"))+ async with httpx.AsyncClient(timeout=idle_timeout_s, verify=verify) as client:async with client.stream("POST", url, headers=headers, json=body) as response:if response.status_code != 200:text = await response.aread()diff --git a/tests/providers/test_openai_codex_provider.py b/tests/providers/test_openai_codex_provider.pyindex 02e43638a..b3089e994 100644--- a/tests/providers/test_openai_codex_provider.py+++ b/tests/providers/test_openai_codex_provider.py@@ -76,8 +76,8 @@ async def test_codex_request_non_200_populates_http_metadata(monkeypatch) -> Nonrequest=request,)- def fake_client(*, timeout: float, verify: bool) -> httpx.AsyncClient:- assert timeout == 60.0+ def fake_client(*, timeout: int, verify: bool) -> httpx.AsyncClient:+ assert timeout == 90assert verify is Truereturn original_client(transport=httpx.MockTransport(handler), timeout=timeout)@@ -95,6 +95,27 @@ async def test_codex_request_non_200_populates_http_metadata(monkeypatch) -> Nonassert error.should_retry is True+async def test_codex_request_honors_stream_idle_timeout_env(monkeypatch) -> None:+ """NANOBOT_STREAM_IDLE_TIMEOUT_S overrides the default Codex stream timeout."""+ monkeypatch.setenv("NANOBOT_STREAM_IDLE_TIMEOUT_S", "5")+ original_client = httpx.AsyncClient+ seen: dict[str, int] = {}++ def handler(request: httpx.Request) -> httpx.Response:+ return httpx.Response(200, request=request)++ def fake_client(*, timeout: int, verify: bool) -> httpx.AsyncClient:+ seen["timeout"] = timeout+ return original_client(transport=httpx.MockTransport(handler), timeout=timeout)++ monkeypatch.setattr("nanobot.providers.openai_codex_provider.httpx.AsyncClient", fake_client)++ await _request_codex("https://codex.example/responses", {}, {"input": []}, verify=True)++ assert seen["timeout"] == 5++@pytest.mark.asyncioasync def test_codex_prompt_cache_key_uses_stable_conversation_prefix(monkeypatch) -> None:bodies: list[dict] = []