fix(model-fallback): re-throw LiveSessionModelSwitchError for genuine user-requested switches without configured fallbacks#101700
Conversation
… user-requested switches without configured fallbacks (openclaw#101676)
|
Codex review: needs real behavior proof before merge. Reviewed July 7, 2026, 10:39 AM ET / 14:39 UTC. Summary PR surface: Source +13, Tests +25. Total +38 across 2 files. Reproducibility: yes. source inspection reproduces the current-main path: a no-fallback Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land this narrow no-fallback guard only after redacted real behavior proof shows an active switch retrying on the requested model, while preserving the stale-switch fallback guard. Do we have a high-confidence way to reproduce the issue? Yes, source inspection reproduces the current-main path: a no-fallback Is this the best way to solve the issue? Yes for the no-fallback scope: this is narrower than rethrowing every redirect miss, because it lets real new-target switches escape while preserving stale same/earlier target fallback handling. The remaining proof gap is runtime evidence, not a better code location. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c8d95da14c5b. Label changesLabel justifications:
Evidence reviewedPR surface: Source +13, Tests +25. Total +38 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (1 earlier review cycle)
|
…ve-model-switch-no-fallback
eb6823b to
c24c770
Compare
What Problem This Solves
When a live model switch is requested mid-turn (via
/model, session_status override, cron job override, etc.) and the agent has no configured fallback models, the in-flight turn is killed with a generic failure instead of retrying against the newly-selected model.Closes #101676
Why This Change Was Made
The root cause is in
runWithModelFallbackInternal(src/agents/model-fallback.ts). WhenLiveSessionModelSwitchErroris caught and the switch target is not a later configured fallback candidate, the error is unconditionally wrapped as aFailoverErrorwithfallbackConfigured: false. With no fallback candidates configured, the loop ends immediately after wrapping, andthrowFallbackFailureSummarythrows a generic error that the outer live-switch retry loops cannot recognize as a model-switch event.The fix adds a guard: when the switch target is not in the candidate chain at all (genuine external user request) and there are no configured fallbacks, re-throw the original
LiveSessionModelSwitchErrorso the outer retry loops can catch and process it correctly. This preserves the stale-switch loop guard from #58496 — when the target is already in the candidate chain (same or earlier position), the error is still wrapped asFailoverErrorto prevent infinite retry loops.User Impact
Any mid-turn model switch (
/model, session_status model override, cron job override, etc.) issued while a turn is running, on an agent without configured fallback models, will now correctly retry the turn against the newly-selected model instead of killing it outright.Evidence
pnpm test src/agents/model-fallback.test.ts— 91/91 passed (includes new Live model switch mid-attempt terminates the run instead of retrying against the new model #101676 test)pnpm test src/agents/agent-command.live-model-switch.test.ts— 72/72 passed (no regressions)pnpm test src/cron/isolated-agent/run.live-session-model-switch.test.ts— 6/6 passed (no regressions)🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]