Skip to content

feat: adopt active sessions across repos and worktrees#1472

Open
peyton-alt wants to merge 18 commits into
mainfrom
feat/session-adopt
Open

feat: adopt active sessions across repos and worktrees#1472
peyton-alt wants to merge 18 commits into
mainfrom
feat/session-adopt

Conversation

@peyton-alt

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

Copy link
Copy Markdown
Contributor

Trail: https://entire.io/gh/entireio/cli/trails/613/adopt-active-sessions-across-repos-and-worktrees

Summary

Adds entire session adopt [session-id] --from <source-worktree> so an active agent session can be explicitly anchored into the repo/worktree where the next commit is about to happen.

This addresses the case we hit where hooks were firing correctly, but the commit happened in a repo/worktree that did not have matching local session state, so the commit had nothing to link and missed the Entire-Checkpoint trailer.

What changed

  • Adds the session adopt subcommand under entire session.
  • Reads source session state from the source worktree’s .git/entire-sessions store.
  • Supports either an explicit session ID or a single recent active source session.
  • Filters shared source stores by the requested --from worktree, using WorktreeID when available and canonical path fallback otherwise.
  • Supports independent repo/worktree adoption by writing target-local session state.
  • Supports same-git-common-dir linked worktree adoption by moving the shared session state to the current worktree instead of rejecting it.
  • Rejects no-op adoption when source and target resolve to the same worktree.
  • Validates that a preserved live transcript path is owned by the source session’s registered agent.
  • Keeps the live transcript path because the transcript belongs to the continuing agent session, not necessarily the target repo.
  • Seeds FilesTouched from current target repo changes so the next commit can pass the staged-file overlap check.
  • Resets target-local checkpoint/transcript bookkeeping so long-running source sessions do not inherit stale checkpoint offsets, checkpoint IDs, prompt windows, or legacy transcript fields.
  • Preserves cumulative turn/context metrics while anchoring the adopted prompt window at the current source turn count.
  • Leaves AttachedManually false because adoption is not entire session attach.

This closes the sibling-worktree gap from #573 through an explicit agent/user command, without adding hook-time automatic matching across worktrees.

Verification

  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli -run TestSessionAdopt -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli -run TestSessionAdopt_MovesSameStoreSessionIntoCurrentWorktree -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli -run 'Test(SessionAdopt|PrepareCommitMsg)' -count=1
  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli -count=1
  • mise run lint
  • mise run check

mise run check passed locally after rebasing on current main, including lint, integration tests, Vogon canary, and roger-roger canary.

Latest commit/checkpoint:

  • db9ada812c38dc67e0750d4e2633662316ffb5bf - Entire-Checkpoint: 48521e055655

Push output confirmed entire/checkpoints/v1 was already up to date on the checkpoint remote.

Caveats

This is explicit adoption, not automatic discovery. Agents or users should run it from the target repo/worktree before committing, and the source transcript path must still be readable on the same machine.

@peyton-alt peyton-alt requested a review from a team as a code owner June 18, 2026 22:38
Copilot AI review requested due to automatic review settings June 18, 2026 22:38

@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 2 potential issues.

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 6add2ba. Configure here.

Comment thread cmd/entire/cli/session_adopt.go
Comment thread cmd/entire/cli/session_adopt.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 adds an explicit entire session adopt subcommand to copy (“adopt”) an in-progress agent session that’s currently tracked under a different repo/worktree into the current repo/worktree so the commit hooks can find local session state and reliably add an Entire-Checkpoint trailer.

Changes:

  • Add entire session adopt [session-id] --from <source-worktree> command wiring under the session group.
  • Implement adoption logic that locates the source worktree’s .git/entire-sessions, selects an adoptable session, and writes a target-local session state seeded with current file changes.
  • Add unit tests covering cross-repo adoption, source resolution from a nested path, and PrepareCommitMsg trailer insertion after adoption.

Reviewed changes

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

File Description
cmd/entire/cli/sessions.go Adds the adopt subcommand to session help text and registers the command.
cmd/entire/cli/session_adopt.go Implements the adopt command, source store resolution, session selection, and target-local state writing.
cmd/entire/cli/session_adopt_test.go Adds tests for adoption behavior and hook trailer behavior after adoption.

Comment thread cmd/entire/cli/session_adopt.go Outdated
Comment thread cmd/entire/cli/session_adopt.go
Comment thread cmd/entire/cli/session_adopt.go
@peyton-alt peyton-alt force-pushed the feat/session-adopt branch from 53264b9 to 2bed72c Compare June 22, 2026 21:57
Entire-Checkpoint: 7fb3d4d78c7f
Entire-Checkpoint: b7f863b91041
Entire-Checkpoint: 0d316d428771
Entire-Checkpoint: a946a346b0a7
Entire-Checkpoint: c555c03f3864
Entire-Checkpoint: 6fb8304acd8d
Entire-Checkpoint: db8b4bffc8b4
Entire-Checkpoint: 616df3aa9473
Entire-Checkpoint: ae0dfea989e0
Entire-Checkpoint: b8bd53b01bba
Entire-Checkpoint: 48521e055655
@peyton-alt peyton-alt force-pushed the feat/session-adopt branch from 2bed72c to db9ada8 Compare June 22, 2026 23:48
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