Skip to content

fix(failover): reject long-window rate limits by Retry-After magnitude - #179967

Closed
coaiMax wants to merge 1 commit into
openclaw:mainfrom
coaiMax:fix/179962-long-window-retry-after-magnitude
Closed

coaiMax wants to merge 1 commit into
openclaw:mainfrom
coaiMax:fix/179962-long-window-retry-after-magnitude

Conversation

@coaiMax

@coaiMax coaiMax commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closes #179962

What Problem This Solves

When a provider (e.g. a LiteLLM proxy) wraps its upstream 429 in a Python-style dict, OpenClaw's diagnostic redaction replaces the error message with [Malformed diagnostic JSON redacted] before hasLongWindowRateLimitEvidence inspects it. The keyword regex then finds no usage-limit/subscription evidence, maybeRetryTransient accepts the retry, and the session is held for the full Retry-After duration (hours) with no user-visible explanation.

User Impact

A cron-job failure-repair turn received a 429 with Retry-After: 41294 (≈11.5 h). The session was held for ~6 hours until a gateway restart. Every message the user sent meanwhile was silently queued. Nothing in the client indicated why.

Why This Change Was Made

classifyRateLimitWindow already treats Retry-After > 60 s as a long window. The retry controller's gate only used the keyword-based hasLongWindowRateLimitEvidence, which fails when redaction destroys the keywords. Adding the same magnitude threshold to the gate makes the classification consistent and redaction-proof.

Evidence

Extracted-function reproduction (node, no build):

=== #179962 REPRODUCTION ===

Control (raw message with keywords):
  hasLongWindowRateLimitEvidence: true
  BEFORE: {"decision":"rejected","reason":"long_window_rate_limit"}
  AFTER:  {"decision":"rejected","reason":"long_window_rate_limit"}

Bug trigger (redacted message, Retry-After: 41294 s):
  hasLongWindowRateLimitEvidence: false
  BEFORE: {"decision":"accepted","reason":"backoff_completed","delayMs":41294000}
  AFTER:  {"decision":"rejected","reason":"long_window_rate_limit"}

Short-window control (5 s retry, should still be accepted):
  BEFORE: {"decision":"accepted","reason":"backoff_completed","delayMs":5000}
  AFTER:  {"decision":"accepted","reason":"backoff_completed","delayMs":5000}

REPRODUCTION CONFIRMED

What was not tested

Could not run repo vitest/typecheck — no local build. Validated via extracted-function node run (above) and the added unit test retry-evidence.long-window.test.ts only.

When a provider wraps its upstream 429 in a Python-style dict (e.g. LiteLLM
proxies), diagnostic redaction replaces the message with "[Malformed diagnostic
JSON redacted]" before hasLongWindowRateLimitEvidence runs.  The keyword check
then misses the usage-limit/subscription evidence and maybeRetryTransient
schedules the full Retry-After wait (hours) as a same-model retry, holding the
session.

Also reject when retryAfterMs exceeds 60 s (the same threshold
classifyRateLimitWindow uses), so a long-window 429 fails fast regardless of
whether the message text survived redaction.

Closes openclaw#179962
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR rejects same-model rate-limit retries whenever a finite Retry-After exceeds 60 seconds.

Example: A redacted 429 carries Retry-After: 41294 and the saved retry-delay cap is disabled.

  • Before: The controller waits 41,294,000 milliseconds before continuing.
  • After: The controller immediately rejects the retry as a long-window rate limit.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) A useful bug report motivates the change, but the patch breaks established recovery behavior and its supplied proof does not exercise the production change.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A wrapped provider usage-limit error can lose its exhaustion evidence and leave a conversation waiting instead of surfacing the failure promptly.
Reason: The underlying repair has clear value, but the proposed fixed cutoff changes an owner-established recovery contract and leaves classification evidence lost for errors without a qualifying Retry-After.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open: the reported loss of usage-window evidence remains actionable, but this PR’s unconditional 60-second threshold breaks established retry behavior and causes existing recovery tests to fail.

Priority: P1
Reviewed head: 879616a2816cc8566a76aa80824d333a2a0648bc
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should this PR preserve the published retry policy, or intentionally replace its configurable and replay-safety exceptions with an unconditional 60-second cutoff?
  • Recommendation: Preserve the existing policy: Repair the loss of usage-window evidence and retain the saved retry cap, disabled-cap behavior, and replay-unsafe continuation.
  • Why: The proposed cutoff changes behavior explicitly preserved by earlier merged work, and no maintainer approval of that direction appears in this PR or its linked issue.

Before merge

  • Add real behavior proof - The supplied after-fix output runs extracted logic rather than the shipped retry owner, and the added tests duplicate the predicate; provide redacted Gateway output or a production-owner trace for the wrapped 429, plus a latest-stable upgrade scenario retaining disabled or enlarged saved retry caps, with IPs, API keys, phone numbers, and non-public endpoints removed. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Preserve replay safety and saved retry caps before rejecting long waits (P1) - This new early return rejects every finite rate-limit floor above 60 seconds before the existing maxRetryDelayMs and failoverEligible checks. For a temporary 429 with retryAfterMs=9897000 after replay-unsafe tool work, attempt-recovery.ts cannot rotate accounts or fall back, so recovery now proceeds to termination instead of waiting and continuing the transcript. It also rejects temporary throttles when maxRetryDelayMs is 0 or greater than the requested floor. These are documented supported cases, and exact-head CI fails the existing controller and recovery controls for them. Preserve those controls and repair the lost usage-window evidence at its producer rather than treating duration alone as exhaustion.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Explain or restore the original intent of Usage-exhaustion guard - cb1b29d: Merged fix: preserve account selection and recovery lifecycle ownership #140973 intentionally distinguished exhausted usage windows from temporary throttles.
  • Explain or restore the original intent of Configurable retry floor and replay-unsafe continuation - fcc927f: Merged fix: rate-limit Retry-After past maxRetryDelayMs sleeps the turn instead of failing over #148580 preserved disabled caps and replay-unsafe continuation; fix: rotate auth profiles before long rate-limit waits #162398 subsequently extended only the replay-safe cap behavior.

Findings

  • [P1] Preserve replay safety and saved retry caps before rejecting long waits — src/agents/embedded-agent-runner/run/failover-retry-controller.ts:347-349

Provenance

Tests

  • Low-value test src/agents/failover/retry-evidence.long-window.test.ts: Remove the copied shouldRejectLongWindow implementation and its tests: they pass without the production change and cannot catch the existing controller regressions; add coverage through the production controller or recovery owner instead.
  • Missing end-to-end proof: Supply the wrapped 429 through a real Gateway or an authorized production-owner transport trace, show prompt failure after the repair and preserved temporary-throttle controls, and demonstrate a production-path regression failing on the base and passing on the fix.
Agent review details

How this fits together

Provider error projection supplies sanitized failure text and retry timing to attempt recovery; the retry controller decides whether to wait and continue before eligible account rotation, model fallback, or terminal failure.

flowchart TD
  A[Provider error and headers] --> B[Diagnostic error projection]
  B --> C[Assistant failover signal]
  C --> D[Attempt recovery]
  D --> E[Retry controller]
  E --> F[Wait and continue transcript]
  E --> G[Eligible fallback or terminal error]
Loading

Technical review

Best possible solution:

Preserve bounded usage-window evidence before diagnostic redaction and let the existing retry controller retain its saved-cap and replay-safety policy.

Do we have a high-confidence way to reproduce the issue?

Source confirms that malformed diagnostic JSON can erase usage-window wording while retry timing survives; current main bounds the default replay-safe case, but disabled-cap and replay-unsafe paths remain affected, and no current-main runtime reproduction was run during this read-only review.

Is this the best way to solve the issue?

The fixed threshold confuses retry duration with usage exhaustion and bypasses controls already owned by the controller; preserving safe classification evidence addresses the reported cause without terminating legitimate temporary-throttle recovery.

Full review comments:

  • [P1] Preserve replay safety and saved retry caps before rejecting long waits — src/agents/embedded-agent-runner/run/failover-retry-controller.ts:347-349
    This new early return rejects every finite rate-limit floor above 60 seconds before the existing maxRetryDelayMs and failoverEligible checks. For a temporary 429 with retryAfterMs=9897000 after replay-unsafe tool work, attempt-recovery.ts cannot rotate accounts or fall back, so recovery now proceeds to termination instead of waiting and continuing the transcript. It also rejects temporary throttles when maxRetryDelayMs is 0 or greater than the requested floor. These are documented supported cases, and exact-head CI fails the existing controller and recovery controls for them. Preserve those controls and repair the lost usage-window evidence at its producer rather than treating duration alone as exhaustion.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 40a236feb0c3.

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cb1b29d adds src/agents/embedded-agent-runner/run/failover-retry-controller.ts:233 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cb1b29d9a1e6; files: src/agents/embedded-agent-runner/run/failover-retry-controller.ts)
  • Abi X Renhart: Raw commit fcc927f adds src/agents/embedded-agent-runner/run/failover-retry-controller.ts:290 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fcc927f58d02; files: src/agents/embedded-agent-runner/run/failover-retry-controller.ts)
  • alkor2000: Raw commit d0d0f86 adds src/agents/embedded-agent-runner/run/failover-retry-controller.ts:353 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d0d0f8654728; files: src/agents/embedded-agent-runner/run/failover-retry-controller.ts)

PR surface

Source +8, Tests +104. Total +112 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 1 104 0 +104
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 113 1 +112

Root-cause cluster

Relationship: same_root_cause
Canonical: #179962
Summary: This PR explicitly targets the linked report’s loss of usage-window evidence during diagnostic redaction.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The underlying report documents hours-long blockage of an active conversation, and the patch introduces premature termination of recoverable agent work.
  • merge-risk: 🚨 compatibility: The unconditional threshold overrides existing disabled or enlarged retry caps and the documented replay-unsafe continuation behavior.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 21, 2026, 6:30 PM ET / 22:30 UTC.

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the work here. We're closing this: it doesn't show a real user-facing problem (no report from an affected user and no natural reproduction), and it follows a pattern of small, speculative or duplicate changes split across many PRs. Please open an issue with a reproduction of real harm first; a fix can follow once the problem is confirmed.

@obviyus obviyus closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Usage-limit 429 is slept out in full when its message embeds a Python-style dict: the long-window check reads the redacted text

2 participants