The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): high-effort reasoning no longer trips the small-prompt watchdogs
teknium1a6cad512a516
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.pyindex 4b91cf72d71..00371c2d352 100644--- a/agent/chat_completion_helpers.py+++ b/agent/chat_completion_helpers.py@@ -1084,6 +1084,23 @@ class _RequestClientRegistry:self.agent._close_request_openai_client(request_client, reason=reason)+# Silence budget for high/xhigh reasoning effort on a Codex request. GPT-5-family models at+# high effort think server-side for 100-170s before the first substantive SSE event even on a+# ~6KB prompt (#112909), while the token-sized tiers below hand such a prompt 12s/120s/90s; the+# watchdog killed healthy requests three times in a row and blamed the provider. Applies as a+# floor to the IMPLICIT defaults only -- explicit env/config values keep winning.+HIGH_EFFORT_SILENCE_FLOOR_SECONDS = 300.0+++def _high_effort_silence_floor(agent) -> float:+ """``HIGH_EFFORT_SILENCE_FLOOR_SECONDS`` when the wire reasoning config is high/xhigh and enabled, else 0."""+ cfg = getattr(agent, "reasoning_config", None)+ if not isinstance(cfg, dict) or cfg.get("enabled") is False:+ return 0.0+ effort = str(cfg.get("effort") or "").strip().lower()+ return HIGH_EFFORT_SILENCE_FLOOR_SECONDS if effort in {"high", "xhigh"} else 0.0++@dataclassclass _NonStreamWatchdogs:"""Poll-loop thresholds for one non-streaming request."""@@ -1116,6 +1133,9 @@ def _resolve_nonstream_watchdogs(agent, api_kwargs: dict) -> _NonStreamWatchdogscodex = agent.api_mode == "codex_responses"openai_codex_backend = _is_openai_codex_backend(agent)est_tokens = estimate_request_context_tokens(api_kwargs)+ effort_floor = _high_effort_silence_floor(agent) if codex else 0.0+ if effort_floor and not agent._stale_timeout_is_explicit():+ stale_timeout = max(stale_timeout, effort_floor)codex_floor = 0.0if codex and openai_codex_backend:# Raise the stale floor for large payloads so healthy gateway-scale@@ -1129,13 +1149,14 @@ def _resolve_nonstream_watchdogs(agent, api_kwargs: dict) -> _NonStreamWatchdogsif hard_timeout > 0:stale_timeout = min(stale_timeout, hard_timeout)- idle_default = next(+ idle_default = max(effort_floor, next((default for threshold, default in ((100_000, 180.0), (50_000, 120.0), (10_000, 60.0)) if est_tokens > threshold),- 12.0)+ 12.0))# No-event TTFB cutoff. Default 120s: the SDK's own read timeout is 600s,# and a tight 12s killed subscription-backed requests mid-prefill.ttfb_enabled = codex+ ttfb_explicit = env_float("HERMES_CODEX_TTFB_TIMEOUT_SECONDS", -1.0) != -1.0ttfb_timeout = env_float("HERMES_CODEX_TTFB_TIMEOUT_SECONDS", 120.0)if ttfb_timeout <= 0:ttfb_enabled = False@@ -1156,6 +1177,9 @@ def _resolve_nonstream_watchdogs(agent, api_kwargs: dict) -> _NonStreamWatchdogs"(context=~%s tokens). Set HERMES_CODEX_TTFB_MAX_SECONDS to tune.", ttfb_timeout, ttfb_cap,f"{est_tokens:,}")ttfb_timeout = ttfb_cap+ if ttfb_enabled and not ttfb_explicit:+ # High-effort thinking precedes the first event; the floor outranks the implicit cap.+ ttfb_timeout = max(ttfb_timeout, effort_floor)# An operator-set idle timeout keeps first-event semantics; only the implicit# default defers arming until model progress. Sentinel: env_float returns thediff --git a/tests/agent/test_codex_watchdog_reasoning_effort.py b/tests/agent/test_codex_watchdog_reasoning_effort.pynew file mode 100644index 00000000000..759c19d7571--- /dev/null+++ b/tests/agent/test_codex_watchdog_reasoning_effort.py@@ -0,0 +1,65 @@+"""Codex non-stream watchdogs honour the request's reasoning effort (#112909).++GPT-5-family models at ``reasoning_effort=high``/``xhigh`` think server-side for 100-170s before+their first substantive SSE event even on a ~6KB prompt, while the token-sized watchdog tiers hand+such a prompt 12s (event-idle) / 120s (TTFB) / 90s (stale) fuses — the client killed healthy+requests three times in a row and reported the provider as unavailable. High effort now raises the+IMPLICIT defaults to one shared silence floor; explicit operator values still win.+"""+from __future__ import annotations++from pathlib import Path++import pytest++_SMALL_PROMPT = {"model": "gpt-5.5", "input": [{"role": "user", "content": "x" * 6000}]}+++def _codex_agent(tmp_path: Path, monkeypatch, effort: str, *, enabled: bool = True):+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ (tmp_path / ".env").write_text("", encoding="utf-8")+ (tmp_path / "config.yaml").write_text("{}\n", encoding="utf-8")+ for var in ("HERMES_API_CALL_STALE_TIMEOUT", "HERMES_CODEX_TTFB_TIMEOUT_SECONDS",+ "HERMES_CODEX_EVENT_STALE_TIMEOUT_SECONDS", "HERMES_CODEX_TTFB_MAX_SECONDS"):+ monkeypatch.delenv(var, raising=False)+ from run_agent import AIAgent++ agent = AIAgent(+ model="gpt-5.5", provider="openai-codex", api_key="sk-dummy",+ base_url="https://chatgpt.com/backend-api/codex", quiet_mode=True,+ skip_context_files=True, skip_memory=True, platform="cli",+ )+ agent.api_mode = "codex_responses"+ agent.reasoning_config = {"enabled": enabled, "effort": effort}+ return agent++[email protected]("effort", ["high", "xhigh"])+def test_high_effort_small_prompt_gets_the_silence_floor_on_all_three_fuses(tmp_path, monkeypatch, effort):+ from agent.chat_completion_helpers import HIGH_EFFORT_SILENCE_FLOOR_SECONDS, _resolve_nonstream_watchdogs++ wd = _resolve_nonstream_watchdogs(_codex_agent(tmp_path, monkeypatch, effort), _SMALL_PROMPT)++ assert wd.idle_enabled and wd.ttfb_enabled+ assert wd.idle_timeout >= HIGH_EFFORT_SILENCE_FLOOR_SECONDS+ assert wd.ttfb_timeout >= HIGH_EFFORT_SILENCE_FLOOR_SECONDS+ assert wd.stale_timeout >= HIGH_EFFORT_SILENCE_FLOOR_SECONDS+++def test_default_effort_tiers_and_explicit_operator_values_are_untouched(tmp_path, monkeypatch):+ """Control: medium effort (and disabled reasoning) keep the small-prompt tiers; an explicit+ env value for any fuse is never raised by the floor."""+ from agent.chat_completion_helpers import _resolve_nonstream_watchdogs++ medium = _resolve_nonstream_watchdogs(_codex_agent(tmp_path, monkeypatch, "medium"), _SMALL_PROMPT)+ assert (medium.idle_timeout, medium.ttfb_timeout, medium.stale_timeout) == (12.0, 120.0, 90.0)++ disabled = _resolve_nonstream_watchdogs(_codex_agent(tmp_path, monkeypatch, "high", enabled=False), _SMALL_PROMPT)+ assert (disabled.idle_timeout, disabled.ttfb_timeout, disabled.stale_timeout) == (12.0, 120.0, 90.0)++ agent = _codex_agent(tmp_path, monkeypatch, "high")+ monkeypatch.setenv("HERMES_CODEX_EVENT_STALE_TIMEOUT_SECONDS", "20")+ monkeypatch.setenv("HERMES_CODEX_TTFB_TIMEOUT_SECONDS", "45")+ monkeypatch.setenv("HERMES_API_CALL_STALE_TIMEOUT", "75")+ explicit = _resolve_nonstream_watchdogs(agent, _SMALL_PROMPT)+ assert (explicit.idle_timeout, explicit.ttfb_timeout, explicit.stale_timeout) == (20.0, 45.0, 75.0)