@devries-cameron20 / t3code-1 / commits / b20bbc595d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix: deliver steering after worktree setup (#34581)

Yash Singh committed Nov 11, 2026 at 16:31 UTC b20bbc595d5968d5754f07dcc103f324e0fe0d36
10 files changed +476 -78
apps/server/src/orchestration-v2/Orchestrator.ts
+150 -18
@@ -5315,6 +5315,33 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5315 });
5316 });
5317
5318 + const ensureSteeringMessage = Effect.fn("Orchestrator.ensureSteeringMessage")(function* (
5319 + command: Extract<
5320 + OrchestrationV2Command,
5321 + { readonly type: "message.dispatch" | "queued-message.promote-to-steer" }
5322 + >,
5323 + message: Pick<OrchestrationV2ConversationMessage, "text" | "attachments" | "context">,
5324 + ) {
5325 + if (isNativeMaintenanceCommand(message)) {
5326 + return yield* new OrchestratorDispatchError({
5327 + commandId: command.commandId,
5328 + commandType: command.type,
5329 + cause:
5330 + message.text.trim().toLowerCase() === "/compact"
5331 + ? "Context compaction must run as a separate turn. Queue it or wait for the active turn to finish."
5332 + : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.",
5333 + });
5334 + }
5335 + if (parseGoalCommand(message) !== null) {
5336 + return yield* new OrchestratorDispatchError({
5337 + commandId: command.commandId,
5338 + commandType: command.type,
5339 + cause:
5340 + "Goal commands must run as a separate turn. Queue it or wait for the active turn to finish.",
5341 + });
5342 + }
5343 + });
5344 +
5345 const dispatchSteerIntoRun = Effect.fn("Orchestrator.dispatchSteerIntoRun")(function* (input: {
5346 readonly command: Extract<
5347 OrchestrationV2Command,
@@ -5358,24 +5385,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5385 cause: `Target run ${input.targetRunId} was not found.`,
5386 });
5387 }
5361 - if (isNativeMaintenanceCommand(input)) {
5362 - return yield* new OrchestratorDispatchError({
5363 - commandId: input.command.commandId,
5364 - commandType: input.command.type,
5365 - cause:
5366 - input.text.trim().toLowerCase() === "/compact"
5367 - ? "Context compaction must run as a separate turn. Queue it or wait for the active turn to finish."
5368 - : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.",
5369 - });
5370 - }
5371 - if (parseGoalCommand(input) !== null) {
5372 - return yield* new OrchestratorDispatchError({
5373 - commandId: input.command.commandId,
5374 - commandType: input.command.type,
5375 - cause:
5376 - "Goal commands must run as a separate turn. Queue it or wait for the active turn to finish.",
5377 - });
5378 - }
5388 + yield* ensureSteeringMessage(input.command, input);
5389 const targetMessage = input.projection.messages.find(
5390 (message) => message.id === targetRun.userMessageId,
5391 );
@@ -6563,6 +6573,36 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6573 payload: { ...sourcePlan, status: "completed" },
6574 });
6575
6576 + let steerWhenReadyRunId: RunId | undefined;
6577 + if (dispatchMode.type === "steer_active") {
6578 + const targetRunId = dispatchMode.targetRunId;
6579 + const target = projection.runs.find((run) => run.id === targetRunId);
6580 + if (
6581 + (target?.status === "preparing" ||
6582 + target?.status === "starting" ||
6583 + (target?.status === "running" &&
6584 + !projection.providerTurns.some(
6585 + (turn) => turn.runAttemptId === target.activeAttemptId && turn.status === "running",
6586 + ))) &&
6587 + !(yield* stopReachedRun(command, command.threadId, target.id))
6588 + ) {
6589 + const adapter = yield* providerAdapters
6590 + .get(target.providerInstanceId)
6591 + .pipe(mapDispatchError(command));
6592 + const capabilities = yield* adapter.getCapabilities().pipe(mapDispatchError(command));
6593 + yield* commandPolicy
6594 + .decideSteeringExecution({
6595 + commandId: command.commandId,
6596 + threadId: command.threadId,
6597 + providerInstanceId: target.providerInstanceId,
6598 + capabilities,
6599 + })
6600 + .pipe(mapDispatchError(command));
6601 + yield* ensureSteeringMessage(command, command);
6602 + steerWhenReadyRunId = target.id;
6603 + dispatchMode = { type: "queue_after_active" };
6604 + }
6605 + }
6606 if (dispatchMode.type === "steer_active" || dispatchMode.type === "restart_active") {
6607 yield* ensureGoalCommandSupported(command, command, modelSelection.instanceId);
6608 yield* dispatchSteerIntoRun({
@@ -6623,6 +6663,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6663 const incomingMessage = { ...command, delegatedCompletion };
6664 if (
6665 shouldQueue &&
6666 + steerWhenReadyRunId === undefined &&
6667 command.modelSelection === undefined &&
6668 queuedRunStop === undefined &&
6669 !followsCurrentConversation(incomingMessage) &&
@@ -6777,6 +6818,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6818 rootNodeId,
6819 activeAttemptId: attemptId,
6820 status: "queued",
6821 + ...(steerWhenReadyRunId === undefined ? {} : { steerWhenReadyRunId }),
6822 ...(worktreeMissingRun !== undefined ||
6823 (heldRunsToRelease.length === 0 &&
6824 queueIsHeld &&
@@ -10413,6 +10455,39 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
10455 now,
10456 });
10457 }
10458 + if (
10459 + (target?.status === "preparing" ||
10460 + target?.status === "starting" ||
10461 + (target?.status === "running" &&
10462 + !projection.providerTurns.some(
10463 + (turn) => turn.runAttemptId === target.activeAttemptId && turn.status === "running",
10464 + ))) &&
10465 + !(yield* stopReachedRun(command, command.threadId, target.id))
10466 + ) {
10467 + yield* ensureSteeringMessage(command, queuedMessage);
10468 + const adapter = yield* providerAdapters
10469 + .get(target.providerInstanceId)
10470 + .pipe(mapDispatchError(command));
10471 + const capabilities = yield* adapter.getCapabilities().pipe(mapDispatchError(command));
10472 + yield* commandPolicy
10473 + .decideSteeringExecution({
10474 + commandId: command.commandId,
10475 + threadId: command.threadId,
10476 + providerInstanceId: target.providerInstanceId,
10477 + capabilities,
10478 + })
10479 + .pipe(mapDispatchError(command));
10480 + yield* emitEvent({
10481 + type: "run.updated",
10482 + threadId: command.threadId,
10483 + runId: queuedRun.id,
10484 + nodeId: queuedRootNode.id,
10485 + providerInstanceId: queuedRun.providerInstanceId,
10486 + occurredAt: now,
10487 + payload: { ...queuedRun, steerWhenReadyRunId: target.id },
10488 + });
10489 + return;
10490 + }
10491 yield* emitEvent({
10492 type: "run.updated",
10493 threadId: command.threadId,
@@ -14613,6 +14688,63 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
14688 Effect.forkScoped,
14689 );
14690
14691 + yield* eventSink
14692 + .stream({ afterSequence: terminalEventsAfterSequence, eventType: "provider-turn.updated" })
14693 + .pipe(
14694 + Stream.filter(
14695 + (stored) =>
14696 + stored.event.type === "provider-turn.updated" &&
14697 + stored.event.payload.status === "running",
14698 + ),
14699 + Stream.runForEach(
14700 + Effect.fn("Orchestrator.deliverDeferredSteers")(
14701 + function* (stored) {
14702 + if (stored.event.type !== "provider-turn.updated") return;
14703 + const threadId = stored.event.threadId;
14704 + const turn = stored.event.payload;
14705 + const projection = yield* projectionStore.getThreadRecords(threadId, ["runs"]);
14706 + const run = projection.runs.find(
14707 + (candidate) =>
14708 + candidate.activeAttemptId === turn.runAttemptId && candidate.status === "running",
14709 + );
14710 + if (run === undefined) return;
14711 + const pending = projection.runs
14712 + .filter(
14713 + (queued) => queued.status === "queued" && queued.steerWhenReadyRunId === run.id,
14714 + )
14715 + .toSorted(
14716 + (left, right) =>
14717 + (left.queuePosition ?? left.ordinal) - (right.queuePosition ?? right.ordinal),
14718 + );
14719 + for (const queued of pending) {
14720 + yield* dispatchWithReceiptEffect({
14721 + type: "queued-message.promote-to-steer",
14722 + commandId: CommandId.make(
14723 + `command:deferred-steer:${queued.id}:${run.id}:${turn.runAttemptId}`,
14724 + ),
14725 + threadId,
14726 + queuedRunId: queued.id,
14727 + targetRunId: run.id,
14728 + }).pipe(
14729 + Effect.catchCause((cause) =>
14730 + Effect.logWarning("Failed to deliver a deferred steer", {
14731 + threadId,
14732 + runId: queued.id,
14733 + cause,
14734 + }),
14735 + ),
14736 + );
14737 + }
14738 + },
14739 + (effect, stored) => threadDispatch.withLock(stored.event.threadId, effect),
14740 + Effect.catchCause((cause) =>
14741 + Effect.logWarning("Failed to deliver deferred steering", { cause }),
14742 + ),
14743 + ),
14744 + ),
14745 + Effect.forkScoped,
14746 + );
14747 +
14748 // A child whose run ends while its background tasks or its own subagents still run has no
14749 // result yet. When that work settles there is no run update to finalize it, so these events
14750 // do it. A background roster counts once it stops holding after it was seen holding.
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+301 -48
@@ -847,6 +847,230 @@ it.effect("sends a selected held message once and preserves the remaining queue
847 ),
848 );
849
850 +it.effect.each(
851 + (["preparing", "starting", "running"] as const).flatMap((status) =>
852 + [false, true].map((direct) => ({ status, direct })),
853 + ),
854 +)("delivers a deferred steer for a $status run (direct: $direct)", ({ status, direct }) =>
855 + Effect.scoped(
856 + Effect.gen(function* () {
857 + const restarting = status === "starting" && !direct;
858 + const { started, steered, layer, startFirstTurn, events } = yield* nextTurnSelectionHarness(
859 + `deferred-steer-${status}-${direct}`,
860 + restarting,
861 + !restarting,
862 + );
863 + yield* Effect.gen(function* () {
864 + const orchestrator = yield* Orchestrator.OrchestratorV2;
865 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
866 + const threadId = yield* startFirstTurn;
867 + const before = yield* orchestrator.getThreadProjection(threadId);
868 + const run = before.runs[0]!;
869 + const turn = before.providerTurns[0]!;
870 + const now = yield* DateTime.now;
871 + yield* (yield* EventSink.EventSinkV2).write({
872 + events: [
873 + {
874 + id: EventId.make("setup-run"),
875 + type: "run.updated",
876 + threadId,
877 + occurredAt: now,
878 + payload: { ...run, status },
879 + },
880 + {
881 + id: EventId.make("setup-turn"),
882 + type: "provider-turn.updated",
883 + threadId,
884 + occurredAt: now,
885 + payload: { ...turn, status: "pending" },
886 + },
887 + ],
888 + });
889 + if (status === "preparing" && !direct) {
890 + yield* orchestrator.dispatch({
891 + type: "message.dispatch",
892 + commandId: CommandId.make("edited-steer"),
893 + threadId,
894 + messageId: MessageId.make("message:edited-steer"),
895 + text: "edit this steer",
896 + attachments: [],
897 + deliveryIntent: "steer",
898 + dispatchMode: { type: "queue_after_active" },
899 + createdBy: "user",
900 + creationSource: "web",
901 + });
902 + const edited = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
903 + (candidate) => candidate.userMessageId === MessageId.make("message:edited-steer"),
904 + )!;
905 + yield* orchestrator.dispatch({
906 + type: "queued-run.edit",
907 + commandId: CommandId.make("edit-steer-to-compact"),
908 + threadId,
909 + runId: edited.id,
910 + text: "/compact",
911 + });
912 + }
913 + if (direct) {
914 + yield* orchestrator.dispatch({
915 + type: "message.dispatch",
916 + commandId: CommandId.make("earlier-queue"),
917 + threadId,
918 + messageId: MessageId.make("message:earlier-queue"),
919 + text: "earlier queued selection",
920 + modelSelection: composerSelection,
921 + attachments: [],
922 + dispatchMode: { type: "queue_after_active" },
923 + createdBy: "user",
924 + creationSource: "web",
925 + });
926 + }
927 + yield* orchestrator.dispatch({
928 + type: "message.dispatch",
929 + commandId: CommandId.make("queue"),
930 + threadId,
931 + messageId: MessageId.make("message:steer-after-setup"),
932 + text: "steer after setup",
933 + attachments: [],
934 + dispatchMode: { type: "queue_after_active" },
935 + ...(direct ? { deliveryIntent: "steer" as const } : {}),
936 + createdBy: "user",
937 + creationSource: "web",
938 + });
939 + const queued = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
940 + (candidate) => candidate.userMessageId === MessageId.make("message:steer-after-setup"),
941 + )!;
942 + assert.deepEqual(queued.modelSelection, runSelection);
943 + for (const text of ["/compact", "/logout"]) {
944 + yield* orchestrator.dispatch({
945 + type: "message.dispatch",
946 + commandId: CommandId.make(`queue-${text}`),
947 + threadId,
948 + messageId: MessageId.make(`message:${text}`),
949 + text,
950 + attachments: [],
951 + dispatchMode: { type: "queue_after_active" },
952 + createdBy: "user",
953 + creationSource: "web",
954 + });
955 + const maintenance = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
956 + (candidate) => candidate.userMessageId === MessageId.make(`message:${text}`),
957 + )!;
958 + const error = yield* orchestrator
959 + .dispatch({
960 + type: "queued-message.promote-to-steer",
961 + commandId: CommandId.make(`promote-${text}`),
962 + threadId,
963 + queuedRunId: maintenance.id,
964 + targetRunId: run.id,
965 + })
966 + .pipe(Effect.flip);
967 + assert.equal(error._tag, "OrchestratorDispatchError");
968 + }
969 + const command = {
970 + type: "queued-message.promote-to-steer" as const,
971 + commandId: CommandId.make("promote"),
972 + threadId,
973 + queuedRunId: queued.id,
974 + targetRunId: run.id,
975 + };
976 + if (!direct) {
977 + yield* orchestrator.dispatch(command);
978 + yield* orchestrator.dispatch(command);
979 + }
980 + let secondQueuedId: typeof queued.id | undefined;
981 + if (restarting) {
982 + yield* orchestrator.dispatch({
983 + type: "message.dispatch",
984 + commandId: CommandId.make("second"),
985 + threadId,
986 + messageId: MessageId.make("message:second"),
987 + text: "second steer",
988 + attachments: [],
989 + dispatchMode: { type: "queue_after_active" },
990 + createdBy: "user",
991 + creationSource: "web",
992 + });
993 + secondQueuedId = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
994 + (candidate) => candidate.userMessageId === MessageId.make("message:second"),
995 + )!.id;
996 + yield* orchestrator.dispatch({
997 + ...command,
998 + commandId: CommandId.make("promote-second"),
999 + queuedRunId: secondQueuedId,
1000 + });
1001 + }
1002 + const secondReDeferred = yield* orchestrator.streamDomainEvents.pipe(
1003 + Stream.filter(
1004 + (event) =>
1005 + event.type === "run.updated" &&
1006 + event.payload.id === secondQueuedId &&
1007 + event.payload.status === "queued",
1008 + ),
1009 + Stream.take(1),
1010 + Stream.runDrain,
1011 + Effect.forkScoped,
1012 + );
1013 + const secondPromoted = yield* orchestrator.streamDomainEvents.pipe(
1014 + Stream.filter(
1015 + (event) =>
1016 + event.type === "run.updated" &&
1017 + event.payload.id === secondQueuedId &&
1018 + event.payload.status === "cancelled",
1019 + ),
1020 + Stream.take(1),
1021 + Stream.runDrain,
1022 + Effect.forkScoped,
1023 + );
1024 + yield* worker.drain();
1025 + assert.deepEqual(steered, []);
1026 + const promoted = yield* orchestrator.streamDomainEvents.pipe(
1027 + Stream.filter(
1028 + (event) =>
1029 + event.type === "run.updated" &&
1030 + event.payload.id === queued.id &&
1031 + event.payload.status === "cancelled",
1032 + ),
1033 + Stream.take(1),
1034 + Stream.runDrain,
1035 + Effect.forkScoped,
1036 + );
1037 + yield* (yield* EventSink.EventSinkV2).write({
1038 + events: [
1039 + {
1040 + id: EventId.make("ready-run"),
1041 + type: "run.updated",
1042 + threadId,
1043 + occurredAt: now,
1044 + payload: run,
1045 + },
1046 + ],
1047 + });
1048 + yield* Queue.offer(events, { type: "provider_turn.updated", driver, providerTurn: turn });
1049 + yield* Fiber.join(promoted);
1050 + if (restarting) yield* Fiber.join(secondReDeferred);
1051 + yield* worker.drain();
1052 + if (restarting) {
1053 + yield* Fiber.join(secondPromoted);
1054 + yield* worker.drain();
1055 + assert.deepEqual(
1056 + started.map((turn) => turn.message.text),
1057 + ["first", "steer after setup", "second steer"],
1058 + );
1059 + } else {
1060 + assert.deepEqual(steered, ["steer after setup"]);
1061 + assert.lengthOf(started, 1);
1062 + }
1063 + const after = yield* orchestrator.getThreadProjection(threadId);
1064 + assert.equal(
1065 + after.messages.find((message) => message.id === queued.userMessageId)?.runId,
1066 + run.id,
1067 + );
1068 + assert.equal(after.runs.find((candidate) => candidate.id === run.id)?.status, "running");
1069 + }).pipe(Effect.provide(layer));
1070 + }),
1071 + ),
1072 +);
1073 +
1074 it.effect("force sends multiple queued messages and can force send a requeued message again", () =>
1075 Effect.scoped(
1076 Effect.gen(function* () {
@@ -1781,61 +2005,90 @@ it.effect("keeps a queued message queued when promoted into a run that Stop reac
2005 );
2006
2007 // regression: #32891 a restart that Stop already reached is lost
1784 -it.effect("refuses a steer but starts a restart sent into a run that Stop reached", () =>
1785 - Effect.scoped(
1786 - Effect.gen(function* () {
1787 - const { started, steered, layer, startFirstTurn } =
1788 - yield* nextTurnSelectionHarness("restart-after-stop");
1789 - yield* Effect.gen(function* () {
1790 - const orchestrator = yield* Orchestrator.OrchestratorV2;
1791 - const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
1792 - const threadId = yield* startFirstTurn;
1793 - const first = started[0]!;
1794 - // The worker has not delivered the interrupt yet, so the run still reads as running.
1795 - yield* orchestrator.dispatch({
1796 - type: "run.interrupt",
1797 - commandId: CommandId.make("stop"),
1798 - threadId,
1799 - runId: first.runId,
1800 - });
1801 - const steerError = yield* orchestrator
1802 - .dispatch({
2008 +it.effect.each([false, true])(
2009 + "refuses a steer after Stop (provider turn ready: %s)",
2010 + (providerTurnReady) =>
2011 + Effect.scoped(
2012 + Effect.gen(function* () {
2013 + const { started, steered, layer, startFirstTurn } =
2014 + yield* nextTurnSelectionHarness("restart-after-stop");
2015 + yield* Effect.gen(function* () {
2016 + const orchestrator = yield* Orchestrator.OrchestratorV2;
2017 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2018 + const threadId = yield* startFirstTurn;
2019 + const first = started[0]!;
2020 + // The worker has not delivered the interrupt yet, so the run still reads as running.
2021 + yield* orchestrator.dispatch({
2022 + type: "run.interrupt",
2023 + commandId: CommandId.make("stop"),
2024 + threadId,
2025 + runId: first.runId,
2026 + });
2027 + const turn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!;
2028 + if (!providerTurnReady) {
2029 + yield* (yield* EventSink.EventSinkV2).write({
2030 + events: [
2031 + {
2032 + id: EventId.make("turn-not-ready"),
2033 + type: "provider-turn.updated",
2034 + threadId,
2035 + occurredAt: yield* DateTime.now,
2036 + payload: { ...turn, status: "pending" },
2037 + },
2038 + ],
2039 + });
2040 + }
2041 + const steerError = yield* orchestrator
2042 + .dispatch({
2043 + type: "message.dispatch",
2044 + commandId: CommandId.make("steer"),
2045 + threadId,
2046 + messageId: MessageId.make("message:steer"),
2047 + text: "steer",
2048 + attachments: [],
2049 + modelSelection: runSelection,
2050 + dispatchMode: { type: "steer_active", targetRunId: first.runId },
2051 + createdBy: "user",
2052 + creationSource: "web",
2053 + })
2054 + .pipe(Effect.flip);
2055 + assert.equal(steerError._tag, "OrchestratorDispatchError");
2056 + assert.include(String(steerError.cause), "is stopping and cannot be steered");
2057 + if (!providerTurnReady) {
2058 + yield* (yield* EventSink.EventSinkV2).write({
2059 + events: [
2060 + {
2061 + id: EventId.make("restore-ready-turn"),
2062 + type: "provider-turn.updated",
2063 + threadId,
2064 + occurredAt: yield* DateTime.now,
2065 + payload: turn,
2066 + },
2067 + ],
2068 + });
2069 + }
2070 + yield* orchestrator.dispatch({
2071 type: "message.dispatch",
1804 - commandId: CommandId.make("steer"),
2072 + commandId: CommandId.make("restart"),
2073 threadId,
1806 - messageId: MessageId.make("message:steer"),
1807 - text: "steer",
2074 + messageId: MessageId.make("message:restart"),
2075 + text: "restart",
2076 attachments: [],
2077 modelSelection: runSelection,
1810 - dispatchMode: { type: "steer_active", targetRunId: first.runId },
2078 + dispatchMode: { type: "restart_active", targetRunId: first.runId },
2079 createdBy: "user",
2080 creationSource: "web",
1813 - })
1814 - .pipe(Effect.flip);
1815 - assert.equal(steerError._tag, "OrchestratorDispatchError");
1816 - assert.include(String(steerError.cause), "is stopping and cannot be steered");
1817 - yield* orchestrator.dispatch({
1818 - type: "message.dispatch",
1819 - commandId: CommandId.make("restart"),
1820 - threadId,
1821 - messageId: MessageId.make("message:restart"),
1822 - text: "restart",
1823 - attachments: [],
1824 - modelSelection: runSelection,
1825 - dispatchMode: { type: "restart_active", targetRunId: first.runId },
1826 - createdBy: "user",
1827 - creationSource: "web",
1828 - });
1829 - yield* worker.drain();
2081 + });
2082 + yield* worker.drain();
2083
1831 - assert.deepEqual(steered, []);
1832 - assert.deepEqual(
1833 - started.map((turn) => turn.message.text),
1834 - ["first", "restart"],
1835 - );
1836 - }).pipe(Effect.provide(layer));
1837 - }),
1838 - ),
2084 + assert.deepEqual(steered, []);
2085 + assert.deepEqual(
2086 + started.map((turn) => turn.message.text),
2087 + ["first", "restart"],
2088 + );
2089 + }).pipe(Effect.provide(layer));
2090 + }),
2091 + ),
2092 );
2093
2094 // regression: #32891 a restart that arrives after the turn ended is lost
apps/web/src/components/ChatView.logic.test.ts
+6
@@ -1127,6 +1127,12 @@ describe("planComposerTurn", () => {
1127 shouldQueueBehindActiveRun: false,
1128 baseBranchForWorktree: null,
1129 });
1130 + expect(
1131 + planComposerTurn({ ...running, sendQueuesBehindSetup: true, dispatchMode: "steer" }),
1132 + ).toMatchObject({
1133 + turnDispatchMode: "steer",
1134 + shouldQueueBehindActiveRun: true,
1135 + });
1136 // A fresh session cannot join the running turn, and a stale one is not compacted first.
1137 expect(
1138 planComposerTurn({
apps/web/src/components/ChatView.logic.ts
+3 -1
@@ -1321,7 +1321,9 @@ export function planComposerTurn(input: {
1321 baseBranchForWorktree: shouldCreateWorktree ? input.activeThreadBranch : null,
1322 compactBeforeSend,
1323 turnDispatchMode:
1324 - compactBeforeSend || input.sendQueuesBehindSetup ? ("queue" as const) : dispatchMode,
1324 + compactBeforeSend || (input.sendQueuesBehindSetup && dispatchMode !== "steer")
1325 + ? ("queue" as const)
1326 + : dispatchMode,
1327 shouldQueueBehindActiveRun:
1328 compactBeforeSend ||
1329 input.sendQueuesBehindSetup ||
apps/web/src/components/ChatView.tsx
+1 -1
@@ -2675,7 +2675,7 @@ export default function ChatView(props: ChatViewProps) {
2675 document.activeElement?.getAttribute("data-testid") === "composer-editor" &&
2676 isInSideChatPane(document.activeElement) === embedded,
2677 draftThreadRoute: routeKind === "draft",
2678 - turnRunning: phase === "running",
2678 + turnRunning: phase === "running" || phase === "connecting",
2679 composerRequiresModifier: composerRequiresModifier(settings.sendShortcut, promptRef.current),
2680 isWeb: !isElectron,
2681 isDesktop: isElectron,
apps/web/src/components/chat/ChatComposer.tsx
+6 -6
@@ -2142,7 +2142,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2142 sendEvent,
2143 dispatchMode ??
2144 resolveComposerDispatchMode({
2145 - running: phase === "running",
2145 + running: phase === "running" || phase === "connecting",
2146 alternateModifier: false,
2147 activeTurnDefault: followUpBehavior,
2148 canSteer,
@@ -2174,7 +2174,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2174 keybindings,
2175 isSoftwareKeyboardOpen,
2176 isDraftThread: routeKind === "draft",
2177 - isRunning: phase === "running",
2177 + isRunning: phase === "running" || phase === "connecting",
2178 sendShortcut: settings.sendShortcut,
2179 prompt: promptRef.current,
2180 });
@@ -2184,7 +2184,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2184 submitComposer(
2185 undefined,
2186 resolveComposerDispatchMode({
2187 - running: phase === "running",
2187 + running: phase === "running" || phase === "connecting",
2188 alternateModifier: intent === "alternate",
2189 canSteer,
2190 activeTurnDefault: followUpBehavior,
@@ -2198,7 +2198,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2198 submitComposer(
2199 event,
2200 resolveComposerDispatchMode({
2201 - running: phase === "running",
2201 + running: phase === "running" || phase === "connecting",
2202 alternateModifier: event.metaKey || event.ctrlKey,
2203 activeTurnDefault: followUpBehavior,
2204 canSteer,
@@ -2210,7 +2210,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2210 return submitComposer(
2211 undefined,
2212 resolveComposerDispatchMode({
2213 - running: phase === "running",
2213 + running: phase === "running" || phase === "connecting",
2214 alternateModifier: false,
2215 activeTurnDefault: followUpBehavior,
2216 canSteer,
@@ -3594,7 +3594,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3594 compact={isComposerPrimaryActionsCompact}
3595 canOperateThread={canOperateThread}
3596 pendingAction={pendingPrimaryAction}
3597 - isRunning={phase === "running"}
3597 + isRunning={phase === "running" || phase === "connecting"}
3598 canInterrupt={canInterrupt}
3599 runId={activeThread?.runtime?.activeRunId ?? null}
3600 followUpBehavior={followUpBehavior}
apps/web/src/components/chat/composerCommandKey.ts
+2 -2
@@ -205,7 +205,7 @@ export function composerCommandKeyHandler(input: {
205 keybindings,
206 isSoftwareKeyboardOpen,
207 isDraftThread: routeKind === "draft",
208 - isRunning: phase === "running",
208 + isRunning: phase === "running" || phase === "connecting",
209 sendShortcut,
210 prompt: promptRef.current,
211 });
@@ -264,7 +264,7 @@ export function composerCommandKeyHandler(input: {
264 submitComposer(
265 undefined,
266 resolveComposerDispatchMode({
267 - running: phase === "running",
267 + running: phase === "running" || phase === "connecting",
268 alternateModifier: submissionIntent === "alternate",
269 activeTurnDefault: followUpBehavior,
270 canSteer,
packages/client-runtime/src/state/threadWorkflows.test.ts
+2 -2
@@ -305,7 +305,7 @@ describe("thread workflows", () => {
305 });
306
307 it.each(["preparing", "starting", "waiting"] as const)(
308 - "does not promote queued work into a %s run",
308 + "defers steering during setup and blocks it while waiting (%s)",
309 (status) => {
310 const state = deriveThreadQueueWorkflowState({
311 thread: { id: "thread", activeProviderThreadId: "provider-thread" },
@@ -343,7 +343,7 @@ describe("thread workflows", () => {
343 ],
344 } as never);
345
346 - expect(state.canPromoteToSteer).toBe(false);
346 + expect(state.canPromoteToSteer).toBe(status !== "waiting");
347 },
348 );
349
packages/client-runtime/src/state/threadWorkflows.ts
+4
@@ -179,6 +179,10 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
179 projection.thread.deletedAt == null,
180 canPromoteToSteer:
181 promoteSkipsCompaction ||
182 + ((activeRun?.status === "preparing" || activeRun?.status === "starting") &&
183 + (capabilities === undefined ||
184 + capabilities.supportsActiveSteering ||
185 + capabilities.supportsSteeringByInterruptRestart)) ||
186 (hasSteerableProviderTurn &&
187 (capabilities?.supportsActiveSteering === true ||
188 capabilities?.supportsSteeringByInterruptRestart === true)),
packages/contracts/src/orchestrationV2.ts
+1
@@ -696,6 +696,7 @@ export const OrchestrationV2Run = Schema.Struct({
696 status: OrchestrationV2RunStatus,
697 queuePosition: Schema.optional(Schema.NullOr(PositiveInt)),
698 queueHeld: Schema.optional(Schema.Boolean),
699 + steerWhenReadyRunId: Schema.optional(RunId),
700 requestedAt: Schema.DateTimeUtc,
701 startedAt: Schema.NullOr(Schema.DateTimeUtc),
702 completedAt: Schema.NullOr(Schema.DateTimeUtc),