Skip to content

The agent that grows with you

fix(codex): floor every effort >= high and keep the run-budget cap over it

teknium1ebd106f3ec53
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index 00371c2d352..ec44738a7c2 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -1084,21 +1084,27 @@ 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
+# Silence budget for high-or-above 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.
+# floor to the IMPLICIT defaults only -- explicit env/config values keep winning, and the stale
+# timeout's run-budget cap is applied AFTER this floor (AIAgent._compute_non_stream_stale_timeout).
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."""
+ """``HIGH_EFFORT_SILENCE_FLOOR_SECONDS`` when the wire reasoning config is enabled at ``high`` or any
+ stronger :data:`~agent.reasoning_effort.EFFORT_LADDER` level (xhigh/max/ultra), else 0."""
+ from agent.reasoning_effort import EFFORT_LADDER
+
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
+ if effort not in EFFORT_LADDER or EFFORT_LADDER.index(effort) < EFFORT_LADDER.index("high"):
+ return 0.0
+ return HIGH_EFFORT_SILENCE_FLOOR_SECONDS
@dataclass
@@ -1129,13 +1135,13 @@ def _resolve_nonstream_watchdogs(agent, api_kwargs: dict) -> _NonStreamWatchdogs
HERMES_CODEX_TTFB_DISABLE_ABOVE_TOKENS / HERMES_CODEX_TTFB_STRICT,
HERMES_CODEX_TTFB_MAX_SECONDS, HERMES_CODEX_HARD_TIMEOUT_SECONDS.
"""
+ # The effort floor on the STALE timeout lives inside _compute_non_stream_stale_timeout so the
+ # run-budget cap still bounds it; here the floor only raises the TTFB/idle implicit defaults.
stale_timeout = agent._compute_non_stream_stale_timeout(api_kwargs)
codex = 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.0
if codex and openai_codex_backend:
# Raise the stale floor for large payloads so healthy gateway-scale
diff --git a/run_agent.py b/run_agent.py
index 2bfbf3e2e23..9c7aac289a1 100644
--- a/run_agent.py
+++ b/run_agent.py
@@ -568,14 +568,19 @@ class AIAgent(
if uses_implicit_default and base_url and is_local_endpoint(base_url):
return float("inf")
- from agent.chat_completion_helpers import estimate_request_context_tokens
+ from agent.chat_completion_helpers import _high_effort_silence_floor, estimate_request_context_tokens
est_tokens = estimate_request_context_tokens(api_payload)
timeout = max(stale_base, 240.0) if est_tokens > 100_000 else max(stale_base, 150.0) if est_tokens > 50_000 else stale_base
+ explicit = self._stale_timeout_is_explicit()
+ # High-effort Codex reasoning (#112909) floors the IMPLICIT stale timeout before the run-budget
+ # cap below, so the floor can never outlive the run budget.
+ if self.api_mode == "codex_responses" and not explicit:
+ timeout = max(timeout, _high_effort_silence_floor(self))
# Run-budget cap: an implicit stale timeout is capped at half the remaining budget (>= 60s) so one
# hung call cannot eat the run. Never raises the timeout; explicit user config still wins.
run_budget = getattr(self, "run_budget_seconds", None)
started = getattr(self, "_run_budget_started_at", None)
- if run_budget and started and not self._stale_timeout_is_explicit():
+ if run_budget and started and not explicit:
remaining = float(run_budget) - (time.time() - started)
timeout = min(timeout, max(60.0, remaining * 0.5))
return timeout
diff --git a/tests/agent/test_codex_watchdog_reasoning_effort.py b/tests/agent/test_codex_watchdog_reasoning_effort.py
index 759c19d7571..c32ad241a23 100644
--- a/tests/agent/test_codex_watchdog_reasoning_effort.py
+++ b/tests/agent/test_codex_watchdog_reasoning_effort.py
@@ -34,7 +34,7 @@ def _codex_agent(tmp_path: Path, monkeypatch, effort: str, *, enabled: bool = Tr
return agent
[email protected]("effort", ["high", "xhigh"])
[email protected]("effort", ["high", "xhigh", "max", "ultra"])
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
@@ -63,3 +63,17 @@ def test_default_effort_tiers_and_explicit_operator_values_are_untouched(tmp_pat
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)
+
+
+def test_effort_floor_never_outlives_the_run_budget_cap(tmp_path, monkeypatch):
+ """A run budget (cron/kanban) caps the IMPLICIT stale timeout at half the remaining budget; the
+ high-effort floor must be applied before that cap, not override it."""
+ import time
+
+ from agent.chat_completion_helpers import _resolve_nonstream_watchdogs
+
+ agent = _codex_agent(tmp_path, monkeypatch, "high")
+ agent.run_budget_seconds = 100
+ agent._run_budget_started_at = time.time() - 5
+
+ assert _resolve_nonstream_watchdogs(agent, _SMALL_PROMPT).stale_timeout == 60.0