Skip to content

Follow fallback chains transitively - #3

Open
KPhi wants to merge 4 commits into
renjfk:mainfrom
KPhi:feat/chained-fallbacks
Open

KPhi wants to merge 4 commits into
renjfk:mainfrom
KPhi:feat/chained-fallbacks

Conversation

@KPhi

@KPhi KPhi commented Nov 11, 2026

Copy link
Copy Markdown

Stacked on #2 - the chain walk reuses its model inventory (isRoutable = cooldown + availability).

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" }

KPhi added 4 commits November 11, 2026 10:45
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
KPhi force-pushed the feat/chained-fallbacks branch from c5efc64 to 34fe16a Compare November 12, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant