From c30d638f4add3f139a852af9ff4fd588d403dfc8 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Sun, 25 Oct 2026 21:59:05 +0000 Subject: [PATCH 1/8] fix(clients): disable steering for queued standalone commands Co-authored-by: Lars Nieuwenhuis <35393046+lnieuwenhuis@users.noreply.github.com> --- .../features/threads/ThreadQueueControl.tsx | 10 ++- .../threadQueueControlPresentation.test.ts | 17 ++++- .../threads/threadQueueControlPresentation.ts | 6 +- .../src/orchestration-v2/CommandPolicy.ts | 13 +--- .../src/orchestration-v2/Orchestrator.ts | 19 ++---- .../orchestration-v2/RestartContinuation.ts | 2 +- .../chat/QueuedRunsControl.browser.test.tsx | 50 ++++++++++++++- .../src/components/chat/QueuedRunsControl.tsx | 63 ++++++++++++------- .../src/state/threadWorkflows.test.ts | 23 +++++++ .../src/state/threadWorkflows.ts | 9 ++- .../contracts/src/orchestrationV2.test.ts | 20 ++++++ packages/contracts/src/orchestrationV2.ts | 27 ++++++++ 12 files changed, 202 insertions(+), 57 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadQueueControl.tsx b/apps/mobile/src/features/threads/ThreadQueueControl.tsx index e2c6f33f22079..56a7aebf8c79e 100644 --- a/apps/mobile/src/features/threads/ThreadQueueControl.tsx +++ b/apps/mobile/src/features/threads/ThreadQueueControl.tsx @@ -230,7 +230,8 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { No messages waiting in this queue. ) : null} - {queuedRuns.map(({ run, text, attachments, context, message }, index) => { + {queuedRuns.map((item, index) => { + const { run, text, attachments, context, message, steerRejectionReason } = item; const controls = resolveThreadQueueRowControls({ busy: busyRunId !== null, // A fresh message starts its own turn: it may skip compaction, but not steer into a turn. @@ -241,6 +242,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { editBlocked: editBlockedReason !== null, isEditing: editing?.runId === run.id, isGuestMessage: context?.guest !== undefined, + steerRejectionReason, text, }); const title = @@ -263,6 +265,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { { id: "steer", title: "Send now", + ...(!workflow?.canSendNow && steerRejectionReason + ? { subtitle: steerRejectionReason } + : {}), attributes: { disabled: !controls.canSend }, image: Platform.OS === "ios" ? "arrow.up" : "arrow_upward", }, @@ -332,6 +337,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { void act(run.id, "steer")} className="shrink-0 justify-center self-stretch pl-4 active:opacity-70 disabled:opacity-40" diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts index c29ef5eea7aa5..455792be76c9b 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts @@ -16,13 +16,25 @@ describe("threadQueueControlPresentation", () => { isEditing, canPromoteToSteer: false, canSendNow: true, - text: "Queued message", + steerRejectionReason: "Goal commands must run as a separate turn.", + text: "/goal finish the refactor", }); expect(controls.canSend).toBe(expected); }, ); + it("rejects steering a goal into an active turn", () => { + const controls = resolveThreadQueueRowControls({ + busy: false, + canPromoteToSteer: true, + canSendNow: false, + steerRejectionReason: "Goal commands must run as a separate turn.", + text: "/goal finish the refactor", + }); + expect(controls.canSend).toBe(false); + }); + it("shows an assistant quote as its quoted text", () => { const href = formatAssistantCitationHref({ version: 1, @@ -39,6 +51,7 @@ describe("threadQueueControlPresentation", () => { busy: false, canPromoteToSteer: true, canSendNow: false, + steerRejectionReason: null, text: `[Assistant quote](${href}) Can we add a backoff here?`, }); @@ -53,6 +66,7 @@ describe("threadQueueControlPresentation", () => { canPromoteToSteer: true, canSendNow: false, isEditing: true, + steerRejectionReason: null, text: "Being edited", }); @@ -68,6 +82,7 @@ describe("threadQueueControlPresentation", () => { canPromoteToSteer: true, canSendNow: false, isGuestMessage: true, + steerRejectionReason: null, text: "Why?", }); diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts index a62e29e14795d..2d2273e529162 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts @@ -22,6 +22,7 @@ export function resolveThreadQueueRowControls(input: { readonly isEditing?: boolean; /** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */ readonly isGuestMessage?: boolean; + readonly steerRejectionReason: string | null; readonly text: string; }): ThreadQueueRowControls { const mutationEnabled = !input.busy; @@ -33,7 +34,10 @@ export function resolveThreadQueueRowControls(input: { // away whatever has been typed since. canEdit: mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true, - canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing, + canSend: + mutationEnabled && + !isEditing && + (input.canSendNow || (input.canPromoteToSteer && input.steerRejectionReason === null)), dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL, // Editing and sending keep the original text so quoted citations stay linked. displayText: isAttachmentOnlyBootstrapPrompt(input.text) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index 02f329e536feb..a7cc3ed973c50 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -1,6 +1,6 @@ import { - type ChatAttachment, CommandId, + isNativeMaintenanceCommand, type OrchestrationV2Command, OrchestrationV2ProviderCapabilities, type OrchestrationV2GoalCommand, @@ -58,17 +58,6 @@ type MessageDispatchMode = Extract< { readonly type: "message.dispatch" } >["dispatchMode"]; -export function isNativeMaintenanceCommand(message: { - readonly text: string; - readonly attachments: ReadonlyArray; - readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined; -}): boolean { - return ( - message.attachments.length === 0 && - ["/compact", "/logout"].includes(message.text.trim().toLowerCase()) - ); -} - /** * A goal command sent into active work stops that work when it starts or * replaces goal work, or ends a goal that is driving the run. diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index d40ca624a11d2..fa9fbf2715ba5 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -23,6 +23,7 @@ import { type ChatAttachment, CommandId, type GuestMessageId, + isNativeMaintenanceCommand, isCompactionCommandMessage, isOrchestrationV2WorkActive, isProviderNativeSubagentThread, @@ -61,6 +62,7 @@ import { latestProviderTurnForAttempt, parseGoalCommand, orchestrationV2RunWorkStartedAt, + orchestrationV2SteerRejectionReason, orchestrationV2WorktreePending, ProviderInstanceId, ProviderInteractionMode, @@ -107,7 +109,6 @@ import { CommandPolicyV2, goalCommandStopsActiveRun, isActiveRun, - isNativeMaintenanceCommand, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; import { CommandReceiptStoreV2 } from "./CommandReceiptStore.ts"; @@ -4897,22 +4898,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio cause: `Target run ${input.targetRunId} was not found.`, }); } - if (isNativeMaintenanceCommand(input)) { + const steerRejectionReason = orchestrationV2SteerRejectionReason(input); + if (steerRejectionReason !== null) { return yield* new OrchestratorDispatchError({ commandId: input.command.commandId, commandType: input.command.type, - cause: - input.text.trim().toLowerCase() === "/compact" - ? "Context compaction must run as a separate turn. Queue it or wait for the active turn to finish." - : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.", - }); - } - if (parseGoalCommand(input) !== null) { - return yield* new OrchestratorDispatchError({ - commandId: input.command.commandId, - commandType: input.command.type, - cause: - "Goal commands must run as a separate turn. Queue it or wait for the active turn to finish.", + cause: `${steerRejectionReason} Queue it or wait for the active turn to finish.`, }); } const targetMessage = input.projection.messages.find( diff --git a/apps/server/src/orchestration-v2/RestartContinuation.ts b/apps/server/src/orchestration-v2/RestartContinuation.ts index 20d110d335aa2..4343060f01572 100644 --- a/apps/server/src/orchestration-v2/RestartContinuation.ts +++ b/apps/server/src/orchestration-v2/RestartContinuation.ts @@ -2,6 +2,7 @@ import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError"; import { resolveProjectSettings } from "@t3tools/shared/projectSettings"; import { CommandId, + isNativeMaintenanceCommand, isOrchestrationV2WorkActive, latestProviderTurnForAttempt, MessageId, @@ -14,7 +15,6 @@ import * as Effect from "effect/Effect"; import type { ProjectionRuntimeRecoveryState } from "./ProjectionStore.ts"; import * as ServerSettings from "../serverSettings.ts"; -import { isNativeMaintenanceCommand } from "./CommandPolicy.ts"; import * as ThreadManagementService from "./ThreadManagementService.ts"; import { awaitingProviderThreadId, diff --git a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx index 7e25e84135ba5..b56465afdd4a9 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx @@ -1,7 +1,7 @@ import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts"; import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations"; import * as DateTime from "effect/DateTime"; -import type { ComponentProps } from "react"; +import { createRef, type ComponentProps } from "react"; import { expect, it, vi } from "vite-plus/test"; import { page } from "vite-plus/test/browser"; @@ -42,7 +42,7 @@ vi.mock(import("../../assets/assetUrls"), async (importOriginal) => ({ import "~/index.css"; import { render as renderUi } from "../../../test/render"; -import { QueuedRunsControl } from "./QueuedRunsControl"; +import { QueuedRunsControl, type QueuedRunsControlHandle } from "./QueuedRunsControl"; function setup() { state.projection = null; @@ -203,3 +203,49 @@ it("stays inside the timeline scroller instead of growing the chat column", asyn const column = screen.getByTestId("column").element(); expect(column.scrollHeight).toBe(column.clientHeight); }); + +it.each([false, true])("gates queued command sending with send-now %s", async (canSendNow) => { + setup(); + state.projection = { projection: { messages: [] } }; + state.workflow = { + activeRun: { id: "run:active" }, + canSendNow, + canPromoteToSteer: !canSendNow, + canReorder: true, + queuedRuns: [ + { + run: { id: "run:goal", userMessageId: "message:goal" }, + text: "/goal finish the refactor", + attachments: [], + steerRejectionReason: "Goal commands must run as a separate turn.", + }, + { + run: { id: "run:plain", userMessageId: "message:plain" }, + text: "Also update the docs", + attachments: [], + steerRejectionReason: null, + }, + ], + }; + const ref = createRef(); + await using _screen = await renderQueue({ ref }); + + const steerButtons = page.getByRole("button", { + name: "Send now", + exact: true, + }); + if (canSendNow) await expect.element(steerButtons.nth(0)).toBeEnabled(); + else await expect.element(steerButtons.nth(0)).toBeDisabled(); + await expect.element(steerButtons.nth(1)).toBeEnabled(); + + expect(ref.current?.steerNext(false)).toBe(true); + expect(state.runCommand).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ + input: expect.objectContaining( + canSendNow + ? { runId: "run:goal" } + : { queuedRunId: "run:plain", targetRunId: "run:active" }, + ), + }), + ); +}); diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx index 2b2cfa78dce2b..e10a996091552 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.tsx @@ -118,6 +118,11 @@ export function QueuedRunsControl({ workflow?.canSendNow === true || (workflow?.canPromoteToSteer === true && (!freshContext || workflow.promoteSkipsCompaction === true)); + const nextSteerable = queued.find( + ({ run, steerRejectionReason }) => + canSendRun(run.freshContext === true) && + (workflow?.canSendNow || steerRejectionReason === null), + ); const queuedImageUrlById = new Map( queuedImageAttachmentUrls.flatMap((url, index) => { const resource = queuedImageAttachmentResources[index]; @@ -128,28 +133,32 @@ export function QueuedRunsControl({ (message) => message.inputIntent === "queued_turn" && !acknowledgedMessageIds.has(message.id), ); const items = [ - ...queued.map(({ run, text, attachments, context, message }, serverIndex) => ({ - key: run.id, - message, - runId: run.id, - messageId: run.userMessageId, - freshContext: run.freshContext === true, - serverIndex, - text, - // A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. - editable: context?.guest === undefined, - attachments, - thumbnails: attachments - .filter((attachment) => attachment.type === "image") - .map((attachment) => ({ - key: attachment.id, - name: attachment.name, - url: queuedImageUrlById.get(attachment.id) ?? null, - })), - pending: false, - })), + ...queued.map( + ({ run, text, attachments, context, message, steerRejectionReason }, serverIndex) => ({ + key: run.id, + steerRejectionReason, + message, + runId: run.id, + messageId: run.userMessageId, + freshContext: run.freshContext === true, + serverIndex, + text, + // A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. + editable: context?.guest === undefined, + attachments, + thumbnails: attachments + .filter((attachment) => attachment.type === "image") + .map((attachment) => ({ + key: attachment.id, + name: attachment.name, + url: queuedImageUrlById.get(attachment.id) ?? null, + })), + pending: false, + }), + ), ...optimisticQueued.map((message) => ({ key: message.id, + steerRejectionReason: null, message: undefined, runId: null, messageId: null, @@ -193,8 +202,8 @@ export function QueuedRunsControl({ useImperativeHandle(ref, () => ({ steerNext(repeat) { - const next = queued[0]; - if (!next || !canSendRun(next.run.freshContext === true)) return false; + const next = nextSteerable; + if (!next) return false; if (!repeat && busyRunId === null) void sendQueuedMessage(next.run.id); return true; }, @@ -282,7 +291,11 @@ export function QueuedRunsControl({ - {`${workflow?.canSendNow ? "Start a turn with this message" : workflow?.promoteSkipsCompaction ? "Skip compaction and send this message" : "Send into the current turn"}${item.serverIndex === 0 && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`} + {!workflow?.canSendNow && item.steerRejectionReason + ? item.steerRejectionReason + : `${workflow?.canSendNow ? "Start a turn with this message" : workflow?.promoteSkipsCompaction ? "Skip compaction and send this message" : "Send into the current turn"}${item.runId === nextSteerable?.run.id && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`} diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index 51f4d5a9e46ca..e1623e0331a16 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -137,6 +137,29 @@ describe("thread workflows", () => { expect(state.canSendNow).toBe(false); }); + it("marks queued runs the server refuses to steer", () => { + const state = deriveThreadQueueWorkflowState({ + thread: { id: "thread", activeProviderThreadId: null }, + runs: [ + { id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 1 }, + { id: "plain", status: "queued", userMessageId: "message-plain", ordinal: 2 }, + ], + messages: [ + { id: "message-goal", text: "/goal finish the refactor", attachments: [] }, + { id: "message-plain", text: "Also update the docs", attachments: [] }, + ], + providerTurns: [], + providerThreads: [], + providerSessions: [], + } as never); + + expect( + state.queuedRuns.map(({ run, steerRejectionReason }) => [run.id, steerRejectionReason]), + ).toEqual([ + ["goal", "Goal commands must run as a separate turn."], + ["plain", null], + ]); + }); it.each(["completed", "interrupted", "cancelled", "failed"])( "allows sending a held message after a %s turn without a live session", (status) => { diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index 9e13b669a1da5..86f36a8b8ea5b 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -1,8 +1,9 @@ import { type ChatAttachment, - isCompactionCommandMessage, type OrchestrationV2ProjectedTurnItem, type OrchestrationV2ProviderCapabilities, + orchestrationV2SteerRejectionReason, + isCompactionCommandMessage, } from "@t3tools/contracts"; import { copySorted } from "@t3tools/shared/Array"; @@ -27,6 +28,8 @@ export interface QueuedThreadRun { readonly attachments: ReadonlyArray; readonly messageId: Message["id"]; readonly context?: Message["context"]; + /** Set when the server would reject promoting this run to a steer. */ + readonly steerRejectionReason: string | null; /** Carries the attribution a sent message shows: automation, agent sender, or guest. */ readonly message?: Message; } @@ -155,6 +158,10 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu // A queued guest message shows the guest's words; the agent still gets the attributed text. text: message?.context?.guest?.text ?? message?.text ?? "Queued message", attachments: message?.attachments ?? [], + steerRejectionReason: orchestrationV2SteerRejectionReason({ + text: message?.text ?? "", + attachments: message?.attachments ?? [], + }), messageId: run.userMessageId, ...(message?.context ? { context: message.context } : {}), ...(message ? { message } : {}), diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index 3782307171e87..c5fe10d48a2e9 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -5,6 +5,7 @@ import * as Schema from "effect/Schema"; import { NodeId, RunAttemptId, TrimmedNonEmptyString } from "./index.ts"; import { latestProviderTurnForAttempt, + orchestrationV2SteerRejectionReason, OrchestrationV2ProviderCapabilities, OrchestrationV2ProviderThread, OrchestrationV2ProviderThreadJson, @@ -639,3 +640,22 @@ describe("latestProviderTurnForAttempt", () => { expect(latestProviderTurnForAttempt(turns, null)).toBeUndefined(); }); }); + +describe("orchestrationV2SteerRejectionReason", () => { + const image = { type: "image", id: "image", name: "a.png", mimeType: "image/png", sizeBytes: 1 }; + + it.each([ + ["/goal finish the refactor", [], "Goal commands must run as a separate turn."], + [" /goal", [], "Goal commands must run as a separate turn."], + [" /COMPACT ", [], "Context compaction must run as a separate turn."], + ["/logout", [], "Signing out must run as a separate turn."], + ["/goalie", [], null], + ["please /goal later", [], null], + ["/goal with a screenshot", [image], null], + ["/compact", [image], null], + ] as const)("%j with %j attachments", (text, attachments, reason) => { + expect(orchestrationV2SteerRejectionReason({ text, attachments: attachments as never })).toBe( + reason, + ); + }); +}); diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 6e70cc66a7203..55cf7f06f1286 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -1319,6 +1319,33 @@ export const OrchestrationV2ConversationMessage = Schema.Struct({ }); export type OrchestrationV2ConversationMessage = typeof OrchestrationV2ConversationMessage.Type; +type OrchestrationV2CommandMessage = Pick< + OrchestrationV2ConversationMessage, + "text" | "attachments" +>; + +/** A bare `/compact` or `/logout`: a provider maintenance turn, not conversation. */ +export function isNativeMaintenanceCommand(message: OrchestrationV2CommandMessage): boolean { + return ( + message.attachments.length === 0 && + ["/compact", "/logout"].includes(message.text.trim().toLowerCase()) + ); +} + +export function orchestrationV2SteerRejectionReason( + message: OrchestrationV2CommandMessage, +): string | null { + if (isNativeMaintenanceCommand(message)) { + return message.text.trim().toLowerCase() === "/compact" + ? "Context compaction must run as a separate turn." + : "Signing out must run as a separate turn."; + } + if (message.attachments.length === 0 && /^\/goal(?:\s|$)/u.test(message.text.trim())) { + return "Goal commands must run as a separate turn."; + } + return null; +} + export const OrchestrationV2PlanStep = Schema.Struct({ id: TrimmedNonEmptyString, text: TrimmedNonEmptyString, From fa16ed0ca7d4aadf7a02d1cc473a9fc5231d6de6 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 30 Oct 2026 00:53:31 +0000 Subject: [PATCH 2/8] fix(clients): preserve queued commands when skipping compaction --- .../features/threads/ThreadQueueControl.tsx | 5 +++- .../threadQueueControlPresentation.test.ts | 24 +++++++++++-------- .../threads/threadQueueControlPresentation.ts | 5 +++- .../chat/QueuedRunsControl.browser.test.tsx | 18 ++++++++++---- .../src/components/chat/QueuedRunsControl.tsx | 6 +++-- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadQueueControl.tsx b/apps/mobile/src/features/threads/ThreadQueueControl.tsx index 56a7aebf8c79e..c9092cd8b1d0d 100644 --- a/apps/mobile/src/features/threads/ThreadQueueControl.tsx +++ b/apps/mobile/src/features/threads/ThreadQueueControl.tsx @@ -243,6 +243,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { isEditing: editing?.runId === run.id, isGuestMessage: context?.guest !== undefined, steerRejectionReason, + promoteSkipsCompaction: workflow?.promoteSkipsCompaction ?? false, text, }); const title = @@ -265,7 +266,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { { id: "steer", title: "Send now", - ...(!workflow?.canSendNow && steerRejectionReason + ...(!workflow?.canSendNow && + !workflow?.promoteSkipsCompaction && + steerRejectionReason ? { subtitle: steerRejectionReason } : {}), attributes: { disabled: !controls.canSend }, diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts index 455792be76c9b..77a1599da5d90 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts @@ -24,16 +24,20 @@ describe("threadQueueControlPresentation", () => { }, ); - it("rejects steering a goal into an active turn", () => { - const controls = resolveThreadQueueRowControls({ - busy: false, - canPromoteToSteer: true, - canSendNow: false, - steerRejectionReason: "Goal commands must run as a separate turn.", - text: "/goal finish the refactor", - }); - expect(controls.canSend).toBe(false); - }); + it.each([false, true])( + "gates a queued goal with compaction skip %s", + (promoteSkipsCompaction) => { + const controls = resolveThreadQueueRowControls({ + busy: false, + canPromoteToSteer: true, + canSendNow: false, + steerRejectionReason: "Goal commands must run as a separate turn.", + text: "/goal finish the refactor", + promoteSkipsCompaction, + }); + expect(controls.canSend).toBe(promoteSkipsCompaction); + }, + ); it("shows an assistant quote as its quoted text", () => { const href = formatAssistantCitationHref({ diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts index 2d2273e529162..e80b5a28e2163 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts @@ -17,6 +17,7 @@ export function resolveThreadQueueRowControls(input: { readonly busy: boolean; readonly canPromoteToSteer: boolean; readonly canSendNow: boolean; + readonly promoteSkipsCompaction?: boolean; /** Something else holds the composer, such as an open question. */ readonly editBlocked?: boolean; readonly isEditing?: boolean; @@ -37,7 +38,9 @@ export function resolveThreadQueueRowControls(input: { canSend: mutationEnabled && !isEditing && - (input.canSendNow || (input.canPromoteToSteer && input.steerRejectionReason === null)), + (input.canSendNow || + (input.canPromoteToSteer && + (input.promoteSkipsCompaction === true || input.steerRejectionReason === null))), dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL, // Editing and sending keep the original text so quoted citations stay linked. displayText: isAttachmentOnlyBootstrapPrompt(input.text) diff --git a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx index b56465afdd4a9..66fd5cc5c12e9 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx @@ -8,6 +8,7 @@ import { page } from "vite-plus/test/browser"; const state = vi.hoisted(() => ({ projection: null as unknown, workflow: null as unknown, + runCommand: vi.fn(async (_input: unknown) => undefined), })); vi.mock(import("@t3tools/client-runtime/state/thread-workflows"), async (importOriginal) => ({ @@ -31,7 +32,7 @@ vi.mock(import("../../state/query"), async (importOriginal) => ({ vi.mock(import("../../state/use-atom-command"), async (importOriginal) => ({ ...(await importOriginal()), - useAtomCommand: (() => async () => undefined) as never, + useAtomCommand: (() => state.runCommand) as never, })); vi.mock(import("../../assets/assetUrls"), async (importOriginal) => ({ @@ -47,6 +48,7 @@ import { QueuedRunsControl, type QueuedRunsControlHandle } from "./QueuedRunsCon function setup() { state.projection = null; state.workflow = null; + state.runCommand.mockClear(); } const baseProps = { @@ -204,12 +206,17 @@ it("stays inside the timeline scroller instead of growing the chat column", asyn expect(column.scrollHeight).toBe(column.clientHeight); }); -it.each([false, true])("gates queued command sending with send-now %s", async (canSendNow) => { +it.each([ + { canSendNow: false, promoteSkipsCompaction: false }, + { canSendNow: true, promoteSkipsCompaction: false }, + { canSendNow: false, promoteSkipsCompaction: true }, +])("gates queued command sending with %j", async ({ canSendNow, promoteSkipsCompaction }) => { setup(); state.projection = { projection: { messages: [] } }; state.workflow = { activeRun: { id: "run:active" }, canSendNow, + promoteSkipsCompaction, canPromoteToSteer: !canSendNow, canReorder: true, queuedRuns: [ @@ -234,7 +241,7 @@ it.each([false, true])("gates queued command sending with send-now %s", async (c name: "Send now", exact: true, }); - if (canSendNow) await expect.element(steerButtons.nth(0)).toBeEnabled(); + if (canSendNow || promoteSkipsCompaction) await expect.element(steerButtons.nth(0)).toBeEnabled(); else await expect.element(steerButtons.nth(0)).toBeDisabled(); await expect.element(steerButtons.nth(1)).toBeEnabled(); @@ -244,7 +251,10 @@ it.each([false, true])("gates queued command sending with send-now %s", async (c input: expect.objectContaining( canSendNow ? { runId: "run:goal" } - : { queuedRunId: "run:plain", targetRunId: "run:active" }, + : { + queuedRunId: promoteSkipsCompaction ? "run:goal" : "run:plain", + targetRunId: "run:active", + }, ), }), ); diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx index e10a996091552..0814300496d15 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.tsx @@ -121,7 +121,7 @@ export function QueuedRunsControl({ const nextSteerable = queued.find( ({ run, steerRejectionReason }) => canSendRun(run.freshContext === true) && - (workflow?.canSendNow || steerRejectionReason === null), + (workflow?.canSendNow || workflow?.promoteSkipsCompaction || steerRejectionReason === null), ); const queuedImageUrlById = new Map( queuedImageAttachmentUrls.flatMap((url, index) => { @@ -294,7 +294,9 @@ export function QueuedRunsControl({ disabled={ item.runId === null || busyRunId !== null || - (!workflow?.canSendNow && item.steerRejectionReason !== null) + (!workflow?.canSendNow && + !workflow?.promoteSkipsCompaction && + item.steerRejectionReason !== null) } onClick={() => { if (item.runId !== null) { From 691cf0e65d5071cd282c1e52c4478f3e9b873339 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 30 Oct 2026 01:15:08 +0000 Subject: [PATCH 3/8] fix(clients): show compaction skip guidance for queued commands --- apps/mobile/src/features/threads/ThreadQueueControl.tsx | 4 +++- apps/web/src/components/chat/QueuedRunsControl.tsx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadQueueControl.tsx b/apps/mobile/src/features/threads/ThreadQueueControl.tsx index c9092cd8b1d0d..4a729f092d457 100644 --- a/apps/mobile/src/features/threads/ThreadQueueControl.tsx +++ b/apps/mobile/src/features/threads/ThreadQueueControl.tsx @@ -340,7 +340,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { - {!workflow?.canSendNow && item.steerRejectionReason + {!workflow?.canSendNow && + !workflow?.promoteSkipsCompaction && + item.steerRejectionReason ? item.steerRejectionReason : `${workflow?.canSendNow ? "Start a turn with this message" : workflow?.promoteSkipsCompaction ? "Skip compaction and send this message" : "Send into the current turn"}${item.runId === nextSteerable?.run.id && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`} From b6d25e12f68abd7f240473e1dfc376e62d7c348d Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 30 Oct 2026 08:20:05 +0000 Subject: [PATCH 4/8] fix(clients): wait for queued messages before enabling steering --- .../client-runtime/src/state/threadWorkflows.test.ts | 2 ++ packages/client-runtime/src/state/threadWorkflows.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index e1623e0331a16..a949efae403ed 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -143,6 +143,7 @@ describe("thread workflows", () => { runs: [ { id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 1 }, { id: "plain", status: "queued", userMessageId: "message-plain", ordinal: 2 }, + { id: "loading", status: "queued", userMessageId: "message-loading", ordinal: 3 }, ], messages: [ { id: "message-goal", text: "/goal finish the refactor", attachments: [] }, @@ -158,6 +159,7 @@ describe("thread workflows", () => { ).toEqual([ ["goal", "Goal commands must run as a separate turn."], ["plain", null], + ["loading", "Queued message is still loading."], ]); }); it.each(["completed", "interrupted", "cancelled", "failed"])( diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index 86f36a8b8ea5b..516897ddef7cb 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -158,10 +158,13 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu // A queued guest message shows the guest's words; the agent still gets the attributed text. text: message?.context?.guest?.text ?? message?.text ?? "Queued message", attachments: message?.attachments ?? [], - steerRejectionReason: orchestrationV2SteerRejectionReason({ - text: message?.text ?? "", - attachments: message?.attachments ?? [], - }), + steerRejectionReason: + message === undefined + ? "Queued message is still loading." + : orchestrationV2SteerRejectionReason({ + text: message.text, + attachments: message.attachments ?? [], + }), messageId: run.userMessageId, ...(message?.context ? { context: message.context } : {}), ...(message ? { message } : {}), From 2a972bed992817e20f1cbeceb684937cfce3a485 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 6 Nov 2026 05:12:16 +0000 Subject: [PATCH 5/8] refactor(contracts): steer rejection reuses the goal command parser --- packages/contracts/src/orchestrationV2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 55cf7f06f1286..36587ebe478be 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -1340,7 +1340,7 @@ export function orchestrationV2SteerRejectionReason( ? "Context compaction must run as a separate turn." : "Signing out must run as a separate turn."; } - if (message.attachments.length === 0 && /^\/goal(?:\s|$)/u.test(message.text.trim())) { + if (parseGoalCommand(message) !== null) { return "Goal commands must run as a separate turn."; } return null; From a6286b462ef7277e70fee916093c85e317b22abc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 08:53:33 +0000 Subject: [PATCH 6/8] fix(clients): keep queued goals steerable after goal promotion Main now lets a queued /goal promote: it stops the running turn and runs first (#25426). Only /compact and /logout still cannot steer, so the shared rejection reason covers just those, and the server reuses it. Co-Authored-By: Claude Opus 5.5 --- .../threads/threadQueueControlPresentation.test.ts | 10 +++++----- apps/server/src/orchestration-v2/Orchestrator.ts | 9 ++++----- .../chat/QueuedRunsControl.browser.test.tsx | 10 +++++----- .../src/state/threadWorkflows.test.ts | 10 +++++----- packages/contracts/src/orchestrationV2.test.ts | 7 ++----- packages/contracts/src/orchestrationV2.ts | 14 +++++--------- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts index 77a1599da5d90..dd105e995aad7 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts @@ -16,8 +16,8 @@ describe("threadQueueControlPresentation", () => { isEditing, canPromoteToSteer: false, canSendNow: true, - steerRejectionReason: "Goal commands must run as a separate turn.", - text: "/goal finish the refactor", + steerRejectionReason: "Context compaction must run as a separate turn.", + text: "/compact", }); expect(controls.canSend).toBe(expected); @@ -25,14 +25,14 @@ describe("threadQueueControlPresentation", () => { ); it.each([false, true])( - "gates a queued goal with compaction skip %s", + "gates a queued /compact with compaction skip %s", (promoteSkipsCompaction) => { const controls = resolveThreadQueueRowControls({ busy: false, canPromoteToSteer: true, canSendNow: false, - steerRejectionReason: "Goal commands must run as a separate turn.", - text: "/goal finish the refactor", + steerRejectionReason: "Context compaction must run as a separate turn.", + text: "/compact", promoteSkipsCompaction, }); expect(controls.canSend).toBe(promoteSkipsCompaction); diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index fd3f45e83b981..7d217ce3c390e 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -66,6 +66,7 @@ import { latestProviderTurnForAttempt, parseGoalCommand, orchestrationV2RunWorkStartedAt, + orchestrationV2SteerRejectionReason, ProviderInstanceId, ProviderInteractionMode, isRuntimeModeAbove, @@ -5799,14 +5800,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio >, message: Pick, ) { - if (isNativeMaintenanceCommand(message)) { + const rejectionReason = orchestrationV2SteerRejectionReason(message); + if (rejectionReason !== null) { return yield* new OrchestratorDispatchError({ commandId: command.commandId, commandType: command.type, - cause: - message.text.trim().toLowerCase() === "/compact" - ? "Context compaction must run as a separate turn. Queue it or wait for the active turn to finish." - : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.", + cause: `${rejectionReason} Queue it or wait for the active turn to finish.`, }); } if (parseGoalCommand(message) !== null) { diff --git a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx index 7b73b9085d115..62fa3931e7fc9 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx @@ -268,10 +268,10 @@ it.each([ canReorder: true, queuedRuns: [ { - run: { id: "run:goal", userMessageId: "message:goal" }, - text: "/goal finish the refactor", + run: { id: "run:compact", userMessageId: "message:compact" }, + text: "/compact", attachments: [], - steerRejectionReason: "Goal commands must run as a separate turn.", + steerRejectionReason: "Context compaction must run as a separate turn.", }, { run: { id: "run:plain", userMessageId: "message:plain" }, @@ -297,9 +297,9 @@ it.each([ expect.objectContaining({ input: expect.objectContaining( canSendNow - ? { runId: "run:goal" } + ? { runId: "run:compact" } : { - queuedRunId: promoteSkipsCompaction ? "run:goal" : "run:plain", + queuedRunId: promoteSkipsCompaction ? "run:compact" : "run:plain", targetRunId: "run:active", }, ), diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index 22346158c3641..94c69150730b3 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -142,13 +142,13 @@ describe("thread workflows", () => { const state = deriveThreadQueueWorkflowState({ thread: { id: "thread", activeProviderThreadId: null }, runs: [ - { id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 1 }, - { id: "plain", status: "queued", userMessageId: "message-plain", ordinal: 2 }, + { id: "compact", status: "queued", userMessageId: "message-compact", ordinal: 1 }, + { id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 2 }, { id: "loading", status: "queued", userMessageId: "message-loading", ordinal: 3 }, ], messages: [ + { id: "message-compact", text: "/compact", attachments: [] }, { id: "message-goal", text: "/goal finish the refactor", attachments: [] }, - { id: "message-plain", text: "Also update the docs", attachments: [] }, ], providerTurns: [], providerThreads: [], @@ -158,8 +158,8 @@ describe("thread workflows", () => { expect( state.queuedRuns.map(({ run, steerRejectionReason }) => [run.id, steerRejectionReason]), ).toEqual([ - ["goal", "Goal commands must run as a separate turn."], - ["plain", null], + ["compact", "Context compaction must run as a separate turn."], + ["goal", null], ["loading", "Queued message is still loading."], ]); }); diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index c5fe10d48a2e9..0a9d2a21b93a1 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -645,13 +645,10 @@ describe("orchestrationV2SteerRejectionReason", () => { const image = { type: "image", id: "image", name: "a.png", mimeType: "image/png", sizeBytes: 1 }; it.each([ - ["/goal finish the refactor", [], "Goal commands must run as a separate turn."], - [" /goal", [], "Goal commands must run as a separate turn."], [" /COMPACT ", [], "Context compaction must run as a separate turn."], ["/logout", [], "Signing out must run as a separate turn."], - ["/goalie", [], null], - ["please /goal later", [], null], - ["/goal with a screenshot", [image], null], + ["/goal finish the refactor", [], null], + ["please /compact later", [], null], ["/compact", [image], null], ] as const)("%j with %j attachments", (text, attachments, reason) => { expect(orchestrationV2SteerRejectionReason({ text, attachments: attachments as never })).toBe( diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index cb47bde5b2b05..c10e2266209e9 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -1414,18 +1414,14 @@ export function isNativeMaintenanceCommand(message: OrchestrationV2CommandMessag ); } +/** Why a message cannot steer an active turn. Queued goals promote through their own path. */ export function orchestrationV2SteerRejectionReason( message: OrchestrationV2CommandMessage, ): string | null { - if (isNativeMaintenanceCommand(message)) { - return message.text.trim().toLowerCase() === "/compact" - ? "Context compaction must run as a separate turn." - : "Signing out must run as a separate turn."; - } - if (parseGoalCommand(message) !== null) { - return "Goal commands must run as a separate turn."; - } - return null; + if (!isNativeMaintenanceCommand(message)) return null; + return message.text.trim().toLowerCase() === "/compact" + ? "Context compaction must run as a separate turn." + : "Signing out must run as a separate turn."; } export const OrchestrationV2PlanStep = Schema.Struct({ From 7f4a005cd5656e01fd28adca364b45c30df3eb8c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 09:00:10 +0000 Subject: [PATCH 7/8] fix(clients): keep goal steering off where the provider has no native goals The server still rejects steering a queued /goal into a provider without native goals, so the queue disables it there too. Co-Authored-By: Claude Opus 5.5 --- .../src/state/threadWorkflows.test.ts | 28 +++++++++++++++++++ .../src/state/threadWorkflows.ts | 25 ++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index 94c69150730b3..a7f0d1c577498 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -163,6 +163,34 @@ describe("thread workflows", () => { ["loading", "Queued message is still loading."], ]); }); + + it.each([ + ["codex", undefined, null], + ["opencode", true, null], + ["opencode", false, "Goal commands must run as a separate turn."], + ["pi", undefined, "Goal commands must run as a separate turn."], + ])( + "lets a queued goal steer a %s session (native goals %s)", + (driver, supportsNativeGoals, reason) => { + const state = deriveThreadQueueWorkflowState({ + thread: { id: "thread", activeProviderThreadId: null }, + runs: [{ id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 1 }], + messages: [{ id: "message-goal", text: "/goal finish the refactor", attachments: [] }], + providerTurns: [], + providerThreads: [], + providerSessions: [ + { + id: "session", + driver, + status: "running", + capabilities: { turns: { supportsNativeGoals } }, + }, + ], + } as never); + + expect(state.queuedRuns[0]?.steerRejectionReason).toBe(reason); + }, + ); it.each(["completed", "interrupted", "cancelled", "failed"])( "allows sending a held message after a %s turn without a live session", (status) => { diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index ec05bcb8e868d..b86766cdfa9b5 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -4,6 +4,7 @@ import { type OrchestrationV2ProviderCapabilities, orchestrationV2SteerRejectionReason, isCompactionCommandMessage, + parseGoalCommand, } from "@t3tools/contracts"; import { copySorted } from "@t3tools/shared/Array"; @@ -139,10 +140,26 @@ export function getUserQueuedThreadRuns( ); } +function steerRejectionReason( + message: { readonly text: string; readonly attachments: ReadonlyArray }, + runsNativeGoals: boolean, +): string | null { + const reason = orchestrationV2SteerRejectionReason(message); + if (reason !== null || runsNativeGoals || parseGoalCommand(message) === null) return reason; + return "Goal commands must run as a separate turn."; +} + export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQueueWorkflowState { const activeRun = resolveActiveThreadRun(projection); const session = resolveThreadProviderSession(projection); const capabilities = session?.capabilities.turns; + // Mirrors the server's goalDriverFor: elsewhere a goal cannot stop the turn, so it cannot steer. + const runsNativeGoals = + session === null || + session.driver === "codex" || + session.driver === "claudeAgent" || + ((session.driver === "opencode" || session.driver === "antigravity") && + capabilities?.supportsNativeGoals === true); const activeMessage = projection.messages.find( (message) => message.id === activeRun?.userMessageId, ); @@ -169,10 +186,10 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu steerRejectionReason: message === undefined ? "Queued message is still loading." - : orchestrationV2SteerRejectionReason({ - text: message.text, - attachments: message.attachments ?? [], - }), + : steerRejectionReason( + { text: message.text, attachments: message.attachments ?? [] }, + runsNativeGoals, + ), messageId: run.userMessageId, ...(message?.context ? { context: message.context } : {}), ...(message ? { message } : {}), From b5f1cfc477cd152aa050a6c33a7726a579fd7348 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 09:13:10 +0000 Subject: [PATCH 8/8] fix(clients): judge queued goal steering by the run's own provider The server checks native goal support against the queued run's model selection. Reject goal steering only when the run and the thread both use the session's provider instance; otherwise leave it to the server. Co-Authored-By: Claude Opus 5.5 --- .../src/state/threadWorkflows.test.ts | 30 ++++++++++++++----- .../src/state/threadWorkflows.ts | 9 ++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index a7f0d1c577498..88250ccf30e8d 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -165,16 +165,29 @@ describe("thread workflows", () => { }); it.each([ - ["codex", undefined, null], - ["opencode", true, null], - ["opencode", false, "Goal commands must run as a separate turn."], - ["pi", undefined, "Goal commands must run as a separate turn."], + ["codex", undefined, "codex", null], + ["opencode", true, "opencode", null], + ["opencode", false, "opencode", "Goal commands must run as a separate turn."], + ["pi", undefined, "pi", "Goal commands must run as a separate turn."], + ["pi", undefined, "codex", null], ])( - "lets a queued goal steer a %s session (native goals %s)", - (driver, supportsNativeGoals, reason) => { + "lets a queued goal steer a %s session (native goals %s) when queued for %s", + (driver, supportsNativeGoals, queuedInstanceId, reason) => { const state = deriveThreadQueueWorkflowState({ - thread: { id: "thread", activeProviderThreadId: null }, - runs: [{ id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 1 }], + thread: { + id: "thread", + activeProviderThreadId: null, + modelSelection: { instanceId: queuedInstanceId }, + }, + runs: [ + { + id: "goal", + status: "queued", + userMessageId: "message-goal", + ordinal: 1, + modelSelection: { instanceId: queuedInstanceId }, + }, + ], messages: [{ id: "message-goal", text: "/goal finish the refactor", attachments: [] }], providerTurns: [], providerThreads: [], @@ -182,6 +195,7 @@ describe("thread workflows", () => { { id: "session", driver, + providerInstanceId: driver, status: "running", capabilities: { turns: { supportsNativeGoals } }, }, diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index b86766cdfa9b5..352fb1ea21a43 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -154,12 +154,17 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu const session = resolveThreadProviderSession(projection); const capabilities = session?.capabilities.turns; // Mirrors the server's goalDriverFor: elsewhere a goal cannot stop the turn, so it cannot steer. - const runsNativeGoals = + const sessionRunsNativeGoals = session === null || session.driver === "codex" || session.driver === "claudeAgent" || ((session.driver === "opencode" || session.driver === "antigravity") && capabilities?.supportsNativeGoals === true); + // The server checks the queued run's own provider; one the session does not show is left to it. + const runsNativeGoals = (run: Run) => + sessionRunsNativeGoals || + run.modelSelection?.instanceId !== session?.providerInstanceId || + projection.thread.modelSelection?.instanceId !== session?.providerInstanceId; const activeMessage = projection.messages.find( (message) => message.id === activeRun?.userMessageId, ); @@ -188,7 +193,7 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu ? "Queued message is still loading." : steerRejectionReason( { text: message.text, attachments: message.attachments ?? [] }, - runsNativeGoals, + runsNativeGoals(run), ), messageId: run.userMessageId, ...(message?.context ? { context: message.context } : {}),