From bbc2db07af8ce668a1375c3e64c88bcedac0e558 Mon Sep 17 00:00:00 2001 From: NikitaMGrimm <65914808+NikitaMGrimm@users.noreply.github.com> Date: Fri, 23 Oct 2026 16:09:36 +0200 Subject: [PATCH 1/6] fix(composer): steer instead of queueing during automatic compaction --- .../src/state/use-thread-composer-state.ts | 40 +++++++++++++------ apps/web/src/components/ChatView.tsx | 14 ++++++- apps/web/src/components/chat/ChatComposer.tsx | 14 +++---- .../components/chat/useComposerCommandKey.ts | 6 +-- .../src/state/composerDispatch.test.ts | 12 ++++++ .../src/state/composerDispatch.ts | 11 ++++- 6 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 packages/client-runtime/src/state/composerDispatch.test.ts diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index ec71677013b44..9e849d4e6fef5 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -81,6 +81,7 @@ import { useComposerDraftSettings, } from "./use-composer-drafts"; import { + isCompactCommandText, resolveComposerDispatchMode, type ActiveTurnComposerAction, } from "@t3tools/client-runtime/state/composer-dispatch"; @@ -333,7 +334,11 @@ export function useThreadComposerState() { ? deriveThreadActivityRun(selectedThreadProjection.projection) : (selectedThreadShell?.latestRun ?? null); - const isCompacting = (() => { + const activeRunId = + selectedThreadRuntime?.activeRunId && threadRuntimeIsActive(selectedThreadRuntime) + ? selectedThreadRuntime.activeRunId + : null; + const compactCommandIsActive = (() => { const queuedCompact = selectedThreadQueuedMessages.some( (message) => message.messageId === dispatchingQueuedMessageId && @@ -341,16 +346,7 @@ export function useThreadComposerState() { message.attachments.length === 0, ); if (queuedCompact) return true; - const activeRunId = selectedThreadRuntime?.activeRunId; - if (!activeRunId || !threadRuntimeIsActive(selectedThreadRuntime)) return false; - if ( - selectedThreadVisibleTurnItems.some( - ({ item }) => - item.runId === activeRunId && item.type === "compaction" && item.status === "running", - ) - ) { - return true; - } + if (!activeRunId) return false; const compactMessage = selectedThreadVisibleTurnItems.findLast( ({ item }) => item.runId === activeRunId && @@ -369,8 +365,26 @@ export function useThreadComposerState() { item.status === "cancelled"), ); })(); - // A compacting turn cannot take steering input, so follow-ups queue meanwhile. - const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !isCompacting; + const compactionRunning = + activeRunId !== null && + selectedThreadVisibleTurnItems.some( + ({ item }) => + item.runId === activeRunId && item.type === "compaction" && item.status === "running", + ); + const isCompacting = compactCommandIsActive || compactionRunning; + // Only an explicit compaction refuses steering. Automatic compaction runs + // inside an ordinary turn, which still accepts it. + const explicitCompactionIsActive = + compactCommandIsActive || + (compactionRunning && + selectedThreadVisibleTurnItems.some( + ({ item }) => + item.runId === activeRunId && + item.type === "user_message" && + isCompactCommandText(item.text), + )); + const canSteerActiveTurn = + queueWorkflow?.canPromoteToSteer === true && !explicitCompactionIsActive; // A stop or a restart holds the queue, completion wakes included, until it // is resumed; the queue sheet lists only the user's own messages. const queueHeld = queueWorkflow?.isHeld === true; diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 62223ba82096a..f6da3777d9234 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -84,6 +84,7 @@ import { workflowOpeningParentThreadId, } from "@t3tools/client-runtime/state/subagentRuntime"; import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows"; +import { isCompactCommandText } from "@t3tools/client-runtime/state/composer-dispatch"; import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff"; import { HandoffRow } from "./chat/V2LifecycleRow"; import { @@ -1398,9 +1399,18 @@ export default function ChatView(props: ChatViewProps) { item.runId === activeRuntime?.activeRunId && item.status === "running", ); + const compactCommandIsActive = compactRequestIsActive && !compactionSettled; const isCompacting = (isSendBusy || phase === "connecting" || phase === "running") && - (compactionRunning || (compactRequestIsActive && !compactionSettled)); + (compactionRunning || compactCommandIsActive); + // Only an explicit compaction refuses steering. Automatic compaction runs + // inside an ordinary turn, which still accepts it. + const explicitCompactionIsActive = + compactCommandIsActive || + (compactionRunning && + latestServerUserItem?.type === "user_message" && + latestServerUserItem.runId === activeRuntime?.activeRunId && + isCompactCommandText(latestServerUserItem.text)); const isWorking = phase === "running" || isSendBusy || @@ -3523,7 +3533,7 @@ export default function ChatView(props: ChatViewProps) { isLocalDraftThread && activeProject === null } phase={phase} - isCompacting={isCompacting} + canSteer={!explicitCompactionIsActive} canInterrupt={canInterruptRunningThread} isConnecting={isConnecting} isSendBusy={ diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 162069163f9b4..13154915a8d6f 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -398,7 +398,7 @@ export interface ChatComposerProps { isRevertingCheckpoint?: boolean; sendDisabledReason: string | null; isPreparingWorktree: boolean; - isCompacting: boolean; + canSteer: boolean; bannerItems: readonly ComposerBannerStackItem[]; resumeCompactionTokens: number | null; keepFullHistory: boolean; @@ -562,7 +562,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) isRevertingCheckpoint = false, sendDisabledReason: externalSendDisabledReason, isPreparingWorktree, - isCompacting, + canSteer, environmentUnavailable, activePendingApproval: incomingPendingApproval, pendingApprovals, @@ -2154,7 +2154,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) running: phase === "running", alternateModifier: false, activeTurnDefault: followUpBehavior, - canSteer: !isCompacting, + canSteer, }), submissionIntent, ); @@ -2177,7 +2177,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) running: phase === "running", alternateModifier: event.metaKey || event.ctrlKey, activeTurnDefault: followUpBehavior, - canSteer: !isCompacting, + canSteer, }), ); }; @@ -2189,7 +2189,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) running: phase === "running", alternateModifier: false, activeTurnDefault: followUpBehavior, - canSteer: !isCompacting, + canSteer, }), ); }; @@ -2248,7 +2248,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) sendShortcut: settings.sendShortcut, routeKind, phase, - isCompacting, + canSteer, followUpBehavior, isSoftwareKeyboardOpen, planModeUiEnabled, @@ -3913,7 +3913,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) isRunning={phase === "running"} canInterrupt={canInterrupt} followUpBehavior={followUpBehavior} - canSteer={!isCompacting} + canSteer={canSteer} alternateShortcutLabel={shortcutLabelForCommand( keybindings, "composer.sendAlternate", diff --git a/apps/web/src/components/chat/useComposerCommandKey.ts b/apps/web/src/components/chat/useComposerCommandKey.ts index c4166b4370530..3b6d14e6831e6 100644 --- a/apps/web/src/components/chat/useComposerCommandKey.ts +++ b/apps/web/src/components/chat/useComposerCommandKey.ts @@ -32,7 +32,7 @@ export function useComposerCommandKey(input: { readonly sendShortcut: ChatComposerProps["settings"]["sendShortcut"]; readonly routeKind: ChatComposerProps["routeKind"]; readonly phase: ChatComposerProps["phase"]; - readonly isCompacting: boolean; + readonly canSteer: boolean; readonly followUpBehavior: ChatComposerProps["settings"]["followUpBehavior"]; readonly isSoftwareKeyboardOpen: boolean; readonly planModeUiEnabled: boolean; @@ -84,7 +84,7 @@ export function useComposerCommandKey(input: { sendShortcut, routeKind, phase, - isCompacting, + canSteer, followUpBehavior, isSoftwareKeyboardOpen, planModeUiEnabled, @@ -226,7 +226,7 @@ export function useComposerCommandKey(input: { running: phase === "running", alternateModifier: submissionIntent === "alternate", activeTurnDefault: followUpBehavior, - canSteer: !isCompacting, + canSteer, }), submissionIntent, ); diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts new file mode 100644 index 0000000000000..1eecca0e55106 --- /dev/null +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -0,0 +1,12 @@ +import { expect, it } from "vite-plus/test"; + +import { isCompactCommandText } from "./composerDispatch.ts"; + +it("recognizes explicit compaction commands, with or without instructions", () => { + expect(isCompactCommandText("/compact")).toBe(true); + expect(isCompactCommandText(" /COMPACT ")).toBe(true); + expect(isCompactCommandText("/compact keep the debugging notes")).toBe(true); + expect(isCompactCommandText("/compactify")).toBe(false); + expect(isCompactCommandText("please /compact")).toBe(false); + expect(isCompactCommandText("Also end your reply with PINEAPPLE.")).toBe(false); +}); diff --git a/packages/client-runtime/src/state/composerDispatch.ts b/packages/client-runtime/src/state/composerDispatch.ts index 145b1ba508147..ebab3de0def0b 100644 --- a/packages/client-runtime/src/state/composerDispatch.ts +++ b/packages/client-runtime/src/state/composerDispatch.ts @@ -5,7 +5,7 @@ export function resolveComposerDispatchMode(input: { readonly running: boolean; readonly alternateModifier: boolean; readonly activeTurnDefault?: ActiveTurnComposerAction; - /** False while the active turn cannot take steering input, such as during compaction. */ + /** False while the active turn cannot take steering input, such as an explicit /compact. */ readonly canSteer?: boolean; }): ComposerDispatchMode { if (!input.running) return "auto"; @@ -15,6 +15,15 @@ export function resolveComposerDispatchMode(input: { return defaultAction; } +/** + * Whether a run's user message asks for an explicit compaction. Its running + * compaction refuses steering, unlike automatic compaction inside an ordinary + * turn. Pi and Claude also compact for `/compact `. + */ +export function isCompactCommandText(text: string): boolean { + return /^\/compact(?:\s|$)/i.test(text.trim()); +} + export function alternateComposerDispatchAction( activeTurnDefault?: ActiveTurnComposerAction, ): ActiveTurnComposerAction { From e5cd68c6d28707aa26a862626efee9656d9294e7 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Mon, 26 Oct 2026 07:13:08 +0000 Subject: [PATCH 2/6] fix(composer): share explicit compaction guard across clients --- .../src/state/use-thread-composer-state.ts | 22 +++--- apps/web/src/components/ChatView.tsx | 19 +++--- .../src/state/composerDispatch.test.ts | 68 ++++++++++++++++--- .../src/state/composerDispatch.ts | 18 +++-- 4 files changed, 91 insertions(+), 36 deletions(-) diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index 3d3ae8151a81b..7dc8eefe6bcca 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -81,7 +81,7 @@ import { useComposerDraftSettings, } from "./use-composer-drafts"; import { - isCompactCommandText, + isExplicitCompactionActive, resolveComposerDispatchMode, type ActiveTurnComposerAction, } from "@t3tools/client-runtime/state/composer-dispatch"; @@ -369,17 +369,15 @@ export function useThreadComposerState() { item.runId === activeRunId && item.type === "compaction" && item.status === "running", ); const isCompacting = compactCommandIsActive || compactionRunning; - // Only an explicit compaction refuses steering. Automatic compaction runs - // inside an ordinary turn, which still accepts it. - const explicitCompactionIsActive = - compactCommandIsActive || - (compactionRunning && - selectedThreadVisibleTurnItems.some( - ({ item }) => - item.runId === activeRunId && - item.type === "user_message" && - isCompactCommandText(item.text), - )); + const activeRunUserItem = selectedThreadVisibleTurnItems.find( + ({ item }) => item.type === "user_message" && item.runId === activeRunId, + )?.item; + const explicitCompactionIsActive = isExplicitCompactionActive({ + compactCommandIsActive, + compactionRunning, + activeRunUserMessageText: + activeRunUserItem?.type === "user_message" ? activeRunUserItem.text : undefined, + }); const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !explicitCompactionIsActive; // A stop or a restart holds the queue, completion wakes included, until it diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 198b1403dce5d..59fdddf690862 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -86,7 +86,7 @@ import { workflowOpeningParentThreadId, } from "@t3tools/client-runtime/state/subagentRuntime"; import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows"; -import { isCompactCommandText } from "@t3tools/client-runtime/state/composer-dispatch"; +import { isExplicitCompactionActive } from "@t3tools/client-runtime/state/composer-dispatch"; import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff"; import { HandoffRow } from "./chat/V2LifecycleRow"; import { @@ -1367,14 +1367,15 @@ export default function ChatView(props: ChatViewProps) { const isCompacting = (isSendBusy || phase === "connecting" || phase === "running") && (compactionRunning || compactCommandIsActive); - // Only an explicit compaction refuses steering. Automatic compaction runs - // inside an ordinary turn, which still accepts it. - const explicitCompactionIsActive = - compactCommandIsActive || - (compactionRunning && - latestServerUserItem?.type === "user_message" && - latestServerUserItem.runId === activeRuntime?.activeRunId && - isCompactCommandText(latestServerUserItem.text)); + const activeRunUserItem = serverVisibleTurnItems.find( + ({ item }) => item.type === "user_message" && item.runId === activeRuntime?.activeRunId, + )?.item; + const explicitCompactionIsActive = isExplicitCompactionActive({ + compactCommandIsActive, + compactionRunning, + activeRunUserMessageText: + activeRunUserItem?.type === "user_message" ? activeRunUserItem.text : undefined, + }); const isWorking = phase === "running" || isSendBusy || diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts index 1eecca0e55106..4edf9bc4cf883 100644 --- a/packages/client-runtime/src/state/composerDispatch.test.ts +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -1,12 +1,64 @@ import { expect, it } from "vite-plus/test"; -import { isCompactCommandText } from "./composerDispatch.ts"; +import { isExplicitCompactionActive, resolveComposerDispatchMode } from "./composerDispatch.ts"; -it("recognizes explicit compaction commands, with or without instructions", () => { - expect(isCompactCommandText("/compact")).toBe(true); - expect(isCompactCommandText(" /COMPACT ")).toBe(true); - expect(isCompactCommandText("/compact keep the debugging notes")).toBe(true); - expect(isCompactCommandText("/compactify")).toBe(false); - expect(isCompactCommandText("please /compact")).toBe(false); - expect(isCompactCommandText("Also end your reply with PINEAPPLE.")).toBe(false); +it("allows steering during automatic compaction and preserves Queue and alternate dispatch", () => { + const canSteer = !isExplicitCompactionActive({ + compactCommandIsActive: false, + compactionRunning: true, + activeRunUserMessageText: "Read the code", + }); + expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( + "steer", + ); + expect(resolveComposerDispatchMode({ running: true, alternateModifier: true, canSteer })).toBe( + "queue", + ); + expect( + resolveComposerDispatchMode({ + running: true, + alternateModifier: false, + activeTurnDefault: "queue", + canSteer, + }), + ).toBe("queue"); +}); + +it("blocks steering only for a pending compact command or a running explicit compaction", () => { + expect( + isExplicitCompactionActive({ + compactCommandIsActive: true, + compactionRunning: false, + activeRunUserMessageText: undefined, + }), + ).toBe(true); + for (const text of ["/compact", " /COMPACT ", "/compact keep the debugging notes"]) { + const canSteer = !isExplicitCompactionActive({ + compactCommandIsActive: false, + compactionRunning: true, + activeRunUserMessageText: text, + }); + expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( + "queue", + ); + expect(resolveComposerDispatchMode({ running: true, alternateModifier: true, canSteer })).toBe( + "queue", + ); + expect( + isExplicitCompactionActive({ + compactCommandIsActive: false, + compactionRunning: false, + activeRunUserMessageText: text, + }), + ).toBe(false); + } + for (const text of ["/compactify", "please /compact", undefined]) { + expect( + isExplicitCompactionActive({ + compactCommandIsActive: false, + compactionRunning: true, + activeRunUserMessageText: text, + }), + ).toBe(false); + } }); diff --git a/packages/client-runtime/src/state/composerDispatch.ts b/packages/client-runtime/src/state/composerDispatch.ts index ebab3de0def0b..e1f77240ea5c7 100644 --- a/packages/client-runtime/src/state/composerDispatch.ts +++ b/packages/client-runtime/src/state/composerDispatch.ts @@ -15,13 +15,17 @@ export function resolveComposerDispatchMode(input: { return defaultAction; } -/** - * Whether a run's user message asks for an explicit compaction. Its running - * compaction refuses steering, unlike automatic compaction inside an ordinary - * turn. Pi and Claude also compact for `/compact `. - */ -export function isCompactCommandText(text: string): boolean { - return /^\/compact(?:\s|$)/i.test(text.trim()); +// Automatic compaction keeps accepting input; only explicit compaction blocks it. +export function isExplicitCompactionActive(input: { + readonly compactCommandIsActive: boolean; + readonly compactionRunning: boolean; + readonly activeRunUserMessageText: string | undefined; +}): boolean { + return ( + input.compactCommandIsActive || + (input.compactionRunning && + /^\/compact(?:\s|$)/i.test(input.activeRunUserMessageText?.trim() ?? "")) + ); } export function alternateComposerDispatchAction( From a5d900de598e7f90bd9cd23cd0829932d6b8655b Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Mon, 26 Oct 2026 07:25:48 +0000 Subject: [PATCH 3/6] fix(composer): retain manual compaction guard across history paging --- .../src/state/use-thread-composer-state.ts | 7 ++--- apps/web/src/components/ChatView.tsx | 7 ++--- .../src/state/composerDispatch.test.ts | 29 +++++++++++++++---- .../src/state/composerDispatch.ts | 12 ++++---- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index 7dc8eefe6bcca..45df8d48baac4 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -369,14 +369,11 @@ export function useThreadComposerState() { item.runId === activeRunId && item.type === "compaction" && item.status === "running", ); const isCompacting = compactCommandIsActive || compactionRunning; - const activeRunUserItem = selectedThreadVisibleTurnItems.find( - ({ item }) => item.type === "user_message" && item.runId === activeRunId, - )?.item; const explicitCompactionIsActive = isExplicitCompactionActive({ compactCommandIsActive, compactionRunning, - activeRunUserMessageText: - activeRunUserItem?.type === "user_message" ? activeRunUserItem.text : undefined, + run: selectedThreadProjection?.projection.runs.find((run) => run.id === activeRunId), + messages: selectedThreadMessages, }); const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !explicitCompactionIsActive; diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 59fdddf690862..4e8e124daf85c 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1367,14 +1367,11 @@ export default function ChatView(props: ChatViewProps) { const isCompacting = (isSendBusy || phase === "connecting" || phase === "running") && (compactionRunning || compactCommandIsActive); - const activeRunUserItem = serverVisibleTurnItems.find( - ({ item }) => item.type === "user_message" && item.runId === activeRuntime?.activeRunId, - )?.item; const explicitCompactionIsActive = isExplicitCompactionActive({ compactCommandIsActive, compactionRunning, - activeRunUserMessageText: - activeRunUserItem?.type === "user_message" ? activeRunUserItem.text : undefined, + run: serverProjection?.runs.find((run) => run.id === activeRuntime?.activeRunId), + messages: serverProjection?.messages, }); const isWorking = phase === "running" || diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts index 4edf9bc4cf883..8b2347e940bf3 100644 --- a/packages/client-runtime/src/state/composerDispatch.test.ts +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -2,11 +2,26 @@ import { expect, it } from "vite-plus/test"; import { isExplicitCompactionActive, resolveComposerDispatchMode } from "./composerDispatch.ts"; +it("uses the run's retained message when its initiating timeline item is paged out", () => { + expect( + isExplicitCompactionActive({ + compactCommandIsActive: false, + compactionRunning: true, + run: { userMessageId: "command" }, + messages: [ + { id: "command", text: "/compact keep the debugging notes" }, + { id: "steer", text: "A later follow-up" }, + ], + }), + ).toBe(true); +}); + it("allows steering during automatic compaction and preserves Queue and alternate dispatch", () => { const canSteer = !isExplicitCompactionActive({ compactCommandIsActive: false, compactionRunning: true, - activeRunUserMessageText: "Read the code", + run: { userMessageId: "user" }, + messages: [{ id: "user", text: "Read the code" }], }); expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( "steer", @@ -29,14 +44,16 @@ it("blocks steering only for a pending compact command or a running explicit com isExplicitCompactionActive({ compactCommandIsActive: true, compactionRunning: false, - activeRunUserMessageText: undefined, + run: undefined, + messages: undefined, }), ).toBe(true); for (const text of ["/compact", " /COMPACT ", "/compact keep the debugging notes"]) { const canSteer = !isExplicitCompactionActive({ compactCommandIsActive: false, compactionRunning: true, - activeRunUserMessageText: text, + run: { userMessageId: "user" }, + messages: text === undefined ? [] : [{ id: "user", text }], }); expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( "queue", @@ -48,7 +65,8 @@ it("blocks steering only for a pending compact command or a running explicit com isExplicitCompactionActive({ compactCommandIsActive: false, compactionRunning: false, - activeRunUserMessageText: text, + run: { userMessageId: "user" }, + messages: text === undefined ? [] : [{ id: "user", text }], }), ).toBe(false); } @@ -57,7 +75,8 @@ it("blocks steering only for a pending compact command or a running explicit com isExplicitCompactionActive({ compactCommandIsActive: false, compactionRunning: true, - activeRunUserMessageText: text, + run: { userMessageId: "user" }, + messages: text === undefined ? [] : [{ id: "user", text }], }), ).toBe(false); } diff --git a/packages/client-runtime/src/state/composerDispatch.ts b/packages/client-runtime/src/state/composerDispatch.ts index e1f77240ea5c7..d22d7036629a2 100644 --- a/packages/client-runtime/src/state/composerDispatch.ts +++ b/packages/client-runtime/src/state/composerDispatch.ts @@ -19,13 +19,13 @@ export function resolveComposerDispatchMode(input: { export function isExplicitCompactionActive(input: { readonly compactCommandIsActive: boolean; readonly compactionRunning: boolean; - readonly activeRunUserMessageText: string | undefined; + readonly run: { readonly userMessageId: string } | undefined; + readonly messages: ReadonlyArray<{ readonly id: string; readonly text: string }> | undefined; }): boolean { - return ( - input.compactCommandIsActive || - (input.compactionRunning && - /^\/compact(?:\s|$)/i.test(input.activeRunUserMessageText?.trim() ?? "")) - ); + if (input.compactCommandIsActive) return true; + if (!input.compactionRunning || input.run === undefined) return false; + const message = input.messages?.find((message) => message.id === input.run?.userMessageId); + return /^\/compact(?:\s|$)/i.test(message?.text.trim() ?? ""); } export function alternateComposerDispatchAction( From ef4cfa7fa1cb67abd460ae95ca2a7f1cc963b4ad Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Tue, 27 Oct 2026 01:35:37 +0000 Subject: [PATCH 4/6] fix(composer): allow steering for attached compact prompts --- .../src/state/composerDispatch.test.ts | 13 +++++++++++++ .../client-runtime/src/state/composerDispatch.ts | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts index 8b2347e940bf3..a6dbee0d7c134 100644 --- a/packages/client-runtime/src/state/composerDispatch.test.ts +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -81,3 +81,16 @@ it("blocks steering only for a pending compact command or a running explicit com ).toBe(false); } }); + +it("allows steering when an attached compact prompt compacts automatically", () => { + const message = { id: "user", text: "/compact", attachments: [{}] }; + const canSteer = !isExplicitCompactionActive({ + compactCommandIsActive: false, + compactionRunning: true, + run: { userMessageId: "user" }, + messages: [message], + }); + expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( + "steer", + ); +}); diff --git a/packages/client-runtime/src/state/composerDispatch.ts b/packages/client-runtime/src/state/composerDispatch.ts index d22d7036629a2..2836d22c36bca 100644 --- a/packages/client-runtime/src/state/composerDispatch.ts +++ b/packages/client-runtime/src/state/composerDispatch.ts @@ -20,12 +20,21 @@ export function isExplicitCompactionActive(input: { readonly compactCommandIsActive: boolean; readonly compactionRunning: boolean; readonly run: { readonly userMessageId: string } | undefined; - readonly messages: ReadonlyArray<{ readonly id: string; readonly text: string }> | undefined; + readonly messages: + | ReadonlyArray<{ + readonly id: string; + readonly text: string; + readonly attachments?: ReadonlyArray; + }> + | undefined; }): boolean { if (input.compactCommandIsActive) return true; if (!input.compactionRunning || input.run === undefined) return false; const message = input.messages?.find((message) => message.id === input.run?.userMessageId); - return /^\/compact(?:\s|$)/i.test(message?.text.trim() ?? ""); + return ( + (message?.attachments?.length ?? 0) === 0 && + /^\/compact(?:\s|$)/i.test(message?.text.trim() ?? "") + ); } export function alternateComposerDispatchAction( From 93295cab2abc9a6e3a14ce10c03ad5917b9e2513 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 05:49:10 +0000 Subject: [PATCH 5/6] test(composer): cover explicit compaction guard in one table AI-assisted; verified with the tests and tools listed above. --- .../src/state/composerDispatch.test.ts | 95 ++++--------------- 1 file changed, 20 insertions(+), 75 deletions(-) diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts index a6dbee0d7c134..758068bc20b8a 100644 --- a/packages/client-runtime/src/state/composerDispatch.test.ts +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -1,45 +1,27 @@ import { expect, it } from "vite-plus/test"; -import { isExplicitCompactionActive, resolveComposerDispatchMode } from "./composerDispatch.ts"; +import { isExplicitCompactionActive } from "./composerDispatch.ts"; -it("uses the run's retained message when its initiating timeline item is paged out", () => { - expect( +it("blocks steering only for explicit compaction, not automatic compaction", () => { + const during = (text: string | undefined, attachments: ReadonlyArray = []) => isExplicitCompactionActive({ compactCommandIsActive: false, compactionRunning: true, - run: { userMessageId: "command" }, + run: { userMessageId: "user" }, messages: [ - { id: "command", text: "/compact keep the debugging notes" }, - { id: "steer", text: "A later follow-up" }, + ...(text === undefined ? [] : [{ id: "user", text, attachments }]), + { id: "later", text: "/compact" }, ], - }), - ).toBe(true); -}); + }); -it("allows steering during automatic compaction and preserves Queue and alternate dispatch", () => { - const canSteer = !isExplicitCompactionActive({ - compactCommandIsActive: false, - compactionRunning: true, - run: { userMessageId: "user" }, - messages: [{ id: "user", text: "Read the code" }], - }); - expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( - "steer", - ); - expect(resolveComposerDispatchMode({ running: true, alternateModifier: true, canSteer })).toBe( - "queue", - ); - expect( - resolveComposerDispatchMode({ - running: true, - alternateModifier: false, - activeTurnDefault: "queue", - canSteer, - }), - ).toBe("queue"); -}); + for (const text of ["/compact", " /COMPACT ", "/compact keep the debugging notes"]) { + expect(during(text)).toBe(true); + } + for (const text of ["Read the code", "/compactify", "please /compact", undefined]) { + expect(during(text)).toBe(false); + } + expect(during("/compact", [{}])).toBe(false); -it("blocks steering only for a pending compact command or a running explicit compaction", () => { expect( isExplicitCompactionActive({ compactCommandIsActive: true, @@ -48,49 +30,12 @@ it("blocks steering only for a pending compact command or a running explicit com messages: undefined, }), ).toBe(true); - for (const text of ["/compact", " /COMPACT ", "/compact keep the debugging notes"]) { - const canSteer = !isExplicitCompactionActive({ + expect( + isExplicitCompactionActive({ compactCommandIsActive: false, - compactionRunning: true, + compactionRunning: false, run: { userMessageId: "user" }, - messages: text === undefined ? [] : [{ id: "user", text }], - }); - expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( - "queue", - ); - expect(resolveComposerDispatchMode({ running: true, alternateModifier: true, canSteer })).toBe( - "queue", - ); - expect( - isExplicitCompactionActive({ - compactCommandIsActive: false, - compactionRunning: false, - run: { userMessageId: "user" }, - messages: text === undefined ? [] : [{ id: "user", text }], - }), - ).toBe(false); - } - for (const text of ["/compactify", "please /compact", undefined]) { - expect( - isExplicitCompactionActive({ - compactCommandIsActive: false, - compactionRunning: true, - run: { userMessageId: "user" }, - messages: text === undefined ? [] : [{ id: "user", text }], - }), - ).toBe(false); - } -}); - -it("allows steering when an attached compact prompt compacts automatically", () => { - const message = { id: "user", text: "/compact", attachments: [{}] }; - const canSteer = !isExplicitCompactionActive({ - compactCommandIsActive: false, - compactionRunning: true, - run: { userMessageId: "user" }, - messages: [message], - }); - expect(resolveComposerDispatchMode({ running: true, alternateModifier: false, canSteer })).toBe( - "steer", - ); + messages: [{ id: "user", text: "/compact" }], + }), + ).toBe(false); }); From 3861b1c49e0a0782692fa470f65666a657862166 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 06:00:14 +0000 Subject: [PATCH 6/6] fix(composer): keep queueing during compaction for providers that cannot take steers then Claude aborts a running automatic compaction when a steer arrives, so steering during compaction is now a per-adapter turn capability. Codex opts in; Claude keeps the queue until it holds steers through compaction. AI-assisted; verified with the tests and tools listed above. --- .../src/state/use-thread-composer-state.ts | 9 +++++---- .../Adapters/CodexAdapterV2.ts | 1 + apps/web/src/components/ChatView.tsx | 8 +++++--- .../src/state/composerDispatch.test.ts | 20 +++++++++++++------ .../src/state/composerDispatch.ts | 9 ++++++--- .../src/state/threadWorkflows.ts | 8 ++++++++ packages/contracts/src/orchestrationV2.ts | 2 ++ 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index 4dd8aab07270b..702aa53f90f0f 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -6,6 +6,7 @@ import { useAtomValue } from "@effect/atom-react"; import { shouldCompactBeforeSend } from "@t3tools/client-runtime/state/context-window"; import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell"; import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; +import { threadSteersDuringCompaction } from "@t3tools/client-runtime/state/thread-workflows"; import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff"; import { deriveProviderSubagentStatus, @@ -84,7 +85,7 @@ import { } from "./use-composer-drafts"; import { isClearComposerCommand, parseSideChatCommand } from "@t3tools/shared/composerTrigger"; import { - isExplicitCompactionActive, + compactionBlocksSteering, resolveComposerDispatchMode, type ActiveTurnComposerAction, } from "@t3tools/client-runtime/state/composer-dispatch"; @@ -361,14 +362,14 @@ export function useThreadComposerState(input: { item.runId === activeRunId && item.type === "compaction" && item.status === "running", ); const isCompacting = compactCommandIsActive || compactionRunning; - const explicitCompactionIsActive = isExplicitCompactionActive({ + const compactionBlocksSteer = compactionBlocksSteering({ compactCommandIsActive, compactionRunning, + steersDuringCompaction: threadSteersDuringCompaction(selectedThreadProjection?.projection), run: selectedThreadProjection?.projection.runs.find((run) => run.id === activeRunId), messages: selectedThreadMessages, }); - const canSteerActiveTurn = - queueWorkflow?.canPromoteToSteer === true && !explicitCompactionIsActive; + const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !compactionBlocksSteer; // A stop or a restart holds the queue, completion wakes included, until it // is resumed; the queue sheet lists only the user's own messages. const queueHeld = queueWorkflow?.isHeld === true; diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts index 6953636a8dcf5..4a5985f6c2ef5 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts @@ -265,6 +265,7 @@ export const CodexProviderCapabilitiesV2 = { emitsTurnCompleted: true, supportsInterrupt: true, supportsActiveSteering: true, + activeSteeringDuringCompaction: true, supportsSteeringByInterruptRestart: true, supportsQueuedMessages: true, terminalStatusQuality: "strong", diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 7b671cc574518..15b8c91ac6950 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -90,9 +90,10 @@ import { } from "@t3tools/client-runtime/state/subagentRuntime"; import { getUserQueuedThreadRuns, + threadSteersDuringCompaction, threadSupportsProviderHandoff, } from "@t3tools/client-runtime/state/thread-workflows"; -import { isExplicitCompactionActive } from "@t3tools/client-runtime/state/composer-dispatch"; +import { compactionBlocksSteering } from "@t3tools/client-runtime/state/composer-dispatch"; import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff"; import { HandoffRow } from "./chat/V2LifecycleRow"; import { @@ -1443,9 +1444,10 @@ export default function ChatView(props: ChatViewProps) { const isCompacting = (isSendBusy || phase === "connecting" || phase === "running") && (compactionRunning || compactCommandIsActive); - const explicitCompactionIsActive = isExplicitCompactionActive({ + const compactionBlocksSteer = compactionBlocksSteering({ compactCommandIsActive, compactionRunning, + steersDuringCompaction: threadSteersDuringCompaction(serverProjection), run: serverProjection?.runs.find((run) => run.id === activeRuntime?.activeRunId), messages: serverProjection?.messages, }); @@ -3600,7 +3602,7 @@ export default function ChatView(props: ChatViewProps) { isLocalDraftThread && activeProject === null } phase={phase} - canSteer={!explicitCompactionIsActive} + canSteer={!compactionBlocksSteer} canInterrupt={canInterruptRunningThread} isSendBusy={ (isSendBusy && !sendQueuesBehindSetup) || diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts index 758068bc20b8a..936ae33111ef4 100644 --- a/packages/client-runtime/src/state/composerDispatch.test.ts +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -1,12 +1,17 @@ import { expect, it } from "vite-plus/test"; -import { isExplicitCompactionActive } from "./composerDispatch.ts"; +import { compactionBlocksSteering } from "./composerDispatch.ts"; -it("blocks steering only for explicit compaction, not automatic compaction", () => { - const during = (text: string | undefined, attachments: ReadonlyArray = []) => - isExplicitCompactionActive({ +it("blocks steering for explicit compaction, and for automatic compaction unless the provider takes steers then", () => { + const during = ( + text: string | undefined, + attachments: ReadonlyArray = [], + steersDuringCompaction = true, + ) => + compactionBlocksSteering({ compactCommandIsActive: false, compactionRunning: true, + steersDuringCompaction, run: { userMessageId: "user" }, messages: [ ...(text === undefined ? [] : [{ id: "user", text, attachments }]), @@ -21,19 +26,22 @@ it("blocks steering only for explicit compaction, not automatic compaction", () expect(during(text)).toBe(false); } expect(during("/compact", [{}])).toBe(false); + expect(during("Read the code", [], false)).toBe(true); expect( - isExplicitCompactionActive({ + compactionBlocksSteering({ compactCommandIsActive: true, compactionRunning: false, + steersDuringCompaction: true, run: undefined, messages: undefined, }), ).toBe(true); expect( - isExplicitCompactionActive({ + compactionBlocksSteering({ compactCommandIsActive: false, compactionRunning: false, + steersDuringCompaction: false, run: { userMessageId: "user" }, messages: [{ id: "user", text: "/compact" }], }), diff --git a/packages/client-runtime/src/state/composerDispatch.ts b/packages/client-runtime/src/state/composerDispatch.ts index 2836d22c36bca..c24bb95628d97 100644 --- a/packages/client-runtime/src/state/composerDispatch.ts +++ b/packages/client-runtime/src/state/composerDispatch.ts @@ -15,10 +15,11 @@ export function resolveComposerDispatchMode(input: { return defaultAction; } -// Automatic compaction keeps accepting input; only explicit compaction blocks it. -export function isExplicitCompactionActive(input: { +// Automatic compaction takes steers only where the provider says a steer leaves it running. +export function compactionBlocksSteering(input: { readonly compactCommandIsActive: boolean; readonly compactionRunning: boolean; + readonly steersDuringCompaction: boolean; readonly run: { readonly userMessageId: string } | undefined; readonly messages: | ReadonlyArray<{ @@ -29,7 +30,9 @@ export function isExplicitCompactionActive(input: { | undefined; }): boolean { if (input.compactCommandIsActive) return true; - if (!input.compactionRunning || input.run === undefined) return false; + if (!input.compactionRunning) return false; + if (!input.steersDuringCompaction) return true; + if (input.run === undefined) return false; const message = input.messages?.find((message) => message.id === input.run?.userMessageId); return ( (message?.attachments?.length ?? 0) === 0 && diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index 9e13b669a1da5..0aae5835eff03 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -92,6 +92,14 @@ function resolveThreadProviderSession(projection: Projection): ProviderSession | ); } +export function threadSteersDuringCompaction(projection: Projection | null | undefined): boolean { + if (projection == null) return false; + return ( + resolveThreadProviderSession(projection)?.capabilities.turns.activeSteeringDuringCompaction === + true + ); +} + export function threadSupportsProviderHandoff(projection: Projection | null | undefined): boolean { if (projection == null) return false; const session = resolveThreadProviderSession(projection); diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index b1fd02b3d3a07..d5033fa02f433 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -288,6 +288,8 @@ export const OrchestrationV2TurnCapabilities = Schema.Struct({ activeSteeringInterruptsTools: Schema.optional(Schema.Boolean), // Some take text only, so a steer with attachments restarts the turn instead. activeSteeringAcceptsAttachments: Schema.optional(Schema.Boolean), + // Only where a steer leaves a running automatic compaction intact; otherwise clients queue. + activeSteeringDuringCompaction: Schema.optional(Schema.Boolean), supportsSteeringByInterruptRestart: Schema.Boolean, supportsQueuedMessages: Schema.Boolean, terminalStatusQuality: Schema.Literals(["strong", "weak", "none"]),