The best way to control Claude Code, Codex and more from any computer or phone
fix(server): live-status thread lists build shells only for threads that may be live (#38733)
Julius Marminge committed
Nov 18, 2026 at 13:08 UTC
75cae42febdbedc2bd39430a1d6f017e38f6bfe0
2 files changed
+59
apps/server/src/mcp/OrchestratorMcpService.test.ts
+37
@@ -6,6 +6,7 @@ import {
6
ContextTransferId,
7
EnvironmentId,
8
GitCommandError,
9
+ isLiveSubagentShell,
10
MessageId,
11
NodeId,
12
ORCHESTRATOR_MCP_RUNNING_TASK_NEXT,
@@ -4861,6 +4862,18 @@ describe("OrchestratorMcpService thread list", () => {
4862
{ taskId: "sleep-600", kind: "command" as const, awaited: true as const },
4863
],
4864
},
4865
+ {
4866
+ ...shell("thread:c-settled", "project:c", false),
4867
+ settledOverride: "settled" as const,
4868
+ settledAt: DateTime.makeUnsafe("2026-01-02T00:00:00Z"),
4869
+ },
4870
+ {
4871
+ ...shell("thread:c-awaiting-command", "project:c", false),
4872
+ activityRunStatus: null,
4873
+ pendingBackgroundTasks: [
4874
+ { taskId: "sleep-600", kind: "command" as const, awaited: true as const },
4875
+ ],
4876
+ },
4877
];
4878
const shellRequests: Array<ReadonlyArray<ThreadId>> = [];
4879
const service = layerOrchestratorService.pipe(
@@ -4875,6 +4888,14 @@ describe("OrchestratorMcpService thread list", () => {
4888
(thread) => input.projectId === undefined || thread.projectId === input.projectId,
4889
),
4890
),
4891
+ listActiveShellIndex: () =>
4892
+ Effect.succeed(
4893
+ shells.map((thread) => ({
4894
+ ...thread,
4895
+ mayBeLive: isLiveSubagentShell(thread),
4896
+ hasRemoteTasks: false,
4897
+ })),
4898
+ ),
4899
getShellSnapshot: (options) => {
4900
const threadIds = options?.threadIds ?? shells.map((thread) => thread.id);
4901
shellRequests.push(threadIds);
@@ -4979,6 +5000,22 @@ describe("OrchestratorMcpService thread list", () => {
5000
}).pipe(Effect.provide(service)),
5001
);
5002
5003
+ it.effect("skips building shells for settled threads when every status filter is live", () =>
5004
+ Effect.gen(function* () {
5005
+ const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;
5006
+ shellRequests.length = 0;
5007
+ const listed = yield* mcp.listThreads(client, {
5008
+ projectId: ProjectId.make("project:c"),
5009
+ statuses: ["preparing", "queued", "starting", "running", "waiting"],
5010
+ });
5011
+ assert.deepStrictEqual(
5012
+ listed.threads.map((thread) => thread.threadId),
5013
+ ["thread:c-awaiting-command"],
5014
+ );
5015
+ assert.notInclude(shellRequests.flat(), ThreadId.make("thread:c-settled"));
5016
+ }).pipe(Effect.provide(service)),
5017
+ );
5018
+
5019
it.effect("builds shells only for the threads on the page", () =>
5020
Effect.gen(function* () {
5021
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;
apps/server/src/mcp/OrchestratorMcpService.ts
+22
@@ -934,6 +934,14 @@ function threadStatus(
934
return backgroundWorkHoldsCompletion(pendingBackgroundTasks ?? []) ? "waiting" : settledStatus;
935
}
936
937
+const LIVE_LISTED_THREAD_STATUSES: ReadonlySet<OrchestratorMcpThreadListItem["status"]> = new Set([
938
+ "queued",
939
+ "preparing",
940
+ "starting",
941
+ "running",
942
+ "waiting",
943
+]);
944
+
945
function listedThreadStatus(shell: OrchestrationV2ThreadShell) {
946
return threadStatus(shell.activityRunStatus, shell.status, shell.pendingBackgroundTasks);
947
}
@@ -3280,7 +3288,21 @@ const make = Effect.gen(function* () {
3288
? null
3289
: new Set(input.statuses);
3290
const titleContains = input.titleContains?.toLocaleLowerCase();
3291
+ // A live status needs a source the index's mayBeLive covers, so a live-only filter
3292
+ // skips building shells for every thread that cannot match.
3293
+ const mayBeLiveIds =
3294
+ statuses !== null &&
3295
+ [...statuses].every((status) => LIVE_LISTED_THREAD_STATUSES.has(status))
3296
+ ? new Set(
3297
+ (yield* threadManagement
3298
+ .listActiveShellIndex()
3299
+ .pipe(Effect.mapError(listFailure))).flatMap((entry) =>
3300
+ entry.mayBeLive ? [entry.id] : [],
3301
+ ),
3302
+ )
3303
+ : null;
3304
const candidates = projectThreads
3305
+ .filter((thread) => mayBeLiveIds === null || mayBeLiveIds.has(thread.id))
3306
.filter(
3307
(thread) =>
3308
input.settled === undefined || threadSettlement(thread).settled === input.settled,