fix(session): clear adopted source owner · Entire

fix(session): clear adopted source owner

8379e34→main·

peyton-alt·3w ago·2 files·+53 added/-0 removed

Sessions

ed2ff36c6c0eView transcript

[?
Adopt Active Sessions Across Repos and WorktreesCodex·GPT-5.5·8 steps](/content/gh/entireio/cli/session/019ef6af-f809-76d3-8c95-7d7f0bc0c5ef#timeline-ed2ff36c6c0e/index.html)

Changes

2

451 unmodified lines

452
453
454
455
456
457
458
459
460

451 unmodified lines

adopted.PromptWindowBase = adopted.SessionTurnCount
    adopted.PromptWindowResetPending = false
    adopted.AttachedManually = false
    // The source process owner may already be gone; a new turn will capture the
    // current owner, and until then liveness should fall back to the timeout.
    adopted.Owner = nil

return &adopted, filesTouched, nil
}

Mcmd/entire/cli/session_adopt.go+3

15 unmodified lines

16
17
18
19
20
21
22
81 unmodified lines

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

15 unmodified lines

"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
    "github.com/entireio/cli/cmd/entire/cli/internal/flock"
    "github.com/entireio/cli/cmd/entire/cli/paths"
    "github.com/entireio/cli/cmd/entire/cli/proclive"
    "github.com/entireio/cli/cmd/entire/cli/session"
    "github.com/entireio/cli/cmd/entire/cli/strategy"
    "github.com/entireio/cli/cmd/entire/cli/testutil"
81 unmodified lines

}
}

func TestSessionAdopt_ClearsSourceOwner(t *testing.T) {
    sourceRepo := setupAdoptRepo(t)
    targetRepo := setupAdoptRepo(t)

sessionID := "test-adopt-clear-owner"
    lastInteraction := time.Now().Add(-1 * time.Minute)
    sourceStore := session.NewStateStoreWithDir(filepath.Join(sourceRepo, ".git", session.SessionStateDirName))
    if err := sourceStore.Save(context.Background(), &session.State{
        SessionID:             sessionID,
        AgentType:             agent.AgentTypeClaudeCode,
        StartedAt:             time.Now().Add(-5 * time.Minute),
        LastInteractionTime:   &lastInteraction,
        Phase:                 session.PhaseActive,
        BaseCommit:            testutil.GetHeadHash(t, sourceRepo),
        AttributionBaseCommit: testutil.GetHeadHash(t, sourceRepo),
        WorktreePath:          sourceRepo,
        Owner:                 &proclive.Identity{PID: os.Getpid(), Start: "source-owner"},
    }); err != nil {
        t.Fatal(err)
    }

testutil.WriteFile(t, targetRepo, "feature.txt", "agent change\n")
    t.Chdir(targetRepo)

var out bytes.Buffer
    err := runAdopt(context.Background(), &out, sessionID, adoptOptions{
        FromWorktree: sourceRepo,
        Force:        true,
    })
    if err != nil {
        t.Fatalf("runAdopt failed: %v", err)
    }

targetStore, err := session.NewStateStore(context.Background())
    if err != nil {
        t.Fatal(err)
    }
    adopted, err := targetStore.Load(context.Background(), sessionID)
    if err != nil {
        t.Fatal(err)
    }
    if adopted == nil {
        t.Fatal("expected adopted session state in target repo")
    }
    if adopted.Owner != nil {
        t.Fatalf("Owner = %#v, want nil so source process liveness cannot finalize adopted session", adopted.Owner)
    }
}

func TestSessionAdopt_RejectsUnexpectedSourceTranscriptPath(t *testing.T) {
    sourceRepo := setupAdoptRepo(t)
    targetRepo := setupAdoptRepo(t)