From 0004692f213d9fefbb5ef47a26cd17469c729f87 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 22:29:50 +0000 Subject: [PATCH 1/2] fix(server): checkpoint capture no longer throws on an undefined stop flag #41685 and #41362 merged together left CheckpointCaptureService reading `stoppedNow`, which #41362 had replaced with `legacyWaiting`. Only runs still `waiting` are settled by capture, so look up a pending Stop only for them. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/CheckpointCaptureService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index 97ca5cc8d48c3..34c427bb2f915 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -263,7 +263,7 @@ export const layer: Layer.Layer< } // A Stop accepted once the provider's turn had ended stored only its request: the // terminal already wrote `waiting`. That Stop still wins, and gets its result here. - const stopSignals = stoppedNow + const stopSignals = !legacyWaiting ? [] : (yield* projections.getThreadRecords(input.threadId, ["turnItems"], { turnItemTypes: ["run_interrupt_request", "run_interrupt_result"], From c7bbfa331e6b97e6b3ce40ad3c4fec6d313b8c7e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 22:43:00 +0000 Subject: [PATCH 2/2] fix(server): a Stop accepted after the turn ends still interrupts the run Since #41362 a run settles as completed when its provider turn ends, and commands treat it as waiting until its checkpoint capture commits. A Stop accepted in that window stored only its request, so the run stayed completed. Checkpoint capture now looks for that pending Stop on completed runs too and settles the run as interrupted with its result, as #41685 intended. Co-Authored-By: Claude Opus 5.5 --- .../CheckpointCaptureService.ts | 20 ++++++++++--------- .../SteeringCompletion.integration.test.ts | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index 34c427bb2f915..62bda6bb35263 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -262,18 +262,20 @@ export const layer: Layer.Layer< return; } // A Stop accepted once the provider's turn had ended stored only its request: the - // terminal already wrote `waiting`. That Stop still wins, and gets its result here. - const stopSignals = !legacyWaiting - ? [] - : (yield* projections.getThreadRecords(input.threadId, ["turnItems"], { - turnItemTypes: ["run_interrupt_request", "run_interrupt_result"], - turnItemRunIds: [run.id], - })).turnItems; + // terminal already wrote `completed` (or legacy `waiting`). That Stop still wins here. + const stopSignals = + !legacyWaiting && currentRun.status !== "completed" + ? [] + : (yield* projections.getThreadRecords(input.threadId, ["turnItems"], { + turnItemTypes: ["run_interrupt_request", "run_interrupt_result"], + turnItemRunIds: [run.id], + })).turnItems; const stopRequest = stopSignals.some((item) => item.type === "run_interrupt_result") ? undefined : stopSignals.find((item) => item.type === "run_interrupt_request"); const settledStatus = stopRequest === undefined ? ("completed" as const) : ("interrupted" as const); + const settlesRun = legacyWaiting || stopRequest !== undefined; // Omit delegatedCompletion to preserve cohort writes made after capture loaded the run. const { delegatedCompletion: _delegatedCompletion, ...runWithoutDelegatedCompletion } = currentRun; @@ -372,7 +374,7 @@ export const layer: Layer.Layer< nodeId: rootNode.id, providerInstanceId: run.providerInstanceId, occurredAt: capturedAt, - payload: legacyWaiting + payload: settlesRun ? { ...runWithoutDelegatedCompletion, status: settledStatus, @@ -381,7 +383,7 @@ export const layer: Layer.Layer< } : { ...runWithoutDelegatedCompletion, checkpointId: checkpoint.id }, }, - ...(!legacyWaiting + ...(!settlesRun ? [] : [ { diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index 7ecd0c428ca15..4a665211ef68b 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -3473,12 +3473,12 @@ it.effect( }); const draining = yield* worker.drain().pipe(Effect.forkScoped); yield* Deferred.await(interruptReached); - const waiting = yield* orchestrator.streamDomainEvents.pipe( + const completed = yield* orchestrator.streamDomainEvents.pipe( Stream.filter( (event) => event.type === "run.updated" && event.payload.id === first.runId && - event.payload.status === "waiting", + event.payload.status === "completed", ), Stream.take(1), Stream.runDrain, @@ -3500,7 +3500,7 @@ it.effect( failure: null, threadDisposition: "reusable", }); - yield* Fiber.join(waiting); + yield* Fiber.join(completed); yield* Deferred.succeed(releaseInterrupt, undefined); yield* Fiber.join(draining); yield* worker.drain();