Skip to content

Commit 96dab59

Browse files
fix: a message you send resumes a held queue, and mobile can resume one
A stop or a restart holds the thread's queue until someone presses Resume. Sending a new message started a run but left the hold in place, and every subagent completion that queued behind that run inherited it, so an orchestrating thread stopped hearing from its subagents for good. Mobile had no way out: its queue sheet lists only the user's own messages, so a queue holding only completion wakes showed nothing to resume. A message the user sends from a client now releases the hold, so what was held follows it. Server continuations after a usage limit or a restart do not, and a missing worktree keeps its hold. Mobile's empty composer shows Resume while the queue is held, as web's does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ab6be13 commit 96dab59

5 files changed

Lines changed: 136 additions & 12 deletions

File tree

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ import {
5858
useComposerDraft,
5959
} from "../../state/use-composer-drafts";
6060
import { appAtomRegistry } from "../../state/atom-registry";
61+
import { threadEnvironment } from "../../state/threads";
62+
import { useAtomCommand } from "../../state/use-atom-command";
63+
import { useThreadQueueWorkflow } from "./ThreadQueueControl";
6164
import type { ComposerDocumentAttachment } from "../../lib/composerContext";
6265
import { useProject, useThreadShells } from "../../state/entities";
6366
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
@@ -357,6 +360,25 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
357360
(queuedEdit?.existingAttachments.length ?? 0) > 0;
358361
const stripAttachments = composerStripAttachments(draftAttachments);
359362
const showStopAction = !hasContent && props.canStopThread && queuedEdit === null;
363+
// A stop or a restart holds the queue, completion wakes included, until it
364+
// is resumed; the queue sheet lists only the user's own messages.
365+
const queueWorkflow = useThreadQueueWorkflow({
366+
environmentId: props.environmentId,
367+
threadId: props.selectedThread.id,
368+
});
369+
const resumeQueue = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
370+
const [resumingQueue, setResumingQueue] = useState(false);
371+
const showResumeAction =
372+
!hasContent && !showStopAction && queuedEdit === null && queueWorkflow?.isHeld === true;
373+
const handleResumeQueue = async () => {
374+
if (resumingQueue) return;
375+
setResumingQueue(true);
376+
await resumeQueue({
377+
environmentId: props.environmentId,
378+
input: { threadId: props.selectedThread.id },
379+
});
380+
setResumingQueue(false);
381+
};
360382

361383
const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
362384
const attachmentsUploading =
@@ -955,6 +977,13 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
955977
disabled={!props.canOperateThread}
956978
onPress={props.onStopThread}
957979
/>
980+
) : showResumeAction ? (
981+
<ComposerActionButton
982+
accessibilityLabel="Resume queue"
983+
icon="play"
984+
disabled={!props.canOperateThread || resumingQueue}
985+
onPress={() => void handleResumeQueue()}
986+
/>
958987
) : (
959988
<SendActionButton
960989
accessibilityLabel={sendBlockedReason ?? sendLabel}
@@ -1050,6 +1079,13 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
10501079
disabled={!props.canOperateThread}
10511080
onPress={props.onStopThread}
10521081
/>
1082+
) : showResumeAction && voicePresentation.showsSend ? (
1083+
<ComposerActionButton
1084+
accessibilityLabel="Resume queue"
1085+
icon="play"
1086+
disabled={!props.canOperateThread || resumingQueue}
1087+
onPress={() => void handleResumeQueue()}
1088+
/>
10531089
) : voicePresentation.showsSend ? (
10541090
<SendActionButton
10551091
accessibilityLabel={sendBlockedReason ?? sendLabel}

‎apps/mobile/src/features/threads/ThreadQueueControl.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
189189
>
190190
{workflow?.isHeld && queuedRuns.length > 0 ? (
191191
<View className="gap-2 py-3">
192-
<Text className="text-sm text-foreground-muted">Queue held after restart</Text>
192+
<Text className="text-sm text-foreground-muted">Queue paused</Text>
193193
<Button
194194
label="Resume queue"
195195
disabled={resuming || busyRunId !== null}

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,11 +4999,38 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
49994999
: undefined;
50005000
const queueBehindRun = activeRun ?? worktreeMissingRun;
50015001
const pendingMergeBackTransfers = pendingMergeBackTransfersForThread(projection);
5002-
const shouldQueue =
5003-
queueBehindRun !== undefined &&
5004-
(dispatchMode.type === "defer_start" ||
5005-
dispatchMode.type === "start_immediately" ||
5006-
dispatchMode.type === "queue_after_active");
5002+
const startsOrQueuesRun =
5003+
dispatchMode.type === "defer_start" ||
5004+
dispatchMode.type === "start_immediately" ||
5005+
dispatchMode.type === "queue_after_active";
5006+
const shouldQueue = queueBehindRun !== undefined && startsOrQueuesRun;
5007+
// A message the user sends from a client means they are back, so what a
5008+
// stop or a restart held follows it rather than waiting for a Resume.
5009+
// Continuations the server sends for them (after a usage limit or a
5010+
// restart) are not them coming back. Starting the queue still re-holds
5011+
// it for a failed provider or a usage limit; a missing worktree keeps its
5012+
// hold, since its messages would start in the project checkout.
5013+
const sentByUserFromClient =
5014+
command.createdBy === "user" &&
5015+
(command.creationSource === "web" || command.creationSource === "mobile");
5016+
const heldRunsToRelease =
5017+
sentByUserFromClient && startsOrQueuesRun && worktreeMissingRun === undefined
5018+
? projection.runs.filter((run) => run.status === "queued" && run.queueHeld === true)
5019+
: [];
5020+
const releasedAt = yield* DateTime.now;
5021+
for (const held of heldRunsToRelease) {
5022+
yield* emit(
5023+
events,
5024+
command,
5025+
)({
5026+
type: "run.updated",
5027+
threadId: command.threadId,
5028+
runId: held.id,
5029+
providerInstanceId: held.providerInstanceId,
5030+
occurredAt: releasedAt,
5031+
payload: { ...held, queueHeld: false },
5032+
});
5033+
}
50075034
if (shouldQueue) {
50085035
if (pendingMergeBackTransfers.length > 0) {
50095036
return yield* new OrchestratorDispatchError({
@@ -5113,9 +5140,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
51135140
activeAttemptId: attemptId,
51145141
status: "queued",
51155142
...(worktreeMissingRun !== undefined ||
5116-
projection.runs.some(
5117-
(candidate) => candidate.status === "queued" && candidate.queueHeld === true,
5118-
)
5143+
(heldRunsToRelease.length === 0 &&
5144+
projection.runs.some(
5145+
(candidate) => candidate.status === "queued" && candidate.queueHeld === true,
5146+
))
51195147
? { queueHeld: true }
51205148
: {}),
51215149
queuePosition:

‎apps/server/src/orchestration-v2/ThreadStop.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,65 @@ it.effect.each(["thread.stop", "run.interrupt"] as const)(
538538
}).pipe(Effect.provide(layerTest)),
539539
);
540540

541+
it.effect("a message the user sends after Stop releases the held queue; an agent's does not", () =>
542+
Effect.gen(function* () {
543+
const orchestrator = yield* Orchestrator.OrchestratorV2;
544+
const projections = yield* ProjectionStore.ProjectionStoreV2;
545+
const threadId = ThreadId.make("thread:stop-release");
546+
const agentSend = (text: string) =>
547+
orchestrator.dispatch({
548+
type: "message.dispatch",
549+
commandId: CommandId.make(`agent-send:${text}`),
550+
threadId,
551+
messageId: MessageId.make(`message:${threadId}:${text}`),
552+
text,
553+
attachments: [],
554+
dispatchMode: { type: "queue_after_active" },
555+
createdBy: "agent",
556+
creationSource: "mcp",
557+
});
558+
yield* createWatchingThread(threadId, 6);
559+
yield* send(threadId, "active", "start_immediately");
560+
yield* send(threadId, "queued before the stop", "queue_after_active");
561+
yield* orchestrator.dispatch({
562+
type: "thread.stop",
563+
commandId: CommandId.make("stop-release"),
564+
threadId,
565+
});
566+
assert.deepEqual((yield* threadState(threadId)).runs, ["interrupted", "queued:held"]);
567+
568+
// An agent's message starts on the idle thread, but the hold is the user's.
569+
yield* agentSend("agent nudge");
570+
assert.deepEqual((yield* threadState(threadId)).runs, [
571+
"interrupted",
572+
"queued:held",
573+
"starting",
574+
]);
575+
const nudge = (yield* orchestrator.getThreadProjection(threadId)).runs.at(-1)!;
576+
const now = yield* DateTime.now;
577+
yield* projections.apply({
578+
id: EventId.make("event:stop-release:nudge-completed"),
579+
type: "run.updated",
580+
threadId,
581+
runId: nudge.id,
582+
occurredAt: now,
583+
payload: { ...nudge, status: "completed", completedAt: now },
584+
});
585+
586+
// The user is back: the held message follows their run, and a wake that
587+
// queues behind it is not held by the old Stop.
588+
yield* send(threadId, "back", "start_immediately");
589+
yield* agentSend("task finished");
590+
assert.deepEqual((yield* threadState(threadId)).runs, [
591+
"interrupted",
592+
"queued",
593+
"completed",
594+
"starting",
595+
"queued",
596+
]);
597+
}).pipe(Effect.provide(layerTest)),
598+
);
599+
541600
it.effect(
542601
"thread.stop ends an idle thread's watches and accepts a thread with nothing to stop",
543602
() =>

‎docs/user/composer.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ Queued messages appear above the composer. Rows show a thumbnail of any attached
206206
the text. Drag a row by its handle to reorder it, use the handle's arrow keys, promote the message
207207
to a steer, or remove it.
208208

209-
If the server restarts, saved queued messages keep their order and are held. Press
210-
**Resume** in an empty composer on web or desktop, or **Resume queue** in the queue
211-
sheet on mobile, to continue. You can edit, reorder, or remove held messages without starting them.
209+
If you stop the agent or the server restarts, queued messages keep their order and are held,
210+
along with results from subagents that finish meanwhile. Press **Resume** in an empty composer to
211+
continue. Sending a new message also resumes the queue: held messages run after it. You can edit,
212+
reorder, or remove held messages without starting them.
212213

213214
The pencil on a queued row opens that message in the composer for editing. The original message
214215
stays in the queue until you save, and its row is highlighted while you edit. The message's

0 commit comments

Comments
 (0)