Skip to content

Commit 84d9229

Browse files
t3dotggclaude
andcommitted
fix(server): a failed interrupt never replaces the stored running turn
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 645542e commit 84d9229

2 files changed

Lines changed: 34 additions & 22 deletions

File tree

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,16 +2626,17 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
26262626
);
26272627

26282628
it.effect.each([
2629-
{ status: "completed", failure: "later-stream" },
2630-
{ status: "failed", failure: "later-stream" },
2631-
{ status: "completed", failure: "terminal-ingest" },
2629+
{ status: "completed", failure: "later-stream", interrupt: "succeeds" },
2630+
{ status: "failed", failure: "later-stream", interrupt: "succeeds" },
2631+
{ status: "completed", failure: "terminal-ingest", interrupt: "succeeds" },
2632+
{ status: "completed", failure: "terminal-ingest", interrupt: "fails" },
26322633
] as const)(
2633-
"keeps a $status root provider turn durable after a $failure failure",
2634-
({ status, failure }) =>
2634+
"keeps a $status root provider turn durable after a $failure failure when the interrupt $interrupt",
2635+
({ status, failure, interrupt }) =>
26352636
Effect.gen(function* () {
26362637
const now = yield* DateTime.now;
26372638
const terminalAt = DateTime.subtract(now, { seconds: 1 });
2638-
const key = `terminal-snapshot:${status}:${failure}`;
2639+
const key = `terminal-snapshot:${status}:${failure}:${interrupt}`;
26392640
const durableTurns = yield* Ref.make<
26402641
ReadonlyMap<ProviderTurnId, OrchestrationV2ProviderTurn>
26412642
>(new Map());
@@ -2692,7 +2693,21 @@ it.effect.each([
26922693
}),
26932694
)
26942695
: persist(event.providerTurn).pipe(Effect.as([])),
2695-
interruptTurn: (input) => Ref.update(interrupts, (current) => [...current, input]),
2696+
interruptTurn: (input) =>
2697+
Ref.update(interrupts, (current) => [...current, input]).pipe(
2698+
Effect.andThen(
2699+
interrupt === "fails"
2700+
? Effect.fail(
2701+
new ProviderAdapter.ProviderAdapterInterruptError({
2702+
driver,
2703+
providerThreadId: input.providerThread.id,
2704+
providerTurnId: input.providerTurnId,
2705+
cause: "provider already exited",
2706+
}),
2707+
)
2708+
: Effect.void,
2709+
),
2710+
),
26962711
beforeTerminalWrite: (request) =>
26972712
Effect.forEach(request.events, (event) =>
26982713
event.type === "provider-turn.updated" ? persist(event.payload) : Effect.void,
@@ -2704,10 +2719,9 @@ it.effect.each([
27042719
assert.deepEqual(observed, ["run:failed", "pull-requests-refreshed"]);
27052720
assert.isTrue(finalEvents.some((event) => event.type === "run.updated"));
27062721
const durable = (yield* Ref.get(durableTurns)).get(ids.rootProviderTurnId);
2707-
assert.deepEqual(
2708-
{ status: durable?.status, completedAt: durable?.completedAt },
2709-
{ status, completedAt: terminalAt },
2710-
);
2722+
// A failed interrupt keeps the stored turn running for the next start to retry.
2723+
assert.equal(durable?.status, interrupt === "fails" ? "running" : status);
2724+
assert.deepEqual(durable?.completedAt, interrupt === "fails" ? null : terminalAt);
27112725
}),
27122726
);
27132727

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,21 +1499,19 @@ export const layer: Layer.Layer<
14991499
{ runId: input.run.id, cause: interruptCause },
15001500
).pipe(Effect.as(false)),
15011501
),
1502-
// The snapshot is cached before it is published, so it may not be
1503-
// stored: replay a terminal one as-is. An active turn whose interrupt
1504-
// failed stays running so the next start retries the interrupt.
1502+
// A failed interrupt leaves the stored turn running so the next start
1503+
// retries it. The snapshot is cached before it is published, so it may
1504+
// not be stored: replay a terminal one as-is.
15051505
Effect.map((interrupted) =>
1506-
rootProviderTurn === null
1506+
!interrupted || rootProviderTurn === null
15071507
? null
15081508
: isTerminalProviderTurnStatus(rootProviderTurn.status)
15091509
? rootProviderTurn
1510-
: interrupted
1511-
? {
1512-
...rootProviderTurn,
1513-
status: "interrupted" as const,
1514-
completedAt,
1515-
}
1516-
: null,
1510+
: {
1511+
...rootProviderTurn,
1512+
status: "interrupted" as const,
1513+
completedAt,
1514+
},
15171515
),
15181516
)
15191517
: null;

0 commit comments

Comments
 (0)