@devries-cameron20 / t3code-1 / commits / 91712ee56c
Fork 0

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

fix(server): agents can see a thread's pending background work (#33858)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Ford Lascari committed Nov 12, 2026 at 15:06 UTC 91712ee56c318acc65dc2d1a0eccdb6333ca164c
5 files changed +96 -3
apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+17 -1
@@ -193,7 +193,19 @@ it("readThread preserves caller access errors and prefers activity-run status ov
193 ? Effect.die("A failed caller read must not reach the target")
194 : Effect.succeed(
195 threadId === parentThreadId
196 - ? (projection.thread as unknown as OrchestrationV2ThreadShell)
196 + ? ({
197 + ...projection.thread,
198 + blockedOnThreadWait: true,
199 + pendingBackgroundTasks: [
200 + {
201 + taskId: "task-subagent",
202 + kind: "subagent",
203 + parentTaskId: "task-parent",
204 + providerInstanceId: parentInstanceId,
205 + childThreadId,
206 + },
207 + ],
208 + } as unknown as OrchestrationV2ThreadShell)
209 : null,
210 ),
211 getProjectThreadRecords: (input) =>
@@ -225,6 +237,10 @@ it("readThread preserves caller access errors and prefers activity-run status ov
237 expect(result.thread.status).toBe("running");
238 expect(result.thread.latestRunId).toBe(cancelledRunId);
239 expect(result.thread.activeRunId).toBe(activeRunId);
240 + expect(result.thread.blockedOnThreadWait).toBe(true);
241 + expect(result.thread.pendingBackgroundTasks).toEqual([
242 + { taskId: "task-subagent", kind: "subagent", childThreadId },
243 + ]);
244 // Every page read must not repeat each linked PR, and an open PR shows whether it is watched.
245 const listed = result.thread.pullRequests ?? [];
246 expect(listed.map((link) => link.number)).not.toContain(1);
apps/server/src/mcp/OrchestratorMcpService.test.ts
+34 -2
@@ -3948,16 +3948,30 @@ describe("OrchestratorMcpService thread list", () => {
3948 capabilities: new Set(["orchestration"]),
3949 issuedAt: 1,
3950 };
3951 - const shell = (id: string, projectId: string, snoozed: boolean) => ({
3951 + const shell = (id: string, projectId: string, snoozed: boolean, waiting = false) => ({
3952 ...liveThreadShell(ThreadId.make(id)),
3953 projectId: ProjectId.make(projectId),
3954 status: "completed" as const,
3955 snoozedUntil: snoozed ? DateTime.makeUnsafe("2099-01-01T00:00:00Z") : null,
3956 + blockedOnThreadWait: waiting,
3957 + pendingBackgroundTasks: waiting
3958 + ? [
3959 + {
3960 + taskId: "task-subagent",
3961 + kind: "subagent" as const,
3962 + description: "Review the diff",
3963 + parentTaskId: "task-parent",
3964 + providerInstanceId: ProviderInstanceId.make("codex"),
3965 + childThreadId: ThreadId.make("thread:b-child"),
3966 + },
3967 + { taskId: "task-tests", kind: "command" as const, awaited: true as const },
3968 + ]
3969 + : [],
3970 });
3971 const shells = [
3972 shell("thread:a-snoozed", "project:a", true),
3973 shell("thread:a-awake", "project:a", false),
3960 - shell("thread:b-snoozed", "project:b", true),
3974 + shell("thread:b-snoozed", "project:b", true, true),
3975 {
3976 ...shell("thread:a-awaiting-command", "project:a", false),
3977 activityRunStatus: null,
@@ -4022,6 +4036,24 @@ describe("OrchestratorMcpService thread list", () => {
4036 ["thread:b-snoozed", "project:b"],
4037 ],
4038 );
4039 + assert.deepStrictEqual(
4040 + listed.threads.map((thread) => [thread.blockedOnThreadWait, thread.pendingBackgroundTasks]),
4041 + [
4042 + [false, []],
4043 + [
4044 + true,
4045 + [
4046 + {
4047 + taskId: "task-subagent",
4048 + kind: "subagent",
4049 + description: "Review the diff",
4050 + childThreadId: ThreadId.make("thread:b-child"),
4051 + },
4052 + { taskId: "task-tests", kind: "command", awaited: true },
4053 + ],
4054 + ],
4055 + ],
4056 + );
4057 }).pipe(Effect.provide(service)),
4058 );
4059
apps/server/src/mcp/OrchestratorMcpService.ts
+20
@@ -803,6 +803,24 @@ function threadSnooze(
803 };
804 }
805
806 +// Provider-internal links (parentTaskId, providerInstanceId) stay out of agent results.
807 +function threadBackgroundWork(
808 + thread: Pick<OrchestrationV2ThreadShell, "blockedOnThreadWait" | "pendingBackgroundTasks">,
809 +): Required<Pick<OrchestratorMcpThreadListItem, "blockedOnThreadWait" | "pendingBackgroundTasks">> {
810 + return {
811 + blockedOnThreadWait: thread.blockedOnThreadWait === true,
812 + pendingBackgroundTasks: (thread.pendingBackgroundTasks ?? []).map((task) => ({
813 + taskId: task.taskId,
814 + kind: task.kind,
815 + ...(task.description === undefined ? {} : { description: task.description }),
816 + ...(task.awaited === undefined ? {} : { awaited: task.awaited }),
817 + ...(task.kind === "subagent" && task.childThreadId !== undefined
818 + ? { childThreadId: task.childThreadId }
819 + : {}),
820 + })),
821 + };
822 +}
823 +
824 function threadPullRequests(
825 links: OrchestrationV2ThreadShell["pullRequests"],
826 includeLinks = true,
@@ -856,6 +874,7 @@ function listItemFromShell(
874 ...threadPullRequests(shell.pullRequests),
875 ...threadSettlement(shell),
876 ...threadSnooze(shell, nowMs),
877 + ...threadBackgroundWork(shell),
878 parentThreadId: shell.lineage.parentThreadId,
879 relationshipToParent: shell.lineage.relationshipToParent,
880 itemCount: shell.visibleItemCount,
@@ -917,6 +936,7 @@ function threadDetail(
936 archived: projection.thread.archivedAt !== null,
937 ...threadSettlement(projection.thread),
938 ...threadSnooze(shell, nowMs),
939 + ...threadBackgroundWork(shell),
940 createdAt: DateTime.formatIso(projection.thread.createdAt),
941 updatedAt: DateTime.formatIso(projection.thread.updatedAt),
942 };
docs/orchestration-v2/orchestrator-mcp-server.md
+6
@@ -429,6 +429,12 @@ client's `effectiveSnoozed`, so agents and the sidebar agree: a snoozed thread
429 wakes early only when it has a pending request or fails after snoozing. Completed
430 runs, background wakes, and delegated completions keep it snoozed.
431
432 +They also report `blockedOnThreadWait` and `pendingBackgroundTasks`, the shell
433 +fields behind the sidebar's Waiting label, so an agent can see what a thread
434 +still waits on after its run completed. A subagent or `background_task` holds
435 +the thread. A command or monitor holds it only with `awaited: true`, since agents
436 +often leave a dev server running.
437 +
438 ### `t3_thread_update`
439
440 Updates metadata for the calling thread or any other thread in the environment.
packages/contracts/src/orchestratorMcp.ts
+19
@@ -362,6 +362,17 @@ export const OrchestratorMcpThreadPullRequest = Schema.Struct({
362 });
363 export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
364
365 +/** Background work still open on the thread, as its provider reported it. */
366 +export const OrchestratorMcpThreadBackgroundTask = Schema.Struct({
367 + taskId: TrimmedNonEmptyString,
368 + kind: Schema.Literals(["subagent", "command", "monitor", "background_task"]),
369 + description: Schema.optional(TrimmedNonEmptyString),
370 + /** The agent waits on this command or monitor. Other kinds always hold the thread. */
371 + awaited: Schema.optional(Schema.Literal(true)),
372 + childThreadId: Schema.optional(ThreadId),
373 +});
374 +export type OrchestratorMcpThreadBackgroundTask = typeof OrchestratorMcpThreadBackgroundTask.Type;
375 +
376 export const OrchestratorMcpThreadListItem = Schema.Struct({
377 threadId: ThreadId,
378 projectId: ProjectId,
@@ -383,6 +394,10 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
394 settledAt: Schema.NullOr(IsoDateTime),
395 snoozed: Schema.Boolean,
396 snoozedUntil: Schema.NullOr(IsoDateTime),
397 + /** Absent from linked environments that predate it. */
398 + blockedOnThreadWait: Schema.optional(Schema.Boolean),
399 + /** Absent from linked environments that predate it. */
400 + pendingBackgroundTasks: Schema.optional(Schema.Array(OrchestratorMcpThreadBackgroundTask)),
401 parentThreadId: Schema.NullOr(ThreadId),
402 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
403 itemCount: NonNegativeInt,
@@ -466,6 +481,10 @@ export const OrchestratorMcpThreadDetail = Schema.Struct({
481 settledAt: Schema.NullOr(IsoDateTime),
482 snoozed: Schema.Boolean,
483 snoozedUntil: Schema.NullOr(IsoDateTime),
484 + /** Absent from linked environments that predate it. */
485 + blockedOnThreadWait: Schema.optional(Schema.Boolean),
486 + /** Absent from linked environments that predate it. */
487 + pendingBackgroundTasks: Schema.optional(Schema.Array(OrchestratorMcpThreadBackgroundTask)),
488 createdAt: IsoDateTime,
489 updatedAt: IsoDateTime,
490 });