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
24 changes: 20 additions & 4 deletions apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ describe("OrchestratorMcpService", () => {
const childThreadId = ThreadId.make("thread:mcp-next-child");
const taskId = NodeId.make("node:mcp-next-task");
let finished = false;
let firstRun = false;
let pendingRequest: "live" | "message" | null = null;
const parentProjection = () =>
({
Expand All @@ -640,12 +641,17 @@ describe("OrchestratorMcpService", () => {
const childRun = () => ({
id: RunId.make("run:mcp-next-child"),
ordinal: 1,
status: finished ? ("completed" as const) : ("running" as const),
delegatedTaskId: taskId,
status: finished && !firstRun ? ("completed" as const) : ("running" as const),
// A task's first run is untagged; the child's fork node names the task.
...(firstRun ? {} : { delegatedTaskId: taskId }),
});
const childProjection = () =>
({
thread: { id: childThreadId, title: "Child task" },
thread: {
id: childThreadId,
title: "Child task",
forkedFrom: { type: "node", nodeId: taskId },
},
runs: [childRun()],
contextTransfers: [],
messages: [],
Expand Down Expand Up @@ -677,7 +683,7 @@ describe("OrchestratorMcpService", () => {
Effect.succeed({
threadId: childThreadId,
run: childRun() as unknown as OrchestrationV2ThreadProjection["runs"][number],
timedOut: !finished,
timedOut: !finished || firstRun,
}),
dispatch: () => Effect.succeed({} as never),
}),
Expand Down Expand Up @@ -725,7 +731,17 @@ describe("OrchestratorMcpService", () => {
assert.equal(working.next, ORCHESTRATOR_MCP_RUNNING_TASK_NEXT);
pendingRequest = null;

firstRun = true;
const first = yield* service.waitForThread(scope, { threadId: childThreadId });
assert.equal(first.next, ORCHESTRATOR_MCP_RUNNING_TASK_NEXT);

// An untagged run after the task has its result is no longer that task.
finished = true;
const followUp = yield* service.waitForThread(scope, { threadId: childThreadId });
assert.isTrue(followUp.timedOut);
assert.notProperty(followUp, "next");
firstRun = false;

const completed = yield* service.taskStatus(scope, taskId);
assert.equal(completed.status, "completed");
assert.notProperty(completed, "next");
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3713,7 +3713,11 @@ const make = Effect.gen(function* () {
})
.pipe(Effect.mapError(threadManagementFailure));
const status = result.run === null ? "idle" : runOutcome(result.run);
const taskId = result.run?.delegatedTaskId;
// A task's first run carries no task id; the child's untagged runs continue that task
// until it has a result.
const taskId =
result.run?.delegatedTaskId ??
(target.thread.forkedFrom?.type === "node" ? target.thread.forkedFrom.nodeId : undefined);
const ownedTask =
result.timedOut &&
status !== "waiting" &&
Expand All @@ -3725,7 +3729,8 @@ const make = Effect.gen(function* () {
task.origin === "app_owned" &&
task.threadId === parent.thread.id &&
task.childThreadId === input.threadId &&
task.completionDelivery?.state !== "disposed",
task.completionDelivery?.state !== "disposed" &&
(result.run?.delegatedTaskId !== undefined || task.result === null),
);
// A child waiting on a question or approval needs an answer, not a wake.
const childRequests = ownedTask
Expand Down
Loading