Skip to content

Commit c8ecd1f

Browse files
jeroenptrsclaude
andcommitted
test(server): reproduce a follow-up task finishing while the child's subagent still runs
A parent sent its delegated child a follow-up with t3_thread_send. The child's run started a native background subagent and ended. The follow-up task got the run's interim reply as its result and the parent was told it completed while the subagent kept running (pingdotgg#16603, the report from jamesvillarrubia). finalizeAppOwnedSubagent holds only the child's original task on delegatedTaskProgress. A follow-up finalizes as soon as its own run ends, and task_status and delegatedTaskResultPending take the same shortcut. The new test seeds that sequence and fails today. It is quarantined under pingdotgg#16603 because a fix has to change all three places and route the later wake to the same follow-up, which is what upstream pingdotgg#21877 does. Holding finalization alone would still hand the parent the interim reply as the result. The other cases from pingdotgg#16603 do not reproduce on this branch, and nothing changes for them: - Original task, nested native subagent still running: held until it ends, covered by "finalizes a child whose run ended before a nested subagent settled". - Original task, background command still running: held while the command is marked awaited with t3_background_wait, covered by "finalizes a child whose run ended before a background command settled" and the awaited rows in SubagentProjection.test.ts. An unmarked command does not hold the task on purpose (pingdotgg#24610, pingdotgg#27468), so a child that leaves a dev server running still finishes. Counting every active command_execution turn item would undo that rule. Refs pingdotgg#16603. Written with Claude Opus 5.5 in Claude Code (T3 Code). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0420d6e commit c8ecd1f

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,109 @@ it.layer(Layer.merge(layerTest, ProviderContinuationRequests.layer))(
24002400
}),
24012401
);
24022402

2403+
// quarantine: #16603 follow-ups skip the child's progress check; upstream #21877 fixes it with wake routing
2404+
it.effect.skip("holds a follow-up while a subagent its run started still runs", () =>
2405+
Effect.gen(function* () {
2406+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2407+
const eventSink = yield* EventSink.EventSinkV2;
2408+
const now = yield* DateTime.now;
2409+
const parentThreadId = ThreadId.make("thread:followup-nested");
2410+
const projectId = ProjectId.make("project:followup-nested");
2411+
const parentRunId = RunId.make("run:followup-nested");
2412+
const rootNodeId = NodeId.make("node:followup-nested");
2413+
yield* seedParentWithTerminalTask({
2414+
threadId: parentThreadId,
2415+
projectId,
2416+
runId: parentRunId,
2417+
rootNodeId,
2418+
taskId: NodeId.make("node:seed-followup-nested"),
2419+
deliveryState: "acknowledged",
2420+
now,
2421+
});
2422+
const child = yield* seedRestartCancelledChild({
2423+
parentThreadId,
2424+
projectId,
2425+
parentRunId,
2426+
rootNodeId,
2427+
name: "followup-nested-child",
2428+
completionWake: "always",
2429+
continuationPending: false,
2430+
runStatus: "completed",
2431+
now,
2432+
});
2433+
yield* orchestrator.recoverDelegatedTasks;
2434+
const messageId = MessageId.make("message:followup-nested");
2435+
yield* orchestrator.dispatch({
2436+
type: "message.dispatch",
2437+
createdBy: "agent",
2438+
creationSource: "mcp",
2439+
commandId: CommandId.make("command:followup-nested-send"),
2440+
threadId: child.childThreadId,
2441+
senderThreadId: parentThreadId,
2442+
messageId,
2443+
text: "Check the same work again.",
2444+
attachments: [],
2445+
dispatchMode: { type: "start_immediately" },
2446+
});
2447+
const run = (yield* orchestrator.getThreadProjection(child.childThreadId)).runs.find(
2448+
(row) => row.userMessageId === messageId,
2449+
)!;
2450+
assert.isDefined(run.delegatedTaskId);
2451+
const nestedId = NodeId.make("node:followup-nested-native");
2452+
yield* eventSink.write({
2453+
commandId: reconcileCommandId("followup-nested-finish"),
2454+
events: [
2455+
{
2456+
id: EventId.make("event:followup-nested-native"),
2457+
type: "subagent.updated",
2458+
threadId: child.childThreadId,
2459+
runId: run.id,
2460+
nodeId: nestedId,
2461+
driver,
2462+
providerInstanceId: modelSelection.instanceId,
2463+
occurredAt: now,
2464+
payload: {
2465+
id: nestedId,
2466+
threadId: child.childThreadId,
2467+
runId: run.id,
2468+
parentNodeId: NodeId.make("node:followup-nested-child-root"),
2469+
origin: "provider_native",
2470+
createdBy: "agent",
2471+
driver,
2472+
providerInstanceId: modelSelection.instanceId,
2473+
providerThreadId: null,
2474+
childThreadId: null,
2475+
nativeTaskRef: null,
2476+
prompt: "Research prices in the background.",
2477+
title: null,
2478+
model: null,
2479+
status: "running",
2480+
result: null,
2481+
startedAt: now,
2482+
completedAt: null,
2483+
updatedAt: now,
2484+
},
2485+
},
2486+
{
2487+
id: EventId.make("event:followup-nested-finish"),
2488+
type: "run.updated",
2489+
threadId: child.childThreadId,
2490+
runId: run.id,
2491+
occurredAt: now,
2492+
payload: { ...run, status: "completed", startedAt: now, completedAt: now },
2493+
},
2494+
],
2495+
});
2496+
yield* orchestrator.recoverDelegatedTasks;
2497+
2498+
const followup = (yield* orchestrator.getThreadProjection(parentThreadId)).subagents.find(
2499+
(task) => task.id === run.delegatedTaskId,
2500+
);
2501+
assert.isNull(followup?.result);
2502+
assert.notEqual(followup?.status, "completed");
2503+
}),
2504+
);
2505+
24032506
it.effect("tracks a child's usage-limit auto-resume as a follow-up", () =>
24042507
Effect.gen(function* () {
24052508
const orchestrator = yield* Orchestrator.OrchestratorV2;

0 commit comments

Comments
 (0)