Skip to content

Commit 9cd5a85

Browse files
test(server): reproduce pingdotgg#33432 unscoped MCP send to a finished delegated child is not tracked as a follow-up
A thread send with no sender thread (the t3 thread send CLI, or any MCP session without a thread scope) to a finished delegated child starts a run that never becomes a follow-up task on the parent, so the parent is never woken when it finishes.
1 parent b8c2cfa commit 9cd5a85

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

‎apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,90 @@ it.layer(Layer.merge(layerTest, ProviderContinuationRequests.layer))(
24672467
}),
24682468
);
24692469

2470+
it.effect("tracks an unscoped MCP send to a finished child as a follow-up", () =>
2471+
Effect.gen(function* () {
2472+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2473+
const eventSink = yield* EventSink.EventSinkV2;
2474+
const requests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
2475+
const now = yield* DateTime.now;
2476+
const parentThreadId = ThreadId.make("thread:unscoped-followup");
2477+
const projectId = ProjectId.make("project:unscoped-followup");
2478+
const parentRunId = RunId.make("run:unscoped-followup");
2479+
const rootNodeId = NodeId.make("node:unscoped-followup");
2480+
yield* seedParentWithTerminalTask({
2481+
threadId: parentThreadId,
2482+
projectId,
2483+
runId: parentRunId,
2484+
rootNodeId,
2485+
taskId: NodeId.make("node:unscoped-followup-seed"),
2486+
deliveryState: "acknowledged",
2487+
now,
2488+
});
2489+
const child = yield* seedRestartCancelledChild({
2490+
parentThreadId,
2491+
projectId,
2492+
parentRunId,
2493+
rootNodeId,
2494+
name: "unscoped-followup-child",
2495+
completionWake: "always",
2496+
continuationPending: false,
2497+
runStatus: "completed",
2498+
now,
2499+
});
2500+
yield* orchestrator.recoverDelegatedTasks;
2501+
let firstWake = yield* requests.take;
2502+
while (firstWake.threadId !== parentThreadId) firstWake = yield* requests.take;
2503+
yield* orchestrator.dispatch({
2504+
type: "delegated_task.completion-delivery.acknowledge",
2505+
commandId: CommandId.make("command:unscoped-followup-ack"),
2506+
parentThreadId,
2507+
taskId: child.taskId,
2508+
observedByRunId: parentRunId,
2509+
});
2510+
const parentRun = (yield* orchestrator.getThreadProjection(parentThreadId)).runs.find(
2511+
(run) => run.id === parentRunId,
2512+
)!;
2513+
yield* eventSink.write({
2514+
commandId: reconcileCommandId("unscoped-followup-parent-finished"),
2515+
events: [
2516+
{
2517+
id: EventId.make("event:unscoped-followup-parent-finished"),
2518+
type: "run.updated",
2519+
threadId: parentThreadId,
2520+
runId: parentRunId,
2521+
occurredAt: now,
2522+
payload: { ...parentRun, status: "completed", completedAt: now },
2523+
},
2524+
],
2525+
});
2526+
// `t3 thread send` and other MCP sessions without a thread scope carry no sender.
2527+
const messageId = MessageId.make("message:unscoped-followup");
2528+
yield* orchestrator.dispatch({
2529+
type: "message.dispatch",
2530+
createdBy: "agent",
2531+
creationSource: "mcp",
2532+
commandId: CommandId.make("command:unscoped-followup-send"),
2533+
threadId: child.childThreadId,
2534+
messageId,
2535+
text: "Check the same work again.",
2536+
attachments: [],
2537+
dispatchMode: { type: "start_immediately" },
2538+
});
2539+
const run = (yield* orchestrator.getThreadProjection(child.childThreadId)).runs.find(
2540+
(row) => row.userMessageId === messageId,
2541+
)!;
2542+
assert.isDefined(
2543+
run.delegatedTaskId,
2544+
"the child's follow-up run is not tracked as a delegated task on its parent",
2545+
);
2546+
const followup = (yield* orchestrator.getThreadProjection(parentThreadId)).subagents.find(
2547+
(task) => task.id === run.delegatedTaskId,
2548+
);
2549+
assert.equal(followup?.childThreadId, child.childThreadId);
2550+
assert.equal(followup?.completionWake, "always");
2551+
}),
2552+
);
2553+
24702554
it.effect("tracks a child's usage-limit auto-resume as a follow-up", () =>
24712555
Effect.gen(function* () {
24722556
const orchestrator = yield* Orchestrator.OrchestratorV2;

0 commit comments

Comments
 (0)