From 71a7c5c70f87d66bd49163366c4dae6653b75f9a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 11:40:26 +0000 Subject: [PATCH 1/6] fix(server): slash commands sent during a turn wait instead of steering A message that is only a slash command (such as /compact or /context) no longer steers into a running turn. It queues behind the active run, so a steered /compact is no longer rejected and a steered /context no longer replaces the agent's task. Sending a queued command now moves it to the front of the queue without stopping the run. An explicit restart still runs the command, and native /goal handling is unchanged. Originally #32633 (commits 71bc014d21..55138fa36c), rebased onto main. Co-Authored-By: Claude Opus 5.5 --- .../orchestration-v2/CommandPolicy.test.ts | 147 +++++++++--------- .../src/orchestration-v2/CommandPolicy.ts | 27 ++++ .../src/orchestration-v2/Orchestrator.ts | 45 ++++-- .../SteeringCompletion.integration.test.ts | 125 +++++++++++++-- .../ThreadLaunchService.test.ts | 2 +- docs/user/composer.md | 3 + 6 files changed, 241 insertions(+), 108 deletions(-) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.test.ts b/apps/server/src/orchestration-v2/CommandPolicy.test.ts index e9f829524948b..5b51aeffb4d82 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.test.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.test.ts @@ -65,25 +65,30 @@ function dispatchProjection( } as unknown as OrchestrationV2ThreadProjection; } +function resolveDispatch( + projection: OrchestrationV2ThreadProjection, + dispatchMode: Parameters[1]["dispatchMode"], + deliveryIntent?: "auto" | "steer" | "restart", + text = "next", +) { + return CommandPolicy.resolveMessageDispatchIntent(projection, { + dispatchMode, + ...(deliveryIntent === undefined ? {} : { deliveryIntent }), + text, + attachments: [], + }); +} + it("resolves automatic message delivery from authoritative provider capabilities", () => { + assert.deepEqual(resolveDispatch(dispatchProjection(), { type: "start_immediately" }, "auto"), { + type: "start_immediately", + }); assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - dispatchProjection(), - { type: "start_immediately" }, - "auto", - ), - { type: "start_immediately" }, - ); - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - dispatchProjection(baseCapabilities), - { type: "start_immediately" }, - "auto", - ), + resolveDispatch(dispatchProjection(baseCapabilities), { type: "start_immediately" }, "auto"), { type: "steer_active", targetRunId: activeRunId }, ); assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( + resolveDispatch( dispatchProjection( capabilities((current) => ({ ...current, @@ -101,7 +106,7 @@ it("resolves automatic message delivery from authoritative provider capabilities { type: "queue_after_active" }, ); assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( + resolveDispatch( dispatchProjection( capabilities((current) => ({ ...current, @@ -125,7 +130,7 @@ it.each(["preparing", "starting"] as const)( (status) => { const projection = dispatchProjection(baseCapabilities); assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( + resolveDispatch( { ...projection, runs: projection.runs.map((run) => ({ ...run, status })) }, { type: "start_immediately" }, "auto", @@ -148,22 +153,17 @@ it.each([ ...dispatchProjection(baseCapabilities), providerTurns, } as unknown as OrchestrationV2ThreadProjection; - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent(projection, { type: "start_immediately" }, "auto"), - { type: "queue_after_active" }, - ); - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent(projection, { type: "start_immediately" }, "steer"), - { type: "steer_active", targetRunId: activeRunId }, - ); - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - projection, - { type: "start_immediately" }, - "restart", - ), - { type: "restart_active", targetRunId: activeRunId }, - ); + assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "auto"), { + type: "queue_after_active", + }); + assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "steer"), { + type: "steer_active", + targetRunId: activeRunId, + }); + assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "restart"), { + type: "restart_active", + targetRunId: activeRunId, + }); }); // regression: #26695 an interrupt-restart steer cancels Copilot's background agents @@ -180,32 +180,23 @@ it("queues a steer for a provider that cannot steer either way", () => { })), ); for (const deliveryIntent of ["auto", "steer"] as const) { - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - projection, - { type: "start_immediately" }, - deliveryIntent, - ), - { type: "queue_after_active" }, - ); + assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, deliveryIntent), { + type: "queue_after_active", + }); } assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent(projection, { + resolveDispatch(projection, { type: "steer_active", targetRunId: activeRunId, }), { type: "queue_after_active" }, ); + assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "restart"), { + type: "restart_active", + targetRunId: activeRunId, + }); assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - projection, - { type: "start_immediately" }, - "restart", - ), - { type: "restart_active", targetRunId: activeRunId }, - ); - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent(projection, { + resolveDispatch(projection, { type: "steer_active", targetRunId: RunId.make("command-policy-missing-run"), }), @@ -223,11 +214,7 @@ it("does not steer a Grok follow-up by interrupting its running turn", () => { ).capabilities; const projection = dispatchProjection(grok); for (const deliveryIntent of ["auto", "steer"] as const) { - const mode = CommandPolicy.resolveMessageDispatchIntent( - projection, - { type: "start_immediately" }, - deliveryIntent, - ); + const mode = resolveDispatch(projection, { type: "start_immediately" }, deliveryIntent); assert.isFalse( mode.type === "steer_active" && !grok.turns.supportsActiveSteering, `${deliveryIntent} follow-up resolved to ${mode.type} by interrupt-restart`, @@ -243,15 +230,30 @@ it("steers a Grok follow-up into its running turn without restarting it", () => >[0], "/home/ada", ).capabilities; - const mode = CommandPolicy.resolveMessageDispatchIntent( - dispatchProjection(grok), - { type: "start_immediately" }, - "steer", - ); + const mode = resolveDispatch(dispatchProjection(grok), { type: "start_immediately" }, "steer"); assert.strictEqual(mode.type, "steer_active"); assert.isTrue(grok.turns.supportsActiveSteering); }); +// regression: #32606 a slash command steered into a running turn replaced the task +it.each([ + ["/compact", { type: "queue_after_active" }], + ["/context", { type: "queue_after_active" }], + [" /context all\n", { type: "queue_after_active" }], + ["/plugin:review-pr 12", { type: "queue_after_active" }], + ["/home/me/x.ts fails", { type: "steer_active", targetRunId: activeRunId }], + ["/ context", { type: "steer_active", targetRunId: activeRunId }], + ["$skill /context", { type: "steer_active", targetRunId: activeRunId }], +] as const)("steers %j only when it is not a slash command", (text, expected) => { + const projection = dispatchProjection(baseCapabilities); + for (const deliveryIntent of ["auto", "steer"] as const) { + assert.deepEqual( + resolveDispatch(projection, { type: "start_immediately" }, deliveryIntent, text), + expected, + ); + } +}); + it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) => { const projection = dispatchProjection(baseCapabilities); const maintenance = { @@ -259,30 +261,21 @@ it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) = messages: [{ id: userMessageId, text, attachments: [] }], } as unknown as OrchestrationV2ThreadProjection; for (const deliveryIntent of ["auto", "steer"] as const) { - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - maintenance, - { type: "start_immediately" }, - deliveryIntent, - ), - { type: "queue_after_active" }, - ); + assert.deepEqual(resolveDispatch(maintenance, { type: "start_immediately" }, deliveryIntent), { + type: "queue_after_active", + }); } assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent(maintenance, { + resolveDispatch(maintenance, { type: "steer_active", targetRunId: activeRunId, }), { type: "queue_after_active" }, ); - assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( - maintenance, - { type: "start_immediately" }, - "restart", - ), - { type: "restart_active", targetRunId: activeRunId }, - ); + assert.deepEqual(resolveDispatch(maintenance, { type: "start_immediately" }, "restart"), { + type: "restart_active", + targetRunId: activeRunId, + }); }); const layer = it.layer(CommandPolicy.layer); diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index 451ca978b9e51..4d033e20605cc 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -81,6 +81,14 @@ export function isNativeMaintenanceCommand(message: { ); } +/** A message that only invokes a slash command, such as `/context all`, not a path like `/src/a.ts`. */ +export function isSlashCommand(message: { + readonly text: string; + readonly attachments: ReadonlyArray; +}): boolean { + return message.attachments.length === 0 && /^\/[\w:-]+(?:\s|$)/u.test(message.text.trim()); +} + /** * 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. @@ -102,6 +110,25 @@ export function goalCommandStopsActiveRun( } export function resolveMessageDispatchIntent( + projection: OrchestrationV2ThreadProjection, + message: Pick< + Extract, + "dispatchMode" | "deliveryIntent" | "text" | "attachments" + >, +): MessageDispatchMode { + const mode = resolveActiveRunDispatchIntent( + projection, + message.dispatchMode, + message.deliveryIntent, + ); + // A provider runs a steered command in place of the turn's task, so commands wait. + return mode.type === "steer_active" && isSlashCommand(message) + ? { type: "queue_after_active" } + : mode; +} + +/** How a message joins active work when it is free to steer. */ +export function resolveActiveRunDispatchIntent( projection: OrchestrationV2ThreadProjection, requestedMode: MessageDispatchMode, deliveryIntent?: "auto" | "steer" | "restart", diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 00939843c13f1..33951f1f3dbbf 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -126,6 +126,8 @@ import { isNativeMaintenanceCommand, providerSwitchWaitsForTurn, providerTurnCapabilities, + isSlashCommand, + resolveActiveRunDispatchIntent, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; import { CommandReceiptStoreV2, type CommandReceiptV2 } from "./CommandReceiptStore.ts"; @@ -6308,6 +6310,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio }); } yield* ensureSteeringMessage(input.command, input); + // An explicit restart already gives up the turn, so only steering holds commands back. + if (!input.forceRestart && isSlashCommand(input)) { + return yield* new OrchestratorDispatchError({ + commandId: input.command.commandId, + commandType: input.command.type, + cause: + "Commands must run as a separate turn. Queue it or wait for the active turn to finish.", + }); + } const targetMessage = input.projection.messages.find( (message) => message.id === targetRun.userMessageId, ); @@ -7416,11 +7427,18 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio projection = applyToProjection(projection, event); } let modelSelection = command.modelSelection ?? projection.thread.modelSelection; - let dispatchMode = resolveMessageDispatchIntent( - projection, - command.dispatchMode, - command.deliveryIntent, - ); + // Native goal commands must not steer an existing turn. + const parsedGoalCommand = parseGoalCommand(command); + const goalCommand = + parsedGoalCommand === null || + (yield* goalDriverFor(command, modelSelection.instanceId)) === undefined + ? null + : parsedGoalCommand; + // A goal command keeps the run it was sent at; the goal handling below queues it. + let dispatchMode = + goalCommand === null + ? resolveMessageDispatchIntent(projection, command) + : resolveActiveRunDispatchIntent(projection, command.dispatchMode, command.deliveryIntent); if (dispatchMode.type === "steer_active" || dispatchMode.type === "restart_active") { const targetRunId = dispatchMode.targetRunId; const target = projection.runs.find((run) => run.id === targetRunId); @@ -7515,13 +7533,6 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ) { dispatchMode = { type: "queue_after_active" }; } - // Native goal commands must not steer an existing turn. - const parsedGoalCommand = parseGoalCommand(command); - const goalCommand = - parsedGoalCommand === null || - (yield* goalDriverFor(command, modelSelection.instanceId)) === undefined - ? null - : parsedGoalCommand; let queuedRunStop: | { readonly runId: RunId; readonly reason: string; readonly skipsHeldQueue?: true } | undefined; @@ -11856,8 +11867,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio cause: "A message that asks for a result can't steer the current turn.", }); } - if (goalCommand !== null) { - yield* ensureGoalCommandSupported(command, queuedMessage, modelSelection.instanceId); + // A steered command replaces the turn's task, so promoting one only moves it first. + if (goalCommand !== null || isSlashCommand(queuedMessage)) { + if (goalCommand !== null) { + yield* ensureGoalCommandSupported(command, queuedMessage, modelSelection.instanceId); + } const goal = projection.providerThreads.find( (candidate) => candidate.id === target?.providerThreadId, )?.goal; @@ -11871,6 +11885,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio payload: { ...queuedRun, queuePosition: 1 }, }); const stops = + goalCommand !== null && target !== undefined && isLiveRun(target) && goalCommandStopsActiveRun(goalCommand, goal?.status ?? null) && @@ -14182,7 +14197,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ), ); - /** Puts a queued goal command first and, given a target, stops the run in its way. */ + /** Puts a queued command first and, given a target, stops the run in its way. */ const stopRunForQueuedCommand = Effect.fn("Orchestrator.stopRunForQueuedCommand")( function* (input: { readonly command: Extract< diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index cc14fde257da8..eaede9daed13a 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -998,16 +998,18 @@ it.effect.each( const maintenance = (yield* orchestrator.getThreadProjection(threadId)).runs.find( (candidate) => candidate.userMessageId === MessageId.make(`message:${text}`), )!; - const error = yield* orchestrator - .dispatch({ - type: "queued-message.promote-to-steer", - commandId: CommandId.make(`promote-${text}`), - threadId, - queuedRunId: maintenance.id, - targetRunId: run.id, - }) - .pipe(Effect.flip); - assert.equal(error._tag, "OrchestratorDispatchError"); + yield* orchestrator.dispatch({ + type: "queued-message.promote-to-steer", + commandId: CommandId.make(`promote-${text}`), + threadId, + queuedRunId: maintenance.id, + targetRunId: run.id, + }); + const promoted = (yield* orchestrator.getThreadProjection(threadId)).runs.find( + (candidate) => candidate.id === maintenance.id, + )!; + assert.equal(promoted.status, "queued"); + assert.equal(promoted.queuePosition, 1); } const command = { type: "queued-message.promote-to-steer" as const, @@ -3165,15 +3167,12 @@ it.effect.each([undefined, false, true])( const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; const threadId = yield* startFirstTurn; yield* send("queued", "queued", "queue"); - const sending = send("goal", "/goal all tests pass", "auto"); - if (nativeGoals === false) { - yield* Effect.flip(sending); - } else yield* sending; + yield* send("goal", "/goal all tests pass", "auto"); yield* worker.drain(); assert.deepEqual(steered, []); assert.deepEqual(yield* read(threadId), { - queue: ["queued"], + queue: nativeGoals === false ? ["queued", "/goal all tests pass"] : ["queued"], started: nativeGoals === false ? ["first"] : ["first", "/goal all tests pass"], stopRequested: nativeGoals !== false, }); @@ -3472,6 +3471,70 @@ it.effect("queues a goal clear without stopping work when no goal drives it", () }), ); +it.effect("promoting a queued /context moves it first and does not steer", () => + Effect.gen(function* () { + const { started, steered, layer, startFirstTurn, send, read } = + yield* goalHarness("slash-promote"); + yield* Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const threadId = yield* startFirstTurn; + yield* send("queued", "queued", "queue"); + yield* send("context", "/context", "queue"); + const queuedRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find( + (run) => run.userMessageId === MessageId.make("message:context"), + )!; + yield* orchestrator.dispatch({ + type: "queued-message.promote-to-steer", + commandId: CommandId.make("promote"), + threadId, + queuedRunId: queuedRun.id, + targetRunId: started[0]!.runId, + }); + yield* worker.drain(); + + assert.deepEqual(steered, []); + assert.deepEqual(yield* read(threadId), { + queue: ["/context", "queued"], + started: ["first"], + stopRequested: false, + }); + }).pipe(Effect.provide(layer)); + }), +); + +it.effect("restarts the turn for a slash command sent as an explicit restart", () => + Effect.gen(function* () { + const { started, steered, interrupted, layer, startFirstTurn } = + yield* nextTurnSelectionHarness("slash-restart", true); + yield* Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const threadId = yield* startFirstTurn; + yield* orchestrator.dispatch({ + type: "message.dispatch", + commandId: CommandId.make("restart-context"), + threadId, + messageId: MessageId.make("message:restart-context"), + text: "/context", + attachments: [], + modelSelection: runSelection, + dispatchMode: { type: "restart_active", targetRunId: started[0]!.runId }, + createdBy: "user", + creationSource: "web", + }); + yield* worker.drain(); + + assert.deepEqual(steered, []); + assert.lengthOf(interrupted, 1); + assert.deepEqual( + started.map((turn) => turn.message.text), + ["first", "/context"], + ); + }).pipe(Effect.provide(layer)); + }), +); + it.effect("promotes a queued goal by stopping the running turn", () => Effect.gen(function* () { const { started, steered, layer, startFirstTurn, send, read } = @@ -3504,6 +3567,38 @@ it.effect("promotes a queued goal by stopping the running turn", () => }), ); +it.effect("stops the running turn for a goal an agent steers into it", () => + Effect.gen(function* () { + const { started, steered, layer, startFirstTurn, read } = yield* goalHarness("goal-raw-steer"); + yield* Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const threadId = yield* startFirstTurn; + // Agent sends carry a raw steer target and no delivery intent. + yield* orchestrator.dispatch({ + type: "message.dispatch", + commandId: CommandId.make("goal"), + threadId, + messageId: MessageId.make("message:goal"), + text: "/goal ship it", + attachments: [], + modelSelection: runSelection, + dispatchMode: { type: "steer_active", targetRunId: started[0]!.runId }, + createdBy: "agent", + creationSource: "server", + }); + yield* worker.drain(); + + assert.deepEqual(steered, []); + assert.deepEqual(yield* read(threadId), { + queue: [], + started: ["first", "/goal ship it"], + stopRequested: true, + }); + }).pipe(Effect.provide(layer)); + }), +); + // A fresh message skips compaction as its own turn, which steering a running turn would not. it.effect.each(["next", "/goal ship it", "fresh next"])( "promoting %s into a compaction stops it and sends it next", diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts index 2a3a8e5510550..73eaabdde2016 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts @@ -913,7 +913,7 @@ it.effect("keeps native maintenance commands out of steering and restart message attachments: [], dispatchMode: { type: scenario.mode, targetRunId: targetRun.id }, }); - if (scenario.name.startsWith("steer-")) { + if (scenario.mode === "steer_active") { yield* dispatch; const queued = (yield* threads.getThreadProjection(launched.threadId)).runs[1]; assert.equal(queued?.status, "queued"); diff --git a/docs/user/composer.md b/docs/user/composer.md index 94b0219e5ab5a..4556b5dbda0fd 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -69,6 +69,9 @@ are saved on the server and can be edited or removed before they send. When Enter sends, `Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux uses the opposite action: it steers when your default is Queue and queues when your default is Steer. +A slash command such as `/context` always waits for the current turn to finish, +because a command steered into a turn would replace the agent's task. Sending a +queued command now moves it to the front of the queue. If your **Send shortcut** requires `Cmd+Enter` or `Ctrl+Enter`, that shortcut uses your default follow-up behavior; add **Shift** to use the opposite action. This applies only to multiline messages when you choose the multiline send option. From b2c248c697c608658a7a844126e30f6510d08d8b Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:41:04 +0000 Subject: [PATCH 2/6] fix(server): notices that start with a slash still queue, and document the goal exception A delegated-task notice whose text starts like a command (such as "/review is ready") was forced into a steer and then refused. It now stays queued. The composer docs also say that a new goal can still stop the running turn. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/Orchestrator.ts | 2 ++ .../SteeringCompletion.integration.test.ts | 7 ++++--- docs/user/composer.md | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 33951f1f3dbbf..efff2767cc54f 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -7683,6 +7683,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio const commandNotice = noticeKind === "command" && command.creationSource === "server"; if ( !freshContext && + // Steering refuses a command, so a notice that reads like one stays queued. + !isSlashCommand(command) && (delegatedCompletion !== undefined ? delegatedCompletion.taskIds.every( (id) => diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index eaede9daed13a..ce18d3f81c041 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -711,14 +711,15 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function* it.effect.each([ { notice: "delegated task question", goal: null, steers: true }, + { notice: "delegated task question", goal: null, steers: false, summary: "/review is ready" }, { notice: "background command", goal: "active", steers: true }, { notice: "background command", goal: null, steers: false }, ] as const)( "a $notice notice steers into the running turn: $steers (goal $goal)", - ({ notice, goal, steers }) => + ({ notice, goal, steers, ...row }) => Effect.gen(function* () { const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness( - `notice-steer-${notice.replaceAll(" ", "-")}-${goal ?? "none"}`, + `notice-steer-${notice.replaceAll(" ", "-")}-${goal ?? "none"}-${steers}`, ); yield* Effect.gen(function* () { const orchestrator = yield* Orchestrator.OrchestratorV2; @@ -762,7 +763,7 @@ it.effect.each([ childThreadId: ThreadId.make("thread:question-child"), }, outcome: "updated" as const, - summary: "Delegated task has a question", + summary: "summary" in row ? row.summary : "Delegated task has a question", } : { source: { kind: "command" as const }, diff --git a/docs/user/composer.md b/docs/user/composer.md index 4556b5dbda0fd..7914a09c18136 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -69,9 +69,10 @@ are saved on the server and can be edited or removed before they send. When Enter sends, `Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux uses the opposite action: it steers when your default is Queue and queues when your default is Steer. -A slash command such as `/context` always waits for the current turn to finish, -because a command steered into a turn would replace the agent's task. Sending a -queued command now moves it to the front of the queue. +A slash command such as `/compact` or `/context` waits for the current turn to +finish, because a command steered into a turn would replace the agent's task. +Sending a queued command now moves it to the front of the queue. A new +[goal](#goals) is the exception: it can stop the current turn to start. If your **Send shortcut** requires `Cmd+Enter` or `Ctrl+Enter`, that shortcut uses your default follow-up behavior; add **Shift** to use the opposite action. This applies only to multiline messages when you choose the multiline send option. From cd0e6626119cd4797cf9cabf59acfd6fc82895ff Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:54:54 +0000 Subject: [PATCH 3/6] test(scenarios): /compact sent while the agent works waits for the turn Co-Authored-By: Claude Opus 5.5 --- .../steered-compact-waits-for-turn.e2e.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/scenarios/steered-compact-waits-for-turn.e2e.ts diff --git a/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts b/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts new file mode 100644 index 0000000000000..b2678a44b837c --- /dev/null +++ b/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts @@ -0,0 +1,28 @@ +import { expect } from "e2e"; + +import { test, WEB } from "./t3.ts"; + +test("/compact sent while the agent works waits for the turn", WEB, async ({ t3, app, screen }) => { + const project = await t3.project("demo"); + // The showcase recording streams for several seconds, long enough to send into its turn. + const thread = await t3.thread({ + project, + title: "Long work", + messages: ["Show me around"], + model: "showcase", + }); + await t3.open(thread); + + const composer = screen.getByRole("textbox"); + await composer.tap(); + await composer.pressSequentially("Show me again"); + await composer.press("Enter"); + await expect(screen.getByRole("button", "Stop generation")).toBeVisible(); + + // The trailing space closes the slash menu so Enter sends instead of picking a command. + await composer.pressSequentially("/compact "); + await composer.press("Enter"); + await app.screenshot("compact-sent"); + + await expect(screen.getByRole("button", "Edit queued message")).toBeVisible(); +}); From 7adc7e226d465d971ca08224056fa48f0deae3db Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:06:04 +0000 Subject: [PATCH 4/6] fix: a command edited into a deferred steer stays queued, and Send now says it moves commands first A steer waiting for its turn to start that is edited into a slash command no longer jumps to the front of the queue on every provider turn update; the edit drops its steer-when-ready mark. The slash-command rule moves to @t3tools/shared/composerTrigger so web's Send now tooltip can say a queued command moves to the front of the queue instead of into the current turn. The composer docs say the same. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/CommandPolicy.ts | 9 +------- .../src/orchestration-v2/Orchestrator.ts | 21 ++++++++++++++++++- .../SteeringCompletion.integration.test.ts | 6 ++++++ .../src/components/chat/QueuedRunsControl.tsx | 15 +++++++++---- apps/web/src/i18n/translations/de.json | 4 +++- apps/web/src/i18n/translations/en.json | 4 +++- apps/web/src/i18n/translations/es.json | 4 +++- apps/web/src/i18n/translations/fr.json | 4 +++- apps/web/src/i18n/translations/ja.json | 4 +++- apps/web/src/i18n/translations/ko.json | 4 +++- apps/web/src/i18n/translations/pt-BR.json | 4 +++- apps/web/src/i18n/translations/ru.json | 4 +++- apps/web/src/i18n/translations/sv.json | 4 +++- apps/web/src/i18n/translations/zh.json | 4 +++- docs/user/composer.md | 8 +++---- packages/shared/src/composerTrigger.ts | 8 +++++++ 16 files changed, 80 insertions(+), 27 deletions(-) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index 4d033e20605cc..69050e4f8c149 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -10,6 +10,7 @@ import { ProviderInstanceId, ThreadId, } from "@t3tools/contracts"; +import { isSlashCommand } from "@t3tools/shared/composerTrigger"; import { latestExecutedRun } from "@t3tools/shared/orchestrationV2ThreadError"; import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; @@ -81,14 +82,6 @@ export function isNativeMaintenanceCommand(message: { ); } -/** A message that only invokes a slash command, such as `/context all`, not a path like `/src/a.ts`. */ -export function isSlashCommand(message: { - readonly text: string; - readonly attachments: ReadonlyArray; -}): boolean { - return message.attachments.length === 0 && /^\/[\w:-]+(?:\s|$)/u.test(message.text.trim()); -} - /** * 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 efff2767cc54f..27e128dfaf562 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -92,6 +92,7 @@ import { isPlaceholderThreadTitle } from "./placeholderThreadTitle.ts"; import { combinePullRequestWatchWakes, type PullRequestWatchWake } from "./pullRequestWatch.ts"; import { outputRequestProblem } from "./runOutput.ts"; import { recordThreadOpen } from "@t3tools/shared/paletteSearch"; +import { isSlashCommand } from "@t3tools/shared/composerTrigger"; import { backgroundWorkHoldsCompletion, derivePendingBackgroundWork, @@ -126,7 +127,6 @@ import { isNativeMaintenanceCommand, providerSwitchWaitsForTurn, providerTurnCapabilities, - isSlashCommand, resolveActiveRunDispatchIntent, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; @@ -12315,6 +12315,25 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio }), }); } + // A command cannot steer, so an edit into one keeps it queued where it is. + if ( + queuedRun.steerWhenReadyRunId !== undefined && + isSlashCommand({ + text: command.text, + attachments: command.attachments ?? queuedMessage.attachments, + }) + ) { + const { steerWhenReadyRunId: _, ...queued } = queuedRun; + yield* emitEvent({ + type: "run.updated", + threadId: command.threadId, + runId: queuedRun.id, + ...(queuedRun.rootNodeId === null ? {} : { nodeId: queuedRun.rootNodeId }), + providerInstanceId: queuedRun.providerInstanceId, + occurredAt: now, + payload: queued, + }); + } // Thread deletion only cleans files the thread still references. const keptAttachmentIds = new Set( (command.attachments ?? queuedMessage.attachments).map((attachment) => attachment.id), diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index ce18d3f81c041..3ef67192ceb77 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -946,6 +946,7 @@ it.effect.each( const edited = (yield* orchestrator.getThreadProjection(threadId)).runs.find( (candidate) => candidate.userMessageId === MessageId.make("message:edited-steer"), )!; + assert.equal(edited.steerWhenReadyRunId, run.id); yield* orchestrator.dispatch({ type: "queued-run.edit", commandId: CommandId.make("edit-steer-to-compact"), @@ -953,6 +954,11 @@ it.effect.each( runId: edited.id, text: "/compact", }); + const compact = (yield* orchestrator.getThreadProjection(threadId)).runs.find( + (candidate) => candidate.id === edited.id, + )!; + assert.isUndefined(compact.steerWhenReadyRunId); + assert.equal(compact.queuePosition, edited.queuePosition); } if (direct) { yield* orchestrator.dispatch({ diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx index fb82f9c858d61..9b897213a33a6 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.tsx @@ -5,6 +5,7 @@ import { } from "@t3tools/client-runtime/state/runtime"; import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows"; import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations"; +import { isSlashCommand } from "@t3tools/shared/composerTrigger"; import { isAttachmentOnlyBootstrapPrompt, replaceComposerContextReferences, @@ -323,14 +324,20 @@ export function QueuedRunsControl({ ? gt("Skip compaction and send this message ({shortcut})", { shortcut: props.steerShortcutLabel, }) - : gt("Send into the current turn ({shortcut})", { - shortcut: props.steerShortcutLabel, - }) + : isSlashCommand(item) + ? gt("Move this command to the front of the queue ({shortcut})", { + shortcut: props.steerShortcutLabel, + }) + : gt("Send into the current turn ({shortcut})", { + shortcut: props.steerShortcutLabel, + }) : workflow?.canSendNow ? gt("Start a turn with this message") : workflow?.promoteSkipsCompaction ? gt("Skip compaction and send this message") - : gt("Send into the current turn")} + : isSlashCommand(item) + ? gt("Move this command to the front of the queue") + : gt("Send into the current turn")} diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 0e48b30d674da..4f60fef9f6088 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -12458,5 +12458,7 @@ "27d76249d09eb69f": "Review-Leitfaden bereit", "faa3bb26abb39c93": "Review-Leitfaden fehlgeschlagen", "b7df38b7d8792d78": "Leitfaden öffnen", - "9e91e9a77b664e4e": "Review-Leitfaden konnte nicht gestartet werden" + "9e91e9a77b664e4e": "Review-Leitfaden konnte nicht gestartet werden", + "d8aaf932f90429c4": "Diesen Befehl an den Anfang der Warteschlange verschieben ({shortcut})", + "425ab15036aec8a4": "Diesen Befehl an den Anfang der Warteschlange verschieben" } diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index e5d8d3dc2ed21..6453de11f9da0 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -12467,5 +12467,7 @@ "27d76249d09eb69f": "Review guide ready", "faa3bb26abb39c93": "Review guide failed", "b7df38b7d8792d78": "Open guide", - "9e91e9a77b664e4e": "Could not start a review guide" + "9e91e9a77b664e4e": "Could not start a review guide", + "d8aaf932f90429c4": "Move this command to the front of the queue ({shortcut})", + "425ab15036aec8a4": "Move this command to the front of the queue" } diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 4a2868a7e97dc..a73a02ec3bcc9 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -12453,5 +12453,7 @@ "27d76249d09eb69f": "Guía de revisión lista", "faa3bb26abb39c93": "Falló la guía de revisión", "b7df38b7d8792d78": "Abrir guía", - "9e91e9a77b664e4e": "No se pudo iniciar una guía de revisión" + "9e91e9a77b664e4e": "No se pudo iniciar una guía de revisión", + "d8aaf932f90429c4": "Mover este comando al principio de la cola ({shortcut})", + "425ab15036aec8a4": "Mover este comando al principio de la cola" } diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index a0962e52bed39..95ea50d6bf22d 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -12458,5 +12458,7 @@ "27d76249d09eb69f": "Guide de revue prêt", "faa3bb26abb39c93": "Échec du guide de revue", "b7df38b7d8792d78": "Ouvrir le guide", - "9e91e9a77b664e4e": "Impossible de démarrer un guide de revue" + "9e91e9a77b664e4e": "Impossible de démarrer un guide de revue", + "d8aaf932f90429c4": "Placer cette commande en tête de la file d’attente ({shortcut})", + "425ab15036aec8a4": "Placer cette commande en tête de la file d’attente" } diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 0c149c28fbe91..96bf9c7c7bf48 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -12407,5 +12407,7 @@ "27d76249d09eb69f": "レビューガイドの準備ができました", "faa3bb26abb39c93": "レビューガイドの作成に失敗しました", "b7df38b7d8792d78": "ガイドを開く", - "9e91e9a77b664e4e": "レビューガイドを開始できませんでした" + "9e91e9a77b664e4e": "レビューガイドを開始できませんでした", + "d8aaf932f90429c4": "このコマンドをキューの先頭に移動 ({shortcut})", + "425ab15036aec8a4": "このコマンドをキューの先頭に移動" } diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index c01191b387b4f..d7b1a7628ffc6 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -12402,5 +12402,7 @@ "27d76249d09eb69f": "검토 가이드 준비됨", "faa3bb26abb39c93": "검토 가이드 실패", "b7df38b7d8792d78": "가이드 열기", - "9e91e9a77b664e4e": "검토 가이드를 시작할 수 없습니다" + "9e91e9a77b664e4e": "검토 가이드를 시작할 수 없습니다", + "d8aaf932f90429c4": "이 명령을 대기열 맨 앞으로 이동 ({shortcut})", + "425ab15036aec8a4": "이 명령을 대기열 맨 앞으로 이동" } diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 5feb95d75c3da..5097324486fb8 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -12458,5 +12458,7 @@ "27d76249d09eb69f": "Guia de revisão pronto", "faa3bb26abb39c93": "O guia de revisão falhou", "b7df38b7d8792d78": "Abrir guia", - "9e91e9a77b664e4e": "Não foi possível iniciar um guia de revisão" + "9e91e9a77b664e4e": "Não foi possível iniciar um guia de revisão", + "d8aaf932f90429c4": "Mover este comando para o início da fila ({shortcut})", + "425ab15036aec8a4": "Mover este comando para o início da fila" } diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 65a8eede879fa..4c19189200eb5 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -12458,5 +12458,7 @@ "27d76249d09eb69f": "Гид по ревью готов", "faa3bb26abb39c93": "Не удалось создать гид по ревью", "b7df38b7d8792d78": "Открыть гид", - "9e91e9a77b664e4e": "Не удалось запустить гид по ревью" + "9e91e9a77b664e4e": "Не удалось запустить гид по ревью", + "d8aaf932f90429c4": "Переместить эту команду в начало очереди ({shortcut})", + "425ab15036aec8a4": "Переместить эту команду в начало очереди" } diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 081857c5dae81..7add0fa009b1d 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -12465,5 +12465,7 @@ "27d76249d09eb69f": "Granskningsguiden är klar", "faa3bb26abb39c93": "Granskningsguiden misslyckades", "b7df38b7d8792d78": "Öppna guiden", - "9e91e9a77b664e4e": "Kunde inte starta en granskningsguide" + "9e91e9a77b664e4e": "Kunde inte starta en granskningsguide", + "d8aaf932f90429c4": "Flytta det här kommandot först i kön ({shortcut})", + "425ab15036aec8a4": "Flytta det här kommandot först i kön" } diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 17d0dd6a93303..5a5c7160230de 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -12484,5 +12484,7 @@ "27d76249d09eb69f": "审查导览已就绪", "faa3bb26abb39c93": "审查导览生成失败", "b7df38b7d8792d78": "打开导览", - "9e91e9a77b664e4e": "无法开始生成审查导览" + "9e91e9a77b664e4e": "无法开始生成审查导览", + "d8aaf932f90429c4": "将此命令移到队列最前面 ({shortcut})", + "425ab15036aec8a4": "将此命令移到队列最前面" } diff --git a/docs/user/composer.md b/docs/user/composer.md index 7914a09c18136..0169e901e087f 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -71,8 +71,8 @@ the opposite action: it steers when your default is Queue and queues when your default is Steer. A slash command such as `/compact` or `/context` waits for the current turn to finish, because a command steered into a turn would replace the agent's task. -Sending a queued command now moves it to the front of the queue. A new -[goal](#goals) is the exception: it can stop the current turn to start. +Sending a queued command now moves it to the front of the queue. [Goal](#goals) +commands are the exception: some can stop the current turn. If your **Send shortcut** requires `Cmd+Enter` or `Ctrl+Enter`, that shortcut uses your default follow-up behavior; add **Shift** to use the opposite action. This applies only to multiline messages when you choose the multiline send option. @@ -275,8 +275,8 @@ shortcut described above. On web and desktop, queued messages appear at the end of the thread as dashed messages that have not been sent yet. On mobile they appear above the composer. Each shows its text and any attached -images. **Send now** sends a message right away, into the running turn if there is one. You can -also edit or remove it. +images. **Send now** sends a message right away, into the running turn if there is one; a slash +command moves to the front of the queue instead. You can also edit or remove it. If you stop the agent or the server restarts, queued messages keep their order and are held. Press **Resume** in an empty composer to continue. For stopped runs and usage limits, diff --git a/packages/shared/src/composerTrigger.ts b/packages/shared/src/composerTrigger.ts index 96a0a877d14df..2a95d6b34cd0a 100644 --- a/packages/shared/src/composerTrigger.ts +++ b/packages/shared/src/composerTrigger.ts @@ -137,6 +137,14 @@ export function replaceTextRange( return { text: nextText, cursor: safeStart + replacement.length }; } +/** A message that only invokes a slash command, such as `/context all`, not a path like `/src/a.ts`. */ +export function isSlashCommand(message: { + readonly text: string; + readonly attachments: ReadonlyArray; +}): boolean { + return message.attachments.length === 0 && /^\/[\w:-]+(?:\s|$)/u.test(message.text.trim()); +} + /** `/clear` as the whole message arms a fresh session instead of sending. */ export function isClearComposerCommand(text: string): boolean { return /^\/clear\s*$/i.test(text.trim()); From 8597fe9439d41ca6a37b4924d3289cd86ed8ccfa Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:09:34 +0000 Subject: [PATCH 5/6] fix(web): the Send now tooltip follows the text the server acts on A guest's queued message is decided on its attributed text, and a goal command can still stop the turn, so neither gets the "move to the front" tooltip. The docs say commands move first only while a turn runs. Co-Authored-By: Claude Opus 5.5 --- .../src/components/chat/QueuedRunsControl.tsx | 20 ++++---- docs/user/composer.md | 5 +- .../steered-compact-waits-for-turn.e2e.ts | 47 ++++++++++++++++++- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx index 9b897213a33a6..d8318b7279e7d 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.tsx @@ -10,12 +10,13 @@ import { isAttachmentOnlyBootstrapPrompt, replaceComposerContextReferences, } from "@t3tools/shared/composerContextReferences"; -import type { - ChatAttachment as ContractChatAttachment, - EnvironmentId, - MessageId, - RunId, - ThreadId, +import { + parseGoalCommand, + type ChatAttachment as ContractChatAttachment, + type EnvironmentId, + type MessageId, + type RunId, + type ThreadId, } from "@t3tools/contracts"; import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message"; import { Link } from "@tanstack/react-router"; @@ -274,6 +275,9 @@ export function QueuedRunsControl({ replaceComposerContextReferences(item.text, (reference) => reference.label), ).trim(); const isEditing = item.runId !== null && item.runId === props.editingRunId; + // The server decides on the agent's text, and a goal command can stop the turn. + const sentText = { text: item.message?.text ?? item.text, attachments: item.attachments }; + const movesCommandFirst = isSlashCommand(sentText) && parseGoalCommand(sentText) === null; return (
  • diff --git a/docs/user/composer.md b/docs/user/composer.md index 0169e901e087f..53017052a2a01 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -275,8 +275,9 @@ shortcut described above. On web and desktop, queued messages appear at the end of the thread as dashed messages that have not been sent yet. On mobile they appear above the composer. Each shows its text and any attached -images. **Send now** sends a message right away, into the running turn if there is one; a slash -command moves to the front of the queue instead. You can also edit or remove it. +images. **Send now** sends a message right away, into the running turn if there is one. While a +turn runs, a slash command moves to the front of the queue instead. You can also edit or +remove it. If you stop the agent or the server restarts, queued messages keep their order and are held. Press **Resume** in an empty composer to continue. For stopped runs and usage limits, diff --git a/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts b/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts index b2678a44b837c..7ed990805fd22 100644 --- a/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts +++ b/scripts/scenarios/steered-compact-waits-for-turn.e2e.ts @@ -1,6 +1,29 @@ import { expect } from "e2e"; +import * as Effect from "effect/Effect"; +import * as FileSystem from "effect/FileSystem"; +import * as Path from "effect/Path"; +import * as Schema from "effect/Schema"; -import { test, WEB } from "./t3.ts"; +import { T3_HOME } from "../e2e.config.ts"; +import { makeState, runPromise, test, WEB } from "./t3.ts"; + +const SettingsJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)); +const decodeSettings = Schema.decodeEffect(SettingsJson); +const encodeSettings = Schema.encodeEffect(SettingsJson); + +const threadRuntimeSettings = Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const settingsPath = (yield* Path.Path).join(T3_HOME, "userdata/settings.json"); + const original = yield* fs.readFileString(settingsPath); + const settings = yield* decodeSettings(original); + return { + supervise: fs.writeFileString( + settingsPath, + yield* encodeSettings({ ...settings, defaultRuntimeMode: "approval-required" }), + ), + restore: fs.writeFileString(settingsPath, original), + }; +}); test("/compact sent while the agent works waits for the turn", WEB, async ({ t3, app, screen }) => { const project = await t3.project("demo"); @@ -23,6 +46,26 @@ test("/compact sent while the agent works waits for the turn", WEB, async ({ t3, await composer.pressSequentially("/compact "); await composer.press("Enter"); await app.screenshot("compact-sent"); - await expect(screen.getByRole("button", "Edit queued message")).toBeVisible(); + + const settings = await runPromise(threadRuntimeSettings); + try { + // An approval holds this turn open, so the queued command stays put while Send now is hovered. + await runPromise(settings.supervise); + const waiting = await t3.thread({ + project, + title: "Waiting work", + messages: ["Change the file"], + model: "approval", + }); + await runPromise(makeState(T3_HOME).cli(["thread", "send", waiting.threadId, "/compact"])); + await t3.open(waiting); + await screen.getByRole("button", "Send now").hover(); + await expect( + screen.getByText("Move this command to the front of the queue", { exact: false }), + ).toBeVisible(); + await app.screenshot("send-now-tooltip"); + } finally { + await runPromise(settings.restore); + } }); From 9cffa8f6f6b35039490c7ca8b480980cf81c2f34 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 12:34:58 +0000 Subject: [PATCH 6/6] refactor(server): keep resolveMessageDispatchIntent's signature for the command wrapper The slash-command rule lives in a new resolveMessageDispatch wrapper, so the existing policy tests keep their call sites and only the #32606 case is new. Co-Authored-By: Claude Opus 5.5 --- .../orchestration-v2/CommandPolicy.test.ts | 135 +++++++++++------- .../src/orchestration-v2/CommandPolicy.ts | 6 +- .../src/orchestration-v2/Orchestrator.ts | 6 +- 3 files changed, 89 insertions(+), 58 deletions(-) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.test.ts b/apps/server/src/orchestration-v2/CommandPolicy.test.ts index 5b51aeffb4d82..d5b06dbf6c47f 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.test.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.test.ts @@ -65,30 +65,25 @@ function dispatchProjection( } as unknown as OrchestrationV2ThreadProjection; } -function resolveDispatch( - projection: OrchestrationV2ThreadProjection, - dispatchMode: Parameters[1]["dispatchMode"], - deliveryIntent?: "auto" | "steer" | "restart", - text = "next", -) { - return CommandPolicy.resolveMessageDispatchIntent(projection, { - dispatchMode, - ...(deliveryIntent === undefined ? {} : { deliveryIntent }), - text, - attachments: [], - }); -} - it("resolves automatic message delivery from authoritative provider capabilities", () => { - assert.deepEqual(resolveDispatch(dispatchProjection(), { type: "start_immediately" }, "auto"), { - type: "start_immediately", - }); assert.deepEqual( - resolveDispatch(dispatchProjection(baseCapabilities), { type: "start_immediately" }, "auto"), + CommandPolicy.resolveMessageDispatchIntent( + dispatchProjection(), + { type: "start_immediately" }, + "auto", + ), + { type: "start_immediately" }, + ); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent( + dispatchProjection(baseCapabilities), + { type: "start_immediately" }, + "auto", + ), { type: "steer_active", targetRunId: activeRunId }, ); assert.deepEqual( - resolveDispatch( + CommandPolicy.resolveMessageDispatchIntent( dispatchProjection( capabilities((current) => ({ ...current, @@ -106,7 +101,7 @@ it("resolves automatic message delivery from authoritative provider capabilities { type: "queue_after_active" }, ); assert.deepEqual( - resolveDispatch( + CommandPolicy.resolveMessageDispatchIntent( dispatchProjection( capabilities((current) => ({ ...current, @@ -130,7 +125,7 @@ it.each(["preparing", "starting"] as const)( (status) => { const projection = dispatchProjection(baseCapabilities); assert.deepEqual( - resolveDispatch( + CommandPolicy.resolveMessageDispatchIntent( { ...projection, runs: projection.runs.map((run) => ({ ...run, status })) }, { type: "start_immediately" }, "auto", @@ -153,17 +148,22 @@ it.each([ ...dispatchProjection(baseCapabilities), providerTurns, } as unknown as OrchestrationV2ThreadProjection; - assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "auto"), { - type: "queue_after_active", - }); - assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "steer"), { - type: "steer_active", - targetRunId: activeRunId, - }); - assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "restart"), { - type: "restart_active", - targetRunId: activeRunId, - }); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent(projection, { type: "start_immediately" }, "auto"), + { type: "queue_after_active" }, + ); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent(projection, { type: "start_immediately" }, "steer"), + { type: "steer_active", targetRunId: activeRunId }, + ); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent( + projection, + { type: "start_immediately" }, + "restart", + ), + { type: "restart_active", targetRunId: activeRunId }, + ); }); // regression: #26695 an interrupt-restart steer cancels Copilot's background agents @@ -180,23 +180,32 @@ it("queues a steer for a provider that cannot steer either way", () => { })), ); for (const deliveryIntent of ["auto", "steer"] as const) { - assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, deliveryIntent), { - type: "queue_after_active", - }); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent( + projection, + { type: "start_immediately" }, + deliveryIntent, + ), + { type: "queue_after_active" }, + ); } assert.deepEqual( - resolveDispatch(projection, { + CommandPolicy.resolveMessageDispatchIntent(projection, { type: "steer_active", targetRunId: activeRunId, }), { type: "queue_after_active" }, ); - assert.deepEqual(resolveDispatch(projection, { type: "start_immediately" }, "restart"), { - type: "restart_active", - targetRunId: activeRunId, - }); assert.deepEqual( - resolveDispatch(projection, { + CommandPolicy.resolveMessageDispatchIntent( + projection, + { type: "start_immediately" }, + "restart", + ), + { type: "restart_active", targetRunId: activeRunId }, + ); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent(projection, { type: "steer_active", targetRunId: RunId.make("command-policy-missing-run"), }), @@ -214,7 +223,11 @@ it("does not steer a Grok follow-up by interrupting its running turn", () => { ).capabilities; const projection = dispatchProjection(grok); for (const deliveryIntent of ["auto", "steer"] as const) { - const mode = resolveDispatch(projection, { type: "start_immediately" }, deliveryIntent); + const mode = CommandPolicy.resolveMessageDispatchIntent( + projection, + { type: "start_immediately" }, + deliveryIntent, + ); assert.isFalse( mode.type === "steer_active" && !grok.turns.supportsActiveSteering, `${deliveryIntent} follow-up resolved to ${mode.type} by interrupt-restart`, @@ -230,7 +243,11 @@ it("steers a Grok follow-up into its running turn without restarting it", () => >[0], "/home/ada", ).capabilities; - const mode = resolveDispatch(dispatchProjection(grok), { type: "start_immediately" }, "steer"); + const mode = CommandPolicy.resolveMessageDispatchIntent( + dispatchProjection(grok), + { type: "start_immediately" }, + "steer", + ); assert.strictEqual(mode.type, "steer_active"); assert.isTrue(grok.turns.supportsActiveSteering); }); @@ -248,7 +265,12 @@ it.each([ const projection = dispatchProjection(baseCapabilities); for (const deliveryIntent of ["auto", "steer"] as const) { assert.deepEqual( - resolveDispatch(projection, { type: "start_immediately" }, deliveryIntent, text), + CommandPolicy.resolveMessageDispatch(projection, { + dispatchMode: { type: "start_immediately" }, + deliveryIntent, + text, + attachments: [], + }), expected, ); } @@ -261,21 +283,30 @@ it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) = messages: [{ id: userMessageId, text, attachments: [] }], } as unknown as OrchestrationV2ThreadProjection; for (const deliveryIntent of ["auto", "steer"] as const) { - assert.deepEqual(resolveDispatch(maintenance, { type: "start_immediately" }, deliveryIntent), { - type: "queue_after_active", - }); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent( + maintenance, + { type: "start_immediately" }, + deliveryIntent, + ), + { type: "queue_after_active" }, + ); } assert.deepEqual( - resolveDispatch(maintenance, { + CommandPolicy.resolveMessageDispatchIntent(maintenance, { type: "steer_active", targetRunId: activeRunId, }), { type: "queue_after_active" }, ); - assert.deepEqual(resolveDispatch(maintenance, { type: "start_immediately" }, "restart"), { - type: "restart_active", - targetRunId: activeRunId, - }); + assert.deepEqual( + CommandPolicy.resolveMessageDispatchIntent( + maintenance, + { type: "start_immediately" }, + "restart", + ), + { type: "restart_active", targetRunId: activeRunId }, + ); }); const layer = it.layer(CommandPolicy.layer); diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index 69050e4f8c149..1319083cca030 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -102,14 +102,14 @@ export function goalCommandStopsActiveRun( } } -export function resolveMessageDispatchIntent( +export function resolveMessageDispatch( projection: OrchestrationV2ThreadProjection, message: Pick< Extract, "dispatchMode" | "deliveryIntent" | "text" | "attachments" >, ): MessageDispatchMode { - const mode = resolveActiveRunDispatchIntent( + const mode = resolveMessageDispatchIntent( projection, message.dispatchMode, message.deliveryIntent, @@ -121,7 +121,7 @@ export function resolveMessageDispatchIntent( } /** How a message joins active work when it is free to steer. */ -export function resolveActiveRunDispatchIntent( +export function resolveMessageDispatchIntent( projection: OrchestrationV2ThreadProjection, requestedMode: MessageDispatchMode, deliveryIntent?: "auto" | "steer" | "restart", diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 27e128dfaf562..e27fe09d07d1b 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -127,7 +127,7 @@ import { isNativeMaintenanceCommand, providerSwitchWaitsForTurn, providerTurnCapabilities, - resolveActiveRunDispatchIntent, + resolveMessageDispatch, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; import { CommandReceiptStoreV2, type CommandReceiptV2 } from "./CommandReceiptStore.ts"; @@ -7437,8 +7437,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio // A goal command keeps the run it was sent at; the goal handling below queues it. let dispatchMode = goalCommand === null - ? resolveMessageDispatchIntent(projection, command) - : resolveActiveRunDispatchIntent(projection, command.dispatchMode, command.deliveryIntent); + ? resolveMessageDispatch(projection, command) + : resolveMessageDispatchIntent(projection, command.dispatchMode, command.deliveryIntent); if (dispatchMode.type === "steer_active" || dispatchMode.type === "restart_active") { const targetRunId = dispatchMode.targetRunId; const target = projection.runs.find((run) => run.id === targetRunId);