Skip to content

feat(platform): model fallback mechanisms with reusable ModelSelector - #1358

Merged
yannickmonney merged 2 commits into
mainfrom
feat/model-fallback
Apr 10, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
feat/model-fallback

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Reusable ModelSelector component with drag-to-reorder (Framer Motion ReorderList + SearchableSelect), Storybook stories, and accessibility-tested unit tests. Replaces the inline model list in the agent instructions page.
  • Generation-level fallback retry loop in runAgentGeneration: when a model call fails with a transient error (rate limit, timeout, 5xx), the system automatically tries the next model in the agent's ordered supportedModels list. Includes circuit breaker recording, deadline budget checks, failed message cleanup, and [MODEL_FALLBACK] system messages displayed as warnings in chat.
  • Arena mode exception: explicit model overrides (arena A/B testing) clear fallbackModels so specific models are tested without failover.
  • Workflow noFallback option: LLM nodes in automations now use fallback-aware resolution by default, with an opt-out noFallback: boolean property.
  • Upgraded 6 background call sites (summarization, message improvement, translation, cron generation, image analysis) to use resolveLanguageModelWithFallback for circuit-breaker-aware resolution.

Test plan

  • All 1863 UI tests pass (npm run test:ui)
  • All 1946 backend tests pass (npm test)
  • Lint clean (npm run lint)
  • CodeRabbit review finding addressed
  • Manual: verify ModelSelector reorder/add/remove in agent editor
  • Manual: verify fallback system message in chat when primary model fails
  • Manual: verify arena mode does NOT fallback
  • Manual: verify workflow LLM node uses fallback by default, respects noFallback

Summary by CodeRabbit

  • New Features
    • Agents now support configuring multiple AI models with automatic fallback—when the primary model is unavailable, the system tries ordered fallback models.
    • Enhanced agent model configuration with reordering controls (move up, move down, drag handles).
    • Workflow steps can optionally disable model fallback behavior.

Add automatic model fallback when LLM calls fail, with ordered retry
based on the agent's supportedModels list (first = primary, rest =
fallback chain).

- Create reusable ModelSelector component with drag-to-reorder
  (ReorderList + SearchableSelect), stories, and tests
- Replace inline model list in agent instructions page
- Add fallbackModels field to SerializableAgentConfig, populated from
  supportedModels[1..]
- Implement generation-level fallback retry loop in runAgentGeneration
  with transient error detection, circuit breaker recording, deadline
  budget checks, and failed message cleanup between attempts
- Add [MODEL_FALLBACK] system message tag (warning variant) so users
  see fallback info in chat
- Disable fallback in arena mode (explicit model override clears
  fallbackModels)
- Add noFallback option to workflow LLM nodes, upgrade to
  fallback-aware resolution by default
- Upgrade 6 background call sites (summarization, message improvement,
  translation, cron generation, image analysis) to use
  resolveLanguageModelWithFallback

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a model fallback/failover system with UI support. It adds a new ModelSelector React component for managing ordered model lists with add, remove, and reorder capabilities, alongside Storybook stories and comprehensive Vitest tests. Agent configuration is updated to populate fallbackModels from supportedModels, and the core chat action handler implements retry logic with circuit breaker handling. Multiple model resolution calls throughout the codebase are switched from resolveLanguageModel to resolveLanguageModelWithFallback. A noFallback flag is added to LLM workflow node configurations. New translations support model reordering UI, describe the fallback behavior, and a new MODEL_FALLBACK system message tag is introduced.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

  • PR #594: The new ModelSelector component directly uses the SearchableSelect component introduced in this PR.
  • PR #949: Overlapping changes to agent model selection UI and configuration in services/platform/app/routes/dashboard/$id/agents/$agentId/instructions.tsx and related components.
  • PR #1348: Direct integration of the ModelSelector component into additional contexts alongside agent model selection features.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: introducing model fallback mechanisms and a reusable ModelSelector component, which are the core themes across all file modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/model-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yannickmonney
yannickmonney merged commit bd2f215 into main Apr 10, 2026
23 checks passed
@yannickmonney
yannickmonney deleted the feat/model-fallback branch April 10, 2026 17:46
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