@@ -719,4 +719,197 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => {
719719 assert . deepEqual ( [ ...projected . readyCheckpointOrdinals ] . toSorted ( ) , [ 0 , 1 ] ) ;
720720 } ) ,
721721 ) ;
722+
723+ it . effect ( "keeps the previous run's checkpoint when the workspace has no snapshots" , ( ) =>
724+ Effect . gen ( function * ( ) {
725+ const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
726+ const now = yield * DateTime . now ;
727+ const noGitThreadId = ThreadId . make ( "thread:checkpoint-capture-no-git" ) ;
728+ const noGitRunId = RunId . make ( "run:checkpoint-capture-no-git-2" ) ;
729+ const noGitScopeId = CheckpointScopeId . make ( "scope:checkpoint-capture-no-git" ) ;
730+ const noGitRootNodeId = NodeId . make ( "node:checkpoint-capture-no-git-root" ) ;
731+ const noGitProviderThreadId = ProviderThreadId . make ( "provider-thread:checkpoint-no-git" ) ;
732+ const scope = {
733+ id : noGitScopeId ,
734+ threadId : noGitThreadId ,
735+ runId : noGitRunId ,
736+ nodeId : noGitRootNodeId ,
737+ parentScopeId : null ,
738+ providerThreadId : noGitProviderThreadId ,
739+ kind : "root_run" as const ,
740+ ordinalWithinParent : 0 ,
741+ advancesAppRunCount : true ,
742+ cwd : "/tmp" ,
743+ createdAt : now ,
744+ } ;
745+ const missingCheckpoint = ( input : {
746+ readonly ordinalWithinScope : number ;
747+ readonly runId : RunId | null ;
748+ } ) => ( {
749+ id : CheckpointId . make ( `checkpoint:no-git-${ input . ordinalWithinScope } ` ) ,
750+ threadId : noGitThreadId ,
751+ scopeId : noGitScopeId ,
752+ runId : input . runId ,
753+ nodeId : noGitRootNodeId ,
754+ parentCheckpointId : null ,
755+ ordinalWithinScope : input . ordinalWithinScope ,
756+ appRunOrdinal : input . runId === null ? null : input . ordinalWithinScope ,
757+ ref : CheckpointRef . make ( `checkpoint-ref:no-git-${ input . ordinalWithinScope } ` ) ,
758+ status : "missing" as const ,
759+ files : [ ] ,
760+ capturedAt : now ,
761+ } ) ;
762+ yield * projectionStore . apply ( {
763+ id : EventId . make ( "event:checkpoint-capture-no-git:thread" ) ,
764+ type : "thread.created" ,
765+ threadId : noGitThreadId ,
766+ occurredAt : now ,
767+ payload : {
768+ createdBy : "user" ,
769+ creationSource : "web" ,
770+ id : noGitThreadId ,
771+ projectId,
772+ title : "Checkpoint capture without Git" ,
773+ providerInstanceId,
774+ modelSelection,
775+ runtimeMode : "full-access" ,
776+ interactionMode : "default" ,
777+ branch : null ,
778+ worktreePath : null ,
779+ activeProviderThreadId : null ,
780+ lineage : {
781+ parentThreadId : null ,
782+ relationshipToParent : null ,
783+ rootThreadId : noGitThreadId ,
784+ } ,
785+ forkedFrom : null ,
786+ createdAt : now ,
787+ updatedAt : now ,
788+ archivedAt : null ,
789+ settledOverride : null ,
790+ settledAt : null ,
791+ lastVisitedAt : null ,
792+ deletedAt : null ,
793+ } ,
794+ } ) ;
795+ yield * projectionStore . apply ( {
796+ id : EventId . make ( "event:checkpoint-capture-no-git:run" ) ,
797+ type : "run.updated" ,
798+ threadId : noGitThreadId ,
799+ runId : noGitRunId ,
800+ nodeId : noGitRootNodeId ,
801+ providerInstanceId,
802+ occurredAt : now ,
803+ payload : {
804+ id : noGitRunId ,
805+ threadId : noGitThreadId ,
806+ ordinal : 2 ,
807+ providerInstanceId,
808+ modelSelection,
809+ providerThreadId : noGitProviderThreadId ,
810+ userMessageId : MessageId . make ( "message:checkpoint-capture-no-git" ) ,
811+ rootNodeId : noGitRootNodeId ,
812+ activeAttemptId : null ,
813+ status : "waiting" ,
814+ requestedAt : now ,
815+ startedAt : now ,
816+ completedAt : null ,
817+ checkpointId : null ,
818+ contextHandoffId : null ,
819+ } ,
820+ } ) ;
821+ yield * projectionStore . apply ( {
822+ id : EventId . make ( "event:checkpoint-capture-no-git:node" ) ,
823+ type : "node.updated" ,
824+ threadId : noGitThreadId ,
825+ runId : noGitRunId ,
826+ nodeId : noGitRootNodeId ,
827+ providerInstanceId,
828+ occurredAt : now ,
829+ payload : {
830+ id : noGitRootNodeId ,
831+ threadId : noGitThreadId ,
832+ runId : noGitRunId ,
833+ parentNodeId : null ,
834+ rootNodeId : noGitRootNodeId ,
835+ kind : "root_turn" ,
836+ status : "waiting" ,
837+ countsForRun : true ,
838+ providerThreadId : noGitProviderThreadId ,
839+ providerTurnId : null ,
840+ nativeItemRef : null ,
841+ runtimeRequestId : null ,
842+ checkpointScopeId : noGitScopeId ,
843+ startedAt : now ,
844+ completedAt : null ,
845+ } ,
846+ } ) ;
847+ yield * projectionStore . apply ( {
848+ id : EventId . make ( "event:checkpoint-capture-no-git:provider-thread" ) ,
849+ type : "provider-thread.updated" ,
850+ threadId : noGitThreadId ,
851+ nodeId : noGitRootNodeId ,
852+ driver,
853+ providerInstanceId,
854+ occurredAt : now ,
855+ payload : {
856+ id : noGitProviderThreadId ,
857+ driver,
858+ providerInstanceId,
859+ providerSessionId : null ,
860+ appThreadId : noGitThreadId ,
861+ ownerNodeId : noGitRootNodeId ,
862+ nativeThreadRef : null ,
863+ nativeConversationHeadRef : null ,
864+ status : "idle" ,
865+ firstRunOrdinal : 1 ,
866+ lastRunOrdinal : 2 ,
867+ handoffIds : [ ] ,
868+ forkedFrom : null ,
869+ createdAt : now ,
870+ updatedAt : now ,
871+ } ,
872+ } ) ;
873+ yield * projectionStore . apply ( {
874+ id : EventId . make ( "event:checkpoint-capture-no-git:scope" ) ,
875+ type : "checkpoint-scope.created" ,
876+ threadId : noGitThreadId ,
877+ runId : noGitRunId ,
878+ nodeId : noGitRootNodeId ,
879+ occurredAt : now ,
880+ payload : scope ,
881+ } ) ;
882+
883+ const committed = yield * Ref . make < ReadonlyArray < OrchestrationV2DomainEvent > > ( [ ] ) ;
884+ const layerCapture = CheckpointCaptureService . layer . pipe (
885+ Layer . provide (
886+ Layer . mergeAll (
887+ IdAllocator . layer ,
888+ Layer . mock ( CheckpointService . CheckpointServiceV2 ) ( {
889+ materializeBaselineCheckpoint : ( { ordinalWithinScope } ) =>
890+ Effect . succeed ( missingCheckpoint ( { ordinalWithinScope, runId : null } ) ) ,
891+ capture : ( ) =>
892+ Effect . succeed ( missingCheckpoint ( { ordinalWithinScope : 2 , runId : noGitRunId } ) ) ,
893+ } ) ,
894+ Layer . mock ( EventSink . EventSinkV2 ) ( {
895+ commitCommand : ( input ) =>
896+ Ref . set ( committed , input . events ) . pipe ( Effect . as ( { committed : true } as never ) ) ,
897+ } ) ,
898+ ) ,
899+ ) ,
900+ ) ;
901+
902+ yield * CheckpointCaptureService . CheckpointCaptureServiceV2 . pipe (
903+ Effect . flatMap ( ( service ) =>
904+ service . execute ( { threadId : noGitThreadId , runId : noGitRunId , scopeId : noGitScopeId } ) ,
905+ ) ,
906+ Effect . provide ( layerCapture ) ,
907+ ) ;
908+
909+ const capturedOrdinals = ( yield * Ref . get ( committed ) ) . flatMap ( ( event ) =>
910+ event . type === "checkpoint.captured" ? [ event . payload . ordinalWithinScope ] : [ ] ,
911+ ) ;
912+ assert . deepEqual ( capturedOrdinals , [ 0 , 2 ] ) ;
913+ } ) ,
914+ ) ;
722915} ) ;
0 commit comments