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:
Warning Your free Security trial is over. An organization admin can activate Security or dismiss this notice. Comment |
Thread transfer impact
This comment will update automatically after the next completed run. |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds an agent-facing checkout workflow and changes existing handoff behavior across Git mutation, durable thread bindings, ownership arbitration, rollback, and provider-session detachment. The breadth and side effects of these production changes warrant human review. You can add or adjust custom eligibility rules. Learn more. |
03d0e2b to
4453207
Compare
4453207 to
1d54579
Compare
76ccdb2 to
69afd25
Compare
There was a problem hiding this comment.
Effect service conventions review of the new WorktreeMcpService.checkout path: service tag, inline interface, make/layer, subpath namespace imports, dependency acquisition (yield* Foo.Foo), and error construction all follow the conventions. One test-organization issue noted inline.
Posted via Macroscope — Effect Service Conventions
1ed8ca4 to
d653ad1
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix is ON, but a cloud agent failed to start.
Reviewed by Cursor Bugbot for commit d653ad1. Configure here.
0e3839f to
e7221b8
Compare
e7221b8 to
4838416
Compare

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 #8711. 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
Large changes to Git orchestration, durable thread bindings, and handoff failure/cleanup semantics; incorrect partial-failure or rollback logic could leave Git and thread metadata diverged or retain unintended worktrees.
Overview
Adds
t3_thread_checkoutso agents can move a thread between branches, the project root, listed worktrees, or a new worktree (via the existing handoff path). Git mutations run first; durablethread.metadata.updatebindings commit only after ref/commit verification, with optional continuation queued when the workspace path changes.Handoff no longer rejects threads already on a worktree—it can create a new checkout from the current binding. Failed or racy bindings surface
partial_failurewith rollback metadata instead of always deleting the new worktree/branch; cleanup runs only when exclusive ownership and unchanged HEAD/dirty state can be proven. Per-thread serialization expands to physical-checkout guards and cross-project owner scans so concurrent checkout/handoff on the same path fails closed.Orchestrator now honors
expectedBranchandexpectedArchivedon metadata updates (alongside existing worktree CAS).GitWorkflowService.resolveCommitsupports commit identity checks. Status/list behavior gains edge-case coverage; tool copy drops the “already in worktree” handoff restriction.Reviewed by Cursor Bugbot for commit 4838416. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add
checkoutoperation toWorktreeMcpServicefor thread workspace changescheckoutMCP operation with four target types: branch, existing worktree, project root, and new worktree. Agents can switch branches, move to unclaimed worktrees, return to project root, or create new worktrees.performHandoffto validate physical source and created worktrees before binding, detect concurrent thread changes, and return partial-failure details with rollback metadata when a created worktree cannot be safely removed or its binding outcome cannot be verified.expectedBranchandexpectedArchivedcompare-and-set fields tothread.metadata.updatein orchestrationV2.ts;Orchestrator.dispatchrejects stale updates that do not match current thread state.loadRefs,loadActiveWorkspaceBindings,queueContinuation, andreadWorkspaceBranchOrNullhelpers; transitions now share a single in-flight registry for both per-thread admission locks and physical-workspace reservations.WorktreeMcpFailuregainscheckout_in_progress,scope_mismatch,dirty_workspace,workspace_in_use,workspace_shared, andpartial_failureerror codes with an optionalWorktreeMcpPartialFailurepayload.statusno longer classifies a path as absent when an inventory record exists. Dispatch failures are treated as committed when a follow-up read confirms the binding, otherwise cleanup removes the created worktree only when exclusive ownership and creation identity are proven.Macroscope summarized 4838416.