@@ -2947,45 +2947,20 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
29472947 : undefined ;
29482948 if ( targetProjectId !== undefined ) {
29492949 const project = yield * projects . get ( targetProjectId ) . pipe ( mapDispatchError ( command ) ) ;
2950- if ( Option . isNone ( project ) || project . value . deletedAt !== null ) {
2951- return yield * new OrchestratorDispatchError ( {
2952- commandId : command . commandId ,
2953- commandType : command . type ,
2954- cause : `Project ${ targetProjectId } does not exist.` ,
2955- } ) ;
2956- }
2957- const records = yield * projectionStore
2958- . getThreadRecords (
2959- command . threadId ,
2960- [ "runs" , "runtimeRequests" , "subagents" , "providerThreads" , "turnItems" ] ,
2961- {
2962- turnItemTypes : [ "command_execution" , "dynamic_tool" , "subagent" ] ,
2963- turnItemStatuses : [ "pending" , "running" , "waiting" ] ,
2964- } ,
2965- )
2950+ const { subagents } = yield * projectionStore
2951+ . getThreadRecords ( command . threadId , [ "subagents" ] )
29662952 . pipe ( mapDispatchError ( command ) ) ;
2967- const latestRun = latestExecutedRun ( records . runs ) ;
2968- // Children share the project; failed worktree setup would retry in the old repo.
29692953 if (
2954+ Option . isNone ( project ) ||
2955+ project . value . deletedAt !== null ||
2956+ thread . settledAt === null ||
29702957 thread . lineage . relationshipToParent === "subagent" ||
2971- records . subagents . some ( ( task ) => task . childThreadId !== null ) ||
2972- records . runs . some ( ( run ) => isBlockingRun ( run ) || run . status === "queued" ) ||
2973- records . runtimeRequests . some ( ( request ) => request . status === "pending" ) ||
2974- derivePendingBackgroundWork ( {
2975- latestRun : records . runs . findLast ( ( run ) => run . status !== "queued" ) ,
2976- providerThreads : records . providerThreads ,
2977- turnItems : records . turnItems ,
2978- activeProviderThreadId : thread . activeProviderThreadId ,
2979- runs : records . runs ,
2980- } ) . length > 0 ||
2981- ( ( latestRun ?. status === "failed" || latestRun ?. status === "interrupted" ) &&
2982- latestRun . workspacePreparation ?. type === "worktree" &&
2983- thread . worktreePath === null )
2958+ subagents . some ( ( task ) => task . childThreadId !== null )
29842959 ) {
29852960 return yield * new OrchestratorDispatchError ( {
29862961 commandId : command . commandId ,
29872962 commandType : command . type ,
2988- cause : `Thread ${ command . threadId } must be idle, top-level, and without child threads or failed worktree setup to move .` ,
2963+ cause : `Only a settled top-level thread without child threads can move to an existing project .` ,
29892964 } ) ;
29902965 }
29912966 }
@@ -3145,18 +3120,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
31453120 }
31463121 }
31473122
3148- const changesWorkspace =
3149- targetProjectId !== undefined ||
3150- ( command . type === "thread.metadata.update" &&
3151- command . worktreePath !== undefined &&
3152- command . worktreePath !== thread . worktreePath ) ;
31533123 const needsProviderState =
31543124 command . type === "thread.runtime-mode.set" ||
31553125 command . type === "thread.model-selection.set" ||
31563126 command . type === "provider.switch" ||
31573127 command . type === "thread.archive" ||
31583128 command . type === "thread.settle" ||
3159- changesWorkspace ;
3129+ ( command . type === "thread.metadata.update" &&
3130+ command . worktreePath !== undefined &&
3131+ command . worktreePath !== thread . worktreePath ) ;
31603132 const providerContext = needsProviderState
31613133 ? yield * projectionStore
31623134 . getThreadProviderContext (
@@ -3417,7 +3389,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
34173389 snooze : command . limitRecovery . snooze ?? previousRecovery ?. snooze ?? false ,
34183390 requestId : command . commandId ,
34193391 } ;
3420- const updated : OrchestrationV2AppThread = {
3392+ return {
34213393 ...thread ,
34223394 ...( command . title === undefined ? { } : { title : command . title } ) ,
34233395 ...( command . limitRecovery === undefined ? { } : { limitRecovery } ) ,
@@ -3475,15 +3447,6 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
34753447 : { } ) ,
34763448 updatedAt : now ,
34773449 } ;
3478- // Watches read through the project's checkout, which no longer holds these links.
3479- return targetProjectId !== undefined
3480- ? {
3481- ...updated ,
3482- pullRequests : updated . pullRequests ?. map ( ( link ) =>
3483- withPullRequestWatch ( link , undefined ) ,
3484- ) ,
3485- }
3486- : updated ;
34873450 }
34883451 case "thread.pull-request.link" :
34893452 case "thread.pull-request.unlink" :
@@ -3915,7 +3878,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
39153878 const detachSessionIds = new Set (
39163879 command . type === "thread.archive" || command . type === "thread.settle"
39173880 ? ( providerContext ?. providerSessions ?? [ ] ) . map ( ( session ) => session . id )
3918- : changesWorkspace
3881+ : command . type === "thread.metadata.update" &&
3882+ command . worktreePath !== undefined &&
3883+ command . worktreePath !== thread . worktreePath
39193884 ? ( providerContext ?. providerSessions ?? [ ] ) . map ( ( session ) => session . id )
39203885 : command . type === "thread.runtime-mode.set"
39213886 ? ( providerContext ?. providerSessions ?? [ ] )
0 commit comments