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): stop showing manifest-less cache entries as downloading (#7858) (#7864)
Tai An8d7b5ca40745
diff --git a/studio/frontend/src/features/chat/api/chat-api.ts b/studio/frontend/src/features/chat/api/chat-api.tsindex 14f3dc2bbf0..195b8a0a5ef 100644--- a/studio/frontend/src/features/chat/api/chat-api.ts+++ b/studio/frontend/src/features/chat/api/chat-api.ts@@ -410,6 +410,12 @@ export async function getGgufDownloadProgress(export interface DownloadProgressResponse {downloaded_bytes: number;+ /**+ * Finalized-blob bytes only. Bytes still landing in a `.incomplete` blob count+ * toward `downloaded_bytes` but not here, so the two are equal exactly when+ * nothing is in flight.+ */+ completed_bytes: number;expected_bytes: number;progress: number;/**diff --git a/studio/frontend/src/features/studio/download-state.ts b/studio/frontend/src/features/studio/download-state.tsnew file mode 100644index 00000000000..55a97ecd6be--- /dev/null+++ b/studio/frontend/src/features/studio/download-state.ts@@ -0,0 +1,61 @@+// 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 download state the training-start overlay renders, plus the coercion that+// decides whether a resource is still arriving or merely unverified. Kept apart+// from the overlay so the rule can be exercised without mounting the component.++export type DownloadState = {+ downloadedBytes: number;+ // Finalized-blob bytes only, mirroring the backend field of the same name:+ // bytes still landing in a `.incomplete` blob count toward `downloadedBytes`+ // but not here.+ completedBytes: number;+ totalBytes: number;+ percent: number;+ cachePath: string | null;+};++export const EMPTY_DOWNLOAD_STATE: DownloadState = {+ downloadedBytes: 0,+ completedBytes: 0,+ totalBytes: 0,+ percent: 0,+ cachePath: null,+};++/**+ * Present a cached resource as ready once nothing is left to transfer.+ *+ * The backend holds progress at 99% until a Studio download manifest verifies the+ * snapshot on disk. Hugging Face cache entries created outside Studio -- or before+ * the manifest system existed -- never get one, so they stay unverified with every+ * byte already present, and the overlay rendered them as an active transfer+ * indefinitely (#7858).+ *+ * `completedBytes` is what separates the two cases: it counts finalized blobs+ * only, so all of them being present means nothing is in flight and the remaining+ * gap is verification rather than transfer. A resumed download -- where finalized+ * bytes can sit near the total while `.incomplete` blobs are still growing -- keeps+ * reporting progress, which is what the backend's 99% cap exists to protect.+ */+export function coerceCachedStateReady(state: DownloadState): DownloadState {+ if (!state.cachePath) return state;+ const everyByteFinalized =+ state.totalBytes > 0 && state.completedBytes >= state.totalBytes;+ if (state.downloadedBytes > 0 && state.percent < 100 && !everyByteFinalized) {+ return state;+ }+ const totalBytes =+ state.totalBytes > 0 ? state.totalBytes : state.downloadedBytes;+ if (totalBytes <= 0) {+ return { ...state, percent: 100 };+ }+ return {+ ...state,+ downloadedBytes: totalBytes,+ completedBytes: totalBytes,+ totalBytes,+ percent: 100,+ };+}diff --git a/studio/frontend/src/features/studio/training-start-overlay.tsx b/studio/frontend/src/features/studio/training-start-overlay.tsxindex 42c07c30396..91392e95214 100644--- a/studio/frontend/src/features/studio/training-start-overlay.tsx+++ b/studio/frontend/src/features/studio/training-start-overlay.tsx@@ -26,6 +26,11 @@ import {} from "@/features/chat/api/chat-api";import { useTransferStats } from "@/features/chat/hooks/use-transfer-stats";import { formatEta, formatRate } from "@/features/chat/utils/format-transfer";+import {+ EMPTY_DOWNLOAD_STATE,+ coerceCachedStateReady,+ type DownloadState,+} from "@/features/studio/download-state";import {useTrainingActions,useTrainingConfigStore,@@ -57,36 +62,6 @@ function formatCachePath(path: string): string {.replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/, "~");}-type DownloadState = {- downloadedBytes: number;- totalBytes: number;- percent: number;- cachePath: string | null;-};--const EMPTY_DOWNLOAD_STATE: DownloadState = {- downloadedBytes: 0,- totalBytes: 0,- percent: 0,- cachePath: null,-};--function coerceCachedStateReady(state: DownloadState): DownloadState {- if (!state.cachePath) return state;- if (state.downloadedBytes > 0 && state.percent < 100) return state;- const totalBytes =- state.totalBytes > 0 ? state.totalBytes : state.downloadedBytes;- if (totalBytes <= 0) {- return { ...state, percent: 100 };- }- return {- ...state,- downloadedBytes: totalBytes,- totalBytes,- percent: 100,- };-}-type Fetcher = (repoId: string) => Promise<DownloadProgressResponse>;/**@@ -133,6 +108,7 @@ function useHfDownloadProgress(total > 0 ? Math.min(100, Math.round(ratio * 100)) : 0;setState({downloadedBytes: downloaded,+ completedBytes: prog.completed_bytes ?? 0,totalBytes: total,percent: pct,cachePath: prog.cache_path ?? null,diff --git a/studio/frontend/tests/training-start-cached-progress.test.ts b/studio/frontend/tests/training-start-cached-progress.test.tsnew file mode 100644index 00000000000..21ae994e030--- /dev/null+++ b/studio/frontend/tests/training-start-cached-progress.test.ts@@ -0,0 +1,83 @@+// 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 training-start overlay showed cached resources as "Downloading -- 99%" with no+// download running (#7858): the backend caps progress at 99% until a Studio manifest+// verifies the snapshot, and cache entries made outside Studio never have one. These+// pin the distinction the overlay now draws -- finalized bytes decide whether anything+// is still arriving -- including the resumed-download case the 99% cap exists for.++import assert from "node:assert/strict";+import test from "node:test";++import {+ type DownloadState,+ coerceCachedStateReady,+} from "../src/features/studio/download-state.ts";++const MB = 1e6;+const GB = 1e9;++function state(over: Partial<DownloadState> = {}): DownloadState {+ return {+ downloadedBytes: 0,+ completedBytes: 0,+ totalBytes: 0,+ percent: 0,+ cachePath: "/home/u/.cache/huggingface/hub/datasets--unsloth--alpaca-cleaned",+ ...over,+ };+}++test("a cache entry with no manifest reads as ready, not as a transfer", () => {+ // Observed with unsloth/alpaca-cleaned: 42.3 MB of 42.3 MB, no worker running.+ const coerced = coerceCachedStateReady(+ state({+ downloadedBytes: 42.3 * MB,+ completedBytes: 42.3 * MB,+ totalBytes: 42.3 * MB,+ percent: 99,+ }),+ );+ assert.equal(coerced.percent, 100);+});++test("a resumed download still reports progress while blobs are incomplete", () => {+ // The case the backend's 99% cap protects: finalized bytes sit just under the+ // total while the remaining `.incomplete` blob is still growing.+ const resuming = state({+ downloadedBytes: 20 * GB,+ completedBytes: 19.9 * GB,+ totalBytes: 20 * GB,+ percent: 99,+ });+ assert.deepEqual(coerceCachedStateReady(resuming), resuming);+});++test("an ordinary in-flight download is left alone", () => {+ const downloading = state({+ downloadedBytes: 5 * GB,+ completedBytes: 4.8 * GB,+ totalBytes: 20 * GB,+ percent: 25,+ });+ assert.deepEqual(coerceCachedStateReady(downloading), downloading);+});++test("a resource with no cache path is never coerced", () => {+ const uncached = state({+ downloadedBytes: 42.3 * MB,+ completedBytes: 42.3 * MB,+ totalBytes: 42.3 * MB,+ percent: 99,+ cachePath: null,+ });+ assert.deepEqual(coerceCachedStateReady(uncached), uncached);+});++test("a cached entry of unknown size still settles instead of hanging", () => {+ const unsized = coerceCachedStateReady(+ state({ downloadedBytes: 0, completedBytes: 0, totalBytes: 0, percent: 0 }),+ );+ assert.equal(unsized.percent, 100);+});