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
Studio: pause the prompt queue without killing its target
Chaitanya Laxman67f294101bb9
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsxindex bc507bff51b..37fbaeba982 100644--- a/studio/frontend/src/components/assistant-ui/thread.tsx+++ b/studio/frontend/src/components/assistant-ui/thread.tsx@@ -186,6 +186,7 @@ import {notifyPromptQueueRunFailed,planLocalPromptQueueStop,planUserPromptQueueStop,+ userStopTargetCancelMode,registerQueuedChatRunSettings,releasePreStreamRunReservation,reservePreStreamRun,@@ -358,6 +359,7 @@ type PromptQueueTarget = {append: (prompt: string) => void | Promise<void>;complete: () => void;cancel: () => void;+ cancelActiveRun: () => void;isIndexing: () => boolean;usesThreadDocuments: boolean;usesLocalModel: boolean;@@ -873,6 +875,9 @@ function getPromptQueueItemStatus(index: number,activeItemIndex: number,): PromptQueueUIItemStatus {+ if (run.paused && run.index >= 0 && index === activeItemIndex) {+ return "paused";+ }if (run.index >= 0 && index === activeItemIndex) {return run.waitingForTargetIdle ? "waiting" : "next";}@@ -936,6 +941,7 @@ function syncPromptQueueUI() {local: promptQueueRunUsesLocalModel(run),temporary: promptQueueRunIsTemporary(run),dispatched: Boolean(getActivePromptQueueItem(run)?.dispatched),+ paused: run.paused,};for (const id of ids) {byThreadId[id] = entry;@@ -1222,16 +1228,11 @@ function startPromptQueue(waitForCurrentRun = false,) {const filtered = items.map((item) => item.trim()).filter(Boolean);- const existingRun = findPromptQueueRunByTarget(target);if (filtered.length === 0) {- if (existingRun?.paused) {- existingRun.paused = false;- syncPromptQueueUI();- requestPromptQueuePump();- }return;}+ const existingRun = findPromptQueueRunByTarget(target);if (existingRun) {if (existingRun.deepResearchConsumed) {target.consumeDeepResearch();@@ -1290,13 +1291,14 @@ function getPromptQueueRunsForThreadIds(threadIds?: string[]) {return Array.from(runs);}-function stopPromptQueueRun(threadIds?: string[]) {+function pausePromptQueueRun(threadIds?: string[]) {for (const run of getPromptQueueRunsForThreadIds(threadIds)) {const activeItem = getActivePromptQueueItem(run);const plan = planUserPromptQueueStop(run.items.map((item) => ({ dispatched: item.dispatched })),run.index,);+ const cancelMode = userStopTargetCancelMode(plan);if (plan.retainedItemIndexes.length === 0) {deletePromptQueueRun(run);} else {@@ -1316,11 +1318,44 @@ function stopPromptQueueRun(threadIds?: string[]) {syncPromptQueueUI();}}- if (!plan.cancelActiveItem) {+ if (cancelMode === "none") {continue;}try {- activeItem?.target.cancel();+ if (cancelMode === "permanent") {+ activeItem?.target.cancel();+ } else {+ activeItem?.target.cancelActiveRun();+ }+ } catch {+ // The active run may have already ended.+ }+ }+ requestPromptQueuePumpIfReady();+}++function resumePromptQueueRun(threadIds?: string[]) {+ for (const run of getPromptQueueRunsForThreadIds(threadIds)) {+ if (!run.paused) {+ continue;+ }+ run.paused = false;+ syncPromptQueueUI();+ }+ requestPromptQueuePumpIfReady();+}++function stopPromptQueueRun(threadIds?: string[]) {+ for (const run of getPromptQueueRunsForThreadIds(threadIds)) {+ const activeItem = getActivePromptQueueItem(run);+ const activeTarget = activeItem?.target;+ const shouldCancelActiveRun = Boolean(activeItem?.dispatched);+ deletePromptQueueRun(run);+ if (!shouldCancelActiveRun) {+ continue;+ }+ try {+ activeTarget?.cancel();} catch {// The active run may have already ended.}@@ -1527,13 +1562,17 @@ interface PromptQueueCallbacks {onAborted?: () => void,) => boolean;stopQueue: () => void;+ resumeQueue: () => void;}const noopStartPromptQueue: PromptQueueCallbacks["startQueue"] = () =>false;const noopStopPromptQueue: PromptQueueCallbacks["stopQueue"] = () => undefined;+const noopResumePromptQueue: PromptQueueCallbacks["resumeQueue"] = () =>+ undefined;const PromptQueueContext = createContext<PromptQueueCallbacks>({startQueue: noopStartPromptQueue,stopQueue: noopStopPromptQueue,+ resumeQueue: noopResumePromptQueue,});// Gap (px) between last message and floating composer; bottom spacer tracks@@ -3551,6 +3590,7 @@ const Composer: FC<{};const pendingSettingsIds = new Set<number>();let cancelled = false;+ let appendEpoch = 0;let shouldCorrectPersistedModel: boolean | null = null;let initializedFreshThreadId: string | null = null;let freshThreadAppendAccepted = false;@@ -3599,6 +3639,7 @@ const Composer: FC<{hasPreStreamRunReservation(getQueueThreadIds()) ||Boolean(getThreadRuntime()?.getState().isRunning),append: async (prompt) => {+ const epoch = appendEpoch;const thread = getThreadRuntime();if (!thread) {throw new Error("Prompt queue thread runtime is unavailable");@@ -3652,6 +3693,7 @@ const Composer: FC<{if (removeFreshThreadPersistedAfterAbort() ||cancelled ||+ epoch !== appendEpoch ||!pendingSettingsIds.has(settingsId)) {return;@@ -3672,6 +3714,7 @@ const Composer: FC<{if (removeFreshThreadPersistedAfterAbort() ||cancelled ||+ epoch !== appendEpoch ||!pendingSettingsIds.has(settingsId)) {return;@@ -3713,6 +3756,11 @@ const Composer: FC<{pendingSettingsIds.clear();getThreadRuntime()?.cancelRun();},+ cancelActiveRun: () => {+ appendEpoch += 1;+ discardOldestPendingSettings();+ getThreadRuntime()?.cancelRun();+ },isIndexing: () =>promptQueueTargetMountedRef.current &&isTargetCurrentThread() &&@@ -4706,7 +4754,11 @@ const Composer: FC<{);const stopQueue = useCallback(() => {- stopPromptQueueRunForThreadIds(promptQueueThreadIds);+ pausePromptQueueRun(promptQueueThreadIds);+ }, [promptQueueThreadIds]);++ const resumeQueue = useCallback(() => {+ resumePromptQueueRun(promptQueueThreadIds);}, [promptQueueThreadIds]);const startQueue = useCallback(@@ -4729,7 +4781,11 @@ const Composer: FC<{[aui, startHydratedPromptQueue, threadIsRunning, disableQueue],);- const queueContextValue: PromptQueueCallbacks = { startQueue, stopQueue };+ const queueContextValue: PromptQueueCallbacks = {+ startQueue,+ stopQueue,+ resumeQueue,+ };const composerContent = (<>@@ -4867,6 +4923,7 @@ const Composer: FC<{// submitting the form, so run the complete queue/capacity path.onSendClick={handleSubmit}onStopClick={stopQueue}+ onResumeClick={resumeQueue}onDictateClick={startDictation}pendingSend={pendingSend}menuSide={effectiveMenuSide}@@ -6327,6 +6384,8 @@ function promptQueueStatusLabel(status: PromptQueueUIItemStatus) {return "Waiting";case "next":return "Next";+ case "paused":+ return "Paused";case "queued":return "Queued";default: {@@ -6574,6 +6633,7 @@ const ComposerRightControls: FC<{onQueueClick?: () => void;onSendClick?: (event: { preventDefault: () => void }) => void;onStopClick?: () => void;+ onResumeClick?: () => void;onDictateClick?: () => void;pendingSend?: boolean;menuSide?: "top" | "bottom";@@ -6584,6 +6644,7 @@ const ComposerRightControls: FC<{onQueueClick,onSendClick,onStopClick,+ onResumeClick,onDictateClick,pendingSend,menuSide,@@ -6699,7 +6760,20 @@ const ComposerRightControls: FC<{</AuiIf>{isQueueRunning && !isResearchActive ? (<AuiIf condition={({ thread }) => !thread.isRunning}>- {queueEntry?.dispatched ? (+ {queueEntry?.paused ? (+ <TooltipIconButton+ tooltip="Resume queue"+ side="bottom"+ type="button"+ variant="default"+ size="icon"+ onClick={onResumeClick}+ className="aui-composer-send ml-1.5 size-9 rounded-full"+ aria-label="Resume queue"+ >+ <FastForwardIcon className="size-[18px] stroke-2" />+ </TooltipIconButton>+ ) : queueEntry?.dispatched ? (<Buttontype="button"variant="default"diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.tsindex 60b79737f41..83d9406978d 100644--- a/studio/frontend/src/features/chat/index.ts+++ b/studio/frontend/src/features/chat/index.ts@@ -165,7 +165,10 @@ export {shouldAbortPendingQueueForModelBoundary,shouldAbortPendingQueueForSettingsChange,} from "./utils/prompt-queue-model-boundary";-export { planUserPromptQueueStop } from "./utils/prompt-queue-user-stop";+export {+ planUserPromptQueueStop,+ userStopTargetCancelMode,+} from "./utils/prompt-queue-user-stop";export { chatHistoryClearBoundary } from "./utils/chat-history-clear-boundary";export { rangeBetween, toggleSelected } from "./utils/row-selection";export {diff --git a/studio/frontend/src/features/chat/stores/prompt-queue-ui-store.ts b/studio/frontend/src/features/chat/stores/prompt-queue-ui-store.tsindex 054d6ea094b..a0e4ddb2524 100644--- a/studio/frontend/src/features/chat/stores/prompt-queue-ui-store.ts+++ b/studio/frontend/src/features/chat/stores/prompt-queue-ui-store.ts@@ -10,13 +10,15 @@ export type PromptQueueUIEntry = {local: boolean;temporary: boolean;dispatched: boolean;+ paused: boolean;};export type PromptQueueUIItemStatus =| "queued"| "next"| "waiting"- | "running";+ | "running"+ | "paused";export type PromptQueueUIItem = {id: string;diff --git a/studio/frontend/src/features/chat/utils/prompt-queue-user-stop.ts b/studio/frontend/src/features/chat/utils/prompt-queue-user-stop.tsindex d5ee035cd1f..68910c61965 100644--- a/studio/frontend/src/features/chat/utils/prompt-queue-user-stop.ts+++ b/studio/frontend/src/features/chat/utils/prompt-queue-user-stop.ts@@ -11,7 +11,17 @@ export type UserPromptQueueStopPlan = {pause: boolean;};-/** Stop generation without discarding prompts that have not been sent yet. */+export type PromptQueueTargetCancelMode = "none" | "activeRun" | "permanent";++export function userStopTargetCancelMode(+ plan: UserPromptQueueStopPlan,+): PromptQueueTargetCancelMode {+ if (!plan.cancelActiveItem) {+ return "none";+ }+ return plan.pause ? "activeRun" : "permanent";+}+export function planUserPromptQueueStop(items: readonly PromptQueueUserStopItem[],runIndex: number,diff --git a/studio/frontend/tests/prompt-queue-user-stop.test.ts b/studio/frontend/tests/prompt-queue-user-stop.test.tsindex 4862393deca..edaf173b184 100644--- a/studio/frontend/tests/prompt-queue-user-stop.test.ts+++ b/studio/frontend/tests/prompt-queue-user-stop.test.ts@@ -1,79 +1,88 @@import assert from "node:assert/strict";import test from "node:test";-import { planUserPromptQueueStop } from "../src/features/chat/utils/prompt-queue-user-stop.ts";+import {+ planUserPromptQueueStop,+ userStopTargetCancelMode,+} from "../src/features/chat/utils/prompt-queue-user-stop.ts";-test("a dispatched stop keeps pending follow-ups and pauses", () => {- assert.deepEqual(- planUserPromptQueueStop(- [- { dispatched: true },- { dispatched: false },- { dispatched: false },- ],- 0,- ),- {- cancelActiveItem: true,- retainedItemIndexes: [1, 2],- pause: true,- },- );-});+class SharedQueueTarget {+ permanentlyCancelled = false;+ activeRunCancels = 0;+ cancel() {+ this.permanentlyCancelled = true;+ }+ cancelActiveRun() {+ this.activeRunCancels += 1;+ }+ append() {+ return this.permanentlyCancelled ? "skipped" : "sent";+ }+}-test("a dispatched stop with no follow-ups leaves nothing to resume", () => {- assert.deepEqual(- planUserPromptQueueStop([{ dispatched: true }], 0),- {- cancelActiveItem: true,- retainedItemIndexes: [],- pause: false,- },- );-});+function applyStopCancel(+ target: SharedQueueTarget,+ plan: ReturnType<typeof planUserPromptQueueStop>,+) {+ const mode = userStopTargetCancelMode(plan);+ if (mode === "permanent") target.cancel();+ else if (mode === "activeRun") target.cancelActiveRun();+ return mode;+}-test("an undispatched stop keeps the whole queue and pauses", () => {- assert.deepEqual(- planUserPromptQueueStop(- [{ dispatched: false }, { dispatched: false }],- 0,- ),- {- cancelActiveItem: false,- retainedItemIndexes: [0, 1],- pause: true,- },- );-});+const plans: Array<{+ name: string;+ items: Array<{ dispatched: boolean }>;+ index: number;+ want: ReturnType<typeof planUserPromptQueueStop>;+}> = [+ {+ name: "a dispatched stop keeps pending follow-ups and pauses",+ items: [{ dispatched: true }, { dispatched: false }, { dispatched: false }],+ index: 0,+ want: { cancelActiveItem: true, retainedItemIndexes: [1, 2], pause: true },+ },+ {+ name: "a dispatched stop with no follow-ups leaves nothing to resume",+ items: [{ dispatched: true }],+ index: 0,+ want: { cancelActiveItem: true, retainedItemIndexes: [], pause: false },+ },+ {+ name: "an undispatched stop keeps the whole queue and pauses",+ items: [{ dispatched: false }, { dispatched: false }],+ index: 0,+ want: { cancelActiveItem: false, retainedItemIndexes: [0, 1], pause: true },+ },+ {+ name: "a queue still waiting to start is paused without cancelling",+ items: [{ dispatched: false }, { dispatched: false }],+ index: -1,+ want: { cancelActiveItem: false, retainedItemIndexes: [0, 1], pause: true },+ },+];-test("completed history is kept when a later dispatched item is stopped", () => {- assert.deepEqual(- planUserPromptQueueStop(- [- { dispatched: true },- { dispatched: true },- { dispatched: false },- ],- 1,- ),- {- cancelActiveItem: true,- retainedItemIndexes: [0, 2],- pause: true,- },+for (const entry of plans) {+ test(entry.name, () => {+ assert.deepEqual(planUserPromptQueueStop(entry.items, entry.index), entry.want);+ });+}++test("pausing a shared-target batch still lets the next prompt append", () => {+ const target = new SharedQueueTarget();+ const plan = planUserPromptQueueStop(+ [{ dispatched: true }, { dispatched: false }],+ 0,);+ assert.equal(applyStopCancel(target, plan), "activeRun");+ assert.equal(target.append(), "sent");+ assert.equal(target.activeRunCancels, 1);+ assert.equal(target.permanentlyCancelled, false);});-test("a queue still waiting to start is paused without cancelling", () => {- assert.deepEqual(- planUserPromptQueueStop(- [{ dispatched: false }, { dispatched: false }],- -1,- ),- {- cancelActiveItem: false,- retainedItemIndexes: [0, 1],- pause: true,- },- );+test("a stop with nothing left permanently cancels the shared target", () => {+ const target = new SharedQueueTarget();+ const plan = planUserPromptQueueStop([{ dispatched: true }], 0);+ assert.equal(applyStopCancel(target, plan), "permanent");+ assert.equal(target.append(), "skipped");});diff --git a/tests/studio/test_prompt_queue_user_stop.py b/tests/studio/test_prompt_queue_user_stop.pyindex e5c91bc122a..e39d28008f2 100644--- a/tests/studio/test_prompt_queue_user_stop.py+++ b/tests/studio/test_prompt_queue_user_stop.py@@ -1,19 +1,14 @@# SPDX-License-Identifier: AGPL-3.0-only# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0-"""Stop generation must keep prompts that have not been sent yet.--https://github.com/unslothai/unsloth/issues/10428-"""+"""Composer stop pauses the queue; delete/archive still delete it."""from pathlib import Path--REPO = Path(__file__).resolve().parents[2]-FRONTEND = REPO / "studio/frontend/src"-THREAD = (FRONTEND / "components/assistant-ui/thread.tsx").read_text(encoding = "utf-8")-PLANNER_PATH = FRONTEND / "features/chat/utils/prompt-queue-user-stop.ts"-BARREL = (FRONTEND / "features/chat/index.ts").read_text(encoding = "utf-8")+THREAD = (+ Path(__file__).resolve().parents[2]+ / "studio/frontend/src/components/assistant-ui/thread.tsx"+).read_text(encoding = "utf-8")def _between(source: str, start: str, end: str) -> str:@@ -23,55 +18,27 @@ def _between(source: str, start: str, end: str) -> str:return tail.split(end, 1)[0]-def test_user_stop_plans_with_pending_items_kept():- assert PLANNER_PATH.is_file()- planner = PLANNER_PATH.read_text(encoding = "utf-8")- assert "export function planUserPromptQueueStop(" in planner- assert 'from "./utils/prompt-queue-user-stop"' in BARREL+def test_composer_stop_pauses_without_permanently_cancelling_the_target():+ pause = _between(+ THREAD,+ "function pausePromptQueueRun(threadIds?: string[])",+ "function resumePromptQueueRun(threadIds?: string[])",+ )+ assert "userStopTargetCancelMode(plan)" in pause+ assert "cancelActiveRun()" in pause+ assert "pausePromptQueueRun(promptQueueThreadIds)" in THREAD+ assert 'aria-label="Resume queue"' in THREADstop = _between(THREAD,"function stopPromptQueueRun(threadIds?: string[])","function stopPromptQueueRunForThreadIds(threadIds: string[])",)- assert "planUserPromptQueueStop(" in stop- assert stop.index("planUserPromptQueueStop(") < stop.index(- "deletePromptQueueRun(run);"- )- assert "run.paused = plan.pause" in stop- assert "run.generation += 1" in stop---def test_paused_queue_does_not_dispatch_or_advance():- ready = _between(- THREAD,- "function isPromptQueueRunReadyToDispatch(run: PromptQueueRun)",- "function getNextReadyPromptQueueRun()",- )- assert "!run.paused" in ready- run_state = _between(- THREAD,- "function handlePromptQueueRunState(",- "function ensurePromptQueueSubscription()",- )- assert run_state.index("if (run.paused)") < run_state.index(- "advancePromptQueue(run);"- )- retained = _between(- THREAD,- "function retainPendingPromptQueueItemsAfterFailure(run: PromptQueueRun)",- "function cancelPendingPromptQueueFactoriesForStop<",- )- assert retained.index("if (run.paused)") < retained.index(- "run.items.splice(activeIndex, 1);"- )---def test_start_unpauses_an_existing_run():- start = _between(+ assert "planUserPromptQueueStop(" not in stop+ assert "deletePromptQueueRun(run);" in stop+ listener = _between(THREAD,- "function startPromptQueue(",- "function getPromptQueueRunsForThreadIds(threadIds?: string[])",+ "window.addEventListener(PROMPT_QUEUE_STOP_EVENT",+ "window.addEventListener(PROMPT_QUEUE_RUN_FAILED_EVENT",)- assert "existingRun.paused = false" in start- assert "existingRun?.paused" in start- assert "paused: false" in start+ assert "stopPromptQueueRunForThreadIds(threadIds)" in listener+ assert "pausePromptQueueRun(" not in listener