Skip to content

Commit 934f917

Browse files
fix(mcp): t3_thread_read tells agents which thread sent a message (pingdotgg#18194)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 2c0a78a commit 934f917

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { OrchestratorDispatchError } from "../orchestration-v2/Orchestrator.ts";
2828
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
2929
import type * as McpInvocationContext from "./McpInvocationContext.ts";
3030
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
31-
import { liveThreadShell } from "./McpToolAccess.testkit.ts";
31+
import { idleThreadProjection, liveThreadShell } from "./McpToolAccess.testkit.ts";
3232

3333
const layerOrchestratorService = OrchestratorMcpService.layer.pipe(
3434
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
@@ -686,3 +686,61 @@ it("sendToThread reports why the orchestrator refused the message", async () =>
686686
);
687687
}).pipe(Effect.provide(layer), Effect.runPromise);
688688
});
689+
690+
it("readThread exposes the stored sender thread only for thread-sent messages", async () => {
691+
const shell = liveThreadShell(parentThreadId);
692+
const messages = [
693+
{ id: "message-from-child", text: "Child reporting in", senderThreadId: childThreadId },
694+
{ id: "message-from-user", text: "Thanks" },
695+
];
696+
const projection = {
697+
...idleThreadProjection(shell),
698+
messages,
699+
visibleTurnItems: messages.map((message, position) => ({
700+
position,
701+
visibility: "local",
702+
sourceThreadId: parentThreadId,
703+
sourceItemId: `item-${message.id}`,
704+
item: {
705+
id: `item-${message.id}`,
706+
type: "user_message",
707+
messageId: message.id,
708+
runId: activeRunId,
709+
status: "completed",
710+
title: null,
711+
text: message.text,
712+
updatedAt: now,
713+
},
714+
})),
715+
} as unknown as OrchestrationV2ThreadProjection;
716+
const layer = layerOrchestratorService.pipe(
717+
Layer.provide(
718+
Layer.mergeAll(
719+
Layer.mock(ThreadManagementService.ThreadManagementService)({
720+
getThreadShell: () => Effect.succeed(shell),
721+
getThreadRecords: () => Effect.succeed(projection),
722+
getProjectThreadRecords: () => Effect.succeed(projection),
723+
getTimelinePage: () =>
724+
Effect.succeed({ items: projection.visibleTurnItems, totalItems: 2, hasMore: false }),
725+
}),
726+
ServerSettings.layerTest(),
727+
Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
728+
Layer.mock(ProjectService.ProjectService)({}),
729+
Layer.mock(SecretRequests.SecretRequests)({}),
730+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
731+
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),
732+
NodeCrypto.layer,
733+
),
734+
),
735+
);
736+
737+
await Effect.gen(function* () {
738+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
739+
const result = yield* service.readThread(makeScope(), { threadId: parentThreadId });
740+
expect(result.items).toMatchObject([
741+
{ messageId: "message-from-child", senderThreadId: childThreadId },
742+
{ messageId: "message-from-user" },
743+
]);
744+
expect(result.items[1]).not.toHaveProperty("senderThreadId");
745+
}).pipe(Effect.provide(layer), Effect.runPromise);
746+
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ function timelineItem(input: {
915915
messageId,
916916
createdBy: message?.createdBy ?? null,
917917
creationSource: message?.creationSource ?? null,
918+
...(message?.senderThreadId === undefined ? {} : { senderThreadId: message.senderThreadId }),
918919
type: input.row.item.type,
919920
status: input.row.item.status,
920921
title: input.row.item.title,

‎packages/contracts/src/orchestratorMcp.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
421421
messageId: Schema.NullOr(MessageId),
422422
createdBy: Schema.NullOr(OrchestrationV2Actor),
423423
creationSource: Schema.NullOr(OrchestrationV2CreationSource),
424+
senderThreadId: Schema.optional(ThreadId),
424425
type: Schema.String,
425426
status: OrchestrationV2TurnItemStatus,
426427
title: Schema.NullOr(Schema.String),

0 commit comments

Comments
 (0)