From a05f11ba10e48ec99e1df204d3b1e60b15858809 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sun, 20 Sep 2026 15:51:08 +0800 Subject: [PATCH] fix(webui): notify chats when a fallback model responds --- docs/providers.md | 3 + .../components/thread/ModelFallbackNotice.tsx | 44 +++++++++++++ webui/src/components/thread/ThreadShell.tsx | 32 ++++++++++ webui/src/i18n/locales/en/common.json | 2 + webui/src/i18n/locales/es/common.json | 2 + webui/src/i18n/locales/fr/common.json | 2 + webui/src/i18n/locales/id/common.json | 2 + webui/src/i18n/locales/ja/common.json | 2 + webui/src/i18n/locales/ko/common.json | 2 + webui/src/i18n/locales/pt-BR/common.json | 2 + webui/src/i18n/locales/vi/common.json | 2 + webui/src/i18n/locales/zh-CN/common.json | 2 + webui/src/i18n/locales/zh-TW/common.json | 2 + webui/src/tests/i18n-chat-resources.test.ts | 1 + webui/src/tests/thread-shell.test.tsx | 61 +++++++++++++++++++ 15 files changed, 161 insertions(+) create mode 100644 webui/src/components/thread/ModelFallbackNotice.tsx diff --git a/docs/providers.md b/docs/providers.md index 83da39e93..de2415635 100644 --- a/docs/providers.md +++ b/docs/providers.md @@ -12,6 +12,9 @@ cache. Network, rate-limit, and service failures instead ask you to try again later (failed refreshes are cached briefly). Existing presets and manual model IDs remain available. A successful chat may have used a fallback preset and does not prove that the selected provider's authorization is still valid. +When a live chat uses a fallback model, a dismissible notice above the composer +names that model and links to model settings. It does not change your selected +preset or assume that every fallback means the login expired. For every setup, answer three questions: diff --git a/webui/src/components/thread/ModelFallbackNotice.tsx b/webui/src/components/thread/ModelFallbackNotice.tsx new file mode 100644 index 000000000..c8bd92291 --- /dev/null +++ b/webui/src/components/thread/ModelFallbackNotice.tsx @@ -0,0 +1,44 @@ +import { ArrowRightLeft, X } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +import { Button } from "@/components/ui/button"; + +/** A live fallback is informative, not a failed message or a changed preset. */ +export function ModelFallbackNotice({ model, onDismiss, onOpenSettings }: { + model: string; + onDismiss: () => void; + onOpenSettings?: () => void; +}) { + const { t } = useTranslation(); + return ( +
+ +
+ + {t("thread.composer.fallbackNotice", { + model, + defaultValue: "This response used a fallback model: {{model}}.", + })} + + {onOpenSettings ? ( + + ) : null} +
+ +
+ ); +} diff --git a/webui/src/components/thread/ThreadShell.tsx b/webui/src/components/thread/ThreadShell.tsx index 546106284..078b18d7b 100644 --- a/webui/src/components/thread/ThreadShell.tsx +++ b/webui/src/components/thread/ThreadShell.tsx @@ -7,6 +7,7 @@ import { FilePreviewAvailabilityProvider } from "@/components/FilePreviewAvailab import { FilePreviewPanel } from "@/components/FilePreviewPanel"; import { SessionHandleLabel } from "@/components/SessionHandleLabel"; import { PromptNavigator } from "@/components/thread/PromptNavigator"; +import { ModelFallbackNotice } from "@/components/thread/ModelFallbackNotice"; import { RecoveryNotice } from "@/components/thread/RecoveryNotice"; import { SessionInfoPopover } from "@/components/thread/SessionInfoPopover"; import { ThreadComposer } from "@/components/thread/ThreadComposer"; @@ -690,6 +691,11 @@ export function ThreadShell({ selectItems: installedMcpPresetsFromPayload, }); const [settings, setSettings] = useState(settingsSnapshot); + const [modelFallback, setModelFallback] = useState<{ + chatId: string; + model: string; + dismissed: boolean; + } | null>(null); const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey); const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState(null); const [filePreviewPath, setFilePreviewPath] = useState(null); @@ -964,6 +970,25 @@ export function ThreadShell({ || settings?.agent.model_preset || "default" ); + useEffect(() => { + setModelFallback(null); + if (!chatId) return; + return client.onChat(chatId, (event) => { + if (event.event !== "turn_model_updated") return; + if (event.fallback !== true) { + // The next turn starts with its configured model, not the previous fallback. + setModelFallback(null); + return; + } + const model = event.model_name.trim(); + if (!model) return; + // A tool loop may report the same fallback repeatedly. Closing the notice + // lasts until the next turn/model change, without changing the actual preset. + setModelFallback((current) => current?.chatId === chatId && current.model === model + ? current + : { chatId, model, dismissed: false }); + }); + }, [activeModelPreset, chatId, client]); const handleModelPresetChange = useCallback((name: string) => { setLocalModelPreset(name); if (chatId) { @@ -1521,6 +1546,13 @@ export function ThreadShell({ const composer = ( <> + {modelFallback?.chatId === chatId && !modelFallback.dismissed ? ( + setModelFallback((current) => current && { ...current, dismissed: true })} + /> + ) : null} {recoveryState ? ( { "chat.groups.all", "chat.groups.projects", "chat.newChat", "chat.fallbackTitle", "chat.activity.running", "chat.rename", "chat.loading", "message.fallbackResponse", + "thread.composer.fallbackNotice", "thread.composer.checkModelSettings", ]) { expect(i18n.exists(key), key).toBe(true); expect(i18n.t(key), key).not.toBe(key); diff --git a/webui/src/tests/thread-shell.test.tsx b/webui/src/tests/thread-shell.test.tsx index 28436764e..2417d3bb2 100644 --- a/webui/src/tests/thread-shell.test.tsx +++ b/webui/src/tests/thread-shell.test.tsx @@ -1180,6 +1180,67 @@ describe("ThreadShell", () => { expect(await screen.findByText("backup")).toBeInTheDocument(); }); + it("shows a dismissible, session-scoped fallback notice without changing the composer preset", async () => { + const client = makeClient(); + const openSettings = vi.fn(); + const settings = modelSettings("openai-codex/gpt-5.5", "openai_codex"); + const tree = (chatId: string) => wrap(client, {}} + settingsSnapshot={settings} onOpenModelSettings={openSettings} + />); + const view = render(tree("notice-a")); + await screen.findByTestId("composer-model-logo-openai_codex"); + const emit = (chatId: string, fallback: boolean) => act(() => client._emitChat(chatId, { + event: "turn_model_updated", chat_id: chatId, + model_name: fallback ? "xai-grok/grok-4.5" : "openai-codex/gpt-5.5", + fallback, + })); + const notice = () => screen.queryByText("This response used a fallback model: xai-grok/grok-4.5."); + emit("notice-b", true); + emit("notice-a", false); + expect(notice()).not.toBeInTheDocument(); + emit("notice-a", true); + const banner = notice()!.closest('[role="status"]') as HTMLElement; + expect(banner).toBeVisible(); + expect(screen.getByTestId("composer-model-logo-openai_codex")).toBeInTheDocument(); + expect(banner.textContent).not.toMatch(/expired|sign in/i); + const input = screen.getByRole("textbox"); + fireEvent.change(input, { target: { value: "Keep my draft" } }); + fireEvent.click(within(banner).getByRole("button", { name: "Check model settings" })); + expect(openSettings).toHaveBeenCalledTimes(1); + fireEvent.click(within(banner).getByRole("button", { name: "Dismiss" })); + expect(notice()).not.toBeInTheDocument(); + expect(input).toHaveValue("Keep my draft"); + expect(client.sendSystemCommand).not.toHaveBeenCalled(); + emit("notice-a", true); + expect(notice()).not.toBeInTheDocument(); + // A new turn can notify again; it does not inherit the previous dismissal. + emit("notice-a", false); + emit("notice-a", true); + expect(notice()).toBeVisible(); + view.rerender(tree("notice-b")); + expect(notice()).not.toBeInTheDocument(); + emit("notice-a", true); + expect(notice()).not.toBeInTheDocument(); + view.rerender(tree("notice-a")); + await act(async () => {}); + expect(notice()).not.toBeInTheDocument(); + }); + + it("does not show a live fallback notice just from replayed response attribution", async () => { + vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => Promise.resolve( + String(input).includes("/webui-thread") ? httpJson({ + schemaVersion: 3, + messages: [{ id: "old-reply", role: "assistant", content: "Previous reply", createdAt: 1_000, + responseSources: [{ provider: "xai", model: "grok-4.5", preset: "backup", fallback: true }] }], + }) : { ok: false, status: 404, json: async () => ({}) }, + ))); + render(wrap(makeClient(), {}} settingsSnapshot={modelSettings("gpt-5.5", "openai_codex")} />)); + expect(await screen.findByText("Previous reply")).toBeInTheDocument(); + expect(screen.queryByText(/This response used a fallback model/)).not.toBeInTheDocument(); + }); + it.each([false, true])("hides unconfigured model details in setup tooltips (existing history: %s)", async (hasHistory) => { const client = makeClient(); const settings = modelSettings("anthropic/claude-opus-4-5", "anthropic");