Skip to content

Keep other worktrees' sessions off an identified committer's commit - #2821

Open
peyton-alt wants to merge 2 commits into
mainfrom
peyton/ent-2463-fallback-sessions
Open

peyton-alt wants to merge 2 commits into
mainfrom
peyton/ent-2463-fallback-sessions

Conversation

@peyton-alt

@peyton-alt peyton-alt commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • A session from another worktree joins only through its record of this worktree (hasWorktreeEntry, from Record a session's edits against the worktree they happen in #2531), and is held to those edits (LinkedByWorktreeEntry).
  • Sessions homed in the committing worktree still join alongside the identified committer, as before.
  • A commit with no identified committer (Windows, no recorded owner) keeps the fallback unchanged.

findSessionsForWorktreeFromStates now 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:

  • An identified committer in a sibling worktree, and in a worktree nested under the main checkout, links only itself plus a main-checkout session that recorded edits there. That session is flagged LinkedByWorktreeEntry.
  • An identified committer homed in a third worktree, where the fallback would otherwise pick the main checkout's recent session.
  • Through 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:

  • With no identified committer, the fallback still links the main checkout's sessions.
  • Sessions homed in the committing worktree stay linked next to an identified committer.

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.

Committer main this branch
Claude Code (EnterWorktree into .claude/worktrees/) Codex session stamped and condensed into the commit committer only
Codex Codex bystander condensed into the commit (older nightly; main build rate-limited) committer only
Pi bystander condensed committer only
Copilot CLI bystander condensed committer only
OpenCode bystander condensed bystander not condensed (OpenCode's own checkpoint not written, see below)
Antigravity — committer only
Cursor CLI bystander condensed bystander condensed (see below)

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

  • Checkpoints already written with extra sessions stay as they are. Cleaning those up would be a separate server-side change.
  • A commit with no identified committer while an unrelated session is mid-turn still links it (unchanged from main; Keep a running agent's session off commits it did not make #2668 covers the case where that agent is running).
  • A committer Entire cannot identify by process ancestry still gets the fallback. Headless cursor-agent -p ran 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.
  • After EnterWorktree Claude 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.
  • If Keep a running agent's session off commits it did not make #2668 merges first, this PR needs a small merge in the same function, or the other way round.

🤖 Generated with Claude Code

peyton-alt and others added 2 commits October 19, 2026 11:36
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
@peyton-alt
peyton-alt requested a review from a team as a code owner October 19, 2026 21:30
Copilot AI balanced review requested due to automatic review settings October 19, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants