feat(mcp): let agents change thread workspaces - #8680
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Thread transfer impact
This comment will update automatically after the next completed run. |
# Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts # apps/server/src/mcp/WorktreeMcpService.ts # apps/server/src/mcp/toolkits/worktree/handlers.ts # apps/server/src/mcp/toolkits/worktree/registration.test.ts # apps/server/src/mcp/toolkits/worktree/tools.ts # docs/orchestration-v2/orchestrator-mcp-server.md # docs/user/source-control.md # packages/contracts/src/worktreeMcp.ts # packages/shared/src/t3McpToolPresentation.test.ts # packages/shared/src/t3McpToolPresentation.ts
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts # apps/server/src/mcp/WorktreeMcpService.ts # apps/server/src/mcp/toolkits/worktree/tools.ts # docs/user/source-control.md
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a destructive MCP capability that can switch branches, create or reuse worktrees, update durable thread bindings, run setup scripts, and restart provider sessions. Its substantial cross-component concurrency and rollback behavior, along with changed handoff semantics, creates a broad runtime surface that requires human review. You can add or adjust custom eligibility rules. Learn more. |
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts
…aces/checkout # Conflicts: # apps/server/src/mcp/WorktreeMcpService.test.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
Bugbot Autofix is ON, but a cloud agent failed to start.
Reviewed by Cursor Bugbot for commit 0a622c2. Configure here.

Problem
Existing threads cannot safely move between their project root, branches, and worktrees through MCP. Updating only the recorded branch can leave durable thread state out of sync with Git, and a workspace change can detach the caller before follow-up work is queued.
Change
t3_thread_checkouttargets for branch switch/create, canonical inventory worktree reuse, project-root return, and new-worktree creationBehavior
Workspace path changes queue an optional continuation after the binding commits and before the calling provider session detaches. Same-workspace retries are idempotent. Failures report whether Git changed, whether the binding committed, and whether rollback completed, failed, or was unsafe. Unknown, unattested, or concurrently changed Git state is preserved. The workflow never stashes or drops files, removes existing worktrees, or implements retention, pruning, or revival.
Validation
vp test run apps/server/src/mcp/WorktreeMcpService.test.ts(107 tests)vp test run apps/server/src/vcs/GitVcsDriverCore.test.ts(59 tests)Dependency
Upper member of native stack #8686. Depends on workspace inventory PR #8685 and remains independent of lifecycle PR #5589.
Implemented by GPT-5.6-Sol via Codex in T3 Code.
Note
High Risk
Mutates Git checkouts and durable thread metadata with complex concurrency, rollback, and cross-project ownership checks; mis-handling could leave Git and recorded branch/worktree out of sync.
Overview
Adds
t3_thread_checkout, an MCP path for an existing thread to switch branches (including create), return to the project root, reuse a listed worktree, or create a new worktree. Git runs before the durablethread.metadata.update, with dirty-tree and cross-thread workspace guards, commit/ref verification, andpartial_failurewhen binding or rollback cannot be proven safe.Handoff is aligned with the same model: threads already on a worktree can move to a new one, rollback drops only the new worktree (not the branch), and dispatch uses
expectedBranch/expectedWorktreePath/expectedArchivedcompare-and-set in the orchestrator. Per-thread (and per-checkout)workspaceTransitionsInFlightserialization covers handoff and checkout.GitWorkflowService.resolveCommitsupports verification; status/list behavior is tightened for missing or non-repo workspaces.Contracts, toolkit registration, docs, and a large
WorktreeMcpServicetest suite cover the flow; a V2 integration test asserts queued continuation after workspace binding detach.Reviewed by Cursor Bugbot for commit 03d0e2b. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add
t3_thread_checkouttool for agents to switch thread workspacesWorktreeMcpService.checkout) that lets agents move their thread to an existing branch, return to the project root, reuse an unclaimed worktree, or create a new worktree. Git mutations run before durable binding updates, with rollback and conflict detection against other threads.thread.metadata.updatevia newexpectedBranchandexpectedArchivedfields in orchestrationV2.ts; the orchestrator now fails dispatch when these preconditions do not match current state.performHandoffin WorktreeMcpService.ts to use the same optimistic-concurrency binding updates, safer rollback (no branch deletion), and structuredpartial_failurediagnostics when cleanup cannot be guaranteed.handoffThreadsInFlightwithworkspaceTransitionsInFlightto serialize both handoffs and checkouts per thread and per workspace.WorktreeMcpFailuregains new error codes (checkout_in_progress,dirty_workspace,workspace_in_use,workspace_shared,partial_failure) and an optionalpartialpayload;thread.metadata.updatenow rejects whenexpectedBranchorexpectedArchivedmismatch.Macroscope summarized 03d0e2b.