[PR #8669] fix(opencode): correct model fallback index tracking and config parsing #12827

Open
opened 2026-02-16 18:17:43 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8669

State: open
Merged: No


Fixes #1267

Summary

  • Add centralized fallbacks config with provider and model-specific fallback rules
  • Create SessionFallback module for fallback resolution logic
  • Remove per-agent models field and replace with global fallback configuration
  • Track attempted fallbacks to prevent infinite retry loops on same failing model

What Changed

packages/opencode/src/session/fallback.ts (NEW)

  • SessionFallback module for centralized fallback resolution
  • Provider-level and model-specific fallback rules
  • Priority system: model-specific fallbacks override provider-level
  • Fallback tracking to prevent retries on already-tried models

packages/opencode/src/session/processor.ts

  • Refactored to use SessionFallback for error handling
  • Removed per-agent fallback logic
  • Cleaner separation of concerns between error handling and fallback resolution

packages/opencode/src/config/config.ts

  • Added global fallbacks config schema with provider and models sections
  • Model and provider fallback validation rules
  • Removed per-agent models field from config schema

packages/opencode/src/agent/agent.ts

  • Removed models field from Agent schema

packages/opencode/test/session/fallback.test.ts (NEW)

  • Provider fallback resolution tests
  • Model-specific fallback priority tests
  • Fallback tracking and prevention of retries

packages/opencode/test/config/config.test.ts

  • Fallbacks config validation tests

New Config Structure

{
  "fallbacks": {
    "provider": {
      "anthropic": ["openai", "zai"]
    },
    "models": {
      "anthropic/claude-haiku-4-5": ["openai/gpt-5-nano"]
    }
  }
}

How I Verified

  • bun run test - 668 tests pass, 1 skip, 0 fail (669 total across 46 files)
  • bun test test/session/fallback.test.ts test/agent/agent.test.ts test/config/config.test.ts - 78 tests pass, 0 fail
  • bun run typecheck - no errors
  • Verified fallback logic correctly cycles through available models on errors
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8669 **State:** open **Merged:** No --- Fixes #1267 ## Summary - Add centralized fallbacks config with provider and model-specific fallback rules - Create SessionFallback module for fallback resolution logic - Remove per-agent models field and replace with global fallback configuration - Track attempted fallbacks to prevent infinite retry loops on same failing model ## What Changed **packages/opencode/src/session/fallback.ts (NEW)** - SessionFallback module for centralized fallback resolution - Provider-level and model-specific fallback rules - Priority system: model-specific fallbacks override provider-level - Fallback tracking to prevent retries on already-tried models **packages/opencode/src/session/processor.ts** - Refactored to use SessionFallback for error handling - Removed per-agent fallback logic - Cleaner separation of concerns between error handling and fallback resolution **packages/opencode/src/config/config.ts** - Added global fallbacks config schema with provider and models sections - Model and provider fallback validation rules - Removed per-agent models field from config schema **packages/opencode/src/agent/agent.ts** - Removed models field from Agent schema **packages/opencode/test/session/fallback.test.ts (NEW)** - Provider fallback resolution tests - Model-specific fallback priority tests - Fallback tracking and prevention of retries **packages/opencode/test/config/config.test.ts** - Fallbacks config validation tests ## New Config Structure ```json { "fallbacks": { "provider": { "anthropic": ["openai", "zai"] }, "models": { "anthropic/claude-haiku-4-5": ["openai/gpt-5-nano"] } } } ```` ## How I Verified - bun run test - 668 tests pass, 1 skip, 0 fail (669 total across 46 files) - bun test test/session/fallback.test.ts test/agent/agent.test.ts test/config/config.test.ts - 78 tests pass, 0 fail - bun run typecheck - no errors - Verified fallback logic correctly cycles through available models on errors
yindo added the pull-request label 2026-02-16 18:17:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12827