Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a worktree handoff's continuation no longer waits behind its own detached run #24444

Closedmatthias-scale(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/24444/headopened View on GitHub

Showing 2 changed files with 207 additions and 1 deletion.

x
0 of 2 viewed, 2 left
14 additions and 1 deletionapps/server/src/orchestration-v2/Orchestrator.tsModified
View file
@@ -1452,8 +1452,21 @@
// A message queued behind a worktree that was cancelled or never created
// would run in the project checkout instead, so it waits for the user.
const failedRun = latestExecutedRun(projection.runs);
+ // 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
macroscopeapp[bot](GitHub profile, opens in a new tab)commented

🔴 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;
const failureClass =
- failedRun?.id === options?.failedRunId
+ failedRun?.id === options?.failedRunId && !workspaceMovedAway
? latestRootProviderFailure(failedRun, projection.turnItems)?.class
: undefined;
const worktreeMissing =
193 additions and 0 deletionsapps/server/src/orchestration-v2/runtimeLayer.test.tsModified
View file
@@ -4395,6 +4395,199 @@