Skip to content

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.

Studio: resume HTTP after Xet stall without a transport-conflict banner (#10045)

Souravrajvi0c47645fbd699
diff --git a/studio/frontend/src/features/hub/download-manager/constants.ts b/studio/frontend/src/features/hub/download-manager/constants.ts
index 683f24cccd3..612d962cdd1 100644
--- a/studio/frontend/src/features/hub/download-manager/constants.ts
+++ b/studio/frontend/src/features/hub/download-manager/constants.ts
@@ -115,6 +115,31 @@ export function isResolvedTransport(
);
}
+export type MismatchStartAction = ResolvedTransport | "conflict";
+
+/** When a partial on disk was written by a different transport than this start
+ * resolved to, pick whether to continue or ask the user.
+ *
+ * Xet cannot byte-resume. Auto and HTTP follow the stall watchdog's HTTP
+ * fallback instead of parking the start on a Hub dialog Chat/Video cannot
+ * resolve. Only an explicit Xet preference versus a resumable HTTP partial is
+ * a real choice (keep resumable bytes, or restart on Xet). */
+export function mismatchStartAction(
+ preferred: TransportMode,
+ resolved: ResolvedTransport,
+ lastTransport: ResolvedTransport,
+ resumable = true,
+): MismatchStartAction {
+ if (lastTransport === resolved) return resolved;
+ if (lastTransport === TRANSPORT.HTTP) {
+ if (preferred === TRANSPORT.XET && resolved === TRANSPORT.XET) {
+ return resumable ? "conflict" : resolved;
+ }
+ return TRANSPORT.HTTP;
+ }
+ return TRANSPORT.HTTP;
+}
+
export const DOWNLOAD_KIND = {
MODEL: "model",
DATASET: "dataset",
diff --git a/studio/frontend/src/features/hub/download-manager/transport-conflict.ts b/studio/frontend/src/features/hub/download-manager/transport-conflict.ts
index b295988f37a..742315a10c4 100644
--- a/studio/frontend/src/features/hub/download-manager/transport-conflict.ts
+++ b/studio/frontend/src/features/hub/download-manager/transport-conflict.ts
@@ -4,7 +4,12 @@
import { toast } from "@/lib/toast";
import { disposableTimeoutSignal } from "../lib/abort-signals";
import { getActiveModelDownloads } from "./api";
-import { TRANSPORT, type TransportMode } from "./constants";
+import {
+ mismatchStartAction,
+ TRANSPORT,
+ type ResolvedTransport,
+ type TransportMode,
+} from "./constants";
import {
apiTransportStatusWithRetry,
effectiveTransportMode,
@@ -61,13 +66,13 @@ function hasActiveOrPendingStart(req: DownloadRequest): boolean {
);
}
-function asTransportMode(value: unknown): TransportMode | null {
+function asTransportMode(value: unknown): ResolvedTransport | null {
return value === TRANSPORT.HTTP || value === TRANSPORT.XET ? value : null;
}
async function activeSiblingTransport(
req: DownloadRequest,
-): Promise<TransportMode | null> {
+): Promise<ResolvedTransport | null> {
if (req.kind !== "model" || !req.variant) return null;
const timeout = disposableTimeoutSignal(TRANSPORT_STATUS_TIMEOUT_MS);
const downloads = await getActiveModelDownloads(req.repoId, timeout.signal, {
@@ -155,21 +160,26 @@ export async function requestStart(
// during; read after them it would name the page they moved to.
const originRoute = currentRoute();
return runWithPendingStartGuard(req, async () => {
- let mode: TransportMode = await resolveTransportMode();
+ const preferred: TransportMode = await resolveTransportMode();
+ let mode: TransportMode = preferred;
try {
- mode = await effectiveTransportMode(mode);
+ mode = await effectiveTransportMode(preferred);
} catch (err) {
console.warn(
"Transport capability check failed; using the selected transport.",
err,
);
}
- let siblingTransport: TransportMode | null = null;
+ let siblingTransport: ResolvedTransport | null = null;
let siblingProbed = false;
try {
siblingTransport = await activeSiblingTransport(req);
siblingProbed = true;
- if (siblingTransport && siblingTransport !== mode) {
+ if (
+ siblingTransport &&
+ siblingTransport !== mode &&
+ preferred !== TRANSPORT.AUTO
+ ) {
toast.info("Another variant is already downloading", {
description:
siblingTransport === TRANSPORT.XET
@@ -183,22 +193,29 @@ export async function requestStart(
}
try {
const status = await apiTransportStatusWithRetry(req);
- if (
- status.has_partial &&
- status.last_transport &&
- status.last_transport !== mode
- ) {
- setConflict(jobKeyOf(req.kind, req.repoId, req.variant), {
- info: {
- previous: status.last_transport,
- next: mode,
- resumable: status.resumable,
- },
- // Without the caller's line: resolved later from the Hub, where "it'll
- // load automatically" is a promise chat cannot keep. The notice stands.
- pending: { ...req, callerToast: undefined },
- });
- return "conflict";
+ const last = asTransportMode(status.last_transport);
+ const resolved = asTransportMode(mode);
+ if (status.has_partial && last && resolved && last !== resolved) {
+ const action = mismatchStartAction(
+ preferred,
+ resolved,
+ last,
+ status.resumable,
+ );
+ if (action === "conflict") {
+ setConflict(jobKeyOf(req.kind, req.repoId, req.variant), {
+ info: {
+ previous: last,
+ next: resolved,
+ resumable: status.resumable,
+ },
+ // Without the caller's line: resolved later from the Hub, where "it'll
+ // load automatically" is a promise chat cannot keep. The notice stands.
+ pending: { ...req, callerToast: undefined },
+ });
+ return "conflict";
+ }
+ mode = action;
}
if (status.has_partial && !status.last_transport) {
toast.info("Restarting this download", {
@@ -229,6 +246,16 @@ export async function requestStart(
"Starting with the selected transport. If a partial from another transport exists, it may be restarted from the beginning.",
});
}
+ if (siblingProbed && siblingTransport && siblingTransport !== mode) {
+ toast.info("Another variant is already downloading", {
+ description:
+ siblingTransport === TRANSPORT.XET
+ ? "This repository is currently downloading with Xet. Switch to Xet or wait for it to finish."
+ : "This repository is currently downloading with HTTP. Switch to HTTP or wait for it to finish.",
+ });
+ return "busy";
+ }
+
await startJob(req, { useXet: mode === TRANSPORT.XET, originRoute });
return isJobActiveFor(req) ? "started" : "error";
});
diff --git a/studio/frontend/src/features/hub/download-manager/use-repo-download.ts b/studio/frontend/src/features/hub/download-manager/use-repo-download.ts
index 64b09c5e8f5..94badc84134 100644
--- a/studio/frontend/src/features/hub/download-manager/use-repo-download.ts
+++ b/studio/frontend/src/features/hub/download-manager/use-repo-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 } from "react";
+import { useCallback, useEffect, useMemo, useRef } from "react";
import { useShallow } from "zustand/react/shallow";
import { useLatestRef } from "../hooks/use-latest-ref";
import type { ResolvedTransport } from "./constants";
@@ -11,6 +11,7 @@ import {
type JobListeners,
downloadManager,
jobKeyOf,
+ repoKeyOf,
selectActiveJob,
subscribeJobListeners,
useDownloadManagerStore,
@@ -115,12 +116,45 @@ export function useRepoDownload(config: RepoDownloadConfig): DownloadJob {
() => jobKeyOf(kind, repoId, activeVariant ?? null),
[activeVariant, kind, repoId],
);
- const transportConflict = useDownloadManagerStore(
- (state) => state.conflicts[conflictKey]?.info ?? null,
+ const repoConflictKey = useMemo(
+ () => repoKeyOf(kind, repoId),
+ [kind, repoId],
+ );
+ const visibleConflict = useDownloadManagerStore(
+ useShallow((state) => {
+ const exact = state.conflicts[conflictKey];
+ if (exact) return { key: conflictKey, info: exact.info };
+ const scoped = Object.entries(state.conflicts).find(([key]) =>
+ key.startsWith(`${repoConflictKey}#`),
+ );
+ return scoped
+ ? { key: scoped[0], info: scoped[1].info }
+ : { key: conflictKey, info: null };
+ }),
);
+ const visibleConflictKey = visibleConflict.key;
+ const transportConflict = visibleConflict.info;
+ // Chat and Video staging park this hook on an idle repo id when the queue
+ // clears. Keep that conflict for Hub, but remember its key so a later real
+ // repo replacement clears the superseded request.
+ const repoIdRef = useRef(repoId);
+ const preservedConflictKeyRef = useRef<string | null>(null);
+ repoIdRef.current = repoId;
useEffect(
() => () => {
+ const parked = repoIdRef.current;
+ if (
+ parked === "__staged_download_idle__" ||
+ parked === "__hub_autoload_idle__"
+ ) {
+ preservedConflictKeyRef.current = conflictKey;
+ return;
+ }
+ if (preservedConflictKeyRef.current) {
+ downloadManager.cancelConflict(preservedConflictKeyRef.current);
+ preservedConflictKeyRef.current = null;
+ }
downloadManager.cancelConflict(conflictKey);
},
[conflictKey],
@@ -158,16 +192,16 @@ export function useRepoDownload(config: RepoDownloadConfig): DownloadJob {
);
const resumeConflict = useCallback(
- () => downloadManager.resumeConflict(conflictKey),
- [conflictKey],
+ () => downloadManager.resumeConflict(visibleConflictKey),
+ [visibleConflictKey],
);
const restartConflict = useCallback(
- () => downloadManager.restartConflict(conflictKey),
- [conflictKey],
+ () => downloadManager.restartConflict(visibleConflictKey),
+ [visibleConflictKey],
);
const cancelConflict = useCallback(
- () => downloadManager.cancelConflict(conflictKey),
- [conflictKey],
+ () => downloadManager.cancelConflict(visibleConflictKey),
+ [visibleConflictKey],
);
const progress = useMemo<DownloadJobProgress | null>(
diff --git a/studio/frontend/tests/download-transport-after-start.test.ts b/studio/frontend/tests/download-transport-after-start.test.ts
index 026cae6cdc7..88cfb49c093 100644
--- a/studio/frontend/tests/download-transport-after-start.test.ts
+++ b/studio/frontend/tests/download-transport-after-start.test.ts
@@ -4,9 +4,13 @@
import assert from "node:assert/strict";
import test from "node:test";
+import { readFileSync } from "node:fs";
+
import {
adoptedTransports,
+ mismatchStartAction,
probeDescribesCurrentRun,
+ TRANSPORT,
transportAfterStart,
} from "../src/features/hub/download-manager/constants.ts";
@@ -103,3 +107,103 @@ test("a reported null with nothing stored still holds no marker", () => {
{ transport: "http", cancelTransport: undefined },
);
});
+
+test("auto continues over HTTP after a Xet stall leftover", () => {
+ // Health demotes Auto to HTTP while the .transport marker is still xet.
+ assert.equal(
+ mismatchStartAction(TRANSPORT.AUTO, TRANSPORT.HTTP, TRANSPORT.XET),
+ TRANSPORT.HTTP,
+ );
+});
+
+test("auto resumes an HTTP partial instead of restarting on Xet", () => {
+ // HTTP fallback already wrote the marker; Auto still resolving to Xet must
+ // not send the user to the Hub conflict banner.
+ assert.equal(
+ mismatchStartAction(TRANSPORT.AUTO, TRANSPORT.XET, TRANSPORT.HTTP),
+ TRANSPORT.HTTP,
+ );
+});
+
+test("an explicit HTTP preference discards a Xet partial without a dialog", () => {
+ assert.equal(
+ mismatchStartAction(TRANSPORT.HTTP, TRANSPORT.HTTP, TRANSPORT.XET),
+ TRANSPORT.HTTP,
+ );
+});
+
+test("an explicit Xet preference still asks before throwing away HTTP bytes", () => {
+ assert.equal(
+ mismatchStartAction(TRANSPORT.XET, TRANSPORT.XET, TRANSPORT.HTTP),
+ "conflict",
+ );
+});
+
+test("an explicit Xet preference restarts an unresumable HTTP partial", () => {
+ assert.equal(
+ mismatchStartAction(TRANSPORT.XET, TRANSPORT.XET, TRANSPORT.HTTP, false),
+ TRANSPORT.XET,
+ );
+});
+
+test("unavailable Xet with an HTTP partial continues over HTTP", () => {
+ // Preference is Xet, but the machine already demoted the resolved transport.
+ assert.equal(
+ mismatchStartAction(TRANSPORT.XET, TRANSPORT.HTTP, TRANSPORT.HTTP),
+ TRANSPORT.HTTP,
+ );
+});
+
+test("a matching pair is left alone", () => {
+ assert.equal(
+ mismatchStartAction(TRANSPORT.AUTO, TRANSPORT.XET, TRANSPORT.XET),
+ TRANSPORT.XET,
+ );
+});
+
+test("a transport mismatch start uses the mismatch helper", () => {
+ const source = readFileSync(
+ new URL(
+ "../src/features/hub/download-manager/transport-conflict.ts",
+ import.meta.url,
+ ),
+ "utf8",
+ );
+ assert.match(
+ source,
+ /mismatchStartAction\(\s*preferred,\s*resolved,\s*last,\s*status\.resumable,\s*\)/,
+ );
+ assert.match(
+ source,
+ /siblingTransport !== mode &&\s*preferred !== TRANSPORT\.AUTO/,
+ );
+ assert.match(source, /mode = action;[\s\S]*?siblingTransport !== mode/);
+});
+
+test("staging owns cleanup while Hub resolves exact or scoped conflicts", () => {
+ const source = readFileSync(
+ new URL(
+ "../src/features/hub/download-manager/use-repo-download.ts",
+ import.meta.url,
+ ),
+ "utf8",
+ );
+ const exactIndex = source.indexOf(
+ "const exact = state.conflicts[conflictKey]",
+ );
+ const scopedIndex = source.indexOf(
+ "const scoped = Object.entries(state.conflicts)",
+ );
+ assert.ok(exactIndex >= 0 && scopedIndex > exactIndex);
+ assert.match(source, /__staged_download_idle__/);
+ assert.match(source, /__hub_autoload_idle__/);
+ assert.match(source, /preservedConflictKeyRef\.current = conflictKey/);
+ assert.match(source, /cancelConflict\(preservedConflictKeyRef\.current\)/);
+ assert.match(source, /resumeConflict\(visibleConflictKey\)/);
+ assert.match(source, /restartConflict\(visibleConflictKey\)/);
+ assert.match(source, /cancelConflict\(visibleConflictKey\)/);
+ assert.match(
+ source,
+ /downloadManager\.cancelConflict\(conflictKey\);\s*\},\s*\[conflictKey\]/,
+ );
+});