fix(agents): always include configured fallbacks in cross-provider model resolution#37972
fix(agents): always include configured fallbacks in cross-provider model resolution#37972q1uf3ng wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR removes the cross-provider guard in However, the existing test at line 1000 ( Confidence Score: 4/5
|
…chain Previously, cross-provider requests (e.g. xai/grok when config primary is anthropic/claude) would skip all configured fallbacks unless the requested model was already in the fallback chain. This meant users lost their safety net when switching providers mid-session. Now configured fallbacks are always included regardless of provider mismatch, ensuring the full fallback chain is traversed before giving up.
89ed160 to
0f960bf
Compare
Summary
resolveFallbackCandidates()contains a cross-provider guard that empties the configured fallback chain when the requested model's provider differs from the configured primary's provider. For example, when usingxai/grok-4-1-fast-reasoning-latestwith a primary ofanthropic/claude-opus-4-6, the guard checks if the requested model is already in the configured fallback list — and since it isn't, returns an empty fallback array.This causes two problems:
Cost escalation: The candidate list becomes
[xai/grok-4-1-fast-reasoning-latest, anthropic/claude-opus-4-6], skipping the configuredanthropic/claude-sonnet-4-6fallback entirely. If the Grok model fails, it jumps directly to the most expensive model.Tool permission bypass: When fallback reaches the primary model, tool permissions are resolved against the primary's provider policy, not the originally-requested model's. A
deny: [gateway, cron, exec]list configured forxai/*is never consulted.Changes
src/agents/model-fallback.ts: Remove the cross-provider guard inresolveFallbackCandidates(). Configured fallbacks are now always included in the candidate list regardless of provider mismatch.The guard was originally added to prevent fallback chain pollution when switching providers, but in practice it causes worse behavior (silent cost escalation and permission bypass) than the problem it tried to prevent.
Test plan
[claude-sonnet-4-6]with primaryclaude-opus-4-6xai/grok-4-1-fast-reasoning-latestCloses #37813