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: fix pause side effects on the prompt queue
danielhanchenb60312cb335d
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex b64d331746c..a91f54d99c6 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -3075,9 +3075,13 @@ export function AppSidebar() {item.type === "compare"? (item.threadIds ?? []).some((id) => Boolean(runningByThreadId[id])): Boolean(runningByThreadId[item.id]);- const hasQueuedActivity = threadIds.some((threadId) =>- Boolean(queueByThreadId[threadId]),- );+ // A paused queue is not activity. The entry survives a Stop now that the composer+ // pauses instead of deleting the run, so without this the row keeps spinning for+ // work the user explicitly stopped, with nothing left to ever clear it.+ const hasQueuedActivity = threadIds.some((threadId) => {+ const entry = queueByThreadId[threadId];+ return Boolean(entry) && !entry.paused;+ });// Active generation and queued work share the in-row spinner slot so they cannot drift.const showQueuedActivity = hasQueuedActivity && !isGenerating;const showWorkSpinner = isGenerating || showQueuedActivity;diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsxindex 03f966975f0..cb7c1c49c05 100644--- a/studio/frontend/src/components/assistant-ui/thread.tsx+++ b/studio/frontend/src/components/assistant-ui/thread.tsx@@ -703,10 +703,23 @@ function pumpPromptQueues() {deletePromptQueueRun(run);continue;}+ const dispatchGeneration = run.generation;promptQueueDispatchingRunIds.add(run.id);dispatchQueuedPrompt(run, item, run.generation).catch(() => undefined).finally(() => {+ // The dispatching flag is keyed on the run, not on the attempt, so a+ // dispatch that a pause superseded would release the flag a LIVE dispatch+ // is holding. Pausing bumps the generation and clears the flag, so after+ // Stop then Resume the old attempt's probe can settle while the new one is+ // still in flight: it frees the flag, re-pumps, and the same prompt is+ // appended twice. Only the attempt that still owns the generation releases.+ if (+ promptQueueRuns.get(run.id) === run &&+ dispatchGeneration !== run.generation+ ) {+ return;+ }promptQueueDispatchingRunIds.delete(run.id);syncPromptQueueUI();if (!promptQueueActiveRunIds.has(run.id)) {@@ -1302,7 +1315,16 @@ function pausePromptQueueRun(threadIds?: string[]) {deletePromptQueueRun(run);} else {run.items = plan.retainedItemIndexes.map((index) => run.items[index]);- const nextIndex = run.items.findIndex((item) => !item.dispatched);+ // Scan from where the run actually was, not from the head of the list. A+ // findIndex from 0 rewinds onto any undispatched item the run has already+ // moved past, so Resume would send it AFTER prompts that already went out.+ const resumeFrom = plan.retainedItemIndexes.findIndex(+ (index) => index >= Math.max(run.index, 0),+ );+ const searchFrom = resumeFrom < 0 ? 0 : resumeFrom;+ const nextIndex = run.items.findIndex(+ (item, index) => index >= searchFrom && !item.dispatched,+ );if (nextIndex < 0) {deletePromptQueueRun(run);} else {@@ -1339,6 +1361,18 @@ function resumePromptQueueRun(threadIds?: string[]) {continue;}run.paused = false;+ // prevStoreRunning is the one that matters. handlePromptQueueRunState writes it+ // BEFORE its `if (run.paused) return`, so a rising edge seen while paused (the+ // user stops the queue and then sends an ordinary message in the same chat, or a+ // shared alias picks up another run) is left behind. Clearing paused without+ // clearing this lets the following idle edge take the advancePromptQueue branch,+ // which completes and SKIPS the first retained prompt without ever sending it --+ // the same silent prompt loss this PR set out to fix, through the new path.+ // The other two are defensive: pausePromptQueueRun already clears the idle wait,+ // and an edit-armed retry timer self-clears.+ run.waitingForTargetIdle = false;+ run.prevStoreRunning = false;+ clearPromptQueueRetryTimer(run);syncPromptQueueUI();}requestPromptQueuePumpIfReady();diff --git a/studio/frontend/src/features/chat/utils/confirm-stop-running-chats.ts b/studio/frontend/src/features/chat/utils/confirm-stop-running-chats.tsindex 78aede718ad..77f52acbf33 100644--- a/studio/frontend/src/features/chat/utils/confirm-stop-running-chats.ts+++ b/studio/frontend/src/features/chat/utils/confirm-stop-running-chats.ts@@ -70,7 +70,10 @@ export async function confirmStopRunningChatsIfNeeded(const aliasesByQueuedRun = new Map<string, string[]>();for (const threadId of promptQueueThreadIds) {const entry = promptQueuesByThreadId[threadId];- if (!entry) {+ // A paused queue is not a running chat. Its entry outlives the composer Stop+ // now that Stop pauses rather than deletes the run, so counting it here would+ // put a chat the user has already stopped into the "still running" list.+ if (!entry || entry.paused) {continue;}const aliases = aliasesByQueuedRun.get(entry.runId) ?? [];diff --git a/tests/studio/test_prompt_queue_pause_side_effects.py b/tests/studio/test_prompt_queue_pause_side_effects.pynew file mode 100644index 00000000000..38ff8eb42a5--- /dev/null+++ b/tests/studio/test_prompt_queue_pause_side_effects.py@@ -0,0 +1,64 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Contracts for the paths a paused prompt queue reaches without being edited by it.++Pausing instead of deleting keeps the run, and therefore its PromptQueueUIEntry,+alive after the user presses Stop. Everything that treated "an entry exists" as+"work is happening" silently starts reporting a chat the user has already stopped.+These pin the three places that had to learn about `paused`.+"""++from pathlib import Path++ROOT = Path(__file__).resolve().parents[2]+THREAD = (ROOT / "studio/frontend/src/components/assistant-ui/thread.tsx").read_text(+ encoding = "utf-8"+)+SIDEBAR = (ROOT / "studio/frontend/src/components/app-sidebar.tsx").read_text(+ encoding = "utf-8"+)+CONFIRM = (+ ROOT / "studio/frontend/src/features/chat/utils/confirm-stop-running-chats.ts"+).read_text(encoding = "utf-8")+++def test_the_sidebar_work_spinner_ignores_a_paused_queue():+ # Measured before the guard: BEFORE 0 sidebar spinners after Stop settled,+ # AFTER 1, on the same probe against two builds of the same commit pair.+ block = SIDEBAR.split("const hasQueuedActivity", 1)[1]+ block = block.split("const showQueuedActivity", 1)[0]+ assert "entry.paused" in block+++def test_a_paused_queue_is_not_a_running_chat_in_the_stop_dialog():+ loop = CONFIRM.split("for (const threadId of promptQueueThreadIds)", 1)[1]+ loop = loop.split("for (const aliases of aliasesByQueuedRun.values())", 1)[0]+ assert "entry.paused" in loop+++def test_resume_clears_the_stale_running_edge_so_it_cannot_skip_a_prompt():+ # handlePromptQueueRunState records prevStoreRunning before it returns for a paused+ # run, so a rising edge seen while paused survives. Resuming without clearing it+ # lets the next idle edge advance past the first retained prompt without sending it.+ resume = THREAD.split("function resumePromptQueueRun(threadIds?: string[])", 1)[1]+ resume = resume.split("function stopPromptQueueRun", 1)[0]+ assert "run.prevStoreRunning = false" in resume+ assert "run.waitingForTargetIdle = false" in resume+ assert "clearPromptQueueRetryTimer(run)" in resume+++def test_a_superseded_dispatch_does_not_release_the_live_dispatch_flag():+ # Without this the same prompt is appended twice when Stop then Resume happen+ # while a document-indexing probe is still outstanding.+ pump = THREAD.split("function pumpPromptQueues()", 1)[1]+ pump = pump.split("async function dispatchQueuedPrompt(", 1)[0]+ assert "const dispatchGeneration = run.generation" in pump+ assert "dispatchGeneration !== run.generation" in pump+++def test_pause_does_not_rewind_past_a_prompt_the_run_already_moved_beyond():+ pause = THREAD.split("function pausePromptQueueRun(threadIds?: string[])", 1)[1]+ pause = pause.split("function resumePromptQueueRun", 1)[0]+ assert "resumeFrom" in pause+ assert "index >= searchFrom" in pause