fix(webui): notify chats when a fallback model responds
This commit is contained in:
1 parent
024fe8f636
commit
a05f11ba10
15 files changed
+161
No files matched your search
@@ -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:
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
role="status"
|
||||
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-start gap-2 rounded-control border border-border/60 bg-muted/40 px-3 py-2 text-xs text-foreground/80 animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none"
|
||||
>
|
||||
<ArrowRightLeft className="mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-3 gap-y-1 leading-5">
|
||||
<span className="min-w-0 break-words [overflow-wrap:anywhere]">
|
||||
{t("thread.composer.fallbackNotice", {
|
||||
model,
|
||||
defaultValue: "This response used a fallback model: {{model}}.",
|
||||
})}
|
||||
</span>
|
||||
{onOpenSettings ? (
|
||||
<button type="button" onClick={onOpenSettings} className="shrink-0 rounded-sm font-medium text-foreground underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
{t("thread.composer.checkModelSettings", { defaultValue: "Check model settings" })}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 shrink-0 rounded-full"
|
||||
aria-label={t("common.dismiss")}
|
||||
onClick={onDismiss}
|
||||
>
|
||||
<X className="h-3.5 w-3.5" aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<SettingsPayload | null>(settingsSnapshot);
|
||||
const [modelFallback, setModelFallback] = useState<{
|
||||
chatId: string;
|
||||
model: string;
|
||||
dismissed: boolean;
|
||||
} | null>(null);
|
||||
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
|
||||
const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState<string | null>(null);
|
||||
const [filePreviewPath, setFilePreviewPath] = useState<string | null>(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 ? (
|
||||
<ModelFallbackNotice
|
||||
model={modelFallback.model}
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
onDismiss={() => setModelFallback((current) => current && { ...current, dismissed: true })}
|
||||
/>
|
||||
) : null}
|
||||
{recoveryState ? (
|
||||
<RecoveryNotice
|
||||
state={recoveryState}
|
||||
|
||||
@@ -1583,6 +1583,8 @@
|
||||
"chooseAI": "Choose your AI",
|
||||
"switchModel": "Switch model for this chat",
|
||||
"manageModels": "Manage models",
|
||||
"fallbackNotice": "This response used a fallback model: {{model}}.",
|
||||
"checkModelSettings": "Check model settings",
|
||||
"context": {
|
||||
"tooltip": "Context {{percent}}%",
|
||||
"detailsLabel": "Open context usage",
|
||||
|
||||
@@ -1384,6 +1384,8 @@
|
||||
"chooseAI": "Elige tu IA",
|
||||
"switchModel": "Cambiar el modelo de este chat",
|
||||
"manageModels": "Gestionar modelos",
|
||||
"fallbackNotice": "Esta respuesta usó un modelo alternativo: {{model}}.",
|
||||
"checkModelSettings": "Revisar ajustes del modelo",
|
||||
"context": {
|
||||
"tooltip": "Contexto {{percent}}%",
|
||||
"detailsLabel": "Abrir uso del contexto",
|
||||
|
||||
@@ -1383,6 +1383,8 @@
|
||||
"chooseAI": "Choisissez votre IA",
|
||||
"switchModel": "Changer le modèle de cette conversation",
|
||||
"manageModels": "Gérer les modèles",
|
||||
"fallbackNotice": "Cette réponse a utilisé un modèle de secours : {{model}}.",
|
||||
"checkModelSettings": "Vérifier les paramètres du modèle",
|
||||
"context": {
|
||||
"tooltip": "Contexte {{percent}} %",
|
||||
"detailsLabel": "Ouvrir l’utilisation du contexte",
|
||||
|
||||
@@ -1383,6 +1383,8 @@
|
||||
"chooseAI": "Pilih AI Anda",
|
||||
"switchModel": "Ganti model untuk percakapan ini",
|
||||
"manageModels": "Kelola model",
|
||||
"fallbackNotice": "Respons ini menggunakan model cadangan: {{model}}.",
|
||||
"checkModelSettings": "Periksa pengaturan model",
|
||||
"context": {
|
||||
"tooltip": "Konteks {{percent}}%",
|
||||
"detailsLabel": "Buka penggunaan konteks",
|
||||
|
||||
@@ -1383,6 +1383,8 @@
|
||||
"chooseAI": "AI を選択",
|
||||
"switchModel": "この会話で使うモデルを切り替える",
|
||||
"manageModels": "モデルを管理",
|
||||
"fallbackNotice": "この応答では代替モデルを使用しました:{{model}}。",
|
||||
"checkModelSettings": "モデル設定を確認",
|
||||
"context": {
|
||||
"tooltip": "コンテキスト {{percent}}%",
|
||||
"detailsLabel": "コンテキスト使用量を開く",
|
||||
|
||||
@@ -1383,6 +1383,8 @@
|
||||
"chooseAI": "AI 선택",
|
||||
"switchModel": "이 대화에서 사용할 모델 전환",
|
||||
"manageModels": "모델 관리",
|
||||
"fallbackNotice": "이 응답은 대체 모델을 사용했습니다: {{model}}.",
|
||||
"checkModelSettings": "모델 설정 확인",
|
||||
"context": {
|
||||
"tooltip": "컨텍스트 {{percent}}%",
|
||||
"detailsLabel": "컨텍스트 사용량 열기",
|
||||
|
||||
@@ -1397,6 +1397,8 @@
|
||||
"chooseAI": "Escolha sua IA",
|
||||
"switchModel": "Alternar o modelo desta conversa",
|
||||
"manageModels": "Gerenciar modelos",
|
||||
"fallbackNotice": "Esta resposta usou um modelo alternativo: {{model}}.",
|
||||
"checkModelSettings": "Verificar configurações do modelo",
|
||||
"context": {
|
||||
"tooltip": "Contexto {{percent}}%",
|
||||
"detailsLabel": "Abrir uso do contexto",
|
||||
|
||||
@@ -1383,6 +1383,8 @@
|
||||
"chooseAI": "Chọn AI của bạn",
|
||||
"switchModel": "Chuyển mô hình cho cuộc trò chuyện này",
|
||||
"manageModels": "Quản lý mô hình",
|
||||
"fallbackNotice": "Phản hồi này đã sử dụng mô hình dự phòng: {{model}}.",
|
||||
"checkModelSettings": "Kiểm tra cài đặt mô hình",
|
||||
"context": {
|
||||
"tooltip": "Ngữ cảnh {{percent}}%",
|
||||
"detailsLabel": "Mở mức sử dụng ngữ cảnh",
|
||||
|
||||
@@ -1582,6 +1582,8 @@
|
||||
"chooseAI": "选择你的 AI",
|
||||
"switchModel": "切换本次对话所用模型",
|
||||
"manageModels": "管理模型预设",
|
||||
"fallbackNotice": "本次已使用备用模型:{{model}}。",
|
||||
"checkModelSettings": "检查模型设置",
|
||||
"context": {
|
||||
"tooltip": "上下文 {{percent}}%",
|
||||
"detailsLabel": "打开上下文用量",
|
||||
|
||||
@@ -1383,6 +1383,8 @@
|
||||
"chooseAI": "選擇你的 AI",
|
||||
"switchModel": "切換此對話使用的模型",
|
||||
"manageModels": "管理模型預設",
|
||||
"fallbackNotice": "本次已使用備用模型:{{model}}。",
|
||||
"checkModelSettings": "檢查模型設定",
|
||||
"context": {
|
||||
"tooltip": "上下文 {{percent}}%",
|
||||
"detailsLabel": "開啟上下文用量",
|
||||
|
||||
@@ -16,6 +16,7 @@ describe("chat translation resources", () => {
|
||||
"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);
|
||||
|
||||
@@ -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, <ThreadShell
|
||||
session={session(chatId)} title="Fallback notice" onToggleSidebar={() => {}}
|
||||
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(), <ThreadShell session={session("old-fallback")} title="History"
|
||||
onToggleSidebar={() => {}} 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");
|
||||
|
||||
Reference in new issue
Block a user