From be5f88cd750eec07b37967f8839d7773cc1fe391 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 19:26:22 +0000 Subject: [PATCH 1/6] test(server): a /context sent during a running turn queues instead of steering (#32606) Reproduces #32606: a slash command such as /context or /context all sent with automatic delivery while a provider that supports active steering is mid-turn is steered into that turn instead of queued behind it. Co-Authored-By: Claude Opus 5.5 --- .../SteeringCompletion.integration.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index 2b08c0b8345b6..1b007b5696108 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -1594,6 +1594,29 @@ it.effect("queues a goal clear without stopping work when no goal drives it", () ), ); +// regression: #32606 a slash command steered into a running turn replaced the task +it.effect("queues a slash command sent into a running turn instead of steering it", () => + Effect.scoped( + Effect.gen(function* () { + const { steered, layer, startFirstTurn, send, read } = yield* goalHarness("slash-steer"); + yield* Effect.gen(function* () { + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const threadId = yield* startFirstTurn; + yield* send("context", "/context", "auto"); + yield* send("context-all", "/context all", "auto"); + yield* worker.drain(); + + assert.deepEqual(steered, []); + assert.deepEqual(yield* read(threadId), { + queue: ["/context", "/context all"], + started: ["first"], + stopRequested: false, + }); + }).pipe(Effect.provide(layer)); + }), + ), +); + it.effect("promotes a queued goal by stopping the running turn", () => Effect.scoped( Effect.gen(function* () { From 71bc014d212a70e4536c033978beb4f7339bbcfc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 19:38:33 +0000 Subject: [PATCH 2/6] fix(server): slash commands sent during a turn queue instead of steering A slash command such as /context sent while a provider that supports active steering was mid-turn was steered into that turn. Claude Code runs a steered command in place of the turn's task, so the task was dropped. The dispatch policy now queues any message that is only a slash command (`/name` followed by whitespace or the end, no attachments) instead of steering it, for automatic, explicit and agent sends alike. Promoting a queued slash command to Steer is rejected the way /goal already was. Goal commands keep stopping the active run for set and resume, including for agent sends that request a steer without a delivery intent. An explicit steer of /compact or /logout now queues instead of failing. Fixes pingdotgg/t3code#32606 Co-Authored-By: Claude Opus 5.5 --- .../orchestration-v2/CommandPolicy.test.ts | 133 +++++++++--------- .../src/orchestration-v2/CommandPolicy.ts | 18 ++- .../src/orchestration-v2/Orchestrator.ts | 21 ++- .../SteeringCompletion.integration.test.ts | 36 +++++ .../ThreadLaunchService.test.ts | 2 +- 5 files changed, 128 insertions(+), 82 deletions(-) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.test.ts b/apps/server/src/orchestration-v2/CommandPolicy.test.ts index 8ed4de3e9dea0..3651f6925805f 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.test.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.test.ts @@ -63,25 +63,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, @@ -99,7 +104,7 @@ it("resolves automatic message delivery from authoritative provider capabilities { type: "queue_after_active" }, ); assert.deepEqual( - CommandPolicy.resolveMessageDispatchIntent( + resolveDispatch( dispatchProjection( capabilities((current) => ({ ...current, @@ -123,7 +128,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", @@ -146,22 +151,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 @@ -178,32 +178,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"), }), @@ -211,6 +202,23 @@ it("queues a steer for a provider that cannot steer either way", () => { ); }); +it.each([ + ["/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 = { @@ -218,30 +226,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 02f329e536feb..97d3ae05d15f5 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -69,6 +69,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. @@ -91,11 +99,15 @@ export function goalCommandStopsActiveRun( export function resolveMessageDispatchIntent( projection: OrchestrationV2ThreadProjection, - requestedMode: MessageDispatchMode, - deliveryIntent?: "auto" | "steer" | "restart", + message: Pick< + Extract, + "dispatchMode" | "deliveryIntent" | "text" | "attachments" + >, ): MessageDispatchMode { - const mode = resolveDeliveryIntent(projection, requestedMode, deliveryIntent); + const mode = resolveDeliveryIntent(projection, message.dispatchMode, message.deliveryIntent); if (mode.type !== "steer_active") return mode; + // A provider runs a steered command in place of the turn's task, so commands wait. + if (isSlashCommand(message)) return { type: "queue_after_active" }; // Compaction and sign-out cannot accept steers; queue follow-ups. const target = projection.runs.find((run) => run.id === mode.targetRunId); const targetMessage = projection.messages.find((message) => message.id === target?.userMessageId); diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 5d3c4391b1fe8..d52601af47b5d 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -108,6 +108,7 @@ import { goalCommandStopsActiveRun, isActiveRun, isNativeMaintenanceCommand, + isSlashCommand, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; import { CommandReceiptStoreV2, type CommandReceiptV2 } from "./CommandReceiptStore.ts"; @@ -4921,12 +4922,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.", }); } - if (parseGoalCommand(input) !== null) { + if (isSlashCommand(input)) { 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.", + "Commands must run as a separate turn. Queue it or wait for the active turn to finish.", }); } const targetMessage = input.projection.messages.find( @@ -5826,11 +5827,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio projection = applyToProjection(projection, event); } const modelSelection = command.modelSelection ?? projection.thread.modelSelection; - let dispatchMode = resolveMessageDispatchIntent( - projection, - command.dispatchMode, - command.deliveryIntent, - ); + let dispatchMode = resolveMessageDispatchIntent(projection, command); if (dispatchMode.type === "steer_active") { const targetRunId = dispatchMode.targetRunId; const target = projection.runs.find((run) => run.id === targetRunId); @@ -5880,13 +5877,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio yield* ensureGoalCommandSupported(command, command, modelSelection.instanceId); // A goal command never joins a running turn. One that starts or ends goal // work stops the run and goes first in the queue; the rest wait. A send - // that asked to be queued (no delivery intent) only queues, and a run - // that is only finishing or running background work is never stopped. + // that asked to be queued only queues, and a run that is only finishing + // or running background work is never stopped. const resolvedMode = dispatchMode; const target = - resolvedMode.type === "steer_active" || resolvedMode.type === "restart_active" + resolvedMode.type === "restart_active" ? projection.runs.find((run) => run.id === resolvedMode.targetRunId) - : resolvedMode.type === "queue_after_active" && command.deliveryIntent !== undefined + : resolvedMode.type === "queue_after_active" && + (command.deliveryIntent !== undefined || + command.dispatchMode.type !== "queue_after_active") ? projection.runs.findLast(isLiveRun) : undefined; if (target !== undefined) { diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index 1b007b5696108..194044ed036ff 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -1617,6 +1617,42 @@ it.effect("queues a slash command sent into a running turn instead of steering i ), ); +it.effect("keeps a queued slash command queued when promoted to steer", () => + Effect.scoped( + 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("context", "/context", "queue"); + const queuedRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find( + (run) => run.userMessageId === MessageId.make("message:context"), + )!; + const promoteError = yield* orchestrator + .dispatch({ + type: "queued-message.promote-to-steer", + commandId: CommandId.make("promote"), + threadId, + queuedRunId: queuedRun.id, + targetRunId: started[0]!.runId, + }) + .pipe(Effect.flip); + yield* worker.drain(); + + assert.include(String(promoteError.cause), "Commands must run as a separate turn"); + assert.deepEqual(steered, []); + assert.deepEqual(yield* read(threadId), { + queue: ["/context"], + started: ["first"], + stopRequested: false, + }); + }).pipe(Effect.provide(layer)); + }), + ), +); + it.effect("promotes a queued goal by stopping the running turn", () => Effect.scoped( Effect.gen(function* () { diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts index 23b46afceca58..d76ea68445c96 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts @@ -709,7 +709,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"); From 5a8ae860f65ac8f14283e9ba5bcf325182173ec5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 19:58:01 +0000 Subject: [PATCH 3/6] fix(server): queued slash commands move first instead of failing to steer Queueing mid-turn slash commands left three regressions: - "Send now" on a queued slash command always failed, because promoting it steered and steering now rejects commands. Promoting one now moves it to the front of the queue through the same path a queued /goal uses, without steering or stopping the turn. /compact and /logout follow the same rule since they are slash commands. - An explicit restart with a slash command failed. Only steering rejects slash commands now; a restart still rejects /goal as before. - A /goal aimed at a finished run could stop the run that replaced it. Goal commands skip the slash-command queueing, so they keep the run they were sent at and the goal handling decides as before. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/CommandPolicy.ts | 21 ++- .../src/orchestration-v2/Orchestrator.ts | 50 ++++-- .../SteeringCompletion.integration.test.ts | 146 ++++++++++++++++-- 3 files changed, 185 insertions(+), 32 deletions(-) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index 97d3ae05d15f5..a3007c0d7a165 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -104,10 +104,25 @@ export function resolveMessageDispatchIntent( "dispatchMode" | "deliveryIntent" | "text" | "attachments" >, ): MessageDispatchMode { - const mode = resolveDeliveryIntent(projection, message.dispatchMode, message.deliveryIntent); - if (mode.type !== "steer_active") return mode; + const mode = resolveActiveRunDispatchIntent( + projection, + message.dispatchMode, + message.deliveryIntent, + ); // A provider runs a steered command in place of the turn's task, so commands wait. - if (isSlashCommand(message)) return { type: "queue_after_active" }; + 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", +): MessageDispatchMode { + const mode = resolveDeliveryIntent(projection, requestedMode, deliveryIntent); + if (mode.type !== "steer_active") return mode; // Compaction and sign-out cannot accept steers; queue follow-ups. const target = projection.runs.find((run) => run.id === mode.targetRunId); const targetMessage = projection.messages.find((message) => message.id === target?.userMessageId); diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index d52601af47b5d..ae4ab7ad1a1fc 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -109,6 +109,7 @@ import { isActiveRun, isNativeMaintenanceCommand, isSlashCommand, + resolveActiveRunDispatchIntent, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; import { CommandReceiptStoreV2, type CommandReceiptV2 } from "./CommandReceiptStore.ts"; @@ -4922,7 +4923,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.", }); } - if (isSlashCommand(input)) { + 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.", + }); + } + // 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, @@ -5827,7 +5837,18 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio projection = applyToProjection(projection, event); } const modelSelection = command.modelSelection ?? projection.thread.modelSelection; - let dispatchMode = resolveMessageDispatchIntent(projection, command); + // Codex and Claude own /goal; elsewhere it is ordinary text that cannot steer. + 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") { const targetRunId = dispatchMode.targetRunId; const target = projection.runs.find((run) => run.id === targetRunId); @@ -5865,27 +5886,18 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ) { dispatchMode = { type: "queue_after_active" }; } - // Codex and Claude own /goal; elsewhere it is ordinary text that cannot steer. - const parsedGoalCommand = parseGoalCommand(command); - const goalCommand = - parsedGoalCommand === null || - (yield* goalDriverFor(command, modelSelection.instanceId)) === undefined - ? null - : parsedGoalCommand; let goalStopRunId: RunId | undefined; if (goalCommand !== null) { yield* ensureGoalCommandSupported(command, command, modelSelection.instanceId); // A goal command never joins a running turn. One that starts or ends goal // work stops the run and goes first in the queue; the rest wait. A send - // that asked to be queued only queues, and a run that is only finishing - // or running background work is never stopped. + // that asked to be queued (no delivery intent) only queues, and a run + // that is only finishing or running background work is never stopped. const resolvedMode = dispatchMode; const target = - resolvedMode.type === "restart_active" + resolvedMode.type === "steer_active" || resolvedMode.type === "restart_active" ? projection.runs.find((run) => run.id === resolvedMode.targetRunId) - : resolvedMode.type === "queue_after_active" && - (command.deliveryIntent !== undefined || - command.dispatchMode.type !== "queue_after_active") + : resolvedMode.type === "queue_after_active" && command.deliveryIntent !== undefined ? projection.runs.findLast(isLiveRun) : undefined; if (target !== undefined) { @@ -9866,8 +9878,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio cause: "A message that starts a fresh session can't steer the current turn.", }); } - if (goalCommand !== null) { - yield* ensureGoalCommandSupported(command, queuedMessage, queuedRun.providerInstanceId); + // 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, queuedRun.providerInstanceId); + } const goal = projection.providerThreads.find( (candidate) => candidate.id === target?.providerThreadId, )?.goal; @@ -9881,6 +9896,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) && diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index 194044ed036ff..c5a844bfc6eed 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -1617,7 +1617,7 @@ it.effect("queues a slash command sent into a running turn instead of steering i ), ); -it.effect("keeps a queued slash command queued when promoted to steer", () => +it.effect("promoting a queued /context moves it first and does not steer", () => Effect.scoped( Effect.gen(function* () { const { started, steered, layer, startFirstTurn, send, read } = @@ -1626,25 +1626,23 @@ it.effect("keeps a queued slash command queued when promoted to steer", () => 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"), )!; - const promoteError = yield* orchestrator - .dispatch({ - type: "queued-message.promote-to-steer", - commandId: CommandId.make("promote"), - threadId, - queuedRunId: queuedRun.id, - targetRunId: started[0]!.runId, - }) - .pipe(Effect.flip); + 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.include(String(promoteError.cause), "Commands must run as a separate turn"); assert.deepEqual(steered, []); assert.deepEqual(yield* read(threadId), { - queue: ["/context"], + queue: ["/context", "queued"], started: ["first"], stopRequested: false, }); @@ -1653,6 +1651,40 @@ it.effect("keeps a queued slash command queued when promoted to steer", () => ), ); +it.effect("restarts the turn for a slash command sent as an explicit restart", () => + Effect.scoped( + 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.scoped( Effect.gen(function* () { @@ -1687,6 +1719,96 @@ it.effect("promotes a queued goal by stopping the running turn", () => ), ); +it.effect("queues a goal aimed at a finished turn without stopping the next one", () => + Effect.scoped( + Effect.gen(function* () { + const { events, started, steered, layer, startFirstTurn, send } = + yield* goalHarness("goal-stale-target"); + yield* Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const threadId = yield* startFirstTurn; + yield* send("second", "second", "queue"); + const settled = yield* orchestrator.streamDomainEvents.pipe( + Stream.filter( + (event) => + event.type === "run.updated" && + event.payload.id === started[0]!.runId && + event.payload.status === "waiting", + ), + Stream.take(1), + Stream.runDrain, + Effect.forkScoped, + ); + const secondRunning = yield* orchestrator.streamDomainEvents.pipe( + Stream.filter( + (event) => + event.type === "provider-turn.updated" && + event.payload.status === "running" && + event.payload.runAttemptId !== started[0]!.attemptId, + ), + Stream.take(1), + Stream.runDrain, + Effect.forkScoped, + ); + const turn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!; + yield* Queue.offer(events, { + type: "provider_turn.updated", + driver, + providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now }, + }); + yield* Queue.offer(events, { + type: "turn.terminal", + driver, + providerThreadId: turn.providerThreadId, + providerTurnId: turn.id, + runOrdinal: started[0]!.runOrdinal, + status: "completed", + failure: null, + threadDisposition: "reusable", + }); + yield* Fiber.join(settled); + yield* worker.drain(); + yield* orchestrator.resumeQueuedRuns; + yield* worker.drain(); + yield* Fiber.join(secondRunning); + + 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: "user", + creationSource: "web", + }); + yield* worker.drain(); + + const projection = yield* orchestrator.getThreadProjection(threadId); + assert.deepEqual(steered, []); + assert.deepEqual( + started.map((turn) => turn.message.text), + ["first", "second"], + ); + assert.isFalse( + projection.turnItems.some( + (item) => item.type === "run_interrupt_request" && item.runId === started[1]!.runId, + ), + ); + assert.deepEqual( + projection.runs + .filter((run) => run.status === "queued") + .map((run) => projection.messages.find((m) => m.id === run.userMessageId)?.text), + ["/goal ship it"], + ); + }).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", From 2830b48e55d655f266a513402f2aa62aa4212a40 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 20:09:25 +0000 Subject: [PATCH 4/6] test(server): pin the agent /goal steer the goal exception protects Replace the stale-target goal test, which passed without the change, with one that fails if goal commands lose their base dispatch path. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Orchestrator.ts | 2 +- .../SteeringCompletion.integration.test.ts | 77 +++---------------- 2 files changed, 12 insertions(+), 67 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index ae4ab7ad1a1fc..2147dd23bbd66 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -12119,7 +12119,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 c5a844bfc6eed..ef2cb1555a925 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -1719,60 +1719,16 @@ it.effect("promotes a queued goal by stopping the running turn", () => ), ); -it.effect("queues a goal aimed at a finished turn without stopping the next one", () => +it.effect("stops the running turn for a goal an agent steers into it", () => Effect.scoped( Effect.gen(function* () { - const { events, started, steered, layer, startFirstTurn, send } = - yield* goalHarness("goal-stale-target"); + 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; - yield* send("second", "second", "queue"); - const settled = yield* orchestrator.streamDomainEvents.pipe( - Stream.filter( - (event) => - event.type === "run.updated" && - event.payload.id === started[0]!.runId && - event.payload.status === "waiting", - ), - Stream.take(1), - Stream.runDrain, - Effect.forkScoped, - ); - const secondRunning = yield* orchestrator.streamDomainEvents.pipe( - Stream.filter( - (event) => - event.type === "provider-turn.updated" && - event.payload.status === "running" && - event.payload.runAttemptId !== started[0]!.attemptId, - ), - Stream.take(1), - Stream.runDrain, - Effect.forkScoped, - ); - const turn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!; - yield* Queue.offer(events, { - type: "provider_turn.updated", - driver, - providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now }, - }); - yield* Queue.offer(events, { - type: "turn.terminal", - driver, - providerThreadId: turn.providerThreadId, - providerTurnId: turn.id, - runOrdinal: started[0]!.runOrdinal, - status: "completed", - failure: null, - threadDisposition: "reusable", - }); - yield* Fiber.join(settled); - yield* worker.drain(); - yield* orchestrator.resumeQueuedRuns; - yield* worker.drain(); - yield* Fiber.join(secondRunning); - + // Agent sends carry a raw steer target and no delivery intent. yield* orchestrator.dispatch({ type: "message.dispatch", commandId: CommandId.make("goal"), @@ -1782,28 +1738,17 @@ it.effect("queues a goal aimed at a finished turn without stopping the next one" attachments: [], modelSelection: runSelection, dispatchMode: { type: "steer_active", targetRunId: started[0]!.runId }, - createdBy: "user", - creationSource: "web", + createdBy: "agent", + creationSource: "server", }); yield* worker.drain(); - const projection = yield* orchestrator.getThreadProjection(threadId); assert.deepEqual(steered, []); - assert.deepEqual( - started.map((turn) => turn.message.text), - ["first", "second"], - ); - assert.isFalse( - projection.turnItems.some( - (item) => item.type === "run_interrupt_request" && item.runId === started[1]!.runId, - ), - ); - assert.deepEqual( - projection.runs - .filter((run) => run.status === "queued") - .map((run) => projection.messages.find((m) => m.id === run.userMessageId)?.text), - ["/goal ship it"], - ); + assert.deepEqual(yield* read(threadId), { + queue: [], + started: ["first", "/goal ship it"], + stopRequested: true, + }); }).pipe(Effect.provide(layer)); }), ), From 72b6d903fa772e591c5e5da1c41fc01323fda0c1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 20:13:48 +0000 Subject: [PATCH 5/6] docs: slash commands wait for the running turn Co-Authored-By: Claude Opus 5.5 --- docs/user/composer.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/user/composer.md b/docs/user/composer.md index 22b499ebe7b0c..85d96b750fb3f 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 55138fa36c48a19015e9b3a5caa48ce35ce4b498 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 20:52:10 +0000 Subject: [PATCH 6/6] test(server): slash commands without native goals queue behind a running turn A /goal on a provider with no native goals is a plain slash command, so it now queues instead of failing to steer. Drop the integration case that repeated the CommandPolicy table. AI-assisted; verified with the tests and tools listed above. --- .../orchestration-v2/CommandPolicy.test.ts | 1 + .../SteeringCompletion.integration.test.ts | 30 ++----------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.test.ts b/apps/server/src/orchestration-v2/CommandPolicy.test.ts index 3651f6925805f..c13005c069ae8 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.test.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.test.ts @@ -202,6 +202,7 @@ it("queues a steer for a provider that cannot steer either way", () => { ); }); +// regression: #32606 a slash command steered into a running turn replaced the task it.each([ ["/context", { type: "queue_after_active" }], [" /context all\n", { type: "queue_after_active" }], diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index cf8317bd5e546..60ffda9bfa8ef 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -2124,15 +2124,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, }); @@ -2203,29 +2200,6 @@ it.effect("queues a goal clear without stopping work when no goal drives it", () ), ); -// regression: #32606 a slash command steered into a running turn replaced the task -it.effect("queues a slash command sent into a running turn instead of steering it", () => - Effect.scoped( - Effect.gen(function* () { - const { steered, layer, startFirstTurn, send, read } = yield* goalHarness("slash-steer"); - yield* Effect.gen(function* () { - const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; - const threadId = yield* startFirstTurn; - yield* send("context", "/context", "auto"); - yield* send("context-all", "/context all", "auto"); - yield* worker.drain(); - - assert.deepEqual(steered, []); - assert.deepEqual(yield* read(threadId), { - queue: ["/context", "/context all"], - started: ["first"], - stopRequested: false, - }); - }).pipe(Effect.provide(layer)); - }), - ), -); - it.effect("promoting a queued /context moves it first and does not steer", () => Effect.scoped( Effect.gen(function* () {