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: let an attachment use Queue while a reply is running (#9215)

Kenshi988ab871d788
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index f9a9dcfb234..466e962ae10 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -245,6 +245,7 @@ import {
registerQueuedChatRunSettings,
releasePreStreamRunReservation,
reservePreStreamRun,
+ subscribePreStreamRunReservations,
claimThreadCreation,
useChatProjectScope,
shouldAbortPendingQueueForModelBoundary,
@@ -3674,6 +3675,12 @@ const Composer: FC<{
referenceThreadId,
]);
const preStreamRunReservationRef = useRef<symbol | null>(null);
+ // Wakes a parked attachment when a preflight releases without ever streaming.
+ const preStreamRunActive = useSyncExternalStore(
+ subscribePreStreamRunReservations,
+ () => hasPreStreamRunReservation(preStreamThreadIds),
+ () => false,
+ );
useEffect(() => {
const token = preStreamRunReservationRef.current;
if (!token) {
@@ -3704,6 +3711,10 @@ const Composer: FC<{
// same text did before it attached, rather than being refused as a file.
const canQueuePastedTextPrompt =
attachmentsAreAllPastedText && composerAcceptsQueueing;
+ // The queue carries text only, so other attachments park in the composer and
+ // send once the run and the queue are idle.
+ const canQueueAttachmentPrompt =
+ hasAttachments && !attachmentsAreAllPastedText && composerAcceptsQueueing;
// Per-thread draft autosave: restore on mount, then mirror composer text
// into localStorage (debounced) so a half-typed message survives a
@@ -4599,23 +4610,26 @@ const Composer: FC<{
| "images"
| "audio"
| "video"
+ | "running"
| "settings" = "indexing",
) => {
if (pendingSendRef.current) return;
pendingSendRef.current = true;
setPendingSend(true);
const title =
- waitingOn === "images"
- ? "Waiting for dropped images"
- : waitingOn === "audio"
- ? "Waiting for dropped audio"
- : waitingOn === "video"
- ? "Waiting for dropped video"
- : waitingOn === "settings"
- ? "Loading this chat's settings"
- : "Waiting for documents to finish indexing";
+ waitingOn === "running"
+ ? "Waiting for the current response to finish"
+ : waitingOn === "images"
+ ? "Waiting for dropped images"
+ : waitingOn === "audio"
+ ? "Waiting for dropped audio"
+ : waitingOn === "video"
+ ? "Waiting for dropped video"
+ : waitingOn === "settings"
+ ? "Loading this chat's settings"
+ : "Waiting for documents to finish indexing";
waitToastRef.current = toast(title, {
- description: "Your message will send automatically once they are ready.",
+ description: "Your message will send automatically once it is ready.",
duration: Infinity,
cancel: { label: "Cancel", onClick: cancelQueuedSend },
});
@@ -4780,11 +4794,18 @@ const Composer: FC<{
],
);
- // Fire the parked send once indexing clears, unless the user emptied the
+ // Fire the parked send once all waits clear, unless the user emptied the
// composer while waiting (then drop it quietly). An image dropped after the
// send was parked has to land first, or indexing finishing early sends the
// text without it and the image attaches to the next draft.
useEffect(() => {
+ const liveThreadIsRunning =
+ threadIsRunning || aui.thread().getState().isRunning;
+ const livePromptQueueActive = Boolean(
+ findPromptQueueEntry(usePromptQueueUI.getState(), promptQueueThreadIds),
+ );
+ const livePreStreamRunActive =
+ hasPreStreamRunReservation(preStreamThreadIds);
// pendingSendRef too: a cancel earlier in this same commit has already
// dropped the send, while `pendingSend` still reads true from this render.
if (
@@ -4792,6 +4813,11 @@ const Composer: FC<{
!pendingSendRef.current ||
indexingActive ||
threadScopedSettingsPending ||
+ (hasAttachments &&
+ !attachmentsAreAllPastedText &&
+ (liveThreadIsRunning ||
+ livePromptQueueActive ||
+ livePreStreamRunActive)) ||
hasMaterializingImageAttachments ||
hasMaterializingAudioAttachments ||
hasMaterializingVideoAttachments
@@ -4867,6 +4893,11 @@ const Composer: FC<{
pendingSend,
indexingActive,
threadScopedSettingsPending,
+ preStreamRunActive,
+ threadIsRunning,
+ promptQueueActive,
+ promptQueueThreadIds,
+ attachmentsAreAllPastedText,
hasMaterializingImageAttachments,
hasMaterializingAudioAttachments,
hasMaterializingVideoAttachments,
@@ -5186,6 +5217,10 @@ const Composer: FC<{
) {
return;
}
+ if (canQueueAttachmentPrompt) {
+ enqueueSend("running");
+ return;
+ }
if (overlay || hasAttachments || hasPendingAudio) {
toast.error(
liveThreadIsRunning
@@ -5193,7 +5228,7 @@ const Composer: FC<{
: "Wait for the prompt queue to finish",
{
description:
- "Only text prompts can be queued while a response is running or the prompt queue is active.",
+ "Only text prompts and ready attachments can be queued while a response is running or the prompt queue is active.",
},
);
}
@@ -5270,6 +5305,7 @@ const Composer: FC<{
},
[
aui,
+ canQueueAttachmentPrompt,
canQueueCurrentPrompt,
canQueuePastedTextPrompt,
queueComposerText,
@@ -5476,7 +5512,11 @@ const Composer: FC<{
// button, so a running thread shows Stop instead of Queue.
queueDisabled={
disableQueue ||
- !(canQueueCurrentPrompt || canQueuePastedTextPrompt)
+ !(
+ canQueueCurrentPrompt ||
+ canQueuePastedTextPrompt ||
+ canQueueAttachmentPrompt
+ )
}
onQueueClick={() => formRef.current?.requestSubmit()}
// ComposerPrimitive.Send handles clicks itself rather than
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index 7a3da666e8f..c26b9e4ec2e 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -218,6 +218,7 @@ export {
releasePreStreamRunForThreadIds,
releasePreStreamRunReservation,
reservePreStreamRun,
+ subscribePreStreamRunReservations,
} from "./utils/pre-stream-run-reservation";
export { claimThreadCreation } from "./utils/chat-thread-creation-claim";
export { useChatProjectScope } from "./chat-project-scope";
diff --git a/studio/frontend/src/features/chat/utils/pre-stream-run-reservation.ts b/studio/frontend/src/features/chat/utils/pre-stream-run-reservation.ts
index b37348272c5..86ce73d4985 100644
--- a/studio/frontend/src/features/chat/utils/pre-stream-run-reservation.ts
+++ b/studio/frontend/src/features/chat/utils/pre-stream-run-reservation.ts
@@ -20,6 +20,20 @@ export interface PreStreamRunReservationOptions {
const reservations = new Map<symbol, PreStreamRunReservation>();
const reservationByThreadId = new Map<string, symbol>();
+const listeners = new Set<() => void>();
+
+export function subscribePreStreamRunReservations(
+ listener: () => void,
+): () => void {
+ listeners.add(listener);
+ return () => {
+ listeners.delete(listener);
+ };
+}
+
+function notifyReservationsChanged(): void {
+ for (const listener of [...listeners]) listener();
+}
export function preStreamRunThreadIdsForAdapter(
unstableThreadId: string | null | undefined,
@@ -85,6 +99,7 @@ export function reservePreStreamRun(
for (const threadId of ids) {
reservationByThreadId.set(threadId, token);
}
+ notifyReservationsChanged();
return token;
}
@@ -118,6 +133,7 @@ function cancelPreStreamReservation(token: symbol): boolean {
reservationByThreadId.delete(id);
}
if (!reservation.claimed) reservations.delete(token);
+ notifyReservationsChanged();
return true;
}
@@ -180,6 +196,7 @@ export function adoptPreStreamRunReservation(
reservation.threadIds.add(threadId);
reservationByThreadId.set(threadId, token);
}
+ notifyReservationsChanged();
return true;
}
@@ -194,6 +211,7 @@ export function releasePreStreamRunReservation(token: symbol): boolean {
reservationByThreadId.delete(threadId);
}
}
+ notifyReservationsChanged();
return true;
}
diff --git a/studio/frontend/tests/composer-submit-path.test.ts b/studio/frontend/tests/composer-submit-path.test.ts
index b8429a4ca81..4bd150c7638 100644
--- a/studio/frontend/tests/composer-submit-path.test.ts
+++ b/studio/frontend/tests/composer-submit-path.test.ts
@@ -180,6 +180,9 @@ for (const active of ["runtime", "pre-stream", "queue", "idle"]) {
pendingFollowUpBehaviorRef,
indexingActive: false,
threadScopedSettingsPending: false,
+ threadIsRunning: false,
+ promptQueueThreadIds: ["own-chat"],
+ attachmentsAreAllPastedText: false,
hasMaterializingImageAttachments: false,
hasMaterializingAudioAttachments: false,
hasMaterializingVideoAttachments: false,
@@ -214,14 +217,69 @@ for (const active of ["runtime", "pre-stream", "queue", "idle"]) {
release(); // An old render cannot release a cancelled/consumed send twice.
assert.deepEqual(
calls,
- active === "idle"
- ? ["clear", "send"]
- : [[active !== "queue", "steer"]],
+ active === "idle" ? ["clear", "send"] : [[active !== "queue", "steer"]],
);
assert.equal(pendingSendRef.current, false);
});
}
+for (const active of ["runtime", "pre-stream", "queue"]) {
+ test(`a queued attachment stays parked through ${active} state and sends once (#9210)`, () => {
+ const calls: string[] = [];
+ const state = { active: true };
+ const pendingSendRef = { current: true };
+ const deps = {
+ pendingSend: true,
+ pendingSendRef,
+ pendingFollowUpBehaviorRef: { current: "queue" },
+ indexingActive: false,
+ threadScopedSettingsPending: false,
+ threadIsRunning: false,
+ promptQueueThreadIds: ["own-chat"],
+ attachmentsAreAllPastedText: false,
+ hasMaterializingImageAttachments: false,
+ hasMaterializingAudioAttachments: false,
+ hasMaterializingVideoAttachments: false,
+ aui: {
+ composer: () => ({
+ getState: () => ({ text: "", attachments: [{ id: "image-1" }] }),
+ }),
+ thread: () => ({
+ getState: () => ({
+ isRunning: state.active && active === "runtime",
+ }),
+ }),
+ },
+ setPendingSend: () => undefined,
+ dismissWaitToast: () => calls.push("dismiss"),
+ hasPreStreamRunReservation: () => state.active && active === "pre-stream",
+ preStreamThreadIds: ["own-chat"],
+ isResearchActive: false,
+ findPromptQueueEntry: () => state.active && active === "queue",
+ usePromptQueueUI: { getState: () => ({}) },
+ disableQueue: false,
+ canQueueCurrentPrompt: false,
+ queueComposerText: () => calls.push("queue-text"),
+ canQueuePastedTextPrompt: false,
+ queuePastedTextPrompt: () => calls.push("queue-paste"),
+ overlay: false,
+ hasAttachments: true,
+ hasPendingAudio: false,
+ clearStoredDraft: () => calls.push("clear"),
+ sendReservedComposer: () => calls.push("send"),
+ toast: { error: () => calls.push("error") },
+ };
+ const release = createCallback(releaseCallback, deps);
+ release();
+ assert.deepEqual(calls, []);
+ assert.equal(pendingSendRef.current, true);
+ state.active = false;
+ release();
+ release();
+ assert.deepEqual(calls, ["dismiss", "clear", "send"]);
+ });
+}
+
test("main cancels an audio upload only after a normal send reservation succeeds", () => {
const run = (reservationToken: symbol | null) => {
const calls: string[] = [];
diff --git a/studio/frontend/tests/pre-stream-run-reservation.test.ts b/studio/frontend/tests/pre-stream-run-reservation.test.ts
index ea381807842..9707f0286da 100644
--- a/studio/frontend/tests/pre-stream-run-reservation.test.ts
+++ b/studio/frontend/tests/pre-stream-run-reservation.test.ts
@@ -15,8 +15,35 @@ import {
releasePreStreamRunForThreadIds,
releasePreStreamRunReservation,
reservePreStreamRun,
+ subscribePreStreamRunReservations,
} from "../src/features/chat/utils/pre-stream-run-reservation.ts";
+test("parked send subscribers observe failed preflight release and cancellation", () => {
+ const observed: boolean[] = [];
+ const unsubscribe = subscribePreStreamRunReservations(() => {
+ observed.push(hasPreStreamRunReservation(["parked-follow-up"]));
+ });
+ try {
+ const token = reservePreStreamRun(["parked-follow-up"]);
+ assert.ok(token);
+ releasePreStreamRunReservation(token);
+ const second = reservePreStreamRun(["parked-follow-up"]);
+ assert.ok(second);
+ cancelPreStreamRunReservations([second]);
+ const third = reservePreStreamRun(["parked-follow-up"]);
+ assert.ok(third);
+ cancelPreStreamRunForThreadIds(["parked-follow-up"]);
+ assert.deepEqual(observed, [true, false, true, false, true, false]);
+ } finally {
+ unsubscribe();
+ releasePreStreamRunForThreadIds(["parked-follow-up"]);
+ }
+ const afterUnsubscribe = reservePreStreamRun(["parked-follow-up"]);
+ assert.ok(afterUnsubscribe);
+ releasePreStreamRunReservation(afterUnsubscribe);
+ assert.equal(observed.length, 6);
+});
+
test("adapter thread ids never mix an identified background run with the visible chat", () => {
assert.deepEqual(
preStreamRunThreadIdsForAdapter("background-thread", "visible-thread"),