@devries-cameron20 / t3code-1 / commits / 43ba62b9fc
Fork 0

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

fix(server): thread reads wait for pending background work (#36610)

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

Wout Stiens committed Nov 14, 2026 at 10:35 UTC 43ba62b9fcf9e7bb34e921e76e7b2f609bb5d40a
2 files changed +43 -15
apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+31 -10
@@ -105,7 +105,7 @@ function baseThread(input: {
105 function makeRun(input: {
106 readonly id: RunId;
107 readonly ordinal: number;
108 - readonly status: "running" | "waiting" | "cancelled" | "queued" | "completed";
108 + readonly status: "running" | "waiting" | "cancelled" | "queued" | "completed" | "failed";
109 readonly instanceId?: ProviderInstanceId;
110 }) {
111 return {
@@ -125,6 +125,15 @@ function makeRun(input: {
125
126 it("readThread preserves caller access errors and prefers activity-run status over a newer cancelled queued run", async () => {
127 let callerUnavailable = false;
128 + let pendingBackgroundTasks: OrchestrationV2ThreadShell["pendingBackgroundTasks"] = [
129 + {
130 + taskId: "task-subagent",
131 + kind: "subagent",
132 + parentTaskId: "task-parent",
133 + providerInstanceId: parentInstanceId,
134 + childThreadId,
135 + },
136 + ];
137 const pullRequestLink = (number: number, state: "open" | "merged", watched: boolean) => ({
138 host: "github.com",
139 repository: "acme/web",
@@ -202,15 +211,7 @@ it("readThread preserves caller access errors and prefers activity-run status ov
211 ? ({
212 ...projection.thread,
213 blockedOnThreadWait: true,
205 - pendingBackgroundTasks: [
206 - {
207 - taskId: "task-subagent",
208 - kind: "subagent",
209 - parentTaskId: "task-parent",
210 - providerInstanceId: parentInstanceId,
211 - childThreadId,
212 - },
213 - ],
214 + pendingBackgroundTasks,
215 } as unknown as OrchestrationV2ThreadShell)
216 : null,
217 ),
@@ -263,6 +264,26 @@ it("readThread preserves caller access errors and prefers activity-run status ov
264 expect(laterPage.thread.pullRequests).toBeUndefined();
265 expect(laterPage.thread.pullRequestCount).toBe(8);
266
267 + Object.assign(projection, {
268 + runs: [makeRun({ id: activeRunId, ordinal: 1, status: "completed" })],
269 + });
270 + const awaiting = yield* service.readThread(makeScope(), { threadId: parentThreadId });
271 + expect(awaiting.thread.status).toBe("waiting");
272 +
273 + Object.assign(projection, {
274 + runs: [makeRun({ id: activeRunId, ordinal: 1, status: "failed" })],
275 + });
276 + const failed = yield* service.readThread(makeScope(), { threadId: parentThreadId });
277 + expect(failed.thread.status).toBe("failed");
278 +
279 + Object.assign(projection, {
280 + runs: [makeRun({ id: activeRunId, ordinal: 1, status: "completed" })],
281 + });
282 + // An unawaited command (a dev server) does not hold the thread once its turn ends.
283 + pendingBackgroundTasks = [{ taskId: "dev-server", kind: "command" }];
284 + const released = yield* service.readThread(makeScope(), { threadId: parentThreadId });
285 + expect(released.thread.status).toBe("completed");
286 +
287 callerUnavailable = true;
288 const denied = yield* service
289 .readThread({ ...makeScope(), capabilities: new Set() }, { threadId: parentThreadId })
apps/server/src/mcp/OrchestratorMcpService.ts
+12 -5
@@ -865,11 +865,18 @@ function threadPullRequests(
865 }
866
867 // Awaited background work keeps a thread live after its turn ends, as auto-settle and the sidebar treat it.
868 +function threadStatus(
869 + activeStatus: OrchestratorMcpThreadListItem["status"] | null | undefined,
870 + settledStatus: OrchestratorMcpThreadListItem["status"],
871 + pendingBackgroundTasks: OrchestrationV2ThreadShell["pendingBackgroundTasks"],
872 +) {
873 + if (activeStatus != null) return activeStatus;
874 + if (settledStatus === "failed") return settledStatus;
875 + return backgroundWorkHoldsCompletion(pendingBackgroundTasks ?? []) ? "waiting" : settledStatus;
876 +}
877 +
878 function listedThreadStatus(shell: OrchestrationV2ThreadShell) {
869 - if (shell.activityRunStatus != null) return shell.activityRunStatus;
870 - return backgroundWorkHoldsCompletion(shell.pendingBackgroundTasks ?? [])
871 - ? "waiting"
872 - : shell.status;
879 + return threadStatus(shell.activityRunStatus, shell.status, shell.pendingBackgroundTasks);
880 }
881
882 function listItemFromShell(
@@ -920,7 +927,7 @@ function threadDetail(
927 link: threadLinkFor(scope, projection.thread.id, projection.thread.title),
928 createdBy: projection.thread.createdBy,
929 creationSource: projection.thread.creationSource,
923 - status: active?.status ?? latest?.status ?? "idle",
930 + status: threadStatus(active?.status, latest?.status ?? "idle", shell.pendingBackgroundTasks),
931 latestRunId: latest?.id ?? null,
932 activeRunId: active?.id ?? null,
933 providerInstanceId: projection.thread.modelSelection.instanceId,