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
Add retry button to download panel for failed/cancelled downloads (CS 146S) (#17225)
Komal Vijdec739aa11a7
diff --git a/studio/frontend/src/features/hub/catalog/gguf-live-variant-states.ts b/studio/frontend/src/features/hub/catalog/gguf-live-variant-states.tsindex 657af6caee4..8805ae85ae4 100644--- a/studio/frontend/src/features/hub/catalog/gguf-live-variant-states.ts+++ b/studio/frontend/src/features/hub/catalog/gguf-live-variant-states.ts@@ -44,6 +44,7 @@ export function createLiveGgufVariantStatesSelector(repoId: string): (state: {activeDownloadState(job.state) ||completedDownloadState(job.state) ||(terminalPartialState(job.state) &&+ !job.retained &&Math.max(job.downloadedBytes, job.completedBytes) > 0);if (!live) continue;entries.push([diff --git a/studio/frontend/src/features/hub/download-manager/download-manager-panel.tsx b/studio/frontend/src/features/hub/download-manager/download-manager-panel.tsxindex 347d401d9f9..3dabfec5fcc 100644--- a/studio/frontend/src/features/hub/download-manager/download-manager-panel.tsx+++ b/studio/frontend/src/features/hub/download-manager/download-manager-panel.tsx@@ -18,6 +18,7 @@ import { ChevronDownStandardIcon } from "@/lib/chevron-icons";import { cn } from "@/lib/utils";import {Alert02Icon,+ ArrowReloadHorizontalIcon,Cancel01Icon,CheckmarkCircle02Icon,Download01Icon,@@ -33,6 +34,8 @@ import {} from "./download-manager-controller";import { DownloadProgressBar } from "./download-progress-bar";import { presentedProgress } from "./download-presentation";+import { isRetryableDownload } from "./retry-download";+import { retryDownload } from "./retry-start";import {type PendingStart,usePendingStarts,@@ -206,6 +209,10 @@ function DownloadRow({job.state === "complete" ||job.state === "cancelled" ||job.state === "error";+ const canRetry =+ (job.state === "error" || job.state === "cancelled") &&+ !starting &&+ isRetryableDownload(job);const progress = presentedProgress(job);return (<li className="flex flex-col gap-1.5 py-2.5 pl-4 pr-3">@@ -225,6 +232,30 @@ function DownloadRow({className="size-4 shrink-0 text-destructive"/>)}+ {canRetry && (+ <Tooltip>+ <TooltipTrigger asChild={true}>+ <button+ type="button"+ aria-label="Retry download"+ onClick={() => void retryDownload(job)}+ className={cn(+ "inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors",+ "hover:bg-[color-mix(in_oklab,var(--foreground)_calc(6%*var(--contrast-wash-gain,1)),transparent)] hover:text-foreground dark:hover:bg-[rgb(255_255_255_/_calc(0.06*var(--contrast-wash-gain,1)))]",+ )}+ >+ <HugeiconsIcon+ icon={ArrowReloadHorizontalIcon}+ strokeWidth={1.75}+ className="size-3.5"+ />+ </button>+ </TooltipTrigger>+ <TooltipContent side="top" sideOffset={4}>+ Retry download+ </TooltipContent>+ </Tooltip>+ )}<Tooltip><TooltipTrigger asChild={true}><buttondiff --git a/studio/frontend/src/features/hub/download-manager/download-manager-state.ts b/studio/frontend/src/features/hub/download-manager/download-manager-state.tsindex 0316084a87b..903bf710db5 100644--- a/studio/frontend/src/features/hub/download-manager/download-manager-state.ts+++ b/studio/frontend/src/features/hub/download-manager/download-manager-state.ts@@ -612,6 +612,20 @@ export function scheduleRemoval(key: string, delayMs: number): void {runtimeRegistry.removalTimers.set(key, timer);}+export function scheduleRetention(key: string, delayMs: number): void {+ const existing = runtimeRegistry.removalTimers.get(key);+ if (existing != null) clearRuntimeTimer(existing);+ const startedAt = getState().jobs[key]?.startedAt;+ const timer = window.setTimeout(() => {+ runtimeRegistry.removalTimers.delete(key);+ const job = getState().jobs[key];+ if (job?.startedAt === startedAt && job.state === "error") {+ patchJob(key, { retained: true });+ }+ }, delayMs);+ runtimeRegistry.removalTimers.set(key, timer);+}+export function selectActiveJob(state: DownloadManagerState,kind: DownloadKind,diff --git a/studio/frontend/src/features/hub/download-manager/download-manager-types.ts b/studio/frontend/src/features/hub/download-manager/download-manager-types.tsindex 61fc218e1fd..3d87a599331 100644--- a/studio/frontend/src/features/hub/download-manager/download-manager-types.ts+++ b/studio/frontend/src/features/hub/download-manager/download-manager-types.ts@@ -44,6 +44,8 @@ export interface ManagedDownload {details?: string[];/** Folder this job downloads into; null means the Models folder. */downloadDir?: string | null;+ /** A failure kept in the panel for retry, no longer a live inventory row. */+ retained?: boolean;}export interface DownloadRequest {diff --git a/studio/frontend/src/features/hub/download-manager/poll-loop.ts b/studio/frontend/src/features/hub/download-manager/poll-loop.tsindex b111dd16813..3f6d891bdd2 100644--- a/studio/frontend/src/features/hub/download-manager/poll-loop.ts+++ b/studio/frontend/src/features/hub/download-manager/poll-loop.ts@@ -97,8 +97,10 @@ import {removeJob,repoKeyOf,scheduleRemoval,+ scheduleRetention,setExpectedBytesForJob,} from "./download-manager-state";+import { isRetryableDownload } from "./retry-download";import {floorHoldEnded,hasObservedExpectedBytes,@@ -300,7 +302,9 @@ export function finalize(etaSeconds: 0,});notify(job, "onError", 0);- scheduleRemoval(key, ERROR_LINGER_MS);+ // A retryable failure stays listed until dismissed or retried; the linger only ends its inventory row.+ if (isRetryableDownload(job)) scheduleRetention(key, ERROR_LINGER_MS);+ else scheduleRemoval(key, ERROR_LINGER_MS);}scheduleInventoryBump();}diff --git a/studio/frontend/src/features/hub/download-manager/retry-download.ts b/studio/frontend/src/features/hub/download-manager/retry-download.tsnew file mode 100644index 00000000000..e0a0cb9b4ef--- /dev/null+++ b/studio/frontend/src/features/hub/download-manager/retry-download.ts@@ -0,0 +1,50 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import type {+ DownloadRequest,+ ManagedDownload,+} from "./download-manager-types";+import { isTrainingDownloadVariant } from "./training-downloads";++type RetrySubject = Pick<+ ManagedDownload,+ | "kind"+ | "repoId"+ | "variant"+ | "expectedBytes"+ | "inventoryKind"+ | "presentation"+ | "scopedFiles"+ | "checkpoint"+ | "downloadDir"+ | "external"+ | "state"+>;++/** Only Hub-started rows: engine / STT and training rows belong to the flows that started them. */+export function isRetryableDownload(job: RetrySubject): boolean {+ if (job.external || isTrainingDownloadVariant(job.variant)) return false;+ // The backend refuses a scope without its file list.+ return !job.variant?.startsWith("@") || (job.scopedFiles?.length ?? 0) > 0;+}++/** The start that produced *job*; a scoped variant must travel as scope_id, not gguf_variant. */+export function retryRequestFor(job: RetrySubject): DownloadRequest {+ const scopeId = job.variant?.startsWith("@") ? job.variant.slice(1) : null;+ return {+ kind: job.kind,+ repoId: job.repoId,+ variant: job.variant,+ expectedBytes: job.expectedBytes,+ ...(scopeId ? { scopeId } : {}),+ ...(job.inventoryKind ? { inventoryKind: job.inventoryKind } : {}),+ ...(job.presentation ? { presentation: job.presentation } : {}),+ ...(job.scopedFiles ? { files: job.scopedFiles } : {}),+ ...(job.checkpoint !== undefined ? { checkpoint: job.checkpoint } : {}),+ // Same rule as withDownloadDir: only a cancel pins its folder; a failure may have been the folder.+ ...(job.state === "cancelled" && job.downloadDir !== undefined+ ? { downloadDir: job.downloadDir }+ : {}),+ };+}diff --git a/studio/frontend/src/features/hub/download-manager/retry-start.ts b/studio/frontend/src/features/hub/download-manager/retry-start.tsnew file mode 100644index 00000000000..7cf425a7a63--- /dev/null+++ b/studio/frontend/src/features/hub/download-manager/retry-start.ts@@ -0,0 +1,26 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import { toast } from "@/lib/toast";+import type { ManagedDownload } from "./download-manager-types";+import { retryRequestFor } from "./retry-download";+import { requestStart, startRefusedAsBusy } from "./transport-conflict";++/** No dismiss first: a refused start must leave the failed row in place. */+export async function retryDownload(job: ManagedDownload): Promise<void> {+ const request = retryRequestFor(job);+ if (startRefusedAsBusy(request)) {+ toast.info("Download already in progress", {+ description:+ "Another download of this model is running. Retry once it finishes.",+ });+ return;+ }+ // The panel has no conflict dialog; the model's Hub card shows the stored one.+ if ((await requestStart(request)) === "conflict") {+ toast.info("Resume this download from Models", {+ description:+ "An earlier partial download used a different transport. Open this model in the Model hub to resume or restart it.",+ });+ }+}diff --git a/studio/frontend/src/features/hub/download-manager/transport-conflict.ts b/studio/frontend/src/features/hub/download-manager/transport-conflict.tsindex c531b7743bb..ad3ad606ddd 100644--- a/studio/frontend/src/features/hub/download-manager/transport-conflict.ts+++ b/studio/frontend/src/features/hub/download-manager/transport-conflict.ts@@ -123,13 +123,18 @@ function scopedFileSetDiffers();}+/** The guard below refuses this start as "busy" without a toast: another job owns the repo. */+export function startRefusedAsBusy(req: DownloadRequest): boolean {+ return hasActiveOrPendingStart(req) && !isJobActiveFor(req);+}+async function runWithPendingStartGuard(req: DownloadRequest,action: () => Promise<DownloadStartOutcome>,): Promise<DownloadStartOutcome> {const startKey = pendingStartKey(req);if (hasActiveOrPendingStart(req)) {- if (!isJobActiveFor(req)) return "busy";+ if (startRefusedAsBusy(req)) return "busy";// Returns "started" without running the action, so this is the only feedback.showCallerToast(jobKeyOf(req.kind, req.repoId, req.variant),diff --git a/studio/frontend/src/features/hub/inventory/use-hub-inventory.ts b/studio/frontend/src/features/hub/inventory/use-hub-inventory.tsindex dbcf1a480fa..7e27ddc2337 100644--- a/studio/frontend/src/features/hub/inventory/use-hub-inventory.ts+++ b/studio/frontend/src/features/hub/inventory/use-hub-inventory.ts@@ -198,6 +198,7 @@ function shouldSurfaceLiveJob(if (isDatasetMode !== (job.kind === "dataset")) return false;if (job.state === "running" || job.state === "cancelling") return true;if (job.state !== "cancelled" && job.state !== "error") return false;+ if (job.retained) return false;return Math.max(job.downloadedBytes, job.completedBytes) > 0;}diff --git a/studio/frontend/tests/download-failed-row-retained.test.ts b/studio/frontend/tests/download-failed-row-retained.test.tsnew file mode 100644index 00000000000..e644efa1730--- /dev/null+++ b/studio/frontend/tests/download-failed-row-retained.test.ts@@ -0,0 +1,87 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++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);++installLocalStorageFake();+type Timer = { fn: () => void; ms: number; cleared: boolean };+const timers: Timer[] = [];+Object.assign(globalThis.window, {+ location: { protocol: "http:", pathname: "/hub" },+ setTimeout: (fn: () => void, ms = 0) =>+ timers.push({ fn, ms, cleared: false }),+ clearTimeout: (id: number) => {+ if (timers[id - 1]) timers[id - 1].cleared = true;+ },+});++const originalFetch = globalThis.fetch;+globalThis.fetch = (async () =>+ Response.json({}, { status: 200 })) as typeof fetch;+after(() => {+ globalThis.fetch = originalFetch;+});++const { getState, jobKeyOf, putJob, 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 { ERROR_LINGER_MS } =+ await import("../src/features/hub/download-manager/download-manager-config.ts");++function job(over: Record<string, unknown> = {}) {+ const variant = (over.variant as string | null | undefined) ?? null;+ return {+ key: jobKeyOf("model", "Org/Repo", variant),+ kind: "model",+ repoId: "Org/Repo",+ variant,+ state: "running",+ downloadedBytes: 1024,+ completedBytes: 0,+ completeOnDisk: false,+ expectedBytes: 4096,+ fraction: 0.25,+ bytesPerSec: 0,+ etaSeconds: 0,+ error: null,+ startedAt: 1,+ ...over,+ } as never;+}++function fireLinger(): void {+ for (const t of timers.splice(0))+ if (!t.cleared && t.ms === ERROR_LINGER_MS) t.fn();+}++test("a failed download stays listed after its linger, marked retained", () => {+ const row = job();+ putJob(row);+ finalize((row as { key: string }).key, "error", {+ error: "Connection reset",+ });+ const key = (row as { key: string }).key;+ assert.equal(getState().jobs[key]?.state, "error");+ assert.notEqual(getState().jobs[key]?.retained, true);++ fireLinger();+ assert.equal(getState().jobs[key]?.state, "error");+ assert.equal(getState().jobs[key]?.retained, true);+ removeJob(key);+});++test("a failure the panel cannot retry is still removed after its linger", () => {+ const row = job({ variant: `@training-${"b".repeat(32)}` });+ const key = (row as { key: string }).key;+ putJob(row);+ finalize(key, "error", { error: "boom" });+ fireLinger();+ assert.equal(getState().jobs[key], undefined);+});diff --git a/studio/frontend/tests/download-retry-conflict.test.ts b/studio/frontend/tests/download-retry-conflict.test.tsnew file mode 100644index 00000000000..65065314783--- /dev/null+++ b/studio/frontend/tests/download-retry-conflict.test.ts@@ -0,0 +1,128 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++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 starts: string[] = [];+const originalFetch = globalThis.fetch;+globalThis.fetch = (async (input: RequestInfo | URL) => {+ const url = String(input);+ if (url.startsWith("/api/studio/download-transport-capabilities")) {+ return Response.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 Response.json({+ has_partial: true,+ last_transport: "http",+ resumable: true,+ });+ }+ if (url === "/api/hub/download") starts.push(url);+ return Response.json({});+}) as typeof fetch;+after(() => {+ globalThis.fetch = originalFetch;+});++const { calls } = await import("./helpers/toast-stub.mjs");+const { retryDownload } =+ await import("../src/features/hub/download-manager/retry-start.ts");+const { getState, jobKeyOf, putJob, removeJob } =+ await import("../src/features/hub/download-manager/download-manager-state.ts");++test("a retry that hits a transport conflict tells the user where to resolve it", async () => {+ calls.length = 0;+ const key = jobKeyOf("model", "Org/Repo", "Q4_K_M");+ await retryDownload({+ key,+ kind: "model",+ repoId: "Org/Repo",+ variant: "Q4_K_M",+ state: "error",+ downloadedBytes: 1024,+ completedBytes: 0,+ completeOnDisk: false,+ expectedBytes: 4096,+ fraction: 0.25,+ bytesPerSec: 0,+ etaSeconds: 0,+ error: "Connection reset",+ startedAt: 1,+ downloadDir: null,+ });+ assert.equal(starts.length, 0);+ assert.ok(getState().conflicts[key]);+ assert.ok(+ calls.some(+ (call: { kind: string; title?: string }) =>+ call.kind === "info" &&+ call.title === "Resume this download from Models",+ ),+ );+});++test("a retry refused because another job owns the repo says so", async () => {+ calls.length = 0;+ starts.length = 0;+ const running = jobKeyOf("model", "Org/Busy", null);+ putJob({+ key: running,+ kind: "model",+ repoId: "Org/Busy",+ variant: null,+ state: "running",+ downloadedBytes: 0,+ completedBytes: 0,+ completeOnDisk: false,+ expectedBytes: 4096,+ fraction: 0,+ bytesPerSec: 0,+ etaSeconds: 0,+ error: null,+ startedAt: 2,+ });+ await retryDownload({+ key: jobKeyOf("model", "Org/Busy", "@hub-assets"),+ kind: "model",+ repoId: "Org/Busy",+ variant: "@hub-assets",+ scopedFiles: ["vae.safetensors"],+ state: "error",+ downloadedBytes: 0,+ completedBytes: 0,+ completeOnDisk: false,+ expectedBytes: 1024,+ fraction: 0,+ bytesPerSec: 0,+ etaSeconds: 0,+ error: "Connection reset",+ startedAt: 1,+ });+ assert.equal(starts.length, 0);+ assert.ok(+ calls.some(+ (call: { kind: string; title?: string }) =>+ call.kind === "info" && call.title === "Download already in progress",+ ),+ );+ removeJob(running);+});diff --git a/studio/frontend/tests/download-retry-inventory.test.ts b/studio/frontend/tests/download-retry-inventory.test.tsnew file mode 100644index 00000000000..f79d271ec14--- /dev/null+++ b/studio/frontend/tests/download-retry-inventory.test.ts@@ -0,0 +1,45 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { registerStoreStubResolver } from "./helpers/kit.ts";++registerStoreStubResolver();++const { createLiveInventoryJobsSelector } =+ await import("../src/features/hub/inventory/use-hub-inventory.ts");+const { createLiveGgufVariantStatesSelector } =+ await import("../src/features/hub/catalog/gguf-live-variant-states.ts");++function failed(over: Record<string, unknown> = {}) {+ return {+ key: "model:org/repo:Q4_K_M",+ kind: "model",+ repoId: "Org/Repo",+ variant: "Q4_K_M",+ state: "error",+ startedAt: 1,+ downloadedBytes: 1024,+ completedBytes: 0,+ expectedBytes: 4096,+ fraction: 0.25,+ bytesPerSec: 0,+ etaSeconds: 0,+ error: "Connection reset",+ completeOnDisk: false,+ ...over,+ } as never;+}++test("a retained failure is a panel row only, not a live inventory or variant row", () => {+ const inventory = createLiveInventoryJobsSelector(false);+ const variants = createLiveGgufVariantStatesSelector("Org/Repo");+ const lingering = { jobs: { a: failed() } };+ assert.equal(inventory(lingering).length, 1);+ assert.equal(variants(lingering).size, 1);+ const retained = { jobs: { a: failed({ retained: true }) } };+ assert.equal(inventory(retained).length, 0);+ assert.equal(variants(retained).size, 0);+});diff --git a/studio/frontend/tests/download-retry.test.ts b/studio/frontend/tests/download-retry.test.tsnew file mode 100644index 00000000000..9baf7a6f5f0--- /dev/null+++ b/studio/frontend/tests/download-retry.test.ts@@ -0,0 +1,70 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { registerBundlerResolver } from "./helpers/kit.ts";++registerBundlerResolver();++const { isRetryableDownload, retryRequestFor } =+ await import("../src/features/hub/download-manager/retry-download.ts");++function job(over: Record<string, unknown> = {}) {+ const variant = (over.variant as string | null | undefined) ?? null;+ return {+ kind: "model",+ repoId: "Org/Repo",+ variant,+ state: "running",+ downloadedBytes: 1024,+ completedBytes: 0,+ completeOnDisk: false,+ expectedBytes: 4096,+ fraction: 0.25,+ bytesPerSec: 0,+ etaSeconds: 0,+ error: null,+ startedAt: 1,+ ...over,+ } as never;+}++test("a scoped row retries with scope_id and its files, a plain variant without", () => {+ const scoped = retryRequestFor(+ job({+ variant: "@hub-assets",+ scopedFiles: ["vae.safetensors"],+ checkpoint: false,+ }),+ );+ assert.equal(scoped.scopeId, "hub-assets");+ assert.deepEqual(scoped.files, ["vae.safetensors"]);+ assert.equal(scoped.checkpoint, false);++ const gguf = retryRequestFor(+ job({ variant: "Q4_K_M", state: "cancelled", downloadDir: "/models" }),+ );+ assert.equal(gguf.scopeId, undefined);+ assert.equal(gguf.variant, "Q4_K_M");+ assert.equal(gguf.downloadDir, "/models");+ // A failed start re-resolves the current folder, which may be the fix.+ const failed = retryRequestFor(+ job({ variant: "Q4_K_M", state: "error", downloadDir: "/missing" }),+ );+ assert.equal("downloadDir" in failed, false);+});++test("rows owned by other flows are not retryable from the panel", () => {+ assert.equal(isRetryableDownload(job()), true);+ assert.equal(+ isRetryableDownload(job({ external: true, repoId: "vLLM" })),+ false,+ );+ assert.equal(+ isRetryableDownload(job({ variant: `@training-${"a".repeat(32)}` })),+ false,+ );+ assert.equal(isRetryableDownload(job({ variant: "@hub-assets" })), false);+});