The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex-app-server): fail pending requests when stdout hits EOF
teknium11db043b3dc90
diff --git a/agent/transports/codex_app_server.py b/agent/transports/codex_app_server.pyindex 517af543342..ee399182764 100644--- a/agent/transports/codex_app_server.py+++ b/agent/transports/codex_app_server.py@@ -217,13 +217,7 @@ class CodexAppServerClient:returnsynthetic = {"error": {"code": _TRANSPORT_LOST_CODE, "message": reason}, "transportLost": True}for _rid, pending in pending_items:- try:- pending.put_nowait(synthetic)- except queue.Full:- # A real reply already landed in this queue at the same- # moment (the reader thread raced us) — the blocked- # request() call gets that instead, which is fine.- pass+ pending.put_nowait(synthetic)def __enter__(self) -> "CodexAppServerClient":return self@@ -329,6 +323,11 @@ class CodexAppServerClient:self._dispatch(msg)except Exception as exc:self._append_stderr(f"<stdout reader error> {exc}")+ finally:+ # EOF (codex died) or a reader failure: nobody will ever answer the+ # requests still waiting, so fail them now instead of letting each+ # ride out its per-call timeout.+ self._fail_pending_requests("codex app-server stdout closed")def _dispatch(self, msg: dict) -> None:if "id" in msg and ("result" in msg or "error" in msg): # replydiff --git a/tests/agent/transports/test_codex_app_server.py b/tests/agent/transports/test_codex_app_server.pyindex 1264f5601fe..c77e4c326eb 100644--- a/tests/agent/transports/test_codex_app_server.py+++ b/tests/agent/transports/test_codex_app_server.py@@ -6,6 +6,7 @@ pure in-memory queue/pipe logic, no real process.from __future__ import annotations+import osimport threadingimport timefrom unittest.mock import Mock@@ -63,3 +64,36 @@ def test_write_failure_raises_transport_error_and_drops_pending():assert isinstance(info.value, CodexAppServerError)assert "stdin closed unexpectedly" in info.value.messageassert client._pending == {}+++def test_stdout_eof_fails_in_flight_request_promptly():+ """Losing the app-server (stdout EOF) must fail a blocked request() with a transport+ error right away rather than letting it ride out its per-call timeout; the later+ close() -> _fail_pending_requests must stay a harmless no-op."""+ client = _bare_client()+ client._send = Mock()+ read_end, write_end = os.pipe()+ client._proc.stdout = os.fdopen(read_end, "rb")+ outcome: dict = {}++ def blocked():+ start = time.monotonic()+ with pytest.raises(CodexAppServerTransportError) as info:+ client.request("turn/start", {}, timeout=10.0)+ outcome["elapsed"] = time.monotonic() - start+ outcome["err"] = info.value++ reader = threading.Thread(target=client._read_stdout)+ reader.start()+ t = threading.Thread(target=blocked)+ t.start()+ time.sleep(0.05)+ os.close(write_end) # codex died: stdout hits EOF mid-request+ t.join(timeout=5)+ reader.join(timeout=5)+ assert not t.is_alive() and not reader.is_alive()+ assert outcome["elapsed"] < 2.0+ assert "stdout closed" in str(outcome["err"])+ assert client._pending == {}+ client._fail_pending_requests("codex app-server client is closing") # idempotent+ client._proc.stdout.close()