Skip to content

Commit 33cec46

Browse files
feat: pause a thread's queue without stopping the run under way
A new queue.hold command marks the queued runs as held; the existing queue.resume releases them. The queue banner above the composer has the button. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f780dc2 commit 33cec46

6 files changed

Lines changed: 88 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ function commandThreadId(command: OrchestrationV2ServerCommand): ThreadId {
470470
case "run.interrupt":
471471
case "queued-message.promote-to-steer":
472472
case "queue.resume":
473+
case "queue.hold":
473474
case "queued-run.reorder":
474475
case "queued-run.cancel":
475476
case "queued-run.edit":
@@ -10807,6 +10808,35 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1080710808
}
1080810809
break;
1080910810
}
10811+
case "queue.hold": {
10812+
const projection = yield* loadProjectionForCommand(command, ["runs"]);
10813+
const waiting = projection.runs.filter(
10814+
(run) => run.status === "queued" && run.queueHeld !== true,
10815+
);
10816+
// The hold lives on the queued runs, so there must be one to carry it.
10817+
if (waiting.length === 0 && !projection.runs.some((run) => run.status === "queued")) {
10818+
return yield* new OrchestratorDispatchError({
10819+
commandId: command.commandId,
10820+
commandType: command.type,
10821+
cause: "Nothing is queued in this thread.",
10822+
});
10823+
}
10824+
const now = yield* DateTime.now;
10825+
for (const run of waiting) {
10826+
yield* emit(
10827+
events,
10828+
command,
10829+
)({
10830+
type: "run.updated",
10831+
threadId: command.threadId,
10832+
runId: run.id,
10833+
providerInstanceId: run.providerInstanceId,
10834+
occurredAt: now,
10835+
payload: { ...run, queueHeld: true },
10836+
});
10837+
}
10838+
break;
10839+
}
1081010840
case "queued-run.reorder":
1081110841
yield* dispatchQueuedRunReorder(command, events);
1081210842
break;

‎apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function commandThreadIds(command: OrchestrationV2Command): ReadonlyArray<Thread
170170
case "run.interrupt":
171171
case "queued-message.promote-to-steer":
172172
case "queue.resume":
173+
case "queue.hold":
173174
case "queued-run.reorder":
174175
case "queued-run.cancel":
175176
case "queued-run.edit":

‎apps/web/src/components/chat/QueuedRunsControl.tsx‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function QueuedRunsControl({
7070
const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun);
7171
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun);
7272
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun);
73+
const holdQueue = useAtomCommand(threadEnvironment.holdThreadQueue, "pause queue");
74+
const resumeQueue = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
7375
const [expanded, setExpanded] = useState(true);
7476
const queueListId = useId();
7577
const [busyRunId, setBusyRunId] = useState<RunId | null>(null);
@@ -89,6 +91,7 @@ export function QueuedRunsControl({
8991
const queued = workflow?.queuedRuns ?? [];
9092
const activeRun = workflow?.activeRun ?? null;
9193
const canReorder = workflow?.canReorder === true;
94+
const queueHeld = workflow?.isHeld === true;
9295
const queuedImageAttachmentIds = useMemo(() => {
9396
const ids: string[] = [];
9497
for (const { attachments } of workflow?.queuedRuns ?? []) {
@@ -263,14 +266,39 @@ export function QueuedRunsControl({
263266
<ComposerBanner.Icon>
264267
<ListOrderedIcon />
265268
</ComposerBanner.Icon>
266-
<ComposerBanner.Content className="text-muted-foreground">Queued</ComposerBanner.Content>
269+
<ComposerBanner.Content className="text-muted-foreground">
270+
{queueHeld ? "Queued, paused" : "Queued"}
271+
</ComposerBanner.Content>
267272
<ComposerBanner.Actions>
268273
<ComposerBanner.Count>{items.length}</ComposerBanner.Count>
269274
<ComposerBanner.ToggleIcon expanded={expanded} />
270275
</ComposerBanner.Actions>
271276
</ComposerBanner.Row>
272277
<ComposerBanner.Scroll className={cn("max-h-32", !expanded && "hidden")}>
273278
<ComposerBanner.Children render={<ol />} id={queueListId}>
279+
{queued.length > 0 ? (
280+
<ComposerBanner.Row render={<li />}>
281+
<ComposerBanner.Content className="text-muted-foreground">
282+
{queueHeld
283+
? "Nothing here starts until you resume."
284+
: "Pausing lets the current run finish and holds the rest."}
285+
</ComposerBanner.Content>
286+
<ComposerBanner.Actions>
287+
<Button
288+
size="xs"
289+
variant="ghost"
290+
onClick={() =>
291+
void (queueHeld ? resumeQueue : holdQueue)({
292+
environmentId: props.environmentId,
293+
input: { threadId: props.threadId },
294+
})
295+
}
296+
>
297+
{queueHeld ? "Resume queue" : "Pause queue"}
298+
</Button>
299+
</ComposerBanner.Actions>
300+
</ComposerBanner.Row>
301+
) : null}
274302
{items.map((item) => {
275303
const previewText = replaceComposerContextReferences(item.text, (reference) =>
276304
reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,

‎packages/client-runtime/src/operations/commands.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,17 @@ export const resumeThreadQueue = Effect.fn("EnvironmentCommands.resumeThreadQueu
990990
});
991991
});
992992

993+
/** Holds the queue and lets the run under way finish. `resumeThreadQueue` releases it. */
994+
export const holdThreadQueue = Effect.fn("EnvironmentCommands.holdThreadQueue")(function* (
995+
input: ThreadCommandInput,
996+
) {
997+
return yield* dispatch({
998+
type: "queue.hold",
999+
commandId: yield* allocateCommandId(input),
1000+
threadId: input.threadId,
1001+
});
1002+
});
1003+
9931004
export const reorderQueuedRun = Effect.fn("EnvironmentCommands.reorderQueuedRun")(function* (
9941005
input: ReorderQueuedRunInput,
9951006
) {

‎packages/client-runtime/src/state/threadCommands.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
mergeThreadBack,
6666
promoteQueuedRun,
6767
reorderQueuedRun,
68+
holdThreadQueue,
6869
resumeThreadQueue,
6970
retryWorkspacePreparation,
7071
linkThreadPullRequest,
@@ -342,6 +343,12 @@ export function createThreadEnvironmentAtoms<R, E>(
342343
scheduler,
343344
concurrency,
344345
}),
346+
holdThreadQueue: createEnvironmentCommand(runtime, {
347+
label: "environment-data:commands:thread:hold-queue",
348+
execute: (input: ThreadCommandInput) => holdThreadQueue(input),
349+
scheduler,
350+
concurrency,
351+
}),
345352
reorderQueuedRun: createEnvironmentCommand(runtime, {
346353
label: "environment-data:commands:thread:reorder-queued-run",
347354
execute: (input: ReorderQueuedRunInput) => reorderQueuedRun(input),

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,16 @@ export const OrchestrationV2Command = Schema.Union([
29502950
commandId: CommandId,
29512951
threadId: ThreadId,
29522952
}),
2953+
/**
2954+
* Holds the thread's queue without touching the run under way: it finishes,
2955+
* and nothing queued starts until `queue.resume`. Stop holds the queue too,
2956+
* but also ends the current run.
2957+
*/
2958+
Schema.Struct({
2959+
type: Schema.Literal("queue.hold"),
2960+
commandId: CommandId,
2961+
threadId: ThreadId,
2962+
}),
29532963
Schema.Struct({
29542964
type: Schema.Literal("queued-run.reorder"),
29552965
commandId: CommandId,

0 commit comments

Comments
 (0)