Skip to content

fix(strategy): warn when ambiguous worktree sessions block commit linking - #1856

Merged
peyton-alt merged 2 commits into
mainfrom
fix/warn-ambiguous-worktree-sessions
Jul 26, 2026
Merged

fix(strategy): warn when ambiguous worktree sessions block commit linking#1856
peyton-alt merged 2 commits into
mainfrom
fix/warn-ambiguous-worktree-sessions

Conversation

@peyton-alt

@peyton-alt peyton-alt commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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

Summary

Follow-up to #1440 for the last ask in #1852: when the sibling/parent worktree fallback finds live sessions but they span multiple worktrees, it refuses to guess — and until now the commit silently lost its Entire-Checkpoint linkage with only a DEBUG-level trace.

  • Surface the refusal at WARN, listing the candidate worktrees and session count
  • Message follows house style (short + factual); the candidate worktrees and session count are in structured attrs. The entire session adopt remedy stays in docs/issue guidance rather than log prose
  • Test asserts the WARN lands in .entire/logs (level, message, and candidate_worktrees attr)

Terminal output was considered but the installed prepare-commit-msg and post-commit hooks intentionally redirect stderr to /dev/null, so the log-file WARN is the available surface.

Validation

  • mise run fmt / mise run lint (0 issues)
  • mise run test — 8377 tests green

🤖 Generated with Claude Code


Note

Low Risk
Observability-only: matching behavior is unchanged; adds structured WARN logging and test coverage for an existing refusal path.

Overview
When sibling/parent worktree fallback finds live sessions but they span more than one worktree, findSessionsForWorktree still returns no match (no guessing). This change emits a WARN via the checkpoint logger instead of leaving the refusal effectively invisible.

The warning lists the commit worktree, candidate session count, and distinct candidate worktrees, and tells users to run entire session adopt --from <worktree> to link a session explicitly. That targets the case where commits in a third worktree silently lose Entire-Checkpoint linkage (#1852).

A new integration test initializes logging, reproduces ambiguous sibling sessions, and asserts WARN level plus the refusal and adopt hints appear under .entire/logs (hooks redirect stderr, so logs are the intended surface).

Reviewed by Cursor Bugbot for commit a19d840. Configure here.

Before / after

Captured from a real run of the ambiguous scenario (live sessions in two worktrees, git commit in a third worktree of the same repo); temp paths shortened.

Before — the only trace, visible only with log_level: DEBUG:

{"level":"DEBUG","msg":"prepare-commit-msg: no active sessions","component":"checkpoint","strategy":"manual-commit","source":"message"}

After — visible at the default level, names the worktrees involved:

{"level":"WARN","msg":"session matching: ambiguous sessions across worktrees; commit will not be linked","component":"checkpoint","commit_worktree":"/repo/.worktrees/commit","candidate_sessions":2,"candidate_worktrees":["/repo/.worktrees/first","/repo/.worktrees/second"]}
{"level":"DEBUG","msg":"prepare-commit-msg: no active sessions","component":"checkpoint","strategy":"manual-commit","source":"message"}

…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 #1852 alongside the matching fix that landed in #1440.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Entire-Checkpoint: 01KYAQV3Z2X1A2FTS5K5MXTT83
@peyton-alt
peyton-alt requested a review from a team as a code owner July 24, 2026 18:58
Copilot AI review requested due to automatic review settings July 24, 2026 18:58

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 improves observability for the manual-commit strategy’s worktree session matching by emitting a WARN when fallback session matching finds active sessions across multiple worktrees but refuses to guess, preventing commits from silently losing Entire-Checkpoint linkage (follow-up to #1440 / #1852).

Changes:

  • Add WARN-level structured logging when ambiguous multi-worktree fallback matches are detected, including an explicit entire session adopt --from <worktree> remedy hint.
  • Extend strategy worktree-session tests to assert the WARN is written to .entire/logs (since hook stderr is intentionally discarded).

Reviewed changes

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

File Description
cmd/entire/cli/strategy/manual_commit_session.go Adds warnAmbiguousWorktreeSessions and calls it when fallback matching is refused due to multi-worktree ambiguity.
cmd/entire/cli/strategy/manual_commit_worktree_session_test.go Adds a test that initializes logging, reproduces ambiguous sibling sessions, and asserts WARN-level logging plus the adopt hint in .entire/logs.

Log messages elsewhere are short and factual with structured attrs
carrying the detail; none embed remedy commands. Drop the inline
'entire session adopt' hint and the 'sibling' qualifier (the warning
also covers the parent-checkout tier) — the candidate_worktrees attr
already identifies the worktrees involved.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Entire-Checkpoint: 01KYAS4TEW84CS9DAPEP7PSYPV
@peyton-alt
peyton-alt merged commit a557d7e into main Jul 26, 2026
10 checks passed
@peyton-alt
peyton-alt deleted the fix/warn-ambiguous-worktree-sessions branch July 26, 2026 05:24
ColeDriver pushed a commit that referenced this pull request Jul 26, 2026
…runnable remedy

#1856 added warnAmbiguousWorktreeSessions for the #1852 case where live
sessions span multiple worktrees and matching refuses to guess, so the
commit is left unlinked. But it only logs to the internal .entire/logs
file and prints no remedy, so the person running `git commit` still sees
nothing -- the "silent" part of #1852 is unchanged for them.

This keeps the structured WARN (diagnostics) and additionally writes a
user-facing notice to stderrWriter -- the same channel
warnIfAttributionDiverged and warnStaleEndedSessions use -- with a
directly runnable remedy:

  entire: this commit was not linked to a checkpoint (live agent sessions
  span multiple worktrees: ../a, ../b).
    run 'entire session adopt <session-id> --from ../a --yes' to link one explicitly.

The command names a concrete session ID rather than the bare
`--from <path>` form: bare --from relies on adoption's auto-detect, which
only considers sessions within adoptRecentWindow (12h) and fails outright
when a worktree has multiple sessions; and same-repo adoption requires
--yes. The named session is the most-recently-active candidate that
adoption will accept (mirrors isAdoptableSourceSession), so the suggested
command actually runs.

Additive only: the warning trigger and the existing log line are
unchanged.

Refs #1852
Follow-up to #1856

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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