Skip to content

fix(session): auto-adopt across git common dirs on commit#1777

Open
suhaanthayyil wants to merge 1 commit into
mainfrom
fix/1439-auto-adopt-cross-common-dir
Open

fix(session): auto-adopt across git common dirs on commit#1777
suhaanthayyil wants to merge 1 commit into
mainfrom
fix/1439-auto-adopt-cross-common-dir

Conversation

@suhaanthayyil

@suhaanthayyil suhaanthayyil commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Trail: https://entire.io/gh/entireio/cli/trails/875

Summary

Fixes #1439

What

Auto-adopt a unique ACTIVE agent session from another git common dir during prepare-commit-msg, so commits in an enabled repo B get an Entire-Checkpoint trailer when the live session state still lives under repo A.

Why / how it helps

Long agent sessions often move across independently enabled repos. Hooks fire in B, but B's .git/entire-sessions is empty, so the trailer is silently skipped even though Entire is installed. Manual entire session adopt (#1472) already exists; this wires a safe automatic path on commit.

How

  • Maintain a best-effort live-session registry under the user cache whenever an ACTIVE session is saved (cleared on end/clear/tombstone).
  • On prepare-commit-msg, if the current repo is enabled and has no local ACTIVE session, discover exactly one recent cross-common-dir candidate via:
    1. live-session registry (covers non-sibling paths), then
    2. immediate sibling repos under the parent directory (microservices / seeded repro).
  • Require FilesTouched overlap with staged paths. Process-owner match only disambiguates among overlap candidates — never adopts alone.
  • Ambiguous candidates skip. Reuses existing external session adopt machinery (retires source, seeds target-local bookkeeping).
  • Tradeoff: this is direction-1 handoff (adopt/retire), not a full joint multi-repo session model (issue direction 3). Coordinated A+B commits in one turn still need a future fan-out model.

Testing

  • Live repro (before): A trailer present; B message unchanged / no trailer; B entire-sessions empty.
  • Live repro (after, same script with /tmp/entire-1439):
    • A: Entire-Checkpoint: …
    • B: Entire-Checkpoint: … and session state present under B.
  • Edges: no FilesTouched overlap → no adopt; two overlapping sibling sources → no adopt.
  • Unit/regression: TestAutoAdopt_*, TestLiveRegistry_*, existing TestSessionAdopt_*.
  • Mutation: early-return no-op in tryAutoAdoptCrossCommonDirSessionTestAutoAdopt_PrepareCommitMsg_ViaLiveRegistry FAIL; restore → PASS.
  • Audit: two clean passes after requiring overlap (blocks owner-only steal) + wrapcheck/lint fixes.
  • mise run fmt && mise run lint green; go test ./cmd/entire/cli/session ./cmd/entire/cli green on committed tree.

When prepare-commit-msg runs in an enabled repo with no local ACTIVE
session, discover a unique recent cross-common-dir candidate (live
registry or sibling scan) whose FilesTouched overlaps staged paths and
adopt it so Entire-Checkpoint trailers are not silently dropped.
Copilot AI review requested due to automatic review settings July 16, 2026 14:50
@suhaanthayyil
suhaanthayyil requested a review from a team as a code owner July 16, 2026 14:50

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 addresses cross-repository agent session continuity by enabling prepare-commit-msg to automatically adopt a unique, recent session from another git common dir when the current repo has no local adoptable session state—so commits in the new repo can still receive an Entire-Checkpoint trailer.

Changes:

  • Introduces a best-effort per-user “live session” registry in the user cache to enable fast cross-common-dir discovery without filesystem scans.
  • Adds prepare-commit-msg auto-adopt logic that filters candidates by recency and required FilesTouched ↔ staged-file overlap, falling back to scanning sibling repos when the registry is inconclusive.
  • Extends session adopt internals with an option to skip transcript-path validation for auto-adopt, clearing invalid transcript paths instead of failing adoption.

Reviewed changes

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

Show a summary per file
File Description
cmd/entire/cli/session/state.go Registers/unregisters sessions in the live registry on save/clear.
cmd/entire/cli/session/live_registry.go Implements the live-session registry stored under the user cache.
cmd/entire/cli/session/live_registry_test.go Unit tests for registry behavior and Save/Clear integration.
cmd/entire/cli/session_auto_adopt.go Implements hook-time cross-common-dir auto-adoption and candidate selection logic.
cmd/entire/cli/session_auto_adopt_test.go Regression tests covering registry-based and sibling-scan adoption plus skip cases.
cmd/entire/cli/session_adopt.go Adds SkipTranscriptValidation and transcript-path clearing for auto-adopt safety.
cmd/entire/cli/hooks_git_cmd.go Invokes auto-adopt during prepare-commit-msg before trailer insertion.

Comment on lines +50 to +53
func RegisterLiveSession(state *State, commonDir string) error {
if !ShouldRegisterLive(state) {
return UnregisterLiveSession(state.SessionID)
}
Comment on lines +222 to 225
// When an ACTIVE agent session lives in another git common dir,
// adopt it into this repo before trailer insertion (#1439).
tryAutoAdoptCrossCommonDirSession(g.ctx)
hookErr := g.strategy.PrepareCommitMsg(g.ctx, commitMsgFile, source)
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.

Agent sessions should adopt enabled repos when a long session switches git common dirs

2 participants