Skip to content

Commit 34e7b66

Browse files
fix(server): t3_thread_list counts threads waiting on background work as live (#34674)
1 parent 8214342 commit 34e7b66

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,13 @@ describe("OrchestratorMcpService thread list", () => {
38863886
shell("thread:a-snoozed", "project:a", true),
38873887
shell("thread:a-awake", "project:a", false),
38883888
shell("thread:b-snoozed", "project:b", true),
3889+
{
3890+
...shell("thread:a-awaiting-command", "project:a", false),
3891+
activityRunStatus: null,
3892+
pendingBackgroundTasks: [
3893+
{ taskId: "sleep-600", kind: "command" as const, awaited: true as const },
3894+
],
3895+
},
38893896
];
38903897
const service = layerOrchestratorService.pipe(
38913898
Layer.provide(
@@ -3932,6 +3939,20 @@ describe("OrchestratorMcpService thread list", () => {
39323939
}).pipe(Effect.provide(service)),
39333940
);
39343941

3942+
it.effect("counts a thread holding awaited background work as live in the status filter", () =>
3943+
Effect.gen(function* () {
3944+
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;
3945+
const listed = yield* mcp.listThreads(client, {
3946+
projectId: ProjectId.make("project:a"),
3947+
statuses: ["preparing", "queued", "starting", "running", "waiting"],
3948+
});
3949+
assert.deepStrictEqual(
3950+
listed.threads.map((thread) => thread.threadId),
3951+
["thread:a-awaiting-command"],
3952+
);
3953+
}).pipe(Effect.provide(service)),
3954+
);
3955+
39353956
it.effect("points a caller outside any thread at allProjects when it omits projectId", () =>
39363957
Effect.gen(function* () {
39373958
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {
6868
SECRET_REQUEST_UNSAVED_NOTE,
6969
} from "@t3tools/contracts";
7070
import { getProviderOptionCurrentValue, withLegacyUltracodeEffort } from "@t3tools/shared/model";
71+
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
7172
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
7273
import { formatThreadLink } from "@t3tools/shared/threadLinks";
7374
import {
@@ -814,6 +815,14 @@ function threadPullRequests(
814815
}));
815816
}
816817

818+
// Awaited background work keeps a thread live after its turn ends, as auto-settle and the sidebar treat it.
819+
function listedThreadStatus(shell: OrchestrationV2ThreadShell) {
820+
if (shell.activityRunStatus != null) return shell.activityRunStatus;
821+
return backgroundWorkHoldsCompletion(shell.pendingBackgroundTasks ?? [])
822+
? "waiting"
823+
: shell.status;
824+
}
825+
817826
function listItemFromShell(
818827
scope: McpInvocationScope,
819828
shell: OrchestrationV2ThreadShell,
@@ -826,7 +835,7 @@ function listItemFromShell(
826835
link: threadLinkFor(scope, shell.id, shell.title),
827836
createdBy: shell.createdBy,
828837
creationSource: shell.creationSource,
829-
status: shell.activityRunStatus ?? shell.status,
838+
status: listedThreadStatus(shell),
830839
latestRunId: shell.latestRunId,
831840
providerInstanceId: shell.modelSelection.instanceId,
832841
model: shell.modelSelection.model,
@@ -2978,9 +2987,7 @@ const make = Effect.gen(function* () {
29782987
: new Set(input.statuses);
29792988
const titleContains = input.titleContains?.toLocaleLowerCase();
29802989
const filtered = projectThreads
2981-
.filter(
2982-
(thread) => statuses === null || statuses.has(thread.activityRunStatus ?? thread.status),
2983-
)
2990+
.filter((thread) => statuses === null || statuses.has(listedThreadStatus(thread)))
29842991
.filter(
29852992
(thread) =>
29862993
input.settled === undefined || threadSettlement(thread).settled === input.settled,

0 commit comments

Comments
 (0)