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 21, 07:15 UTC
fix(server): a Claude command moved to the background keeps its command in Background work (#37787)
Joseph Vidal committed
Nov 18, 2026 at 08:27 UTC
cb129ba2ccc117859b8171b101150f185310b62c
2 files changed
+93
-20
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+63
@@ -12454,6 +12454,57 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12454
}),
12455
);
12456
yield* Queue.offer(harness.sdkMessages, wakeTaskStarted);
12457
+ // Claude moves a long foreground command to the background mid-turn.
12458
+ yield* Queue.offer(
12459
+ harness.sdkMessages,
12460
+ claudeSdkFrame({
12461
+ type: "assistant",
12462
+ message: {
12463
+ model: "claude-sonnet-4-6",
12464
+ id: "msg_foreground_command",
12465
+ type: "message",
12466
+ role: "assistant",
12467
+ content: [
12468
+ {
12469
+ type: "tool_use",
12470
+ id: "toolu_moved_build",
12471
+ name: "Bash",
12472
+ input: { command: "vp run build" },
12473
+ },
12474
+ ],
12475
+ },
12476
+ parent_tool_use_id: null,
12477
+ uuid: "foreground-command-launch",
12478
+ session_id: WAKE_NATIVE_SESSION,
12479
+ }),
12480
+ );
12481
+ yield* Queue.offer(
12482
+ harness.sdkMessages,
12483
+ claudeSdkFrame({
12484
+ type: "system",
12485
+ subtype: "task_started",
12486
+ task_id: "moved-build",
12487
+ tool_use_id: "toolu_moved_build",
12488
+ description: "vp run build",
12489
+ is_backgrounded: false,
12490
+ task_type: "local_bash",
12491
+ uuid: "00000000-0000-4000-8000-000000000205",
12492
+ session_id: WAKE_NATIVE_SESSION,
12493
+ }),
12494
+ );
12495
+ yield* Queue.offer(
12496
+ harness.sdkMessages,
12497
+ claudeSdkFrame({
12498
+ type: "system",
12499
+ subtype: "background_tasks_changed",
12500
+ tasks: [
12501
+ { task_id: WAKE_TASK_ID, task_type: "local_bash", description: "Audit" },
12502
+ { task_id: "moved-build", task_type: "local_bash", description: "vp run build" },
12503
+ ],
12504
+ uuid: "00000000-0000-4000-8000-000000000206",
12505
+ session_id: WAKE_NATIVE_SESSION,
12506
+ }),
12507
+ );
12508
yield* Queue.offer(harness.sdkMessages, turnOneResult);
12509
yield* harness.awaitTerminal(1);
12510
@@ -12478,6 +12529,18 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12529
itemId: command.turnItem.id,
12530
};
12531
assert.deepInclude(afterStart.at(-1)?.providerThread.pendingBackgroundTasks?.[0], details);
12532
+ const movedCommand = harness.events.find(
12533
+ (event) =>
12534
+ event.type === "turn_item.updated" &&
12535
+ event.turnItem.nativeItemRef?.nativeId === "toolu_moved_build",
12536
+ );
12537
+ assert.equal(movedCommand?.type, "turn_item.updated");
12538
+ if (movedCommand?.type !== "turn_item.updated") return;
12539
+ assert.deepInclude(afterStart.at(-1)?.providerThread.pendingBackgroundTasks?.[1], {
12540
+ taskId: "moved-build",
12541
+ command: "vp run build",
12542
+ itemId: movedCommand.turnItem.id,
12543
+ });
12544
yield* harness.offerAndWait(
12545
claudeSdkFrame({
12546
type: "system",
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+30
-20
@@ -10270,6 +10270,30 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10270
});
10271
});
10272
10273
+ const backgroundTaskLaunch = (
10274
+ activeContext: ActiveClaudeTurnContext | null,
10275
+ toolUseId: string | undefined,
10276
+ ): Pick<OrchestrationV2PendingBackgroundTask, "command" | "itemId" | "sourceThreadId"> => {
10277
+ const launch =
10278
+ toolUseId === undefined || activeContext === null
10279
+ ? undefined
10280
+ : findToolCall(activeContext, toolUseId);
10281
+ const command =
10282
+ launch?.classification.itemType === "command_execution" ||
10283
+ launch?.toolName === "Monitor"
10284
+ ? firstStringInputField(launch.input, ["command"])
10285
+ : undefined;
10286
+ if (launch === undefined || command === undefined) return {};
10287
+ return {
10288
+ command,
10289
+ itemId: idAllocator.derive.turnItemFromProviderItem({
10290
+ driver: CLAUDE_PROVIDER,
10291
+ nativeItemId: launch.nativeItemId,
10292
+ }),
10293
+ sourceThreadId: launch.threadId,
10294
+ };
10295
+ };
10296
+
10297
const applyBackgroundTaskRosterMessage = Effect.fnUntraced(function* (input: {
10298
readonly nativeThreadId: string;
10299
readonly message: SDKMessage;
@@ -10311,7 +10335,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10335
for (const entry of roster) {
10336
const task = parseClaudeBackgroundTaskEntry(entry, monitorTasks, toolUseIds);
10337
if (task !== null) {
10314
- nextTasks.push(task);
10338
+ // A foreground command Claude moved to the background first appears here.
10339
+ nextTasks.push({
10340
+ ...backgroundTaskLaunch(input.activeContext, task.nativeItemId),
10341
+ ...task,
10342
+ });
10343
}
10344
}
10345
yield* replacePendingBackgroundTasks(input.nativeThreadId, nextTasks);
@@ -10335,26 +10363,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10363
if (message.is_backgrounded === false) {
10364
return false;
10365
}
10338
- const launch =
10339
- message.tool_use_id === undefined || input.activeContext === null
10340
- ? undefined
10341
- : findToolCall(input.activeContext, message.tool_use_id);
10342
- const command =
10343
- launch?.classification.itemType === "command_execution" ||
10344
- launch?.toolName === "Monitor"
10345
- ? firstStringInputField(launch.input, ["command"])
10346
- : undefined;
10366
yield* upsertPendingBackgroundTask(input.nativeThreadId, {
10348
- ...(launch === undefined || command === undefined
10349
- ? {}
10350
- : {
10351
- itemId: idAllocator.derive.turnItemFromProviderItem({
10352
- driver: CLAUDE_PROVIDER,
10353
- nativeItemId: launch.nativeItemId,
10354
- }),
10355
- sourceThreadId: launch.threadId,
10356
- }),
10357
- ...(command === undefined ? {} : { command }),
10367
+ ...backgroundTaskLaunch(input.activeContext, message.tool_use_id),
10368
...claudePendingBackgroundTask({
10369
taskId: message.task_id,
10370
taskType: claudeTaskTypeFromSdkMessage(message),