@@ -727,7 +727,12 @@ const writeParentRun = (input: {
727727 queuePosition : null ,
728728 requestedAt : now ,
729729 startedAt : now ,
730- completedAt : input . status === "completed" ? now : null ,
730+ completedAt :
731+ input . status === "preparing" ||
732+ input . status === "running" ||
733+ input . status === "queued"
734+ ? null
735+ : now ,
731736 checkpointId : input . stable ? CheckpointId . make ( `${ input . runId } :checkpoint` ) : null ,
732737 contextHandoffId : null ,
733738 ...( input . status === "preparing" ||
@@ -1029,6 +1034,61 @@ it.effect("a side chat waits for the parent's new worktree, also after its setup
10291034 } ) . pipe ( Effect . provide ( forkCases [ 0 ] ! . layer ) ) ,
10301035) ;
10311036
1037+ it . effect ( "a side chat opens once a later run has worked in the project checkout" , ( ) =>
1038+ Effect . gen ( function * ( ) {
1039+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1040+ const parentId = ThreadId . make ( "side-chat-worktree-abandoned-parent" ) ;
1041+ const sideChatId = ThreadId . make ( "side-chat-worktree-abandoned-child" ) ;
1042+ yield * createParent ( parentId ) ;
1043+ yield * writeParentRun ( {
1044+ threadId : parentId ,
1045+ runId : RunId . make ( "side-chat-worktree-abandoned-run-1" ) ,
1046+ ordinal : 1 ,
1047+ status : "interrupted" ,
1048+ text : "Stopped during setup" ,
1049+ } ) ;
1050+ yield * writeParentRun ( {
1051+ threadId : parentId ,
1052+ runId : RunId . make ( "side-chat-worktree-abandoned-run-2" ) ,
1053+ ordinal : 2 ,
1054+ status : "completed" ,
1055+ text : "Worked in the project checkout" ,
1056+ stable : true ,
1057+ } ) ;
1058+
1059+ yield * forkSideChat ( "side-chat-worktree-abandoned-fork" , parentId , sideChatId ) ;
1060+ assert . isNull ( ( yield * orchestrator . getThreadProjection ( sideChatId ) ) . thread . deletedAt ) ;
1061+
1062+ // A retried setup that is running again, or failed again, comes after the later run.
1063+ for ( const status of [ "preparing" , "failed" ] as const ) {
1064+ const retriedParentId = ThreadId . make ( `side-chat-worktree-retried-parent-${ status } ` ) ;
1065+ yield * createParent ( retriedParentId ) ;
1066+ yield * writeParentRun ( {
1067+ threadId : retriedParentId ,
1068+ runId : RunId . make ( `side-chat-worktree-retried-run-2-${ status } ` ) ,
1069+ ordinal : 2 ,
1070+ status : "completed" ,
1071+ text : "Worked in the project checkout" ,
1072+ stable : true ,
1073+ } ) ;
1074+ yield * TestClock . adjust ( "1 second" ) ;
1075+ yield * writeParentRun ( {
1076+ threadId : retriedParentId ,
1077+ runId : RunId . make ( `side-chat-worktree-retried-run-1-${ status } ` ) ,
1078+ ordinal : 1 ,
1079+ status,
1080+ text : "Retried setup" ,
1081+ } ) ;
1082+ const rejected = yield * forkSideChat (
1083+ `side-chat-worktree-retried-fork-${ status } ` ,
1084+ retriedParentId ,
1085+ ThreadId . make ( `side-chat-worktree-retried-child-${ status } ` ) ,
1086+ ) . pipe ( Effect . flip ) ;
1087+ assert . include ( String ( rejected . cause ) , "has no worktree yet" , status ) ;
1088+ }
1089+ } ) . pipe ( Effect . provide ( forkCases [ 0 ] ! . layer ) ) ,
1090+ ) ;
1091+
10321092it . effect ( "closing a side chat deletes it only while unused; a deleted parent takes no more" , ( ) =>
10331093 Effect . gen ( function * ( ) {
10341094 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments