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: stopping a model load leaves no Starting model status behind (#13803)
Michael Han82c608b311b0
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 c84001a3638..15761430cbe 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@@ -16,6 +16,7 @@ import {} from "../lib/server-tuning-fields";import { createElement, useCallback, useEffect, useRef, useState } from "react";import { toast } from "@/lib/toast";+import { createNavigationNonce } from "@/lib/navigation-nonce";import {isBackendDownForDesktopUpdate,isSilencedDesktopUpdateFailure,@@ -1192,11 +1193,15 @@ export function useChatModelRuntime() {const cancelLoadingWithCheckpointPolicy = useCallback((preserveCheckpoint = false): Promise<boolean> => {const run = activeLoadRunRef.current;- return run- ? cancelLoadRun(run, preserveCheckpoint)- : Promise.resolve(false);+ if (run) return cancelLoadRun(run, preserveCheckpoint);+ if (loadingModelRef.current) {+ const tid = loadToastIdRef.current;+ resetLoadingUi();+ if (tid != null) toast.dismiss(tid);+ }+ return Promise.resolve(false);},- [cancelLoadRun],+ [cancelLoadRun, resetLoadingUi],);const cancelLoading = useCallback(@@ -1992,7 +1997,7 @@ export function useChatModelRuntime() {settledPromise: loadRunSettled,markSettled: markLoadRunSettled,- requestId: crypto.randomUUID(),+ requestId: createNavigationNonce(),loadAttemptPath: null,};activeLoadRunRef.current = loadRun;@@ -2499,6 +2504,7 @@ export function useChatModelRuntime() {) {pendingReplacementRollback = null;}+ toast.dismiss(toastId);resetLoadingUiForRun(loadRun);abortCtrl.abort();throw new Error("Cancelled");@@ -3450,7 +3456,7 @@ export function useChatModelRuntime() {getDownloadProgress(progressModelId, hfToken, mlxLoadProgress),),);- if (!loadingModelRef.current) return;+ if (abortCtrl.signal.aborted || !loadingModelRef.current) return;if (progressModelIdsAtRequest.length !== progressModelIds.length ||progressModelIdsAtRequest.some(@@ -3587,7 +3593,7 @@ export function useChatModelRuntime() {}try {const prog = await getLoadProgress();- if (!loadingModelRef.current) return;+ if (abortCtrl.signal.aborted || !loadingModelRef.current) return;if (!prog || prog.phase == null) return;if (prog.phase === "ready") {// Loaded. The chat flow will flip loadingModelRef shortly; just stop polling.@@ -3842,7 +3848,7 @@ export function useChatModelRuntime() {attemptId: loadIntentId,intentId: loadIntentId,abortController: abortCtrl,- requestId: crypto.randomUUID(),+ requestId: createNavigationNonce(),loadAttemptPath: null,cancelPromise: null,rollbackCheckpoint: previousCheckpoint,diff --git a/studio/frontend/tests/chat-model-load-replacement.test.ts b/studio/frontend/tests/chat-model-load-replacement.test.tsindex 2d9bdcece17..526901cdffe 100644--- a/studio/frontend/tests/chat-model-load-replacement.test.ts+++ b/studio/frontend/tests/chat-model-load-replacement.test.ts@@ -74,7 +74,7 @@ const contracts: Contract[] = [["cancel", /run\.cancelPromise = cancelPromise;/],["cancel", /ownsModelLoadRun\(activeLoadRunRef\.current, run\)/], ["cancel", /releaseOwnedModelLoadRun\(/]] },{ name: "the matching request ID is threaded to both /load and its cancel",- match: [["registration", /requestId: crypto\.randomUUID\(\),/],+ match: [["registration", /requestId: createNavigationNonce\(\),/],["runtime", /load_request_id: loadRun\.requestId,/],["cancel", /cancel_load_request_id: run\.requestId,/], ["cancel", /model_path: run\.loadAttemptPath,/],["runtime", /loadRun\.loadAttemptPath = loadPath;/]],diff --git a/studio/frontend/tests/chat-model-load-stop-leftovers.test.ts b/studio/frontend/tests/chat-model-load-stop-leftovers.test.tsnew file mode 100644index 00000000000..dfd7d305b98--- /dev/null+++ b/studio/frontend/tests/chat-model-load-stop-leftovers.test.ts@@ -0,0 +1,44 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Stopping a load must leave no "Starting model…" toast or header status behind. The decisions sit+// inside a React hook whose awaits span the backend load, so these are source contracts.+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";+import { fileURLToPath } from "node:url";++const runtime = readFileSync(+ fileURLToPath(new URL("../src/features/chat/hooks/use-chat-model-runtime.ts", import.meta.url)),+ "utf8",+);+const section = (start: string, end: string) => {+ const from = runtime.indexOf(start);+ assert.notEqual(from, -1, `expected to find ${start}`);+ const to = runtime.indexOf(end, from + start.length);+ assert.notEqual(to, -1, `expected to find ${end} after ${start}`);+ return runtime.slice(from, to);+};++test("a progress poll in flight when its run is stopped does not touch the next run's toast", () => {+ const download = section("const pollDownload = async () => {", "const pollLoad = async () => {");+ const afterFetch = download.slice(download.indexOf("getDownloadProgress(progressModelId"));+ assert.match(afterFetch, /^[\s\S]*?\n\s*if \(abortCtrl\.signal\.aborted \|\| !loadingModelRef\.current\) return;/);+ const load = section("const pollLoad = async () => {", "const cacheMissDownloadStarted = async");+ assert.match(load, /await getLoadProgress\(\);\n\s*if \(abortCtrl\.signal\.aborted \|\| !loadingModelRef\.current\) return;/);+});++test("Stop with no run left to cancel still clears the load status", () => {+ const stop = section("const cancelLoadingWithCheckpointPolicy = useCallback(", "const cancelLoading = useCallback(");+ assert.match(stop, /if \(loadingModelRef\.current\) \{[\s\S]*resetLoadingUi\(\);[\s\S]*toast\.dismiss\(tid\)/);+});++test("declining to stop running chats dismisses the load toast it leaves", () => {+ const decline = section("// Declined before anything was unloaded", 'throw new Error("Cancelled");');+ assert.match(decline, /toast\.dismiss\(toastId\);\n\s*resetLoadingUiForRun\(loadRun\);/);+});++test("a load run gets its id without crypto.randomUUID, which plain-HTTP LAN origins lack", () => {+ assert.doesNotMatch(runtime, /requestId: crypto\.randomUUID\(\)/);+ assert.equal(runtime.match(/requestId: createNavigationNonce\(\)/g)?.length, 2);+});