@devries-cameron20 / t3code Mirror · read-only / commits / 52451a7909
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 21, 11:00 UTC

fix(claude): keep monitor threads waiting between updates (#37085)

Yash Singh committed Nov 15, 2026 at 01:40 UTC 52451a7909cf5f20b3fe10309ff904d2472ac486
5 files changed +51 -9
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+29
@@ -12526,6 +12526,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12526 {
12527 taskId: longRunning.taskId,
12528 kind: "monitor",
12529 + awaited: true,
12530 description: "Monitor 0",
12531 nativeItemId: "toolu_monitor_0",
12532 command: "sleep 8 && echo MONITOR_DONE",
@@ -12533,6 +12534,29 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12534 sourceThreadId: harness.threadId,
12535 },
12536 ]);
12537 + assert.isDefined(harness.runtime.awaitBackgroundTasks);
12538 + const released = yield* harness.runtime.awaitBackgroundTasks!({
12539 + providerThread: harness.providerThread,
12540 + taskIds: [longRunning.taskId],
12541 + awaited: false,
12542 + });
12543 + assert.deepEqual(released.matched, [longRunning.taskId]);
12544 + yield* harness.offerAndWait(
12545 + claudeSdkFrame({
12546 + type: "system",
12547 + subtype: "background_tasks_changed",
12548 + tasks: [
12549 + { task_id: longRunning.taskId, task_type: "local_bash", description: "Monitor 0" },
12550 + ],
12551 + uuid: nextUuid(),
12552 + session_id: WAKE_NATIVE_SESSION,
12553 + }),
12554 + );
12555 + assert.equal(
12556 + providerThreadRosterEvents(harness.events).at(-1)?.providerThread
12557 + .pendingBackgroundTasks?.[0]?.awaited,
12558 + undefined,
12559 + );
12560 }).pipe(
12561 Effect.provide(
12562 Layer.mergeAll(
@@ -12728,6 +12752,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12752 assert.equal(harness.terminalEvents()[settled + 1]?.status, "completed");
12753 assert.include(assistantTexts(), "Scheduled answer.");
12754 assert.lengthOf(harness.continuationRequests, 2);
12755 + assert.deepInclude(
12756 + providerThreadRosterEvents(harness.events).at(-1)?.providerThread
12757 + .pendingBackgroundTasks?.[0],
12758 + { taskId, kind: "monitor", awaited: true },
12759 + );
12760 }).pipe(
12761 Effect.provide(
12762 Layer.mergeAll(
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+17 -5
@@ -6665,11 +6665,23 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
6665 nativeThreadId: string,
6666 task: OrchestrationV2PendingBackgroundTask,
6667 ) {
6668 - yield* Ref.update(pendingBackgroundTasksByNativeThread, (current) => {
6669 - const roster = new Map(rosterForNativeThread(current, nativeThreadId));
6670 - roster.set(task.taskId, task);
6671 - return new Map(current).set(nativeThreadId, roster);
6672 - });
6668 + const startedMonitor = yield* Ref.modify(
6669 + pendingBackgroundTasksByNativeThread,
6670 + (current) => {
6671 + const roster = new Map(rosterForNativeThread(current, nativeThreadId));
6672 + const startedMonitor =
6673 + task.kind === "monitor" && roster.get(task.taskId)?.kind !== "monitor";
6674 + roster.set(task.taskId, task);
6675 + return [startedMonitor, new Map(current).set(nativeThreadId, roster)] as const;
6676 + },
6677 + );
6678 + if (startedMonitor) {
6679 + yield* addTaskIdsToNativeThreadSet(
6680 + awaitedBackgroundTasksByNativeThread,
6681 + nativeThreadId,
6682 + [task.taskId],
6683 + );
6684 + }
6685 yield* rememberOpaqueTasks([task]);
6686 yield* markWakeEligibleOpaqueBackgroundTasks(nativeThreadId, [task.taskId]);
6687 });
apps/server/src/orchestration-v2/testkit/fixtures/claude_background_monitor_wake/output.ts
+1
@@ -44,6 +44,7 @@ export function assertClaudeBackgroundMonitorWakeOutput(
44 taskId: MONITOR_TASK_ID,
45 description: "Background monitor test",
46 kind: "monitor",
47 + awaited: true,
48 nativeItemId: "toolu_019b4EUbhEcYP4TS7vZn27N1",
49 command: "sleep 8 && echo MONITOR_DONE",
50 itemId: monitorItem?.id,
docs/user/thread-sidebar.md
+2 -2
@@ -135,8 +135,8 @@ open.
135
136 Threads that are working or waiting on work they will resume from move into a collapsed
137 **Working** section below the active list.
138 -That includes subagents, watched pull requests with checks still running, and background commands or monitors the agent
139 -says it is waiting on. A dev server or other process an agent leaves running does not keep a thread
138 +That includes subagents, watched pull requests with checks still running, Claude monitors,
139 +and background commands or other monitors the agent says it is waiting on. A dev server or other process an agent leaves running does not keep a thread
140 there. A thread returns to the top of the active list when it finishes, fails, or needs an approval or
141 answer. The Working section lists the thread you last sent work to first. Pinned threads stay in
142 the pinned section.
docs/user/updating.md
+2 -2
@@ -72,8 +72,8 @@ different value, use **Apply to all** in Settings after it connects.
72 T3 Code must start again on that machine;
73 the setting does not enable automatic startup. Terminal commands may still be
74 interrupted, and threads without saved provider resume state need a new message.
75 -A thread that finished its turn to wait on a subagent, a background task, or a
76 -command or monitor the agent said it was waiting on is woken and told that this work
75 +A thread that finished its turn to wait on a subagent, a background task, a Claude
76 +monitor, or a command or other monitor the agent said it was waiting on is woken and told that this work
77 stopped. Other background shells and monitors, such as a dev server and its
78 watchdog, do not wake it; the thread learns about them with your next message.
79 A thread is not resumed while it waits for your approval, answer, or secret, or