cleanup orphan detection reads via topology · Entire
cleanup orphan detection reads via topology
48a2ea7→main·
pfleidi·1mo ago·2 files·+66 added/-1 removed
Swap ListOrphanedSessionStates from NewGitStore (v1-pinned) to NewCommittedReadStore (topology-aware) so v1.1 mode reads orphan candidates from the configured mirror ref.
A failed mirror advance under v1.1 could cause a false-orphan flag; this trade-off is intentional. v1.1 is internal-only until topology inversion lands.
Adds a TDD test that enables v1.1 with no mirror ref present and asserts that a session whose checkpoint exists only on v1 is flagged as orphaned.
Sessions
e19eadfd42feView transcript
Changes
2
cmd/entire/cli/strategy
Mclean_test.go+65
Mcleanup.go+1/-1
1 unmodified line
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
450 unmodified lines
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
1 unmodified line
import (
"context"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/entireio/cli/cmd/entire/cli/checkpoint"
"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
"github.com/entireio/cli/cmd/entire/cli/paths"
"github.com/entireio/cli/cmd/entire/cli/testutil"
"github.com/entireio/cli/redact"
"github.com/go-git/go-git/v6"
"github.com/go-git/go-git/v6/plumbing"
450 unmodified lines
}
}
// In v1.1 mode, a session whose checkpoint lives only on v1 must be flagged
// orphaned because the topology read goes to the (unset) mirror.
func TestListOrphanedSessionStates_V11ReadsViaTopology(t *testing.T) {
dir := t.TempDir()
testutil.InitRepo(t, dir)
testutil.WriteFile(t, dir, "f.txt", "init")
testutil.GitAdd(t, dir, "f.txt")
testutil.GitCommit(t, dir, "init")
t.Chdir(dir)
repo, err := git.PlainOpen(dir)
require.NoError(t, err)
const sessionID = "test-session-v11-orphan"
cpID := id.MustCheckpointID("b2c3d4e5f6a1")
require.NoError(t, checkpoint.NewGitStore(repo).WriteCommitted(t.Context(), checkpoint.WriteCommittedOptions{
CheckpointID: cpID,
SessionID: sessionID,
Strategy: "manual-commit",
Transcript: redact.AlreadyRedacted([]byte("transcript\n")),
Prompts: []string{"prompt"},
AuthorName: "Test",
AuthorEmail: "test@test.com",
}))
// BaseCommit is arbitrary; no shadow branch is created, so any value routes
// through the same orphan path. StartedAt clears the grace window.
state := &SessionState{
SessionID: sessionID,
BaseCommit: "0000000000000000000000000000000000000000",
StartedAt: time.Now().Add(-(sessionGracePeriod + time.Minute)),
StepCount: 1,
}
require.NoError(t, SaveSessionState(t.Context(), state))
settingsDir := filepath.Join(dir, ".entire")
require.NoError(t, os.MkdirAll(settingsDir, 0o755))
require.NoError(t, os.WriteFile(
filepath.Join(settingsDir, paths.SettingsFileName),
[]byte(`{"enabled": true, "strategy_options": {"checkpoints_version": "1.1"}}`),
0o644,
))
orphans, err := ListOrphanedSessionStates(t.Context())
require.NoError(t, err)
var flagged bool
for _, item := range orphans {
if item.ID == sessionID {
flagged = true
break
}
}
assert.True(t, flagged, "session must be flagged orphaned: mirror is unset, so topology read returns no checkpoints")
}
Mcmd/entire/cli/strategy/clean_test.go+65
168 unmodified lines
169
170
171
172
172
173
174
175
168 unmodified lines
}
// Get all checkpoints to find which sessions have checkpoints
cpStore := checkpoint.NewGitStore(repo)
cpStore := checkpoint.NewCommittedReadStore(ctx, repo)
sessionsWithCheckpoints := make(map[string]bool)
checkpoints, listErr := cpStore.ListCommitted(ctx)