Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadManagementService.ThreadManagementService["Service"]>),
ServerSettings.layerTest(),
Layer.mock(ProviderRegistry.ProviderRegistry)({
getProviders: Effect.succeed([]),
} satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
Layer.mock(ProjectService.ProjectService)({}),
Layer.mock(SecretRequests.SecretRequests)({}),
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
Layer.mock(ScheduledTaskService.ScheduledTaskService)({
list: () => Effect.succeed({ tasks: [] }),
} satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
list: () => Effect.succeed([]),
} satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
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({
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
: {}),
Expand Down
8 changes: 8 additions & 0 deletions docs/orchestration-v2/orchestrator-mcp-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
`<t3-thread://v2/<environmentId>/<threadId>>`, so they never format an id or
write a title, which goes stale when the user renames the thread. The
Expand Down
12 changes: 11 additions & 1 deletion packages/contracts/src/orchestratorMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
Loading