Skip to content

Commit 7469c37

Browse files
committed
fix(server): recover failed interrupts before turn binding
1 parent 0ad8979 commit 7469c37

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,62 @@ describe("ProviderCommandReactor", () => {
25692569
}),
25702570
);
25712571

2572+
effectIt.effect("stops a starting session without a bound turn when interrupt fails", () =>
2573+
Effect.gen(function* () {
2574+
const harness = yield* Effect.promise(() =>
2575+
createHarness({
2576+
interruptTurnEffect: () =>
2577+
Effect.fail(
2578+
new ProviderAdapterRequestError({
2579+
provider: "codex",
2580+
method: "thread.interrupt",
2581+
detail: "provider session disappeared",
2582+
}),
2583+
),
2584+
}),
2585+
);
2586+
const now = "2026-01-01T00:00:00.000Z";
2587+
2588+
yield* harness.engine.dispatch({
2589+
type: "thread.session.set",
2590+
commandId: CommandId.make("cmd-session-set-interrupt-starting"),
2591+
threadId: ThreadId.make("thread-1"),
2592+
session: {
2593+
threadId: ThreadId.make("thread-1"),
2594+
status: "starting",
2595+
providerName: "codex",
2596+
runtimeMode: "approval-required",
2597+
activeTurnId: null,
2598+
lastError: null,
2599+
updatedAt: now,
2600+
},
2601+
createdAt: now,
2602+
});
2603+
2604+
yield* harness.engine.dispatch({
2605+
type: "thread.turn.interrupt",
2606+
commandId: CommandId.make("cmd-turn-interrupt-starting-provider-failure"),
2607+
threadId: ThreadId.make("thread-1"),
2608+
createdAt: now,
2609+
});
2610+
2611+
yield* Effect.promise(() => harness.drain());
2612+
2613+
const thread = (yield* Effect.promise(() => harness.readModel())).threads.find(
2614+
(entry) => entry.id === ThreadId.make("thread-1"),
2615+
);
2616+
expect(thread?.session).toMatchObject({
2617+
status: "stopped",
2618+
activeTurnId: null,
2619+
lastError: "provider session disappeared",
2620+
});
2621+
expect(harness.stopSession).toHaveBeenCalledWith({ threadId: ThreadId.make("thread-1") });
2622+
expect(
2623+
thread?.activities.find((activity) => activity.kind === "provider.turn.interrupt.failed"),
2624+
).toMatchObject({ payload: { detail: "provider session disappeared" } });
2625+
}),
2626+
);
2627+
25722628
effectIt.effect("does not overwrite a session that became ready while an interrupt failed", () =>
25732629
Effect.gen(function* () {
25742630
const harness = yield* Effect.promise(() => createHarness());

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,9 @@ const make = Effect.gen(function* () {
12041204
if (
12051205
!latestSession ||
12061206
latestSession.status === "stopped" ||
1207-
latestSession.activeTurnId === null ||
1207+
latestSession.status === "ready" ||
12081208
(event.payload.turnId !== undefined &&
1209+
latestSession.activeTurnId !== null &&
12091210
latestSession.activeTurnId !== event.payload.turnId)
12101211
) {
12111212
return;
@@ -1231,8 +1232,9 @@ const make = Effect.gen(function* () {
12311232
if (
12321233
!stoppedSession ||
12331234
stoppedSession.status === "stopped" ||
1234-
stoppedSession.activeTurnId === null ||
1235+
stoppedSession.status === "ready" ||
12351236
(event.payload.turnId !== undefined &&
1237+
stoppedSession.activeTurnId !== null &&
12361238
stoppedSession.activeTurnId !== event.payload.turnId)
12371239
) {
12381240
return;

0 commit comments

Comments
 (0)