The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a late checkpoint keeps the stopped run's baselines (#30830)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Navid Nadali committed
Nov 6, 2026 at 04:39 UTC
66fa3fe53614959556cd66fc57f3401c6b30e09a
4 files changed
+217
-12
apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts
+198
@@ -477,6 +477,204 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => {
477
}),
478
);
479
480
+ // A stopped run is captured after it ends; by then the next root run, dispatched or queued, may
481
+ // have re-created the thread's one root scope with its own node and time.
482
+ it.effect.each([1, 2])(
483
+ "attributes the baselines a late capture materializes to the stopped run %i",
484
+ (ordinal) =>
485
+ Effect.gen(function* () {
486
+ const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
487
+ const requestedAt = yield* DateTime.now;
488
+ const stoppedAt = DateTime.add(requestedAt, { seconds: 1 });
489
+ const rescopedAt = DateTime.add(requestedAt, { seconds: 2 });
490
+ const lateThreadId = ThreadId.make(`thread:checkpoint-capture-late-${ordinal}`);
491
+ const lateRunId = RunId.make(`run:checkpoint-capture-late-${ordinal}`);
492
+ const lateRootNodeId = NodeId.make(`node:checkpoint-capture-late-${ordinal}-root`);
493
+ const lateScopeId = CheckpointScopeId.make(`scope:checkpoint-capture-late-${ordinal}`);
494
+ const lateProviderThreadId = ProviderThreadId.make(
495
+ `provider-thread:checkpoint-capture-late-${ordinal}`,
496
+ );
497
+ yield* projectionStore.apply({
498
+ id: EventId.make(`event:checkpoint-capture-late-${ordinal}:thread`),
499
+ type: "thread.created",
500
+ threadId: lateThreadId,
501
+ occurredAt: requestedAt,
502
+ payload: {
503
+ createdBy: "user",
504
+ creationSource: "web",
505
+ id: lateThreadId,
506
+ projectId,
507
+ title: "Checkpoint capture after the next run re-created the scope",
508
+ providerInstanceId,
509
+ modelSelection,
510
+ runtimeMode: "full-access",
511
+ interactionMode: "default",
512
+ branch: null,
513
+ worktreePath: null,
514
+ activeProviderThreadId: null,
515
+ lineage: {
516
+ parentThreadId: null,
517
+ relationshipToParent: null,
518
+ rootThreadId: lateThreadId,
519
+ },
520
+ forkedFrom: null,
521
+ createdAt: requestedAt,
522
+ updatedAt: requestedAt,
523
+ archivedAt: null,
524
+ settledOverride: null,
525
+ settledAt: null,
526
+ lastVisitedAt: null,
527
+ deletedAt: null,
528
+ },
529
+ });
530
+ yield* projectionStore.apply({
531
+ id: EventId.make(`event:checkpoint-capture-late-${ordinal}:run`),
532
+ type: "run.updated",
533
+ threadId: lateThreadId,
534
+ runId: lateRunId,
535
+ nodeId: lateRootNodeId,
536
+ providerInstanceId,
537
+ occurredAt: stoppedAt,
538
+ payload: {
539
+ id: lateRunId,
540
+ threadId: lateThreadId,
541
+ ordinal,
542
+ providerInstanceId,
543
+ modelSelection,
544
+ providerThreadId: lateProviderThreadId,
545
+ userMessageId: MessageId.make(`message:checkpoint-capture-late-${ordinal}`),
546
+ rootNodeId: lateRootNodeId,
547
+ activeAttemptId: null,
548
+ status: "interrupted",
549
+ requestedAt,
550
+ startedAt: requestedAt,
551
+ completedAt: stoppedAt,
552
+ checkpointId: null,
553
+ contextHandoffId: null,
554
+ },
555
+ });
556
+ yield* projectionStore.apply({
557
+ id: EventId.make(`event:checkpoint-capture-late-${ordinal}:node`),
558
+ type: "node.updated",
559
+ threadId: lateThreadId,
560
+ runId: lateRunId,
561
+ nodeId: lateRootNodeId,
562
+ providerInstanceId,
563
+ occurredAt: stoppedAt,
564
+ payload: {
565
+ id: lateRootNodeId,
566
+ threadId: lateThreadId,
567
+ runId: lateRunId,
568
+ parentNodeId: null,
569
+ rootNodeId: lateRootNodeId,
570
+ kind: "root_turn",
571
+ status: "interrupted",
572
+ countsForRun: true,
573
+ providerThreadId: lateProviderThreadId,
574
+ providerTurnId: null,
575
+ nativeItemRef: null,
576
+ runtimeRequestId: null,
577
+ checkpointScopeId: lateScopeId,
578
+ startedAt: requestedAt,
579
+ completedAt: stoppedAt,
580
+ },
581
+ });
582
+ yield* projectionStore.apply({
583
+ id: EventId.make(`event:checkpoint-capture-late-${ordinal}:provider-thread`),
584
+ type: "provider-thread.updated",
585
+ threadId: lateThreadId,
586
+ nodeId: lateRootNodeId,
587
+ driver,
588
+ providerInstanceId,
589
+ occurredAt: requestedAt,
590
+ payload: {
591
+ id: lateProviderThreadId,
592
+ driver,
593
+ providerInstanceId,
594
+ providerSessionId: null,
595
+ appThreadId: lateThreadId,
596
+ ownerNodeId: lateRootNodeId,
597
+ nativeThreadRef: null,
598
+ nativeConversationHeadRef: null,
599
+ status: "idle",
600
+ firstRunOrdinal: 1,
601
+ lastRunOrdinal: ordinal,
602
+ handoffIds: [],
603
+ forkedFrom: null,
604
+ createdAt: requestedAt,
605
+ updatedAt: requestedAt,
606
+ },
607
+ });
608
+ const nextRunId = RunId.make(`run:checkpoint-capture-late-${ordinal}-next`);
609
+ const nextRootNodeId = NodeId.make(`node:checkpoint-capture-late-${ordinal}-next-root`);
610
+ yield* projectionStore.apply({
611
+ id: EventId.make(`event:checkpoint-capture-late-${ordinal}:scope-of-next-run`),
612
+ type: "checkpoint-scope.created",
613
+ threadId: lateThreadId,
614
+ runId: nextRunId,
615
+ nodeId: nextRootNodeId,
616
+ occurredAt: rescopedAt,
617
+ payload: {
618
+ id: lateScopeId,
619
+ threadId: lateThreadId,
620
+ runId: nextRunId,
621
+ nodeId: nextRootNodeId,
622
+ parentScopeId: null,
623
+ providerThreadId: lateProviderThreadId,
624
+ kind: "root_run",
625
+ ordinalWithinParent: 0,
626
+ advancesAppRunCount: true,
627
+ cwd: "/repo",
628
+ createdAt: rescopedAt,
629
+ },
630
+ });
631
+
632
+ const committed = yield* Ref.make<ReadonlyArray<OrchestrationV2DomainEvent>>([]);
633
+ const layerCapture = CheckpointCaptureService.layer.pipe(
634
+ Layer.provide(
635
+ Layer.mergeAll(
636
+ IdAllocator.layer,
637
+ CheckpointService.layer.pipe(
638
+ Layer.provide(
639
+ Layer.mergeAll(
640
+ IdAllocator.layer,
641
+ NodeCrypto.layer,
642
+ Layer.mock(CheckpointStore.CheckpointStore)({
643
+ isGitRepository: () => Effect.succeed(true),
644
+ hasCheckpointRef: () => Effect.succeed(true),
645
+ captureCheckpoint: () => Effect.void,
646
+ diffCheckpoints: () => Effect.succeed(""),
647
+ listAuthoredPaths: () => Effect.succeed(null),
648
+ }),
649
+ ),
650
+ ),
651
+ ),
652
+ Layer.mock(EventSink.EventSinkV2)({
653
+ commitCommand: (input) =>
654
+ Ref.set(committed, input.events).pipe(Effect.as({ committed: true } as never)),
655
+ }),
656
+ ),
657
+ ),
658
+ );
659
+ yield* CheckpointCaptureService.CheckpointCaptureServiceV2.use((service) =>
660
+ service.execute({ threadId: lateThreadId, runId: lateRunId, scopeId: lateScopeId }),
661
+ ).pipe(Effect.provide(layerCapture));
662
+
663
+ const baselines = (yield* Ref.get(committed)).flatMap((event) =>
664
+ event.type === "checkpoint.captured" && event.payload.runId === null ? [event] : [],
665
+ );
666
+ assert.deepEqual(
667
+ baselines.map((event) => event.payload.ordinalWithinScope),
668
+ ordinal === 1 ? [0] : [0, 1],
669
+ );
670
+ for (const baseline of baselines) {
671
+ assert.equal(baseline.nodeId, lateRootNodeId);
672
+ assert.equal(baseline.payload.nodeId, lateRootNodeId);
673
+ assert.deepEqual(baseline.payload.capturedAt, requestedAt);
674
+ }
675
+ }),
676
+ );
677
+
678
it.effect("records the checkpoint of a cancelled run and keeps it cancelled", () =>
679
Effect.gen(function* () {
680
const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
apps/server/src/orchestration-v2/CheckpointCaptureService.ts
+12
-10
@@ -103,21 +103,23 @@ export const layer: Layer.Layer<
103
const baselineOrdinalWithinScope = Math.max(0, run.ordinal - 1);
104
const hasReadyCheckpoint = (ordinalWithinScope: number) =>
105
readyCheckpointOrdinals.includes(ordinalWithinScope);
106
+ // The baselines this capture materializes are attributed to the run materializing them. The
107
+ // thread's scope may already be a later run's: one queued meanwhile, or sent after Stop.
108
+ const materializeBaseline = (ordinalWithinScope: number) =>
109
+ checkpoints.materializeBaselineCheckpoint({
110
+ scope,
111
+ ordinalWithinScope,
112
+ nodeId: rootNode.id,
113
+ capturedAt: run.requestedAt,
114
+ forceMissing: sideChat,
115
+ });
116
const threadStartCheckpoint =
117
baselineOrdinalWithinScope === 0 || hasReadyCheckpoint(0)
118
? null
109
- : yield* checkpoints.materializeBaselineCheckpoint({
110
- scope,
111
- ordinalWithinScope: 0,
112
- forceMissing: sideChat,
113
- });
119
+ : yield* materializeBaseline(0);
120
const baselineCheckpoint = hasReadyCheckpoint(baselineOrdinalWithinScope)
121
? null
116
- : yield* checkpoints.materializeBaselineCheckpoint({
117
- scope,
118
- ordinalWithinScope: baselineOrdinalWithinScope,
119
- forceMissing: sideChat,
120
- });
122
+ : yield* materializeBaseline(baselineOrdinalWithinScope);
123
const checkpoint = yield* checkpoints.capture({
124
scope,
125
runId: run.id,
apps/server/src/orchestration-v2/CheckpointService.test.ts
+2
@@ -87,6 +87,8 @@ it.effect(
87
const materialized = yield* checkpoints.materializeBaselineCheckpoint({
88
scope,
89
ordinalWithinScope: 0,
90
+ nodeId: scope.nodeId,
91
+ capturedAt: scope.createdAt,
92
});
93
assert.strictEqual(materialized.status, "missing");
94
}
apps/server/src/orchestration-v2/CheckpointService.ts
+5
-2
@@ -118,6 +118,9 @@ export interface CheckpointServiceV2Shape {
118
readonly materializeBaselineCheckpoint: (input: {
119
readonly scope: OrchestrationV2CheckpointScope;
120
readonly ordinalWithinScope: number;
121
+ /** The run materializing the baseline: its root node, and when it was requested. */
122
+ readonly nodeId: NodeId;
123
+ readonly capturedAt: DateTime.Utc;
124
/** Records a missing checkpoint without touching git, for side chats sharing a parent's worktree. */
125
readonly forceMissing?: boolean;
126
}) => Effect.Effect<OrchestrationV2Checkpoint, CheckpointServiceV2Error>;
@@ -324,14 +327,14 @@ export const layer: Layer.Layer<
327
id: checkpointId,
328
scope: input.scope,
329
runId: null,
327
- nodeId: input.scope.nodeId,
330
+ nodeId: input.nodeId,
331
parentCheckpointId: null,
332
ordinalWithinScope: input.ordinalWithinScope,
333
appRunOrdinal: null,
334
ref: checkpointRef,
335
status: available ? "ready" : "missing",
336
files: [],
334
- capturedAt: input.scope.createdAt,
337
+ capturedAt: input.capturedAt,
338
});
339
}),
340
).pipe(