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
fix(studio): show queued downloads consistently across media routes (#13219)
Lee Jackson9b8338cb10e7
diff --git a/.github/workflows/studio-ui-smoke.yml b/.github/workflows/studio-ui-smoke.ymlindex 27373f1bb2c..e84d9ccf635 100644--- a/.github/workflows/studio-ui-smoke.yml+++ b/.github/workflows/studio-ui-smoke.yml@@ -762,6 +762,16 @@ jobs:PW_ART_DIR="$PW_ART_DIR/late-filename" PW_RESOLVE_FIRST=1 python tests/studio/playwright_image_download_queue.pyPW_ART_DIR="$PW_ART_DIR/late-quant" PW_LOAD_SECOND=1 PW_HOLD_FIRST_PLAN=1 PW_DIFFERENT_QUANT=1 python tests/studio/playwright_image_download_queue.py+ # A cached model with two missing asset repos lists the queued stage beside the active one.+ - name: Image staged-download pending rows regression (Playwright)+ if: matrix.shard == 'extra'+ env:+ BASE_URL: http://127.0.0.1:18894+ PW_ART_DIR: logs/playwright_staged_download_rows+ run: |+ mkdir -p logs/playwright_staged_download_rows+ python tests/studio/playwright_staged_download_rows.py+# The Text encoder precision control: what the select sends to the plan and to the load, that# Default omits the field entirely, that a refresh race cannot leave a stale reading, and that# the select follows the build the backend reports back, downgrade or decline included.@@ -973,6 +983,7 @@ jobs:logs/playwright_image_cancel_retrylogs/playwright_image_cancel_retry_coldlogs/playwright_image_download_queue+ logs/playwright_staged_download_rowslogs/playwright_image_text_encoderlogs/playwright_modelcfglogs/playwright_memory_estimatediff --git a/studio/frontend/src/features/hub/download-manager/download-manager-controller.ts b/studio/frontend/src/features/hub/download-manager/download-manager-controller.tsindex 02eba31a389..d738a94b72c 100644--- a/studio/frontend/src/features/hub/download-manager/download-manager-controller.ts+++ b/studio/frontend/src/features/hub/download-manager/download-manager-controller.ts@@ -18,6 +18,7 @@ import {import { hydrateDownloadManager, resetHydrationState } from "./hydration";import { cancelJob, probeAndAdopt, setExpected } from "./poll-loop";import { runtimeRegistry } from "./runtime-registry";+import { useStagedDownloadQueues } from "./staged-download-queue";import {cancelConflict,requestStart,@@ -48,6 +49,8 @@ function resetDownloadManagerState(): void {resetDownloadApiAdapterState();resetHydrationState();setState(createDownloadManagerInitialState());+ // A media page stays mounted across a cross-tab session change, so its queue would outlive the jobs.+ useStagedDownloadQueues.setState({ queues: {} });}export function __resetDownloadManagerForTests(): void {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 235eba8d1d6..cd869618c29 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@@ -34,6 +34,7 @@ import {import { DownloadProgressBar } from "./download-progress-bar";import { presentedProgress } from "./download-presentation";import { assetLabel } from "./required-assets";+import { queuedStagedEntries, useStagedDownloadQueues } from "./staged-download-queue";function createOrderedJobKeysSelector(): (state: {jobs: Record<string, ManagedDownload>;@@ -250,7 +251,10 @@ export function DownloadManagerPanel({const selectOrderedJobKeys = useMemo(createOrderedJobKeysSelector, []);const jobKeys = useDownloadManagerStore(selectOrderedJobKeys);- const queued = useQueuedHubEntries();+ const hubQueued = useQueuedHubEntries();+ const stagedQueues = useStagedDownloadQueues((s) => s.queues);+ const jobs = useDownloadManagerStore((s) => s.jobs);+ const queued = [...hubQueued, ...queuedStagedEntries(stagedQueues, jobs)];const activeCount = useDownloadManagerStore(selectActiveJobCount) + queued.length;if (!enabled || (jobKeys.length === 0 && queued.length === 0)) return null;diff --git a/studio/frontend/src/features/hub/download-manager/staged-download-queue.ts b/studio/frontend/src/features/hub/download-manager/staged-download-queue.tsnew file mode 100644index 00000000000..a33f33ee3ea--- /dev/null+++ b/studio/frontend/src/features/hub/download-manager/staged-download-queue.ts@@ -0,0 +1,53 @@+// 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 { create } from "zustand";+import { scopedVariant, type ManagedDownload } from "./download-manager-types";+import type { StagedDownloadEntry } from "./use-staged-download";++export interface StagedQueue {+ scopeId: string;+ entries: StagedDownloadEntry[];+}++// Display state only. The owning hook still controls advancement and loading.+export const useStagedDownloadQueues = create<{+ queues: Record<string, StagedQueue>;+}>(() => ({ queues: {} }));++export function publishStagedQueue(owner: string, queue: StagedQueue | null) {+ useStagedDownloadQueues.setState(({ queues }) => {+ if (queue?.entries.length) return { queues: { ...queues, [owner]: queue } };+ if (!(owner in queues)) return { queues };+ const next = { ...queues };+ delete next[owner];+ return { queues: next };+ });+}++export function queuedStagedEntries(+ queues: Record<string, StagedQueue>,+ jobs: Record<+ string,+ Pick<+ ManagedDownload,+ "kind" | "repoId" | "variant" | "state" | "scopedFiles"+ >+ >,+) {+ return Object.entries(queues).flatMap(([owner, { scopeId, entries }]) =>+ entries.flatMap((entry, index) => {+ const active = Object.values(jobs).some(+ (job) =>+ job.kind === "model" &&+ job.repoId === entry.repoId &&+ job.variant === (entry.ggufVariant ?? scopedVariant(scopeId)) &&+ (job.state === "running" || job.state === "cancelling") &&+ (entry.ggufVariant ||+ (entry.files.length === job.scopedFiles?.length &&+ entry.files.every((file) => job.scopedFiles?.includes(file)))),+ );+ return active ? [] : [{ ...entry, planId: `staged:${owner}:${index}` }];+ }),+ );+}diff --git a/studio/frontend/src/features/hub/download-manager/use-hub-download-queue.ts b/studio/frontend/src/features/hub/download-manager/use-hub-download-queue.tsindex f0669329586..aa6264c5c84 100644--- a/studio/frontend/src/features/hub/download-manager/use-hub-download-queue.ts+++ b/studio/frontend/src/features/hub/download-manager/use-hub-download-queue.ts@@ -50,6 +50,7 @@ export function useHubDownloadQueue() {}));const { stage, remaining } = useStagedDownload({scopeId: "hub-assets",+ publishQueue: false,onReady: () => {finish();toast.success("Download complete", {diff --git a/studio/frontend/src/features/hub/download-manager/use-staged-download.ts b/studio/frontend/src/features/hub/download-manager/use-staged-download.tsindex af232e5917d..6e65cb6ac61 100644--- a/studio/frontend/src/features/hub/download-manager/use-staged-download.ts+++ b/studio/frontend/src/features/hub/download-manager/use-staged-download.ts@@ -1,7 +1,7 @@// 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 { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";import { toast } from "@/lib/toast";@@ -11,6 +11,7 @@ import {scopedDownloadInventoryKind,scopedVariant,} from "./download-manager-types";+import { publishStagedQueue } from "./staged-download-queue";import { useRepoDownload } from "./use-repo-download";/** Total progress for the plan ID returned by `stage()`. */@@ -42,8 +43,11 @@ export function useStagedDownload({scopeId,onReady,onCancelled,+ publishQueue = true,}: {scopeId: string;+ /** The Hub publishes its full queue, including plans not started yet. */+ publishQueue?: boolean;onReady: () => void;/** Clears the consumer's pending auto-load when the plan ends without every entry on disk: leaving it behind lets a later completion load a model nobody asked for. */onCancelled?: () => void;@@ -52,6 +56,12 @@ export function useStagedDownload({// Keep the original total as completed entries leave the queue.const [staged, setStaged] = useState({ bytes: 0, plan: 0 });const current = queue?.[0] ?? null;+ const queueOwner = useId();+ useEffect(() => {+ if (!publishQueue) return;+ publishStagedQueue(queueOwner, queue ? { scopeId, entries: queue } : null);+ return () => publishStagedQueue(queueOwner, null);+ }, [queueOwner, queue, scopeId, publishQueue]);// Every other entry is scoped, including a GGUF checkpoint: the Hub's snapshot ignore list drops *.gguf, so a plain snapshot job would finish having fetched everything EXCEPT the weights.const activeVariant = currentdiff --git a/studio/frontend/tests/download-panel-not-permanent.test.ts b/studio/frontend/tests/download-panel-not-permanent.test.tsindex 8679c03d62c..eca81a19bbf 100644--- a/studio/frontend/tests/download-panel-not-permanent.test.ts+++ b/studio/frontend/tests/download-panel-not-permanent.test.ts@@ -116,9 +116,20 @@ type Truth = true | false | null;function underAnEmptyList(node: ts.Node, jobKeys: string): Truth {// Queued plans show before their first job exists, so the panel hides only when both are empty.- const queued = panelComponent().body?.statements.flatMap(statement =>+ const declarations = panelComponent().body?.statements.flatMap(statement =>ts.isVariableStatement(statement) ? [...statement.declarationList.declarations] : []- ).find(declaration => declaration.initializer?.getText() === "useQueuedHubEntries()")?.name.getText();+ ) ?? [];+ // Prefer the combined route queue over its Hub-only input.+ const combined = declarations.find(declaration =>+ declaration.initializer && ts.isArrayLiteralExpression(declaration.initializer) &&+ declaration.initializer.elements.some(element =>+ ts.isSpreadElement(element) && ts.isCallExpression(element.expression) &&+ element.expression.expression.getText() === "queuedStagedEntries"+ )+ );+ const queued = (combined ?? declarations.find(declaration =>+ declaration.initializer?.getText() === "useQueuedHubEntries()"+ ))?.name.getText();if (isEmptyTest(node, jobKeys) || (queued && isEmptyTest(node, queued))) return true;if (ts.isParenthesizedExpression(node)) {return underAnEmptyList(node.expression, jobKeys);diff --git a/studio/frontend/tests/download-session-boundary.test.ts b/studio/frontend/tests/download-session-boundary.test.tsindex 9cd582cb344..bb53ca92f76 100644--- a/studio/frontend/tests/download-session-boundary.test.ts+++ b/studio/frontend/tests/download-session-boundary.test.ts@@ -30,6 +30,9 @@ const { getState, jobKeyOf, putJob, useDownloadManagerStore } = await import(const { runtimeRegistry } = await import("../src/features/hub/download-manager/runtime-registry.ts");+const { publishStagedQueue, useStagedDownloadQueues } = await import(+ "../src/features/hub/download-manager/staged-download-queue.ts"+);const boundaries: [string,@@ -67,6 +70,18 @@ for (const [name, eventType, event] of boundaries) {transport: "http",});runtimeRegistry.pendingStartRepoKeys.add("model:private-org/private-model");+ // A media page stays mounted across a cross-tab sign-out, so its queue is not unpublished.+ publishStagedQueue("images", {+ scopeId: "diffusion",+ entries: [+ {+ repoId: "private-org/private-vae",+ files: ["vae.safetensors"],+ bytes: 1,+ checkpoint: false,+ },+ ],+ });store.set(PERSIST_KEY, "prior-session-downloads");try {@@ -74,6 +89,7 @@ for (const [name, eventType, event] of boundaries) {assert.deepEqual(getState().jobs, {});assert.equal(runtimeRegistry.pendingStartRepoKeys.size, 0);assert.equal(store.has(PERSIST_KEY), false);+ assert.deepEqual(useStagedDownloadQueues.getState().queues, {});} finally {controller.__resetDownloadManagerForTests();await useDownloadManagerStore.persist.clearStorage();diff --git a/studio/frontend/tests/staged-download-queue.test.ts b/studio/frontend/tests/staged-download-queue.test.tsnew file mode 100644index 00000000000..81f63019f56--- /dev/null+++ b/studio/frontend/tests/staged-download-queue.test.ts@@ -0,0 +1,99 @@+// 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 { queuedStagedEntries, publishStagedQueue, useStagedDownloadQueues } =+ await import("../src/features/hub/download-manager/staged-download-queue.ts");++const encoder = {+ repoId: "encoder",+ files: ["text_encoder/model.safetensors"],+ bytes: 100,+ checkpoint: false,+};+const decoder = {+ repoId: "decoder",+ files: ["vae/model.safetensors"],+ bytes: 20,+ checkpoint: false,+};+const job = {+ kind: "model" as const,+ repoId: "encoder",+ variant: "@diffusion",+ state: "running" as const,+ scopedFiles: encoder.files,+};++test("image/video and audio stages stay visible while only the active transfer is hidden", () => {+ const queues = {+ image: { scopeId: "diffusion", entries: [encoder, decoder] },+ audio: { scopeId: "audio", entries: [encoder] },+ };+ assert.deepEqual(+ queuedStagedEntries(queues, { job }).map((e) => e.repoId),+ ["decoder", "encoder"],+ );+ assert.equal(queuedStagedEntries(queues, {}).length, 3);+});++test("another file set, scope, or dataset transfer cannot hide a pending model stage", () => {+ const queues = { image: { scopeId: "diffusion", entries: [encoder] } };+ for (const other of [+ { ...job, variant: "@hub-assets" },+ { ...job, scopedFiles: ["other.safetensors"] },+ { ...job, kind: "dataset" as const },+ ]) {+ assert.equal(queuedStagedEntries(queues, { other }).length, 1);+ }+ assert.equal(+ queuedStagedEntries(queues, { job: { ...job, state: "cancelling" } })+ .length,+ 0,+ );+ assert.equal(+ queuedStagedEntries(queues, { job: { ...job, state: "complete" } }).length,+ 1,+ );+});++test("GGUF audio stages match their variant without requiring scoped files", () => {+ const queues = {+ audio: {+ scopeId: "audio",+ entries: [{ ...encoder, ggufVariant: "Q4_K_M" }],+ },+ };+ assert.equal(+ queuedStagedEntries(queues, {+ job: { ...job, variant: "Q4_K_M", scopedFiles: undefined },+ }).length,+ 0,+ );+ assert.equal(+ queuedStagedEntries(queues, { job: { ...job, variant: "Q8_0" } }).length,+ 1,+ );+});++test("replacing, advancing, and retiring one owner preserves other queues in the same scope", () => {+ publishStagedQueue("images", {+ scopeId: "diffusion",+ entries: [encoder, decoder],+ });+ publishStagedQueue("video", { scopeId: "diffusion", entries: [encoder] });+ publishStagedQueue("images", { scopeId: "diffusion", entries: [decoder] });+ assert.equal(+ useStagedDownloadQueues.getState().queues.images.entries.length,+ 1,+ );+ publishStagedQueue("images", null);+ assert.deepEqual(Object.keys(useStagedDownloadQueues.getState().queues), [+ "video",+ ]);+ publishStagedQueue("video", { scopeId: "diffusion", entries: [] });+ assert.deepEqual(useStagedDownloadQueues.getState().queues, {});+});diff --git a/tests/studio/playwright_staged_download_rows.py b/tests/studio/playwright_staged_download_rows.pynew file mode 100644index 00000000000..5e337acfa95--- /dev/null+++ b/tests/studio/playwright_staged_download_rows.py@@ -0,0 +1,221 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Cached image model: show both missing asset stages, then cancel/retry/complete.++Runs the real picker, staging hook, and download panel with deterministic API+responses. No model download or GPU. PW_EXPECT=before records the missing row;+otherwise asserts parity. Use BASE_URL and PW_ART_DIR for isolated comparisons.+"""++import json+import os+import time+from pathlib import Path+from urllib.parse import parse_qs, urlparse++from playwright.sync_api import expect, sync_playwright+from playwright_image_model_footprint import (+ BASE_URL,+ REPO_ID,+ CHECKPOINT_BYTES,+ _api_payload,+ _json,+)+from playwright_image_download_cancel_retry import _open_quant++ENCODER = "unsloth/FLUX.2-klein-4B-FP8"+DECODER = "unsloth/FLUX.2-klein-4B"+ENTRIES = [+ {+ "repo_id": ENCODER,+ "files": ["text_encoder/model.safetensors"],+ "bytes": 4_000_000_000,+ "checkpoint": False,+ "gguf_filename": None,+ },+ {+ "repo_id": DECODER,+ "files": ["vae/diffusion_pytorch_model.safetensors", "model_index.json"],+ "bytes": 200_000_000,+ "checkpoint": False,+ "gguf_filename": None,+ },+]+++def main():+ before = os.environ.get("PW_EXPECT", "after") == "before"+ art = Path(os.environ.get("PW_ART_DIR", "logs/playwright_staged_download_rows"))+ art.mkdir(parents = True, exist_ok = True)+ state = {"jobs": {}, "starts": [], "loads": 0, "released": [], "plans": []}+ errors = []+ facts = {}+ with sync_playwright() as pw:+ browser = getattr(pw, os.environ.get("PW_BROWSER", "chromium")).launch(headless = True)+ context = browser.new_context(+ viewport = {"width": 1440, "height": 1000}, reduced_motion = "reduce"+ )+ context.add_init_script(+ "localStorage.setItem('unsloth_auth_token','rendered-ui-test');localStorage.setItem('unsloth_download_transport','http')"+ )++ def route(r):+ url = urlparse(r.request.url)+ path = url.path+ query = parse_qs(url.query)+ if not path.startswith("/api/"):+ if url.hostname in ("localhost", "127.0.0.1"):+ r.continue_()+ else:+ _json(r, [])+ return+ data = json.loads(r.request.post_data or "{}")+ repo = data.get("repo_id") or query.get("repo_id", [None])[0]+ if path == "/api/inference/images/download-plan":+ state["plans"].append(data)+ _json(+ r,+ {+ "entries": ENTRIES,+ "total_bytes": 4_200_000_000,+ "required_bytes": CHECKPOINT_BYTES + 4_200_000_000,+ "checkpoint_bytes": CHECKPOINT_BYTES,+ },+ )+ elif path == "/api/studio/download-transport-capabilities":+ _json(+ r,+ {+ "http": {"available": True},+ "xet": {"available": False},+ "auto_resolves_to": "http",+ },+ )+ elif path == "/api/hub/transport-status":+ _json(r, {"has_partial": False, "last_transport": None, "resumable": False})+ elif path == "/api/hub/download" and r.request.method == "POST":+ assert data["scope_id"] == "diffusion", data+ assert repo != REPO_ID, "cached model must not download again"+ state["starts"].append(repo)+ job = {"state": "running", "generation": len(state["starts"])}+ state["jobs"][repo] = job+ _json(+ r,+ {+ **job,+ "accepted": True,+ "job_key": f"model:{repo}:@diffusion",+ "transport": "http",+ },+ )+ elif path == "/api/hub/download/cancel":+ state["jobs"][repo]["state"] = "cancelled"+ _json(r, {"success": True, "state": "cancelled"})+ elif path == "/api/hub/download-status":+ job = state["jobs"].get(repo, {"state": "idle"})+ if job["state"] == "running" and repo in state["released"]:+ job["state"] = "complete"+ _json(r, {**job, "error": None})+ elif path in ("/api/hub/download-progress", "/api/hub/gguf-download-progress"):+ complete = state["jobs"].get(repo, {}).get("state") == "complete"+ size = next((e["bytes"] for e in ENTRIES if e["repo_id"] == repo), CHECKPOINT_BYTES)+ _json(+ r,+ {+ "downloaded_bytes": size if complete else size // 4,+ "completed_bytes": size if complete else 0,+ "complete_on_disk": complete,+ "expected_bytes": size,+ "progress": 1 if complete else 0.25,+ "cache_path": "/simulated-cache",+ },+ )+ elif path == "/api/inference/images/load":+ state["loads"] += 1+ _json(r, {"status": "loading"})+ else:+ result = _api_payload(path, query, full_footprint = True)+ if path in ("/api/hub/gguf-variants", "/api/models/gguf-variants"):+ result["variants"][0]["downloaded"] = True+ _json(r, result)++ context.route("**/*", route)+ page = context.new_page()+ page.on("pageerror", lambda e: errors.append(str(e)))++ def wait_for(predicate):+ deadline = time.monotonic() + 30+ while not predicate() and time.monotonic() < deadline:+ page.wait_for_timeout(100)+ assert predicate(), state++ try:+ page.goto(BASE_URL + "/images", wait_until = "domcontentloaded")+ expect(page.locator(".hub-download-panel")).to_have_count(0)+ _open_quant(page, navigate = False)+ wait_for(lambda: state["starts"] == [ENCODER])+ panel = page.locator(".hub-download-panel")+ expect(panel).to_be_visible()+ expected_rows = 1 if before else 2+ expect(panel.locator("li")).to_have_count(expected_rows)+ expect(panel).to_contain_text(f"Downloading {expected_rows} item")+ expect(panel).to_contain_text("Text encoder")+ expect(panel).to_contain_text("1.0 GB / 4.0 GB")+ if not before:+ expect(panel).to_contain_text("Decoder & configuration")+ expect(panel).to_contain_text("Queued")+ page.evaluate("""async () => {+ await document.fonts.load('12px "Inter Variable"');+ await document.fonts.ready;+ }""")+ facts["initial"] = {+ "rows": panel.locator("li").count(),+ "text": panel.inner_text(),+ "starts": list(state["starts"]),+ }+ panel.screenshot(path = str(art / "panel.png"))+ page.screenshot(path = str(art / "page.png"))+ panel.get_by_role("button", name = "Cancel download", exact = True).click()+ wait_for(lambda: state["jobs"][ENCODER]["state"] == "cancelled")+ expect(panel).not_to_contain_text("Queued")+ expect(panel).not_to_contain_text(DECODER + " ·")+ assert state["loads"] == 0+ _open_quant(page, navigate = False)+ wait_for(lambda: state["starts"] == [ENCODER, ENCODER])+ expect(panel.locator("li")).to_have_count(expected_rows)+ state["released"].append(ENCODER)+ wait_for(lambda: DECODER in state["starts"])+ expect(panel).not_to_contain_text("Queued")+ expect(panel.get_by_role("button", name = "Cancel download", exact = True)).to_have_count(1)+ state["released"].append(DECODER)+ wait_for(lambda: state["loads"] == 1)+ expect(panel).not_to_contain_text("Downloading")+ assert state["starts"] == [ENCODER, ENCODER, DECODER]+ for _ in range(panel.get_by_role("button", name = "Dismiss", exact = True).count()):+ panel.get_by_role("button", name = "Dismiss", exact = True).first.click()+ expect(panel).to_have_count(0)+ assert not errors, errors+ facts["lifecycle"] = (+ "cancel removes pending row; retry restores it; stages advance once; load runs once"+ )+ finally:+ (art / "facts.json").write_text(+ json.dumps(+ {+ "expect": "cached model: active encoder plus queued decoder",+ "side": "before" if before else "after",+ "url": BASE_URL,+ "facts": facts,+ "state": state,+ "page_errors": errors,+ },+ indent = 2,+ )+ )+ browser.close()+ print(f"PASS staged rows ({'before' if before else 'after'}): {facts}")+++if __name__ == "__main__":+ main()