Skip to content

fix(agent): exponential backoff for rate-limit fallback cooldown (#30223 salvage) - #77607

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/30223-ratelimit-backoff
Aug 3, 2026
Merged

fix(agent): exponential backoff for rate-limit fallback cooldown (#30223 salvage)#77607
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/30223-ratelimit-backoff

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Salvage of #30223 by @cicav — commit cherry-picked to preserve authorship, plus one review follow-up commit.

Context — what this changes for users

When a provider rate-limits (429), Hermes fails over to a fallback and periodically tries to restore the primary. Upstream used a flat 60s cooldown: a provider in a sustained rate-limit storm gets hammered with restore attempts every minute, re-marshaling the whole conversation across providers each time. cicav's fix escalates the cooldown exponentially so persistent 429s back off.

Review follow-up folded

The original changed the BASE cooldown 60s -> 1800s: the FIRST 429 benched the primary for 30 minutes (a 30x regression in primary-restore latency for the common transient-429 case) and broke the existing test_rate_limit_exhaustion_keeps_60s_cooldown contract. Folded: keep upstream's 60s base, escalate per CONSECUTIVE rate-limit 60s -> 2m -> 4m -> ... capped at 4h. cicav's mechanism (counter + reset-on-successful-restore) is unchanged.

Verification

  • Existing 60s contract test passes UNCHANGED (first-hit behavior is a true no-op vs upstream).
  • New tests: escalation doubling, 14400s cap, counter reset on restore.
  • Mutation: escalation disabled -> 2 fail; reset disabled -> 1 fails; 14/14 green across the 3 touched suites; ruff clean.
  • Escalation state is per-agent (same scope as upstream); other failover reasons (billing, upstream_rate_limit) flow through the same corrected path.

Closes #30223.

@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 3, 2026 11:40
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Aug 3, 2026
@Ruanjq98

Ruanjq98 commented Aug 3, 2026

Copy link
Copy Markdown

Code Review: #77607

Verdict: Approve

Trivial prompt detection: good optimization to skip memory provider on one-word prompts.

LGTM - Reviewed diff. Changes are sound.

@kshitijk4poor kshitijk4poor added the ci-reviewed applied to manually approve dangerous changes label Aug 3, 2026
cicav and others added 2 commits August 3, 2026 22:48
Replace the fixed 60-second cooldown with exponential backoff:
30min → 1h → 2h → 4h cap.

The counter is reset by restore_primary_runtime on successful
primary-provider recovery, so the backoff is strictly for
consecutive failures within a single degradation window.

Closes NousResearch#29702
…ve rate-limits

Review follow-up on the NousResearch#30223 salvage: the original changed the base
cooldown from 60s to 1800s, benching the primary for 30 minutes on the
FIRST 429 (30x regression in primary-restore latency) and breaking the
existing test_rate_limit_exhaustion_keeps_60s_cooldown contract.

Keep upstream's 60s base and escalate per consecutive rate-limit:
60s -> 2m -> 4m -> 8m -> ... capped at 4h. Counter still resets on
successful primary restore (cicae's mechanism, unchanged).

New tests: escalation doubling, 14400s cap, reset-on-restore.
Existing 60s contract test passes UNCHANGED. Mutation-checked:
escalation disabled -> 2 fail; reset disabled -> 1 fails.
@kshitijk4poor
kshitijk4poor force-pushed the salvage/30223-ratelimit-backoff branch from f79231a to f37a149 Compare August 3, 2026 17:19
@kshitijk4poor
kshitijk4poor merged commit df9dbba into NousResearch:main Aug 3, 2026
35 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/30223-ratelimit-backoff branch August 5, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-reviewed applied to manually approve dangerous changes comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants