openclaw - ✅(Solved) Fix Fallback model selection overridden by session model reconciliation — causes infinite 429 loop [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#59213Fetched 2026-04-08 02:27:26
View on GitHub
Comments
3
Participants
3
Timeline
7
Reactions
0
Timeline (top)
commented ×3cross-referenced ×2referenced ×2

When an agent's primary model (e.g. anthropic/claude-sonnet-4-6) hits a rate limit, OpenClaw correctly selects a fallback model (kiro/claude-sonnet-4.6). However, a session model reconciliation step fires between fallback selection and the actual request, sees the agent config specifies the primary model, and overrides the fallback back to the primary. This creates an infinite 429 retry loop that renders the agent completely unresponsive.

Error Message

provider=anthropic error=⚠️ API rate limit reached. rawError=429 {"type":"error","error":{"type":"rate_limit_error", The error message "Extra usage is required for long context requests." is not in ERROR_PATTERNS.rateLimit. The fallback triggers (the 429 HTTP status is caught by a different path), but the message-level pattern should be added for defense in depth:

Root Cause

When an agent's primary model (e.g. anthropic/claude-sonnet-4-6) hits a rate limit, OpenClaw correctly selects a fallback model (kiro/claude-sonnet-4.6). However, a session model reconciliation step fires between fallback selection and the actual request, sees the agent config specifies the primary model, and overrides the fallback back to the primary. This creates an infinite 429 retry loop that renders the agent completely unresponsive.

Fix Action

Fixed

PR fix notes

PR #1: fix: KIRO fallback reconciliation (#59213)

Description (problem / solution / changelog)

Fixes 4 issues blocking KIRO Anthropic Max fallback:

  1. Skip live session model reconciliation during failover - Prevents infinite loops when fallback model conflicts with persisted session selection
  2. Use primary model context window for compaction - Fallback models may have larger context windows, now stores primary separately
  3. Add 'extra usage is required' to rate-limit patterns - Anthropic Max billing gate message now classified as rate_limit
  4. Add provider-specific pattern for Anthropic Max - Ensures proper failover classification

See: https://github.com/openclaw/openclaw/issues/59213

Changed files

  • .agent-checkpoint.json (added, +11/-0)
  • src/agents/command/attempt-execution.ts (modified, +1/-0)
  • src/agents/pi-embedded-helpers/failover-matches.ts (modified, +1/-0)
  • src/agents/pi-embedded-helpers/provider-error-patterns.ts (modified, +6/-0)
  • src/agents/pi-embedded-runner/run.ts (modified, +8/-2)
  • src/agents/pi-embedded-runner/run/params.ts (modified, +6/-0)
  • src/auto-reply/reply/agent-runner-execution.ts (modified, +4/-0)
  • src/cron/isolated-agent/run.ts (modified, +4/-0)

Code Example

[model-fallback/decision] model fallback decision: decision=candidate_failed 
  requested=anthropic/claude-sonnet-4-6 candidate=anthropic/claude-sonnet-4-6 
  reason=rate_limit next=kiro/claude-sonnet-4.6

[agent/embedded] live session model switch detected before attempt for <session-id>: 
  kiro/claude-sonnet-4.6 -> anthropic/claude-sonnet-4-6

[agent/embedded] embedded run agent end: isError=true model=claude-sonnet-4-6 
  provider=anthropic error=⚠️ API rate limit reached. 
  rawError=429 {"type":"error","error":{"type":"rate_limit_error",
  "message":"Extra usage is required for long context requests."}}

---

// Add to ERROR_PATTERNS.rateLimit in reply-payloads-dedupe:
"extra usage is required",  // Anthropic Max long-context billing gate
RAW_BUFFERClick to expand / collapse

Summary

When an agent's primary model (e.g. anthropic/claude-sonnet-4-6) hits a rate limit, OpenClaw correctly selects a fallback model (kiro/claude-sonnet-4.6). However, a session model reconciliation step fires between fallback selection and the actual request, sees the agent config specifies the primary model, and overrides the fallback back to the primary. This creates an infinite 429 retry loop that renders the agent completely unresponsive.

Reproduction

  1. Agent configured with primary anthropic/claude-sonnet-4-6 and fallback kiro/claude-sonnet-4.6
  2. Anthropic returns 429 rate_limit_error ("Extra usage is required for long context requests.")
  3. Fallback decision fires correctly: next=kiro/claude-sonnet-4.6
  4. Session model reconciliation overrides back to anthropic/claude-sonnet-4-6 before the request
  5. Anthropic returns 429 again → loop → agent dead

Log Evidence

[model-fallback/decision] model fallback decision: decision=candidate_failed 
  requested=anthropic/claude-sonnet-4-6 candidate=anthropic/claude-sonnet-4-6 
  reason=rate_limit next=kiro/claude-sonnet-4.6

[agent/embedded] live session model switch detected before attempt for <session-id>: 
  kiro/claude-sonnet-4.6 -> anthropic/claude-sonnet-4-6

[agent/embedded] embedded run agent end: isError=true model=claude-sonnet-4-6 
  provider=anthropic error=⚠️ API rate limit reached. 
  rawError=429 {"type":"error","error":{"type":"rate_limit_error",
  "message":"Extra usage is required for long context requests."}}

The pattern repeats every ~4-8 seconds until the session is manually reset with /new.

Expected Behavior

A fallback-selected model during an active run attempt should not be overridden by config-driven session model reconciliation. The reconciliation step should be skipped or deferred when a fallback is in effect.

Secondary Issue (Bug 2)

The error message "Extra usage is required for long context requests." is not in ERROR_PATTERNS.rateLimit. The fallback triggers (the 429 HTTP status is caught by a different path), but the message-level pattern should be added for defense in depth:

// Add to ERROR_PATTERNS.rateLimit in reply-payloads-dedupe:
"extra usage is required",  // Anthropic Max long-context billing gate

Environment

  • OpenClaw version: current (as of 2026-04-01)
  • Provider: Anthropic (Max subscription)
  • Fallback provider: Kiro (custom provider via local gateway)
  • Trigger condition: Anthropic Max long-context billing gate (~200K-390K cached tokens)
  • Affects all agents on Anthropic provider

extent analysis

TL;DR

To fix the infinite 429 retry loop, skip or defer the session model reconciliation step when a fallback model is in effect.

Guidance

  • Identify the session model reconciliation step in the code and add a condition to skip or defer it when a fallback model is selected.
  • Verify that the fallback model is not overridden by the primary model after the reconciliation step.
  • Consider adding a flag or indicator to track when a fallback model is in effect, to simplify the skipping or deferring logic.
  • Review the error handling mechanism to ensure that the "Extra usage is required for long context requests." message is properly handled and added to the ERROR_PATTERNS.rateLimit list.

Example

// Pseudo-code example of skipping reconciliation when fallback is in effect
if (fallbackModelSelected) {
  // Skip reconciliation step
  return;
} else {
  // Perform reconciliation step
  reconcileSessionModel();
}

Notes

The provided solution assumes that the session model reconciliation step can be skipped or deferred without affecting the overall functionality of the system. Additional testing and verification may be necessary to ensure that the fix does not introduce new issues.

Recommendation

Apply workaround: Skip or defer the session model reconciliation step when a fallback model is in effect, to prevent the infinite 429 retry loop. This workaround addresses the immediate issue and allows for further investigation and refinement of the error handling mechanism.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Fallback model selection overridden by session model reconciliation — causes infinite 429 loop [1 pull requests, 3 comments, 3 participants]