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
43 changes: 42 additions & 1 deletion apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3414,8 +3414,12 @@ const openSessionWithBackgroundCommand = (fixtureName: string) =>
toolName: "mcp__t3-code__t3_worktree_handoff",
input: {},
}) satisfies OrchestrationV2TurnItem;
const cutOffNodeId = idAllocator.derive.nodeFromProviderItem({
driver: CODEX_DRIVER,
nativeItemId: "cut-off",
});
const seededToolCalls = {
cutOff: toolCall("cut-off", providerThreads[0]!, "running", now),
cutOff: { ...toolCall("cut-off", providerThreads[0]!, "running", now), nodeId: cutOffNodeId },
finished: toolCall("finished", providerThreads[0]!, "completed", now),
otherSession: toolCall("other-session", providerThreads[1]!, "running", now),
// Started by a replacement session after the release.
Expand All @@ -3441,7 +3445,41 @@ const openSessionWithBackgroundCommand = (fixtureName: string) =>
],
});
});
yield* eventSink.write({
events: [
{
id: yield* idAllocator.allocate.event({ threadId }),
type: "node.updated",
threadId,
nodeId: cutOffNodeId,
driver: CODEX_DRIVER,
occurredAt: now,
payload: {
id: cutOffNodeId,
threadId,
runId: null,
parentNodeId: null,
rootNodeId: cutOffNodeId,
kind: "tool_call",
status: "running",
countsForRun: true,
providerThreadId: providerThreads[0]!.id,
providerTurnId: null,
nativeItemRef: null,
runtimeRequestId: null,
checkpointScopeId: null,
startedAt: now,
completedAt: null,
},
},
],
});
yield* Effect.forEach(Object.values(seededToolCalls), writeToolCall);
const cutOffNodeStatus = Effect.gen(function* () {
const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
const projection = yield* projectionStore.getThreadProjection(threadId);
return projection.nodes.find((node) => node.id === cutOffNodeId)?.status;
});
// A background native subagent that outlived its completed run; Claude records no provider thread on it.
const nativeSubagentRunId = idAllocator.derive.run({ threadId, ordinal: 1 });
const nativeSubagentId = idAllocator.derive.nodeFromProviderItem({
Expand Down Expand Up @@ -3525,6 +3563,7 @@ const openSessionWithBackgroundCommand = (fixtureName: string) =>
toolCalls,
toolCallStatus,
nativeSubagentStatus,
cutOffNodeStatus,
};
});

Expand All @@ -3544,6 +3583,7 @@ it.effect.each(["detach", "stream failure", "provider stop", "early close"] as c
seededToolCalls,
writeToolCall,
nativeSubagentStatus,
cutOffNodeStatus,
} = yield* openSessionWithBackgroundCommand("provider-session-manager-detach-roster");
const runtime = Option.getOrThrow(yield* manager.get(providerSessionId));
const subscription = yield* runtime.subscribeEvents!;
Expand Down Expand Up @@ -3628,6 +3668,7 @@ it.effect.each(["detach", "stream failure", "provider stop", "early close"] as c
otherSession: "running",
replacement: "running",
});
assert.equal(yield* cutOffNodeStatus, "interrupted");
// regression: #36548 a native subagent the dead process ran stayed running after its run completed
assert.notInclude(["pending", "running", "waiting"], yield* nativeSubagentStatus);
});
Expand Down
41 changes: 27 additions & 14 deletions apps/server/src/orchestration-v2/ProviderSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,23 +1050,36 @@ export const layerWithOptions = (
// after each pass: queued events can also store more cut-off items.
let pending = yield* readCutOff;
for (let pass = 0; pass < 3 && pending.length > 0; pass++) {
const { nodes } = yield* projectionStore.getThreadRecords(threadId, ["nodes"], {
nodeIds: pending.flatMap((item) => (item.nodeId === null ? [] : [item.nodeId])),
});
for (const item of pending) {
const now = yield* DateTime.now;
yield* eventSink.writeIfTurnItemUnchanged({
expected: item,
events: [
{
id: yield* idAllocator.allocate.event({ threadId, providerSessionId }),
type: "turn-item.updated",
threadId,
...(item.runId === null ? {} : { runId: item.runId }),
...(item.nodeId === null ? {} : { nodeId: item.nodeId }),
driver,
occurredAt: now,
payload: { ...item, status: "interrupted", completedAt: now, updatedAt: now },
},
],
const node = nodes.find((candidate) => candidate.id === item.nodeId);
const events: Array<OrchestrationV2DomainEvent> = [];
if (node !== undefined && isOrchestrationV2WorkActive(node.status)) {
events.push({
id: yield* idAllocator.allocate.event({ threadId, providerSessionId }),
type: "node.updated",
threadId,
...(node.runId === null ? {} : { runId: node.runId }),
nodeId: node.id,
driver,
occurredAt: now,
payload: { ...node, status: "interrupted", completedAt: now },
});
}
events.push({
id: yield* idAllocator.allocate.event({ threadId, providerSessionId }),
type: "turn-item.updated",
threadId,
...(item.runId === null ? {} : { runId: item.runId }),
...(item.nodeId === null ? {} : { nodeId: item.nodeId }),
driver,
occurredAt: now,
payload: { ...item, status: "interrupted", completedAt: now, updatedAt: now },
});
yield* eventSink.writeIfTurnItemUnchanged({ expected: item, events });
}
pending = yield* readCutOff;
}
Expand Down
Loading