fix(server): settle cancelled worktree setup before rollback #12176
main fromrefs/pull/12176/head·merged by juliusmarminge View on GitHubCancelling a worktree bootstrap interrupted its failure handler before it could publish the cancelled outcome or roll back the thread. Clients could keep showing setup as running after the task stopped.
Keep the bootstrap interruptible while letting its settlement handler finish recording the outcome, closing the setup terminal, removing the worktree, and rolling back the thread. A focused router test verifies the cancelled receipt, deleted thread, failed original dispatch, and absence of an agent turn; the existing synchronous and asynchronous handoff cases still pass.
Validation: all three focused setup router cases pass, server typecheck passes, and targeted lint has no errors. This changes server settlement only; screenshots are not applicable.
Implemented with GPT-6 in Codex.
Summary by CodeRabbit#
- Bug Fixes
- Improved cancellation handling during synchronous worktree setup.
- Cancelled setup now reports a clear “Worktree setup cancelled.” error and cleans up the temporary bootstrap thread.
- Prevented the bootstrap turn from starting after setup is cancelled.
- Ensured cancellation cleanup and rollback complete reliably before the operation ends.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
juliusmarminge changed the title
All clear
Posted via Macroscope — Effect Service Conventionsmacroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
51c0812Macroscope's review found this PR approvable — This narrowly fixes cancelled worktree setup by allowing cancellation to reach the existing rollback path and ensuring the cancellation outcome and cleanup finish atomically. A focused server test verifies the thread is deleted, the cancelled activity is recorded, and no turn starts.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Team
Run ID:
c08b7252-22ed-40fc-ba7f-59407d2b8671📥 Commits
Reviewing files that changed from the base of the PR and between 962bf62921c0ecbc9320f9b071e16b1d41484aad and 51c0812a4536387f4d0ea50dca179fb750153354.
📒 Files selected for processing (2)
apps/server/src/server.test.tsapps/server/src/ws.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
Worktree setup cancellation now interrupts the bootstrap program, protects cleanup and rollback, deletes the bootstrap thread, reports cancellation, and prevents turn dispatch. Tests cover the cancellation result and related dispatch metadata.
Changes#
Worktree setup cancellation
Layer / File(s) Summary Cancellation flow and validation
apps/server/src/ws.ts,apps/server/src/server.test.tsThe bootstrap program is interruptible during setup and uninterruptible during cancellation cleanup and rollback. Tests verify the cancelled outcome, deleted bootstrap thread, failed dispatch metadata, and absent turn dispatch. Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant CancellationRPC participant BootstrapProgram participant TurnDispatch CancellationRPC->>BootstrapProgram: interrupt running setup BootstrapProgram->>BootstrapProgram: complete cleanup and rollback BootstrapProgram->>CancellationRPC: report cancellation and deleted thread BootstrapProgram-->>TurnDispatch: fail dispatch without starting a turnSuggested reviewers:
t3dotggMerge Risk: ⚪ Minimal · up to
51c08Cancelled worktree setup completes its cleanup and reports the cancelled result without starting an agent turn. No current merge-blocking risk was identified.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly and concisely describes the main change: settling cancelled worktree setup before rollback. Description check ✅ Passed The description explains what changed, why it was needed, the test coverage, and that UI changes do not apply. It does not use the template headings or checklist, but it contains the required informat… ✨ Finishing Touches
📝 Generate docstrings
- Create stacked PR
- Commit on current branch
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch `mobile-worktree-setup/cancellation`
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge merged this3bee4c2
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
962bf62· PR result:51c0812· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.