The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(streaming): explicit stale_timeout_seconds wins over the context-size tier and reasoning floor
teknium180154cf3cfee
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.pyindex 68692c4e288..aec43aad82c 100644--- a/agent/chat_completion_helpers.py+++ b/agent/chat_completion_helpers.py@@ -642,7 +642,18 @@ def _cloud_stale_timeout(base: float, api_kwargs: dict) -> float:def _derive_stream_stale_timeout(agent, api_kwargs: dict) -> float:"""Stale-stream patience for a provider that is never a local endpoint (Bedrock):the OpenAI/Anthropic stale detector's budget minus its local branch."""- return _cloud_stale_timeout(_configured_stale_base(agent), api_kwargs)+ return _cloud_stale_timeout_for(agent, api_kwargs)+++def _cloud_stale_timeout_for(agent, api_kwargs: dict) -> float:+ """An explicit ``providers.<id>.stale_timeout_seconds`` is the operator's deadline and+ wins over every implicit floor — the context-size tier as well as the reasoning-model+ floor — so it can SHORTEN patience for a hung stream (#115024). Only the 180s default+ is scaled and floored."""+ explicit = get_provider_stale_timeout(agent.provider, agent.model)+ if explicit is not None:+ return explicit+ return _cloud_stale_timeout(env_float("HERMES_STREAM_STALE_TIMEOUT", 180.0), api_kwargs)def _bedrock_reasoning_stale_floor(model_id: object) -> "float | None":@@ -3611,7 +3622,7 @@ class _StreamingCall(StreamingWaitMonitor):logger.debug("Local provider detected (%s) — stale stream timeout set to %.0fs",self.agent.base_url, self._stream_stale_timeout)return- self._stream_stale_timeout = _cloud_stale_timeout(base, self.api_kwargs)+ self._stream_stale_timeout = _cloud_stale_timeout_for(self.agent, self.api_kwargs)def _partial_stream_stub(self):"""Tokens already reached the platform: a finish_reason="length" stub fires thediff --git a/tests/agent/test_reasoning_stale_timeout_floor.py b/tests/agent/test_reasoning_stale_timeout_floor.pyindex 53be45558cf..8abfbaea932 100644--- a/tests/agent/test_reasoning_stale_timeout_floor.py+++ b/tests/agent/test_reasoning_stale_timeout_floor.py@@ -248,3 +248,23 @@ def test_stream_stale_timeout_floor_for_nemotron_3_ultra():est_tokens=10_000,)assert timeout == 600.0+++def test_explicit_provider_stale_timeout_wins_over_context_tier_and_reasoning_floor(monkeypatch, tmp_path):+ """``providers.<id>.stale_timeout_seconds`` must be able to SHORTEN patience (#115024):+ a 60s explicit value on a >50k-token request for a reasoning model stays 60s, while the+ same request with no explicit value still gets the 240s tier / 600s floor (control)."""+ from types import SimpleNamespace++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ monkeypatch.delenv("HERMES_STREAM_STALE_TIMEOUT", raising=False)+ from agent.chat_completion_helpers import _derive_stream_stale_timeout++ api_kwargs = {"model": "gpt-5.6-sol", "messages": [{"role": "user", "content": "word " * 60_000}]}+ agent = SimpleNamespace(provider="custom", model="gpt-5.6-sol", base_url="https://api.example.invalid/v1")++ _write_config(tmp_path, "providers:\n custom:\n stale_timeout_seconds: 60\n")+ assert _derive_stream_stale_timeout(agent, api_kwargs) == 60.0++ _write_config(tmp_path, "")+ assert _derive_stream_stale_timeout(agent, api_kwargs) == 600.0diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex 76795cd87b8..aabb5698448 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -158,7 +158,7 @@ For AI provider setup (OpenRouter, Anthropic, Copilot, custom endpoints, self-hoYou can set `providers.<id>.request_timeout_seconds` for a provider-wide request timeout, plus `providers.<id>.models.<model>.timeout_seconds` for a model-specific override. Applies to the primary turn client on every transport (OpenAI-wire, native Anthropic, Anthropic-compatible), the fallback chain, rebuilds after credential rotation, and (for OpenAI-wire) the per-request timeout kwarg — so the configured value wins over the legacy `HERMES_API_TIMEOUT` env var.-You can also set `providers.<id>.stale_timeout_seconds` for the non-streaming stale-call detector, plus `providers.<id>.models.<model>.stale_timeout_seconds` for a model-specific override. This wins over the legacy `HERMES_API_CALL_STALE_TIMEOUT` env var.+You can also set `providers.<id>.stale_timeout_seconds` for the non-streaming stale-call detector, plus `providers.<id>.models.<model>.stale_timeout_seconds` for a model-specific override. This wins over the legacy `HERMES_API_CALL_STALE_TIMEOUT` env var. The same key is the streaming stale-stream deadline: an explicit value is used as-is — the implicit context-size tiers (240s above 50k tokens, 300s above 100k) and the reasoning-model floors apply only to the 180s default, so an explicit value can shorten how long a hung stream is tolerated.Leaving these unset keeps the legacy defaults (`HERMES_API_TIMEOUT=1800`s, `HERMES_API_CALL_STALE_TIMEOUT=90`s, native Anthropic 900s). The non-streaming stale detector is auto-disabled for local endpoints when left implicit and can scale upward for very large contexts. Not currently wired for AWS Bedrock (both `bedrock_converse` and AnthropicBedrock SDK paths use boto3 with its own timeout configuration). See the commented example in [`cli-config.yaml.example`](https://github.com/NousResearch/hermes-agent/blob/main/cli-config.yaml.example).