GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — feat(session): add configurable fallback model chain by loss-and-quick · Pull Request #27939 · anomalyco/opencode ConversationIssue for this PRCloses #7602 Related: refactors and extends the approach from #26292. Type of change
What does this PR do?Adds a configurable fallback chain: when the primary model returns a retryable error (rate limit, 5xx, overload, quota), the session switches to the next model in the chain instead of failing. The failed model is parked in a process-local cooldown so subsequent turns skip it until it recovers, then traffic flows back to primary on its own. {
"model": "anthropic/claude-sonnet-4-20250514",
"fallbacks": ["openai/gpt-4.1", "deepseek/deepseek-v4"],
"cooldown_seconds": 300
}
This is a continuation of #26292 with three correctness fixes that came up while running it:
A few smaller things:
How did you verify your code works?
Screenshots / recordings
Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Signed-off-by: minicx <[email protected]> Signed-off-by: minicx <[email protected]>
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Fallback notices (e.g. 'Using GLM-4.5-Air while ... is cooling down') are stored with ignored: true but were not filtered out when converting assistant parts to model messages, causing them to leak into the LLM context and be repeated in responses. SessionRetry's built-in heuristics only catch English-language quota /
rate-limit messages (e.g. "Overloaded", "weekly", 429, 5xx). Providers
that return localised quota errors (Zhipu/DeepSeek-style "用户额度不足",
custom "balance" / "payment-required" responses, 402 / 403 / 451
statuses) slip through and the session fails instead of falling back.
Adds opt-in extension points to opencode config:
{
"fallbacks": ["..."],
"fallback_on_errors": {
"patterns": ["额度不足", "insufficient.*balance"],
"status_codes": [402, 403]
}
}
- `patterns` is matched against error.data.message + responseBody.
Tried first as a JS RegExp (case-insensitive), then as a plain
substring if the pattern is not a valid regex — invalid regex never
crashes classification.
- `status_codes` is matched against error.data.statusCode.
- User overrides win; if nothing matches, falls through to
SessionRetry's hardcoded heuristics (anthropic/openai/etc work
out-of-the-box).
`matchUserFallbackConfig` lives in fallback.ts and is unit-tested
against the actual Chinese quota string from a real session
(see fallback.test.ts).
3 of 6 tasks
3 of 6 tasks
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. # Conflicts: # packages/opencode/src/session/llm.ts Fallback chain injects text deltas with IDs like 'fallback-notice' when switching providers. These were passing through the title stream filter and appearing in generated session titles. …ll models When users don't configure agent.title.fallbacks, title generation silently fails on provider errors. Now we automatically build a fallback chain from small models of all other available providers.
3 tasks done
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
hunterchristian
added a commit
to chipp-ai/opencode
that referenced
this pull request
Agents can now configure a fallback model chain (agents.<name>.fallback in config, or the older top-level agent: format). When the selected model fails after RequestExecutor's transport retry budget is spent (429/5xx/529), or with a quota/transport/model-not-found failure, the V2 session runner switches to the next untried fallback and retries the turn -- rather than erroring the whole turn out to the user. Ported from real, working upstream implementations rather than written from scratch (per the standing "reuse upstream PR work" directive for this fork): anomalyco#35188 already targeted this repo's V2 session runner (unlike anomalyco#49125/anomalyco#26292/anomalyco#27939/anomalyco#42424, which patch the legacy V1 processor.ts our own AGENTS.md says new orchestration code must not bridge through) and is the primary source for the config schema shape and general approach. The retry-exhaustion classifier's names/shape come from anomalyco#49125; its logic reuses RequestExecutor's existing LLMError.retryable flag as the single source of truth for "is this retryable" instead of re-deriving a second status-code list. Model-switch attribution is recorded via the session's existing SessionEvent.ModelSwitched event rather than mutating an in-flight input object in place -- a lesson taken directly from anomalyco#27939's writeup of a real bug in its own V1-era approach. New packages/core/src/session/runner/fallback.ts (~40 lines: a classifier + a candidate resolver) and a new ContinueAfterFallback turn-transition in packages/core/src/session/runner/llm.ts, following the exact pattern already used for post-compaction turn continuation. Config plumbing threads the new field through packages/schema/src/ agent.ts, packages/core/src/config/agent.ts (+ plugin and v1 config variants). Regenerated the client and legacy JS SDKs. Known, honestly-scoped gaps: the switch is sticky for the rest of the session (no cooldown/return-to-primary); no mid-stream failover once assistant output has started; only errors marked retryable trigger a switch, so some in-stream provider errors won't while an equivalent HTTP status will; fallback is per-agent only, not per-model or global; a fallback model uses its default variant; no TUI/docs yet. New packages/core/test/session-runner-fallback.test.ts (9 tests) exercises real RequestExecutor retry counts against a scripted fake HTTP client -- exact call sequences, session projection correctness (model-switched message inserted, no leaked failed assistant message, correct final session model), chain-walking past an unresolvable model, non-retryable failures correctly not switching, and chain exhaustion still surfacing the real terminal error. Full packages/core suite: 1164 pass (only the pre-existing, unrelated pty flake). bun typecheck clean across all 30 packages. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabelsProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. [FEATURE]: Native Model Fallback / Failover SupportUh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | ||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |