@devries-cameron20 / t3code Mirror · read-only / commits / b6295dd801
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(server): auto-delivered messages queue between provider turns (#15691)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Guillermo Casanova committed Oct 19, 2026 at 01:58 UTC b6295dd801e72d3e74245ac0aa782e1873dcfce7
2 files changed +55 -2
apps/server/src/orchestration-v2/CommandPolicy.test.ts
+46 -1
@@ -7,6 +7,7 @@ import {
7 ProviderInstanceId,
8 ProviderSessionId,
9 ProviderThreadId,
10 + RunAttemptId,
11 RunId,
12 ThreadId,
13 } from "@t3tools/contracts";
@@ -20,6 +21,7 @@ import * as CommandPolicy from "./CommandPolicy.ts";
21 const commandId = CommandId.make("command-policy-test");
22 const threadId = ThreadId.make("command-policy-thread");
23 const activeRunId = RunId.make("command-policy-active-run");
24 +const activeAttemptId = RunAttemptId.make("command-policy-active-attempt");
25 const userMessageId = MessageId.make("command-policy-user-message");
26
27 const baseCapabilities: OrchestrationV2ProviderCapabilities = CodexProviderCapabilitiesV2;
@@ -39,7 +41,15 @@ function dispatchProjection(
41 runs:
42 sessionCapabilities === undefined
43 ? []
42 - : [{ id: activeRunId, status: "running", providerThreadId, userMessageId }],
44 + : [
45 + {
46 + id: activeRunId,
47 + status: "running",
48 + providerThreadId,
49 + activeAttemptId,
50 + userMessageId,
51 + },
52 + ],
53 messages: [{ id: userMessageId, text: "first", attachments: [] }],
54 providerThreads:
55 sessionCapabilities === undefined ? [] : [{ id: providerThreadId, providerSessionId }],
@@ -47,6 +57,10 @@ function dispatchProjection(
57 sessionCapabilities === undefined
58 ? []
59 : [{ id: providerSessionId, capabilities: sessionCapabilities }],
60 + providerTurns:
61 + sessionCapabilities === undefined
62 + ? []
63 + : [{ runAttemptId: activeAttemptId, status: "running" }],
64 } as unknown as OrchestrationV2ThreadProjection;
65 }
66
@@ -120,6 +134,37 @@ it.each(["preparing", "starting"] as const)(
134 },
135 );
136
137 +it.each([
138 + ["has not started", []],
139 + ["is pending", [{ runAttemptId: activeAttemptId, status: "pending" }]],
140 + ["has completed", [{ runAttemptId: activeAttemptId, status: "completed" }]],
141 + [
142 + "belongs to a previous attempt",
143 + [{ runAttemptId: RunAttemptId.make("previous-attempt"), status: "running" }],
144 + ],
145 +])("queues only automatic delivery when the active run's provider turn %s", (_, providerTurns) => {
146 + const projection = {
147 + ...dispatchProjection(baseCapabilities),
148 + providerTurns,
149 + } as unknown as OrchestrationV2ThreadProjection;
150 + assert.deepEqual(
151 + CommandPolicy.resolveMessageDispatchIntent(projection, { type: "start_immediately" }, "auto"),
152 + { type: "queue_after_active" },
153 + );
154 + assert.deepEqual(
155 + CommandPolicy.resolveMessageDispatchIntent(projection, { type: "start_immediately" }, "steer"),
156 + { type: "steer_active", targetRunId: activeRunId },
157 + );
158 + assert.deepEqual(
159 + CommandPolicy.resolveMessageDispatchIntent(
160 + projection,
161 + { type: "start_immediately" },
162 + "restart",
163 + ),
164 + { type: "restart_active", targetRunId: activeRunId },
165 + );
166 +});
167 +
168 it("targets the latest active run for explicit steer and restart intent", () => {
169 const projection = dispatchProjection(baseCapabilities);
170 assert.deepEqual(
apps/server/src/orchestration-v2/CommandPolicy.ts
+9 -1
@@ -165,7 +165,15 @@ function resolveDeliveryIntent(
165 if (deliveryIntent === "restart") {
166 return { type: "restart_active", targetRunId: activeRun.id };
167 }
168 - if (activeRun.status === "preparing" || activeRun.status === "starting") {
168 + // A run can be active before its provider turn starts or after it finishes.
169 + // Queue automatic input in those gaps so steering cannot reject the message.
170 + if (
171 + activeRun.status === "preparing" ||
172 + activeRun.status === "starting" ||
173 + !projection.providerTurns.some(
174 + (turn) => turn.runAttemptId === activeRun.activeAttemptId && turn.status === "running",
175 + )
176 + ) {
177 return { type: "queue_after_active" };
178 }
179