Skip to content

Guard attach against cross-worktree sessions#1453

Open
peyton-alt wants to merge 1 commit into
mainfrom
fix/session-attach-guardrail
Open

Guard attach against cross-worktree sessions#1453
peyton-alt wants to merge 1 commit into
mainfrom
fix/session-attach-guardrail

Conversation

@peyton-alt

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

Copy link
Copy Markdown
Contributor

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

Summary

  • Refuse entire session attach when an existing tracked session belongs to another worktree.
  • Compare stored WorktreeID first so git worktree move remains attachable; fall back to normalized WorktreePath for legacy state.
  • Add --allow-cross-worktree for explicit override on session attach and review attach.
  • Add unit and integration coverage for wrong-worktree refusal, moved-worktree attach, and explicit override.

Validation

  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli -run 'TestAttach_' -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test -tags=integration ./cmd/entire/cli/integration_test -run 'TestAttach_(RefusesTrackedSessionFromDifferentWorktree|AllowsTrackedSessionAfterWorktreeMove)' -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test -tags=integration ./cmd/entire/cli/integration_test -run 'TestAttach_' -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli -run 'Test(Attach|ReviewAttach)_' -count=1
  • mise run lint
  • mise run check

Notes

  • --force still only skips amend confirmation. It does not bypass the worktree identity guard.
  • Rebased on current main at e3fc6f88c.
  • Latest commit: 41dbf9bef8c6e509781cd365750efef8c4aaeaa6 with Entire-Checkpoint: c8a3d493b515.

Copilot AI review requested due to automatic review settings June 17, 2026 22:46
@peyton-alt peyton-alt marked this pull request as ready for review June 17, 2026 22:47
@peyton-alt peyton-alt requested a review from a team as a code owner June 17, 2026 22:47

@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 093d1ca. Configure here.

Comment thread cmd/entire/cli/attach.go

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 adds a safety guard to prevent entire session attach (and entire review attach) from attaching/amending in the wrong git worktree when a tracked session’s state indicates it belongs to a different worktree, with an explicit --allow-cross-worktree escape hatch. This reduces the chance of accidentally amending the “wrong” HEAD in multi-worktree setups.

Changes:

  • Add --allow-cross-worktree to both session attach and review attach, and plumb it into attachOptions.
  • Add attach-time worktree validation (validateAttachWorktree) before any checkpoint write/amend.
  • Add unit + integration tests covering refusal behavior and explicit override behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cmd/entire/cli/attach.go Adds AllowCrossWorktree flag plumbing and a worktree mismatch guard before attach proceeds.
cmd/entire/cli/review_helpers.go Exposes --allow-cross-worktree on entire review attach and forwards it into attach options.
cmd/entire/cli/attach_test.go Adds unit coverage for refusing cross-worktree attach and for the explicit override.
cmd/entire/cli/integration_test/attach_test.go Adds integration coverage to ensure wrong-worktree attach refusal does not amend the wrong HEAD or add trailers.

Comment thread cmd/entire/cli/attach.go
@peyton-alt peyton-alt force-pushed the fix/session-attach-guardrail branch from 093d1ca to 75712e6 Compare June 17, 2026 23:22
Entire-Checkpoint: c8a3d493b515
@peyton-alt peyton-alt force-pushed the fix/session-attach-guardrail branch from 0deb305 to 41dbf9b Compare June 22, 2026 23:20
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