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: keep download restart toasts job-scoped (#10136)
Wasim Yousef Said74661077e5a1
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsxindex f8da044ab18..1a8545c5e1a 100644--- a/studio/frontend/src/features/chat/chat-page.tsx+++ b/studio/frontend/src/features/chat/chat-page.tsx@@ -61,6 +61,7 @@ import { useIsMobile } from "@/hooks/use-mobile";import {DOWNLOAD_KIND,dismissStartToast,+ dismissStartToastsForModelSelection,downloadManager,jobKeyOf,useRepoDownload,@@ -2866,6 +2867,12 @@ export function ChatPage({async (selection: SelectedModelInput) => {const store = useChatRuntimeStore.getState();const wantManagerStaging = wantsDownloadManagerStaging(selection);++ if (wantManagerStaging) {+ // Uncached picks return below and do not reach selectModel until completion.+ // Invalidate the previous model's notice at the actual picker boundary.+ dismissStartToastsForModelSelection();+ }if (store.modelLoading) {const isLoadingThisPick =!!loadingModel &&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 501060f835b..a7895f8b999 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@@ -35,6 +35,8 @@ import { consumeNativePathToken } from "@/features/native-intents/api";import { modelDisplayName } from "@/features/hub/lib/model-identity";// eslint-disable-next-line no-restricted-imports -- Avoid the hub barrel's React and download-manager exports.import { subscribeResidentStatusRefresh } from "@/features/hub/lib/resident-status-refresh";+// eslint-disable-next-line no-restricted-imports -- The hub barrel imports chat; this lifecycle leaf does not.+import { dismissStartToastsForModelSelection } from "@/features/hub/download-manager";import { prepareHfTokenForUse } from "@/features/hf-auth";import { ModelLoadDescription } from "../components/model-load-status";import {@@ -783,6 +785,8 @@ export function useChatModelRuntime() {restorePreviousConfig();return;}+ dismissStartToastsForModelSelection();+// A load is already in flight. If it's this exact pick (id + variant + token),// ignore the duplicate click. If it's a DIFFERENT model (including a different// GGUF variant of the same repo, which the old id+token guard wrongly treateddiff --git a/studio/frontend/src/features/hub/download-manager/index.ts b/studio/frontend/src/features/hub/download-manager/index.tsindex 6068632a0fb..23bf012005e 100644--- a/studio/frontend/src/features/hub/download-manager/index.ts+++ b/studio/frontend/src/features/hub/download-manager/index.ts@@ -52,7 +52,11 @@ export {downloadInventoryHintKind,scopedVariant,} from "./download-manager-types";-export { dismissStartToast, dismissStartToasts } from "./start-toast";+export {+ dismissStartToast,+ dismissStartToasts,+ dismissStartToastsForModelSelection,+} from "./start-toast";export {TRANSPORT_MODE_STORAGE_KEY,getTransportMode,diff --git a/studio/frontend/src/features/hub/download-manager/poll-loop.ts b/studio/frontend/src/features/hub/download-manager/poll-loop.tsindex edd51de8a47..72cb58e00f9 100644--- a/studio/frontend/src/features/hub/download-manager/poll-loop.ts+++ b/studio/frontend/src/features/hub/download-manager/poll-loop.ts@@ -69,13 +69,16 @@ import {type Terminal,} from "./download-manager-types";import {+ RESTART_NOTICE_TITLE,XET_NOTICE_TITLE,composeNoticeDescription,+ composeRestartNoticeDescription,shouldShowXetNotice,} from "./xet-progress-notice";import { reserveXetNoticeFromServer } from "@/features/settings/api/xet-notice";import {currentRoute,+ currentStartToastSelectionEpoch,dismissStartToast,liveCallerToast,showCallerToast,@@ -104,6 +107,26 @@ import {} from "./runtime-registry";import { resolveTransportMode } from "./transport-preference";+function showRestartStartToast(+ key: string,+ xet: boolean,+ caller: DownloadRequest["callerToast"],+ originRoute: string,+ originSelectionEpoch: number,+): void {+ showStartToast(+ key,+ {+ title: RESTART_NOTICE_TITLE,+ description: composeRestartNoticeDescription({+ xet,+ callerToast: caller,+ }),+ },+ originRoute,+ originSelectionEpoch,+ );+}function notify(job: ManagedDownload,event: keyof JobListeners,@@ -585,10 +608,14 @@ export async function startJob(transport?: ResolvedTransport;cancelTransport?: ResolvedTransport | null;originRoute?: string;+ originSelectionEpoch?: number;+ restartDisclosure?: boolean;} = {},): Promise<void> {const key = jobKeyOf(req.kind, req.repoId, req.variant);const startRoute = opts.originRoute ?? currentRoute();+ const startSelectionEpoch =+ opts.originSelectionEpoch ?? currentStartToastSelectionEpoch();// Peer guard stops a FRESH start from double-starting a variant already downloading. Skipped when ADOPTING:// the restored own entry would look like a peer and freeze the bar, and adoptJob already guards double-polling.if (!opts.adopt && hasActiveRepoPeer(req.kind, req.repoId, key, req.variant)) {@@ -740,12 +767,21 @@ export async function startJob(}const started = transportAfterStart(mode, result.transport);if (started !== activeTransport) patchJob(key, { transport: started });- // One start, one toast: a cancel can land mid-flight, and neither message is true of a start that is already stopping.+ // One accepted start, one job-owned toast. A preflight restart disclosure+ // waits until here so rejected, attached and already-stopping starts cannot+ // leave a claim behind for the next model selection.const stopping = rt.cancelRequested;- // Checked BEFORE reserving: a reservation is one of three for the life of the install, and spending one on a toast discarded on arrival burns all three unseen.+ const liveOwnStart =+ result.attached !== true && result.state === "running" && !stopping;+ const discloseRestart = opts.restartDisclosure === true && liveOwnStart;+ // Checked BEFORE reserving: a reservation is one of three for the life of the install, and spending one on a toast discarded on arrival burns all three unseen.const onOriginRoute = currentRoute() === startRoute;+ const onOriginSelection =+ req.kind !== DOWNLOAD_KIND.MODEL ||+ currentStartToastSelectionEpoch() === startSelectionEpoch;if (onOriginRoute &&+ onOriginSelection &&shouldShowXetNotice({kind: req.kind,transport: started,@@ -754,10 +790,20 @@ export async function startJob(})) {void reserveXetNoticeFromServer().then(({ granted }) => {- // This round trip can outlive the transfer: finalize() dismisses by id before it resolves, so raising here would leave a finished or cancelled job claiming to run.+ // This round trip can outlive the transfer: finalize() dismisses by id before it resolves, so raising here would leave a finished or cancelled job claiming to run.if (!isCurrent(key, epoch) || rt.cancelRequested) return;- // The caller's line can go stale while the notice stays true: chat moved thread, but the 0% still needs explaining.+ // The caller's line can go stale while the transport/restart facts stay true.const caller = liveCallerToast(req.callerToast);+ if (discloseRestart) {+ showRestartStartToast(+ key,+ granted,+ caller,+ startRoute,+ startSelectionEpoch,+ );+ return;+ }if (granted) {showStartToast(key,@@ -766,13 +812,25 @@ export async function startJob(description: composeNoticeDescription(caller),},startRoute,+ startSelectionEpoch,);return;}- showCallerToast(key, caller, startRoute);+ showCallerToast(key, caller, startRoute, startSelectionEpoch);});- } else if (!stopping && onOriginRoute) {- showCallerToast(key, liveCallerToast(req.callerToast), startRoute);+ } else if (!stopping && onOriginRoute && onOriginSelection) {+ const caller = liveCallerToast(req.callerToast);+ if (discloseRestart) {+ showRestartStartToast(+ key,+ false,+ caller,+ startRoute,+ startSelectionEpoch,+ );+ } else {+ showCallerToast(key, caller, startRoute, startSelectionEpoch);+ }}// An adopted job may already have fallen back from Xet to HTTP, which keeps its original cancel marker and so its stop control.if (isResolvedTransport(result.cancel_transport)) {diff --git a/studio/frontend/src/features/hub/download-manager/start-toast.ts b/studio/frontend/src/features/hub/download-manager/start-toast.tsindex 0c66aa8316b..dc9d4fbe0d0 100644--- a/studio/frontend/src/features/hub/download-manager/start-toast.ts+++ b/studio/frontend/src/features/hub/download-manager/start-toast.ts@@ -10,6 +10,8 @@import { toast } from "@/lib/toast";+import { DOWNLOAD_KIND, type DownloadKind } from "./constants";+import type { CallerToast } from "./download-manager-types";import {XET_NOTICE_DESCRIPTION_CLASS,@@ -21,9 +23,20 @@ export function startToastId(jobKey: string): string {return `download-start:${jobKey}`;}-// Id -> the route it was raised on. Keyed that way rather than dismissing everything-// live, because a start can itself navigate: that toast belongs where it landed.-const liveStartToasts = new Map<string, string>();+// Id -> the route and download kind it was raised for. Kind-scoping matters because+// a Chat model pick must not erase an unrelated dataset notice on the same /hub route.+const liveStartToasts = new Map<+ string,+ { route: string; kind: DownloadKind }+>();++let modelSelectionEpoch = 0;++function downloadKindOfJobKey(jobKey: string): DownloadKind {+ return jobKey.startsWith(`${DOWNLOAD_KIND.DATASET}:`)+ ? DOWNLOAD_KIND.DATASET+ : DOWNLOAD_KIND.MODEL;+}/** The route to hold a start against. Captured when the start begins, since the* preflight and the reservation are round trips a raise can outlive. */@@ -31,15 +44,28 @@ export function currentRoute(): string {return typeof window === "undefined" ? "" : window.location.pathname;}+/** Captured with the route so an async preflight cannot raise after another pick. */+export function currentStartToastSelectionEpoch(): number {+ return modelSelectionEpoch;+}+export function showStartToast(jobKey: string,message: { title: string; description: string },originRoute: string = currentRoute(),+ originSelectionEpoch: number = currentStartToastSelectionEpoch(),): void {- // Raised late, surface gone: the route sweep has already run, so this would sit- // on the new page for its full 8s.- if (originRoute !== currentRoute()) return;- liveStartToasts.set(startToastId(jobKey), originRoute);+ const kind = downloadKindOfJobKey(jobKey);+ // Raised late, surface or selected model gone: the corresponding sweep already+ // ran. Dataset notices are independent of Chat's model-selection epoch.+ if (+ originRoute !== currentRoute() ||+ (kind === DOWNLOAD_KIND.MODEL &&+ originSelectionEpoch !== currentStartToastSelectionEpoch())+ ) {+ return;+ }+ liveStartToasts.set(startToastId(jobKey), { route: originRoute, kind });toast.info(message.title, {id: startToastId(jobKey),description: message.description,@@ -63,9 +89,10 @@ export function showCallerToast(jobKey: string,message: CallerToast | undefined,originRoute?: string,+ originSelectionEpoch?: number,): void {if (!message || message.noticeOnly) return;- showStartToast(jobKey, message, originRoute);+ showStartToast(jobKey, message, originRoute, originSelectionEpoch);}/** Drop the start toast once the transfer is over. Safe for a job that never raised@@ -82,8 +109,19 @@ export function dismissStartToast(jobKey: string): void {* #9293 reverted. Only ids raised here, so other toasts survive the navigation. */export function dismissStartToasts(): void {const here = currentRoute();- for (const [id, raisedOn] of liveStartToasts) {- if (raisedOn === here) continue;+ for (const [id, context] of liveStartToasts) {+ if (context.route === here) continue;+ liveStartToasts.delete(id);+ toast.dismiss(id);+ }+}++/** A model pick can change while the route stays put. Drop every prior start+ * disclosure so it cannot describe the newly selected model. */+export function dismissStartToastsForModelSelection(): void {+ modelSelectionEpoch += 1;+ for (const [id, context] of liveStartToasts) {+ if (context.kind !== DOWNLOAD_KIND.MODEL) continue;liveStartToasts.delete(id);toast.dismiss(id);}diff --git a/studio/frontend/src/features/hub/download-manager/transport-conflict.ts b/studio/frontend/src/features/hub/download-manager/transport-conflict.tsindex c1ce051d889..8049d74a02d 100644--- a/studio/frontend/src/features/hub/download-manager/transport-conflict.ts+++ b/studio/frontend/src/features/hub/download-manager/transport-conflict.ts@@ -28,7 +28,11 @@ import {setConflict,} from "./download-manager-state";import { startJob } from "./poll-loop";-import { currentRoute, showCallerToast } from "./start-toast";+import {+ currentRoute,+ currentStartToastSelectionEpoch,+ showCallerToast,+} from "./start-toast";import { runtimeRegistry } from "./runtime-registry";import { resolveTransportMode } from "./transport-preference";import { ACTIVE_STATES, TRANSPORT_STATUS_TIMEOUT_MS } from "./download-manager-config";@@ -161,6 +165,7 @@ export async function requestStart(// Before the preflight below, which is two round trips the user can navigate// during; read after them it would name the page they moved to.const originRoute = currentRoute();+ const originSelectionEpoch = currentStartToastSelectionEpoch();return runWithPendingStartGuard(req, async () => {const preferred: TransportMode = await resolveTransportMode();let mode: TransportMode = preferred;@@ -193,6 +198,8 @@ export async function requestStart(} catch (err) {console.warn("Active download transport check failed.", err);}+ let restartDisclosure = false;+try {const status = await apiTransportStatusWithRetry(req);const last = asTransportMode(status.last_transport);@@ -224,10 +231,9 @@ export async function requestStart(status.has_partial &&(status.resumable === false || !status.last_transport)) {- toast.info("Restarting this download", {- description:- "An earlier partial download can't be resumed, so it will start again from the beginning.",- });+ // Do not raise during preflight: the backend may still reject or attach+ // this start. The accepted job owns and later dismisses the disclosure.+ restartDisclosure = true;}} catch (err) {console.warn(@@ -244,7 +250,12 @@ export async function requestStart(description:"Starting with HTTP so an existing partial is not discarded. Switch transport to retry with Xet.",});- await startJob(req, { useXet: false, originRoute });+ await startJob(req, {+ useXet: false,+ originRoute,+ originSelectionEpoch,+ restartDisclosure,+ });return isJobActiveFor(req) ? "started" : "error";}toast.warning("Couldn't verify existing partial download", {@@ -262,7 +273,12 @@ export async function requestStart(return "busy";}- await startJob(req, { useXet: mode === TRANSPORT.XET, originRoute });+ await startJob(req, {+ useXet: mode === TRANSPORT.XET,+ originRoute,+ originSelectionEpoch,+ restartDisclosure,+ });return isJobActiveFor(req) ? "started" : "error";});}diff --git a/studio/frontend/src/features/hub/download-manager/xet-progress-notice.ts b/studio/frontend/src/features/hub/download-manager/xet-progress-notice.tsindex d1a582b4797..38df6d44871 100644--- a/studio/frontend/src/features/hub/download-manager/xet-progress-notice.ts+++ b/studio/frontend/src/features/hub/download-manager/xet-progress-notice.ts@@ -28,15 +28,44 @@ export const XET_NOTICE_TITLE = "Download is running";export const XET_NOTICE_DESCRIPTION ="Xet sends the file in small pieces, so the bar can sit at 0% and then jump to done. Nothing is stuck.";export const XET_NOTICE_DESCRIPTION_CLASS = "!text-muted-foreground";+// A restart is also a start disclosure. Keeping its copy here lets poll-loop+// combine it with the Xet explanation instead of creating an unrelated toast+// that can outlive its download.+export const RESTART_NOTICE_TITLE = "Restarting this download";+export const RESTART_NOTICE_DESCRIPTION =+ "The earlier partial can't be resumed, so this download is starting over.";+export const RESTART_XET_NOTICE_DESCRIPTION =+ "The partial can't be resumed, so Xet is starting over. The bar may stay at 0% and jump to done.";/** The notice, plus whatever the starting surface wanted to add. Chat auto-loads and* says so; the Hub does not, passes nothing, and gets the short form. The test budget* applies to that form alone, since only it renders over the hub toolbar. */-export function composeNoticeDescription(+function appendCallerDescription(+ description: string,callerToast?: { description: string } | null,): string {const extra = callerToast?.description?.trim();- return extra ? `${XET_NOTICE_DESCRIPTION} ${extra}` : XET_NOTICE_DESCRIPTION;+ return extra ? `${description} ${extra}` : description;+}++export function composeNoticeDescription(+ callerToast?: { description: string } | null,+): string {+ return appendCallerDescription(XET_NOTICE_DESCRIPTION, callerToast);+}++/** One accepted restart, optionally carrying the Xet and caller facts. */+export function composeRestartNoticeDescription({+ xet,+ callerToast,+}: {+ xet: boolean;+ callerToast?: { description: string } | null;+}): string {+ return appendCallerDescription(+ xet ? RESTART_XET_NOTICE_DESCRIPTION : RESTART_NOTICE_DESCRIPTION,+ callerToast,+ );}/** Only the transport that behaves this way, and only while it is news.diff --git a/studio/frontend/tests/chat-remembers-its-model.test.ts b/studio/frontend/tests/chat-remembers-its-model.test.tsindex 9a2e9b34d69..5c5ddb0f645 100644--- a/studio/frontend/tests/chat-remembers-its-model.test.ts+++ b/studio/frontend/tests/chat-remembers-its-model.test.ts@@ -503,6 +503,16 @@ test("switching back to a hub GGUF loads it instead of staging a download", () =page,/const wantManagerStaging = wantsDownloadManagerStaging\(selection\);/,);++ const stage = slice(+ page,+ "const stageOrLoad = useCallback",+ "if (store.modelLoading)",+ );+ assert.match(+ stage,+ /const wantManagerStaging = wantsDownloadManagerStaging\(selection\);[\s\S]*if \(wantManagerStaging\) \{[\s\S]*dismissStartToastsForModelSelection\(\)/,+ );});test("a history update that leaves the model alone is not re-emitted", () => {diff --git a/studio/frontend/tests/download-center-resume.test.ts b/studio/frontend/tests/download-center-resume.test.tsindex 7a02a46268e..b1da74e48c7 100644--- a/studio/frontend/tests/download-center-resume.test.ts+++ b/studio/frontend/tests/download-center-resume.test.ts@@ -117,13 +117,6 @@ test("web auth session boundaries clear persisted download rows", () => {assert.match(CONTROLLER, /event\.key === AUTH_SESSION_MARK_KEY/);});-test("a restart-only partial is disclosed before Resume starts it over", () => {- assert.match(- CONFLICT,- /status\.has_partial &&[\s\S]*?status\.resumable === false[\s\S]*?Restarting this download/,- );-});-test("a transport conflict belongs to exactly one dialog surface", () => {const info = { previous: "http", next: "xet", resumable: true } as const;const entry: ConflictEntry = {diff --git a/studio/frontend/tests/download-start-lifecycle.test.ts b/studio/frontend/tests/download-start-lifecycle.test.tsnew file mode 100644index 00000000000..b73c734c489--- /dev/null+++ b/studio/frontend/tests/download-start-lifecycle.test.ts@@ -0,0 +1,214 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Exercise the real preflight -> accepted start -> terminal lifecycle. Helper-only+// tests cannot prove that preflight waits for acceptance or that finalize owns the+// same toast id.++import assert from "node:assert/strict";+import test, { after } from "node:test";+import { register } from "node:module";++import { installLocalStorageFake } from "./helpers/kit.ts";++register("./helpers/download-lifecycle-resolver.mjs", import.meta.url);++const { storage } = installLocalStorageFake();+Object.assign(globalThis.window, {+ location: { protocol: "http:", pathname: "/chat" },+ setTimeout: globalThis.setTimeout.bind(globalThis),+ clearTimeout: globalThis.clearTimeout.bind(globalThis),+});+storage.setItem("unsloth.studio.transportMode", "xet");++const originalFetch = globalThis.fetch;+after(() => {+ globalThis.fetch = originalFetch;+});++const { calls } = await import("./helpers/toast-stub.mjs");+const { requestStart } =+ await import("../src/features/hub/download-manager/transport-conflict.ts");+const { jobKeyOf, removeJob } =+ await import("../src/features/hub/download-manager/download-manager-state.ts");+const { finalize } =+ await import("../src/features/hub/download-manager/poll-loop.ts");+const { dismissStartToastsForModelSelection, startToastId } =+ await import("../src/features/hub/download-manager/start-toast.ts");++function json(body: unknown): Response {+ return Response.json(body, { status: 200 });+}++function visibleToastCalls() {+ return calls.filter((call) => call.kind !== "dismiss");+}++test("restart disclosure waits for acceptance and completion dismisses its one keyed toast", async () => {+ calls.length = 0;++ let acceptStart!: () => void;+ let markStartRequested!: () => void;+ const startRequested = new Promise<void>((resolve) => {+ markStartRequested = resolve;+ });++ globalThis.fetch = (async (input: RequestInfo | URL) => {+ const url = String(input);+ if (url.startsWith("/api/hub/active-downloads")) {+ return json({ downloads: [] });+ }+ if (url.startsWith("/api/studio/download-transport-capabilities")) {+ return json({+ http: { available: true, reason: null },+ xet: { available: true, reason: null },+ auto_resolves_to: "xet",+ auto_reason: null,+ });+ }+ if (url.startsWith("/api/hub/transport-status")) {+ return json({+ has_partial: true,+ last_transport: "xet",+ resumable: false,+ });+ }+ if (url === "/api/hub/download") {+ markStartRequested();+ return new Promise<Response>((resolve) => {+ acceptStart = () =>+ resolve(+ json({+ accepted: true,+ attached: false,+ state: "running",+ generation: 7,+ transport: "xet",+ job_key: "backend-key",+ }),+ );+ });+ }+ if (url === "/api/settings/xet-notice/reserve") {+ return json({ granted: true, shown: 1, limit: 3 });+ }+ throw new Error(`Unexpected request: ${url}`);+ }) as typeof fetch;++ const request = {+ kind: "model" as const,+ repoId: "org/restart-model",+ variant: "Q4_K_M",+ expectedBytes: 4096,+ };+ const starting = requestStart(request);+ await startRequested;+ assert.deepEqual(+ visibleToastCalls(),+ [],+ "preflight claimed a restart before the backend accepted it",+ );++ acceptStart();+ assert.equal(await starting, "started");+ await new Promise<void>((resolve) => setImmediate(resolve));++ const key = jobKeyOf(request.kind, request.repoId, request.variant);+ assert.deepEqual(visibleToastCalls(), [+ {+ kind: "info",+ title: "Restarting this download",+ options: {+ id: startToastId(key),+ description:+ "The partial can't be resumed, so Xet is starting over. The bar may stay at 0% and jump to done.",+ duration: 8000,+ classNames: { description: "!text-muted-foreground" },+ },+ },+ ]);++ finalize(key, "complete");+ assert.deepEqual(calls.at(-1), {+ kind: "dismiss",+ id: startToastId(key),+ });+ removeJob(key);+});++test("a stale model selection does not spend an Xet notice reservation", async () => {+ calls.length = 0;++ let acceptStart!: () => void;+ let markStartRequested!: () => void;+ let reservations = 0;+ const startRequested = new Promise<void>((resolve) => {+ markStartRequested = resolve;+ });++ globalThis.fetch = (async (input: RequestInfo | URL) => {+ const url = String(input);+ if (url.startsWith("/api/hub/active-downloads")) {+ return json({ downloads: [] });+ }+ if (url.startsWith("/api/studio/download-transport-capabilities")) {+ return json({+ http: { available: true, reason: null },+ xet: { available: true, reason: null },+ auto_resolves_to: "xet",+ auto_reason: null,+ });+ }+ if (url.startsWith("/api/hub/transport-status")) {+ return json({+ has_partial: false,+ last_transport: null,+ resumable: false,+ });+ }+ if (url === "/api/hub/download") {+ markStartRequested();+ return new Promise<Response>((resolve) => {+ acceptStart = () =>+ resolve(+ json({+ accepted: true,+ attached: false,+ state: "running",+ generation: 8,+ transport: "xet",+ job_key: "backend-key",+ }),+ );+ });+ }+ if (url === "/api/settings/xet-notice/reserve") {+ reservations += 1;+ return json({ granted: true, shown: reservations, limit: 3 });+ }+ throw new Error(`Unexpected request: ${url}`);+ }) as typeof fetch;++ const request = {+ kind: "model" as const,+ repoId: "org/stale-model",+ variant: "Q4_K_M",+ expectedBytes: 4096,+ };+ const starting = requestStart(request);+ await startRequested;++ dismissStartToastsForModelSelection();+ acceptStart();+ assert.equal(await starting, "started");+ await new Promise<void>((resolve) => setImmediate(resolve));++ const key = jobKeyOf(request.kind, request.repoId, request.variant);+ try {+ assert.equal(reservations, 0);+ assert.deepEqual(visibleToastCalls(), []);+ } finally {+ finalize(key, "complete");+ removeJob(key);+ }+});diff --git a/studio/frontend/tests/download-start-toast.test.ts b/studio/frontend/tests/download-start-toast.test.tsindex 5c0da969e2e..c94669f221a 100644--- a/studio/frontend/tests/download-start-toast.test.ts+++ b/studio/frontend/tests/download-start-toast.test.ts@@ -26,6 +26,8 @@ const { calls } = await import("./helpers/toast-stub.mjs");const {dismissStartToast,dismissStartToasts,+ currentStartToastSelectionEpoch,+ dismissStartToastsForModelSelection,liveCallerToast,showCallerToast,showStartToast,@@ -111,6 +113,49 @@ test("a toast raised on the route it landed on stays", () => {assert.deepEqual(raised(), []);});+test("a later model selection drops start toasts without a route change", () => {+ reset("/chat");+ showStartToast("model:old-repo:q4", {+ title: "Restarting this download",+ description: "The partial can't be resumed.",+ });+ calls.length = 0;++ dismissStartToastsForModelSelection();+ assert.deepEqual(raised(), [+ { kind: "dismiss", id: startToastId("model:old-repo:q4") },+ ]);+});++test("a model pick preserves dataset notices and their delayed raises", () => {+ reset("/hub");+ const modelKey = "model:model-repo:q4";+ const datasetKey = "dataset:dataset-repo:main";+ showStartToast(modelKey, MESSAGE);+ showStartToast(datasetKey, MESSAGE);+ const startedForSelection = currentStartToastSelectionEpoch();+ calls.length = 0;++ dismissStartToastsForModelSelection();+ assert.deepEqual(raised(), [{ kind: "dismiss", id: startToastId(modelKey) }]);++ calls.length = 0;+ showStartToast(datasetKey, MESSAGE, "/hub", startedForSelection);+ assert.equal(calls[0]?.kind, "info");+ assert.equal(calls[0]?.options?.id, startToastId(datasetKey));+ dismissStartToast(datasetKey);+});+test("a delayed start cannot reappear after the next model selection", () => {+ reset("/chat");+ const startedForSelection = currentStartToastSelectionEpoch();++ dismissStartToastsForModelSelection();+ calls.length = 0;+ showStartToast("model:old-repo:q4", MESSAGE, "/chat", startedForSelection);++ assert.deepEqual(raised(), []);+});+test("a noticeOnly caller is folded in or not shown at all", () => {// #9663 removed chat's own auto-load toast as a duplicate of the download panel.// Its sentence still rides along for the Xet notice to fold in, but on an HTTPdiff --git a/studio/frontend/tests/helpers/download-lifecycle-auth-stub.mjs b/studio/frontend/tests/helpers/download-lifecycle-auth-stub.mjsnew file mode 100644index 00000000000..2cac98bbb43--- /dev/null+++ b/studio/frontend/tests/helpers/download-lifecycle-auth-stub.mjs@@ -0,0 +1,6 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++export function authFetch(input, init) {+ return globalThis.fetch(input, init);+}diff --git a/studio/frontend/tests/helpers/download-lifecycle-resolver.mjs b/studio/frontend/tests/helpers/download-lifecycle-resolver.mjsnew file mode 100644index 00000000000..d6942089b0a--- /dev/null+++ b/studio/frontend/tests/helpers/download-lifecycle-resolver.mjs@@ -0,0 +1,20 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Node cannot load the TSX feature barrels reached by the download manager. Keep+// this integration test on the real download modules while replacing only those+// browser-only boundaries and Sonner.+import { resolve as resolveBundler } from "../bundler-resolver.mjs";++const STUBS = new Map([+ ["@/features/auth", "./download-lifecycle-auth-stub.mjs"],+ ["@/features/auth/api", "./download-lifecycle-auth-stub.mjs"],+ ["@/features/settings", "./download-lifecycle-settings-stub.mjs"],+ ["@/lib/toast", "./toast-stub.mjs"],+]);++export function resolve(specifier, context, next) {+ const stub = STUBS.get(specifier);+ if (stub) return next(new URL(stub, import.meta.url).href, context);+ return resolveBundler(specifier, context, next);+}diff --git a/studio/frontend/tests/helpers/download-lifecycle-settings-stub.mjs b/studio/frontend/tests/helpers/download-lifecycle-settings-stub.mjsnew file mode 100644index 00000000000..7ae3e725d8c--- /dev/null+++ b/studio/frontend/tests/helpers/download-lifecycle-settings-stub.mjs@@ -0,0 +1,14 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++export async function loadDownloadTransportSettings() {+ return { mode: "auto" };+}++export function subscribeDownloadTransportSettings() {+ return () => undefined;+}++export async function updateDownloadTransportSettings() {+ return { mode: "auto" };+}diff --git a/studio/frontend/tests/xet-progress-notice.test.ts b/studio/frontend/tests/xet-progress-notice.test.tsindex 2fb38e05abe..98b091bb06e 100644--- a/studio/frontend/tests/xet-progress-notice.test.ts+++ b/studio/frontend/tests/xet-progress-notice.test.ts@@ -19,11 +19,15 @@ const noticeModule = await import("../src/features/hub/download-manager/xet-progress-notice.ts");const {+ RESTART_NOTICE_DESCRIPTION,+ RESTART_NOTICE_TITLE,+ RESTART_XET_NOTICE_DESCRIPTION,XET_NOTICE_DESCRIPTION,XET_NOTICE_DESCRIPTION_CLASS,XET_NOTICE_DURATION_MS,XET_NOTICE_TITLE,composeNoticeDescription,+ composeRestartNoticeDescription,shouldShowXetNotice,} = noticeModule;@@ -117,6 +121,38 @@ test("a caller with nothing to add leaves the notice alone", () => {);});+test("restart and Xet facts compose into one short notice", () => {+ const composed = composeRestartNoticeDescription({ xet: true });+ assert.equal(RESTART_NOTICE_TITLE, "Restarting this download");+ assert.equal(composed, RESTART_XET_NOTICE_DESCRIPTION);+ assert.match(composed, /can't be resumed/);+ assert.match(composed, /0%/);+ assert.match(composed, /jump to done/);+ assert.ok(RESTART_NOTICE_TITLE.length <= 32);+ assert.ok(composed.length <= 110);+ assert.ok(!composed.includes("\n"));+});++test("restart disclosure survives a spent Xet allowance", () => {+ assert.equal(+ composeRestartNoticeDescription({ xet: false }),+ RESTART_NOTICE_DESCRIPTION,+ );+ assert.match(RESTART_NOTICE_DESCRIPTION, /starting over/);+ assert.ok(RESTART_NOTICE_DESCRIPTION.length <= 110);+});++test("chat auto-load copy folds into the restart notice", () => {+ const composed = composeRestartNoticeDescription({+ xet: true,+ callerToast: {+ description: "It'll load automatically once the download finishes.",+ },+ });+ assert.ok(composed.startsWith(RESTART_XET_NOTICE_DESCRIPTION));+ assert.match(composed, /load automatically once the download finishes\.$/);+});+test("it stays up longer than the Toaster default", () => {// Two sentences to notice while watching a progress bar, at most 3 times ever, so// 5s is enough to miss. An upper bound only: it is dismissed when the transfer ends.