t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: After a thread moves to another worktree, its next turn's diff shows the other branch, and "Revert files too" overwrites the new worktree with the old one's files

Open navidnadali opened this issue 3 weeks ago • 1 comments

Before submitting

  • [X] I searched existing issues and did not find a duplicate.
  • [X] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Start a thread in worktree A of a repository and send a turn that edits a file.
  2. Move the thread to worktree B of the same repository, on another branch with its own commits and files.
  3. Send a turn that edits one file.
  4. Open turn 2's diff.
  5. Choose "Edit from here?" on turn 1, then "Revert files too".

Expected behavior

  • Turn 2's diff lists only the file turn 2 edited.
  • A file revert never writes a checkpoint taken in one worktree into another. It is refused, and the conversation-only revert still works.

Actual behavior

  • Turn 2's diff lists every difference between A's tree and B's tree (B's branch commits and turn 1's files) as turn 2's changes.
  • The revert is accepted and writes A's turn-1 tree into worktree B, so B's branch-only files are deleted or reverted.
  • With B in another repository instead, turn 2's baseline is missing and its diff is empty or wrong.

Impact: data loss in the destination worktree (uncommitted and branch-only files) from an action the UI presents as safe.

Why, in the current code:

  • CheckpointService.makeRootRunScope allocates every root run's scope from the one name ROOT_CHECKPOINT_SCOPE_NAME ("root"), and writes the run's own cwd into it. A thread therefore has one root checkpoint scope, re-created by each run with that run's cwd.
  • Checkpoint refs are per scope and ordinal and live in the repository, which worktrees of one repository share. So turn 2 is diffed against the ref A's turn 1 left.
  • isCheckpointRestoreIsolated (CheckpointRestoreSafety.ts) compares the scope's cwd (now B) with the thread's worktreePath (B), so the check passes.

Related but different: #27336 reports the same diff symptom when the agent moves into a worktree of its own or switches branch, without T3 Code moving the thread.

Impact

Major degradation or frequent failure

Version or commit

main @ 8b44f42b1

Environment

No response

Logs or stack traces

No response

Screenshots, recordings, or supporting files

No response

Workaround

Use the conversation-only revert, not "Revert files too", on turns taken before the thread moved to another worktree.

Made with Claude Opus 5.5 via Claude Code.

🤖 Generated with Claude Code

navidnadali avatar Nov 04 '26 14:11 navidnadali

I observed this during a read-only turn that called t3_worktree_handoff to move the current thread to a worktree at an earlier commit. That same turn’s changed-files card reported changes even though the turn made no edits. The checkpoint before the handoff captured the source checkout, the next captured the destination, and subsequent review snapshots had identical trees.

A regression test for this path could verify that the read-only handoff turn reports zero changed files and that the first edit in the destination is reported against a fresh destination baseline. This case hasn’t been verified against #30972.

Prepared with Sol 6.2.

zbynekwinkler avatar Nov 24 '26 09:11 zbynekwinkler