@devries-cameron20 / t3code Mirror · read-only / commits / 9acb76929e
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 22, 13:15 UTC

fix(server): queue Copilot follow-ups without killing background agents (#26715)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Oct 29, 2026 at 17:37 UTC 9acb76929e17aa27e961f51e0b8679d7c0431c8e
5 files changed +213 -22
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+36
@@ -1007,6 +1007,42 @@ describe("AcpRegistryAdapterV2", () => {
1007 }).pipe(Effect.provide(layerTest), Effect.scoped),
1008 );
1009
1010 + // regression: #26695 cancelling a Copilot prompt kills its background agents
1011 + it.effect("never steers Copilot by cancelling its prompt", () =>
1012 + Effect.gen(function* () {
1013 + const steering = Effect.fn("steering")(function* (config: Record<string, unknown>) {
1014 + const instanceId = ProviderInstanceId.make("acp-registry-steering");
1015 + const adapter = yield* makeAcpRegistryAdapterV2({
1016 + selfInvocation: yield* resolveSelfInvocation(),
1017 + instanceId,
1018 + settings: yield* decodeAcpRegistryAdapterSettings(config),
1019 + environment: {},
1020 + }).pipe(Effect.provide(layerInjectedRuntimeCatalog));
1021 + const { turns } = yield* adapter.getCapabilities();
1022 + return {
1023 + supportsInterrupt: turns.supportsInterrupt,
1024 + supportsActiveSteering: turns.supportsActiveSteering,
1025 + supportsSteeringByInterruptRestart: turns.supportsSteeringByInterruptRestart,
1026 + };
1027 + });
1028 + const copilot = {
1029 + supportsInterrupt: true,
1030 + supportsActiveSteering: false,
1031 + supportsSteeringByInterruptRestart: false,
1032 + };
1033 +
1034 + assert.deepEqual(yield* steering({ agentId: "github-copilot-cli" }), copilot);
1035 + assert.deepEqual(
1036 + yield* steering({ source: "local", commandPath: "C:\\tools\\copilot.cmd" }),
1037 + copilot,
1038 + );
1039 + assert.deepEqual(yield* steering({ agentId: "gemini" }), {
1040 + ...copilot,
1041 + supportsSteeringByInterruptRestart: true,
1042 + });
1043 + }).pipe(Effect.provide(layerTest), Effect.scoped),
1044 + );
1045 +
1046 it.effect("settles Claude's accepted foreground reply while retaining child output", () =>
1047 Effect.gen(function* () {
1048 const gate = makeProviderReplayGate(["accepted", "child-output", "wake"]);
apps/server/src/orchestration-v2/CommandPolicy.test.ts
+47
@@ -164,6 +164,53 @@ it.each([
164 );
165 });
166
167 +// regression: #26695 an interrupt-restart steer cancels Copilot's background agents
168 +it("queues a steer for a provider that cannot steer either way", () => {
169 + const projection = dispatchProjection(
170 + capabilities((current) => ({
171 + ...current,
172 + turns: {
173 + ...current.turns,
174 + supportsActiveSteering: false,
175 + supportsSteeringByInterruptRestart: false,
176 + supportsQueuedMessages: true,
177 + },
178 + })),
179 + );
180 + for (const deliveryIntent of ["auto", "steer"] as const) {
181 + assert.deepEqual(
182 + CommandPolicy.resolveMessageDispatchIntent(
183 + projection,
184 + { type: "start_immediately" },
185 + deliveryIntent,
186 + ),
187 + { type: "queue_after_active" },
188 + );
189 + }
190 + assert.deepEqual(
191 + CommandPolicy.resolveMessageDispatchIntent(projection, {
192 + type: "steer_active",
193 + targetRunId: activeRunId,
194 + }),
195 + { type: "queue_after_active" },
196 + );
197 + assert.deepEqual(
198 + CommandPolicy.resolveMessageDispatchIntent(
199 + projection,
200 + { type: "start_immediately" },
201 + "restart",
202 + ),
203 + { type: "restart_active", targetRunId: activeRunId },
204 + );
205 + assert.deepEqual(
206 + CommandPolicy.resolveMessageDispatchIntent(projection, {
207 + type: "steer_active",
208 + targetRunId: RunId.make("command-policy-missing-run"),
209 + }),
210 + { type: "steer_active", targetRunId: RunId.make("command-policy-missing-run") },
211 + );
212 +});
213 +
214 it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) => {
215 const projection = dispatchProjection(baseCapabilities);
216 const maintenance = {
apps/server/src/orchestration-v2/CommandPolicy.ts
+39 -18
@@ -99,11 +99,47 @@ export function resolveMessageDispatchIntent(
99 // Compaction and sign-out cannot accept steers; queue follow-ups.
100 const target = projection.runs.find((run) => run.id === mode.targetRunId);
101 const targetMessage = projection.messages.find((message) => message.id === target?.userMessageId);
102 - return targetMessage !== undefined && isNativeMaintenanceCommand(targetMessage)
102 + if (targetMessage !== undefined && isNativeMaintenanceCommand(targetMessage)) {
103 + return { type: "queue_after_active" };
104 + }
105 + // A provider that can neither steer nor restart its turn takes the message after the turn.
106 + const turns =
107 + target === undefined || !isActiveRun(target)
108 + ? undefined
109 + : providerTurnCapabilities(projection, target);
110 + return turns !== undefined &&
111 + !turns.supportsActiveSteering &&
112 + !(turns.supportsInterrupt && turns.supportsSteeringByInterruptRestart) &&
113 + turns.supportsQueuedMessages
114 ? { type: "queue_after_active" }
115 : mode;
116 }
117
118 +function isActiveRun(run: OrchestrationV2Run): boolean {
119 + return (
120 + run.status === "preparing" ||
121 + run.status === "starting" ||
122 + run.status === "running" ||
123 + run.status === "waiting"
124 + );
125 +}
126 +
127 +function providerTurnCapabilities(
128 + projection: OrchestrationV2ThreadProjection,
129 + run: OrchestrationV2Run,
130 +) {
131 + const providerThread = projection.providerThreads.find(
132 + (candidate) => candidate.id === run.providerThreadId,
133 + );
134 + const providerSession =
135 + providerThread?.providerSessionId == null
136 + ? undefined
137 + : projection.providerSessions.find(
138 + (candidate) => candidate.id === providerThread.providerSessionId,
139 + );
140 + return providerSession?.capabilities.turns;
141 +}
142 +
143 function resolveDeliveryIntent(
144 projection: OrchestrationV2ThreadProjection,
145 requestedMode: MessageDispatchMode,
@@ -111,13 +147,7 @@ function resolveDeliveryIntent(
147 ): MessageDispatchMode {
148 if (deliveryIntent === undefined) return requestedMode;
149
114 - const activeRun = projection.runs.findLast(
115 - (run) =>
116 - run.status === "preparing" ||
117 - run.status === "starting" ||
118 - run.status === "running" ||
119 - run.status === "waiting",
120 - );
150 + const activeRun = projection.runs.findLast(isActiveRun);
151 if (activeRun === undefined) return { type: "start_immediately" };
152 if (deliveryIntent === "steer") {
153 return { type: "steer_active", targetRunId: activeRun.id };
@@ -137,16 +167,7 @@ function resolveDeliveryIntent(
167 return { type: "queue_after_active" };
168 }
169
140 - const providerThread = projection.providerThreads.find(
141 - (candidate) => candidate.id === activeRun.providerThreadId,
142 - );
143 - const providerSession =
144 - providerThread?.providerSessionId == null
145 - ? undefined
146 - : projection.providerSessions.find(
147 - (candidate) => candidate.id === providerThread.providerSessionId,
148 - );
149 - const capabilities = providerSession?.capabilities.turns;
170 + const capabilities = providerTurnCapabilities(projection, activeRun);
171 if (capabilities?.supportsActiveSteering === true) {
172 return { type: "steer_active", targetRunId: activeRun.id };
173 }
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+84 -3
@@ -447,16 +447,18 @@ const composerSelection = {
447 const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function* (
448 name: string,
449 canRestart = false,
450 + canSteer = true,
451 ) {
452 const cwd = yield* checkpointWorkspace(name);
453 const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
454 const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = [];
455 const steered: string[] = [];
456 + const interrupted: ProviderTurnId[] = [];
457 const capabilities = {
458 ...CodexProviderCapabilitiesV2,
459 turns: {
460 ...CodexProviderCapabilitiesV2.turns,
459 - supportsActiveSteering: true,
461 + supportsActiveSteering: canSteer,
462 supportsSteeringByInterruptRestart: canRestart,
463 },
464 };
@@ -533,7 +535,10 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
535 Effect.sync(() => {
536 steered.push(turn.message.text);
537 }),
536 - interruptTurn: () => Effect.void,
538 + interruptTurn: ({ providerTurnId }) =>
539 + Effect.sync(() => {
540 + interrupted.push(providerTurnId);
541 + }),
542 respondToRuntimeRequest: () => Effect.void,
543 readThreadSnapshot: () => Effect.die("unused"),
544 rollbackThread: () => Effect.die("unused"),
@@ -588,7 +593,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
593 yield* Fiber.join(running);
594 return threadId;
595 });
591 - return { cwd, events, started, steered, layer, startFirstTurn };
596 + return { cwd, events, started, steered, interrupted, layer, startFirstTurn };
597 });
598
599 it.effect("sends a selected held message once and preserves the remaining queue order", () =>
@@ -938,6 +943,82 @@ it.effect("starts a steer that missed the turn on the saved next-turn selection"
943 ),
944 );
945
946 +// regression: #26695 cancelling a Copilot prompt to steer it kills its background agents
947 +it.effect("queues a steer until the turn ends when the provider cannot steer it", () =>
948 + Effect.scoped(
949 + Effect.gen(function* () {
950 + const { events, started, steered, interrupted, layer, startFirstTurn } =
951 + yield* nextTurnSelectionHarness("steering-unsupported", false, false);
952 + yield* Effect.gen(function* () {
953 + const orchestrator = yield* Orchestrator.OrchestratorV2;
954 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
955 + const threadId = yield* startFirstTurn;
956 + const first = started[0]!;
957 + const messageId = MessageId.make("message:steer");
958 + yield* orchestrator.dispatch({
959 + type: "message.dispatch",
960 + commandId: CommandId.make("steer"),
961 + threadId,
962 + messageId,
963 + text: "follow up",
964 + attachments: [],
965 + modelSelection: runSelection,
966 + dispatchMode: { type: "start_immediately" },
967 + deliveryIntent: "steer",
968 + createdBy: "user",
969 + creationSource: "web",
970 + });
971 + yield* worker.drain();
972 +
973 + const held = yield* orchestrator.getThreadProjection(threadId);
974 + assert.deepEqual(steered, []);
975 + assert.deepEqual(interrupted, []);
976 + assert.equal(started.length, 1);
977 + assert.equal(held.runs.find((run) => run.id === first.runId)?.status, "running");
978 + const queued = held.runs.find((run) => run.userMessageId === messageId);
979 + assert.equal(queued?.status, "queued");
980 +
981 + const settled = yield* orchestrator.streamDomainEvents.pipe(
982 + Stream.filter(
983 + (event) =>
984 + event.type === "run.updated" &&
985 + event.payload.id === first.runId &&
986 + event.payload.status === "waiting",
987 + ),
988 + Stream.take(1),
989 + Stream.runDrain,
990 + Effect.forkScoped,
991 + );
992 + const turn = held.providerTurns[0]!;
993 + yield* Queue.offer(events, {
994 + type: "provider_turn.updated",
995 + driver,
996 + providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now },
997 + });
998 + yield* Queue.offer(events, {
999 + type: "turn.terminal",
1000 + driver,
1001 + providerThreadId: turn.providerThreadId,
1002 + providerTurnId: turn.id,
1003 + runOrdinal: first.runOrdinal,
1004 + status: "completed",
1005 + failure: null,
1006 + threadDisposition: "reusable",
1007 + });
1008 + yield* Fiber.join(settled);
1009 + yield* worker.drain();
1010 + yield* orchestrator.resumeQueuedRuns;
1011 + yield* worker.drain();
1012 +
1013 + assert.deepEqual(interrupted, []);
1014 + assert.equal(started.length, 2);
1015 + assert.equal(started[1]?.runId, queued?.id);
1016 + assert.equal(started[1]?.message.text, "follow up");
1017 + }).pipe(Effect.provide(layer));
1018 + }),
1019 + ),
1020 +);
1021 +
1022 // Codex flushes held drafts after the final answer; reserve their pre-steer position before turn end.
1023 it.effect("keeps a held commentary draft before the steer when turn end flushes it", () =>
1024 Effect.scoped(
packages/provider-acp-registry/src/server/adapter.ts
+7 -1
@@ -210,7 +210,13 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
210 const copilotRouting = isCopilot ? makeCopilotSubagentRouting() : undefined;
211 const flavor: AcpAdapterV2Flavor = {
212 driver: ACP_REGISTRY_PROVIDER,
213 - capabilities: AcpProviderCapabilitiesV2,
213 + // Cancelling a Copilot prompt also kills the background agents it started.
214 + capabilities: isCopilot
215 + ? {
216 + ...AcpProviderCapabilitiesV2,
217 + turns: { ...AcpProviderCapabilitiesV2.turns, supportsSteeringByInterruptRestart: false },
218 + }
219 + : AcpProviderCapabilitiesV2,
220 customModels: readCustomModelEntries(options.settings.customModels).map((entry) => entry.slug),
221 promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause),
222 ...(registryAgentId === "factory-droid"