fix(server): a worktree handoff's continuation no longer waits behind its own detached run #24444
Closed
matthias-scale(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/24444/head·opened View on GitHubShowing 2 changed files with 207 additions and 1 deletion.
x
@@ -1452,8 +1452,21 @@
+ // A worktree handoff detaches the running session on purpose, which fails
+ // its run; that failure says nothing about the provider, and holding the
+ // queue would strand the handoff's own continuation.
+ const failedSessionId = projection.providerThreads.find(
Thread on line 1458
🔴 Critical orchestration-v2/Orchestrator.ts:1458
After a real worktree handoff, the failed run’s provider session is absent from projection.providerSessions, so failedSessionCwd is undefined and workspaceMovedAway stays false; the queued continuation is then held as though the provider had failed. WorktreeMcpService reaches this path by dispatching thread.metadata.update, which detaches the session before the turn fails, and the projection no longer loads sessions without their bindings. Read the historical session independently of its current binding or persist the handoff signal before detaching.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/orchestration-v2/Orchestrator.ts around line 1458:
After a real worktree handoff, the failed run’s provider session is absent from `projection.providerSessions`, so `failedSessionCwd` is `undefined` and `workspaceMovedAway` stays `false`; the queued continuation is then held as though the provider had failed. `WorktreeMcpService` reaches this path by dispatching `thread.metadata.update`, which detaches the session before the turn fails, and the projection no longer loads sessions without their bindings. Read the historical session independently of its current binding or persist the handoff signal before detaching.
+ (thread) => thread.id === failedRun?.providerThreadId,
+ )?.providerSessionId;
+ const failedSessionCwd = projection.providerSessions.find(
+ (session) => session.id === failedSessionId,
+ )?.cwd;
+ const workspaceMovedAway =
+ projection.thread.worktreePath !== null &&
+ failedSessionCwd !== undefined &&
+ failedSessionCwd !== projection.thread.worktreePath;
- failedRun?.id === options?.failedRunId
+ failedRun?.id === options?.failedRunId && !workspaceMovedAway
193 additions and 0 deletions+193-0apps/server/src/orchestration-v2/runtimeLayer.test.tsModifiedView file
@@ -4395,6 +4395,199 @@