Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): settle cancelled worktree setup before rollback #12176

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/12176/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Cancelling 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

    2. juliusmarminge changed the title

    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.6 KiB13.6 KiB+18 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire7.1 KiB7.1 KiB+2 B (+0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.6 KiB6.6 KiB+16 B (+0.2%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.1 KiB57.1 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.6 KiB13.6 KiB−4 B (−0.0%)15.1 KiB✅
      ClaudeThread snapshot wire7.1 KiB7.1 KiB+1 B (+0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.5 KiB−5 B (−0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.8 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages990 (0.0%)21✅

      Baseline: 962bf62 · PR result: 51c0812 · Source CI: success

      Scenario 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.

      • Codex decoded thread snapshot: 113.9 KiB
      • Claude decoded thread snapshot: 114.6 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      All clear

      Posted via Macroscope — Effect Service Conventions
    5. Approvability

      Verdict: Approved at 51c0812

      Macroscope'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).
    6. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      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.ts
      • apps/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.ts
      The 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 turn

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 51c08

      Cancelled 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 nameStatusExplanation
      Docstring Coverage✅ PassedNo 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✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely describes the main change: settling cancelled worktree setup before rollback.
      Description check✅ PassedThe 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.
    7. juliusmarminge merged this3bee4c2

    8. juliusmarminge closed this

Sign in to join this conversation.