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 21, 23:30 UTC
fix(composer): steer instead of queueing during automatic compaction (#24138)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Nikita Maximilian Grimm committed
Nov 11, 2026 at 13:11 UTC
b3f5d52701430c8458ee4893c6d523bc9d59e85b
9 files changed
+132
-27
apps/mobile/src/state/use-thread-composer-state.ts
+23
-13
@@ -6,6 +6,7 @@ import { useAtomValue } from "@effect/atom-react";
6
import { shouldCompactBeforeSend } from "@t3tools/client-runtime/state/context-window";
7
import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell";
8
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
9
+import { threadSteersDuringCompaction } from "@t3tools/client-runtime/state/thread-workflows";
10
import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff";
11
import {
12
deriveProviderSubagentStatus,
@@ -84,6 +85,7 @@ import {
85
} from "./use-composer-drafts";
86
import { isClearComposerCommand, parseSideChatCommand } from "@t3tools/shared/composerTrigger";
87
import {
88
+ compactionBlocksSteering,
89
resolveComposerDispatchMode,
90
type ActiveTurnComposerAction,
91
} from "@t3tools/client-runtime/state/composer-dispatch";
@@ -322,7 +324,11 @@ export function useThreadComposerState(input: {
324
? deriveThreadActivityRun(selectedThreadProjection.projection)
325
: (selectedThreadShell?.latestRun ?? null);
326
325
- const isCompacting = (() => {
327
+ const activeRunId =
328
+ selectedThreadRuntime?.activeRunId && threadRuntimeIsActive(selectedThreadRuntime)
329
+ ? selectedThreadRuntime.activeRunId
330
+ : null;
331
+ const compactCommandIsActive = (() => {
332
const queuedCompact = selectedThreadQueuedMessages.some(
333
(message) =>
334
message.messageId === dispatchingQueuedMessageId &&
@@ -330,16 +336,7 @@ export function useThreadComposerState(input: {
336
message.attachments.length === 0,
337
);
338
if (queuedCompact) return true;
333
- const activeRunId = selectedThreadRuntime?.activeRunId;
334
- if (!activeRunId || !threadRuntimeIsActive(selectedThreadRuntime)) return false;
335
- if (
336
- selectedThreadVisibleTurnItems.some(
337
- ({ item }) =>
338
- item.runId === activeRunId && item.type === "compaction" && item.status === "running",
339
- )
340
- ) {
341
- return true;
342
- }
339
+ if (!activeRunId) return false;
340
const compactMessage = selectedThreadVisibleTurnItems.findLast(
341
({ item }) =>
342
item.runId === activeRunId &&
@@ -358,8 +355,21 @@ export function useThreadComposerState(input: {
355
item.status === "cancelled"),
356
);
357
})();
361
- // A compacting turn cannot take steering input, so follow-ups queue meanwhile.
362
- const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !isCompacting;
358
+ const compactionRunning =
359
+ activeRunId !== null &&
360
+ selectedThreadVisibleTurnItems.some(
361
+ ({ item }) =>
362
+ item.runId === activeRunId && item.type === "compaction" && item.status === "running",
363
+ );
364
+ const isCompacting = compactCommandIsActive || compactionRunning;
365
+ const compactionBlocksSteer = compactionBlocksSteering({
366
+ compactCommandIsActive,
367
+ compactionRunning,
368
+ steersDuringCompaction: threadSteersDuringCompaction(selectedThreadProjection?.projection),
369
+ run: selectedThreadProjection?.projection.runs.find((run) => run.id === activeRunId),
370
+ messages: selectedThreadMessages,
371
+ });
372
+ const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !compactionBlocksSteer;
373
// A stop or a restart holds the queue, completion wakes included, until it
374
// is resumed; the queue sheet lists only the user's own messages.
375
const queueHeld = queueWorkflow?.isHeld === true;
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+1
@@ -265,6 +265,7 @@ export const CodexProviderCapabilitiesV2 = {
265
emitsTurnCompleted: true,
266
supportsInterrupt: true,
267
supportsActiveSteering: true,
268
+ activeSteeringDuringCompaction: true,
269
supportsSteeringByInterruptRestart: true,
270
supportsQueuedMessages: true,
271
terminalStatusQuality: "strong",
apps/web/src/components/ChatView.tsx
+12
-2
@@ -90,8 +90,10 @@ import {
90
} from "@t3tools/client-runtime/state/subagentRuntime";
91
import {
92
getUserQueuedThreadRuns,
93
+ threadSteersDuringCompaction,
94
threadSupportsProviderHandoff,
95
} from "@t3tools/client-runtime/state/thread-workflows";
96
+import { compactionBlocksSteering } from "@t3tools/client-runtime/state/composer-dispatch";
97
import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff";
98
import { HandoffRow } from "./chat/V2LifecycleRow";
99
import {
@@ -1419,9 +1421,17 @@ export default function ChatView(props: ChatViewProps) {
1421
item.runId === activeRuntime?.activeRunId &&
1422
item.status === "running",
1423
);
1424
+ const compactCommandIsActive = compactRequestIsActive && !compactionSettled;
1425
const isCompacting =
1426
(isSendBusy || phase === "connecting" || phase === "running") &&
1424
- (compactionRunning || (compactRequestIsActive && !compactionSettled));
1427
+ (compactionRunning || compactCommandIsActive);
1428
+ const compactionBlocksSteer = compactionBlocksSteering({
1429
+ compactCommandIsActive,
1430
+ compactionRunning,
1431
+ steersDuringCompaction: threadSteersDuringCompaction(serverProjection),
1432
+ run: serverProjection?.runs.find((run) => run.id === activeRuntime?.activeRunId),
1433
+ messages: serverProjection?.messages,
1434
+ });
1435
const isWorking =
1436
phase === "running" || isSendBusy || isCompacting || runlessWorkStartedAt !== null;
1437
const activeContextWindow = deriveLatestContextWindowSnapshot(
@@ -3576,7 +3586,7 @@ export default function ChatView(props: ChatViewProps) {
3586
isLocalDraftThread && activeProject === null
3587
}
3588
phase={phase}
3579
- isCompacting={isCompacting}
3589
+ canSteer={!compactionBlocksSteer}
3590
canInterrupt={canInterruptRunningThread}
3591
isSendBusy={
3592
(isSendBusy && !sendQueuesBehindSetup) ||
apps/web/src/components/chat/ChatComposer.tsx
+8
-8
@@ -370,7 +370,7 @@ export interface ChatComposerProps {
370
isRevertingCheckpoint?: boolean;
371
sendDisabledReason: string | null;
372
isPreparingWorktree: boolean;
373
- isCompacting: boolean;
373
+ canSteer: boolean;
374
bannerItems: readonly ComposerBannerStackItem[];
375
resumeCompactionTokens: number | null;
376
keepFullHistory: boolean;
@@ -516,7 +516,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
516
isRevertingCheckpoint = false,
517
sendDisabledReason: externalSendDisabledReason,
518
isPreparingWorktree,
519
- isCompacting,
519
+ canSteer,
520
environmentUnavailable,
521
activePendingApproval: incomingPendingApproval,
522
pendingApprovals,
@@ -2144,7 +2144,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2144
running: phase === "running",
2145
alternateModifier: false,
2146
activeTurnDefault: followUpBehavior,
2147
- canSteer: !isCompacting,
2147
+ canSteer,
2148
}),
2149
submissionIntent,
2150
);
@@ -2185,7 +2185,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2185
resolveComposerDispatchMode({
2186
running: phase === "running",
2187
alternateModifier: intent === "alternate",
2188
- canSteer: !isCompacting,
2188
+ canSteer,
2189
activeTurnDefault: followUpBehavior,
2190
}),
2191
intent,
@@ -2200,7 +2200,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2200
running: phase === "running",
2201
alternateModifier: event.metaKey || event.ctrlKey,
2202
activeTurnDefault: followUpBehavior,
2203
- canSteer: !isCompacting,
2203
+ canSteer,
2204
}),
2205
);
2206
};
@@ -2212,7 +2212,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2212
running: phase === "running",
2213
alternateModifier: false,
2214
activeTurnDefault: followUpBehavior,
2215
- canSteer: !isCompacting,
2215
+ canSteer,
2216
}),
2217
);
2218
};
@@ -2293,7 +2293,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2293
sendShortcut: settings.sendShortcut,
2294
routeKind,
2295
phase,
2296
- isCompacting,
2296
+ canSteer,
2297
followUpBehavior,
2298
isSoftwareKeyboardOpen,
2299
isLiteralPendingAnswer,
@@ -3584,7 +3584,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3584
isRunning={phase === "running"}
3585
canInterrupt={canInterrupt}
3586
followUpBehavior={followUpBehavior}
3587
- canSteer={!isCompacting}
3587
+ canSteer={canSteer}
3588
alternateShortcutLabel={shortcutLabelForCommand(
3589
keybindings,
3590
"composer.sendAlternate",
apps/web/src/components/chat/composerCommandKey.ts
+3
-3
@@ -38,7 +38,7 @@ export function composerCommandKeyHandler(input: {
38
readonly sendShortcut: ChatComposerProps["settings"]["sendShortcut"];
39
readonly routeKind: ChatComposerProps["routeKind"];
40
readonly phase: ChatComposerProps["phase"];
41
- readonly isCompacting: boolean;
41
+ readonly canSteer: boolean;
42
readonly followUpBehavior: ChatComposerProps["settings"]["followUpBehavior"];
43
readonly isSoftwareKeyboardOpen: boolean;
44
readonly isLiteralPendingAnswer: boolean;
@@ -91,7 +91,7 @@ export function composerCommandKeyHandler(input: {
91
sendShortcut,
92
routeKind,
93
phase,
94
- isCompacting,
94
+ canSteer,
95
followUpBehavior,
96
isSoftwareKeyboardOpen,
97
isLiteralPendingAnswer,
@@ -267,7 +267,7 @@ export function composerCommandKeyHandler(input: {
267
running: phase === "running",
268
alternateModifier: submissionIntent === "alternate",
269
activeTurnDefault: followUpBehavior,
270
- canSteer: !isCompacting,
270
+ canSteer,
271
}),
272
submissionIntent,
273
);
packages/client-runtime/src/state/composerDispatch.test.ts
new
+49
@@ -0,0 +1,49 @@
1
+import { expect, it } from "vite-plus/test";
2
+
3
+import { compactionBlocksSteering } from "./composerDispatch.ts";
4
+
5
+it("blocks steering for explicit compaction, and for automatic compaction unless the provider takes steers then", () => {
6
+ const during = (
7
+ text: string | undefined,
8
+ attachments: ReadonlyArray<unknown> = [],
9
+ steersDuringCompaction = true,
10
+ ) =>
11
+ compactionBlocksSteering({
12
+ compactCommandIsActive: false,
13
+ compactionRunning: true,
14
+ steersDuringCompaction,
15
+ run: { userMessageId: "user" },
16
+ messages: [
17
+ ...(text === undefined ? [] : [{ id: "user", text, attachments }]),
18
+ { id: "later", text: "/compact" },
19
+ ],
20
+ });
21
+
22
+ for (const text of ["/compact", " /COMPACT ", "/compact keep the debugging notes"]) {
23
+ expect(during(text)).toBe(true);
24
+ }
25
+ for (const text of ["Read the code", "/compactify", "please /compact", undefined]) {
26
+ expect(during(text)).toBe(false);
27
+ }
28
+ expect(during("/compact", [{}])).toBe(false);
29
+ expect(during("Read the code", [], false)).toBe(true);
30
+
31
+ expect(
32
+ compactionBlocksSteering({
33
+ compactCommandIsActive: true,
34
+ compactionRunning: false,
35
+ steersDuringCompaction: true,
36
+ run: undefined,
37
+ messages: undefined,
38
+ }),
39
+ ).toBe(true);
40
+ expect(
41
+ compactionBlocksSteering({
42
+ compactCommandIsActive: false,
43
+ compactionRunning: false,
44
+ steersDuringCompaction: false,
45
+ run: { userMessageId: "user" },
46
+ messages: [{ id: "user", text: "/compact" }],
47
+ }),
48
+ ).toBe(false);
49
+});
packages/client-runtime/src/state/composerDispatch.ts
+26
-1
@@ -5,7 +5,7 @@ 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. */
8
+ /** False while the active turn cannot take steering input, such as an explicit /compact. */
9
readonly canSteer?: boolean;
10
}): ComposerDispatchMode {
11
if (!input.running) return "auto";
@@ -15,6 +15,31 @@ export function resolveComposerDispatchMode(input: {
15
return defaultAction;
16
}
17
18
+// Automatic compaction takes steers only where the provider says a steer leaves it running.
19
+export function compactionBlocksSteering(input: {
20
+ readonly compactCommandIsActive: boolean;
21
+ readonly compactionRunning: boolean;
22
+ readonly steersDuringCompaction: boolean;
23
+ readonly run: { readonly userMessageId: string } | undefined;
24
+ readonly messages:
25
+ | ReadonlyArray<{
26
+ readonly id: string;
27
+ readonly text: string;
28
+ readonly attachments?: ReadonlyArray<unknown>;
29
+ }>
30
+ | undefined;
31
+}): boolean {
32
+ if (input.compactCommandIsActive) return true;
33
+ if (!input.compactionRunning) return false;
34
+ if (!input.steersDuringCompaction) return true;
35
+ if (input.run === undefined) return false;
36
+ const message = input.messages?.find((message) => message.id === input.run?.userMessageId);
37
+ return (
38
+ (message?.attachments?.length ?? 0) === 0 &&
39
+ /^\/compact(?:\s|$)/i.test(message?.text.trim() ?? "")
40
+ );
41
+}
42
+
43
export function alternateComposerDispatchAction(
44
activeTurnDefault?: ActiveTurnComposerAction,
45
): ActiveTurnComposerAction {
packages/client-runtime/src/state/threadWorkflows.ts
+8
@@ -92,6 +92,14 @@ function resolveThreadProviderSession(projection: Projection): ProviderSession |
92
);
93
}
94
95
+export function threadSteersDuringCompaction(projection: Projection | null | undefined): boolean {
96
+ if (projection == null) return false;
97
+ return (
98
+ resolveThreadProviderSession(projection)?.capabilities.turns.activeSteeringDuringCompaction ===
99
+ true
100
+ );
101
+}
102
+
103
export function threadSupportsProviderHandoff(projection: Projection | null | undefined): boolean {
104
if (projection == null) return false;
105
const session = resolveThreadProviderSession(projection);
packages/contracts/src/orchestrationV2.ts
+2
@@ -288,6 +288,8 @@ export const OrchestrationV2TurnCapabilities = Schema.Struct({
288
activeSteeringInterruptsTools: Schema.optional(Schema.Boolean),
289
// Some take text only, so a steer with attachments restarts the turn instead.
290
activeSteeringAcceptsAttachments: Schema.optional(Schema.Boolean),
291
+ // Only where a steer leaves a running automatic compaction intact; otherwise clients queue.
292
+ activeSteeringDuringCompaction: Schema.optional(Schema.Boolean),
293
supportsSteeringByInterruptRestart: Schema.Boolean,
294
supportsQueuedMessages: Schema.Boolean,
295
terminalStatusQuality: Schema.Literals(["strong", "weak", "none"]),