#10178: fix: trigger fallback when model resolution fails with unknown model
agents
stale
Cluster:
Model Fallback and Error Handling
## Summary
- When a model is unknown (e.g. `claude-opus-4-6` not yet available for setup-token auth), the error was thrown as a plain `Error` before the fallback mechanism could intercept it
- Added `isUnknownModelErrorMessage()` to detect "Unknown model" / "Model not found" errors
- `classifyFailoverReason()` now classifies these as `"auth"` (model availability is auth-mode-dependent)
- When fallback is configured, `run.ts` now throws `FailoverError` instead of plain `Error`, allowing the agent to retry with the fallback model
- Added regression test for the new error classification
Closes #10088
## Test plan
- [x] Existing `classifyFailoverReason` tests pass (no regressions)
- [x] New test: `classifies unknown model errors as auth` passes
- [x] `pnpm vitest run src/agents/pi-embedded-helpers.classifyfailoverreason.test.ts` — 3 tests pass
🤖 Generated with [Claude Code](https://claude.ai/code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates embedded-agent failover classification to treat “Unknown model” / “Model not found” errors as an `auth` failover reason, and changes the embedded runner to throw `FailoverError` (instead of a plain `Error`) when model resolution fails and fallbacks are configured. It also adds a regression test covering the new classification.
These changes integrate with the existing failover pipeline by ensuring model-resolution failures can be intercepted by the retry/fallback mechanism (`FailoverError` + `classifyFailoverReason`).
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but fix the new test compile error first
- Behavioral change is small and localized (new unknown-model classification and throwing FailoverError when fallback is configured). However, the added test file references an unimported type, which will break TypeScript builds/typecheck in environments that include tests.
- src/agents/pi-embedded-helpers.classifyfailoverreason.test.ts
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#21152: fix(agents): throw FailoverError for unknown model so fallback chai...
by Mellowambience · 2026-02-19
85.3%
#12314: fix: treat HTTP 5xx server errors as failover-worthy
by hsssgdtc · 2026-02-09
82.6%
#7229: fix: add network error resilience to agentic loop failover
by ai-fanatic · 2026-02-02
81.9%
#13191: pi-embedded: enable failover when per-agent fallbacks are configured
by zesty-clawd · 2026-02-10
81.8%
#15815: Fallback LLM doesn't trigger if primary model is local
by shihanqu · 2026-02-13
81.8%
#11821: fix(auth): trigger failover on 401 status code from expired OAuth t...
by AnonO6 · 2026-02-08
81.6%
#9427: fix: trigger model fallback on all 4xx HTTP errors
by dbottme · 2026-02-05
81.3%
#23033: fix: continue to fallbacks when first fallback throws unclassified ...
by ismsaa · 2026-02-21
81.0%
#4462: fix: prevent gateway crash when all auth profiles are in cooldown
by garnetlyx · 2026-01-30
80.9%
#11349: fix(agents): do not filter fallback models by models allowlist
by liuxiaopai-ai · 2026-02-07
80.6%