Skip to content

The agent that grows with you

fix: only the free tier ends a live turn on a long cooldown; paid providers wait out Retry-After again (#129410)

Siddharth Balyanca4cb9804750
diff --git a/agent/retry_utils.py b/agent/retry_utils.py
index 86c710f8916..921ac7bde86 100644
--- a/agent/retry_utils.py
+++ b/agent/retry_utils.py
@@ -174,11 +174,12 @@ def zai_coding_overload_retry_ceiling(short_attempts: int = _ZAI_CODING_OVERLOAD
return short_attempts + len(_ZAI_CODING_OVERLOAD_LONG_BACKOFF) + 1
-# Surfaces where a person watches the turn as it runs (desktop chat, TUI). A provider cooldown
-# longer than ``LIVE_RETRY_WAIT_CAP_S`` is not slept through there: a retry before the provider's
-# reset only meets the same refusal, and the person sits in front of a spinner for minutes. The
-# turn ends at once with the reset time and the ways forward instead. Background surfaces (cron,
-# batch, messaging gateways, ``hermes chat -q``) keep the long wait, capped at ``RETRY_AFTER_CAP_S``.
+# Surfaces where a person watches the turn as it runs (desktop chat, TUI). On the Nous free tier
+# a cooldown longer than ``LIVE_RETRY_WAIT_CAP_S`` is not slept through there: the free tier's
+# pause is service-wide, a retry before its reset only meets the same refusal, and the person
+# sits in front of a spinner for minutes. The turn ends at once with the reset time and the ways
+# forward instead. Every other provider, and every background surface (cron, batch, messaging
+# gateways, ``hermes chat -q``), waits out the cooldown, capped at ``RETRY_AFTER_CAP_S``.
LIVE_SURFACES = frozenset({"desktop", "tui"})
LIVE_RETRY_WAIT_CAP_S = 60.0
# Anthropic Tier 1 input-token buckets reset in ~171s, so a 120s cap re-tripped the limit; 600s
@@ -190,11 +191,6 @@ def is_live_surface(platform: Any) -> bool:
return str(platform or "").strip().lower() in LIVE_SURFACES
-def retry_wait_cap(platform: Any) -> float:
- """The longest single retry wait this surface sits through."""
- return LIVE_RETRY_WAIT_CAP_S if is_live_surface(platform) else RETRY_AFTER_CAP_S
-
-
def provider_retry_after_seconds(error: Any) -> Optional[float]:
"""Provider-declared cooldown: the ``Retry-After`` header, else a ``retry_after`` body field
(top level or nested under ``error``). None when absent, unparseable or zero — a zero/expired
diff --git a/agent/turn_api_error.py b/agent/turn_api_error.py
index a2d6597aff3..3a4c788e2a3 100644
--- a/agent/turn_api_error.py
+++ b/agent/turn_api_error.py
@@ -353,11 +353,11 @@ def settle_unrecovered_error(
base_url=_base, model=_model, delivered=_delivered,
))
- # A cooldown the live surface will not sit through ends the attempt cycle now (fallback,
- # else the reset time and the ways forward); the copy counts the attempts actually made.
+ # A free-tier cooldown the live surface will not sit through ends the attempt cycle now
+ # (fallback, else the reset time and the ways forward); the copy counts the attempts made.
attempts_made = retry_count
- if is_rate_limited and retry_count < max_retries and cooldown_outlasts_live_wait(agent, api_error):
- logger.info("%sProvider cooldown outlasts the live wait cap — ending retries after attempt %s",
+ if is_rate_limited and retry_count < max_retries and cooldown_outlasts_live_wait(agent, api_error, _base):
+ logger.info("%sFree-tier cooldown outlasts the live wait cap — ending retries after attempt %s",
agent.log_prefix, retry_count)
retry_count = max_retries
if retry_count >= max_retries:
diff --git a/agent/turn_recovery.py b/agent/turn_recovery.py
index 1a3ff511780..f3b161a96f4 100644
--- a/agent/turn_recovery.py
+++ b/agent/turn_recovery.py
@@ -1472,13 +1472,15 @@ def _is_welcome_guest(agent: Any, base_url: Any) -> bool:
return False
-def cooldown_outlasts_live_wait(agent: Any, api_error: Exception) -> bool:
- """True on a live surface when the provider's declared cooldown is longer than the surface
- sits through. A retry before that reset only meets the same refusal (the free tier's
- service-wide pause answered a 600 s retry with a second 429 while its 1069 s window ran),
- so the caller ends the attempt cycle now: fallback, or the reset time and the ways forward."""
+def cooldown_outlasts_live_wait(agent: Any, api_error: Exception, base_url: Any) -> bool:
+ """True when a live surface on the Nous free tier's host meets a cooldown longer than it sits
+ through. The free tier's pause is service-wide: a 600 s retry met a second 429 while its
+ 1069 s window ran, so the caller ends the attempt cycle now (fallback, or the reset time and
+ the sign-in / model doors). Every other provider waits out its ``Retry-After`` as before: a
+ paid bucket reopens on time, and ``fallback.min_switch_reset_seconds`` relies on that wait."""
from agent.retry_utils import LIVE_RETRY_WAIT_CAP_S, is_live_surface, provider_retry_after_seconds
- if not is_live_surface(getattr(agent, "platform", "")):
+ from hermes_cli.anon_auth import route_is_welcome_host
+ if not (is_live_surface(getattr(agent, "platform", "")) and route_is_welcome_host(base_url)):
return False
cooldown = provider_retry_after_seconds(api_error)
return cooldown is not None and cooldown > LIVE_RETRY_WAIT_CAP_S
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 9accec0e403..16442a35292 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -1234,7 +1234,7 @@ agent:
`agent.api_max_retries` controls how many times Hermes retries a provider API call on transient errors (rate limits, connection drops, 5xx) **before** fallback-provider switching engages. The default is `3` — four attempts total. If you have [fallback providers](./features/fallback-providers.md) configured and want to fail over faster, drop this to `0` so the first transient error on your primary immediately hands off to the fallback instead of churning retries against the flaky endpoint.
-A rate limit that names its reset (`Retry-After` or a `retry_after` body field) is waited out, capped at 600 s per retry. The Desktop app and the TUI do not sit through a cooldown longer than 60 s: a retry before the reset only meets the same refusal. The turn ends at once and says when the limit lifts, and a configured fallback runs first. Cron jobs, messaging platforms and `hermes chat -q` keep the long wait, and every wait over a minute is announced when it starts.
+A rate limit that names its reset (`Retry-After` or a `retry_after` body field) is waited out, capped at 600 s per retry. The Desktop app and the TUI announce a rate-limit wait when it starts. One exception: on the free Nous tier (no sign-in), the Desktop app and the TUI do not sit through a cooldown longer than 60 s, because the free tier's pause covers the whole service and a retry before the reset only meets the same refusal. The turn ends at once and says when the limit lifts, and a configured fallback runs first. Every wait over a minute is announced when it starts.
`agent.auto_recovery_cycles` is the safety net *after* both the retries and the fallback chain are spent. When the failure is a transient outage (HTTP 5xx, an `overloaded`/529 response, a connect or read timeout) and no answer text has reached you yet, Hermes does not end the turn with "API failed after N retries" — it waits and tries again, up to this many cycles (default `5`), with a jittered 15/30/60/60/60 s schedule. A provider `Retry-After` header wins over the schedule (honoured up to 120 s). Every surface shows the same line while it waits — `⏳ Provider temporarily unavailable — retrying automatically in 30s (cycle 2/5); press Esc to stop` on the CLI/TUI/Desktop, a status bubble on messaging platforms (`send /stop to cancel`), a `hermes.status` SSE event on the API server, and a log line for cron jobs. Pressing Esc (or `/stop`) cancels the wait immediately. Fallback still comes first: with a fallback chain configured, exhaustion moves to the next provider as before, and the ladder only engages once the chain has nothing left. Authentication, billing, request-format, entitlement, content-policy and account-policy errors never enter the ladder. Set `0` to disable it.