#23033: fix: continue to fallbacks when first fallback throws unclassified error
agents
size: S
Cluster:
Image Model Enhancements
## Summary
This fix addresses two issues:
### Issue 1: Fallbacks being skipped
When the primary model fails with a classified error (like rate limit), and the first fallback fails with an unclassified error, OpenClaw was throwing immediately instead of trying the second fallback. This caused the "2nd model blocks 3rd" problem.
### Issue 2: (unknown) in error summaries
The CLI runner was explicitly setting reason: "unknown" when errors could not be classified, resulting in "(unknown)" appearing in error messages.
## Changes
1. Only fail-fast on primary model (i===0) for unclassified errors - preserves safety semantics
2. Continue to next fallback for unclassified errors on fallback models (i > 0)
3. Set reason: undefined instead of "unknown" to avoid (unknown) in summaries
4. Added regression test for: primary fails with classified error -> fallback #1 fails with unclassified error -> fallback #2 succeeds
## Reviewed by
Krill (OpenClaw maintainer) - provided feedback on preserving safety semantics
---
Testing:
- The fix maintains the existing safety behavior (fail-fast on primary model unclassified errors)
- Added e2e test case for the specific scenario
Files changed:
- src/agents/model-fallback.ts - core fix
- src/agents/model-fallback.e2e.test.ts - regression test
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed fallback mechanism to continue trying remaining fallbacks when a non-primary model throws an unclassified error, resolving the "2nd model blocks 3rd" issue.
**Key changes:**
- Modified `src/agents/model-fallback.ts:386-405` to only fail-fast on unclassified errors from the primary model (i===0), preserving safety semantics
- For fallback models (i>0), unclassified errors are now recorded in attempts with `reason: undefined` and execution continues to the next fallback
- Added regression test covering: primary fails (classified) → fallback #1 fails (unclassified) → fallback #2 succeeds
**Issues found:**
- Test structure issue: new test is placed outside the `describe` block and needs to be moved inside
<h3>Confidence Score: 4/5</h3>
- Safe to merge after fixing test placement - logic is sound but test structure needs correction
- The core logic fix is correct and preserves fail-fast safety for primary model unclassified errors while enabling fallback continuation. However, the test has a structural issue (placed outside describe block) that will cause test runner problems.
- src/agents/model-fallback.e2e.test.ts needs the test moved inside the describe block
<sub>Last reviewed commit: 53c7489</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21963: fix(cli): models fallbacks add now includes primary model in allowlist
by ashiabbott · 2026-02-20
86.0%
#22064: fix(failover): bypass models allowlist for configured fallback models
by winston-bepresent · 2026-02-20
84.6%
#20275: fix(cli): include primary model in allowlist when adding fallbacks
by MFS-code · 2026-02-18
83.9%
#11349: fix(agents): do not filter fallback models by models allowlist
by liuxiaopai-ai · 2026-02-07
81.7%
#10178: fix: trigger fallback when model resolution fails with unknown model
by Yida-Dev · 2026-02-06
81.0%
#15815: Fallback LLM doesn't trigger if primary model is local
by shihanqu · 2026-02-13
80.7%
#23816: fix(agents): model fallback skipped during session overrides and pr...
by ramezgaberiel · 2026-02-22
80.5%
#21152: fix(agents): throw FailoverError for unknown model so fallback chai...
by Mellowambience · 2026-02-19
80.4%
#16838: fix: include configured fallbacks in model allowlist
by taw0002 · 2026-02-15
80.1%
#8390: feat: notify user when fallback model is used (#8182)
by Glucksberg · 2026-02-04
79.6%