Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): remove the failover models field from chat settings (#20661)

Zhichang Yu3b1d7b5e86cb
diff --git a/web/src/components/llm-setting-items/failover-models-field.test.tsx b/web/src/components/llm-setting-items/failover-models-field.test.tsx
deleted file mode 100644
index 26a009f84d..0000000000
--- a/web/src/components/llm-setting-items/failover-models-field.test.tsx
+++ /dev/null
@@ -1,85 +0,0 @@
-import { render, screen, waitFor } from '@testing-library/react';
-import { TooltipProvider } from '@/components/ui/tooltip';
-import { FormProvider, useForm } from 'react-hook-form';
-import { FailoverModelsField } from './failover-models-field';
-
-const models: any[] = [
- {
- model_id: 'primary-id',
- name: 'gpt-4o',
- instance_name: 'openai-main',
- provider_name: 'OpenAI',
- model_type: ['chat'],
- },
- {
- model_id: 'backup-id',
- name: 'deepseek-chat',
- instance_name: 'deepseek-cn',
- provider_name: 'DeepInfra',
- model_type: ['chat'],
- },
-];
-
-jest.mock('@/hooks/use-llm-request', () => ({
- useFetchAllAddedModels: () => ({ data: models, isFetched: true }),
- useFindLlmByUuid: () => (id: string) => models.find((m) => m.model_id === id),
-}));
-
-function Harness({ value }: { value: string[] }) {
- const form = useForm({ defaultValues: { failover_llm_ids: value } });
- return (
- <FormProvider {...form}>
- <form>
- <TooltipProvider>
- <FailoverModelsField
- ownerTenantId="tenant-1"
- primaryLlmId="primary-id"
- />
- </TooltipProvider>
- </form>
- </FormProvider>
- );
-}
-
-describe('FailoverModels display', () => {
- it('shows the primary as name + instance rather than a raw id', async () => {
- render(<Harness value={[]} />);
-
- await waitFor(() => {
- expect(screen.getByText('gpt-4o')).toBeInTheDocument();
- });
- expect(screen.getByText('openai-main')).toBeInTheDocument();
- expect(screen.queryByText('primary-id')).not.toBeInTheDocument();
- });
-
- it('shows each member as name + instance, in order', async () => {
- render(<Harness value={['backup-id']} />);
-
- await waitFor(() => {
- expect(screen.getByText('deepseek-chat')).toBeInTheDocument();
- });
- expect(screen.getByText('deepseek-cn')).toBeInTheDocument();
- expect(screen.queryByText('backup-id')).not.toBeInTheDocument();
- });
-
- it('marks a member the backend can no longer resolve as stale, keeping the row', async () => {
- // The backend skips an unresolvable member with a warning rather than
- // failing the turn, so the row must stay visible for the author to remove.
- render(<Harness value={['deleted-id']} />);
-
- await waitFor(() => {
- expect(screen.getByTestId('chat-failover-member-0')).toBeInTheDocument();
- });
- expect(screen.getByText('deleted-id')).toBeInTheDocument();
- });
-
- it('never lists the primary as a fallback member', async () => {
- render(<Harness value={['primary-id', 'backup-id']} />);
-
- await waitFor(() => {
- expect(screen.getByTestId('chat-failover-member-0')).toBeInTheDocument();
- });
- // Only the backup survives; the primary duplicate is dropped.
- expect(screen.getAllByTestId(/chat-failover-member-/)).toHaveLength(1);
- });
-});
diff --git a/web/src/components/llm-setting-items/failover-models-field.tsx b/web/src/components/llm-setting-items/failover-models-field.tsx
deleted file mode 100644
index a3b44f5b40..0000000000
--- a/web/src/components/llm-setting-items/failover-models-field.tsx
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { LLMLabel, MissingModelLabel } from '@/components/llm-select/llm-label';
-import { ModelTreeSelect } from '@/components/model-tree-select';
-import {
- FormControl,
- FormField,
- FormItem,
- FormLabel,
-} from '@/components/ui/form';
-import { Button } from '@/components/ui/button';
-import { useFetchAllAddedModels } from '@/hooks/use-llm-request';
-import { ArrowDown, ArrowUp, X } from 'lucide-react';
-import { useTranslation } from 'react-i18next';
-
-export type FailoverModelsFieldProps = {
- name?: string;
- ownerTenantId?: string;
- /** The dialog's own model, rendered read-only as the chain's head. */
- primaryLlmId?: string;
-};
-
-type FailoverModelsProps = Omit<FailoverModelsFieldProps, 'name'> & {
- value?: string[];
- onChange?: (value: string[]) => void;
-};
-
-/**
- * FailoverModels edits the ordered list of fallback models a dialog may switch
- * to when the primary model hits a provider-level failure.
- *
- * Order is the author's priority: the backend hands this list to
- * NewFailoverEinoChatModel, which walks it in order and keeps a member that
- * served a call in front. The primary model is deliberately NOT part of this
- * list — it is the dialog's own model selection and always heads the chain, so
- * including it here would let the list contradict the primary.
- *
- * This is unrelated to the "Multiple models" panel button, which opens N
- * side-by-side conversations for a human to compare answers.
- */
-function FailoverModels({
- ownerTenantId,
- primaryLlmId,
- value = [],
- onChange,
-}: FailoverModelsProps) {
- const { t } = useTranslation();
- const { data: allModels, isFetched: modelsFetched } = useFetchAllAddedModels(
- undefined,
- ownerTenantId,
- );
- const members = Array.isArray(value) ? value : [];
-
- // A member that equals the primary would be attempted twice in a row; drop it
- // on the way in so a stale saved value cannot produce a pointless duplicate.
- const distinct = members.filter((id) => id && id !== primaryLlmId);
-
- const emit = (next: string[]) => {
- onChange?.(next.filter((id, index) => id && next.indexOf(id) === index));
- };
-
- const addMember = (id: string) => {
- if (!id || id === primaryLlmId || distinct.includes(id)) return;
- emit([...distinct, id]);
- };
-
- const removeAt = (index: number) =>
- emit(distinct.filter((_, i) => i !== index));
-
- const move = (index: number, delta: number) => {
- const target = index + delta;
- if (target < 0 || target >= distinct.length) return;
- const next = [...distinct];
- [next[index], next[target]] = [next[target], next[index]];
- emit(next);
- };
-
- /**
- * A member the backend can no longer resolve is still shown, marked stale
- * rather than dropped: the backend skips it with a warning, so removing the
- * row here would hide a real (if degraded) configuration from the author.
- */
- const isStale = (id: string) =>
- modelsFetched && !allModels?.some((m) => m.model_id === id);
-
- return (
- <FormItem>
- <FormLabel tooltip={t('chat.failoverModelsTip')}>
- {t('chat.failoverModels')}
- </FormLabel>
- <FormControl>
- <div className="space-y-2" data-testid="chat-failover-models">
- <div className="flex items-center gap-1.5 text-xs">
- <span className="text-text-secondary shrink-0">
- {t('chat.failoverModelsPrimaryLabel')}
- </span>
- {primaryLlmId ? (
- <div className="min-w-0 flex-1">
- <LLMLabel value={primaryLlmId} ownerTenantId={ownerTenantId} />
- </div>
- ) : (
- <span className="text-text-disabled truncate">
- {t('chat.failoverModelsNoPrimary')}
- </span>
- )}
- </div>
-
- {distinct.length === 0 ? (
- <p
- className="text-text-disabled text-xs"
- data-testid="chat-failover-empty"
- >
- {t('chat.failoverModelsEmpty')}
- </p>
- ) : (
- <ul className="space-y-1">
- {distinct.map((id, index) => (
- <li
- key={id}
- className="border-border-button flex items-center gap-2 rounded border px-2 py-1"
- data-testid={`chat-failover-member-${index}`}
- >
- <span className="text-text-secondary w-4 shrink-0 text-xs">
- {index + 1}
- </span>
- <div className="min-w-0 flex-1 text-sm">
- {isStale(id) ? (
- <MissingModelLabel
- value={id}
- ownerTenantId={ownerTenantId}
- />
- ) : (
- <LLMLabel value={id} ownerTenantId={ownerTenantId} />
- )}
- </div>
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- disabled={index === 0}
- onClick={() => move(index, -1)}
- data-testid={`chat-failover-up-${index}`}
- >
- <ArrowUp className="size-3.5" />
- </Button>
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- disabled={index === distinct.length - 1}
- onClick={() => move(index, 1)}
- data-testid={`chat-failover-down-${index}`}
- >
- <ArrowDown className="size-3.5" />
- </Button>
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- onClick={() => removeAt(index)}
- data-testid={`chat-failover-remove-${index}`}
- >
- <X className="size-3.5" />
- </Button>
- </li>
- ))}
- </ul>
- )}
-
- <div className="flex items-center gap-2">
- <ModelTreeSelect
- modelTypes={['chat']}
- ownerTenantId={ownerTenantId}
- allowClear
- placeholder={t('chat.failoverModelsAdd')}
- onChange={addMember}
- testId="chat-failover-add-select"
- />
- </div>
- </div>
- </FormControl>
- </FormItem>
- );
-}
-
-/**
- * FailoverModelsField binds FailoverModels to a react-hook-form field whose value
- * is the raw string[] stored in llm_setting.
- */
-export function FailoverModelsField(props: FailoverModelsFieldProps) {
- return (
- <FormField
- name={props.name ?? 'failover_llm_ids'}
- render={({ field }) => (
- <FailoverModels
- {...props}
- value={Array.isArray(field.value) ? field.value : []}
- onChange={field.onChange}
- />
- )}
- />
- );
-}
diff --git a/web/src/components/llm-setting-items/failover-schema.test.ts b/web/src/components/llm-setting-items/failover-schema.test.ts
deleted file mode 100644
index 080dd7191b..0000000000
--- a/web/src/components/llm-setting-items/failover-schema.test.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import { z } from 'zod';
-
-/**
- * Chat settings validate the model settings with `z.object(LlmSettingFieldSchema)`
- * (see use-chat-setting-schema.tsx), and zod DROPS undeclared keys. So a field
- * that is not declared in that map fails silently: it never reaches the form
- * (the editor renders nothing) and is stripped on submit (nothing is
- * persisted). type-check and lint both pass in that state, which is why the
- * declaration needs a runtime assertion.
- *
- * The field list is duplicated here rather than imported from
- * llm-setting-items/next.tsx on purpose: importing that module pulls in the
- * component tree, which needs a DOM `Request` global that the jest environment
- * does not provide. Keep this in sync with LlmSettingFieldSchema — the
- * failover_llm_ids entry is the one this test protects.
- */
-const LlmSettingFieldSchemaSubset = {
- temperature: z.coerce.number().optional(),
- max_tokens: z.number().optional(),
- thinking: z.enum(['default', 'enabled', 'disabled']).optional(),
- failover_llm_ids: z.array(z.string()).optional(),
-};
-
-describe('chat llm_setting schema keeps failover_llm_ids', () => {
- const schema = z.object(LlmSettingFieldSchemaSubset);
-
- it('keeps the field so the editor receives a value', () => {
- const parsed = schema.parse({
- temperature: 0.5,
- failover_llm_ids: ['model-a', 'model-b'],
- });
-
- expect(parsed.failover_llm_ids).toEqual(['model-a', 'model-b']);
- });
-
- it('preserves author order, which is the failover priority', () => {
- const parsed = schema.parse({ failover_llm_ids: ['z-model', 'a-model'] });
-
- expect(parsed.failover_llm_ids).toEqual(['z-model', 'a-model']);
- });
-
- it('accepts an absent or empty list', () => {
- expect(schema.parse({}).failover_llm_ids).toBeUndefined();
- expect(schema.parse({ failover_llm_ids: [] }).failover_llm_ids).toEqual([]);
- });
-
- it('rejects a non-string member rather than persisting garbage', () => {
- // The backend drops non-string entries; rejecting here surfaces the typo in
- // the UI instead of silently shortening the chain.
- expect(() => schema.parse({ failover_llm_ids: ['ok', 42] })).toThrow();
- });
-
- it('demonstrates the failure mode: an undeclared key is dropped', () => {
- // This is what the feature looked like before the fix — proof that the
- // assertion above is load-bearing and not a formality.
- const withoutDeclaration = z.object({
- temperature: z.coerce.number().optional(),
- });
-
- expect(
- withoutDeclaration.parse({ failover_llm_ids: ['model-a'] }),
- ).not.toHaveProperty('failover_llm_ids');
- });
-});
diff --git a/web/src/components/llm-setting-items/next.tsx b/web/src/components/llm-setting-items/next.tsx
index ea1d5b3622..ffc2732e2f 100644
--- a/web/src/components/llm-setting-items/next.tsx
+++ b/web/src/components/llm-setting-items/next.tsx
@@ -83,10 +83,6 @@ export const LlmSettingFieldSchema = {
max_tokens: z.number().optional(),
parameter: z.string().optional(),
thinking: z.enum(['default', 'enabled', 'disabled']).optional(),
- // Ordered fallback models for the agentic agent. It has to be declared here
- // or z.object() strips it: an undeclared key never reaches the form, so the
- // editor renders nothing and the value is dropped on submit.
- failover_llm_ids: z.array(z.string()).optional(),
};
export const LlmSettingSchema = {
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 95ee6f33a9..02c6e4d9f2 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -1170,14 +1170,6 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s
thinkingLevelUltraDescription: 'Maximum cognitive effort',
thinkingLevelAgentic: 'Agentic',
thinkingLevelAgenticDescription: 'Self-directed corpus exploration',
- failoverModels: 'Failover models',
- failoverModelsTip:
- 'When the primary model hits a provider error, the agentic agent switches to the next model in this list, in order.',
- failoverModelsPrimaryLabel: 'Primary model',
- failoverModelsNoPrimary: 'Tenant default',
- failoverModelsEmpty:
- 'No fallback model. Add at least one so a provider failure can be survived.',
- failoverModelsAdd: 'Add a fallback model',
thinkingTip:
'Only controls thinking mode for official Qwen, Kimi, and GLM model providers. System default disables Qwen thinking to avoid long-running tasks.',
quote: 'Show citations',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 649c365713..6e1776bc50 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -1065,14 +1065,6 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R
thinkingLevelUltraDescription: '尽力思考',
thinkingLevelAgentic: 'Agentic',
thinkingLevelAgenticDescription: '自主探索语料库',
- failoverModels: '备用模型',
- failoverModelsTip:
- '当主模型遇到服务商故障时,Agentic智能体按此列表顺序切换到下一个模型。',
- failoverModelsPrimaryLabel: '主模型',
- failoverModelsNoPrimary: '租户默认',
- failoverModelsEmpty:
- '暂无备用模型。至少添加一个,才能在服务商故障时继续服务。',
- failoverModelsAdd: '添加备用模型',
thinkingTip:
'仅控制官方模型提供商中的 Qwen、Kimi 和 GLM 模型思考模式。系统默认会关闭 Qwen 思考,以避免任务长时间运行。',
quote: '显示引文',
diff --git a/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx b/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx
index ec51b697a5..5de48ca2a8 100644
--- a/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx
+++ b/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx
@@ -2,7 +2,6 @@
import { AvatarNameDescription } from '@/components/avatar-name-description';
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
-import { FailoverModelsField } from '@/components/llm-setting-items/failover-models-field';
import { LlmSettingFieldItems } from '@/components/llm-setting-items/next';
import {
FormControl,
@@ -12,7 +11,6 @@ import {
FormMessage,
} from '@/components/ui/form';
import { Textarea } from '@/components/ui/textarea';
-import { useFetchChat } from '@/hooks/use-chat-request';
import { useTranslate } from '@/hooks/common-hooks';
import { prefixName } from '@/utils/form';
import { getDirAttribute } from '@/utils/text-direction';
@@ -42,15 +40,6 @@ export default function ChatBasicSetting({
const llmSettingPrefix = prefixName(prefix, 'llm_setting');
- // The failover list heads the chain with the dialog's own model, so the
- // editor needs that id and the tenant that owns the model list.
- const { data: chatData } = useFetchChat();
- const llmIdValue = useWatch({
- control: form.control,
- name: prefixName(prefix, 'llm_id'),
- });
- const ownerTenantId = chatData?.tenant_id;
-
return (
<div className="space-y-8">
{hideName || (
@@ -68,12 +57,6 @@ export default function ChatBasicSetting({
onCollapseOpenChange={onCollapseOpenChange}
></LlmSettingFieldItems>
- <FailoverModelsField
- name={prefixName(prefix, 'llm_setting.failover_llm_ids')}
- ownerTenantId={ownerTenantId}
- primaryLlmId={llmIdValue}
- />
-
<FormField
control={form.control}
name={prefixName(prefix, 'prompt_config.prologue')}