diff --git a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts index 3ad2b05d82f04..6963529e56914 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts @@ -670,6 +670,110 @@ it("readThread keeps an activity page within an MCP client's output limit and pa }).pipe(Effect.provide(layer), Effect.runPromise); }); +it("readThread shows who answered a question dialog", async () => { + const projection = { + thread: baseThread({ + threadId: parentThreadId, + title: "Parent", + instanceId: parentInstanceId, + model: "gpt-5.4", + }), + runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })], + visibleTurnItems: [], + providerTurns: [], + runtimeRequests: [], + messages: [], + contextTransfers: [], + subagents: [], + updatedAt: now, + } as unknown as OrchestrationV2ThreadProjection; + const question = (position: number, questionAnswer: unknown) => ({ + position, + visibility: "visible", + sourceThreadId: parentThreadId, + sourceItemId: TurnItemId.make(`turn-item-mcp-question-${position}`), + item: { + type: "user_input_request", + runId: activeRunId, + status: questionAnswer === undefined ? "in_progress" : "completed", + title: null, + requestId: `request-${position}`, + questions: [], + ...(questionAnswer === undefined ? {} : { questionAnswer }), + updatedAt: now, + }, + }); + const answer = { requestId: "request", answers: {}, attachmentsByQuestionId: {} }; + const rows = [ + question(0, { + ...answer, + answeredBy: "owner_client", + answeringClient: { sessionId: "7aa1d0cf", clientLabel: "T3 Connect" }, + }), + question(1, { ...answer, answeredBy: "agent" }), + // Answered before the server stamped the responder. + question(2, answer), + question(3, undefined), + ]; + + const layer = layerOrchestratorService.pipe( + Layer.provide( + Layer.mergeAll( + Layer.mock(ThreadManagementService.ThreadManagementService)({ + getThreadEventSequence: () => Effect.succeed(1), + getTimelinePage: () => + Effect.succeed({ + items: rows as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"], + totalItems: rows.length, + hasMore: false, + hasEarlier: false, + }), + getThreadRecords: () => Effect.succeed(projection), + getProjectThreadRecords: () => Effect.succeed(projection), + getThreadShell: () => + Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell), + } satisfies Partial), + ServerSettings.layerTest(), + Layer.mock(ProviderRegistry.ProviderRegistry)({ + getProviders: Effect.succeed([]), + } satisfies Partial), + Layer.mock(ProjectService.ProjectService)({}), + Layer.mock(SecretRequests.SecretRequests)({}), + Layer.mock(RemoteDelegation.RemoteDelegation)({}), + Layer.mock(ScheduledTaskService.ScheduledTaskService)({ + list: () => Effect.succeed({ tasks: [] }), + } satisfies Partial), + Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({ + list: () => Effect.succeed([]), + } satisfies Partial), + NodeCrypto.layer, + ), + ), + ); + + await Effect.gen(function* () { + const service = yield* OrchestratorMcpService.OrchestratorMcpService; + const result = yield* service.readThread(makeScope(), { + threadId: parentThreadId, + view: "activity", + limit: 100, + afterPosition: -1, + }); + const byPosition = new Map(result.items.map((item) => [item.position, item])); + expect(byPosition.get(0)?.answeredBy).toBe("owner_client"); + expect(byPosition.get(0)?.answeringClient).toEqual({ + sessionId: "7aa1d0cf", + clientLabel: "T3 Connect", + }); + expect(byPosition.get(1)?.answeredBy).toBe("agent"); + expect(byPosition.get(1)).not.toHaveProperty("answeringClient"); + for (const position of [2, 3]) { + expect(byPosition.get(position)).not.toHaveProperty("answeredBy"); + expect(byPosition.get(position)).not.toHaveProperty("answeringClient"); + } + }).pipe(Effect.provide(layer), Effect.runPromise); +}); + it("taskStatus returns task.providerInstanceId rather than the driver kind", async () => { const parentProjection = { thread: baseThread({ diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 1782b4451ff55..e2cd513cfe854 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -1134,6 +1134,15 @@ function timelineItem(input: { creationSource: message?.creationSource ?? null, ...(message?.senderThreadId === undefined ? {} : { senderThreadId: message.senderThreadId }), ...(message?.senderClient === undefined ? {} : { senderClient: message.senderClient }), + ...(input.row.item.type === "user_input_request" && + input.row.item.questionAnswer?.answeredBy !== undefined + ? { + answeredBy: input.row.item.questionAnswer.answeredBy, + ...(input.row.item.questionAnswer.answeringClient === undefined + ? {} + : { answeringClient: input.row.item.questionAnswer.answeringClient }), + } + : {}), ...(input.row.item.type === "user_message" && input.row.item.inputIntent === "post" ? { postOnly: true } : {}), diff --git a/docs/orchestration-v2/orchestrator-mcp-server.md b/docs/orchestration-v2/orchestrator-mcp-server.md index 217c6b27ed35c..d4b6e4ad943ab 100644 --- a/docs/orchestration-v2/orchestrator-mcp-server.md +++ b/docs/orchestration-v2/orchestrator-mcp-server.md @@ -428,6 +428,14 @@ and `creationSource: "mcp"`; provider output uses `creationSource: "provider"`. Actor and ingress are separate so agent-authored user-role messages remain distinguishable from human-authored messages. +A question dialog (`user_input_request`) is not a message, so its `createdBy` +and `creationSource` are null. Once answered, the item carries `answeredBy`, +the server's record of who answered: `owner_client` (the owner's signed-in app), +`mcp_client` (an outside MCP sign-in) or `agent`. An owner answer also carries +`answeringClient`, the short session id and label of the app it came from. +Both are absent while the dialog is pending and on answers recorded before the +server stamped them. + Agents mention another thread by the `link` its result carries, `/>`, so they never format an id or write a title, which goes stale when the user renames the thread. The diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index 8a3e808e76816..9467e578c0853 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -26,7 +26,13 @@ import { ScheduledTaskSchedule, ScheduledTaskUpsertSchedule, } from "./scheduledTask.ts"; -import { ProviderInteractionMode, ProviderRequestKind, RuntimeMode } from "./providerPolicy.ts"; +import { + ProviderInteractionMode, + ProviderRequestKind, + RuntimeMode, + UserInputAnsweredBy, + UserInputAnsweringClient, +} from "./providerPolicy.ts"; import { PullRequestState } from "./pullRequest.ts"; import { ThreadLinkedPullRequest, @@ -551,6 +557,10 @@ export const OrchestratorMcpThreadTimelineItem = Schema.Struct({ creationSource: Schema.NullOr(OrchestrationV2CreationSource), senderThreadId: Schema.optional(ThreadId), senderClient: Schema.optional(OrchestrationV2SenderClient), + // Question dialogs only: the server's record of who answered. Absent while pending and on + // answers recorded before the server stamped it. + answeredBy: Schema.optional(UserInputAnsweredBy), + answeringClient: Schema.optional(UserInputAnsweringClient), type: Schema.String, status: OrchestrationV2TurnItemStatus, title: Schema.NullOr(Schema.String),