Skip to content

fix(failover): allow model_not_found to trigger fallback chain when configured (fixes #97564) - #97571

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
liuhao1024:fix/failover-model-not-found-fallback
Jun 29, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
liuhao1024:fix/failover-model-not-found-fallback

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What Problem This Solves

When a configured primary model is decommissioned by the provider (returns model_not_found), OpenClaw's failover policy treats this as a terminal error and never attempts the configured fallback chain. Users who set up model.fallbacks specifically for resilience against model decommission silently lose that protection.

Why This Change Was Made

The shouldEscalateRetryLimit function in failover-policy.ts explicitly excluded model_not_found from failover escalation. This was defensible for typos (a misconfigured model should surface loudly), but it conflated two distinct cases:

  1. Typo / never-existed model — surfacing the error is correct.
  2. Previously-valid model decommissioned mid-life — the fallback chain is the intended remedy.

Since there's no reliable way to distinguish these at runtime, the fix removes the exclusion so model_not_found behaves like other availability-class reasons: attempt fallback when configured, surface error when the chain is exhausted.

User Impact

  • Agents with configured model.fallbacks will now correctly cascade to fallback models when the primary model returns model_not_found.
  • Single-model configs with no fallback configured still surface the error immediately (no behavior change).
  • Other excluded reasons (timeout, format, session_expired) are unaffected.

Evidence

  • Behavior addressed: model_not_found failover escalation when fallback chain is configured
  • Environment tested: macOS, Node 22, OpenClaw 2026.5.28, commit 9bb0043
  • Steps run after the patch: Call resolveRunFailoverDecision with failoverReason: "model_not_found" and fallbackConfigured: true via the production failover-policy module
  • Evidence after fix:
$ npx tsx -e "
import { resolveRunFailoverDecision } from './src/agents/embedded-agent-runner/run/failover-policy.ts';
const r = resolveRunFailoverDecision({ stage: 'retry_limit', fallbackConfigured: true, failoverReason: 'model_not_found' });
console.log(JSON.stringify(r));
"
{"action":"fallback_model","reason":"model_not_found"}
  • Observed result after fix: model_not_found with fallbackConfigured: true returns { action: "fallback_model", reason: "model_not_found" } — fallback chain engages.
  • What was not tested: Live provider interaction with a decommissioned model (no provider API key configured for test scenario). The fix is a single-line removal in a pure policy function, validated by the same production code path used by the embedded agent runner.

Real behavior proof

  • Behavior addressed: model_not_found failover escalation when fallback chain is configured
  • Environment tested: macOS, Node 22, OpenClaw 2026.5.28, commit 9bb0043
  • Steps run after the patch: Call resolveRunFailoverDecision with failoverReason: "model_not_found" and fallbackConfigured: true via the production failover-policy module
  • Evidence after fix:
$ npx tsx -e "
import { resolveRunFailoverDecision } from './src/agents/embedded-agent-runner/run/failover-policy.ts';
const r = resolveRunFailoverDecision({ stage: 'retry_limit', fallbackConfigured: true, failoverReason: 'model_not_found' });
console.log(JSON.stringify(r));
"
{"action":"fallback_model","reason":"model_not_found"}
  • Observed result after fix: model_not_found with fallbackConfigured: true returns { action: "fallback_model", reason: "model_not_found" } — fallback chain engages. With fallbackConfigured: false, returns { action: "return_error_payload" } — error surfaces when no fallback available.

  • What was not tested: Live provider interaction with a decommissioned model. The fix is validated through the production failover policy function used by the embedded agent runner.

  • AI-assisted (Hermes Agent)

…onfigured

Remove model_not_found from the shouldEscalateRetryLimit exclusion list
so that configured fallback models are attempted when the primary model
is decommissioned by the provider. Previously, model_not_found was
treated as terminal, silently defeating the fallback chain for the
decommission case.

Fixes openclaw#97564
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jun 28, 2026
@clawsweeper

clawsweeper Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 5:38 PM ET / 21:38 UTC.

Summary
The PR removes model_not_found from the retry-limit non-escalating reasons and adds focused failover-policy tests for configured and unconfigured fallback cases.

PR surface: Source -4, Tests +27. Total +23 across 2 files.

Reproducibility: yes. at source level: current main excludes model_not_found from retry-limit fallback escalation even when fallbackConfigured is true. I did not run tests because this review is read-only.

Review metrics: 1 noteworthy metric.

  • Retry-limit failover eligibility: 1 reason newly escalated; 2 tests added. This is a provider/model routing behavior change, so maintainers should review it as compatibility-sensitive rather than only as a local predicate edit.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P2] Merging changes existing configured-fallback behavior: a typoed primary model with a fallback chain can now advance to another model instead of surfacing the terminal model_not_found retry-limit error.
  • [P2] The proof demonstrates the production policy helper, not a live provider-decommission run; maintainers may still want end-to-end fallback proof before landing.
  • [P1] A same-root-cause sibling PR is also open, so maintainers should choose one canonical branch before merging or closing the other.

Maintainer options:

  1. Accept Configured-Fallback Semantics (recommended)
    Merge a proof-positive branch after maintainers accept that non-empty configured fallbacks should continue on model_not_found, including typoed primary-plus-fallback configs.
  2. Require End-To-End Fallback Proof
    Ask for redacted embedded-runner or provider-simulated proof showing a primary model_not_found retry-limit path advances to a distinct fallback candidate.
  3. Pause For Stricter Policy
    If typo strictness must remain for fallback-configured models, pause this PR and the sibling until maintainers define a different signal or opt-in policy.

Next step before merge

  • Maintainer review should decide whether to accept the intentional configured-fallback routing change and choose between this proof-positive PR and the overlapping sibling branch.

Security
Cleared: The diff only changes TypeScript failover policy logic and focused tests; it does not touch dependencies, workflows, secrets, install scripts, or package resolution.

Review details

Best possible solution:

Land one proof-positive, narrow policy/test change for the linked issue after maintainers accept that configured fallback chains should cover retry-limit model_not_found exhaustion, then close or supersede the sibling branch.

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

Yes at source level: current main excludes model_not_found from retry-limit fallback escalation even when fallbackConfigured is true. I did not run tests because this review is read-only.

Is this the best way to solve the issue?

Yes as an implementation shape: changing the existing retry-limit predicate is the narrow owner-boundary fix because the outer fallback loop already owns candidate filtering and exhaustion behavior. Maintainers still need to accept the compatibility tradeoff before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a54919dcbc95.

Label changes

Label justifications:

  • P2: This is a normal-priority agent fallback reliability fix with limited blast radius to configured model fallback chains.
  • merge-risk: 🚨 compatibility: Existing fallback-configured setups with a typoed or unavailable primary can observe a different retry-limit failure mode after merge.
  • merge-risk: 🚨 auth-provider: The patch changes provider/model routing when the selected primary returns model_not_found and fallbacks are configured.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output invoking the production failover policy module and showing model_not_found with configured fallback returns fallback_model; live provider-decommission proof was not included.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output invoking the production failover policy module and showing model_not_found with configured fallback returns fallback_model; live provider-decommission proof was not included.
Evidence reviewed

PR surface:

Source -4, Tests +27. Total +23 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 5 -4
Tests 1 27 0 +27
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 28 5 +23

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/failover-policy.test.ts.
  • [P2] node scripts/run-vitest.mjs src/agents/model-fallback.test.ts.
  • [P2] node scripts/run-vitest.mjs src/agents/model-fallback.run-embedded.e2e.test.ts.

What I checked:

Likely related people:

  • Peter Steinberger: Shortlog and history show the largest contribution set across model fallback implementation, tests, and the model-failover docs. (role: fallback feature and docs owner by history; confidence: high; commits: d01cb5ecc643, dcc3392a1a40; files: src/agents/model-fallback.ts, src/agents/model-fallback.test.ts, docs/concepts/model-failover.md)
  • Vincent Koc: Recent history shows repeated work around model fallback helper imports and embedded-runner/fallback surfaces. (role: recent adjacent area contributor; confidence: medium; commits: 93ce76afe310, da3977e6818b; files: src/agents/model-fallback.ts, src/agents/embedded-agent-runner/run.ts, docs/concepts/model-failover.md)
  • xiwuqi: git log -S model_not_found identifies their merged invalid-model fallback classification work as adjacent to this behavior. (role: adjacent invalid-model fallback contributor; confidence: medium; commits: 7fbd31818b31; files: src/agents/failover-error.test.ts, src/agents/model-fallback.test.ts)
  • ly-wang19: git blame attributes the extracted retry-limit predicate lines to a broad snapshot commit, which is useful for current-line provenance but weak for behavior ownership. (role: current line-history carrier; confidence: low; commits: 881ec2f93f37; files: src/agents/embedded-agent-runner/run/failover-policy.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 28, 2026
@vincentkoc
vincentkoc merged commit f6115dd into openclaw:main Jun 29, 2026
151 of 160 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
…onfigured (openclaw#97571)

Remove model_not_found from the shouldEscalateRetryLimit exclusion list
so that configured fallback models are attempted when the primary model
is decommissioned by the provider. Previously, model_not_found was
treated as terminal, silently defeating the fallback chain for the
decommission case.

Fixes openclaw#97564
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
…onfigured (openclaw#97571)

Remove model_not_found from the shouldEscalateRetryLimit exclusion list
so that configured fallback models are attempted when the primary model
is decommissioned by the provider. Previously, model_not_found was
treated as terminal, silently defeating the fallback chain for the
decommission case.

Fixes openclaw#97564
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Jul 15, 2026
…onfigured (openclaw#97571)

Remove model_not_found from the shouldEscalateRetryLimit exclusion list
so that configured fallback models are attempted when the primary model
is decommissioned by the provider. Previously, model_not_found was
treated as terminal, silently defeating the fallback chain for the
decommission case.

Fixes openclaw#97564

(cherry picked from commit f6115dd)
convyusboy added a commit to getboon/openclaw that referenced this pull request Sep 18, 2026
…onflicts)

Merges 45 commits from origin/boon (boon.34 through boon.45, tag bump
06c4eff) into the 6.34 integration branch. 213 initial conflicts,
~206 were mechanical version-string conflicts (package.json /
npm-shrinkwrap.json across root + bundled plugins, resolved to ours
since this branch's purpose is advancing past the 2026.6.11-boon.N
train). Non-trivial resolutions:

- src/agents/embedded-agent-runner/run/failover-policy.ts: kept our
  side's non-exclusion of "model_not_found" in
  shouldEscalateRetryLimit (upstream openclaw#97571, already tested on this
  branch since the original 6.34 sync) while adopting boon's new
  "edge_blocked" exclusion. Blindly taking boon's side here would have
  silently reverted the upstream fix; caught via
  failover-policy.test.ts failing 1/44 before the correction.

- src/config/sessions/session-accessor.ts: adopted boon's
  projectSessionEntryForPersistenceRevision call in
  createReplySessionInitializationRevision, replacing our own
  identity-field comparison workaround. Boon's own recent PR #205
  reintroduced real use of this projection, so the workaround is no
  longer needed.

- src/config/sessions/session-accessor.reply-init-concurrency.test.ts:
  kept our PID-suffixed temp-file naming in the child test script
  (avoids same-directory temp-path collisions across concurrent
  children); took boon's minor whitespace cleanup elsewhere.

- extensions/matrix/CHANGELOG.md: kept our 3 newest entries on top,
  followed by boon's full chain.

- scripts/plugin-sdk-surface-report.mjs: bumped publicExports budget
  10406 -> 10410 and publicFunctionExports 5216 -> 5217 to match
  actual measured surface after the merge (publicEntrypoints already
  324, unchanged).

- docs/.generated/*.sha256: regenerated via `pnpm run
  plugin-sdk:api:gen` and `pnpm run config:docs:gen` against the
  merged tree. Also had to `git rm --cached` 6 underlying .json/.jsonl
  data files that origin/boon tracks but our .gitignore (unchanged by
  this merge) explicitly excludes (docs/.generated/*.json,
  docs/.generated/*.jsonl) -- git's merge machinery adds a file from
  either parent on a clean non-conflicting add regardless of the
  other side's gitignore rules.

- pnpm-lock.yaml: merged clean with no conflict markers, but the
  auto-merge misplaced extensions/diagnostics-otel's @opentelemetry/*
  dependency block under the root "." importer instead of the
  extensions/diagnostics-otel importer. `pnpm install` (run as a
  side-effect of plugin-sdk:api:gen) correctly relocated it; confirmed
  root package.json has never declared these deps (neither current
  nor pre-merge HEAD) and extensions/diagnostics-otel/package.json
  declares exactly this set. Diff is a pure 33-line removal of the
  misplaced duplicate, kept.

Verified: tsgo:core:test and tsgo:extensions:test clean; broad
node scripts/run-vitest.mjs sweeps across all touched feature surfaces
(embedded-agent-runner, config/sessions, cron, plugin-sdk,
sentry-monitor, pdf-tool, media, subagents) all green.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants