Repository navigation
fix: rate-limit Retry-After past maxRetryDelayMs sleeps the turn instead of failing over - #148580
Conversation
|
Codex review: blocked before merge. Reviewed September 20, 2026, 8:11 AM ET / 12:11 UTC (Revision 20). ClawSweeper reviewWhat this changesThe embedded agent runner uses the existing retry-delay cap to reach configured fallbacks sooner after long rate limits, while preserving waits when replay is unsafe or no fallback is configured. Merge readiness⛔ Blocked before merge - 3 items remain This remains useful work: current main and the latest release still accept the long wait. No blocking code defect was found, and the recorded transport proof remains relevant; approval of the changed retry contract is still unresolved. Priority: P1 Review scores
Verification
How this fits togetherThe embedded agent runner receives provider failures and decides whether to continue the current conversation or invoke existing account and model fallback handling. This change connects saved retry settings to that decision. flowchart TD
A[Provider rate-limit response] --> C[Embedded recovery controller]
B[Saved retry-delay cap] --> C
C --> D{Over cap with fallback and safe replay?}
D -->|Yes| E[Existing account and model fallback]
D -->|No| F[Wait and continue transcript]
E --> G[Reply or final failure]
F --> G
Decision needed
Why: Current documentation deliberately preserves long provider waits; the proposed contract changes that shipped behavior, and the inspected discussion does not establish maintainer acceptance. Before merge
Agent review detailsSecurityNone. PR surfaceSource +42, Tests +263, Docs 0. Total +305 across 9 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Use the existing recovery owner and saved cap, with explicit acceptance of its expanded fallback-timing contract and preserved replay-unsafe continuation. Do we have a high-confidence way to reproduce the issue? Yes: a replay-safe attempt with a header-only 9,897-second rate limit and configured fallback reaches an uncapped wait on current main. This was established from source and contributor evidence, not executed locally. Is this the best way to solve the issue? Yes, technically: carrying the existing setting into the existing controller avoids a competing threshold and preserves replay safety. Expanding its shipped meaning remains a product-policy choice. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 02c89f1b07ca. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (19 earlier review cycles; latest 8 shown)
|
c147f81 to
953ed5e
Compare
7ba3793 to
ea7c01c
Compare
|
Rebased onto current SHA mapping, since a rebase replays every commit under a new SHA:
The previous head is preserved at The rebase applied with no conflicts, but
That is a re-run of the real-transport harness on the rebased head, so the numbers differ from the ones in the body while the substance is the same. The runs were launched at low CPU and I/O priority so that the other services on the shared machine kept their share. |
|
Rebased onto SHA mapping, since the rebase replays every commit under a new SHA:
The recorded run in the PR body predates this rebase and was taken on the previous base. The behaviour under test is unchanged, and the run above is the rebased head. |
74f1144 to
efc81f1
Compare
|
Rebased onto SHA mapping, since the rebase replays every commit under a new SHA:
The previous head stays reachable at The conflict came from Verification on the rebased head, Node 24.20.0 on a 4-core Linux box:
|
fc191cc to
437d1ed
Compare
14b1a9a to
1207422
Compare
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
5b3777e to
fb68306
Compare
… instead of sleeping it Anthropic's session-window exhaustion answers 429 with "This request would exceed your account's rate limit. Please try again later." and a Retry-After equal to the window reset, measured at 3598 s to 11143 s on 2026-09-14. That text matches none of the usage-window keyword patterns, so maybeRetryTransient treats it as a temporary throttle and sleeps the whole floor inside the turn. Every scheduled job that hit it died at its own timeout with "cron: job execution timed out (last phase: model-call-started)" while agents.defaults.model.fallbacks was never tried. retry.provider.maxRetryDelayMs already means "the longest server-requested wait before the request should fail so higher-level retry logic can handle it", and the SDK honours it; the controller then slept the same delay the setting had just refused, because only maxRetries was wired through. Carry maxRetryDelayMs from the prepared session settings onto the attempt and into maybeRetryTransient next to the floor it caps. A rate-limit floor above the cap with a fallback configured now fails over immediately; with no fallback there is nothing to do but wait, so the floor is still honoured, and maxRetryDelayMs: 0 keeps its documented meaning of no cap. Floors inside the cap keep retrying on the same model. The shortcut is also gated on the attempt being replay-safe. After an exec or write, neither profile rotation nor model fallback runs downstream, so declining the wait there would end the turn instead of continuing it; that attempt keeps waiting and continuing the transcript exactly as before. Related: openclaw#143274, openclaw#145719
…ner e2e Adds an injected transport fault to the run-embedded fault-sequences e2e: a 429 whose assistant error text matches no usage-window keyword and carries the reset only in errorBody.headers["retry-after"] (~2.75h), with the operator's retry.provider.maxRetryDelayMs on the attempt. This is the real path buildAssistantFailoverSignal -> resolveRetryAfterMs -> maybeRetryTransient, not a controller mock. Without the source fix the second observed attempt is openai/mock-1 again: the runner slept the floor and retried the same model. With it the second attempt is the groq fallback, and the 9,897,000ms floor never reaches sleepWithAbort. This is the after-fix real-behavior evidence the review asked for; an injected fault stands in for an on-demand session-window 429. Related: openclaw#143274, openclaw#145719
Drive runWithModelFallback, the layer that owns the candidate chain, with two loopback HTTP servers: the primary answers 429 with the reset only in Retry-After, far above retry.provider.maxRetryDelayMs, and the fallback answers a normal completion. With the cap applied the attempt declines the multi-hour floor and the turn completes on the fallback instead of sleeping it.
The saved-cap and fresh-default paths reach the attempt differently, and a new install has no settings.json at all, so both need to show the same failover.
…xpects The fault-sequences harness handed errorBody an object where the runtime type is the provider response body string, so test-types rejected it. resolveRetryAfterMs parses a string body back to the same record, so the injected retry-after header and the assertion it drives are unchanged.
…fter the setter was removed upstream
fb68306 to
b8f4b38
Compare
|
Merged via squash.
|
…ead of failing over (openclaw#148580) * fix: fail over a rate-limit floor past retry.provider.maxRetryDelayMs instead of sleeping it Anthropic's session-window exhaustion answers 429 with "This request would exceed your account's rate limit. Please try again later." and a Retry-After equal to the window reset, measured at 3598 s to 11143 s on 2026-09-14. That text matches none of the usage-window keyword patterns, so maybeRetryTransient treats it as a temporary throttle and sleeps the whole floor inside the turn. Every scheduled job that hit it died at its own timeout with "cron: job execution timed out (last phase: model-call-started)" while agents.defaults.model.fallbacks was never tried. retry.provider.maxRetryDelayMs already means "the longest server-requested wait before the request should fail so higher-level retry logic can handle it", and the SDK honours it; the controller then slept the same delay the setting had just refused, because only maxRetries was wired through. Carry maxRetryDelayMs from the prepared session settings onto the attempt and into maybeRetryTransient next to the floor it caps. A rate-limit floor above the cap with a fallback configured now fails over immediately; with no fallback there is nothing to do but wait, so the floor is still honoured, and maxRetryDelayMs: 0 keeps its documented meaning of no cap. Floors inside the cap keep retrying on the same model. The shortcut is also gated on the attempt being replay-safe. After an exec or write, neither profile rotation nor model fallback runs downstream, so declining the wait there would end the turn instead of continuing it; that attempt keeps waiting and continuing the transcript exactly as before. Related: openclaw#143274, openclaw#145719 * test(agents): prove header-only 429 failover through the embedded runner e2e Adds an injected transport fault to the run-embedded fault-sequences e2e: a 429 whose assistant error text matches no usage-window keyword and carries the reset only in errorBody.headers["retry-after"] (~2.75h), with the operator's retry.provider.maxRetryDelayMs on the attempt. This is the real path buildAssistantFailoverSignal -> resolveRetryAfterMs -> maybeRetryTransient, not a controller mock. Without the source fix the second observed attempt is openai/mock-1 again: the runner slept the floor and retried the same model. With it the second attempt is the groq fallback, and the 9,897,000ms floor never reaches sleepWithAbort. This is the after-fix real-behavior evidence the review asked for; an injected fault stands in for an on-demand session-window 429. Related: openclaw#143274, openclaw#145719 * test(agents): prove 429 retry-after failover with the real transport Drive runWithModelFallback, the layer that owns the candidate chain, with two loopback HTTP servers: the primary answers 429 with the reset only in Retry-After, far above retry.provider.maxRetryDelayMs, and the fallback answers a normal completion. With the cap applied the attempt declines the multi-hour floor and the turn completes on the fallback instead of sleeping it. * test(agents): cover the fresh default cap alongside a saved one The saved-cap and fresh-default paths reach the attempt differently, and a new install has no settings.json at all, so both need to show the same failover. * fix(test): pass the injected error body as the body string the type expects The fault-sequences harness handed errorBody an object where the runtime type is the provider response body string, so test-types rejected it. resolveRetryAfterMs parses a string body back to the same record, so the injected retry-after header and the assertion it drives are unchanged. * test(agents): set the transient retry budget through observeAttempt after the setter was removed upstream * test(agents): drop slow retry-after transport harness --------- Co-authored-by: Altay <[email protected]>
Related: #143274 (canonical), #145719. Filed from #148558, which ClawSweeper closed into #143274 as a duplicate; this PR is the implementation of that report's proposal.
What Problem This Solves
Fixes: an agent run sleeps a
429Retry-Afterof hours inside the turn instead of failing over, when the provider's message matches no usage-window keyword. Anthropic session-window exhaustion is this shape ("Please try again later." with aRetry-Afterequal to the window reset), so every scheduled job that hits it dies at its own timeout withcron: job execution timed out (last phase: model-call-started)while the configured fallback chain is never tried.User Impact
User impact: with a fallback configured, a rate-limit floor longer than the saved
retry.provider.maxRetryDelayMs(default 60 s) now fails over to the next auth profile or model immediately, so scheduled jobs complete on the fallback instead of timing out and interactive turns do not hang for hours. Short throttles inside the cap keep retrying on the same model. Nothing changes when no fallback is configured (the floor is honoured in full), whenmaxRetryDelayMs: 0(cap disabled), or after a replay-unsafe tool action (the attempt keeps waiting and continuing the transcript, since neither rotation nor fallback can run there).Why This Change Was Made
retry.provider.maxRetryDelayMsis documented as the longest server-requested wait before "the request fails immediately ... allowing higher-level retry logic to handle it". The SDK honours that and returns control, but onlymaxRetrieswas wired into the embedded run's failover controller, somaybeRetryTransientthen slept the same delay the setting had just refused. This carriesmaxRetryDelayMsfrom the prepared session settings onto the attempt and intomaybeRetryTransientnext to the floor it caps, and treats a rate-limit floor above the cap as long-window evidence when a fallback exists and the attempt can still fail over. No new constant and no new setting; the threshold is the one the operator already configured.How this relates to the two open PRs on the same lines:
MAX_SHORT_WINDOW_RETRY_AFTER_SECONDS) when a fallback or a remaining auth profile exists. This PR uses the operator'smaxRetryDelayMsinstead of a constant, and adds the replay-safety gate that ClawSweeper's P1 on fix: exhausted subscription 429 holds the turn for hours instead of rotating auth profiles #145720 asks for: without it, a long floor after an exec or write returnsfalse,recoverEmbeddedRunAttemptexits at its replay-safety gate andhandleEmbeddedAssistantFailurerefuses fallback, so a turn that used to wait and continue now terminates. That case is covered by a recovery-level test here. fix: exhausted subscription 429 holds the turn for hours instead of rotating auth profiles #145720's remaining-auth-profile signal is complementary and not taken here;run-loop.tssits at the 700-linemax-linesceiling onmain, so wiring a new controller input needs a small refactor that deserves its own evidence.The docs sentence in
docs/concepts/retry.mdthat described the old behaviour as intended is updated to describe the cap.Evidence
The prepared head
1207422ed4ais a patch-identical rebase onto repairedmainat2ba076dc630; the stable patch ID and touched-file set are unchanged, so the prior exact-patch proof remains applicable. Cloudflare Crabbox passedgit diff --check, changed-scope guards through core production typecheck, the root/shard contract (24 tests), the focused controller and recovery suites (124 tests), and the embedded fault-sequence e2e (10 tests). Full core-test typechecking was not completed on the 12 GiB runner after 31 minutes without diagnostics; hosted CI remains required.Regression tests fail on
mainat the branch's previous base (3d21b1dce) and pass with the change, with the source patch stashed and the tests kept:The replay-safety gate has its own failing-then-passing pair. With the
failoverEligiblecheck removed from the shortcut and everything else in place:'proceed'there is the terminated turn ClawSweeper described on #145720; with the gate the attempt returns'retry'and sleeps the floor as before.The controller test uses the measured Anthropic body and a
retry-after: 9897header (resolveRetryAfterMsgives 9,897,000 ms) withmaxRetryDelayMs: 30000. Control cases that must keep their current behaviour pass in both states: the same floor with no fallback still sleeps 9,897,000 ms; cap0and capundefinedstill sleep; a 20 s floor inside the cap still retries on the same model; aserver_errorfloor is still governed by the transient time window rather than this cap. The existing 120 s and 30-day floor tests are unchanged (they run without a fallback).After-fix real behavior through the embedded runner (injected transport fault)
The fault-sequences e2e drives the real
runEmbeddedAgentand injects a 429 whose assistant error text matches no usage-window keyword and carries the reset only inerrorBody.headers["retry-after"](9897 s), with the operator'sretry.provider.maxRetryDelayMs: 30000on the attempt. This is the real pathbuildAssistantFailoverSignal->resolveRetryAfterMs->maybeRetryTransient, not a controller mock; a single openai profile and agroq/mock-2fallback are configured.The test asserts the observed provider attempts. Reverting the four source files to
upstream/mainand keeping the test, the second attempt is the same model, proving the runner slept the floor and retried instead of failing over:With the fix the second attempt is the
groqfallback, the run completes on it, andsleepWithAbortis never called with the 9,897,000 ms floor. This is the after-fix runtime evidence the review asked for: an injected transport fault standing in for an on-demand session-window 429, exercised end to end through the production runner.With the change:
src/agents/embedded-agent-runner/run/54 files, 599 tests pass; the retry-related e2e files (model-fallback.run-embedded,run-embedded-agent.auth-profile-rotation,run-embedded-agent.fault-sequences) 3 files, 63 tests pass undertest/vitest/vitest.e2e.config.ts.oxlintandoxfmt --checkclean on the changed files.run-loop.tsis deliberately untouched: it sits exactly at the 700-linemax-linesceiling onmain, which is why the cap rides the existingmaybeRetryTransientcall inattempt-recovery.tsrather than a secondsetTransientRetryBudgetargument.Live shape this fixes, from the gateway log on 2026.9.4 (host clock Pacific):
This is a library-level fix with no container to A/B; the failing-then-passing tests, including the embedded-runner e2e above, are the validation, and the deploy is the next release. An organic session-window 429 cannot be provoked on demand, which is why the e2e injects the exact transport shape rather than waiting for one; if the account's window closes again while this is open, the patched gateway log will be added here.
Contract decision
Adopted:
retry.provider.maxRetryDelayMsalso bounds fallback timing for an existing replay-safe run, so an install with a positive or default cap and a configured fallback switches account or model sooner rather than sleeping a multi-hour floor. Unchanged elsewhere: with no fallback configured the floor is honoured in full,maxRetryDelayMs: 0leaves the cap disabled, and a replay-unsafe attempt still waits and continues the transcript, since neither rotation nor fallback can run there. Thedocs/concepts/retry.mdsentence that described the previous behaviour as intended is updated to describe the cap.