@@ -2941,28 +2941,18 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
29412941 cause : `Thread ${ command . threadId } is no longer empty.` ,
29422942 } ) ;
29432943 }
2944- const movesProject =
2945- command . type === "thread.metadata.update" &&
2946- command . projectId !== undefined &&
2947- command . projectId !== thread . projectId ;
2948- if (
2949- command . type === "thread.metadata.update" &&
2950- command . projectId !== undefined &&
2951- command . projectId !== thread . projectId
2952- ) {
2953- if ( thread . lineage . relationshipToParent === "subagent" ) {
2954- return yield * new OrchestratorDispatchError ( {
2955- commandId : command . commandId ,
2956- commandType : command . type ,
2957- cause : `Thread ${ command . threadId } is a subagent and moves with its parent.` ,
2958- } ) ;
2959- }
2960- const project = yield * projects . get ( command . projectId ) . pipe ( mapDispatchError ( command ) ) ;
2944+ const targetProjectId =
2945+ command . type === "thread.metadata.update" && command . projectId !== thread . projectId
2946+ ? command . projectId
2947+ : undefined ;
2948+ const movesProject = targetProjectId !== undefined ;
2949+ if ( targetProjectId !== undefined ) {
2950+ const project = yield * projects . get ( targetProjectId ) . pipe ( mapDispatchError ( command ) ) ;
29612951 if ( Option . isNone ( project ) || project . value . deletedAt !== null ) {
29622952 return yield * new OrchestratorDispatchError ( {
29632953 commandId : command . commandId ,
29642954 commandType : command . type ,
2965- cause : `Project ${ command . projectId } does not exist.` ,
2955+ cause : `Project ${ targetProjectId } does not exist.` ,
29662956 } ) ;
29672957 }
29682958 const records = yield * projectionStore
@@ -2975,44 +2965,28 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
29752965 } ,
29762966 )
29772967 . pipe ( mapDispatchError ( command ) ) ;
2978- // Children inherit the parent's project and workspace; moving only the parent would strand them.
2979- if ( records . subagents . some ( ( task ) => task . childThreadId !== null ) ) {
2980- return yield * new OrchestratorDispatchError ( {
2981- commandId : command . commandId ,
2982- commandType : command . type ,
2983- cause : `Thread ${ command . threadId } has child threads and cannot move to another project.` ,
2984- } ) ;
2985- }
2968+ const latestRun = latestExecutedRun ( records . runs ) ;
2969+ // Children share the project; failed worktree setup would retry in the old repo.
29862970 if (
2987- records . runs . some ( ( run ) =>
2988- [ "preparing" , "queued" , "starting" , "running" , "waiting" ] . includes ( run . status ) ,
2989- ) ||
2971+ thread . lineage . relationshipToParent === "subagent" ||
2972+ records . subagents . some ( ( task ) => task . childThreadId !== null ) ||
2973+ records . runs . some ( ( run ) => isBlockingRun ( run ) || run . status === "queued" ) ||
29902974 records . runtimeRequests . some ( ( request ) => request . status === "pending" ) ||
29912975 derivePendingBackgroundWork ( {
29922976 latestRun : records . runs . findLast ( ( run ) => run . status !== "queued" ) ,
29932977 providerThreads : records . providerThreads ,
29942978 turnItems : records . turnItems ,
29952979 activeProviderThreadId : thread . activeProviderThreadId ,
29962980 runs : records . runs ,
2997- } ) . length > 0
2998- ) {
2999- return yield * new OrchestratorDispatchError ( {
3000- commandId : command . commandId ,
3001- commandType : command . type ,
3002- cause : `Thread ${ command . threadId } is busy. Stop it or clear its queue before moving it.` ,
3003- } ) ;
3004- }
3005- // Failed worktree setup holds the queue and would retry in the old project's repo.
3006- const latestRun = latestExecutedRun ( records . runs ) ;
3007- if (
3008- ( latestRun ?. status === "failed" || latestRun ?. status === "interrupted" ) &&
3009- latestRun . workspacePreparation ?. type === "worktree" &&
3010- thread . worktreePath === null
2981+ } ) . length > 0 ||
2982+ ( ( latestRun ?. status === "failed" || latestRun ?. status === "interrupted" ) &&
2983+ latestRun . workspacePreparation ?. type === "worktree" &&
2984+ thread . worktreePath === null )
30112985 ) {
30122986 return yield * new OrchestratorDispatchError ( {
30132987 commandId : command . commandId ,
30142988 commandType : command . type ,
3015- cause : `Thread ${ command . threadId } has failed worktree setup. Retry it or continue locally before moving .` ,
2989+ cause : `Thread ${ command . threadId } must be idle, top-level, and without child threads or failed worktree setup to move .` ,
30162990 } ) ;
30172991 }
30182992 }
@@ -3465,13 +3439,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
34653439 : { } ) ,
34663440 ...( command . branch === undefined ? { } : { branch : command . branch } ) ,
34673441 ...( command . worktreePath === undefined ? { } : { worktreePath : command . worktreePath } ) ,
3468- ...( command . projectId === undefined || command . projectId === thread . projectId
3442+ ...( targetProjectId === undefined
34693443 ? { }
3470- : {
3471- projectId : command . projectId ,
3472- branch : command . branch ?? null ,
3473- worktreePath : command . worktreePath ?? null ,
3474- } ) ,
3444+ : { projectId : targetProjectId , branch : null , worktreePath : null } ) ,
34753445 ...( command . linkedPullRequest === undefined
34763446 ? { }
34773447 : {
0 commit comments