fix(opencode): correct model fallback index tracking and config parsing#8669
fix(opencode): correct model fallback index tracking and config parsing#8669manascb1344 wants to merge 8 commits intoanomalyco:devfrom
Conversation
- Extract tryFallbackModel() helper function to reduce nesting - Break long lines for better readability - Reduce nesting from 3 levels to 2 levels - Improve separation of concerns
- Fix fallbackIndex never incrementing after successful model switch - Add 'models' to knownKeys in config transform to prevent moving to options - Simplify tryFallbackModel to take targetIndex directly - Add tests for empty models array, options isolation, and native agent fallbacks
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
Okay this is decent, but was wondering if this could be better... I think the top level config should have a key called "fallbacks" which is an object that has 1 or two keys something like: Something like this, and it shouldn't be on the agents config I'd rather have it completely centralized and using the same providerID / modelID pattern we use everywhere else Idk if this is the cleanest but thoughts? |
|
Makes sense, centralized is cleaner. A couple questions:
|
- Add global fallbacks config with provider and model-specific rules
- Create SessionFallback module for fallback resolution logic
- Remove per-agent models field from Agent schema and config
- Model-specific fallbacks take priority over provider-level
- Track attempted fallbacks to avoid retries on same model
BREAKING CHANGE: Fallbacks are now configured globally:
Before:
agent:
build:
models: [anthropic/claude-3-opus, openai/gpt-4o]
After:
fallbacks:
models:
anthropic/claude-3-opus: [openai/gpt-4o]
provider:
anthropic: [openai]
|
I assumed the following while implementing it, please confirm if correct:
|
|
@rekram1-node When can we have this feature merged? |
…ng sent back as assistant message content (anomalyco#11270) Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Will I be able to set this up for specific agents too? Or is this a global config? |
|
Is this feature out? |
Looks like its in review by maintainers |
|
Thanks for the work on model fallback and the refactor, this is a useful step forward. I’d like to suggest a slightly different abstraction that could make this more flexible and predictable long-term: introducing “virtual models” as a first-class concept in the configuration. Instead of only defining fallback behavior on concrete models or providers, a virtual model would act as an alias to a set of real provider-specific models, together with a selection strategy. Key idea
Why this helps
Example configuration{
"models": {
"virtual/coding": {
"type": "virtual",
"strategy": "sequential",
"models": [
"anthropic/claude-opus-4.5",
"openai/gpt-4.1",
"openai/gpt-4o"
]
},
"virtual/fast": {
"type": "virtual",
"strategy": "round_robin",
"models": [
"openai/gpt-4o-mini",
"openai/gpt-4.1-mini"
]
}
}
}Semantics
This aligns well with ongoing discussions around native fallback and multi-provider usage, and could build cleanly on top of the current implementation without breaking existing configs. |
Fixes #1267
Summary
What Changed
packages/opencode/src/session/fallback.ts (NEW)
packages/opencode/src/session/processor.ts
packages/opencode/src/config/config.ts
packages/opencode/src/agent/agent.ts
packages/opencode/test/session/fallback.test.ts (NEW)
packages/opencode/test/config/config.test.ts
New Config Structure
{ "fallbacks": { "provider": { "anthropic": ["openai", "zai"] }, "models": { "anthropic/claude-haiku-4-5": ["openai/gpt-5-nano"] } } }How I Verified