You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7a45a65
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/concepts/model-failover.md
+16-35Lines changed: 16 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,31 +28,31 @@ OpenClaw handles failures in two stages:
28
28
<Steptitle="Advance on failover-worthy errors">
29
29
If that provider is exhausted with a failover-worthy error, move to the next model candidate.
30
30
</Step>
31
-
<Steptitle="Persist fallback override">
32
-
Persist the selected fallback override before the retry starts so other session readers see the same provider/model the runner is about to use. The persisted model override is marked `modelOverrideSource: "auto"`.
31
+
<Steptitle="Use fallback for the current turn">
32
+
Run the winning fallback candidate without changing the session's selected provider/model.
33
33
</Step>
34
-
<Steptitle="Roll back narrowly on failure">
35
-
If the fallback candidate fails, roll back only the fallback-owned session override fields when they still match that failed candidate.
34
+
<Steptitle="Retry safe pure overload exhaustion">
35
+
If every candidate fails only because providers are overloaded, retry the full turn-local chain up to 10 times with exponential backoff while no tool execution or assistant output has started. After 30 seconds, send one status notice so the user is not left waiting silently.
36
36
</Step>
37
37
<Steptitle="Throw FallbackSummaryError if exhausted">
38
38
If every candidate fails, throw a `FallbackSummaryError` with per-attempt detail and the soonest cooldown expiry when one is known.
39
39
</Step>
40
40
</Steps>
41
41
42
-
This is intentionally narrower than "save and restore the whole session." The reply runner only persists the model-selection fields it owns for fallback: `providerOverride`, `modelOverride`, `modelOverrideSource`, `authProfileOverride`, `authProfileOverrideSource`, `authProfileOverrideCompactionCount`. That prevents a failed fallback retry from overwriting newer unrelated session mutations, such as a manual `/model` change or a session rotation update that happened while the attempt was running.
42
+
Fallback execution is turn-local. The reply runner persists only fallback notice state so `/status` and transition notices can distinguish the selected model from the model that answered; it does not persist the fallback as the next turn's model selection.
43
43
44
44
## Selection source policy
45
45
46
46
The selection source controls whether the fallback chain is allowed:
-**Agent primary**: `agents.list[].model` is strict unless that agent's model object includes its own `fallbacks`. Use `fallbacks: []` to make the strict behavior explicit, or a non-empty list to opt that agent into model fallback.
50
-
-**Auto fallback override**: a runtime fallback writes `providerOverride`, `modelOverride`, `modelOverrideSource: "auto"`, and the selected origin model before retrying. This override keeps walking the configured fallback chain without probing the primary on every message, but OpenClaw probes the configured origin every 5 minutes (not configurable) and clears the override once it recovers. `/new`, `/reset`, and `sessions.reset` also clear auto-sourced overrides. Heartbeat runs without an explicit `heartbeat.model` clear direct auto overrides when their origin no longer matches the current configured default.
50
+
-**Runtime fallback**: the fallback candidate applies only to the current turn. The next turn starts from the selected primary again. OpenClaw still recognizes previously stored `modelOverrideSource: "auto"` entries, probes their configured origin every 5 minutes, and clears them once the origin recovers. `/new`, `/reset`, and `sessions.reset` also clear those entries.
51
51
-**User session override**: `/model`, the model picker, `session_status(model=...)`, and `sessions.patch` write `modelOverrideSource: "user"`. This is an exact session selection. If the selected provider/model fails before producing a reply, OpenClaw reports the failure instead of answering from an unrelated configured fallback.
52
52
-**Legacy session override**: older session entries may have `modelOverride` without `modelOverrideSource`. OpenClaw treats those as user overrides so an explicit old selection is not silently converted into fallback behavior.
53
53
-**Cron payload model**: a cron job `payload.model` / `--model` is a job primary, not a user session override. It uses configured fallbacks unless the job provides `payload.fallbacks`; `payload.fallbacks: []` makes the cron run strict.
54
54
55
-
OpenClaw remembers recent primary probes per session and primary model so a failing primary is not retried on every turn. It sends a visible notice when a session moves onto fallback and another notice when it returns to the selected primary; it does not repeat the notice on every sticky fallback turn.
55
+
OpenClaw sends a visible notice when a turn moves onto fallback and another notice when a later turn succeeds on the selected primary. Persisted notice state prevents repeated notices when consecutive turns use the same selected/active pair, while model selection itself remains unchanged.
56
56
57
57
## Auth failure skip cache
58
58
@@ -82,7 +82,7 @@ When a later probe succeeds and the session returns to the selected primary, Ope
82
82
↪️ Model Fallback cleared: <primary> (was <fallback>)
83
83
```
84
84
85
-
These notices are operational messages, not assistant content. They deliver once per state change, including side-effect-only turns when feasible, but sticky fallback turns do not repeat them. Delivery bypasses normal source-reply suppression, does not consume the first assistant reply slot for threaded channels, and is excluded from text-to-speech and commitment extraction.
85
+
These notices are operational messages, not assistant content. They deliver once per state change, including side-effect-only turns when feasible, but repeated turn-local fallback transitions do not repeat them. Delivery bypasses normal source-reply suppression, does not consume the first assistant reply slot for threaded channels, and is excluded from text-to-speech and commitment extraction.
86
86
87
87
## Auth storage (keys + OAuth)
88
88
@@ -262,6 +262,8 @@ If all profiles for a provider fail, OpenClaw moves to the next model in `agents
262
262
263
263
Provider-busy signals such as `ModelNotReadyException` land in the overloaded bucket and follow the same one-rotation-then-fallback policy as rate limits (see the defaults table above).
264
264
265
+
If the entire candidate chain is exhausted only by overload failures, the reply runner retries the chain up to 10 times in the same turn. Full-turn retry is allowed only before tool execution or assistant output starts, avoiding duplicate mutations or messages if an overload arrives after observable work. Backoff starts at 2.5 seconds and doubles to a 30-second cap. Once the turn has been waiting for 30 seconds, OpenClaw sends one transient status notice: `The AI service is temporarily overloaded. I’m still retrying; this may take a few minutes.` The retry and any fallback winner remain turn-local; ordinary transient server errors retain their separate one-retry policy.
266
+
265
267
When a run starts from the configured default primary, a cron job primary, an agent primary with explicit fallbacks, or an auto-selected fallback override, OpenClaw can walk the matching configured fallback chain. Agent primaries without explicit fallbacks and explicit user selections (for example `/model ollama/qwen3.5:27b`, the model picker, `sessions.patch`, or one-off CLI provider/model overrides) are strict: if that provider/model is unreachable or fails before producing a reply, OpenClaw reports the failure instead of answering from an unrelated fallback.
266
268
267
269
### Candidate chain rules
@@ -319,42 +321,21 @@ When every auth profile for a provider is already in cooldown, OpenClaw does not
319
321
320
322
## Session overrides and live model switching
321
323
322
-
Session model changes are shared state. The active runner, `/model` command, compaction/session updates, and live-session reconciliation all read or write parts of the same session entry.
324
+
Session model changes are shared state. The active runner, `/model` command, compaction/session updates, and live-session reconciliation all read or write parts of the same session entry. Fallback execution does not write model-selection fields, so it cannot replace a newer manual selection while retrying.
323
325
324
-
That means fallback retries have to coordinate with live model switching:
326
+
Live model switching follows these rules:
325
327
326
328
- Only explicit user-driven model changes mark a pending live switch. That includes `/model`, `session_status(model=...)`, and `sessions.patch`.
327
329
- System-driven model changes such as fallback rotation, heartbeat overrides, or compaction never mark a pending live switch on their own.
328
330
- User-driven model overrides are treated as exact selections for fallback policy, so an unreachable selected provider surfaces as a failure instead of being masked by `agents.defaults.model.fallbacks`.
329
-
-Before a fallback retry starts, the reply runner persists the selected fallback override fields to the session entry.
330
-
-Auto fallback overrides remain selected on subsequent turns so OpenClaw does not probe a known-bad primary on every message. OpenClaw periodically probes the configured origin again and clears the auto override when it recovers; `/new`, `/reset`, and `sessions.reset` clear auto-sourced overrides immediately.
331
-
- User replies announce fallback transitions and fallback-cleared recovery once per state change. Sticky fallback turns do not repeat the notice.
331
+
-Runtime fallback candidates remain turn-local. The next turn starts from the current selected model, including a manual selection that arrived during the previous run.
332
+
-Previously stored auto fallback overrides remain supported: OpenClaw periodically probes their configured origin and clears the override when it recovers; `/new`, `/reset`, and `sessions.reset` clear auto-sourced overrides immediately.
333
+
- User replies announce fallback transitions and fallback-cleared recovery once per state change. Repeated turns with the same selected/active pair do not repeat the notice.
332
334
-`/status` shows the selected model and, when fallback state differs, the active fallback model and reason.
333
335
- Live-session reconciliation prefers persisted session overrides over stale runtime model fields.
334
336
- If a live-switch error points at a later candidate in the active fallback chain, OpenClaw jumps directly to that selected model instead of walking unrelated candidates first.
335
-
- If the fallback attempt fails, the runner rolls back only the override fields it wrote, and only if they still match that failed candidate.
336
-
337
-
This prevents the classic race:
338
-
339
-
<Steps>
340
-
<Steptitle="Primary fails">
341
-
The selected primary model fails.
342
-
</Step>
343
-
<Steptitle="Fallback chosen in memory">
344
-
Fallback candidate is chosen in memory.
345
-
</Step>
346
-
<Steptitle="Session store still says old primary">
347
-
Session store still reflects the old primary.
348
-
</Step>
349
-
<Steptitle="Live reconciliation reads stale state">
350
-
Live-session reconciliation reads the stale session state.
351
-
</Step>
352
-
<Steptitle="Retry snapped back">
353
-
The retry gets snapped back to the old model before the fallback attempt starts.
354
-
</Step>
355
-
</Steps>
356
337
357
-
The persisted fallback override closes that window, and the narrow rollback keeps newer manual or runtime session changes intact.
338
+
The active run carries its chosen candidate directly. Live reconciliation changes that candidate only for an explicit pending user switch, so no temporary fallback override or rollback is needed.
0 commit comments