Skip to content

Match sessions across sibling worktrees#1440

Draft
peyton-alt wants to merge 1 commit into
mainfrom
fix/session-sibling-worktree
Draft

Match sessions across sibling worktrees#1440
peyton-alt wants to merge 1 commit into
mainfrom
fix/session-sibling-worktree

Conversation

@peyton-alt

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

Copy link
Copy Markdown
Contributor

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.

}

if len(parentWorktreeMatches) > 0 {
return parentWorktreeMatches, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Parent fallback ignores ambiguous sessions

Medium Severity

When sibling fallback finds multiple candidate sessions it returns none, but the parent-worktree branch returns every match as soon as parentWorktreeMatches is non-empty. A commit from a nested .worktrees/... checkout can then bind one checkpoint trailer to several active sessions that were all recorded on the parent path.

Fix in Cursor Fix in Web

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

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 on lines +156 to +159
worktreeCommonDir, err := gitCommonDirForWorktree(ctx, worktreePath)
if err != nil {
return nil, nil
}
Comment on lines +195 to +196
cmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "rev-parse", "--git-common-dir")
output, err := cmd.Output()
Comment on lines +161 to +170
var parentWorktreeMatches []*SessionState
var commonDirMatches []*SessionState
for _, state := range allStates {
if state.WorktreePath == "" {
continue
}

stateCommonDir, err := gitCommonDirForWorktree(ctx, state.WorktreePath)
if err != nil || stateCommonDir != worktreeCommonDir {
continue
Entire-Checkpoint: c8a3d493b515
@peyton-alt peyton-alt force-pushed the fix/session-sibling-worktree branch from 9bf7cc1 to 8dd3a0a Compare June 17, 2026 00:31
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