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
20 changes: 11 additions & 9 deletions apps/server/src/orchestration-v2/CheckpointCaptureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = stoppedNow
? []
: (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;
Expand Down Expand Up @@ -372,7 +374,7 @@ export const layer: Layer.Layer<
nodeId: rootNode.id,
providerInstanceId: run.providerInstanceId,
occurredAt: capturedAt,
payload: legacyWaiting
payload: settlesRun
? {
...runWithoutDelegatedCompletion,
status: settledStatus,
Expand All @@ -381,7 +383,7 @@ export const layer: Layer.Layer<
}
: { ...runWithoutDelegatedCompletion, checkpointId: checkpoint.id },
},
...(!legacyWaiting
...(!settlesRun
? []
: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
Loading