Repository navigation
Conversation
OpenCode resolves an explicitly selected unavailable model to a hard 'Model unavailable' error and silently substitutes its default model for an unavailable agent pin - both at resolution time, before any provider request exists, so the retry hooks cannot see them. route_unavailable (on by default) extends the prompt hook to consult OpenCode's enabled model inventory before the request is built: a mapped original that is not in the inventory is routed to its fallback without waiting for a failure, and sessions return to the original once it is available again. Sessions without an explicit selection (e.g. subagents running on their agent's pinned model) are covered too: an unavailable mapped original pin is routed away, while a deliberately pinned fallback is respected. The inventory snapshot is cached for 30 seconds and invalidated by provider.updated/model.updated events; an inventory that cannot be read never routes.
Switches dropped the session's reasoning effort entirely: the fallback model ran at its default even when it supported the same effort level. switchSessionModel now keeps the session's current variant when the target lists it in its catalog, and falls back to the target's default otherwise (e.g. a non-reasoning fallback or one without the specific level). A mapping value may pin the effort explicitly ('azure/gpt-5.5#high'), which always wins over matching; mapping keys are normalized to be variant-less. When the fallback drops the effort, recovery restores it without plugin-side state: from the session agent's pinned model when it points at the original, else from the original's most recent recorded response (assistant messages persist the model ref with variant). Both sources survive plugin restarts. An untrustworthy inventory never reports support, keeping the previous default-effort behavior.
Model.Info carries both the catalog id (the selectable reference used by sessions, agent pins and mappings) and modelID (the ID sent to the provider). A model renamed through a modelID config attribute - e.g. a provider config key 'mistral-medium-latest' with modelID 'magistral-medium-latest' - made the inventory lookup miss it, so availability routing treated the model as unavailable and silently rerouted sessions to the fallback without any failed request. The inventory now keys by the catalog id, falling back to modelID for entries without one.
Mappings were followed exactly one step: a retryable failure on the fallback itself reported 'Model Fallback Exhausted' and left the decision to the host. Chains now emerge from the transitive composition of the one-to-one mappings ({ A: B, B: C } routes A through B to C): a retryable failure switches the session to the first chain member that can serve the request, skipping members in a global cooldown or missing from the enabled model inventory - which also breaks configured cycles (a cycle truncates at the first repeat). Prompt-time routing walks the same chain. Recovery steps back one level per prompt; a chain member that is itself a mapping key continues to its upstream root when the session's recorded responses show it arrived from there, so deliberately pinned chain members are never yanked. Chain members may carry an explicit #variant (the mapping value), which wins over effort matching as before.
KPhi
force-pushed
the
feat/chained-fallbacks
branch
from
November 12, 2026 06:48
c5efc64 to
34fe16a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Mappings were followed exactly one step: a retryable failure on the fallback
itself reported "Model Fallback Exhausted" and left the decision to the host.
This PR makes chains emerge from the transitive composition of the one-to-one
mappings — no config format change, keys stay one-to-one:
{ "a/gpt": "b/gpt", "b/gpt": "c/gpt" }