Match sessions across sibling worktrees#1440
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 9bf7cc1. Configure here.
There was a problem hiding this comment.
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
findSessionsForWorktreeto prefer exactWorktreePathmatches, 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
PrepareCommitMsginserts 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. |
| worktreeCommonDir, err := gitCommonDirForWorktree(ctx, worktreePath) | ||
| if err != nil { | ||
| return nil, nil | ||
| } |
| cmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "rev-parse", "--git-common-dir") | ||
| output, err := cmd.Output() |
| 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
9bf7cc1 to
8dd3a0a
Compare


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.
WorktreePathmatches as the first choice.worktrees/...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..HEADgofmt -l cmd/entire/cli/strategy/manual_commit_session.go cmd/entire/cli/strategy/manual_commit_worktree_session_test.goGOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli/strategy -count=1GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli/... -count=1Note: the broad Go test suite was rerun outside the sandbox because sandboxed
httptestpackages 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
findSessionsForWorktreeso commit hooks can find an active session when the session was recorded on a different checkout of the same repository than wheregit commitruns.Exact
WorktreePathmatches still win. If none exist, the code comparesgit rev-parse --git-common-dirfor 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
PrepareCommitMsgcheckpoint trailers), unique sibling matching, exact-over-fallback priority, unrelated repos, and ambiguous siblings.Reviewed by Cursor Bugbot for commit 9bf7cc1. Configure here.