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: Steer now stops the response for a parked attachment send (#17583)

Etherl2f0da1e7eeeb
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 294ec73c444..374c5583552 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -114,8 +114,10 @@ import {
imeKeydownBlocksComposerSubmit,
followUpSubmitIntent,
steeringInsertionIndex,
+ parkedSendSteer,
cancelPreStreamRunForThreadIds,
type ComposerSendShortcut,
+ type ParkedSendSteerState,
type ComposerSubmitIntent,
type ComposerFollowUpBehavior,
type ContextTruncation,
@@ -4477,6 +4479,19 @@ const Composer: FC<{
}
>(),
);
+ // Starts not yet in the queue store.
+ const hasPendingQueueStart = useCallback(
+ () =>
+ hasPendingPromptQueueStart(
+ promptQueueStartPendingRef.current.values(),
+ referenceThreadId,
+ ) ||
+ hasPendingPromptQueueStart(
+ pastedTextQueuePendingRef.current.values(),
+ referenceThreadId,
+ ),
+ [referenceThreadId],
+ );
useEffect(() => {
promptQueueTargetMountedRef.current = true;
return () => {
@@ -5213,6 +5228,26 @@ const Composer: FC<{
[cancelQueuedSend],
);
+ // Consuming the intent makes one press cancel once.
+ const steerParkedSend = useCallback(
+ (state: Omit<ParkedSendSteerState, "behavior">) => {
+ const steer = parkedSendSteer({
+ ...state,
+ behavior: pendingFollowUpBehaviorRef.current,
+ });
+ if (!steer) return;
+ pendingFollowUpBehaviorRef.current = "queue";
+ cancelPreStreamRunForThreadIds(preStreamThreadIds);
+ if (!steer.cancelRun) return;
+ try {
+ aui.thread().cancelRun();
+ } catch {
+ // Already ended.
+ }
+ },
+ [aui, preStreamThreadIds],
+ );
+
// A materializing image or clip parks the send; both gates share this to agree.
const parkIfWaitingOnAttachments = useCallback(() => {
if (
@@ -5371,21 +5406,35 @@ const Composer: FC<{
);
const livePreStreamRunActive =
hasPreStreamRunReservation(preStreamThreadIds);
+ const parkedBehindResponse =
+ hasAttachments &&
+ !attachmentsAreQueueableText &&
+ (liveThreadIsRunning || livePromptQueueActive || livePreStreamRunActive);
// pendingSendRef is authoritative because pendingSend still reflects the pre-cancel render.
if (
!pendingSend ||
!pendingSendRef.current ||
indexingActive ||
threadScopedSettingsPending ||
- (hasAttachments &&
- !attachmentsAreQueueableText &&
- (liveThreadIsRunning ||
- livePromptQueueActive ||
- livePreStreamRunActive)) ||
+ parkedBehindResponse ||
hasMaterializingImageAttachments ||
hasMaterializingAudioAttachments ||
hasMaterializingVideoAttachments
) {
+ // Keeps its steer until an upload or settings hold clears.
+ if (pendingSend && pendingSendRef.current) {
+ steerParkedSend({
+ parkedBehindResponse,
+ otherHoldActive:
+ threadScopedSettingsPending ||
+ hasMaterializingImageAttachments ||
+ hasMaterializingAudioAttachments ||
+ hasMaterializingVideoAttachments,
+ promptQueueActive: livePromptQueueActive || hasPendingQueueStart(),
+ researchActive: isResearchActive,
+ threadRunning: liveThreadIsRunning,
+ });
+ }
return;
}
const { text, attachments } = aui.composer().getState();
@@ -5459,6 +5508,8 @@ const Composer: FC<{
queueComposerText,
queueTextAttachmentsPrompt,
sendReservedComposer,
+ steerParkedSend,
+ hasPendingQueueStart,
preStreamThreadIds,
disableQueue,
isResearchActive,
@@ -5765,14 +5816,7 @@ const Composer: FC<{
threadIsRunning || aui.thread().getState().isRunning;
const livePromptQueueActive =
promptQueueActive ||
- hasPendingPromptQueueStart(
- promptQueueStartPendingRef.current.values(),
- referenceThreadId,
- ) ||
- hasPendingPromptQueueStart(
- pastedTextQueuePendingRef.current.values(),
- referenceThreadId,
- ) ||
+ hasPendingQueueStart() ||
Boolean(
findPromptQueueEntry(
usePromptQueueUI.getState(),
@@ -5805,6 +5849,14 @@ const Composer: FC<{
}
if (canQueueAttachmentPrompt) {
enqueueSend("running");
+ // A repeat press does not re-run the release effect.
+ steerParkedSend({
+ parkedBehindResponse: true,
+ otherHoldActive: false,
+ promptQueueActive: livePromptQueueActive,
+ researchActive: isResearchActive,
+ threadRunning: liveThreadIsRunning,
+ });
return;
}
if (overlay || hasAttachments || hasPendingAudio) {
@@ -5916,6 +5968,8 @@ const Composer: FC<{
setPendingImageEditReference,
sendReservedComposer,
shouldBlockSend,
+ steerParkedSend,
+ hasPendingQueueStart,
threadIsRunning,
],
);
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index 138ec88b97f..738dd4d8674 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -668,10 +668,12 @@ export {
effectiveSendShortcut,
followUpSubmitIntent,
imeKeydownBlocksComposerSubmit,
+ parkedSendSteer,
steeringInsertionIndex,
type ComposerSendShortcut,
type ComposerFollowUpBehavior,
type ComposerSubmitIntent,
+ type ParkedSendSteerState,
} from "./utils/composer-preferences";
export { isTextAttachmentName } from "./text-attachment-accept";
diff --git a/studio/frontend/src/features/chat/utils/composer-preferences.ts b/studio/frontend/src/features/chat/utils/composer-preferences.ts
index e99677dbe98..505c264406e 100644
--- a/studio/frontend/src/features/chat/utils/composer-preferences.ts
+++ b/studio/frontend/src/features/chat/utils/composer-preferences.ts
@@ -203,3 +203,30 @@ export function steeringInsertionIndex(
const index = Math.max(0, runIndex);
return Math.min(items.length, index + (items[index]?.dispatched ? 1 : 0));
}
+
+export type ParkedSendSteerState = {
+ behavior: ComposerFollowUpBehavior;
+ /** held behind a response, queue or pre-stream send. */
+ parkedBehindResponse: boolean;
+ /** an upload or chat settings still hold the send. */
+ otherHoldActive: boolean;
+ promptQueueActive: boolean;
+ researchActive: boolean;
+ threadRunning: boolean;
+};
+
+/** Binary attachments cannot be queued, so steer cancels the response instead; null keeps waiting. */
+export function parkedSendSteer(
+ state: ParkedSendSteerState,
+): { cancelRun: boolean } | null {
+ if (
+ state.behavior !== "steer" ||
+ !state.parkedBehindResponse ||
+ state.otherHoldActive ||
+ state.promptQueueActive ||
+ state.researchActive
+ ) {
+ return null;
+ }
+ return { cancelRun: state.threadRunning };
+}
diff --git a/studio/frontend/tests/composer-preferences.test.ts b/studio/frontend/tests/composer-preferences.test.ts
index 2a9ba0e130d..f0d4230e42e 100644
--- a/studio/frontend/tests/composer-preferences.test.ts
+++ b/studio/frontend/tests/composer-preferences.test.ts
@@ -8,6 +8,7 @@ import {
effectiveSendShortcut,
followUpSubmitIntent,
normalizeComposerPreferences,
+ parkedSendSteer,
type ComposerKeyEvent,
} from "../src/features/chat/utils/composer-preferences.ts";
import { installLocalStorageFake } from "./helpers/kit.ts";
@@ -238,3 +239,12 @@ test("sharing switched on by another window's rehydrate still adopts this tab's
assert.equal(prefs.getState().shareComposerDraft, true);
assert.equal(drafts.latestDraft(drafts.composerDraftKey("", true)), "typed here");
});
+
+test("steering a parked attachment stops the response only when nothing else holds it", () => {
+ const parked = { behavior: "steer" as const, parkedBehindResponse: true, otherHoldActive: false, promptQueueActive: false, researchActive: false, threadRunning: true };
+ assert.deepEqual(parkedSendSteer(parked), { cancelRun: true });
+ assert.deepEqual(parkedSendSteer({ ...parked, threadRunning: false }), { cancelRun: false });
+ for (const hold of [{ behavior: "queue" as const }, { promptQueueActive: true }, { researchActive: true }, { parkedBehindResponse: false }, { otherHoldActive: true }]) {
+ assert.equal(parkedSendSteer({ ...parked, ...hold }), null);
+ }
+});
diff --git a/studio/frontend/tests/composer-submit-path.test.ts b/studio/frontend/tests/composer-submit-path.test.ts
index d5d01114e06..e0c9cbb12e6 100644
--- a/studio/frontend/tests/composer-submit-path.test.ts
+++ b/studio/frontend/tests/composer-submit-path.test.ts
@@ -6,6 +6,7 @@ import {
composerKeyEventForImeSubmit,
composerSubmitIntent,
imeKeydownBlocksComposerSubmit,
+ parkedSendSteer,
} from "../src/features/chat/utils/composer-preferences.ts";
const text = readSrc("components/assistant-ui/thread.tsx");
@@ -53,6 +54,11 @@ const reservedSendCallback = lift(
n.getText(source).startsWith("(...alsoGuard: string[]) =>") &&
n.getText(source).includes("reservePreStreamRun"),
);
+const steerParkedSendCallback = lift(
+ (n) =>
+ ts.isArrowFunction(n) &&
+ n.getText(source).startsWith("(state: Omit<ParkedSendSteerState"),
+);
function createCallback(
code: string,
deps: Record<string, unknown>,
@@ -221,15 +227,21 @@ for (const active of ["runtime", "pre-stream", "queue", "idle"]) {
});
}
-for (const active of ["runtime", "pre-stream", "queue"]) {
- test(`a queued attachment stays parked through ${active} state and sends once (#9210)`, () => {
+for (const [active, behavior] of ["runtime", "pre-stream", "queue"].flatMap(
+ (a) => [
+ [a, "queue"],
+ [a, "steer"],
+ ],
+)) {
+ test(`a ${behavior} attachment stays parked through ${active} state and sends once (#9210)`, () => {
const calls: string[] = [];
const state = { active: true };
const pendingSendRef = { current: true };
+ const pendingFollowUpBehaviorRef = { current: behavior };
const deps = {
pendingSend: true,
pendingSendRef,
- pendingFollowUpBehaviorRef: { current: "queue" },
+ pendingFollowUpBehaviorRef,
indexingActive: false,
threadScopedSettingsPending: false,
threadIsRunning: false,
@@ -246,6 +258,7 @@ for (const active of ["runtime", "pre-stream", "queue"]) {
getState: () => ({
isRunning: state.active && active === "runtime",
}),
+ cancelRun: () => calls.push("cancel-run") && (state.active = false),
}),
},
setPendingSend: () => undefined,
@@ -254,6 +267,7 @@ for (const active of ["runtime", "pre-stream", "queue"]) {
preStreamThreadIds: ["own-chat"],
isResearchActive: false,
findPromptQueueEntry: () => state.active && active === "queue",
+ hasPendingQueueStart: () => false,
usePromptQueueUI: { getState: () => ({}) },
disableQueue: false,
canQueueCurrentPrompt: false,
@@ -267,14 +281,29 @@ for (const active of ["runtime", "pre-stream", "queue"]) {
sendReservedComposer: () => calls.push("send"),
toast: { error: () => calls.push("error") },
};
- const release = createCallback(releaseCallback, deps);
+ const steerParkedSend = createCallback(steerParkedSendCallback, {
+ ...deps,
+ parkedSendSteer,
+ cancelPreStreamRunForThreadIds: () => calls.push("cancel-pre-stream"),
+ });
+ const release = createCallback(releaseCallback, {
+ ...deps,
+ steerParkedSend,
+ });
release();
- assert.deepEqual(calls, []);
+ // queued prompts stay ahead of the image.
+ const cancels =
+ behavior === "queue" || active === "queue"
+ ? []
+ : active === "runtime"
+ ? ["cancel-pre-stream", "cancel-run"]
+ : ["cancel-pre-stream"];
+ assert.deepEqual(calls, cancels);
assert.equal(pendingSendRef.current, true);
state.active = false;
release();
release();
- assert.deepEqual(calls, ["dismiss", "clear", "send"]);
+ assert.deepEqual(calls, [...cancels, "dismiss", "clear", "send"]);
});
}