claude-code: the latest login wins over a login not handed to the manager

A login not handed is kept only against a lease that does not succeed it; a lease
of the same account that succeeds it replaces it, said as login superseded. A login
to another account is kept until the manager adopts it.

Builds: ADR 0206, ADR 0209, design 39 §6, H-A-138 (hq design/47-H1-answers-59 175ed320), H-A-139 (hq design/47-H1-answers-59 e359911e), H-A-140 (hq design/47-H1-answers-59 b75d1386)
This commit is contained in:
2026-11-20 14:47:49 +01:00
parent 0934292f47
commit 121125aa50
2 changed files with 44 additions and 13 deletions
+15 -2
View File
@@ -633,9 +633,19 @@ func Apply(p Paths, c Current, sealed SealedBox, write WriteManaged) (map[string
// asks claude_code_grant for it on this node's report; its successor then comes as a newer generation.
// This return skips the binding's generation below on purpose: later binding events pull again until
// the manager adopts the login.
// The latest login wins (design 39 §6): a lease of the same account that succeeds the login (H-A-139) —
// the manager adopted a later login to that account from another node — replaces it, said as "login
// superseded"; a login to another account than the lease's licence is always kept (H-A-140, hq
// design/47-H1-answers-59 b75d1386).
superseded := false
if LoginNotHanded(local, readHanded(p)) {
log.Printf("login kept: the login in the credentials file was not handed to the manager yet (licence %s)", c.Licence)
return map[string]any{"applied": false, "licence": c.Licence, "reason": LoginKept}, nil
id := ReadIdentity(p.account())
if id == nil || id.EmailAddress == "" || id.EmailAddress != c.Licence || !Succeeds(local, g) {
log.Printf("login kept: the login in the credentials file was not handed to the manager yet (licence %s)", c.Licence)
return map[string]any{"applied": false, "licence": c.Licence, "reason": LoginKept}, nil
}
superseded = true
log.Printf("login superseded: a later login to the account of licence %s was adopted by the manager (generation %d)", c.Licence, c.Generation)
}
// A login handed to the manager is replaced only by a grant of a newer lineage (its refresh token's
// expiry later than the login's, or the same lineage with a later access expiry, as the manager's refresh yields it): a lease older than the login is never
@@ -646,6 +656,9 @@ func Apply(p Paths, c Current, sealed SealedBox, write WriteManaged) (map[string
return map[string]any{"applied": false, "licence": c.Licence, "reason": LoginKept}, nil
}
d := DecideApply(GrantOf(local), g, switched || HoldsLogin(local))
if d.Apply && superseded {
out["reason"] = "login superseded"
}
if d.Apply {
next := WithGrant(local, g)
if switched {