Skip to content

The agent that grows with you

fix(agent): configure stream_max_lifetime through config.yaml only

Tekniumb484be561039
diff --git a/agent/stream_max_lifetime.py b/agent/stream_max_lifetime.py
index 712f63e3a6c..6ebb7a9dd56 100644
--- a/agent/stream_max_lifetime.py
+++ b/agent/stream_max_lifetime.py
@@ -3,8 +3,8 @@
The stale-stream detector bounds the gap BETWEEN chunks and resets on every
chunk, so a stream that keeps yielding data but never finishes (a gateway
trickling chunks, a runaway generation) is never cut. ``agent.stream_max_lifetime``
-(env ``HERMES_STREAM_MAX_LIFETIME``) caps the wall-clock time since the current
-attempt started; it never resets on chunk arrival. Default ``0`` = off, so a
+caps the wall-clock time since the current attempt started; it never resets on
+chunk arrival. Default ``0`` = off, so a
legitimately long reasoning stream is never cut unless the user asks for it.
"""
@@ -14,8 +14,6 @@ import logging
import math
import time
-from utils import env_float
-
logger = logging.getLogger(__name__)
@@ -32,12 +30,11 @@ def resolve_stream_max_lifetime(stale_timeout: float | None) -> float:
configured = float(value)
except Exception: # unreadable config = the documented default (off)
logger.debug("stream_max_lifetime: config unreadable, cap off", exc_info=True)
- cap = env_float("HERMES_STREAM_MAX_LIFETIME", configured)
- if not cap or cap <= 0 or not math.isfinite(cap):
+ if configured <= 0 or not math.isfinite(configured):
return 0.0
if stale_timeout is not None and math.isfinite(stale_timeout):
- cap = max(cap, stale_timeout)
- return cap
+ return max(configured, stale_timeout)
+ return configured
class StreamLifetimeExceeded(TimeoutError):
@@ -45,6 +42,7 @@ class StreamLifetimeExceeded(TimeoutError):
delivering chunks, so the user-facing error names the setting, not the endpoint."""
def __init__(self, elapsed: float, cap: float):
+ self.cap = cap
super().__init__(
f"Response still streaming after {elapsed:.0f}s, cut by agent.stream_max_lifetime ({cap:g}s). "
f"Raise agent.stream_max_lifetime, or set it to 0 to turn the cap off, if this model "
diff --git a/tests/agent/test_stream_max_lifetime.py b/tests/agent/test_stream_max_lifetime.py
index 52be8958b2f..ca29bfcc625 100644
--- a/tests/agent/test_stream_max_lifetime.py
+++ b/tests/agent/test_stream_max_lifetime.py
@@ -52,6 +52,12 @@ class _DripWire:
self.base_url = f"http://127.0.0.1:{self.server.server_address[1]}/v1"
+def _set_cap(monkeypatch, tmp_path, cap):
+ """``agent.stream_max_lifetime`` in a temp HERMES_HOME config.yaml, read by the real loader."""
+ (tmp_path / "config.yaml").write_text(f"agent:\n stream_max_lifetime: {cap}\n")
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+
+
@pytest.fixture
def drip_wire():
w = _DripWire()
@@ -60,9 +66,9 @@ def drip_wire():
w.server.server_close()
-def test_cap_cuts_a_stream_that_never_goes_quiet(drip_wire, monkeypatch):
+def test_cap_cuts_a_stream_that_never_goes_quiet(drip_wire, monkeypatch, tmp_path):
+ _set_cap(monkeypatch, tmp_path, 1.5)
monkeypatch.setenv("HERMES_STREAM_STALE_TIMEOUT", "1.0")
- monkeypatch.setenv("HERMES_STREAM_MAX_LIFETIME", "1.5")
monkeypatch.setenv("HERMES_STREAM_RETRIES", "0")
monkeypatch.setenv("HERMES_STREAM_STALE_GIVEUP", "2")
agent = run_agent.AIAgent(
@@ -84,11 +90,10 @@ def test_cap_cuts_a_stream_that_never_goes_quiet(drip_wire, monkeypatch):
assert call("short").choices[0].message.content == "."
-def test_cap_is_off_by_default_and_never_undercuts_the_stale_timeout(monkeypatch):
- monkeypatch.delenv("HERMES_STREAM_MAX_LIFETIME", raising=False)
+def test_yaml_key_is_off_by_default_and_never_undercuts_the_stale_timeout(monkeypatch, tmp_path):
assert DEFAULT_CONFIG["agent"]["stream_max_lifetime"] == 0
- monkeypatch.setenv("HERMES_STREAM_MAX_LIFETIME", "60")
+ _set_cap(monkeypatch, tmp_path, 60)
assert resolve_stream_max_lifetime(180.0) == 180.0
assert resolve_stream_max_lifetime(float("inf")) == 60.0
- monkeypatch.setenv("HERMES_STREAM_MAX_LIFETIME", "0")
+ _set_cap(monkeypatch, tmp_path, 0)
assert resolve_stream_max_lifetime(180.0) == 0.0
diff --git a/website/docs/reference/environment-variables.md b/website/docs/reference/environment-variables.md
index 7528fa348c5..736aeba849a 100644
--- a/website/docs/reference/environment-variables.md
+++ b/website/docs/reference/environment-variables.md
@@ -830,7 +830,6 @@ Advanced per-platform knobs for throttling the outbound message batcher. Most us
| `HERMES_STREAM_READ_TIMEOUT` | Streaming socket read timeout in seconds (default: `120`). Auto-increased to `HERMES_API_TIMEOUT` for local providers. Increase if local LLMs time out during long code generation. |
| `HERMES_STREAM_STALE_TIMEOUT` | Stale stream detection timeout in seconds (default: `180`). Auto-disabled for local providers. Triggers connection kill if no chunks arrive within this window. |
| `HERMES_LOCAL_STREAM_STALE_TIMEOUT` | Stale stream ceiling for local providers (Ollama, oMLX, llama-cpp) in seconds (default: `900`). When the base stale timeout is at its default and a local endpoint is detected, this finite ceiling replaces the former infinite disable so a wedged local server eventually trips the detector instead of hanging forever. Also configurable via `agent.local_stream_stale_timeout` in `config.yaml`. |
-| `HERMES_STREAM_MAX_LIFETIME` | Opt-in total wall-clock cap in seconds for one streaming response attempt (default: `0`, off). Unlike the stale-stream detector it never resets on chunk arrival, so it stops a stream that keeps sending data but never finishes. Never fires before the effective stale-stream timeout. Applies to Chat Completions and Anthropic Messages streams only; Codex/Responses (`codex_responses`, including custom Responses providers) and Bedrock streams are not capped. A capped attempt is retried and does not count toward `HERMES_STREAM_STALE_GIVEUP`. Also configurable via `agent.stream_max_lifetime` in `config.yaml`. |
| `HERMES_STREAM_RETRIES` | Number of mid-stream reconnect attempts on transient network errors (default: `3`). |
| `HERMES_STREAM_STALE_GIVEUP` | Cross-turn circuit breaker: after this many consecutive stale kills (streaming or non-streaming) with no completed response, abort each call immediately with an actionable error instead of re-waiting out the stale timeout (default: `5`, `0` disables). Resets on any completed response, `/model` switch, fallback activation, or turn-start primary restore. |
| `HERMES_AGENT_TIMEOUT` | Gateway inactivity timeout for a running agent in seconds (default: `1800`, 30 minutes). Resets on every tool call and streamed token. Set to `0` to disable. |
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index a7609572844..4264bac05c2 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -1368,7 +1368,7 @@ Hermes has separate timeout layers for streaming, plus a stale detector for non-
|---------|---------|----------------|--------------|
| Socket read timeout | 120s | Auto-raised to 1800s | `HERMES_STREAM_READ_TIMEOUT` |
| Stale stream detection | 180s | Raised to a 900s ceiling (`agent.local_stream_stale_timeout`) | `HERMES_STREAM_STALE_TIMEOUT` |
-| Stream max lifetime (opt-in) | Off (`0`) | Same | `agent.stream_max_lifetime` or `HERMES_STREAM_MAX_LIFETIME` |
+| Stream max lifetime (opt-in) | Off (`0`) | Same | `agent.stream_max_lifetime` |
| Stale non-stream detection | 90s | Auto-disabled when left implicit | `providers.<id>.stale_timeout_seconds` or `HERMES_API_CALL_STALE_TIMEOUT` |
| Responses first-event watchdog | 120s | Raised to the 900s ceiling (`agent.local_stream_stale_timeout`) | `HERMES_CODEX_TTFB_TIMEOUT_SECONDS` |
| API call (non-streaming) | 1800s | Unchanged | `providers.<id>.request_timeout_seconds` / `timeout_seconds` or `HERMES_API_TIMEOUT` |