Skip to content

Commit 09da6ee

Browse files
karngyanclaude
andauthored
fix(session): reattach sweeps only holders that are actually gone
DialRemote's ErrHolderGone is the license to sweep; a holder that answered the dial and then failed the handshake is alive, with a plausibly running session behind it, and its directory is left for a daemon that can speak to it. A missing or corrupt identity record no longer costs a live session its reattach either — the hello carries the spawn-time facts, so a zero record lets the holder's account stand. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 0fa3005 commit 09da6ee

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

internal/session/reattach.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package session
22

33
import (
4+
"errors"
45
"os"
56
"path/filepath"
67
)
@@ -29,16 +30,23 @@ func ReattachHolders(r *Registry, root string) (reattached, swept int) {
2930
continue
3031
}
3132
dir := filepath.Join(root, e.Name())
32-
rec, err := LoadIdentity(dir)
33-
if err != nil {
34-
_ = os.RemoveAll(dir)
35-
swept++
36-
continue
37-
}
33+
// The identity record is auxiliary here, not a gate: the hello
34+
// carries every fact the holder knew at spawn, so a record that
35+
// failed to write (or to survive) costs the reattach nothing but
36+
// the one edit only the record remembers, an ephemeral promotion.
37+
// A zero record lets the holder's own account stand.
38+
rec, _ := LoadIdentity(dir)
3839
rem, err := DialRemote(dir, rec, r.clock)
3940
if err != nil {
40-
_ = os.RemoveAll(dir)
41-
swept++
41+
if errors.Is(err, ErrHolderGone) {
42+
_ = os.RemoveAll(dir)
43+
swept++
44+
}
45+
// A holder that answered the dial and then failed the
46+
// handshake is alive, and behind it plausibly a running
47+
// session — a newer holder under an older daemon, say. Not
48+
// this daemon's to destroy; leave the directory for a daemon
49+
// that can speak to it.
4250
continue
4351
}
4452
r.mu.Lock()

0 commit comments

Comments
 (0)