Repository navigation
Keep other worktrees' sessions off an identified committer's commit - #2821
Open
peyton-alt wants to merge 2 commits into
Open
peyton-alt wants to merge 2 commits into
peyton-alt wants to merge 2 commits into
Conversation
An agent started in the main checkout that moved into a linked worktree (Claude Code's EnterWorktree) commits there with no session homed in it. Worktree matching then fell back to every session of the main checkout, and the shortcuts that skip content checks condensed each one that was mid-turn into the commit. When process ancestry identifies the committer and no session is homed in the committing worktree, the fallback's sessions are dropped; a session from elsewhere joins only through its record of this worktree, held to those edits. Sessions homed here still union with the committer, and a commit with no identified committer keeps the fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5AQ6MYHK7RMSDMZAFZ79Q4R
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused change has no identified blocking issues and includes targeted regression coverage; tests were not executed during this review.
No open issues 🎉
What changed in this PR
Prevents unrelated sessions from other worktrees from joining an identified agent’s commit, fixing ENT-2463.
Changes:
- Drops cross-worktree fallback matches when ancestry identifies the committer.
- Preserves home-worktree matches, recorded cross-worktree edits, and unidentified-committer fallback behavior.
- Adds regression coverage and documents the linking exception.
| File | Description |
|---|---|
| docs/development/checkpoint-implementation.md | Documents identity-based fallback filtering. |
| cmd/entire/cli/strategy/worktree_work_test.go | Tests filtering and preserved linking behavior. |
| cmd/entire/cli/strategy/worktree_home_test.go | Adapts to the additional return value. |
| cmd/entire/cli/strategy/session_identity.go | Removes fallback matches for identified committers. |
| cmd/entire/cli/strategy/session_identity_test.go | Tests commit-hook isolation of unrelated sessions. |
| cmd/entire/cli/strategy/manual_commit_session.go | Reports whether matching used the fallback. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes ENT-2463.
Problem
An agent that starts in the main checkout and moves into a linked worktree (Claude Code's
EnterWorktree, which creates.claude/worktrees/…) stays homed in the main checkout. When it commits from the linked worktree, no session is homed there, so worktree matching falls back to every session of the main checkout. The shortcuts that skip content checks then condense every one of those sessions that is mid-turn into the agent's commit. These shortcuts are the no-TTY fast path, content detection by transcript growth, and post-commit ACTIVE condensation. The result is one checkpoint that holds the committer's session plus unrelated sessions from the main checkout, and the trail shows all of them.Reproduced on the 0.10.7 release and on current main. #2668 hides the unrelated session only while that session's agent is still running.
Fix
In
findSessionsForCommitLinking: when process ancestry identifies the committer and no session is homed in the committing worktree, the fallback's matches are dropped.hasWorktreeEntry, from Record a session's edits against the worktree they happen in #2531), and is held to those edits (LinkedByWorktreeEntry).findSessionsForWorktreeFromStatesnow reports whether its result came from the fallback. Amend restore and post-rewrite (findSessionsForWorktree) are unchanged.Diff: +201/−13 across 6 files.
Tests
Each new test fails without the fix:
LinkedByWorktreeEntry.PrepareCommitMsg+PostCommit: the committer is stamped and condensed, and a mid-turn main-checkout session with pending work is not condensed into the checkpoint.Guards that also pass without the fix:
Live, with real agents (headless). An unrelated Codex session in the main checkout edits README.md and stays mid-turn in
sleep; the agent under test creates a linked worktree, edits there and commits. Entire's hooks are pinned to the build under test.EnterWorktreeinto.claude/worktrees/)Also checked against real binaries with a scripted repro: an unrelated mid-turn session in the main checkout, with its agent alive or gone. Built from this branch, that session is never linked when the committer is identified; the committer always is.
Not in this PR
cursor-agent -pran no Entire hooks at all, so no session was recorded and the bystander was condensed on both builds; in the IDE, Cursor's recorded owner is the extension host, which is not an ancestor of its commands.EnterWorktreeClaude Code writes its transcript under the worktree's project directory, and OpenCode's transcript was likewise unreadable mid-turn: a commit made mid-turn gets a trailer, but its checkpoint fails with "live transcript is empty or unreadable" and is never written. The turn's transcript is still captured at turn end. Happens on main as well; separate fix.🤖 Generated with Claude Code