opencode
opencode copied to clipboard
fix(opencode): correct model fallback index tracking and config parsing
Fixes #1267
Summary
- Fix
fallbackIndexnever incrementing after successful model switch, causing infinite retry loop on same failing model - Add
modelstoknownKeysin config transform to prevent it being moved tooptions - Add tests for edge cases: empty models array, options isolation, native agent fallbacks
What changed
processor.ts
- Increment
fallbackIndexbefore callingtryFallbackModel, not after - Simplified the helper to take
targetIndexdirectly
config.ts
- Added
"models"to the known keys set so the config transform preserves it correctly
agent.test.ts
- Added 3 new test cases covering edge cases
How I verified
- Ran
bun test test/agent/agent.test.ts— all 31 tests pass - Ran
bun run typecheck— no errors - Ran
bun run test— 666 pass, 1 skip - Reviewed the logic: each error now advances to the next fallback model instead of retrying the same one