From 0dcdc2e0981818f85ba1bb370bded9540e997a87 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 19:20:37 +0000 Subject: [PATCH 1/5] test(server): a Stop request on a waiting run must not end as completed Fails on main: checkpoint capture flips a waiting run to completed even though a run_interrupt_request with no result is stored for it (#41617). Co-Authored-By: Claude Opus 5.5 --- .../CheckpointCaptureService.test.ts | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts index cc570a9ef113d..cb7d48fc8accb 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts @@ -16,6 +16,7 @@ import { ProviderThreadId, RunId, ThreadId, + TurnItemId, } from "@t3tools/contracts"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; @@ -1172,6 +1173,222 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }), ); + it.effect("does not complete a waiting run whose Stop request has no result yet", () => + Effect.gen(function* () { + const projectionStore = yield* ProjectionStore.ProjectionStoreV2; + const now = yield* DateTime.now; + const sideChatThreadId = ThreadId.make("thread:checkpoint-capture-stop-request"); + const sideChatRunId = RunId.make("run:checkpoint-capture-stop-request"); + const sideChatScopeId = CheckpointScopeId.make("scope:checkpoint-capture-stop-request"); + const sideChatRootNodeId = NodeId.make("node:checkpoint-capture-stop-request-root"); + const sideChatProviderThreadId = ProviderThreadId.make( + "provider-thread:checkpoint-capture-stop-request", + ); + const event = { threadId: sideChatThreadId, occurredAt: now }; + const events: ReadonlyArray = [ + { + ...event, + id: EventId.make("event:checkpoint-capture-stop-request:thread"), + type: "thread.created", + payload: { + createdBy: "user", + creationSource: "web", + id: sideChatThreadId, + projectId, + title: "Side chat", + providerInstanceId, + modelSelection, + runtimeMode: "approval-required", + interactionMode: "default", + branch: null, + worktreePath: "/repo", + activeProviderThreadId: null, + lineage: { + parentThreadId: threadId, + relationshipToParent: "fork", + rootThreadId: threadId, + sideChat: true, + }, + forkedFrom: null, + createdAt: now, + updatedAt: now, + archivedAt: null, + settledOverride: null, + settledAt: null, + lastVisitedAt: null, + deletedAt: null, + }, + }, + { + ...event, + id: EventId.make("event:checkpoint-capture-stop-request:provider-thread"), + type: "provider-thread.updated", + driver, + providerInstanceId, + payload: { + id: sideChatProviderThreadId, + driver, + providerInstanceId, + providerSessionId: null, + appThreadId: sideChatThreadId, + ownerNodeId: null, + nativeThreadRef: null, + nativeConversationHeadRef: null, + status: "idle", + firstRunOrdinal: 1, + lastRunOrdinal: 1, + handoffIds: [], + forkedFrom: null, + createdAt: now, + updatedAt: now, + }, + }, + { + ...event, + id: EventId.make("event:checkpoint-capture-stop-request:run"), + type: "run.updated", + runId: sideChatRunId, + payload: { + id: sideChatRunId, + threadId: sideChatThreadId, + ordinal: 1, + providerInstanceId, + modelSelection, + providerThreadId: sideChatProviderThreadId, + userMessageId: MessageId.make("message:checkpoint-capture-stop-request"), + rootNodeId: sideChatRootNodeId, + activeAttemptId: null, + status: "waiting", + requestedAt: now, + startedAt: now, + completedAt: null, + checkpointId: null, + contextHandoffId: null, + }, + }, + { + ...event, + id: EventId.make("event:checkpoint-capture-stop-request:node"), + type: "node.updated", + runId: sideChatRunId, + nodeId: sideChatRootNodeId, + payload: { + id: sideChatRootNodeId, + threadId: sideChatThreadId, + runId: sideChatRunId, + parentNodeId: null, + rootNodeId: sideChatRootNodeId, + kind: "root_turn", + status: "waiting", + countsForRun: true, + providerThreadId: sideChatProviderThreadId, + providerTurnId: null, + nativeItemRef: null, + runtimeRequestId: null, + checkpointScopeId: sideChatScopeId, + startedAt: now, + completedAt: null, + }, + }, + { + ...event, + id: EventId.make("event:checkpoint-capture-stop-request:scope"), + type: "checkpoint-scope.created", + runId: sideChatRunId, + nodeId: sideChatRootNodeId, + payload: { + id: sideChatScopeId, + threadId: sideChatThreadId, + runId: sideChatRunId, + nodeId: sideChatRootNodeId, + parentScopeId: null, + providerThreadId: sideChatProviderThreadId, + kind: "root_run", + ordinalWithinParent: 0, + advancesAppRunCount: true, + cwd: "/repo", + createdAt: now, + }, + }, + // Stop committed its request while the provider's completed terminal was finalizing. + { + ...event, + id: EventId.make("event:checkpoint-capture-stop-request:interrupt-request"), + type: "turn-item.updated", + runId: sideChatRunId, + nodeId: sideChatRootNodeId, + providerInstanceId, + payload: { + id: TurnItemId.make("turn-item:checkpoint-capture-stop-request:interrupt-request"), + type: "run_interrupt_request", + threadId: sideChatThreadId, + runId: sideChatRunId, + nodeId: sideChatRootNodeId, + providerThreadId: sideChatProviderThreadId, + providerTurnId: null, + nativeItemRef: null, + parentItemId: null, + ordinal: 1, + status: "completed", + title: "Interrupt requested", + startedAt: now, + completedAt: now, + updatedAt: now, + message: "Stopped by user", + }, + }, + ]; + yield* Effect.forEach(events, (candidate) => projectionStore.apply(candidate)); + const gitUnavailable = () => Effect.die("side chats must not snapshot the shared worktree"); + const layerCapture = CheckpointCaptureService.layer.pipe( + Layer.provide( + Layer.mergeAll( + IdAllocator.layer, + CheckpointService.layer.pipe( + Layer.provide( + Layer.mergeAll( + IdAllocator.layer, + NodeCrypto.layer, + layerNoTrackedFolders, + Layer.mock(CheckpointStore.CheckpointStore)({ + isGitRepository: gitUnavailable, + captureCheckpoint: gitUnavailable, + hasCheckpointRef: gitUnavailable, + }), + ), + ), + ), + Layer.mock(EventSink.EventSinkV2)({ + commitCommand: (input) => + Effect.forEach(input.events, (committed) => projectionStore.apply(committed)).pipe( + Effect.as({ committed: true } as never), + Effect.orDie, + ), + }), + ), + ), + ); + + yield* CheckpointCaptureService.CheckpointCaptureServiceV2.use((service) => + service.execute({ + threadId: sideChatThreadId, + runId: sideChatRunId, + scopeId: sideChatScopeId, + }), + ).pipe(Effect.provide(layerCapture)); + + const { checkpoints, runs } = yield* projectionStore.getThreadRecords(sideChatThreadId, [ + "runs", + "checkpoints", + ]); + assert.equal(runs[0]?.status, "interrupted"); + assert.notEqual( + checkpoints.find((candidate) => candidate.id === runs[0]?.checkpointId), + undefined, + ); + }), + ); + // A thread on real Git checkouts: `folders` is what the project tracks, read at each turn. const withTrackedRepositories = ( name: string, From d206bc2d0993c74449211ede0bdb734efb3c7651 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 19:28:14 +0000 Subject: [PATCH 2/5] fix(server): a Stop accepted on a waiting run now ends it as interrupted Checkpoint capture finalized a waiting run as completed from its status alone, so a Stop that landed while the provider's terminal was finalizing or the checkpoint was being captured was dropped: the request never got a result and the turn showed as a normal finish (#41617). Under the thread lock, capture now looks for an unanswered run_interrupt_request and, if one exists, ends the run and root node as interrupted and writes the matching run_interrupt_result. Co-Authored-By: Claude Opus 5.5 --- .../CheckpointCaptureService.ts | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index dd7f27079a4e5..a7202d5b00a9f 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -21,6 +21,7 @@ import * as CheckpointService from "./CheckpointService.ts"; import * as EventSink from "./EventSink.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProjectionStore from "./ProjectionStore.ts"; +import * as RunExecutionService from "./RunExecutionService.ts"; import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; // Git processes are already capped server-wide; this keeps one thread from taking every slot. @@ -259,6 +260,18 @@ export const layer: Layer.Layer< if (currentRun.status !== "waiting" && !stoppedNow) { return; } + // Stop on a waiting run only records its request; the run must still end stopped. + const { turnItems: stopItems } = stoppedNow + ? { turnItems: [] } + : yield* projections.getThreadRecords(input.threadId, ["turnItems"], { + turnItemTypes: ["run_interrupt_request", "run_interrupt_result"], + turnItemRunIds: [run.id], + }); + const stopRequest = stopItems.some((item) => item.type === "run_interrupt_result") + ? undefined + : stopItems.find((item) => item.type === "run_interrupt_request"); + const stopRequested = stopRequest?.type === "run_interrupt_request"; + const finalStatus = stopRequested ? ("interrupted" as const) : ("completed" as const); // Omit delegatedCompletion to preserve cohort writes made after capture loaded the run. const { delegatedCompletion: _delegatedCompletion, ...runWithoutDelegatedCompletion } = currentRun; @@ -328,6 +341,27 @@ export const layer: Layer.Layer< completedAt: capturedAt, }), }, + ...(stopRequested + ? [ + { + id: yield* ids.allocate.event({ threadId: input.threadId, commandId }), + type: "turn-item.updated" as const, + threadId: input.threadId, + runId: run.id, + nodeId: rootNode.id, + providerInstanceId: run.providerInstanceId, + occurredAt: capturedAt, + payload: RunExecutionService.makeInterruptResultTurnItem({ + idAllocator: ids, + run, + rootNode, + providerThread, + reason: stopRequest.message, + completedAt: capturedAt, + }), + }, + ] + : []), { id: yield* ids.allocate.event({ threadId: input.threadId, commandId }), type: "run.updated", @@ -340,7 +374,7 @@ export const layer: Layer.Layer< ? { ...runWithoutDelegatedCompletion, checkpointId: checkpoint.id } : { ...runWithoutDelegatedCompletion, - status: "completed", + status: finalStatus, completedAt: capturedAt, checkpointId: checkpoint.id, }, @@ -358,7 +392,7 @@ export const layer: Layer.Layer< occurredAt: capturedAt, payload: { ...rootNode, - status: "completed" as const, + status: finalStatus, completedAt: capturedAt, checkpointScopeId: scope.id, }, From 367647d58c313fa312591b41584c01150d419a33 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 19:41:09 +0000 Subject: [PATCH 3/5] fix(server): leave a Stop delivered to a provider turn to that turn's outcome A Stop that targeted a finished turn's background work is sent to that provider turn, and the turn's own completion stands (pinned by the task_cancel checkpoint test). Only a request that reached no provider turn now ends a waiting run as interrupted during checkpoint capture. Co-Authored-By: Claude Opus 5.5 --- .../server/src/orchestration-v2/CheckpointCaptureService.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index a7202d5b00a9f..38d3eef834edc 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -260,7 +260,8 @@ export const layer: Layer.Layer< if (currentRun.status !== "waiting" && !stoppedNow) { return; } - // Stop on a waiting run only records its request; the run must still end stopped. + // A Stop that reached no provider turn only recorded its request; only capture can end the + // run stopped. One delivered to a provider turn (its background work) defers to that turn. const { turnItems: stopItems } = stoppedNow ? { turnItems: [] } : yield* projections.getThreadRecords(input.threadId, ["turnItems"], { @@ -270,7 +271,8 @@ export const layer: Layer.Layer< const stopRequest = stopItems.some((item) => item.type === "run_interrupt_result") ? undefined : stopItems.find((item) => item.type === "run_interrupt_request"); - const stopRequested = stopRequest?.type === "run_interrupt_request"; + const stopRequested = + stopRequest?.type === "run_interrupt_request" && stopRequest.providerTurnId === null; const finalStatus = stopRequested ? ("interrupted" as const) : ("completed" as const); // Omit delegatedCompletion to preserve cohort writes made after capture loaded the run. const { delegatedCompletion: _delegatedCompletion, ...runWithoutDelegatedCompletion } = From d77a2382057a2a08b551aadb711f742242c4279a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 19:58:35 +0000 Subject: [PATCH 4/5] fix(server): honour a Stop that reached a turn before it ended Stop on a running run is sent to its provider turn, and a turn that finishes successfully before the interrupt lands was still recorded as completed. Capture now ends a waiting run interrupted when its unanswered Stop request reached no provider turn or was recorded before the run's attempt ended. A Stop sent after the turn ended, to its background work, still leaves the turn's own completion. Co-Authored-By: Claude Opus 5.5 --- .../CheckpointCaptureService.test.ts | 109 ++++++++++++++---- .../CheckpointCaptureService.ts | 17 ++- 2 files changed, 96 insertions(+), 30 deletions(-) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts index cb7d48fc8accb..ce3d5afb47999 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts @@ -14,6 +14,8 @@ import { ProviderDriverKind, ProviderInstanceId, ProviderThreadId, + ProviderTurnId, + RunAttemptId, RunId, ThreadId, TurnItemId, @@ -1173,22 +1175,31 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }), ); - it.effect("does not complete a waiting run whose Stop request has no result yet", () => + // Stop recorded on a waiting run: `turn` is the provider turn it was sent to, with when its attempt + // ended relative to the request; none means it reached no provider turn. + const captureWithStopRequest = (name: string, turn?: { readonly endedAfterStop: boolean }) => Effect.gen(function* () { const projectionStore = yield* ProjectionStore.ProjectionStoreV2; const now = yield* DateTime.now; - const sideChatThreadId = ThreadId.make("thread:checkpoint-capture-stop-request"); - const sideChatRunId = RunId.make("run:checkpoint-capture-stop-request"); - const sideChatScopeId = CheckpointScopeId.make("scope:checkpoint-capture-stop-request"); - const sideChatRootNodeId = NodeId.make("node:checkpoint-capture-stop-request-root"); + const sideChatThreadId = ThreadId.make(`thread:checkpoint-capture-stop-request-${name}`); + const sideChatRunId = RunId.make(`run:checkpoint-capture-stop-request-${name}`); + const sideChatScopeId = CheckpointScopeId.make( + `scope:checkpoint-capture-stop-request-${name}`, + ); + const sideChatRootNodeId = NodeId.make(`node:checkpoint-capture-stop-request-${name}-root`); const sideChatProviderThreadId = ProviderThreadId.make( - "provider-thread:checkpoint-capture-stop-request", + `provider-thread:checkpoint-capture-stop-request-${name}`, + ); + const stoppedAt = DateTime.add(now, { seconds: 1 }); + const attemptId = RunAttemptId.make(`attempt:checkpoint-capture-stop-request-${name}`); + const providerTurnId = ProviderTurnId.make( + `provider-turn:checkpoint-capture-stop-request-${name}`, ); const event = { threadId: sideChatThreadId, occurredAt: now }; const events: ReadonlyArray = [ { ...event, - id: EventId.make("event:checkpoint-capture-stop-request:thread"), + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:thread`), type: "thread.created", payload: { createdBy: "user", @@ -1221,7 +1232,7 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }, { ...event, - id: EventId.make("event:checkpoint-capture-stop-request:provider-thread"), + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:provider-thread`), type: "provider-thread.updated", driver, providerInstanceId, @@ -1245,7 +1256,7 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }, { ...event, - id: EventId.make("event:checkpoint-capture-stop-request:run"), + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:run`), type: "run.updated", runId: sideChatRunId, payload: { @@ -1255,9 +1266,9 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { providerInstanceId, modelSelection, providerThreadId: sideChatProviderThreadId, - userMessageId: MessageId.make("message:checkpoint-capture-stop-request"), + userMessageId: MessageId.make(`message:checkpoint-capture-stop-request-${name}`), rootNodeId: sideChatRootNodeId, - activeAttemptId: null, + activeAttemptId: turn === undefined ? null : attemptId, status: "waiting", requestedAt: now, startedAt: now, @@ -1268,7 +1279,7 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }, { ...event, - id: EventId.make("event:checkpoint-capture-stop-request:node"), + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:node`), type: "node.updated", runId: sideChatRunId, nodeId: sideChatRootNodeId, @@ -1292,7 +1303,7 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }, { ...event, - id: EventId.make("event:checkpoint-capture-stop-request:scope"), + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:scope`), type: "checkpoint-scope.created", runId: sideChatRunId, nodeId: sideChatRootNodeId, @@ -1310,30 +1321,57 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { createdAt: now, }, }, + ...(turn === undefined + ? [] + : [ + { + ...event, + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:attempt`), + type: "run-attempt.updated" as const, + runId: sideChatRunId, + nodeId: sideChatRootNodeId, + providerInstanceId, + payload: { + id: attemptId, + runId: sideChatRunId, + attemptOrdinal: 1, + rootNodeId: sideChatRootNodeId, + providerInstanceId, + providerThreadId: sideChatProviderThreadId, + providerTurnId, + reason: "initial" as const, + status: "completed" as const, + startedAt: now, + completedAt: turn.endedAfterStop ? DateTime.add(stoppedAt, { seconds: 1 }) : now, + }, + }, + ]), // Stop committed its request while the provider's completed terminal was finalizing. { ...event, - id: EventId.make("event:checkpoint-capture-stop-request:interrupt-request"), + id: EventId.make(`event:checkpoint-capture-stop-request-${name}:interrupt-request`), type: "turn-item.updated", runId: sideChatRunId, nodeId: sideChatRootNodeId, providerInstanceId, payload: { - id: TurnItemId.make("turn-item:checkpoint-capture-stop-request:interrupt-request"), + id: TurnItemId.make( + `turn-item:checkpoint-capture-stop-request-${name}:interrupt-request`, + ), type: "run_interrupt_request", threadId: sideChatThreadId, runId: sideChatRunId, nodeId: sideChatRootNodeId, providerThreadId: sideChatProviderThreadId, - providerTurnId: null, + providerTurnId: turn === undefined ? null : providerTurnId, nativeItemRef: null, parentItemId: null, ordinal: 1, status: "completed", title: "Interrupt requested", - startedAt: now, - completedAt: now, - updatedAt: now, + startedAt: stoppedAt, + completedAt: stoppedAt, + updatedAt: stoppedAt, message: "Stopped by user", }, }, @@ -1377,15 +1415,38 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => { }), ).pipe(Effect.provide(layerCapture)); - const { checkpoints, runs } = yield* projectionStore.getThreadRecords(sideChatThreadId, [ - "runs", - "checkpoints", - ]); - assert.equal(runs[0]?.status, "interrupted"); + const { checkpoints, runs, turnItems } = yield* projectionStore.getThreadRecords( + sideChatThreadId, + ["runs", "checkpoints", "turnItems"], + ); assert.notEqual( checkpoints.find((candidate) => candidate.id === runs[0]?.checkpointId), undefined, ); + return { + status: runs[0]?.status, + answered: turnItems.some((item) => item.type === "run_interrupt_result"), + }; + }); + + it.effect("does not complete a waiting run whose Stop request has no result yet", () => + Effect.gen(function* () { + const outcome = yield* captureWithStopRequest("unreached"); + assert.deepEqual(outcome, { status: "interrupted", answered: true }); + }), + ); + + it.effect("ends interrupted a run whose turn completed after Stop reached it", () => + Effect.gen(function* () { + const outcome = yield* captureWithStopRequest("live", { endedAfterStop: true }); + assert.deepEqual(outcome, { status: "interrupted", answered: true }); + }), + ); + + it.effect("completes a run whose turn ended before Stop was sent to its background work", () => + Effect.gen(function* () { + const outcome = yield* captureWithStopRequest("background", { endedAfterStop: false }); + assert.deepEqual(outcome, { status: "completed", answered: false }); }), ); diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index 38d3eef834edc..5b5428bb5f62e 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -260,19 +260,24 @@ export const layer: Layer.Layer< if (currentRun.status !== "waiting" && !stoppedNow) { return; } - // A Stop that reached no provider turn only recorded its request; only capture can end the - // run stopped. One delivered to a provider turn (its background work) defers to that turn. - const { turnItems: stopItems } = stoppedNow - ? { turnItems: [] } - : yield* projections.getThreadRecords(input.threadId, ["turnItems"], { + // An unanswered Stop ends the run stopped when it reached no provider turn, or reached the + // turn before it ended. One sent after the turn ended only stops its background work. + const { turnItems: stopItems, attempts } = stoppedNow + ? { turnItems: [], attempts: [] } + : yield* projections.getThreadRecords(input.threadId, ["turnItems", "attempts"], { turnItemTypes: ["run_interrupt_request", "run_interrupt_result"], turnItemRunIds: [run.id], + attemptIds: currentRun.activeAttemptId === null ? [] : [currentRun.activeAttemptId], }); const stopRequest = stopItems.some((item) => item.type === "run_interrupt_result") ? undefined : stopItems.find((item) => item.type === "run_interrupt_request"); + const attemptEndedAt = attempts[0]?.completedAt ?? null; const stopRequested = - stopRequest?.type === "run_interrupt_request" && stopRequest.providerTurnId === null; + stopRequest?.type === "run_interrupt_request" && + (stopRequest.providerTurnId === null || + (attemptEndedAt !== null && + DateTime.isLessThan(stopRequest.startedAt, attemptEndedAt))); const finalStatus = stopRequested ? ("interrupted" as const) : ("completed" as const); // Omit delegatedCompletion to preserve cohort writes made after capture loaded the run. const { delegatedCompletion: _delegatedCompletion, ...runWithoutDelegatedCompletion } = From e7015182981dd67a853a20d0510185502e4b3e24 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 20:05:44 +0000 Subject: [PATCH 5/5] fix(server): skip a Stop request without a start time in the attempt comparison Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/CheckpointCaptureService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index 5b5428bb5f62e..29d722602f6aa 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -277,6 +277,7 @@ export const layer: Layer.Layer< stopRequest?.type === "run_interrupt_request" && (stopRequest.providerTurnId === null || (attemptEndedAt !== null && + stopRequest.startedAt !== null && DateTime.isLessThan(stopRequest.startedAt, attemptEndedAt))); const finalStatus = stopRequested ? ("interrupted" as const) : ("completed" as const); // Omit delegatedCompletion to preserve cohort writes made after capture loaded the run.