carlos / platform Public

drain: name what quiesce waits on, give up, end stale recoveries (#1062)

An HA group drain could hang silently: quiesce polled DrainQuietNow with
no log and no bound but the call context, and a lost host's record kept
Recovering forever once its recovery entry ended without succeeding.

- activator: endHARecoveryLocked clears l.recovery when the recovery
  entry leaves (failed wake, finishStop: failed post-check, retired
  route). The loss stays latched; local wakes stay refused until a
  recovery succeeds.
- drain: quiesce and settle log the non-zero counts with host names once
  a minute and give up after 5 minutes with a reason naming them; the
  move fails through the existing path, so cancel and return work.
- status: the drain socket and group-maintenance status gain an additive
  waiting block (step, since, counts, hosts, truncated), byte-bounded
  under the 8192-byte status limit.

Astra review: READY AFTER FIXES, P2 (status byte bound) fixed. Census
approved by Astra.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from drain-quiesce-1062 into main.
claude agent, operated by paul@keymail.dev d279e9046cb1170b94e0e6a06726480a37f71f55 parent 9eec023
13 files changed, +819 −40
  • docs/superpowers/notes/census-proposal-drain-quiesce-1062.md +21 −0
  • internal/activator/activator.go +2 −0
  • internal/activator/hadrainmove.go +55 −9
  • internal/activator/hadrainquiet_test.go +168 −0
  • internal/activator/haleaseloss.go +14 −0
  • internal/host/group_maintenance_drain.go +1 −0
  • internal/host/group_maintenance_verbs.go +3 −0
  • internal/host/hadrain.go +205 −31
  • internal/host/hadrain_quiet_linux_test.go +111 −0
  • internal/host/hadrain_quiet_test.go +222 −0
  • internal/host/hadrain_test.go +8 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-drain-quiesce-1062.tsv +8 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-drain-quiesce-1062.md b/docs/superpowers/notes/census-proposal-drain-quiesce-1062.md
new file mode 100644
index 000000000..318b55e66
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-drain-quiesce-1062.md
@@ -0,0 +1,21 @@
+# Census approval: drain-quiesce-1062
+
+Ruling `census-ruling-drain-quiesce-1062`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/activator.go` `Service.finishStop` | body | unchanged (5) | #1062: before deleting the entry, calls endHARecoveryLocked(e) (in-memory, under a.mu), which clears a lost host's l.recovery when e was its recovery entry; the loss stays latched; read sites unchanged, no read added |
+| `internal/activator/activator.go` `Service.wake` | body | unchanged (16) | #1062: the failed-wake cleanup calls endHARecoveryLocked(e) as it removes the entry (in-memory, under a.mu); read sites unchanged, no read added |
+
+Envelopes re-pinned: `internal/activator`, `internal/host`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/activator/activator.go` `Service.finishStop`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with a run's settle checked before replication closes, which keeps the stop pending until the run is proven stopped; read sites unchanged, offsets moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: an HA entry (its replica is an HA one, haEntryRep) now releases through releaseHAClean (a new unit on this card) instead of e.rep.Close; when that answers errHostSliceUnproven the stop is kept pending (keepPendingLocked) with the lease held and renewing, and the sweep finishes it once proven; a non-HA entry is unchanged; the same five sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: a forgotten entry's stop is noted for its resident (noteResidentStopLocked: crash or lost lease backs off, any other stop restarts on the next tick) and its ownerDone channel is closed; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: while the host has a release command's record (a.releaseOps[e.host], running or not proven stopped), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the record's proof; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.20: while a rootfs worker may run or is a stray (rootfsWorkersLiveLocked, in-memory, read under a.mu), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the workers are proven stopped; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1 (Astra P1): beside the worker check, under the same lock, a stop with a lease stop of its commands outstanding (e.leaseStops) is kept pending, the replica and lease held, and the sweep finishes it once they have returned; the entry is never released while a kill captured for it may still reach its unit; the same five read sites, no read added Task 9 (PF-3): the count is pendingLeaseStopsLocked(e), the sum of e.leaseStops over both one-shot roles (now a map per role, cmd and tty), so a session's lease stop of the tty unit keeps the stop pending, the replica and lease held, as a run's does; the same five read sites, no read added;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Retain command, worker, release and cgroup proofs. For an actual stateless generation no replica needs closing; close local lifecycle ownership only once those proofs finish.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds a.cancelHeldLegsLocked(e, 0) under a.mu just before the entry is deleted; it only calls the legs' context cancel functions. No read added, none removed.;rev3=census-ruling-region-ha-g2-fixes;basis=Latch HA loss if release leaves an obligation; stopping proofs still precede entry removal; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5 fix 1: records the finished stop's release outcome (marker written, clean) in the drain transaction's in-memory release log while a drain records (noteDrainReleaseLocked); memory only; no read added;rev3=census-ruling-fleet-record-labels-m1;basis=fleet record labels R2: a non-HA replica of a fleet-placed row releases through closeFleetCheckpoint (CloseProven) instead of Close; an unproven final checkpoint keeps the stop pending (keepPendingLocked) with the lease held and renewing, or ends unclean without a release over a lost lease (ErrCheckpointAbandoned); at Shutdown it is only named (C45) and the lease runs to its TTL; never releases over an unproven checkpoint; platform-region rows unchanged; the same five read sites, no read added
+- `internal/activator/activator.go` `Service.wake`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body; the stop now carries its reason for a run it interrupts (beginStopLocked's why argument); read sites unchanged, offsets moved;rev3=census-ruling-wake-latency-1;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=logs that timer's breakdown to the journal after a successful wake (w.steps.String(), e.host, w.wakeTook); no read added;rev3=census-ruling-plans-4d-lapse;basis=cancels a wake whose row the turned-off hook names, like a fence, unless it is a move's active probe (plans 4d). One more whole-row read: the row handed to the hook (a.disabled). Only refuses.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: a refusal before the lease is reported once per change (noteRootfsRefusal) instead of a wake-failure event; the proc, generation and replica are installed through installProcLocked (which puts a resident under its lease watch before the fence); residency notes the outcome (noteResidentWakeLocked); same generation values;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R [pf R3.5]: the wake's context ceiling is wakeCeilingFor(e.route): the old 5 minutes for a binary row, 5 minutes plus runs.MaxTimeout for a rootfs row (room for a release inside the wake); new site +whole:Route (e.route to wakeCeilingFor, which reads Runtime only); no other change;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (branch review R1 P1-1): the wake's context is also cancelled before doWake when RetireExcept has marked the entry retired (e.retired, in memory under a.mu), as it is for a fence or a shutdown. Read sites unchanged (13). Agent, not root; it only refuses more.;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Carry successful hold preparation into its wake, preserve actual mode in the generation and OnWake projection, and project serving version/mode through the narrow registry writer before releasing wake waiters. Final review I1: SetServingMode only for non-worker successful wakes with a nonempty spawned version and either a stateless generation or a mode transition from the route. Ordinary stateful wakes leave rollout status and the wake critical path unchanged.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds a.cancelHeldLegsLocked(e, 0) on the failed-wake path before the entry is deleted, and after close(e.ready) on success calls a.noteHeldAdmissible(e.host), the non-blocking held wake callback, outside a.mu. No read added.;rev3=census-ruling-wake-storm-cap;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): waits for a box-wide wake slot (acquireWakeSlot, an in-memory buffered channel) before doWake; the fence/shutdown/retired/disabled refusals move into refuseWakeLocked and are asked again after admission (one fewer direct whole-Route read here: a.disabled(e.route) now runs inside refuseWakeLocked, same value); e.wakeStart is set at admission and e.admitted marks it. Only waits and refuses more; no new read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Install the successful-acquire observer and restrict due, worker and resident starts before doWake, off a.mu. Add a whole-route argument to restriction; refused work has known-no-start evidence.;rev3=census-ruling-region-ha-g2-fixes;basis=Bind recovery wakes to the service lifetime; no new read.;rev3=census-ruling-edge-page-cache-1;basis=the generation-current call is now noteCurrent(e) instead of noteCurrent(e.host, e.gen.N), so the new noteCurrent can also publish the process's page cache launch inputs; read sites unchanged (16); no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: a failed wake that journalledWakeFailure counts as a real failure is logged through logWakeFailure (rate-limited per host, in memory); a successful wake calls clearWakeFailure. Agent, not root; reads the error already in hand; no read added;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 first commit (#511 F11 log dedupe): before a failed wake's member event, noteHeldWake (in-memory, per host, under the leaf wakeFailMu) tells whether the failure is held by a release attempt with no backoff and is the same (attempt ID, error class) as the host's last one; a repeat writes no event, a first or changed one writes one journal line and the event. Reads only the error in hand; no read site added.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (27d3f501, activator-settle-wait) adds the background counter increment and deferred decrement at entry; this branch (Task 5) keeps its own changes. Both kept as-is; no read added.;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent as carlos: a wakeReturned test seam (nil in production) after doWake; on a failed wake of an entry the write fence marked (e.writeFenced, in memory) e.err wraps ErrHALeaseUnavailable; at the awake transition a marked entry begins the existing StopLeaseLost stop before e.ready closes. Only refuses and stops more; no read added; no kill, no root call.
+
+Seal: `edd68225d4f61e5953ecaa710fe07e8c06c204da88669b00935d60121499562d` → `66404a2fb26ea541e99d9c3d3bd87cb3f2a346eda95cdb7d7838cab2fcd844f5`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-drain-quiesce-1062.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index 4d9f131a2..2c9bf854a 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -2324,6 +2324,7 @@ func (a *Service) wake(e *actEntry) {
a.rememberStopLocked(e.host, outcome)
a.cancelHeldLegsLocked(e, 0)
delete(a.entries, e.host) // next request retries from scratch
+ a.endHARecoveryLocked(e)
} else {
e.state = actAwake
e.sidecar, e.sidecarWanted = w.sidecar, w.sidecarWanted
@@ -5482,6 +5483,7 @@ func (a *Service) finishStop(e *actEntry, outcome *stopObservation) {
republish := e.worker || a.publishesLocked(e)
a.cancelHeldLegsLocked(e, 0)
delete(a.entries, e.host)
+ a.endHARecoveryLocked(e)
// A resident's stop, as it is forgotten (Plan 3 Task 8): a crash or a
// lost lease backs off; any other stop is restarted on the next tick.
a.noteResidentStopLocked(e)
diff --git a/internal/activator/hadrainmove.go b/internal/activator/hadrainmove.go
index 35f679080..54084a6c9 100644
--- a/internal/activator/hadrainmove.go
+++ b/internal/activator/hadrainmove.go
@@ -9,6 +9,7 @@ package activator
import (
"context"
"errors"
+ "path"
"sort"
"time"
@@ -47,24 +48,69 @@ func (q DrainQuiet) Zero() bool { return q == DrainQuiet{} }
// DrainQuietNow counts what is still settling, memory only.
func (a *Service) DrainQuietNow() DrainQuiet {
- owed := len(lease.PendingObligations())
+ q, _ := a.DrainQuietNamed()
+ return q
+}
+
+// DrainQuietHosts names the hosts behind each DrainQuiet count (#1062),
+// sorted, one name per count: a host can appear more than once in Owed
+// (an owed marker and an owed release, say).
+type DrainQuietHosts struct {
+ Waking []string `json:"waking"`
+ Stopping []string `json:"stopping"`
+ Recovering []string `json:"recovering"`
+ // Owed names each release obligation by its host: an owed marker by
+ // its lock's host (the key itself when it is not a lock), then owed
+ // legacy releases, retained failed wakes and open release commands.
+ Owed []string `json:"owed"`
+}
+
+// DrainQuietNamed is DrainQuietNow with the hosts behind each count, read
+// in the same critical section, memory only.
+func (a *Service) DrainQuietNamed() (DrainQuiet, DrainQuietHosts) {
+ obligations := lease.PendingObligations()
+ n := DrainQuietHosts{Waking: []string{}, Stopping: []string{}, Recovering: []string{}, Owed: []string{}}
+ for _, o := range obligations {
+ n.Owed = append(n.Owed, obligationHost(o.Key))
+ }
a.mu.Lock()
- defer a.mu.Unlock()
- q := DrainQuiet{Owed: owed + len(a.unprovenWakes) + len(a.owedReleases) + len(a.releaseOps)}
- for _, e := range a.entries {
+ for host := range a.unprovenWakes {
+ n.Owed = append(n.Owed, host)
+ }
+ for o := range a.owedReleases {
+ n.Owed = append(n.Owed, o.host)
+ }
+ for host := range a.releaseOps {
+ n.Owed = append(n.Owed, host)
+ }
+ for host, e := range a.entries {
switch e.state {
case actWaking:
- q.Waking++
+ n.Waking = append(n.Waking, host)
case actStopping:
- q.Stopping++
+ n.Stopping = append(n.Stopping, host)
}
}
- for _, l := range a.haLoss.hosts {
+ for host, l := range a.haLoss.hosts {
if l.running || l.recovery != nil {
- q.Recovering++
+ n.Recovering = append(n.Recovering, host)
}
}
- return q
+ a.mu.Unlock()
+ for _, s := range [][]string{n.Waking, n.Stopping, n.Recovering, n.Owed} {
+ sort.Strings(s)
+ }
+ q := DrainQuiet{Waking: len(n.Waking), Stopping: len(n.Stopping), Recovering: len(n.Recovering), Owed: len(n.Owed)}
+ return q, n
+}
+
+// obligationHost is the host of an owed marker's lock key
+// (<prefix>/<host>/lock.json, haOwedKey), or the key itself.
+func obligationHost(key string) string {
+ if path.Base(key) == "lock.json" && path.Dir(key) != "." {
+ return path.Base(path.Dir(key))
+ }
+ return key
}
// DrainHost is one awake host the drain must release (§25.4 step 3).
diff --git a/internal/activator/hadrainquiet_test.go b/internal/activator/hadrainquiet_test.go
new file mode 100644
index 000000000..9935e6ccd
--- /dev/null
+++ b/internal/activator/hadrainquiet_test.go
@@ -0,0 +1,168 @@
+package activator
+
+import (
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/edgesfile"
+ "github.com/carlosframework/platform/internal/lease"
+)
+
+// assertRecoveryEnded is #1062's check: once a lost host's recovery entry
+// has left a.entries, nothing is recovering, the drain's Recovering count
+// is zero, and the loss itself is still latched (local wakes refused).
+func assertRecoveryEnded(t *testing.T, s *haSvc) {
+ t.Helper()
+ s.a.mu.Lock()
+ l := s.a.haLoss.hosts[s.rt.Host]
+ var stale bool
+ if l != nil {
+ stale = l.recovery != nil || l.running
+ }
+ s.a.mu.Unlock()
+ if l == nil {
+ t.Fatal("the loss record went with its recovery entry: the loss is discharged")
+ }
+ if stale {
+ t.Fatal("the loss record still names a recovery that has ended")
+ }
+ if q := s.a.DrainQuietNow(); q.Recovering != 0 {
+ t.Fatalf("Recovering = %d after the recovery ended (%+v)", q.Recovering, q)
+ }
+ assertLossLatched(t, s)
+}
+
+// The recovery wakes, then the route is removed (the edge's RetireExcept,
+// as on a route deletion or a trashed app) before the recovery's success
+// check: the recovery entry stops and goes. Field case #1062.
+func TestDrainQuietRecoveryRetiredRouteClears(t *testing.T) {
+ s, e, r := lostTestEntry(t)
+ finishLostTestEntry(t, s, e, r)
+ var recovered *actEntry
+ s.a.wakeEnded = func(host string) {
+ s.a.mu.Lock()
+ recovered = s.a.entries[host]
+ s.a.mu.Unlock()
+ s.a.RetireExcept(map[string]bool{})
+ }
+ s.a.retryHALostHost(s.rt)
+ s.a.haLoss.joined.Wait()
+ if recovered == nil {
+ t.Fatal("recovery did not wake")
+ }
+ s.a.mu.Lock()
+ stopped := recovered.stopped
+ s.a.mu.Unlock()
+ if stopped == nil {
+ t.Fatal("retirement did not stop the recovery entry")
+ }
+ select {
+ case <-stopped:
+ case <-time.After(10 * time.Second):
+ t.Fatal("retired recovery did not stop")
+ }
+ assertRecoveryEnded(t, s)
+ if q := s.a.DrainQuietNow(); !q.Zero() {
+ t.Fatalf("drain never quiesces: %+v", q)
+ }
+ // The loss is still owed a recovery: the next request starts one, and
+ // its healthy fresh acquisition discharges the loss.
+ s.a.wakeEnded = nil
+ clk := &fakeClock{t: time.Now().Add(haLossRetryInterval)}
+ s.a.now = clk.now
+ recoverLostTestHost(t, s)
+ s.a.mu.Lock()
+ left := s.a.haLoss.hosts[s.rt.Host]
+ s.a.mu.Unlock()
+ if left != nil {
+ t.Fatal("a recovered host kept its loss record")
+ }
+}
+
+// The recovery wakes, then fails its post-check (the pool withdrawn): the
+// worker stops it for the lease, and the failed recovery entry goes.
+func TestDrainQuietRecoveryFailedPostCheckClears(t *testing.T) {
+ s, e, r := lostTestEntry(t)
+ finishLostTestEntry(t, s, e, r)
+ var withdrawn atomic.Bool
+ original := s.b.ServedPools
+ s.b.ServedPools = func() edgesfile.PoolEvidence {
+ if withdrawn.Load() {
+ return edgesfile.PoolEvidence(`["another-pool"]`)
+ }
+ return original()
+ }
+ var recovered *actEntry
+ s.a.wakeEnded = func(host string) {
+ s.a.mu.Lock()
+ recovered = s.a.entries[host]
+ s.a.mu.Unlock()
+ withdrawn.Store(true)
+ }
+ s.a.retryHALostHost(s.rt)
+ s.a.haLoss.joined.Wait()
+ if recovered == nil {
+ t.Fatal("recovery did not wake")
+ }
+ s.a.mu.Lock()
+ stopped := recovered.stopped
+ s.a.mu.Unlock()
+ if stopped == nil {
+ t.Fatal("failed post-check left the recovery entry awake")
+ }
+ select {
+ case <-stopped:
+ case <-time.After(10 * time.Second):
+ t.Fatal("failed recovery did not stop")
+ }
+ assertRecoveryEnded(t, s)
+}
+
+// The recovery's wake itself fails (its owed marker cannot settle): the
+// failed wake's entry goes.
+func TestDrainQuietRecoveryFailedWakeClears(t *testing.T) {
+ s, e, r := lostTestEntry(t)
+ s.failMarkerPuts(2) // the release, then the recovery's settlement
+ finishLostTestEntry(t, s, e, r)
+ clk := &fakeClock{t: time.Now()}
+ s.a.now = clk.now
+ s.a.retryHALostHost(s.rt)
+ s.a.haLoss.joined.Wait()
+ s.a.mu.Lock()
+ current := s.a.entries[s.rt.Host]
+ s.a.mu.Unlock()
+ if current != nil {
+ t.Fatalf("failed recovery wake left an entry in state %v", current.state)
+ }
+ if len(lease.PendingObligations()) != 1 {
+ t.Fatal("failed settlement discarded the obligation")
+ }
+ assertRecoveryEnded(t, s)
+}
+
+// DrainQuietNamed names the host behind each count, in step with the
+// counts (#1062): a recovery under way, then an owed marker.
+func TestDrainQuietNamedNamesTheHosts(t *testing.T) {
+ s, e, r := lostTestEntry(t)
+ s.failMarkerPuts(2) // the release, then the recovery's settlement
+ finishLostTestEntry(t, s, e, r)
+ clk := &fakeClock{t: time.Now()}
+ s.a.now = clk.now
+ var during DrainQuietHosts
+ var duringQ DrainQuiet
+ s.a.wakeEnded = func(string) { duringQ, during = s.a.DrainQuietNamed() }
+ s.a.retryHALostHost(s.rt)
+ s.a.haLoss.joined.Wait()
+ host := s.rt.Host
+ if duringQ.Recovering != 1 || len(during.Recovering) != 1 || during.Recovering[0] != host {
+ t.Fatalf("during the recovery: %+v %+v", duringQ, during)
+ }
+ q, n := s.a.DrainQuietNamed()
+ if q != s.a.DrainQuietNow() {
+ t.Fatalf("counts differ: %+v %+v", q, s.a.DrainQuietNow())
+ }
+ if q.Owed != 1 || len(n.Owed) != 1 || n.Owed[0] != host || len(n.Recovering) != 0 || len(n.Waking) != 0 || len(n.Stopping) != 0 {
+ t.Fatalf("after the failed recovery: %+v %+v", q, n)
+ }
+}
diff --git a/internal/activator/haleaseloss.go b/internal/activator/haleaseloss.go
index d3b6c2426..e1410f58b 100644
--- a/internal/activator/haleaseloss.go
+++ b/internal/activator/haleaseloss.go
@@ -85,6 +85,20 @@ func (a *Service) latchHALossLocked(e *actEntry) {
a.pokeMoveLocked(e.host)
}
+// endHARecoveryLocked is e leaving a.entries (a failed wake's cleanup, or
+// finishStop): if e was its loss's recovery entry, that recovery is over
+// (#1062). The loss stays latched, so local wakes are still refused, and
+// the next request starts a new recovery; only a recovery's healthy, newly
+// acquired replica discharges a loss. Left set, l.recovery named a gone
+// entry, so the drain counted it as recovering forever: only a new
+// recovery replaced it, and none starts without demand for a route that
+// is still there and eligible. Under a.mu.
+func (a *Service) endHARecoveryLocked(e *actEntry) {
+ if l := e.haRecovery; l != nil && l.recovery == e {
+ l.recovery = nil
+ }
+}
+
func haUnexpectedLoss(e *actEntry, err error) bool {
return err != nil && (!e.haReleasing || !errors.Is(err, lease.ErrSpent))
}
diff --git a/internal/host/group_maintenance_drain.go b/internal/host/group_maintenance_drain.go
index 8f8e15d1c..24f3f533f 100644
--- a/internal/host/group_maintenance_drain.go
+++ b/internal/host/group_maintenance_drain.go
@@ -213,5 +213,6 @@ func (cmd *groupMaintenanceCommand) handoverStatus(ctx context.Context) (mainten
if s.Step != "" {
ds.Step = &s.Step
}
+ ds.Waiting = s.Waiting
return fs, ds
}
diff --git a/internal/host/group_maintenance_verbs.go b/internal/host/group_maintenance_verbs.go
index 173785bd0..7497409f6 100644
--- a/internal/host/group_maintenance_verbs.go
+++ b/internal/host/group_maintenance_verbs.go
@@ -284,6 +284,9 @@ type maintenanceDrainStatus struct {
Step *string `json:"step"`
Result *string `json:"result"`
Error *string `json:"error"`
+ // Waiting is what the agent's move step waits on to settle, or gave
+ // up waiting on, by host (#1062); null when it is not waiting.
+ Waiting *drainWaiting `json:"waiting"`
}
type maintenanceProcessStatus struct {
State string `json:"state"`
diff --git a/internal/host/hadrain.go b/internal/host/hadrain.go
index 701404fd0..38247d378 100644
--- a/internal/host/hadrain.go
+++ b/internal/host/hadrain.go
@@ -28,11 +28,15 @@ import (
"context"
"crypto/rand"
"encoding/hex"
+ "encoding/json"
"errors"
"fmt"
+ "log"
"sort"
+ "strings"
"sync"
"time"
+ "unicode/utf8"
"github.com/carlosframework/platform/internal/activator"
"github.com/carlosframework/platform/internal/boxchoice"
@@ -42,14 +46,19 @@ import (
// The drain's bounds (§25.4).
var (
- drainAckEvery = 5 * time.Second
- drainAckBound = 2 * time.Minute
- drainInflightBound = 10 * time.Second
- drainConnBound = 60 * time.Second
- drainTakeBound = 40 * time.Second
- drainDeadlineBase = 15 * time.Minute
- drainDeadlinePer20 = time.Minute
- drainQuietPoll = 100 * time.Millisecond
+ drainAckEvery = 5 * time.Second
+ drainAckBound = 2 * time.Minute
+ drainInflightBound = 10 * time.Second
+ drainConnBound = 60 * time.Second
+ drainTakeBound = 40 * time.Second
+ drainDeadlineBase = 15 * time.Minute
+ drainDeadlinePer20 = time.Minute
+ drainQuietPoll = 100 * time.Millisecond
+ // drainQuietBound is how long quiesce and settle wait for the box to
+ // settle before the move gives up (#1062), well inside the verb's own
+ // timeout, and drainQuietLogEvery how often they say what they wait on.
+ drainQuietBound = 5 * time.Minute
+ drainQuietLogEvery = time.Minute
drainMovesAtOnce = 4
drainPublishTimeout = 2 * time.Minute
)
@@ -76,6 +85,7 @@ func drainDeadline(awake int) time.Duration {
// and handover.go).
type drainActivator interface {
DrainQuietNow() activator.DrainQuiet
+ DrainQuietNamed() (activator.DrainQuiet, activator.DrainQuietHosts)
DrainHosts() []activator.DrainHost
DrainHeld() []string
BeginMove(host string) error
@@ -187,6 +197,10 @@ type drainDriver struct {
marks drainMarks
fence func() fenceState
now func() time.Time
+ // quietTick is the quiesce and settle poll (a ticker, and its stop),
+ // and logf their log: seams for tests.
+ quietTick func() (<-chan time.Time, func())
+ logf func(format string, args ...any)
mu sync.Mutex
// txn is the drain transaction this agent is in, "" for none.
@@ -199,6 +213,9 @@ type drainDriver struct {
withdrawn bool
// cancelling is set while cancel joins and clears: no step starts.
cancelling bool
+ // waiting is what quiesce or settle waits on, while it waits and after
+ // it gave up; nil once the box settled (#1062).
+ waiting *drainWaiting
}
type drainRun struct {
@@ -220,7 +237,11 @@ var (
)
func newDrainDriver(act drainActivator, e drainEdge, marks drainMarks, fence func() fenceState) *drainDriver {
- return &drainDriver{act: act, edge: e, marks: marks, fence: fence, now: time.Now}
+ return &drainDriver{act: act, edge: e, marks: marks, fence: fence, now: time.Now, logf: log.Printf,
+ quietTick: func() (<-chan time.Time, func()) {
+ t := time.NewTicker(drainQuietPoll)
+ return t.C, t.Stop
+ }}
}
// start runs step for txn, or joins the same step already running, and
@@ -286,7 +307,7 @@ func (d *drainDriver) start(txn, step string, peers []string) (<-chan struct{},
r := &drainRun{step: step, peers: append([]string{}, peers...), cancel: cancel, done: make(chan struct{})}
rep := &drainReport{V: 1, Transaction: txn, Incarnation: agentIncarnation, Step: step, Result: "running", StartedAt: now,
Reasons: []string{}, Acked: []string{}, Moved: []drainMoved{}, Released: []drainLeft{}, Unclean: []string{}, Left: []drainLeft{}}
- d.run, d.report = r, rep
+ d.run, d.report, d.waiting = r, rep, nil
go func() {
defer close(r.done)
defer cancel()
@@ -378,7 +399,7 @@ func (d *drainDriver) cancel(ctx context.Context, txn string) error {
d.edge.EndConnectionDrain()
d.marks.clear()
d.mu.Lock()
- d.txn, d.run, d.report, d.withdrawn, d.deadline = "", nil, nil, false, time.Time{}
+ d.txn, d.run, d.report, d.withdrawn, d.deadline, d.waiting = "", nil, nil, false, time.Time{}, nil
d.mu.Unlock()
return nil
}
@@ -391,12 +412,136 @@ type drainStatus struct {
Step string `json:"step"`
Result string `json:"result"`
Reasons int `json:"reasons"`
+ // Waiting is what the move's quiesce or settle step waits on, or gave
+ // up waiting on (#1062); absent when it is not waiting.
+ Waiting *drainWaiting `json:"waiting,omitempty"`
+}
+
+// drainWaiting is what quiesce or settle is waiting on (#1062): the
+// counts, and the hosts behind each, at most drainNamesMax per count.
+type drainWaiting struct {
+ // Step is "quiesce" (before the moves) or "settle" (after them).
+ Step string `json:"step"`
+ Since time.Time `json:"since"`
+ // GaveUp is set once the wait passed drainQuietBound and the move
+ // failed.
+ GaveUp bool `json:"gave_up"`
+ Quiet activator.DrainQuiet `json:"quiet"`
+ Hosts activator.DrainQuietHosts `json:"hosts"`
+ // Held is settle's entries still here, by host.
+ Held []string `json:"held"`
+ HeldCount int `json:"held_count"`
+ // Truncated is set when a name was cut short or left out to keep the
+ // block within drainWaitingMaxBytes; the counts are always whole.
+ Truncated bool `json:"truncated"`
+}
+
+// drainNamesMax is how many hosts the log, the refusal and the status
+// name per count; the counts themselves are whole. drainNameMaxBytes
+// bounds each name (an owed key that is not a lock's is named whole), and
+// drainWaitingMaxBytes the waiting block's JSON, well inside the status
+// verb's 8192-byte answer.
+const (
+ drainNamesMax = 3
+ drainNameMaxBytes = 128
+ drainWaitingMaxBytes = 2048
+ // draft for copy review (D1062-5)
+ drainNameCut = "(cut)"
+)
+
+// firstNames is the first drainNamesMax names, each cut at
+// drainNameMaxBytes (on a rune boundary, marked drainNameCut).
+func firstNames(names []string, cut *bool) []string {
+ if len(names) > drainNamesMax {
+ names = names[:drainNamesMax]
+ }
+ out := make([]string, 0, len(names))
+ for _, n := range names {
+ if len(n) > drainNameMaxBytes {
+ i := drainNameMaxBytes
+ for i > 0 && !utf8.RuneStart(n[i]) {
+ i--
+ }
+ n = n[:i] + drainNameCut
+ *cut = true
+ }
+ out = append(out, n)
+ }
+ return out
+}
+
+// newDrainWaiting is the projection the log, the refusal and the status
+// share: at most drainNamesMax names per count, each bounded, and names
+// dropped from the last count first until the encoded block fits
+// drainWaitingMaxBytes. The counts stay whole.
+func newDrainWaiting(step string, since time.Time, q activator.DrainQuiet, names activator.DrainQuietHosts, held []string) *drainWaiting {
+ w := &drainWaiting{Step: step, Since: since, Quiet: q, HeldCount: len(held)}
+ w.Held = firstNames(held, &w.Truncated)
+ w.Hosts = activator.DrainQuietHosts{Waking: firstNames(names.Waking, &w.Truncated), Stopping: firstNames(names.Stopping, &w.Truncated),
+ Recovering: firstNames(names.Recovering, &w.Truncated), Owed: firstNames(names.Owed, &w.Truncated)}
+ lists := []*[]string{&w.Held, &w.Hosts.Waking, &w.Hosts.Stopping, &w.Hosts.Recovering, &w.Hosts.Owed}
+ for {
+ b, err := json.Marshal(w)
+ if err == nil && len(b) <= drainWaitingMaxBytes {
+ return w
+ }
+ dropped := false
+ for i := len(lists) - 1; i >= 0; i-- {
+ if l := lists[i]; len(*l) > 0 {
+ *l = (*l)[:len(*l)-1]
+ dropped = true
+ break
+ }
+ }
+ w.Truncated = true
+ if !dropped {
+ return w
+ }
+ }
+}
+
+// describe is the waiting counts that are not zero, each with its hosts:
+// "recovering 1 (shop.example.com); owed 2 (a.example.com, b.example.com)".
+func (w *drainWaiting) describe() string {
+ var parts []string
+ add := func(name string, n int, hosts []string) {
+ if n == 0 {
+ return
+ }
+ named := strings.Join(hosts, ", ")
+ if more := n - len(hosts); more > 0 && len(hosts) > 0 {
+ // draft for copy review (D1062-3)
+ named = fmt.Sprintf("%s and %d more", named, more)
+ }
+ if named == "" {
+ parts = append(parts, fmt.Sprintf("%s %d", name, n))
+ return
+ }
+ parts = append(parts, fmt.Sprintf("%s %d (%s)", name, n, named))
+ }
+ add("held", w.HeldCount, w.Held)
+ add("waking", w.Quiet.Waking, w.Hosts.Waking)
+ add("stopping", w.Quiet.Stopping, w.Hosts.Stopping)
+ add("recovering", w.Quiet.Recovering, w.Hosts.Recovering)
+ add("owed", w.Quiet.Owed, w.Hosts.Owed)
+ return strings.Join(parts, "; ")
+}
+
+func (w *drainWaiting) copy() *drainWaiting {
+ if w == nil {
+ return nil
+ }
+ c := *w
+ c.Held = append([]string{}, w.Held...)
+ c.Hosts = activator.DrainQuietHosts{Waking: append([]string{}, w.Hosts.Waking...), Stopping: append([]string{}, w.Hosts.Stopping...),
+ Recovering: append([]string{}, w.Hosts.Recovering...), Owed: append([]string{}, w.Hosts.Owed...)}
+ return &c
}
func (d *drainDriver) status() drainStatus {
d.mu.Lock()
defer d.mu.Unlock()
- s := drainStatus{Incarnation: agentIncarnation, Transaction: d.txn, Result: "none"}
+ s := drainStatus{Incarnation: agentIncarnation, Transaction: d.txn, Result: "none", Waiting: d.waiting.copy()}
if d.report != nil {
s.Step, s.Result, s.Reasons = d.report.Step, d.report.Result, len(d.report.Reasons)
}
@@ -693,35 +838,64 @@ func (d *drainDriver) releaseOne(ctx context.Context, h activator.DrainHost, rep
// quiesce waits, memory only, until nothing is settling: wakes restoring,
// acquires on their PUT, recoveries, pending stops and owed markers.
func (d *drainDriver) quiesce(ctx context.Context) error {
- t := time.NewTicker(drainQuietPoll)
- defer t.Stop()
- for {
- q := d.act.DrainQuietNow()
- if q.Zero() {
- return nil
- }
- select {
- case <-ctx.Done():
- return fmt.Errorf("%w: %+v", ctx.Err(), q)
- case <-t.C:
- }
- }
+ return d.waitQuiet(ctx, "quiesce", false)
}
// settle waits, memory only, until no entry is held here and nothing is
// settling.
func (d *drainDriver) settle(ctx context.Context) error {
- t := time.NewTicker(drainQuietPoll)
- defer t.Stop()
+ return d.waitQuiet(ctx, "settle", true)
+}
+
+// errDrainQuietBound is a quiesce or settle that gave up at
+// drainQuietBound (#1062).
+var errDrainQuietBound = errors.New("gave up waiting")
+
+// waitQuiet is quiesce (held false) and settle (held true). While the box
+// is not quiet it logs, once a minute, what it waits on and for which
+// hosts, and keeps that for the status op; at drainQuietBound it gives up,
+// naming the counts that did not clear and their hosts, and the move
+// fails as any failed move does (#1062).
+func (d *drainDriver) waitQuiet(ctx context.Context, step string, held bool) error {
+ tick, stop := d.quietTick()
+ defer stop()
+ start := d.now()
+ logged := start
for {
- held, q := d.act.DrainHeld(), d.act.DrainQuietNow()
- if len(held) == 0 && q.Zero() {
+ var h []string
+ if held {
+ h = d.act.DrainHeld()
+ }
+ q, names := d.act.DrainQuietNamed()
+ if len(h) == 0 && q.Zero() {
+ d.note(func() { d.waiting = nil })
return nil
}
+ w := newDrainWaiting(step, start, q, names, h)
+ now := d.now()
+ waited := now.Sub(start)
+ if waited >= drainQuietBound {
+ w.GaveUp = true
+ d.note(func() { d.waiting = w })
+ // draft for copy review (D1062-2)
+ err := fmt.Errorf("%w after %s: %s", errDrainQuietBound, drainQuietBound, w.describe())
+ // draft for copy review (D1062-4)
+ d.logf("agent: drain %s: %v", step, err)
+ return err
+ }
+ d.note(func() { d.waiting = w })
+ if now.Sub(logged) >= drainQuietLogEvery {
+ logged = now
+ // draft for copy review (D1062-1)
+ d.logf("agent: drain %s: waiting %s for the box to settle: %s", step, waited.Round(time.Second), w.describe())
+ }
select {
case <-ctx.Done():
- return fmt.Errorf("%w: held %v, %+v", ctx.Err(), held, q)
- case <-t.C:
+ if held {
+ return fmt.Errorf("%w: held %v, %+v", ctx.Err(), h, q)
+ }
+ return fmt.Errorf("%w: %+v", ctx.Err(), q)
+ case <-tick:
}
}
}
diff --git a/internal/host/hadrain_quiet_linux_test.go b/internal/host/hadrain_quiet_linux_test.go
new file mode 100644
index 000000000..973e270d9
--- /dev/null
+++ b/internal/host/hadrain_quiet_linux_test.go
@@ -0,0 +1,111 @@
+package host
+
+import (
+ "encoding/json"
+ "errors"
+ "slices"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/activator"
+)
+
+// The verb's side of #1062: a box whose recovery never clears fails the
+// move at the bound, so the drain verb returns at once with the failed
+// report naming the host; group-maintenance status names it too, under
+// drain.waiting; and drain --cancel ends the drain.
+func TestDrainVerbQuiesceGivesUpAndStatusNamesTheHosts(t *testing.T) {
+ act, ed, marks := healthyDrain()
+ d, clk, _ := quietDriver(act, ed, marks)
+ act.quiet = func() activator.DrainQuiet {
+ clk.poll()
+ return activator.DrainQuiet{Recovering: 1}
+ }
+ act.named = func() activator.DrainQuietHosts {
+ return activator.DrainQuietHosts{Recovering: []string{"lost.example.com"}}
+ }
+ cmd, l := verbDrain(t, d)
+ d.fence = l.read
+ rep, err := runDrainVerb(t, cmd, "drain", "t1")
+ if !errors.Is(err, errDrainFailed) || rep == nil || rep.Result != "failed" || !strings.Contains(strings.Join(rep.Reasons, ";"), "recovering 1 (lost.example.com)") {
+ t.Fatalf("drain: %+v %v", rep, err)
+ }
+ out, err := runMaintenanceVerb(cmd, "status", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var st groupMaintenanceStatus
+ must(t, json.Unmarshal(out, &st))
+ w := st.Drain.Waiting
+ if st.Drain.State != "known" || *st.Drain.Result != "failed" || w == nil || w.Step != "quiesce" || !w.GaveUp || w.Quiet.Recovering != 1 || !slices.Equal(w.Hosts.Recovering, []string{"lost.example.com"}) {
+ t.Fatalf("status: %s", out)
+ }
+ if _, err := runDrainVerb(t, cmd, "drain-cancel", "t1"); err != nil {
+ t.Fatal(err)
+ }
+ out, err = runMaintenanceVerb(cmd, "status", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ st = groupMaintenanceStatus{}
+ must(t, json.Unmarshal(out, &st))
+ if st.Drain.Waiting != nil || l.read().Present {
+ t.Fatalf("status after cancel: %s", out)
+ }
+}
+
+// Astra's P2 on #1062: names are not bounded by their count alone. Owed
+// keys that are not a lock's are named whole, and a 500-byte key of '<'
+// encodes to 3000 bytes; with every count full of them the status verb's
+// whole answer still fits its 8192 bytes, the counts stay exact, the
+// truncation is marked, and the refusal still names the counter.
+func TestDrainVerbStatusBoundsHostileNames(t *testing.T) {
+ hostile := func(c byte) []string {
+ var out []string
+ for i := range 5 {
+ out = append(out, strings.Repeat("<", 500)+string(rune('a'+i))+string(c))
+ }
+ return out
+ }
+ act, ed, marks := healthyDrain()
+ d, clk, _ := quietDriver(act, ed, marks)
+ act.quiet = func() activator.DrainQuiet {
+ clk.poll()
+ return activator.DrainQuiet{Waking: 5, Stopping: 5, Recovering: 5, Owed: 5}
+ }
+ act.named = func() activator.DrainQuietHosts {
+ return activator.DrainQuietHosts{Waking: hostile('w'), Stopping: hostile('s'), Recovering: hostile('r'), Owed: hostile('o')}
+ }
+ cmd, l := verbDrain(t, d)
+ d.fence = l.read
+ rep, err := runDrainVerb(t, cmd, "drain", "t1")
+ if !errors.Is(err, errDrainFailed) || rep == nil || !strings.Contains(strings.Join(rep.Reasons, ";"), "recovering 5") {
+ t.Fatalf("drain: %+v %v", rep, err)
+ }
+ out, err := runMaintenanceVerb(cmd, "status", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(out) > 8192 {
+ t.Fatalf("status is %d bytes", len(out))
+ }
+ var st groupMaintenanceStatus
+ must(t, json.Unmarshal(out, &st))
+ w := st.Drain.Waiting
+ if w == nil || !w.GaveUp || !w.Truncated || w.Quiet != (activator.DrainQuiet{Waking: 5, Stopping: 5, Recovering: 5, Owed: 5}) {
+ t.Fatalf("status: %s", out)
+ }
+ for _, names := range [][]string{w.Hosts.Waking, w.Hosts.Stopping, w.Hosts.Recovering, w.Hosts.Owed} {
+ for _, n := range names {
+ if len(n) > drainNameMaxBytes+len(drainNameCut) || !strings.HasSuffix(n, drainNameCut) {
+ t.Fatalf("name not cut: %d bytes", len(n))
+ }
+ }
+ }
+ if len(w.Hosts.Waking) == 0 {
+ t.Fatal("the budget dropped every name, the first count's too")
+ }
+ if got := w.describe(); !strings.Contains(got, "recovering 5") || !strings.Contains(got, "owed 5") {
+ t.Fatalf("describe %q", got)
+ }
+}
diff --git a/internal/host/hadrain_quiet_test.go b/internal/host/hadrain_quiet_test.go
new file mode 100644
index 000000000..b2c0e9849
--- /dev/null
+++ b/internal/host/hadrain_quiet_test.go
@@ -0,0 +1,222 @@
+package host
+
+import (
+ "context"
+ "fmt"
+ "slices"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/activator"
+)
+
+// quietClock is the drain's clock for #1062's witnesses: each poll of the
+// activator moves it on by step, so the waits are counted in polls, with
+// no real time and no goroutine to keep in step.
+type quietClock struct {
+ mu sync.Mutex
+ t time.Time
+ step time.Duration
+}
+
+func (c *quietClock) now() time.Time {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ return c.t
+}
+
+func (c *quietClock) poll() {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.t = c.t.Add(c.step)
+}
+
+// drainLogLines collects the driver's log lines.
+type drainLogLines struct {
+ mu sync.Mutex
+ lines []string
+}
+
+func (l *drainLogLines) logf(format string, args ...any) {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ l.lines = append(l.lines, fmt.Sprintf(format, args...))
+}
+
+func (l *drainLogLines) all() []string {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ return append([]string(nil), l.lines...)
+}
+
+// quietDriver is a drain driver on the fakes whose poll never waits (a
+// closed tick), whose clock moves 20 s per poll, and whose log is kept.
+func quietDriver(act *fakeDrainAct, ed *fakeDrainEdge, marks *fakeMarks) (*drainDriver, *quietClock, *drainLogLines) {
+ clk := &quietClock{t: time.Now(), step: 20 * time.Second}
+ logs := &drainLogLines{}
+ d := newDrainDriver(act, ed, marks, fenceOf("t1"))
+ d.now = clk.now
+ d.logf = logs.logf
+ tick := make(chan time.Time)
+ close(tick)
+ d.quietTick = func() (<-chan time.Time, func()) { return tick, func() {} }
+ return d, clk, logs
+}
+
+// A recovery that never clears (#1062's field case): quiesce says once a
+// minute what it waits on and for which host, gives up at
+// drainQuietBound naming the count and the host, and the move fails as
+// any failed move does: no move began, nothing published drained, the
+// status op names the host, and drain --cancel ends it at once.
+func TestDrainQuiesceGivesUpNamingTheHosts(t *testing.T) {
+ if drainQuietBound != 5*time.Minute || drainQuietLogEvery != time.Minute {
+ t.Fatalf("bounds %v %v, want 5m and 1m", drainQuietBound, drainQuietLogEvery)
+ }
+ act, ed, marks := healthyDrain()
+ d, clk, logs := quietDriver(act, ed, marks)
+ act.quiet = func() activator.DrainQuiet {
+ clk.poll()
+ return activator.DrainQuiet{Recovering: 1}
+ }
+ act.named = func() activator.DrainQuietHosts {
+ return activator.DrainQuietHosts{Recovering: []string{"lost.example.com"}}
+ }
+ rep := runDrain(t, d, "t1")
+ want := "the box did not settle: gave up waiting after 5m0s: recovering 1 (lost.example.com)"
+ if rep.Result != "failed" || !slices.Equal(rep.Reasons, []string{want}) {
+ t.Fatalf("report %+v", rep)
+ }
+ act.mu.Lock()
+ begun := len(act.begun)
+ act.mu.Unlock()
+ if _, drained, _ := marks.counts(); begun != 0 || drained != 0 || indexOf(act.rec.events(), "stop ") >= 0 {
+ t.Fatal("a move began, or drained was published, on a box that never settled")
+ }
+ lines := logs.all()
+ var waiting, gaveUp int
+ for _, l := range lines {
+ switch {
+ case strings.HasPrefix(l, "agent: drain quiesce: waiting ") && strings.HasSuffix(l, "for the box to settle: recovering 1 (lost.example.com)"):
+ waiting++
+ case l == "agent: drain quiesce: "+strings.TrimPrefix(want, "the box did not settle: "):
+ gaveUp++
+ default:
+ t.Errorf("unexpected log line %q", l)
+ }
+ }
+ // One line a minute until the bound: at 1, 2, 3 and 4 minutes.
+ if waiting != 4 || gaveUp != 1 {
+ t.Fatalf("log lines %q", lines)
+ }
+ st := d.status()
+ if w := st.Waiting; w == nil || w.Step != "quiesce" || !w.GaveUp || w.Quiet.Recovering != 1 || !slices.Equal(w.Hosts.Recovering, []string{"lost.example.com"}) {
+ t.Fatalf("status %+v waiting %+v", st, st.Waiting)
+ }
+ if st.Result != "failed" || st.Step != "move" || st.Reasons != 1 {
+ t.Fatalf("status %+v", st)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+ if err := d.cancel(ctx, "t1"); err != nil {
+ t.Fatal(err)
+ }
+ if st := d.status(); st.Waiting != nil || st.Result != "none" {
+ t.Fatalf("status after cancel %+v", st)
+ }
+}
+
+// While it waits, the status op names what quiesce waits on; a box that
+// settles inside the bound moves as before, logging nothing, and the
+// status op then names nothing.
+func TestDrainQuiesceStatusWhileWaiting(t *testing.T) {
+ act, ed, marks := healthyDrain()
+ d, clk, logs := quietDriver(act, ed, marks)
+ release := make(chan struct{})
+ seen := make(chan drainStatus, 1)
+ polls := 0
+ act.quiet = func() activator.DrainQuiet {
+ select {
+ case <-release:
+ return activator.DrainQuiet{}
+ default:
+ }
+ clk.poll()
+ polls++
+ if polls == 2 {
+ // The first poll's answer is the status now (a poll later, so
+ // the driver has recorded it).
+ seen <- d.status()
+ close(release)
+ }
+ return activator.DrainQuiet{Waking: 1, Owed: 2}
+ }
+ act.named = func() activator.DrainQuietHosts {
+ return activator.DrainQuietHosts{Waking: []string{"wake.example.com"}, Owed: []string{"a.example.com", "b.example.com"}}
+ }
+ rep := runDrain(t, d, "t1")
+ if rep.Result != "ok" || len(rep.Moved) != 2 {
+ t.Fatalf("report %+v", rep)
+ }
+ st := <-seen
+ w := st.Waiting
+ if w == nil || w.Step != "quiesce" || w.GaveUp || w.Quiet.Waking != 1 || w.Quiet.Owed != 2 ||
+ !slices.Equal(w.Hosts.Waking, []string{"wake.example.com"}) || !slices.Equal(w.Hosts.Owed, []string{"a.example.com", "b.example.com"}) {
+ t.Fatalf("status while waiting %+v", w)
+ }
+ if got := w.describe(); got != "waking 1 (wake.example.com); owed 2 (a.example.com, b.example.com)" {
+ t.Fatalf("describe %q", got)
+ }
+ if lines := logs.all(); len(lines) != 0 {
+ t.Fatalf("a short wait logged %q", lines)
+ }
+ if st := d.status(); st.Waiting != nil {
+ t.Fatalf("status after the box settled %+v", st.Waiting)
+ }
+}
+
+// settle, after the moves, has the same bound: an entry that stays held
+// fails the move at drainQuietBound, naming it, long before the drain
+// deadline; at most drainNamesMax hosts are named per count.
+func TestDrainSettleGivesUpNamingTheHosts(t *testing.T) {
+ act, ed, marks := healthyDrain()
+ d, clk, logs := quietDriver(act, ed, marks)
+ var moved bool
+ act.stop = func(ctx context.Context, host string) (activator.DrainRelease, error) {
+ act.mu.Lock()
+ act.awake[host] = false
+ if host == "busy.example.com" {
+ for _, h := range []string{"late1.example.com", "late2.example.com", "late3.example.com", "late4.example.com"} {
+ act.awake[h] = true
+ }
+ }
+ moved = true
+ act.mu.Unlock()
+ return activator.DrainRelease{HA: true, Marker: true, Clean: true}, nil
+ }
+ act.quiet = func() activator.DrainQuiet {
+ act.mu.Lock()
+ after := moved
+ act.mu.Unlock()
+ if !after {
+ return activator.DrainQuiet{}
+ }
+ clk.poll()
+ return activator.DrainQuiet{Stopping: 1}
+ }
+ act.named = func() activator.DrainQuietHosts {
+ return activator.DrainQuietHosts{Stopping: []string{"late1.example.com"}}
+ }
+ rep := runDrain(t, d, "t1")
+ want := "the box did not settle after the moves: gave up waiting after 5m0s: held 4 (late1.example.com, late2.example.com, late3.example.com and 1 more); stopping 1 (late1.example.com)"
+ if _, drained, _ := marks.counts(); rep.Result != "failed" || drained != 0 || !slices.Equal(rep.Reasons, []string{want}) {
+ t.Fatalf("report %+v", rep)
+ }
+ if w := d.status().Waiting; w == nil || w.Step != "settle" || !w.GaveUp || w.HeldCount != 4 || len(w.Held) != drainNamesMax {
+ t.Fatalf("status %+v", w)
+ }
+ if len(logs.all()) != 5 {
+ t.Fatalf("log lines %q", logs.all())
+ }
+}
diff --git a/internal/host/hadrain_test.go b/internal/host/hadrain_test.go
index 2a624eb52..df4dd9ae5 100644
--- a/internal/host/hadrain_test.go
+++ b/internal/host/hadrain_test.go
@@ -48,6 +48,7 @@ func (r *recorder) events() []string {
type fakeDrainAct struct {
rec *recorder
quiet func() activator.DrainQuiet
+ named func() activator.DrainQuietHosts
stop func(ctx context.Context, host string) (activator.DrainRelease, error)
owner func(rt registry.Route) (string, int64, bool)
@@ -83,6 +84,13 @@ func (f *fakeDrainAct) DrainQuietNow() activator.DrainQuiet {
}
return f.quiet()
}
+func (f *fakeDrainAct) DrainQuietNamed() (activator.DrainQuiet, activator.DrainQuietHosts) {
+ q := f.DrainQuietNow()
+ if f.named == nil {
+ return q, activator.DrainQuietHosts{}
+ }
+ return q, f.named()
+}
func (f *fakeDrainAct) quietCalls() int {
f.mu.Lock()
defer f.mu.Unlock()
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 8f9274c4c..f9120cc2e 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -220,3 +220,4 @@ plan14-root-reads-fleet-record-labels-m1.tsv 5603979dfa1a34a1b30784d1f9252f20b0e
plan14-root-reads-fleet-record-labels-m2.tsv 5603979dfa1a34a1b30784d1f9252f20b0ed95c114bde54e8b173f9262fe8f46
plan14-root-reads-services-secret-scripts-1056.tsv 183a9ccd8e8bd29ba677833142ec79bf4a9055b6a39e8da2bf4baa1616793da2
plan14-root-reads-platform-mail-submission.tsv edd68225d4f61e5953ecaa710fe07e8c06c204da88669b00935d60121499562d
+plan14-root-reads-drain-quiesce-1062.tsv 66404a2fb26ea541e99d9c3d3bd87cb3f2a346eda95cdb7d7838cab2fcd844f5
diff --git a/internal/provision/testdata/plan14-root-reads-drain-quiesce-1062.tsv b/internal/provision/testdata/plan14-root-reads-drain-quiesce-1062.tsv
new file mode 100644
index 000000000..ce0abca4d
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-drain-quiesce-1062.tsv
@@ -0,0 +1,8 @@
+# Census overlay drain-quiesce-1062, written by census-propose (#369). census-ruling-drain-quiesce-1062, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-drain-quiesce-1062.md.
+# 2 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy 81ed3b1b4daddd53ba77a6a99bf53007c14525e73f383648ac89a7f288fe6530 internal/activator/activator.go Service.finishStop legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with a run's settle checked before replication closes, which keeps the stop pending until the run is proven stopped; read sites unchanged, offsets moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: an HA entry (its replica is an HA one, haEntryRep) now releases through releaseHAClean (a new unit on this card) instead of e.rep.Close; when that answers errHostSliceUnproven the stop is kept pending (keepPendingLocked) with the lease held and renewing, and the sweep finishes it once proven; a non-HA entry is unchanged; the same five sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: a forgotten entry's stop is noted for its resident (noteResidentStopLocked: crash or lost lease backs off, any other stop restarts on the next tick) and its ownerDone channel is closed; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: while the host has a release command's record (a.releaseOps[e.host], running or not proven stopped), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the record's proof; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.20: while a rootfs worker may run or is a stray (rootfsWorkersLiveLocked, in-memory, read under a.mu), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the workers are proven stopped; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1 (Astra P1): beside the worker check, under the same lock, a stop with a lease stop of its commands outstanding (e.leaseStops) is kept pending, the replica and lease held, and the sweep finishes it once they have returned; the entry is never released while a kill captured for it may still reach its unit; the same five read sites, no read added Task 9 (PF-3): the count is pendingLeaseStopsLocked(e), the sum of e.leaseStops over both one-shot roles (now a map per role, cmd and tty), so a session's lease stop of the tty unit keeps the stop pending, the replica and lease held, as a run's does; the same five read sites, no read added;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Retain command, worker, release and cgroup proofs. For an actual stateless generation no replica needs closing; close local lifecycle ownership only once those proofs finish.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds a.cancelHeldLegsLocked(e, 0) under a.mu just before the entry is deleted; it only calls the legs' context cancel functions. No read added, none removed.;rev3=census-ruling-region-ha-g2-fixes;basis=Latch HA loss if release leaves an obligation; stopping proofs still precede entry removal; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5 fix 1: records the finished stop's release outcome (marker written, clean) in the drain transaction's in-memory release log while a drain records (noteDrainReleaseLocked); memory only; no read added;rev3=census-ruling-fleet-record-labels-m1;basis=fleet record labels R2: a non-HA replica of a fleet-placed row releases through closeFleetCheckpoint (CloseProven) instead of Close; an unproven final checkpoint keeps the stop pending (keepPendingLocked) with the lease held and renewing, or ends unclean without a release over a lost lease (ErrCheckpointAbandoned); at Shutdown it is only named (C45) and the lease runs to its TTL; never releases over an unproven checkpoint; platform-region rows unchanged; the same five read sites, no read added;rev3=census-ruling-drain-quiesce-1062;basis=#1062: before deleting the entry, calls endHARecoveryLocked(e) (in-memory, under a.mu), which clears a lost host's l.recovery when e was its recovery entry; the loss stays latched; read sites unchanged, no read added registry:Socket@4908,registry:Socket@5013,whole:Route@4858,whole:Route@4910,whole:Route@5015 aa710c395b18608c65414b72f90d479c62a4b8aba1f20d72433665094e8295af
+@legacy 542c28d2bb0e742576cf1c005fe584000406a05322177a694bdb27b14d8666bd internal/activator/activator.go Service.wake legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body; the stop now carries its reason for a run it interrupts (beginStopLocked's why argument); read sites unchanged, offsets moved;rev3=census-ruling-wake-latency-1;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=logs that timer's breakdown to the journal after a successful wake (w.steps.String(), e.host, w.wakeTook); no read added;rev3=census-ruling-plans-4d-lapse;basis=cancels a wake whose row the turned-off hook names, like a fence, unless it is a move's active probe (plans 4d). One more whole-row read: the row handed to the hook (a.disabled). Only refuses.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: a refusal before the lease is reported once per change (noteRootfsRefusal) instead of a wake-failure event; the proc, generation and replica are installed through installProcLocked (which puts a resident under its lease watch before the fence); residency notes the outcome (noteResidentWakeLocked); same generation values;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R [pf R3.5]: the wake's context ceiling is wakeCeilingFor(e.route): the old 5 minutes for a binary row, 5 minutes plus runs.MaxTimeout for a rootfs row (room for a release inside the wake); new site +whole:Route (e.route to wakeCeilingFor, which reads Runtime only); no other change;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (branch review R1 P1-1): the wake's context is also cancelled before doWake when RetireExcept has marked the entry retired (e.retired, in memory under a.mu), as it is for a fence or a shutdown. Read sites unchanged (13). Agent, not root; it only refuses more.;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Carry successful hold preparation into its wake, preserve actual mode in the generation and OnWake projection, and project serving version/mode through the narrow registry writer before releasing wake waiters. Final review I1: SetServingMode only for non-worker successful wakes with a nonempty spawned version and either a stateless generation or a mode transition from the route. Ordinary stateful wakes leave rollout status and the wake critical path unchanged.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds a.cancelHeldLegsLocked(e, 0) on the failed-wake path before the entry is deleted, and after close(e.ready) on success calls a.noteHeldAdmissible(e.host), the non-blocking held wake callback, outside a.mu. No read added.;rev3=census-ruling-wake-storm-cap;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): waits for a box-wide wake slot (acquireWakeSlot, an in-memory buffered channel) before doWake; the fence/shutdown/retired/disabled refusals move into refuseWakeLocked and are asked again after admission (one fewer direct whole-Route read here: a.disabled(e.route) now runs inside refuseWakeLocked, same value); e.wakeStart is set at admission and e.admitted marks it. Only waits and refuses more; no new read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Install the successful-acquire observer and restrict due, worker and resident starts before doWake, off a.mu. Add a whole-route argument to restriction; refused work has known-no-start evidence.;rev3=census-ruling-region-ha-g2-fixes;basis=Bind recovery wakes to the service lifetime; no new read.;rev3=census-ruling-edge-page-cache-1;basis=the generation-current call is now noteCurrent(e) instead of noteCurrent(e.host, e.gen.N), so the new noteCurrent can also publish the process's page cache launch inputs; read sites unchanged (16); no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: a failed wake that journalledWakeFailure counts as a real failure is logged through logWakeFailure (rate-limited per host, in memory); a successful wake calls clearWakeFailure. Agent, not root; reads the error already in hand; no read added;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 first commit (#511 F11 log dedupe): before a failed wake's member event, noteHeldWake (in-memory, per host, under the leaf wakeFailMu) tells whether the failure is held by a release attempt with no backoff and is the same (attempt ID, error class) as the host's last one; a repeat writes no event, a first or changed one writes one journal line and the event. Reads only the error in hand; no read site added.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (27d3f501, activator-settle-wait) adds the background counter increment and deferred decrement at entry; this branch (Task 5) keeps its own changes. Both kept as-is; no read added.;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent as carlos: a wakeReturned test seam (nil in production) after doWake; on a failed wake of an entry the write fence marked (e.writeFenced, in memory) e.err wraps ErrHALeaseUnavailable; at the awake transition a marked entry begins the existing StopLeaseLost stop before e.ready closes. Only refuses and stops more; no read added; no kill, no root call.;rev3=census-ruling-drain-quiesce-1062;basis=#1062: the failed-wake cleanup calls endHARecoveryLocked(e) as it removes the entry (in-memory, under a.mu); read sites unchanged, no read added registry:Socket@9240,registry:Socket@9401,registry:Stateless@11109,registry:Stateless@11857,whole:Route@11100,whole:Route@11155,whole:Route@11859,whole:Route@1811,whole:Route@3420,whole:Route@3693,whole:Route@3850,whole:Route@515,whole:Route@7502,whole:Route@9193,whole:Route@9242,whole:Route@9403 bafa960a58b9e97bcf1348de427e244470982499822465480d2820b472af4640
+internal/activator/activator.go Service.finishStop legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with a run's settle checked before replication closes, which keeps the stop pending until the run is proven stopped; read sites unchanged, offsets moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: an HA entry (its replica is an HA one, haEntryRep) now releases through releaseHAClean (a new unit on this card) instead of e.rep.Close; when that answers errHostSliceUnproven the stop is kept pending (keepPendingLocked) with the lease held and renewing, and the sweep finishes it once proven; a non-HA entry is unchanged; the same five sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: a forgotten entry's stop is noted for its resident (noteResidentStopLocked: crash or lost lease backs off, any other stop restarts on the next tick) and its ownerDone channel is closed; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: while the host has a release command's record (a.releaseOps[e.host], running or not proven stopped), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the record's proof; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.20: while a rootfs worker may run or is a stray (rootfsWorkersLiveLocked, in-memory, read under a.mu), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the workers are proven stopped; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1 (Astra P1): beside the worker check, under the same lock, a stop with a lease stop of its commands outstanding (e.leaseStops) is kept pending, the replica and lease held, and the sweep finishes it once they have returned; the entry is never released while a kill captured for it may still reach its unit; the same five read sites, no read added Task 9 (PF-3): the count is pendingLeaseStopsLocked(e), the sum of e.leaseStops over both one-shot roles (now a map per role, cmd and tty), so a session's lease stop of the tty unit keeps the stop pending, the replica and lease held, as a run's does; the same five read sites, no read added;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Retain command, worker, release and cgroup proofs. For an actual stateless generation no replica needs closing; close local lifecycle ownership only once those proofs finish.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds a.cancelHeldLegsLocked(e, 0) under a.mu just before the entry is deleted; it only calls the legs' context cancel functions. No read added, none removed.;rev3=census-ruling-region-ha-g2-fixes;basis=Latch HA loss if release leaves an obligation; stopping proofs still precede entry removal; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5 fix 1: records the finished stop's release outcome (marker written, clean) in the drain transaction's in-memory release log while a drain records (noteDrainReleaseLocked); memory only; no read added;rev3=census-ruling-fleet-record-labels-m1;basis=fleet record labels R2: a non-HA replica of a fleet-placed row releases through closeFleetCheckpoint (CloseProven) instead of Close; an unproven final checkpoint keeps the stop pending (keepPendingLocked) with the lease held and renewing, or ends unclean without a release over a lost lease (ErrCheckpointAbandoned); at Shutdown it is only named (C45) and the lease runs to its TTL; never releases over an unproven checkpoint; platform-region rows unchanged; the same five read sites, no read added;rev3=census-ruling-drain-quiesce-1062;basis=#1062: before deleting the entry, calls endHARecoveryLocked(e) (in-memory, under a.mu), which clears a lost host's l.recovery when e was its recovery entry; the loss stays latched; read sites unchanged, no read added registry:Socket@4908,registry:Socket@5013,whole:Route@4858,whole:Route@4910,whole:Route@5015 aa710c395b18608c65414b72f90d479c62a4b8aba1f20d72433665094e8295af
+internal/activator/activator.go Service.wake legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body; the stop now carries its reason for a run it interrupts (beginStopLocked's why argument); read sites unchanged, offsets moved;rev3=census-ruling-wake-latency-1;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=logs that timer's breakdown to the journal after a successful wake (w.steps.String(), e.host, w.wakeTook); no read added;rev3=census-ruling-plans-4d-lapse;basis=cancels a wake whose row the turned-off hook names, like a fence, unless it is a move's active probe (plans 4d). One more whole-row read: the row handed to the hook (a.disabled). Only refuses.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: a refusal before the lease is reported once per change (noteRootfsRefusal) instead of a wake-failure event; the proc, generation and replica are installed through installProcLocked (which puts a resident under its lease watch before the fence); residency notes the outcome (noteResidentWakeLocked); same generation values;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R [pf R3.5]: the wake's context ceiling is wakeCeilingFor(e.route): the old 5 minutes for a binary row, 5 minutes plus runs.MaxTimeout for a rootfs row (room for a release inside the wake); new site +whole:Route (e.route to wakeCeilingFor, which reads Runtime only); no other change;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (branch review R1 P1-1): the wake's context is also cancelled before doWake when RetireExcept has marked the entry retired (e.retired, in memory under a.mu), as it is for a fence or a shutdown. Read sites unchanged (13). Agent, not root; it only refuses more.;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Carry successful hold preparation into its wake, preserve actual mode in the generation and OnWake projection, and project serving version/mode through the narrow registry writer before releasing wake waiters. Final review I1: SetServingMode only for non-worker successful wakes with a nonempty spawned version and either a stateless generation or a mode transition from the route. Ordinary stateful wakes leave rollout status and the wake critical path unchanged.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds a.cancelHeldLegsLocked(e, 0) on the failed-wake path before the entry is deleted, and after close(e.ready) on success calls a.noteHeldAdmissible(e.host), the non-blocking held wake callback, outside a.mu. No read added.;rev3=census-ruling-wake-storm-cap;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): waits for a box-wide wake slot (acquireWakeSlot, an in-memory buffered channel) before doWake; the fence/shutdown/retired/disabled refusals move into refuseWakeLocked and are asked again after admission (one fewer direct whole-Route read here: a.disabled(e.route) now runs inside refuseWakeLocked, same value); e.wakeStart is set at admission and e.admitted marks it. Only waits and refuses more; no new read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Install the successful-acquire observer and restrict due, worker and resident starts before doWake, off a.mu. Add a whole-route argument to restriction; refused work has known-no-start evidence.;rev3=census-ruling-region-ha-g2-fixes;basis=Bind recovery wakes to the service lifetime; no new read.;rev3=census-ruling-edge-page-cache-1;basis=the generation-current call is now noteCurrent(e) instead of noteCurrent(e.host, e.gen.N), so the new noteCurrent can also publish the process's page cache launch inputs; read sites unchanged (16); no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: a failed wake that journalledWakeFailure counts as a real failure is logged through logWakeFailure (rate-limited per host, in memory); a successful wake calls clearWakeFailure. Agent, not root; reads the error already in hand; no read added;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 first commit (#511 F11 log dedupe): before a failed wake's member event, noteHeldWake (in-memory, per host, under the leaf wakeFailMu) tells whether the failure is held by a release attempt with no backoff and is the same (attempt ID, error class) as the host's last one; a repeat writes no event, a first or changed one writes one journal line and the event. Reads only the error in hand; no read site added.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (27d3f501, activator-settle-wait) adds the background counter increment and deferred decrement at entry; this branch (Task 5) keeps its own changes. Both kept as-is; no read added.;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent as carlos: a wakeReturned test seam (nil in production) after doWake; on a failed wake of an entry the write fence marked (e.writeFenced, in memory) e.err wraps ErrHALeaseUnavailable; at the awake transition a marked entry begins the existing StopLeaseLost stop before e.ready closes. Only refuses and stops more; no read added; no kill, no root call.;rev3=census-ruling-drain-quiesce-1062;basis=#1062: the failed-wake cleanup calls endHARecoveryLocked(e) as it removes the entry (in-memory, under a.mu); read sites unchanged, no read added registry:Socket@9240,registry:Socket@9401,registry:Stateless@11109,registry:Stateless@11857,whole:Route@11100,whole:Route@11155,whole:Route@11859,whole:Route@1811,whole:Route@3420,whole:Route@3693,whole:Route@3850,whole:Route@515,whole:Route@7502,whole:Route@9193,whole:Route@9242,whole:Route@9403 bafa960a58b9e97bcf1348de427e244470982499822465480d2820b472af4640
+@coverage internal/activator 4df3c1a2fda87ae19b9d48e2b96eadfdea51bb53e436f545a74d4e3422c046a9
+@coverage internal/host 341112c90b3e8ced207e4c4efd55432a64706e6effa4e7dde76236652a3c8936