@devries-cameron20 / t3code Mirror · read-only / commits / a54a44c669
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 08:00 UTC

fix(orchestration): queue follow-ups sent while a thread compacts (#20184)

maria committed Oct 16, 2026 at 19:14 UTC a54a44c6693460ac5c2a8529bbe6f9d0931c6477
11 files changed +123 -29
apps/mobile/src/state/use-thread-composer-state.ts
+2 -1
@@ -307,7 +307,6 @@ export function useThreadComposerState() {
307 ? EMPTY_QUEUE_WORKFLOW_ATOM
308 : environmentThreadDetails.queueWorkflowAtom(selectedThreadDetailRef),
309 );
310 - const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true;
310 const queuedRunEdit = useQueuedRunEdit(selectedThreadKey);
311 const composerDraftKey =
312 selectedThreadKey === null
@@ -394,6 +393,8 @@ export function useThreadComposerState() {
393 selectedThreadRuntime,
394 selectedThreadVisibleTurnItems,
395 ]);
396 + // A compacting turn cannot take steering input, so follow-ups queue meanwhile.
397 + const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !isCompacting;
398
399 const runlessWorkStartedAt = useMemo(
400 () =>
apps/server/src/orchestration-v2/CommandPolicy.test.ts
+37 -1
@@ -1,6 +1,7 @@
1 import { assert, it } from "@effect/vitest";
2 import {
3 CommandId,
4 + MessageId,
5 type OrchestrationV2ProviderCapabilities,
6 type OrchestrationV2ThreadProjection,
7 ProviderInstanceId,
@@ -19,6 +20,7 @@ import * as CommandPolicy from "./CommandPolicy.ts";
20 const commandId = CommandId.make("command-policy-test");
21 const threadId = ThreadId.make("command-policy-thread");
22 const activeRunId = RunId.make("command-policy-active-run");
23 +const userMessageId = MessageId.make("command-policy-user-message");
24
25 const baseCapabilities: OrchestrationV2ProviderCapabilities = CodexProviderCapabilitiesV2;
26
@@ -37,7 +39,8 @@ function dispatchProjection(
39 runs:
40 sessionCapabilities === undefined
41 ? []
40 - : [{ id: activeRunId, status: "running", providerThreadId }],
42 + : [{ id: activeRunId, status: "running", providerThreadId, userMessageId }],
43 + messages: [{ id: userMessageId, text: "first", attachments: [] }],
44 providerThreads:
45 sessionCapabilities === undefined ? [] : [{ id: providerThreadId, providerSessionId }],
46 providerSessions:
@@ -141,6 +144,39 @@ it("targets the latest active run for explicit steer and restart intent", () =>
144 );
145 });
146
147 +it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) => {
148 + const projection = dispatchProjection(baseCapabilities);
149 + const maintenance = {
150 + ...projection,
151 + messages: [{ id: userMessageId, text, attachments: [] }],
152 + } as unknown as OrchestrationV2ThreadProjection;
153 + for (const deliveryIntent of ["auto", "steer"] as const) {
154 + assert.deepEqual(
155 + CommandPolicy.resolveMessageDispatchIntent(
156 + maintenance,
157 + { type: "start_immediately" },
158 + deliveryIntent,
159 + ),
160 + { type: "queue_after_active" },
161 + );
162 + }
163 + assert.deepEqual(
164 + CommandPolicy.resolveMessageDispatchIntent(maintenance, {
165 + type: "steer_active",
166 + targetRunId: activeRunId,
167 + }),
168 + { type: "queue_after_active" },
169 + );
170 + assert.deepEqual(
171 + CommandPolicy.resolveMessageDispatchIntent(
172 + maintenance,
173 + { type: "start_immediately" },
174 + "restart",
175 + ),
176 + { type: "restart_active", targetRunId: activeRunId },
177 + );
178 +});
179 +
180 const layer = it.layer(CommandPolicy.layer);
181
182 layer("CommandPolicyV2", (it) => {
apps/server/src/orchestration-v2/CommandPolicy.ts
+28
@@ -1,4 +1,5 @@
1 import {
2 + type ChatAttachment,
3 CommandId,
4 ModelSelection,
5 type OrchestrationV2Command,
@@ -116,10 +117,37 @@ type MessageDispatchMode = Extract<
117 { readonly type: "message.dispatch" }
118 >["dispatchMode"];
119
120 +export function isNativeMaintenanceCommand(message: {
121 + readonly text: string;
122 + readonly attachments: ReadonlyArray<ChatAttachment>;
123 + readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
124 +}): boolean {
125 + return (
126 + message.attachments.length === 0 &&
127 + ["/compact", "/logout"].includes(message.text.trim().toLowerCase())
128 + );
129 +}
130 +
131 export function resolveMessageDispatchIntent(
132 projection: OrchestrationV2ThreadProjection,
133 requestedMode: MessageDispatchMode,
134 deliveryIntent?: "auto" | "steer" | "restart",
135 +): MessageDispatchMode {
136 + const mode = resolveDeliveryIntent(projection, requestedMode, deliveryIntent);
137 + if (mode.type !== "steer_active") return mode;
138 + // Compaction and sign-out turns cannot take steering input. A message sent
139 + // while one runs waits in the queue like any other follow-up.
140 + const target = projection.runs.find((run) => run.id === mode.targetRunId);
141 + const targetMessage = projection.messages.find((message) => message.id === target?.userMessageId);
142 + return targetMessage !== undefined && isNativeMaintenanceCommand(targetMessage)
143 + ? { type: "queue_after_active" }
144 + : mode;
145 +}
146 +
147 +function resolveDeliveryIntent(
148 + projection: OrchestrationV2ThreadProjection,
149 + requestedMode: MessageDispatchMode,
150 + deliveryIntent?: "auto" | "steer" | "restart",
151 ): MessageDispatchMode {
152 if (deliveryIntent === undefined) return requestedMode;
153
apps/server/src/orchestration-v2/Orchestrator.ts
+5 -12
@@ -84,7 +84,11 @@ import {
84 SHARED_WORKSPACE_RESTORE_MESSAGE,
85 } from "./CheckpointRestoreSafety.ts";
86 import { CheckpointServiceV2 } from "./CheckpointService.ts";
87 -import { CommandPolicyV2, resolveMessageDispatchIntent } from "./CommandPolicy.ts";
87 +import {
88 + CommandPolicyV2,
89 + isNativeMaintenanceCommand,
90 + resolveMessageDispatchIntent,
91 +} from "./CommandPolicy.ts";
92 import { CommandReceiptStoreV2 } from "./CommandReceiptStore.ts";
93 import { ContextHandoffServiceV2 } from "./ContextHandoffService.ts";
94 import { notificationTurnItem } from "@t3tools/provider-core/server/notification";
@@ -404,17 +408,6 @@ function wakeWorkStartedAt(
408 return previous === undefined ? {} : { workStartedAt: orchestrationV2RunWorkStartedAt(previous) };
409 }
410
407 -export function isNativeMaintenanceCommand(message: {
408 - readonly text: string;
409 - readonly attachments: ReadonlyArray<ChatAttachment>;
410 - readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
411 -}): boolean {
412 - return (
413 - message.attachments.length === 0 &&
414 - ["/compact", "/logout"].includes(message.text.trim().toLowerCase())
415 - );
416 -}
417 -
411 function isGoalCommand(message: {
412 readonly text: string;
413 readonly attachments: ReadonlyArray<ChatAttachment>;
apps/server/src/orchestration-v2/RestartContinuation.ts
+1 -1
@@ -13,7 +13,7 @@ import * as Effect from "effect/Effect";
13 import type { ProjectionRuntimeRecoveryState } from "./ProjectionStore.ts";
14
15 import * as ServerSettings from "../serverSettings.ts";
16 -import { isNativeMaintenanceCommand } from "./Orchestrator.ts";
16 +import { isNativeMaintenanceCommand } from "./CommandPolicy.ts";
17 import * as ThreadManagementService from "./ThreadManagementService.ts";
18 import {
19 cancelledRosterTaskWork,
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+20 -13
@@ -755,19 +755,26 @@ it.effect("keeps native maintenance commands out of steering and restart message
755 const targetRun = before.runs[0];
756 if (targetRun === undefined) return yield* Effect.die("Launch must create a run");
757 const commandId = CommandId.make(`${scenario.name}:message`);
758 - const failure = yield* threads
759 - .dispatch({
760 - type: "message.dispatch",
761 - commandId,
762 - threadId: launched.threadId,
763 - messageId: MessageId.make(`${scenario.name}:message`),
764 - createdBy: "user",
765 - creationSource: "web",
766 - text: scenario.next,
767 - attachments: [],
768 - dispatchMode: { type: scenario.mode, targetRunId: targetRun.id },
769 - })
770 - .pipe(Effect.flip);
758 + const dispatch = threads.dispatch({
759 + type: "message.dispatch",
760 + commandId,
761 + threadId: launched.threadId,
762 + messageId: MessageId.make(`${scenario.name}:message`),
763 + createdBy: "user",
764 + creationSource: "web",
765 + text: scenario.next,
766 + attachments: [],
767 + dispatchMode: { type: scenario.mode, targetRunId: targetRun.id },
768 + });
769 + // A steer sent while a maintenance turn runs waits as a queued follow-up.
770 + if (scenario.name.startsWith("steer-")) {
771 + yield* dispatch;
772 + const queued = (yield* threads.getThreadProjection(launched.threadId)).runs[1];
773 + assert.equal(queued?.status, "queued");
774 + assert.equal(queued?.userMessageId, MessageId.make(`${scenario.name}:message`));
775 + continue;
776 + }
777 + const failure = yield* dispatch.pipe(Effect.flip);
778 assert.include(
779 String(failure.cause).toLowerCase(),
780 scenario.name.includes("logout") ? "sign" : "context compaction",
apps/web/src/components/ChatView.tsx
+1
@@ -11192,6 +11192,7 @@ export default function ChatView(props: ChatViewProps) {
11192 isLocalDraftThread && activeProject === null
11193 }
11194 phase={phase}
11195 + isCompacting={isCompacting}
11196 canInterrupt={canInterruptRunningThread}
11197 isConnecting={isConnecting}
11198 isSendBusy={
apps/web/src/components/chat/ChatComposer.tsx
+9
@@ -1354,6 +1354,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
1354 isRunning: boolean;
1355 canInterrupt: boolean;
1356 followUpBehavior: "queue" | "steer";
1357 + canSteer: boolean;
1358 alternateShortcutLabel: string | null;
1359 showPlanFollowUpPrompt: boolean;
1360 promptHasText: boolean;
@@ -1397,6 +1398,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
1398 isRunning={props.isRunning}
1399 canInterrupt={props.canInterrupt}
1400 followUpBehavior={props.followUpBehavior}
1401 + canSteer={props.canSteer}
1402 alternateShortcutLabel={props.alternateShortcutLabel}
1403 showPlanFollowUpPrompt={props.showPlanFollowUpPrompt}
1404 promptHasText={props.promptHasText}
@@ -1516,6 +1518,7 @@ export interface ChatComposerProps {
1518 isRevertingCheckpoint?: boolean;
1519 sendDisabledReason: string | null;
1520 isPreparingWorktree: boolean;
1521 + isCompacting: boolean;
1522 bannerItems: readonly ComposerBannerStackItem[];
1523 resumeCompactionTokens: number | null;
1524 keepFullHistory: boolean;
@@ -1676,6 +1679,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
1679 isRevertingCheckpoint = false,
1680 sendDisabledReason: externalSendDisabledReason,
1681 isPreparingWorktree,
1682 + isCompacting,
1683 environmentUnavailable,
1684 activePendingApproval: incomingPendingApproval,
1685 pendingApprovals,
@@ -4023,6 +4027,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4027 running: phase === "running",
4028 alternateModifier: false,
4029 activeTurnDefault: settings.followUpBehavior,
4030 + canSteer: !isCompacting,
4031 }),
4032 submissionIntent,
4033 );
@@ -4045,6 +4050,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4050 running: phase === "running",
4051 alternateModifier: event.metaKey || event.ctrlKey,
4052 activeTurnDefault: settings.followUpBehavior,
4053 + canSteer: !isCompacting,
4054 }),
4055 );
4056 };
@@ -4056,6 +4062,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4062 running: phase === "running",
4063 alternateModifier: false,
4064 activeTurnDefault: settings.followUpBehavior,
4065 + canSteer: !isCompacting,
4066 }),
4067 );
4068 };
@@ -4216,6 +4223,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4223 running: phase === "running",
4224 alternateModifier: submissionIntent === "alternate",
4225 activeTurnDefault: settings.followUpBehavior,
4226 + canSteer: !isCompacting,
4227 }),
4228 submissionIntent,
4229 );
@@ -7282,6 +7290,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
7290 isRunning={phase === "running"}
7291 canInterrupt={canInterrupt}
7292 followUpBehavior={settings.followUpBehavior}
7293 + canSteer={!isCompacting}
7294 alternateShortcutLabel={shortcutLabelForCommand(
7295 keybindings,
7296 "composer.sendAlternate",
apps/web/src/components/chat/ComposerPrimaryActions.tsx
+4 -1
@@ -32,6 +32,7 @@ interface ComposerPrimaryActionsProps {
32 isRunning: boolean;
33 canInterrupt: boolean;
34 followUpBehavior?: "queue" | "steer";
35 + canSteer?: boolean;
36 alternateShortcutLabel?: string | null;
37 showPlanFollowUpPrompt: boolean;
38 promptHasText: boolean;
@@ -86,6 +87,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
87 isRunning,
88 canInterrupt,
89 followUpBehavior = "steer",
90 + canSteer = true,
91 alternateShortcutLabel = null,
92 showPlanFollowUpPrompt,
93 promptHasText,
@@ -117,6 +119,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
119 resolveComposerDispatchMode({
120 running: isRunning,
121 activeTurnDefault: followUpBehavior,
122 + canSteer,
123 alternateModifier: shortcutModifiers.metaKey || shortcutModifiers.ctrlKey,
124 }) === "queue";
125 const alternateAction = alternateComposerDispatchAction(followUpBehavior);
@@ -297,7 +300,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
300 submitStatus ??
301 (compactsBeforeSend
302 ? `Summarize ${compactTokens} tokens of history, then send`
300 - : isRunning && !isEditingQueuedMessage
303 + : isRunning && !isEditingQueuedMessage && canSteer
304 ? `Click to ${followUpBehavior}, Ctrl/⌘-click${alternateShortcutLabel ? ` or ${alternateShortcutLabel}` : ""} to ${alternateAction}`
305 : submitLabel);
306
packages/client-runtime/src/state/composerDispatch.test.ts
+13
@@ -64,6 +64,19 @@ describe("resolveComposerDispatchMode", () => {
64 },
65 );
66
67 + it("queues with or without the modifier while steering is unavailable", () => {
68 + for (const alternateModifier of [false, true]) {
69 + expect(
70 + resolveComposerDispatchMode({
71 + running: true,
72 + alternateModifier,
73 + activeTurnDefault: "steer",
74 + canSteer: false,
75 + }),
76 + ).toBe("queue");
77 + }
78 + });
79 +
80 it("names the alternate action so the affordance can be labelled", () => {
81 expect(alternateComposerDispatchAction("queue")).toBe("steer");
82 expect(alternateComposerDispatchAction("steer")).toBe("queue");
packages/client-runtime/src/state/composerDispatch.ts
+3
@@ -5,8 +5,11 @@ export function resolveComposerDispatchMode(input: {
5 readonly running: boolean;
6 readonly alternateModifier: boolean;
7 readonly activeTurnDefault?: ActiveTurnComposerAction;
8 + /** False while the active turn cannot take steering input, such as during compaction. */
9 + readonly canSteer?: boolean;
10 }): ComposerDispatchMode {
11 if (!input.running) return "auto";
12 + if (input.canSteer === false) return "queue";
13 const defaultAction = input.activeTurnDefault ?? "steer";
14 if (input.alternateModifier) return defaultAction === "queue" ? "steer" : "queue";
15 return defaultAction;