Skip to content

Commit 06a909d

Browse files
committed
perf(server): skip unused transfers in parentless thread reads
1 parent 960d576 commit 06a909d

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,13 +1201,19 @@ const make = Effect.gen(function* () {
12011201
`Thread ${threadId} is no longer available.`,
12021202
);
12031203
}
1204-
const target = yield* threadManagement
1205-
.getProjectThreadRecords({ projectId: shell.projectId, threadId }, [
1206-
"runs",
1207-
"runtimeRequests",
1208-
"contextTransfers",
1209-
])
1210-
.pipe(Effect.mapError(threadManagementFailure));
1204+
const input = { projectId: shell.projectId, threadId };
1205+
// Transfers are needed only to acknowledge a caller's child-task result.
1206+
const records =
1207+
parent === undefined
1208+
? threadManagement
1209+
.getProjectThreadRecords(input, ["runs", "runtimeRequests"])
1210+
.pipe(Effect.map((target) => ({ ...target, contextTransfers: [] })))
1211+
: threadManagement.getProjectThreadRecords(input, [
1212+
"runs",
1213+
"runtimeRequests",
1214+
"contextTransfers",
1215+
]);
1216+
const target = yield* records.pipe(Effect.mapError(threadManagementFailure));
12111217
return { parent, target, shell } as const;
12121218
});
12131219

‎apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as NodeURL from "node:url";
12
import * as NodeServices from "@effect/platform-node/NodeServices";
23
import { describe, expect, it } from "@effect/vitest";
34
import {
@@ -96,9 +97,7 @@ const readDelegatedTaskStatusTranscript = Effect.fn("readDelegatedTaskStatusTran
9697
followupResult: string,
9798
) {
9899
const fs = yield* FileSystem.FileSystem;
99-
const text = yield* fs.readFileString(
100-
decodeURIComponent(delegatedTaskStatusTranscriptFile.pathname),
101-
);
100+
const text = yield* fs.readFileString(NodeURL.fileURLToPath(delegatedTaskStatusTranscriptFile));
102101
const transcript = yield* decodeProviderReplayNdjson(
103102
text.replaceAll(queuedFollowupResult, followupResult),
104103
);
@@ -315,11 +314,11 @@ describe("orchestrator MCP toolkit", () => {
315314
capabilities: new Set(["orchestration"]),
316315
issuedAt: 1,
317316
};
318-
const invoke = (name: string, args: Record<string, unknown>) =>
317+
const invoke = (name: string, args: Record<string, unknown>, scope = invocation) =>
319318
server
320319
.callTool({ name, arguments: args })
321320
.pipe(
322-
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
321+
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
323322
Effect.provideService(McpSchema.McpServerClient, client),
324323
);
325324

@@ -596,11 +595,24 @@ describe("orchestrator MCP toolkit", () => {
596595
expect(finalStatus.latestTerminalResultContextTransferId).not.toBe(
597596
delegated.resultContextTransferId,
598597
);
598+
const parentlessRead = yield* invoke(
599+
"t3_thread_read",
600+
{ threadId: delegated.childThreadId, limit: 100 },
601+
{ ...invocation, thread: undefined },
602+
);
603+
expect(parentlessRead.isError).not.toBe(true);
604+
const afterParentlessRead = yield* orchestrator.getThreadProjection(parentThreadId);
605+
expect(
606+
afterParentlessRead.subagents.find((task) => task.id === queuedFollowup.taskId)
607+
?.completionDelivery?.state,
608+
).toBe("claimed");
609+
599610
const read = yield* invoke("t3_thread_read", {
600611
threadId: delegated.childThreadId,
601612
limit: 100,
602613
});
603614
expect(read.isError).not.toBe(true);
615+
expect(read.structuredContent).toEqual(parentlessRead.structuredContent);
604616
const afterRead = yield* orchestrator.getThreadProjection(parentThreadId);
605617
expect(
606618
afterRead.subagents.find((task) => task.id === queuedFollowup.taskId)

0 commit comments

Comments
 (0)