feat(processor): add model fallback chain when retries are exhausted#24369
feat(processor): add model fallback chain when retries are exhausted#24369herjarsa wants to merge 1 commit into
Conversation
When the primary model fails after all retries, automatically try the next model from the fallback chain. This adds: - fallbackModels field to MessageV2.User schema - resolveFallbackChain helper to Provider service - outer fallback loop in SessionProcessor.process() - error classification: only retryable errors trigger fallback - No fallback for: AuthError, AbortedError, non-retryable APIError - Fallback for: rate limits, 5xx, other transient errors
|
The following comment was made by an LLM, it may be inaccurate: I found two potentially related PRs:
These PRs may have addressed similar or overlapping functionality regarding model fallback chains. You may want to check if PR #24369 duplicates work from these earlier PRs or if they complement each other. |
|
Thanks for the automatic detection of related PRs! I'm aware of #13189 (by @keakon) which provides a more comprehensive implementation with TTFT timeout, SessionFallback module, state tracking, and toast notifications. This PR (#24369) is intentionally a lightweight alternative:
Tradeoffs:
When to use each:
I'''m keeping this PR open as an option for the maintainers - if #13189 gets merged first, I'''m happy to close this one. If the team prefers a simpler approach first, this PR is ready to go. |
|
Sibling PR — heads up that #26292 implements a complete fallback chain with cooldown, stream error detection, and model attribution. Detailed comparison in the PR description. Would be great to align on approach so these don't diverge further. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #10287
Type of change
What does this PR do?
Adds automatic model fallback chain when the primary model fails after all retries are exhausted.
When a model encounters an error that retries cannot resolve, the processor now checks if a
fallbackModelschain was configured (e.g. viafallback_modelin agent config). If so, it resolves the next model in the chain and re-attempts the stream with that model.Error classification for fallback:
Implementation details:
fallbackModelsfield toMessageV2.UserschemaresolveFallbackChainhelper toProviderservice (returns{model, remaining})whileloop inSessionProcessor.process()to iterate through fallback modelshalt()to classify errors and setctx.shouldFallbackflag when appropriateHow did you verify your code works?
bun typecheckpasses with zero errors in modified filestest/session/fallback.test.ts:Checklist