@@ -613,7 +613,7 @@ const writeParentRun = (input: {
613613 readonly threadId : ThreadId ;
614614 readonly runId : RunId ;
615615 readonly ordinal : number ;
616- readonly status : "running" | "completed" ;
616+ readonly status : "preparing" | " running" | "completed" ;
617617 readonly text : string ;
618618 /** A checkpointed run on a native provider thread, which `latest_stable` forks start from. */
619619 readonly stable ?: boolean ;
@@ -682,6 +682,9 @@ const writeParentRun = (input: {
682682 completedAt : input . status === "completed" ? now : null ,
683683 checkpointId : input . stable ? CheckpointId . make ( `${ input . runId } :checkpoint` ) : null ,
684684 contextHandoffId : null ,
685+ ...( input . status === "preparing"
686+ ? { workspacePreparation : { type : "worktree" as const , baseRef : "main" } }
687+ : { } ) ,
685688 } ,
686689 } ,
687690 {
@@ -718,6 +721,55 @@ const writeParentRun = (input: {
718721 } ) ;
719722 } ) ;
720723
724+ /** Marks `threadId` as imported from V1 and gives it one runless imported user message. */
725+ const writeImportedHistory = ( threadId : ThreadId , text : string ) =>
726+ Effect . gen ( function * ( ) {
727+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
728+ const eventSink = yield * EventSink . EventSinkV2 ;
729+ const now = yield * DateTime . now ;
730+ const { thread } = yield * orchestrator . getThreadProjection ( threadId ) ;
731+ yield * eventSink . write ( {
732+ events : [
733+ {
734+ id : EventId . make ( `${ threadId } :imported` ) ,
735+ type : "thread.metadata-updated" ,
736+ threadId,
737+ occurredAt : now ,
738+ payload : { ...thread , historyOrigin : "v1_import" } ,
739+ } ,
740+ {
741+ id : EventId . make ( `${ threadId } :imported-item` ) ,
742+ type : "turn-item.updated" ,
743+ threadId,
744+ occurredAt : now ,
745+ payload : {
746+ id : TurnItemId . make ( `${ threadId } :imported-item` ) ,
747+ threadId,
748+ runId : null ,
749+ nodeId : null ,
750+ providerThreadId : null ,
751+ providerTurnId : null ,
752+ nativeItemRef : null ,
753+ parentItemId : null ,
754+ ordinal : 1 ,
755+ status : "completed" ,
756+ title : null ,
757+ startedAt : now ,
758+ completedAt : now ,
759+ updatedAt : now ,
760+ type : "user_message" ,
761+ createdBy : "user" ,
762+ creationSource : "web" ,
763+ inputIntent : "turn_start" ,
764+ messageId : MessageId . make ( `${ threadId } :imported-message` ) ,
765+ text,
766+ attachments : [ ] ,
767+ } ,
768+ } ,
769+ ] ,
770+ } ) ;
771+ } ) ;
772+
721773const createParent = ( threadId : ThreadId ) =>
722774 Effect . gen ( function * ( ) {
723775 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
@@ -797,6 +849,27 @@ it.effect("a side chat of an idle parent still starts with the framing note", ()
797849 } ) . pipe ( Effect . provide ( forkCases [ 0 ] ! . layer ) ) ,
798850) ;
799851
852+ it . effect ( "a side chat waits for the parent's new worktree" , ( ) =>
853+ Effect . gen ( function * ( ) {
854+ const parentId = ThreadId . make ( "side-chat-worktree-parent" ) ;
855+ yield * createParent ( parentId ) ;
856+ yield * writeParentRun ( {
857+ threadId : parentId ,
858+ runId : RunId . make ( "side-chat-worktree-parent-run" ) ,
859+ ordinal : 1 ,
860+ status : "preparing" ,
861+ text : "Parent work" ,
862+ } ) ;
863+
864+ const rejected = yield * forkSideChat (
865+ "side-chat-worktree-fork" ,
866+ parentId ,
867+ ThreadId . make ( "side-chat-worktree-child" ) ,
868+ ) . pipe ( Effect . flip ) ;
869+ assert . include ( String ( rejected . cause ) , "still preparing its worktree" ) ;
870+ } ) . pipe ( Effect . provide ( forkCases [ 0 ] ! . layer ) ) ,
871+ ) ;
872+
800873it . effect ( "closing a side chat deletes it only while unused; a deleted parent takes no more" , ( ) =>
801874 Effect . gen ( function * ( ) {
802875 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
@@ -849,6 +922,7 @@ it.effect("a side chat opened during the parent's first turn starts from a diges
849922 const parentId = ThreadId . make ( "side-chat-busy-parent" ) ;
850923 const sideChatId = ThreadId . make ( "side-chat-busy-child" ) ;
851924 yield * createParent ( parentId ) ;
925+ yield * writeImportedHistory ( parentId , "PARENT_IMPORTED_MARKER" ) ;
852926 yield * writeParentRun ( {
853927 threadId : parentId ,
854928 runId : RunId . make ( "side-chat-busy-parent-run" ) ,
@@ -934,6 +1008,7 @@ it.effect("a side chat opened during the parent's first turn starts from a diges
9341008 contextHandoffId : handoff ! . id ,
9351009 } ) ;
9361010 assert . include ( handoff ! . summaryText , "You are in a side chat beside the main thread." ) ;
1011+ assert . include ( handoff ! . summaryText , "- User: PARENT_IMPORTED_MARKER" ) ;
9371012 assert . include ( handoff ! . summaryText , "- User: PARENT_RUNNING_MARKER" ) ;
9381013 assert . include ( handoff ! . summaryText , `t3_thread_read on thread ${ parentId } ` ) ;
9391014 assert . equal (
0 commit comments