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: show an unloading toast when the image or video model is ejected (#17560)

Nilay95dd0cf18e8d
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index ba1d38394d7..743a7f9ed79 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -228,6 +228,7 @@ import {
routedGgufLabel,
} from "@/lib/diffusion-route-search";
import { toast } from "@/lib/toast";
+import { ejectWithToast } from "@/lib/media-eject";
import { useLoadAnywayPrompt } from "@/components/load-anyway-dialog";
import { readAllowOversizedLoad, retryWhileCurrent, shouldOfferLoadAnyway } from "@/lib/unified-memory-load-refusal";
import { evictedSlotsFrom, evictedToastOptions, resyncEvicted, type EvictedSlot } from "@/lib/evicted-toast";
@@ -5018,6 +5019,9 @@ export function ImagesPage({
}
}, [refreshStatus, dropResidentState]);
+ const ejecting = useRef(false);
+ const handleEject = useCallback(() => ejectWithToast(ejecting, handleUnload), [handleUnload]);
+
// The unload cancels the load; it leaves only cache, so reloading resumes.
const handleCancelLoad = useCallback(async () => {
const wasLoading = busy === "loading";
@@ -6256,7 +6260,7 @@ export function ImagesPage({
activeGgufVariant={quant}
onValueChange={handleModelSelect}
resolveDownloadFootprint={resolveDownloadFootprint}
- onEject={status?.loaded ? handleUnload : undefined}
+ onEject={status?.loaded ? handleEject : undefined}
variant="ghost"
className="ml-1.5 max-w-full overflow-hidden !pl-2.5 !pr-1.5 !h-[var(--studio-chat-control-height,34px)]"
task={IMAGE_GEN_TASKS}
diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsx
index 91db37f4fa9..8f8104589d8 100644
--- a/studio/frontend/src/features/video/video-page.tsx
+++ b/studio/frontend/src/features/video/video-page.tsx
@@ -229,6 +229,7 @@ import {
isDownloadCancelled,
} from "@/lib/native-files";
import { toast } from "@/lib/toast";
+import { ejectWithToast } from "@/lib/media-eject";
import { useLoadAnywayPrompt } from "@/components/load-anyway-dialog";
import { readAllowOversizedLoad, retryWhileCurrent, shouldOfferLoadAnyway } from "@/lib/unified-memory-load-refusal";
import { evictedSlotsFrom, evictedToastOptions, resyncEvicted, type EvictedSlot } from "@/lib/evicted-toast";
@@ -3624,6 +3625,9 @@ function VideoGenerator({
}
}, [refreshStatus, dropResidentState]);
+ const ejecting = useRef(false);
+ const handleEject = useCallback(() => ejectWithToast(ejecting, handleUnload), [handleUnload]);
+
// Cancelling a load IS the unload; only cache remains, so reloading resumes.
const handleCancelLoad = useCallback(async () => {
const wasLoading = busy === "loading";
@@ -4090,7 +4094,7 @@ function VideoGenerator({
activeGgufVariant={quant}
onValueChange={handleModelSelect}
resolveDownloadFootprint={resolveDownloadFootprint}
- onEject={status?.loaded ? handleUnload : undefined}
+ onEject={status?.loaded ? handleEject : undefined}
variant="ghost"
className="ml-1.5 max-w-full overflow-hidden !pl-2.5 !pr-1.5 !h-[var(--studio-chat-control-height,34px)]"
task={VIDEO_GEN_TASKS}
diff --git a/studio/frontend/src/lib/media-eject.ts b/studio/frontend/src/lib/media-eject.ts
new file mode 100644
index 00000000000..189b546e320
--- /dev/null
+++ b/studio/frontend/src/lib/media-eject.ts
@@ -0,0 +1,25 @@
+// 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";
+
+/** Images / Video pill eject: the chat pill's unloading toast, one unload at a time. */
+export async function ejectWithToast(
+ inFlight: { current: boolean },
+ unload: () => Promise<boolean>,
+): Promise<void> {
+ if (inFlight.current) {
+ toast.info("Wait for the model to finish unloading.");
+ return;
+ }
+ inFlight.current = true;
+ const toastId = toast.loading("Unloading model");
+ let unloaded = false;
+ try {
+ unloaded = await unload();
+ } finally {
+ inFlight.current = false;
+ if (unloaded) toast.success("Model unloaded", { id: toastId, duration: 1200 });
+ else toast.dismiss(toastId);
+ }
+}
diff --git a/studio/frontend/tests/helpers/toast-stub.mjs b/studio/frontend/tests/helpers/toast-stub.mjs
index 1df863a0dad..fed43f65c7c 100644
--- a/studio/frontend/tests/helpers/toast-stub.mjs
+++ b/studio/frontend/tests/helpers/toast-stub.mjs
@@ -8,6 +8,10 @@ export const toast = Object.assign(
(title, options) => calls.push({ kind: "default", title, options }),
{
info: (title, options) => calls.push({ kind: "info", title, options }),
+ loading: (title, options) => {
+ calls.push({ kind: "loading", title, options });
+ return options?.id ?? `loading-${calls.length}`;
+ },
error: (title, options) => calls.push({ kind: "error", title, options }),
warning: (title, options) =>
calls.push({ kind: "warning", title, options }),
diff --git a/studio/frontend/tests/media-eject-toast.test.ts b/studio/frontend/tests/media-eject-toast.test.ts
new file mode 100644
index 00000000000..3131b38304e
--- /dev/null
+++ b/studio/frontend/tests/media-eject-toast.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 from "node:test";
+import { register } from "node:module";
+
+register("./helpers/toast-resolver.mjs", import.meta.url);
+
+const { calls } = await import("./helpers/toast-stub.mjs");
+const { ejectWithToast } = await import("../src/lib/media-eject.ts");
+const { readSrc } = await import("./helpers/kit.ts");
+
+type Call = { kind: string; title?: string; id?: string; options?: { id?: string } };
+
+function deferred() {
+ let resolve!: (v: boolean) => void;
+ let reject!: (e: unknown) => void;
+ const promise = new Promise<boolean>((res, rej) => {
+ resolve = res;
+ reject = rej;
+ });
+ return { promise, resolve, reject };
+}
+
+function shown(): [string, string | undefined][] {
+ return (calls as Call[]).map((c) => [c.kind, c.title ?? c.id]);
+}
+
+test("eject shows Unloading model, then Model unloaded on the same toast", async () => {
+ calls.length = 0;
+ await ejectWithToast({ current: false }, async () => true);
+ const success = (calls as Call[])[1];
+ assert.deepEqual(shown(), [
+ ["loading", "Unloading model"],
+ ["success", "Model unloaded"],
+ ]);
+ assert.equal(success.options?.id, "loading-1");
+});
+
+test("a second eject while unloading sends no unload and says to wait", async () => {
+ calls.length = 0;
+ const inFlight = { current: false };
+ const gate = deferred();
+ let unloads = 0;
+ const unload = () => {
+ unloads++;
+ return gate.promise;
+ };
+ const first = ejectWithToast(inFlight, unload);
+ const second = ejectWithToast(inFlight, unload);
+ const unloadsDuring = unloads;
+ const last = shown().at(-1);
+ gate.resolve(true);
+ await Promise.all([first, second]);
+ assert.equal(unloadsDuring, 1);
+ assert.deepEqual(last, ["info", "Wait for the model to finish unloading."]);
+ calls.length = 0;
+ await ejectWithToast(inFlight, unload);
+ assert.equal(unloads, 2, "the guard clears once the unload ends");
+});
+
+test("a failed or still-loading unload drops the loading toast", async () => {
+ calls.length = 0;
+ const inFlight = { current: false };
+ await ejectWithToast(inFlight, async () => false);
+ assert.deepEqual(shown(), [
+ ["loading", "Unloading model"],
+ ["dismiss", "loading-1"],
+ ]);
+ calls.length = 0;
+ await assert.rejects(
+ ejectWithToast(inFlight, async () => {
+ throw new Error("boom");
+ }),
+ );
+ assert.equal(shown().at(-1)?.[0], "dismiss");
+ assert.equal(inFlight.current, false);
+});
+
+for (const path of ["features/images/images-page.tsx", "features/video/video-page.tsx"]) {
+ test(`${path} routes the pill eject through ejectWithToast`, () => {
+ const page = readSrc(path);
+ assert.match(page, /onEject=\{status\?\.loaded \? handleEject : undefined\}/);
+ assert.match(page, /const handleEject = useCallback\(\(\) => ejectWithToast\(ejecting, handleUnload\), \[handleUnload\]\);/);
+ });
+}
diff --git a/studio/frontend/tests/media-load-cancel.test.ts b/studio/frontend/tests/media-load-cancel.test.ts
index e07f42ebff1..3317bd4a8dc 100644
--- a/studio/frontend/tests/media-load-cancel.test.ts
+++ b/studio/frontend/tests/media-load-cancel.test.ts
@@ -137,7 +137,7 @@ for (const [page, path] of PAGES) {
test(`the ${page} eject is still offered only for a resident model`, () => {
assert.match(
SOURCE,
- /onEject=\{status\?\.loaded \? handleUnload : undefined\}/,
+ /onEject=\{status\?\.loaded \? handleEject : undefined\}/,
);
});