carlos / platform Public

region HA: a drained acknowledgement retires in-flight holder hints

Branch review r1, Astra B1.2. The drained fold dropped holder-cache
entries naming the drained box, but a lock read already in flight (a
discovery on an empty cache) and a delayed backhaul 503 naming the box
could install it again after the acknowledgement.

Both caches now refuse a drained ref from the fold's drop until a later
publication of that box no longer says ha_drained (memory only): no
path installs an entry naming it, an in-flight read that names it is
neither cached nor used (its callers read again), and a holder answer
naming it is neither followed nor remembered. A box that is only
draining stays a holder. The fold runs an undrained hook when a noted
box's file stops saying drained or goes.

Tests: a discovery paused across the drop and acknowledgement; set and
answered paths after the drop; draining not refused; the later
publication; a delayed backhaul answer after the drop relays the 503
and is followed again after an undrained publication. Spec §24 E11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2565b71ca56c8a60ce74b80360858694e8fd58f0 parent d6b3f24
12 files changed, +252 −27
  • docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md +1 −1
  • internal/activator/hacache.go +63 −19
  • internal/activator/hadrain.go +7 −0
  • internal/activator/hadrain_test.go +60 −0
  • internal/edge/backhaul_holder.go +31 −3
  • internal/edge/backhaul_holder_export_test.go +8 −0
  • internal/edge/backhaul_holder_wiring_test.go +27 −0
  • internal/edge/edge.go +3 −0
  • internal/edge/hadrain.go +25 −0
  • internal/edge/hadrain_test.go +19 −0
  • internal/edge/homemap.go +7 −4
  • internal/host/agent.go +1 −0

Intent

Human

<task-notification> <task-id>a39317d89a5ed42b7</task-id> <tool-use-id>toolu_01FcbMJFnmTcyMufjcLHZWEY</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/283be278-5c6a-4a71-a8d6-b3d32c668985/tasks/a39317d89a5ed42b7.output</output-file> <status>failed</status> <summary>Agent "Branch review fix wave 1" failed: Agent terminated early due to an API error: You've hit your weekly limit · resets Nov 12, 8pm (Europe/Dublin) (error type rate_limit, HTTP 429, request id req_011CgsYT2yBL1WJLbufySTb1, model sent to the API: claude-opus-5-5)</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once. This agent's work so far is saved. The limit resets Nov 12, 8pm (Europe/Dublin). Once its requests are accepted again, send the agent a message (SendMessage) to let it continue from where it stopped instead of starting a new agent.</note> <result>Caught. Now the spec row and a broader targeted run before committing.</result> </task-notification>

diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
index 788b6df7f..7064462e6 100644
--- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
+++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
@@ -1002,7 +1002,7 @@ the same rule for every box.
| C18 | Domain attach conflict check | Blind: live member routes reserve names, as H2. |
| Scripts | Group roll and boot witness | Aware operator tools: inspect members by reference and check that a completed witness left no member files. The roll tool's §25.9 floor check reads `ha_take` on every live box of the region's view, fixed forwarders included, and refuses a drain unless each says the number 1. A stale member file counts until departure removes it. |
| E10 | Silence rule (`Edge.PeerDraining`, read by the activator's `NoteForward`; §25.5) | Blind: a box whose file says `draining` or `ha_drained` is not made silent or suspect for a held answer. Dial failures still make any box suspect. A terminated member that was draining keeps that file until departure, so only its silence is ignored. |
-| E11 | Holder-cache drop (`notePeerDrained`, §25.4 step 4) | Blind: a file that says `ha_drained` drops this box's holder-cache entries naming that box, once per publication (its `ha_drain` id, else its generation). A stale drained file drops nothing new. |
+| E11 | Holder-cache drop (`notePeerDrained`, §25.4 step 4) | Blind: a file that says `ha_drained` drops this box's holder-cache entries naming that box, once per publication (its `ha_drain` id, else its generation), before the drained acknowledgement. From then until a later publication of that box no longer says `ha_drained`, neither cache installs or follows the box as a holder: a lock read that was in flight across the drop, and a delayed holder answer naming it, are not used (build ruling, 2026-11-09). A stale drained file drops nothing new. A box that is only `draining` stays a holder. |
| E12 | Drain acknowledgement receiver (`/.carlos/ha-drain`, `foldedDrain`, §25.4 step 1) | Blind: it reads the asker's own file by its exact key and answers whether its fold shows `draining` or `ha_drained` under the asked `ha_drain` transaction and id. A file that no longer matches, a stale one included, is answered as not seen. |
| E13 | Take capability (`takeCapable`, `Edge.PeerTakes`; §25.7) | Blind: a box is asked to take only when its file says `ha_take` as the number 1. Absent, other numbers, strings and booleans mean no. A stale member file can still name a successor; the take then fails its dial, and the drain tries the next candidate or fails. |
diff --git a/internal/activator/hacache.go b/internal/activator/hacache.go
index 687b30a30..7de23276a 100644
--- a/internal/activator/hacache.go
+++ b/internal/activator/hacache.go
@@ -49,6 +49,13 @@ type holderCache struct {
order list.List // oldest set at the front
flights map[string]*holderFlight // host -> the lock read in flight
seq uint64 // the last generation handed out
+ // drained is every ref whose drained publication this cache has seen
+ // (dropRef) and no later publication has cleared (allowRef). No entry
+ // naming one is installed, from any path, and a read that names one is
+ // not used: §25.4 step 4's acknowledgement retires every hint naming
+ // the drained box, including those still in flight (branch review r1,
+ // Astra B1.2). Draining boxes are not in it: they stay reachable.
+ drained map[string]bool
}
type holderEntry struct {
@@ -190,16 +197,23 @@ func (c *holderCache) drop(host string) {
}
}
-// dropRef forgets every entry naming ref, suspect or not, and marks any
-// read in flight revalidating ref stale, so its answer is not cached
-// (§25.4 step 4: ref published drained). Negative entries and entries
-// naming other boxes stand. A scan, run once per drained publication.
+// dropRef forgets every entry naming ref, suspect or not, and refuses ref
+// from now until allowRef (§25.4 step 4: ref published drained): no path
+// installs an entry naming it, and a lock read in flight, which may have
+// read ref's old lease before the drop (a discovery on an empty cache
+// included), is not cached or used if it names ref. Negative entries and
+// entries naming other boxes stand. A scan, run once per drained
+// publication, before the publication's acknowledgement.
func (c *holderCache) dropRef(ref string) {
if ref == "" {
return
}
c.mu.Lock()
defer c.mu.Unlock()
+ if c.drained == nil {
+ c.drained = map[string]bool{}
+ }
+ c.drained[ref] = true
for _, el := range c.holders {
if el.Value.(*holderEntry).ref == ref {
c.removeLocked(el)
@@ -212,11 +226,27 @@ func (c *holderCache) dropRef(ref string) {
}
}
-// putLocked sets host's entry under a new generation.
-func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duration) {
+// allowRef ends dropRef's refusal of ref: a later publication of ref's
+// edges file no longer says drained.
+func (c *holderCache) allowRef(ref string) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ delete(c.drained, ref)
+}
+
+// putLocked sets host's entry under a new generation and returns it. An
+// entry naming a drained ref is not set: host's entry is removed instead,
+// and putLocked returns nil.
+func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duration) *holderEntry {
if f := c.flights[host]; f != nil {
f.stale = true
}
+ if ref != "" && c.drained[ref] {
+ if el := c.holders[host]; el != nil {
+ c.removeLocked(el)
+ }
+ return nil
+ }
if c.holders == nil {
c.holders = map[string]*list.Element{}
}
@@ -234,12 +264,14 @@ func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duratio
e.rechecked = false
e.kind = edge.Holder
c.order.MoveToBack(el)
- return
+ return e
}
for len(c.holders) >= holderCacheMax {
c.removeLocked(c.order.Front())
}
- c.holders[host] = c.order.PushBack(&holderEntry{host: host, ref: ref, suspect: suspect, expires: expires, gen: c.seq})
+ e := &holderEntry{host: host, ref: ref, suspect: suspect, expires: expires, gen: c.seq}
+ c.holders[host] = c.order.PushBack(e)
+ return e
}
func (c *holderCache) removeLocked(el *list.Element) {
@@ -368,35 +400,47 @@ func (c *holderCache) runRead(host string, f *holderFlight, read func() holderRe
delete(c.flights, host)
switch {
case f.stale:
+ case r.Err == nil && r.Ref != "" && c.drained[r.Ref]:
+ // The read began before ref's drained publication was folded here
+ // and read its old lease: neither cached nor used. Its callers
+ // look again (Astra B1.2).
+ f.stale = true
+ if el := c.holders[host]; el != nil && el.Value.(*holderEntry).ref == r.Ref {
+ c.removeLocked(el)
+ }
case f.silent && (r.Err != nil || r.View == nil):
// An unreadable lock supplies no new evidence about the holder.
if c.clock().Before(f.fallbackUntil) {
- c.putLocked(host, f.suspect, false, f.fallbackUntil.Sub(c.clock()))
- c.holders[host].Value.(*holderEntry).silentUntil = f.until
- f.cached = true
+ if e := c.putLocked(host, f.suspect, false, f.fallbackUntil.Sub(c.clock())); e != nil {
+ e.silentUntil = f.until
+ f.cached = true
+ }
} else if el := c.holders[host]; el != nil {
c.removeLocked(el)
}
case !f.silent && !f.until.IsZero() && !(r.Err == nil && r.View != nil && (r.View.Absent || r.View.Lock.Release != nil)):
// N-HA15: only a release or absence ends backoff early. Keep the
// original deadline, including on read errors and live owners.
- c.putLocked(host, f.suspect, true, f.until.Sub(c.clock()))
- c.holders[host].Value.(*holderEntry).rechecked = true
+ if e := c.putLocked(host, f.suspect, true, f.until.Sub(c.clock())); e != nil {
+ e.rechecked = true
+ }
f.refuse = true
case r.Err == nil && r.View != nil:
ttl := holderNegativeTTL
if r.Ref != "" {
ttl = holderPositiveTTL
}
- c.putLocked(host, r.Ref, false, ttl)
- c.holders[host].Value.(*holderEntry).view = r.View
- if f.silent && r.Ref == f.suspect {
- c.holders[host].Value.(*holderEntry).silentUntil = f.until
+ if e := c.putLocked(host, r.Ref, false, ttl); e != nil {
+ e.view = r.View
+ if f.silent && r.Ref == f.suspect {
+ e.silentUntil = f.until
+ }
}
f.cached = true
case f.suspect != "":
- c.putLocked(host, f.suspect, true, holderSuspectTTL)
- c.holders[host].Value.(*holderEntry).rechecked = true
+ if e := c.putLocked(host, f.suspect, true, holderSuspectTTL); e != nil {
+ e.rechecked = true
+ }
f.refuse = true
}
f.ref, f.view = r.Ref, r.View
diff --git a/internal/activator/hadrain.go b/internal/activator/hadrain.go
index 9706ea5f3..e5c4025f9 100644
--- a/internal/activator/hadrain.go
+++ b/internal/activator/hadrain.go
@@ -56,3 +56,10 @@ func (a *Service) peerDraining(ref string) bool {
func (a *Service) DropHoldersNaming(ref string) {
a.holders.dropRef(ref)
}
+
+// AllowHoldersNaming ends DropHoldersNaming's refusal of ref: the edge's
+// fold sees ref's file no longer say drained (a later publication: a
+// cancelled drain, or a restarted member that serves again).
+func (a *Service) AllowHoldersNaming(ref string) {
+ a.holders.allowRef(ref)
+}
diff --git a/internal/activator/hadrain_test.go b/internal/activator/hadrain_test.go
index 864b85ec6..b7d172fb7 100644
--- a/internal/activator/hadrain_test.go
+++ b/internal/activator/hadrain_test.go
@@ -146,3 +146,63 @@ func TestDropHoldersNaming(t *testing.T) {
t.Fatal("DropHoldersNaming left the entry")
}
}
+
+// Branch review r1, Astra B1.2: a discovery on an empty cache has read A's
+// old lease and is paused before it commits; A's drained publication is
+// folded (DropHoldersNaming) and acknowledged; the read then completes. Its
+// answer is neither cached nor used: its callers look again and get the
+// current holder. After the drop no path installs A (a set, a forward's
+// answer); a draining box is not refused; a later publication that no
+// longer says drained (AllowHoldersNaming) ends the refusal.
+func TestDrainedDropOutlivesAPausedRead(t *testing.T) {
+ s := haService(t, "shop.example.com")
+ c := &s.a.holders
+ host := "x.example.com"
+ paused, resume := make(chan struct{}), make(chan struct{})
+ var reads atomic.Int32
+ read := func() holderRead {
+ if reads.Add(1) == 1 {
+ close(paused)
+ <-resume
+ return holderRead{Ref: "a", View: &hafresh.View{}}
+ }
+ return holderRead{Ref: "b", View: &hafresh.View{}}
+ }
+ got := make(chan holderResolution, 1)
+ go func() { got <- c.resolve(context.Background(), host, read) }()
+ <-paused
+ s.a.DropHoldersNaming("a") // the fold's drained effect, before its ack
+ close(resume)
+ r := <-got
+ if r.Ref != "b" || reads.Load() != 2 {
+ t.Fatalf("the paused read's caller got %+v after %d reads, want b after a second read", r, reads.Load())
+ }
+ if ref, positive, _ := c.get(host); ref != "b" || !positive {
+ t.Fatalf("cached %q %v, want b", ref, positive)
+ }
+ // No path installs a afterwards.
+ c.set("y.example.com", "a")
+ c.answered(host, "a")
+ if ref, _, found := c.get("y.example.com"); found {
+ t.Fatalf("set installed the drained box: %q", ref)
+ }
+ if ref, _, _ := c.get(host); ref != "b" {
+ t.Fatalf("an answer from the drained box replaced b: %q", ref)
+ }
+ c.set(host, "a")
+ if _, _, found := c.get(host); found {
+ t.Fatal("a set naming the drained box left an entry for the host")
+ }
+ // A box that is only draining stays a holder.
+ s.a.SetPeerDrainView(func(ref string) bool { return ref == "d" })
+ c.set("z.example.com", "d")
+ if ref, positive, _ := c.get("z.example.com"); ref != "d" || !positive {
+ t.Fatal("a draining box was refused as a holder")
+ }
+ // A later publication that is not drained ends the refusal.
+ s.a.AllowHoldersNaming("a")
+ c.set("y.example.com", "a")
+ if ref, positive, _ := c.get("y.example.com"); ref != "a" || !positive {
+ t.Fatalf("a after AllowHoldersNaming: %q %v", ref, positive)
+ }
+}
diff --git a/internal/edge/backhaul_holder.go b/internal/edge/backhaul_holder.go
index 1b4d63ca5..d84a8dbed 100644
--- a/internal/edge/backhaul_holder.go
+++ b/internal/edge/backhaul_holder.go
@@ -43,6 +43,10 @@ type backhaulHolderCache struct {
mu sync.Mutex
entries map[string]*list.Element
order list.List
+ // drained is every ref whose drained publication this edge has folded
+ // (dropRef) and no later publication has cleared (allowRef): nothing
+ // naming it is remembered or followed (branch review r1, Astra B1.2).
+ drained map[string]bool
}
func (c *backhaulHolderCache) get(host string, owner backhaulOwner, now time.Time) string {
@@ -67,6 +71,9 @@ func (c *backhaulHolderCache) get(host string, owner backhaulOwner, now time.Tim
func (c *backhaulHolderCache) remember(host, ref string, owner backhaulOwner, now time.Time) bool {
c.mu.Lock()
defer c.mu.Unlock()
+ if c.drained[ref] {
+ return false
+ }
if c.entries == nil {
c.entries = make(map[string]*list.Element)
}
@@ -98,14 +105,35 @@ func (c *backhaulHolderCache) drop(host, ref string, owner backhaulOwner) bool {
return false
}
+// isDrained is whether ref is refused as a holder: its drained
+// publication is folded here and not cleared since.
+func (c *backhaulHolderCache) isDrained(ref string) bool {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ return c.drained[ref]
+}
+
+// allowRef ends dropRef's refusal of ref.
+func (c *backhaulHolderCache) allowRef(ref string) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ delete(c.drained, ref)
+}
+
// dropRef forgets every entry naming ref (it published drained, §25.4
-// step 4) and reports how many went.
+// step 4), refuses ref from now until allowRef, so a delayed holder
+// answer naming ref neither installs nor is followed, and reports how many
+// entries went.
func (c *backhaulHolderCache) dropRef(ref string) int {
if ref == "" {
return 0
}
c.mu.Lock()
defer c.mu.Unlock()
+ if c.drained == nil {
+ c.drained = make(map[string]bool)
+ }
+ c.drained[ref] = true
n := 0
for host, el := range c.entries {
if el.Value.(backhaulHolderEntry).ref == ref {
@@ -230,7 +258,7 @@ func (e *Edge) backhaulAttempt(w http.ResponseWriter, r *http.Request, host, dia
return nil
}
hRef, _, ok := ParseHandover(handover)
- if !ok {
+ if !ok || e.backhaulHolders.isDrained(hRef) {
return nil
}
now := time.Now()
@@ -244,7 +272,7 @@ func (e *Edge) backhaulAttempt(w http.ResponseWriter, r *http.Request, host, dia
nextDial, nextRef, nextReason = addr, hRef, "handover"
return errBackhaulHolder
}
- if ref == "" || ref == "none" || ref == box {
+ if ref == "" || ref == "none" || ref == box || e.backhaulHolders.isDrained(ref) {
return nil
}
now := time.Now()
diff --git a/internal/edge/backhaul_holder_export_test.go b/internal/edge/backhaul_holder_export_test.go
index 7e80903dd..b80ea17cb 100644
--- a/internal/edge/backhaul_holder_export_test.go
+++ b/internal/edge/backhaul_holder_export_test.go
@@ -245,3 +245,11 @@ func (s *BackhaulHolderScene) CancelHeldRequest(t *testing.T) {
time.Sleep(time.Millisecond)
}
}
+
+// SenderFoldsDrained runs the sender's drained effects for ref, as its
+// fold does before a drained acknowledgement (§25.4 step 4).
+func (s *BackhaulHolderScene) SenderFoldsDrained(ref string) { s.sender.edge.runPeerDrained(ref) }
+
+// SenderFoldsUndrained runs the sender's effects of a later publication
+// of ref that no longer says drained.
+func (s *BackhaulHolderScene) SenderFoldsUndrained(ref string) { s.sender.edge.runPeerUndrained(ref) }
diff --git a/internal/edge/backhaul_holder_wiring_test.go b/internal/edge/backhaul_holder_wiring_test.go
index 8e2b0485b..5655d9d91 100644
--- a/internal/edge/backhaul_holder_wiring_test.go
+++ b/internal/edge/backhaul_holder_wiring_test.go
@@ -281,3 +281,30 @@ func TestBackhaulHolderUpgrade(t *testing.T) {
t.Fatalf("upgrade calls=%d/%d", a, b)
}
}
+
+// Branch review r1, Astra B1.2: a holder answer that names a box arrives
+// after this edge folded that box's drained publication (a backhaul whose
+// 503 was delayed past the acknowledgement). It is neither followed nor
+// remembered: the 503 is relayed, today's answer. A later publication
+// that no longer says drained makes the box a holder again.
+func TestBackhaulHolderAnswerAfterDrainedIsIgnored(t *testing.T) {
+ svc, rt, bucket, _ := backhaulHeldService(t, "betty")
+ s := edge.NewBackhaulHolderScene(t, bucket, svc, rt)
+ s.SenderFoldsDrained("betty")
+ for i := 0; i < 2; i++ {
+ status, headers, body := s.Request(t, "GET", "/", "")
+ if status != 503 || headers.Get("X-Carlos-Holder") != "betty" || body != unreachableBody {
+ t.Fatalf("after drained: %d %v %q", status, headers, body)
+ }
+ }
+ if a, b := s.Counts(); a != 2 || b != 0 {
+ t.Fatalf("calls=%d/%d; the drained holder was followed or remembered", a, b)
+ }
+ s.SenderFoldsUndrained("betty")
+ if status, _, body := s.Request(t, "GET", "/", ""); status != 200 || !strings.HasPrefix(body, "holder|") {
+ t.Fatalf("after a later publication: %d %q", status, body)
+ }
+ if a, b := s.Counts(); a != 3 || b != 1 {
+ t.Fatalf("calls=%d/%d; want the holder followed again", a, b)
+ }
+}
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 4d1cbddb1..0d012d33c 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -376,6 +376,9 @@ type Edge struct {
// peerDrained is the hook a fold runs when it first sees a peer's file
// say ha_drained (hadrain.go, SetPeerDrainedHook).
peerDrained atomic.Pointer[func(string)]
+ // peerUndrained is the hook a fold runs when a peer it noted drained
+ // no longer says so (SetPeerUndrainedHook).
+ peerUndrained atomic.Pointer[func(string)]
// conns is the planned-handover connection drain (hadrainconns.go,
// region HA §25.4 step 4): every request ServeHTTP serves, counted.
conns connDrain
diff --git a/internal/edge/hadrain.go b/internal/edge/hadrain.go
index 9d9b646b2..8bcf2269b 100644
--- a/internal/edge/hadrain.go
+++ b/internal/edge/hadrain.go
@@ -371,6 +371,13 @@ func (m *homeMap) notePeerDrained(files map[string]edgesFileView) {
}
done[box] = id
}
+ // A box noted drained whose file no longer says so (a later
+ // publication, or no file) is a holder again.
+ for box := range prev {
+ if _, ok := now[box]; !ok && m.peerUndrained != nil {
+ m.peerUndrained(box)
+ }
+ }
m.drainedMu.Lock()
m.drainedNoted = done
m.drainedMu.Unlock()
@@ -410,6 +417,24 @@ func (e *Edge) SetPeerDrainedHook(fn func(ref string)) {
e.peerDrained.Store(&fn)
}
+// SetPeerUndrainedHook sets what else runs when this edge's fold sees a
+// peer it noted drained no longer say so: the activator's holder cache
+// accepts it again. The edge's own backhaul cache does first.
+func (e *Edge) SetPeerUndrainedHook(fn func(ref string)) {
+ if fn == nil {
+ e.peerUndrained.Store(nil)
+ return
+ }
+ e.peerUndrained.Store(&fn)
+}
+
+func (e *Edge) runPeerUndrained(ref string) {
+ e.backhaulHolders.allowRef(ref)
+ if fn := e.peerUndrained.Load(); fn != nil {
+ (*fn)(ref)
+ }
+}
+
func (e *Edge) runPeerDrained(ref string) {
if n := e.backhaulHolders.dropRef(ref); n > 0 {
e.logThrottled("backhaul-holder-drained "+ref, fmt.Sprintf("backhaul holder: dropped %d entries naming %s: it published drained", n, ref))
diff --git a/internal/edge/hadrain_test.go b/internal/edge/hadrain_test.go
index 84f619924..ffdc6e2ce 100644
--- a/internal/edge/hadrain_test.go
+++ b/internal/edge/hadrain_test.go
@@ -435,6 +435,25 @@ func TestHADrainedClearsBackhaulHolders(t *testing.T) {
if b.edge().backhaulHolders.get("x.example.com", other, time.Now()) != "carol" {
t.Fatal("an entry naming another box was dropped")
}
+ // After the acknowledgement nothing installs annie again (Astra B1.2).
+ if b.edge().backhaulHolders.remember(c.host, "annie", owner, time.Now()) {
+ t.Fatal("a holder answer naming the drained box was remembered after the ack")
+ }
+ if _, box := b.edge().backhaulTarget(c.host, c.ip, "carol", owner); box != "carol" {
+ t.Fatalf("after the ack the routing chose %s", box)
+ }
+ // A later publication that no longer says drained clears the refusal,
+ // on the fold, through the undrained hook.
+ var undrained []string
+ b.edge().SetPeerUndrainedHook(func(ref string) { undrained = append(undrained, ref) })
+ s.file(t, a, drainGen0.Add(2*time.Minute), notDrain)
+ refreshHomeMap(t, b.be.homes)
+ if len(undrained) != 1 || undrained[0] != "annie" {
+ t.Fatalf("undrained hook %v, want [annie]", undrained)
+ }
+ if !b.edge().backhaulHolders.remember(c.host, "annie", owner, time.Now()) {
+ t.Fatal("annie stayed refused after a publication that is not drained")
+ }
}
// P2 (finding 4): two members that publish no hosts still reach each
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go
index d4a788d81..8579f5828 100644
--- a/internal/edge/homemap.go
+++ b/internal/edge/homemap.go
@@ -393,10 +393,12 @@ type homeMap struct {
// the edge's drained effects (nil: none), and drainedNoted, guarded by
// drainedMu, the publication ID of each drained file whose effects
// completed.
- drainAcks drainAcks
- peerDrained func(ref string)
- drainedMu sync.Mutex
- drainedNoted map[string]uint64
+ drainAcks drainAcks
+ peerDrained func(ref string)
+ // peerUndrained runs when a box noted drained no longer is.
+ peerUndrained func(ref string)
+ drainedMu sync.Mutex
+ drainedNoted map[string]uint64
}
func newHomeMap(s release.Store, self string) *homeMap {
@@ -418,6 +420,7 @@ func (e *Edge) newHomeMap() *homeMap {
m.watch = e.changeWatch
m.departureTick = e.departureTick
m.peerDrained = e.runPeerDrained
+ m.peerUndrained = e.runPeerUndrained
return m
}
diff --git a/internal/host/agent.go b/internal/host/agent.go
index 8b8c04da8..b8d75108b 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -1221,6 +1221,7 @@ func runAgent(args []string, buildClaims ClaimFactory) {
svc.SetDrainingSource(boxDrain.IsDraining)
svc.SetPeerDrainView(e.PeerDraining)
e.SetPeerDrainedHook(svc.DropHoldersNaming)
+ e.SetPeerUndrainedHook(svc.AllowHoldersNaming)
// The drain driver and its agent-user-only socket (hadrain.go),
// on group members only: the drain verbs are theirs.
if admission != nil && admission.group {