Skip to content

Commit c907625

Browse files
khush-2106claude
andcommitted
fix(server): leave an app-owned task's node out of an orphaned run's cascade
An app-owned delegated task has a parent-thread subagent node with the parent run's id and its subagent's id. The projection-rebuilt cascade filtered out its subagent row and turn item but still matched that node, so Stop on an orphaned parent marked it interrupted while the task kept running. Nodes whose id is an app-owned subagent's are now excluded, and the orphaned-stop test seeds both kinds of node. Refs #15197 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d9f769f commit c907625

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,30 @@ it.effect("ends the run of a stopped turn its adapter settled unseen", () =>
694694
},
695695
subagent(nativeSubagentId, "provider_native"),
696696
subagent(appOwnedSubagentId, "app_owned"),
697+
...[nativeSubagentId, appOwnedSubagentId].map((id): OrchestrationV2DomainEvent => ({
698+
...common,
699+
id: EventId.make(`event:${id}:node`),
700+
type: "node.updated",
701+
runId,
702+
nodeId: id,
703+
payload: {
704+
id,
705+
threadId,
706+
runId,
707+
parentNodeId: rootNodeId,
708+
rootNodeId,
709+
kind: "subagent",
710+
status: "running",
711+
countsForRun: false,
712+
providerThreadId: null,
713+
providerTurnId: null,
714+
nativeItemRef: null,
715+
runtimeRequestId: null,
716+
checkpointScopeId: null,
717+
startedAt: now,
718+
completedAt: null,
719+
},
720+
})),
697721
{
698722
...common,
699723
id: EventId.make("event:orphaned-stop:request-node"),
@@ -769,6 +793,9 @@ it.effect("ends the run of a stopped turn its adapter settled unseen", () =>
769793
nativeSubagent: projection.subagents.find((item) => item.id === nativeSubagentId)?.status,
770794
appOwnedSubagent: projection.subagents.find((item) => item.id === appOwnedSubagentId)
771795
?.status,
796+
nativeSubagentNode: projection.nodes.find((node) => node.id === nativeSubagentId)?.status,
797+
appOwnedSubagentNode: projection.nodes.find((node) => node.id === appOwnedSubagentId)
798+
?.status,
772799
request: projection.runtimeRequests.find((request) => request.id === requestId)?.status,
773800
interruptResult: projection.turnItems.some(
774801
(item) => item.runId === runId && item.type === "run_interrupt_result",
@@ -783,6 +810,8 @@ it.effect("ends the run of a stopped turn its adapter settled unseen", () =>
783810
nativeSubagent: "interrupted",
784811
// An app-owned subagent runs on its own run and session.
785812
appOwnedSubagent: "running",
813+
nativeSubagentNode: "interrupted",
814+
appOwnedSubagentNode: "running",
786815
request: "cancelled",
787816
interruptResult: true,
788817
} as const;

‎apps/server/src/orchestration-v2/RunExecutionService.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,18 @@ export function openRunOwnedSubagentsFromProjection(input: {
233233
item.childThreadId === null ? [] : [item.childThreadId],
234234
),
235235
);
236+
// An app-owned task's parent-thread node shares its subagent's id.
237+
const appOwnedSubagentIds = new Set<NodeId>([
238+
...input.subagents.flatMap((subagent) =>
239+
subagent.origin === "app_owned" ? [subagent.id] : [],
240+
),
241+
...input.turnItems.flatMap((item) =>
242+
item.type === "subagent" && item.origin === "app_owned" ? [item.subagentId] : [],
243+
),
244+
]);
236245
const isOwnedNode = (node: OrchestrationV2ExecutionNode) =>
237246
node.threadId === input.run.threadId
238-
? node.kind === "subagent" && node.runId === input.run.id
247+
? node.kind === "subagent" && node.runId === input.run.id && !appOwnedSubagentIds.has(node.id)
239248
: linkedChildThreadIds.has(node.threadId);
240249
return {
241250
subagents: new Map(

0 commit comments

Comments
 (0)