Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: stop the false "Failed to refresh models" error during a desktop update (#11224)
Nilay6a5ab1f389f2
diff --git a/studio/frontend/src/app/provider.tsx b/studio/frontend/src/app/provider.tsxindex e3f1548619c..5fc14ca795a 100644--- a/studio/frontend/src/app/provider.tsx+++ b/studio/frontend/src/app/provider.tsx@@ -43,6 +43,8 @@ import { TauriUpdateContext } from "@/hooks/tauri-update-context";import { type BackendStatus, useTauriBackend } from "@/hooks/use-tauri-backend";import { useTauriUpdate } from "@/hooks/use-tauri-update";import { isTauri } from "@/lib/api-base";+import { followDesktopUpdateScreen } from "@/lib/desktop-update-activity";+import { resyncInferenceStatusAfterServerModelChange } from "@/features/chat";import { getToastOffsets } from "@/lib/toast-offset";import { Z_LAYER } from "@/lib/z-layers";import { useRouterState } from "@tanstack/react-router";@@ -441,6 +443,18 @@ function TauriUpdateLayer({update.status === "installing" ||(update.status === "error" && !update.dismissed);+ const wasUpdatingRef = useRef(false);+ useEffect(() => {+ const wasUpdating = wasUpdatingRef.current;+ wasUpdatingRef.current = isUpdating;+ // The backend restarted empty under a mounted chat page, whose picker still names the old model.+ return followDesktopUpdateScreen(+ isUpdating,+ wasUpdating,+ resyncInferenceStatusAfterServerModelChange,+ );+ }, [isUpdating]);+const content = isUpdating ? (<UpdateScreenstatus={update.status}diff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.tsindex fa334f89357..f746eab20a1 100644--- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts+++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts@@ -10,6 +10,10 @@ import {} from "../lib/server-tuning-fields";import { createElement, useCallback, useEffect, useRef, useState } from "react";import { toast } from "@/lib/toast";+import {+ isBackendDownForDesktopUpdate,+ isSilencedDesktopUpdateFailure,+} from "@/lib/desktop-update-activity";import { subscribeModelLifecycle } from "@/lib/model-lifecycle-events";import {type TransferSample,@@ -475,6 +479,7 @@ async function syncInferenceStatusToStore(options?: {externalChatSlotLoad?: boolean;}): Promise<void> {const signal = options?.signal;+ const downWhenIssued = isBackendDownForDesktopUpdate();const includeLoras = options?.includeLoras ?? true;const generation = ++syncGeneration;const loraGeneration = includeLoras ? ++loraSyncGeneration : null;@@ -619,6 +624,8 @@ async function syncInferenceStatusToStore(options?: {// A superseded refresh reports nothing, or a stale failure would raise a toast about a read// whose answer would have been discarded. The LoRA inventory settles from its own request.if (signal?.aborted || superseded()) return;+ // The update screen already reports the backend it stopped.+ if (isSilencedDesktopUpdateFailure(error, downWhenIssued)) return;const message =error instanceof Error ? error.message : "Failed to load models";setModelsError(message);diff --git a/studio/frontend/src/features/rag/components/use-rag-documents.ts b/studio/frontend/src/features/rag/components/use-rag-documents.tsindex 89a0338278c..cdb57e10ce7 100644--- a/studio/frontend/src/features/rag/components/use-rag-documents.ts+++ b/studio/frontend/src/features/rag/components/use-rag-documents.ts@@ -6,6 +6,10 @@ import {type NativeIntent,} from "@/features/native-intents";import { toast } from "@/lib/toast";+import {+ isBackendDownForDesktopUpdate,+ isSilencedDesktopUpdateFailure,+} from "@/lib/desktop-update-activity";import { useCallback, useEffect, useRef, useState } from "react";import {PROJECT_SOURCES_CHANGED_EVENT,@@ -280,6 +284,7 @@ export function useRagDocuments(const refresh = useCallback(async (opts?: { quiet?: boolean; silentErrors?: boolean }) => {if (!scopeKey) return true;+ const downWhenIssued = isBackendDownForDesktopUpdate();const requestId = ++refreshSeq.current;refreshInFlight.current = true;if (!opts?.quiet) setLoading(true);@@ -310,6 +315,8 @@ export function useRagDocuments(// A superseded failure describes a scope no longer shown, and a host// without RAG 503s every one of these: no toast per composer opened.if (refreshSeq.current !== requestId) return true;+ // The indexing poll keeps running under the update screen.+ if (isSilencedDesktopUpdateFailure(err, downWhenIssued)) return false;if (!opts?.silentErrors &&!useRagAvailabilityStore.getState().isUnavailable()diff --git a/studio/frontend/src/lib/desktop-update-activity.ts b/studio/frontend/src/lib/desktop-update-activity.tsnew file mode 100644index 00000000000..949959870b7--- /dev/null+++ b/studio/frontend/src/lib/desktop-update-activity.ts@@ -0,0 +1,48 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// The desktop update stops the backend on purpose while the app stays mounted under the update screen.+let backendDownForUpdate = false;++export function isBackendDownForDesktopUpdate(): boolean {+ return backendDownForUpdate;+}++/**+ * Tracks the update screen and returns the effect cleanup. Leaving it holds the flag until `resync`+ * settles: Skip & Restart and the shell-failure recovery spawn a fresh backend without waiting for it+ * to answer.+ */+export function followDesktopUpdateScreen(+ isUpdating: boolean,+ wasUpdating: boolean,+ resync: () => Promise<void>,+): () => void {+ const leaving = wasUpdating && !isUpdating;+ backendDownForUpdate = isUpdating || leaving;+ let active = true;+ if (leaving) {+ void resync().finally(() => {+ if (active) backendDownForUpdate = false;+ });+ }+ return () => {+ active = false;+ backendDownForUpdate = false;+ };+}++/**+ * Whether a failed read never reached a backend the update stopped. `downWhenIssued` is latched when+ * the request is issued: its rejection can land ~20s later, after the update screen has gone.+ */+export function isSilencedDesktopUpdateFailure(+ error: unknown,+ downWhenIssued: boolean,+): boolean {+ if (!downWhenIssued && !backendDownForUpdate) return false;+ return (+ (error as { unslothTransportFailure?: boolean } | null)+ ?.unslothTransportFailure === true+ );+}diff --git a/studio/frontend/tests/desktop-update-refresh-toast.test.ts b/studio/frontend/tests/desktop-update-refresh-toast.test.tsnew file mode 100644index 00000000000..38bf9430f6c--- /dev/null+++ b/studio/frontend/tests/desktop-update-refresh-toast.test.ts@@ -0,0 +1,137 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// The desktop update stops the backend while chat stays mounted under the update screen, so its+// focus refresh and the documents poll raised "Failed to refresh models" over a healthy update.++import assert from "node:assert/strict";+import test from "node:test";++import {+ followDesktopUpdateScreen,+ isBackendDownForDesktopUpdate,+ isSilencedDesktopUpdateFailure,+} from "../src/lib/desktop-update-activity.ts";+import { readSrc } from "./helpers/kit.ts";++const RUNTIME = readSrc("features/chat/hooks/use-chat-model-runtime.ts");+const RAG = readSrc("features/rag/components/use-rag-documents.ts");++function region(source: string, from: string, to: string): string {+ const start = source.indexOf(from);+ const end = source.indexOf(to, start);+ assert.ok(start !== -1, `region start not found: ${from}`);+ assert.ok(end > start, `region end not found after start: ${to}`);+ return source.slice(start, end);+}++const transport = () =>+ Object.assign(new Error("Unsloth isn't running -- please relaunch it."), {+ unslothTransportFailure: true,+ });++function deferred() {+ let resolve!: () => void;+ const promise = new Promise<void>((r) => (resolve = r));+ return { promise, resolve };+}++const noResync = () => Promise.resolve();+const settle = () => new Promise((r) => setImmediate(r));++test("only a transport failure under the update screen is silenced", () => {+ assert.equal(isSilencedDesktopUpdateFailure(transport(), false), false);+ const cleanup = followDesktopUpdateScreen(true, false, noResync);+ assert.equal(isSilencedDesktopUpdateFailure(transport(), false), true);+ assert.equal(+ isSilencedDesktopUpdateFailure(new Error("Internal Server Error"), true),+ false,+ );+ cleanup();+ assert.equal(isBackendDownForDesktopUpdate(), false);+});++test("a read issued under the update screen stays silent after the flag drops", () => {+ const cleanup = followDesktopUpdateScreen(true, false, noResync);+ const downWhenIssued = isBackendDownForDesktopUpdate();+ cleanup();+ assert.equal(isSilencedDesktopUpdateFailure(transport(), downWhenIssued), true);+});++// start_server returns once the backend is spawned, before it answers.+test("leaving the update screen holds the flag until the resync settles", async () => {+ followDesktopUpdateScreen(true, false, noResync)();+ const resync = deferred();+ let resyncs = 0;+ followDesktopUpdateScreen(false, true, () => {+ resyncs += 1;+ return resync.promise;+ });+ assert.equal(resyncs, 1);+ assert.equal(isBackendDownForDesktopUpdate(), true);+ resync.resolve();+ await settle();+ assert.equal(isBackendDownForDesktopUpdate(), false);+});++test("a retry during the resync keeps the flag when the resync settles", async () => {+ const resync = deferred();+ const leave = followDesktopUpdateScreen(false, true, () => resync.promise);+ leave();+ const retry = followDesktopUpdateScreen(true, false, noResync);+ resync.resolve();+ await settle();+ assert.equal(isBackendDownForDesktopUpdate(), true);+ retry();+});++test("no resync without a transition off the update screen", () => {+ let resyncs = 0;+ const count = () => {+ resyncs += 1;+ return Promise.resolve();+ };+ followDesktopUpdateScreen(false, false, count)();+ followDesktopUpdateScreen(true, false, count)();+ followDesktopUpdateScreen(true, true, count)();+ assert.equal(resyncs, 0);+});++test("the chat status refresh latches the flag at issue and checks it before reporting", () => {+ const sync = region(+ RUNTIME,+ "async function syncInferenceStatusToStore(",+ "async function refreshAndWaitForServerModel(",+ );+ const catchAt = sync.indexOf("} catch (error) {");+ const latch = sync.indexOf("const downWhenIssued = isBackendDownForDesktopUpdate();");+ assert.ok(latch !== -1 && latch < catchAt);+ const guard = sync.indexOf(+ "if (isSilencedDesktopUpdateFailure(error, downWhenIssued)) return;",+ );+ assert.ok(guard > catchAt);+ assert.ok(guard < sync.indexOf("setModelsError(message)"));+ assert.ok(guard < sync.indexOf("toast.error"));+});++test("the documents refresh latches the flag at issue and checks it before reporting", () => {+ const refresh = region(RAG, "const refresh = useCallback(", "const loadProjectSources");+ const latch = refresh.indexOf("const downWhenIssued = isBackendDownForDesktopUpdate();");+ const guard = refresh.indexOf(+ "if (isSilencedDesktopUpdateFailure(err, downWhenIssued)) return false;",+ );+ assert.ok(latch !== -1 && latch < refresh.indexOf("} catch (err) {"));+ assert.ok(guard !== -1 && guard < refresh.indexOf("toast.error"));+});++test("the update layer drives the flag and resyncs chat when the screen drops", () => {+ const layer = region(+ readSrc("app/provider.tsx"),+ "function TauriUpdateLayer(",+ "const HIDDEN_TITLEBAR_SIDEBAR_ROUTES",+ );+ assert.match(+ layer,+ /const wasUpdating = wasUpdatingRef\.current;\s*wasUpdatingRef\.current = isUpdating;[\s\S]*?return followDesktopUpdateScreen\(\s*isUpdating,\s*wasUpdating,\s*resyncInferenceStatusAfterServerModelChange,\s*\);\s*\}, \[isUpdating\]\);/,+ );+});diff --git a/studio/frontend/tests/rag-refresh-sequencing.test.ts b/studio/frontend/tests/rag-refresh-sequencing.test.tsindex fd23ce1e399..120b27925c3 100644--- a/studio/frontend/tests/rag-refresh-sequencing.test.ts+++ b/studio/frontend/tests/rag-refresh-sequencing.test.ts@@ -122,11 +122,12 @@ test("the scope-change effect takes a ticket on the way out", () => {});// A superseded failure describes a scope no longer shown, and a host without the-// vector extension 503s every one of these: no toast per composer opened.+// vector extension 503s every one of these: no toast per composer opened. The desktop-update+// guard may sit between the two, but nothing that reports may come before the supersession check.test("a failure is only reported for the request still being awaited", () => {assert.match(USE_RAG_DOCUMENTS,- /if \(refreshSeq\.current !== requestId\) return true;\s*if \(\s*!opts\?\.silentErrors &&\s*!useRagAvailabilityStore\.getState\(\)\.isUnavailable\(\)/,+ /if \(refreshSeq\.current !== requestId\) return true;(?:(?!toast\.error)[\s\S]){0,400}?if \(\s*!opts\?\.silentErrors &&\s*!useRagAvailabilityStore\.getState\(\)\.isUnavailable\(\)/,);});diff --git a/studio/frontend/tests/rag-upload-lifecycle.test.ts b/studio/frontend/tests/rag-upload-lifecycle.test.tsindex 1f136394f93..ee8d00dbebf 100644--- a/studio/frontend/tests/rag-upload-lifecycle.test.ts+++ b/studio/frontend/tests/rag-upload-lifecycle.test.ts@@ -97,6 +97,11 @@ function harness({react,"@/features/native-intents": {},+ // No desktop update is running in these: every failure here is a real one and must report.+ "@/lib/desktop-update-activity": {+ isBackendDownForDesktopUpdate: () => false,+ isSilencedDesktopUpdateFailure: () => false,+ },"@/lib/toast": {toast: {error: (message: string) => errors.push(message),diff --git a/tests/studio/test_chat_mount_cli_load_adoption.py b/tests/studio/test_chat_mount_cli_load_adoption.pyindex 1a15889433c..ffb05479d43 100644--- a/tests/studio/test_chat_mount_cli_load_adoption.py+++ b/tests/studio/test_chat_mount_cli_load_adoption.py@@ -173,6 +173,10 @@ export const toast = {error: (title: string, options?: any) => EVENTS.push({ kind: "toast.error", title, options }),};+// No desktop update runs here, so every failure must report.+export const isBackendDownForDesktopUpdate = () => false;+export const isSilencedDesktopUpdateFailure = () => false;+// The two ponyfills server-model-wait.ts imports. Its own per-read cap is 30s, which no test// should wait out, so the timeout here is short and the real constant is asserted separately.export const TEST_POLL_TIMEOUT_MS = 1200;