feat: adopt active sessions across repos and worktrees#1472
feat: adopt active sessions across repos and worktrees#1472peyton-alt wants to merge 11 commits into
Conversation
Entire-Checkpoint: 7fb3d4d78c7f
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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.
There was a problem hiding this comment.
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 thesessiongroup. - 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
PrepareCommitMsgtrailer 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. |
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

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 an agent session was tracked under one repo/worktree, but the agent made and committed changes in another repo. The target repo hooks can fire correctly, but without target-local session state the commit has no session to link and can miss the
Entire-Checkpointtrailer.What changed
session adoptsubcommand underentire session..git/entire-sessions.FilesTouchedfrom current target repo changes.StepCount, transcript offset/size, transcript identifier, last checkpoint IDs) so long-running sessions do not inherit stale source-repo checkpoint state.AttachedManuallyfalse because adoption is notentire session attach.This lets the target repo commit hooks find the adopted session by target worktree, pass the staged-file overlap check, add an
Entire-Checkpointtrailer, and condense normally on post-commit.Review fixes
Addressed the first four trail findings in follow-up commit
aae06c4e100bf091dd305b222df469ee9cab4228:AttachedManuallyfor adopted active sessions.Follow-up trailer:
Entire-Checkpoint: b7f863b91041After that, a new transcript-path finding was opened. The suggested behavior was not correct for cross-repo adoption, because the live transcript belongs to the continuing source agent session, not the target repo. Commit
9ffec38cf2fad2c962d48267aa9a1738358f0070documents that intent in code.Clarification trailer:
Entire-Checkpoint: 0d316d428771Commit
1cc4003cc15da8c821ca98657ae6a27730770107resets adopted checkpoint/transcript window state and adds a regression test where the source session already had prior checkpoint state before adoption.Window-reset trailer:
Entire-Checkpoint: a946a346b0a7Commit
86cb382b985235c877cc19f6174f1d52661ca969rejects same-git-common-dir adoption and proves the existing source state is preserved.Shared-store guard trailer:
Entire-Checkpoint: c555c03f3864Commit
e6f63ebcf38630fa8bb9b61b33b801a0c65b5a84anchors the adopted prompt window at the current source turn count while preserving cumulative session metrics, so long-running sessions do not inflate the target checkpoint prompt count.Prompt-window anchor trailer:
Entire-Checkpoint: 6fb8304acd8dCommit
dd22ba19819221df5250e041a491e988f8c414d1clears deprecated legacy transcript offset fields whenever adoption resets the checkpoint transcript window, and adds a regression that proves those stale JSON fields are not re-persisted.Legacy-offset trailer:
Entire-Checkpoint: db8b4bffc8b4Commit and checkpoint verification
6add2bae652a5983fe0ffe9171e92710051714c5-Entire-Checkpoint: 7fb3d4d78c7faae06c4e100bf091dd305b222df469ee9cab4228-Entire-Checkpoint: b7f863b910419ffec38cf2fad2c962d48267aa9a1738358f0070-Entire-Checkpoint: 0d316d4287711cc4003cc15da8c821ca98657ae6a27730770107-Entire-Checkpoint: a946a346b0a786cb382b985235c877cc19f6174f1d52661ca969-Entire-Checkpoint: c555c03f3864e6f63ebcf38630fa8bb9b61b33b801a0c65b5a84-Entire-Checkpoint: 6fb8304acd8ddd22ba19819221df5250e041a491e988f8c414d1-Entire-Checkpoint: db8b4bffc8b4Push output confirmed
entire/checkpoints/v1synced to the checkpoint remote.Real smoke test
Ran a disposable cross-repository smoke test with two separate temp git repos.
Flow:
src/feature.gostaged.entire session adopt smoke-adopt-session-001 --from <source> --forcein the target repo.src/feature.go.hooks git prepare-commit-msghandler.Entire-Checkpoint: 08f656dbcb95.hooks git post-commit.Smoke result:
Tests
go test ./cmd/entire/cli -run TestSessionAdopt_CopiesExternalSessionIntoCurrentWorktree -count=1go test ./cmd/entire/cli -run TestSessionAdopt -count=1go test ./cmd/entire/cli -count=1mise run lintmise run checkLatest verification after
dd22ba19819221df5250e041a491e988f8c414d1:mise run checkpassed, including lint, integration tests, Vogon canary, and roger-roger canary.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.
Adoption now intentionally rejects source/target worktrees that share the same git common dir. Those sessions share one
.git/entire-sessionsstore; copying adoption state there would mutate the original live session instead of creating independent target-local state. Same-repo sibling worktree matching should be handled by the sibling-worktree matching path instead.