Skip to content

Match sessions across sibling worktrees - #1440

Merged
peyton-alt merged 4 commits into
mainfrom
fix/session-sibling-worktree
Jul 24, 2026
Merged

Match sessions across sibling worktrees#1440
peyton-alt merged 4 commits into
mainfrom
fix/session-sibling-worktree

Conversation

@peyton-alt

@peyton-alt peyton-alt commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

https://entire.io/gh/entireio/cli/trails/573

Summary

Fix missing checkpoint trailers when an active session is recorded against one worktree but the commit hook runs from another worktree in the same git repository.

  • keep exact WorktreePath matches as the first choice
  • fall back to same git-common-dir matching for sibling worktrees
  • handle sessions recorded at the parent repo while commits happen under .worktrees/...
  • avoid guessing when multiple sibling sessions could match

This intentionally does not match across different git common dirs. Cross-repo session adoption is tracked separately in #1439.

Validation

  • git diff --check origin/main..HEAD
  • gofmt -l cmd/entire/cli/strategy/manual_commit_session.go cmd/entire/cli/strategy/manual_commit_worktree_session_test.go
  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli/strategy -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli/... -count=1

Note: the broad Go test suite was rerun outside the sandbox because sandboxed httptest packages cannot bind localhost ports.


Note

Medium Risk
Changes commit-hook session resolution for multi-worktree repos; wrong matching could attach wrong checkpoints, but ambiguity is explicitly avoided and scope is limited to one git common dir.

Overview
Extends findSessionsForWorktree so commit hooks can find an active session when the session was recorded on a different checkout of the same repository than where git commit runs.

Exact WorktreePath matches still win. If none exist, the code compares git rev-parse --git-common-dir for the commit worktree and each stored session, then applies two fallbacks: prefer sessions recorded on a parent repo path when the commit happens under that repo’s .worktrees/..., otherwise adopt a single sibling session that shares the common dir. Multiple ambiguous siblings or unrelated repos return no match.

New integration tests cover nested worktrees (including PrepareCommitMsg checkpoint trailers), unique sibling matching, exact-over-fallback priority, unrelated repos, and ambiguous siblings.

Reviewed by Cursor Bugbot for commit 9bf7cc1. Configure here.

Copilot AI review requested due to automatic review settings June 17, 2026 00:19

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9bf7cc1. Configure here.

Comment thread cmd/entire/cli/strategy/manual_commit_session.go Outdated

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.

Pull request overview

This PR fixes missing Entire-Checkpoint commit trailers when an active session is recorded in one worktree but prepare-commit-msg runs from a sibling (or nested) worktree within the same repository, by expanding session lookup beyond exact WorktreePath matches while still avoiding ambiguous adoption.

Changes:

  • Extend findSessionsForWorktree to prefer exact WorktreePath matches, then fall back to matching sessions by shared git common dir, with a special-case for commits happening under a parent repo’s .worktrees/....
  • Add strategy-level tests that cover nested-worktree parent matching, unique sibling matching, exact-over-fallback priority, and ambiguity/unrelated-repo non-matches.
  • Add a hook-level test asserting PrepareCommitMsg inserts a checkpoint trailer when only the parent-recorded session is available.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmd/entire/cli/strategy/manual_commit_session.go Updates active-session resolution logic to support sibling/nested worktree matching via git common-dir fallbacks.
cmd/entire/cli/strategy/manual_commit_worktree_session_test.go Adds test coverage for the new session-matching behavior and trailer insertion from nested worktrees.

Comment thread cmd/entire/cli/strategy/manual_commit_session.go
Comment thread cmd/entire/cli/strategy/manual_commit_session.go
Comment thread cmd/entire/cli/strategy/manual_commit_session.go
Entire-Checkpoint: c8a3d493b515
peyton-alt and others added 2 commits July 24, 2026 13:31
- Refuse fallback matches spanning distinct worktrees (parent tier
  included), while keeping concurrent sessions from a single worktree
  matchable — consistent with exact-match semantics
- Strip GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE when resolving another
  worktree's common dir, so hook-exported vars can't redirect discovery
- Return the committing worktree's common-dir resolution error instead
  of swallowing it (callers already treat errors as a non-fatal skip)
- Memoize per-path common-dir lookups to avoid one git subprocess per
  session state

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Entire-Checkpoint: 01KYAMA82R9G99GNGYAPQ0D1CT
@peyton-alt
peyton-alt marked this pull request as ready for review July 24, 2026 17:58
@peyton-alt
peyton-alt requested a review from a team as a code owner July 24, 2026 17:58
…ss commits

postCommitUpdateBaseCommitOnly rewrites BaseCommit to the committing
worktree's HEAD, which is only correct for sessions recorded in that
worktree — a sibling session's HEAD didn't move, and rewriting its base
orphans its shadow branch (keyed by BaseCommit + WorktreeID). Route the
no-trailer path through a new exact-match-only lookup so the sibling
fallback never feeds base-commit mutation.

The trailer path keeps the fallback: a fallback trailer only exists
because that session passed PrepareCommitMsg content validation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Entire-Checkpoint: 01KYANAB0TPCF5ZYYJW7HV4WM3
@peyton-alt
peyton-alt merged commit ec5d9a7 into main Jul 24, 2026
10 checks passed
@peyton-alt
peyton-alt deleted the fix/session-sibling-worktree branch July 24, 2026 18:40
tkfor21 pushed a commit to tkfor21/entire-cli that referenced this pull request Jul 27, 2026
…king

When the sibling/parent worktree fallback finds live sessions but they
span multiple worktrees, it refuses to guess and the commit silently
loses its Entire-Checkpoint linkage with only a DEBUG trace. Surface
that refusal at WARN with the candidate worktrees and a pointer to
'entire session adopt' as the explicit remedy.

Requested in entireio#1852 alongside the matching fix that landed in entireio#1440.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Entire-Checkpoint: 01KYAQV3Z2X1A2FTS5K5MXTT83
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.

3 participants