fix: worktree threads keep their worktree when the agent starts, and messages sent during setup queue #17654
Mergedmaria-rcksmerged 12 commits into
main fromrefs/pull/17654/headmerged by maria-rcks View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
maria-rcks changed the title
- apps/server/src/orchestration-v2/Orchestrator.ts lines 1314 to 1319Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1298,12 +1298,16 @@12981298 // Hold the queue so the user decides when to resume it. Validation12991299 // failures (setup, unsupported handoff) belong to that message alone,13001300 // and a message queued for another provider is how users recover.1301+ // A message queued behind a worktree that was cancelled or never created1302+ // would run in the project checkout instead, so it waits for the user.13011303 const failedRun = latestExecutedRun(projection.runs);13021304 const failureClass =13031305 failedRun?.id === options?.failedRunId13041306 ? latestRootProviderFailure(failedRun, projection.turnItems)?.class13051307 : undefined;1308+ const worktreeMissing =1309+ failedRun?.id === options?.failedRunId &&1310+ failedRun?.workspacePreparation?.type === "worktree" &&1311+ projection.thread.worktreePath === null;13061312 if (1307- failureClass !== undefined &&1308- failureClass !== "validation_error" &&1309- failedRun?.providerInstanceId === queuedRun.providerInstanceId1313+ worktreeMissing ||apps/web/src/components/ChatView.tsx line 3676OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3667,3 +3667,10 @@36673667 // Server-side workspace preparation: unlike the local-dispatch flag this36683668 // survives reloads and shows on remote viewers of the same thread.36693669 const activeRunPreparing = activeActivityRun?.status === "preparing";3670+ // The server queues a message behind a run that is still preparing its3671+ // worktree or starting its agent, so a send during setup waits there and3672+ // starts on its own instead of being refused.3673+ const sendQueuesBehindSetup =3674+ isServerThread && (activeRunPreparing || activeActivityRun?.status === "starting");3675+ // Such a send skips the local dispatch, so this keeps the composer busy while it is in flight.3676+ const [setupQueueSendInFlight, setSetupQueueSendInFlight] = useState(false);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
maria-rcks changed the title
- apps/server/src/orchestration-v2/Orchestrator.ts line 1315Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1298,8 +1301,12 @@12981301 // Hold the queue so the user decides when to resume it. Validation12991302 // failures (setup, unsupported handoff) belong to that message alone,13001303 // and a message queued for another provider is how users recover.1304+ // A message queued behind a worktree that was cancelled or never created1305+ // would run in the project checkout instead, so it waits for the user.13011306 const failedRun = latestExecutedRun(projection.runs);13021307 const failureClass =13031308 failedRun?.id === options?.failedRunId13041309 ? latestRootProviderFailure(failedRun, projection.turnItems)?.class13051310 : undefined;1311+ const worktreeMissing =1312+ failedRun?.id === options?.endedRunId &&
- @@ -4852,3 +4862,11 @@48524862 (candidate) => candidate.id === projection.thread.activeProviderThreadId,48534863 );48544864 const activeRun = projection.runs.find(isBlockingRun);4865+ // A message queued during worktree setup can arrive after that setup failed4866+ // without a worktree. It waits, held, like the messages queued before the4867+ // failure, instead of starting in the project checkout.4868+ const latestRun = latestExecutedRun(projection.runs);4869+ const worktreeMissingRun =4870+ activeRun === undefined &&4871+ dispatchMode.type === "queue_after_active" &&4872+ latestRun?.status === "failed" &&
maria-rcks merged this4772822
maria-rcks closed this
Sign in to join this conversation.






Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
8b301e6b-782b-4a6d-9f09-9ff46cb74be4📥 Commits
Reviewing files that changed from the base of the PR and between 570168db39a424e419b84c188f662bca2c1ad547 and 579ea42430b4d22e1001b5b3d3a18ed621cb9f18.
📒 Files selected for processing (3)
apps/mobile/src/state/use-thread-composer-state.tsapps/server/src/orchestration-v2/Orchestrator.tsapps/server/src/orchestration-v2/ThreadLaunchService.test.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Walkthrough#
Mobile and web clients allow follow-up sends during server-owned worktree setup. Server orchestration holds queued runs when preparation ends without a worktree and can release them after a qualifying retry. Automatic branch metadata updates include an expected-empty condition.
Changes#
Follow-ups during worktree setup
apps/mobile/src/features/threads/ThreadRouteScreen.tsx,apps/mobile/src/features/threads/ThreadDetailScreen.tsx,apps/mobile/src/state/use-thread-composer-state.tsapps/web/src/components/ChatView.tsx,apps/web/src/components/BranchToolbarBranchSelector.tsx,packages/client-runtime/src/operations/commands.tsexpectedEmpty: true; manual updates use the regular mutation.apps/server/src/orchestration-v2/Orchestrator.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.tsPriority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Suggested reviewers:
juliusmarmingeMerge Risk | 🟡 Moderate · up to
579eaMerge Risk: 🟡 Moderate · up to
579eaFollow-ups sent while worktree setup is failing could still run in the project checkout in a narrow timing window. The related interrupt test may not reliably exercise its intended interleaving. Confirm the dispatch-time hold before merging.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
579eaThe normal setup-failure path is safer, but delayed messages after a restart can still start in the shared project checkout. Retrying setup can also release messages held by an independent Stop action. Both risks are bounded by the thread’s existing execution permissions.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
Pre-merge checks |
4
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.