Skip to content

Commit 3d902df

Browse files
fix(server): also interrupt tool nodes whose item never arrived
Adapters report a tool call's node and its item as separate events, so a stream lost between them left an open node with no item. Interrupt every open tool node of the run, not only those paired with an open item.
1 parent 22aa4a4 commit 3d902df

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,7 @@ it.effect("closes the run's open tool calls when its provider stream is lost", (
34633463
const finishedItemId = TurnItemId.make(`turn-item:${key}:finished`);
34643464
const commandItemId = TurnItemId.make(`turn-item:${key}:command`);
34653465
const imageData = "iVBORw0KGgo".repeat(16);
3466+
const unpairedNodeId = NodeId.make(`node:${key}:unpaired`);
34663467
const { written, observed } = yield* captureRootRunTermination({
34673468
key,
34683469
shouldFinalizeRun: () => Effect.succeed(true),
@@ -3477,6 +3478,8 @@ it.effect("closes the run's open tool calls when its provider stream is lost", (
34773478
{ source: { type: "base64", media_type: "image/png", data: imageData } },
34783479
),
34793480
backgroundTurnItemEvent(ids, "command_execution", "running", 4, commandItemId),
3481+
// The stream ends before this node's item arrives.
3482+
toolCallNodeEvent(ids, "running", unpairedNodeId),
34803483
]),
34813484
// A provider switch releases the session, which fails its event stream.
34823485
Stream.fail(
@@ -3490,6 +3493,7 @@ it.effect("closes the run's open tool calls when its provider stream is lost", (
34903493
});
34913494
assert.deepEqual(observed, [
34923495
`node:${toolItemId}:node:interrupted`,
3496+
`node:${unpairedNodeId}:interrupted`,
34933497
"run:failed",
34943498
"pull-requests-refreshed",
34953499
]);
@@ -3833,12 +3837,13 @@ function backgroundTurnItemEvent(
38333837
function toolCallNodeEvent(
38343838
ids: BackgroundScenarioIds,
38353839
status: "running" | "completed",
3840+
nodeId: NodeId = NodeId.make(`${ids.itemId}:node`),
38363841
): ProviderAdapterV2Event {
38373842
return {
38383843
type: "node.updated",
38393844
driver,
38403845
node: {
3841-
id: NodeId.make(`${ids.itemId}:node`),
3846+
id: nodeId,
38423847
threadId: ids.threadId,
38433848
runId: ids.runId,
38443849
kind: "tool_call",

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,20 @@ function interruptOpenRunToolCalls(input: {
350350
> {
351351
return Effect.gen(function* () {
352352
const events: Array<OrchestrationV2DomainEvent> = [];
353+
// A node can arrive without its item when the stream ends between the two.
354+
for (const node of input.open.nodes.values()) {
355+
events.push({
356+
id: yield* input.allocateEventId(),
357+
type: "node.updated",
358+
threadId: node.threadId,
359+
runId: input.run.id,
360+
nodeId: node.id,
361+
providerInstanceId: input.run.providerInstanceId,
362+
occurredAt: input.completedAt,
363+
payload: { ...node, status: "interrupted", completedAt: input.completedAt },
364+
});
365+
}
353366
for (const turnItem of input.open.turnItems.values()) {
354-
const node = turnItem.nodeId === null ? undefined : input.open.nodes.get(turnItem.nodeId);
355-
if (node !== undefined) {
356-
events.push({
357-
id: yield* input.allocateEventId(),
358-
type: "node.updated",
359-
threadId: node.threadId,
360-
runId: input.run.id,
361-
nodeId: node.id,
362-
providerInstanceId: input.run.providerInstanceId,
363-
occurredAt: input.completedAt,
364-
payload: { ...node, status: "interrupted", completedAt: input.completedAt },
365-
});
366-
}
367367
events.push({
368368
id: yield* input.allocateEventId(),
369369
type: "turn-item.updated",

0 commit comments

Comments
 (0)