carlos / platform Public

region-ha p1b-3a: publish awake app counts and define cold choice

Count owned awake hosts per app through an optional atomic source and
publish additive headroom apps on existing timed writes. Add a pure
cold-wake chooser using the existing capacity and spread policy.

Targeted, race, census and darwin/windows builds pass. Full activator and
boxchoice suites pass; all 21 host claim/lifecycle failures reproduce at
bf5e3c74.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 095e25db0a15274eab7539a8a4213d5d81462610 parent bf5e3c7
13 files changed, +435 −7
  • docs/superpowers/notes/census-proposal-region-ha-p1b3a.md +15 −0
  • docs/superpowers/notes/census-region-ha-p1b3a-claims.md +1 −0
  • internal/activator/awakeapps.go +19 −0
  • internal/activator/awakeapps_test.go +67 −0
  • internal/boxchoice/boxchoice.go +6 −5
  • internal/boxchoice/coldwake.go +37 −0
  • internal/boxchoice/coldwake_test.go +127 −0
  • internal/host/edgesfile.go +3 −2
  • internal/host/haawake_source.go +23 −0
  • internal/host/headroom.go +1 −0
  • internal/host/headroom_test.go +127 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-region-ha-p1b3a.tsv +8 −0
diff --git a/docs/superpowers/notes/census-proposal-region-ha-p1b3a.md b/docs/superpowers/notes/census-proposal-region-ha-p1b3a.md
new file mode 100644
index 000000000..1ffe80332
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-region-ha-p1b3a.md
@@ -0,0 +1,15 @@
+# Census approval: region-ha-p1b3a
+
+Ruling `census-ruling-region-ha-p1b3a`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `internal/activator`, `internal/boxchoice`, `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.
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/activator/awakeapps.go:Service.AwakeApps`: reads +registry:App, +whole:Route ×2; written legacy, accepted-legacy, frozen
+
+Seal: `5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc` → `9be819eba3b4a4d2cb38a1ae4feaae4496cc057d1d93f9da6b1e950ce2dfccb8`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-p1b3a.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/census-region-ha-p1b3a-claims.md b/docs/superpowers/notes/census-region-ha-p1b3a-claims.md
new file mode 100644
index 000000000..11720829e
--- /dev/null
+++ b/docs/superpowers/notes/census-region-ha-p1b3a-claims.md
@@ -0,0 +1 @@
+internal/activator/awakeapps.go:Service.AwakeApps Count owned awake entries under the service mutex by release.RouteAccount(route)/route.App, validating the resolved account and app. Reads in-memory route values only; no store, registry or filesystem call and no new root authority.
diff --git a/internal/activator/awakeapps.go b/internal/activator/awakeapps.go
new file mode 100644
index 000000000..7abfb8e1d
--- /dev/null
+++ b/internal/activator/awakeapps.go
@@ -0,0 +1,19 @@
+package activator
+
+import "github.com/carlosframework/platform/internal/release"
+
+func (a *Service) AwakeApps() map[string]int {
+ a.mu.Lock()
+ defer a.mu.Unlock()
+ apps := make(map[string]int)
+ for _, e := range a.entries {
+ if a.ownedLocked(e, false) != nil {
+ continue
+ }
+ acct, app := release.RouteAccount(e.route), e.route.App
+ if release.ValidAccount(acct) && release.ValidApp(app) {
+ apps[acct+"/"+app]++
+ }
+ }
+ return apps
+}
diff --git a/internal/activator/awakeapps_test.go b/internal/activator/awakeapps_test.go
new file mode 100644
index 000000000..01cb67f95
--- /dev/null
+++ b/internal/activator/awakeapps_test.go
@@ -0,0 +1,67 @@
+package activator
+
+import (
+ "errors"
+ "path/filepath"
+ "reflect"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+func TestAwakeAppsUsesOwnedEntries(t *testing.T) {
+ reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { reg.Close() })
+ if err := reg.Upsert(registry.Route{Host: "one.example.com", Account: "acct", App: "shop", Kind: "instance", Status: "ready"}); err != nil {
+ t.Fatal(err)
+ }
+ for _, host := range []string{"alias.example.com", "second-alias.example.com"} {
+ if err := reg.UpsertAlias(registry.RouteAlias{Alias: host, Host: "one.example.com", Account: "acct", App: "shop"}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ a := &Service{fences: make(map[string]uint64), Routes: reg}
+ add := func(host, account, app string) *actEntry {
+ e := &actEntry{host: host, state: actAwake, rep: &fakeRep{},
+ route: registry.Route{Host: host, Account: account, App: app, Hibernate: true}}
+ a.putEntryLocked(host, e)
+ return e
+ }
+ add("one.example.com", "acct", "shop").sidecar = &fakeProc{}
+ add("two.example.com", "acct", "shop")
+ add("other.example.com", "other", "shop")
+ worker := add("worker.example.com", "acct", "jobs")
+ worker.worker = true
+ worker.route.Kind = "sidecar"
+ worker.route.Hibernate = false
+ add("waking.example.com", "acct", "shop").state = actWaking
+ add("stopping.example.com", "acct", "shop").state = actStopping
+ add("fenced.example.com", "acct", "shop")
+ a.fences["fenced.example.com"] = 1
+ add("lost.example.com", "acct", "shop").rep = &fakeRep{err: errors.New("lease lost")}
+ add("no-lease.example.com", "acct", "shop").rep = nil
+ add("invalid-app.example.com", "acct", "../shop")
+ add("no-app.example.com", "acct", "")
+ add("legacy.example.com", "", "legacy")
+ want := map[string]int{"acct/shop": 2, "other/shop": 1, "acct/jobs": 1, release.OpsAccount + "/legacy": 1}
+ if got := a.AwakeApps(); !reflect.DeepEqual(got, want) {
+ t.Fatalf("awake apps = %v, want %v", got, want)
+ }
+ got := a.AwakeApps()
+ got["acct/shop"] = 99
+ delete(got, "acct/jobs")
+ if fresh := a.AwakeApps(); !reflect.DeepEqual(fresh, want) {
+ t.Fatalf("returned map changed service: %v", fresh)
+ }
+ a.shuttingDown = true
+ if got := a.AwakeApps(); len(got) != 0 {
+ t.Fatalf("shutdown counts = %v", got)
+ }
+ if got := (&Service{}).AwakeApps(); got == nil || len(got) != 0 {
+ t.Fatalf("empty service must return fresh empty map: %v", got)
+ }
+}
diff --git a/internal/boxchoice/boxchoice.go b/internal/boxchoice/boxchoice.go
index 00eab928f..9355a6bc6 100644
--- a/internal/boxchoice/boxchoice.go
+++ b/internal/boxchoice/boxchoice.go
@@ -25,11 +25,12 @@ const Capability = "region-ha-1"
// the totals the free figures are fractions of. A total of 0 is a writer
// that predates it, or a reading that failed.
type Headroom struct {
- MemFreeMiB int64 `json:"mem_free_mib"`
- DiskFreeMiB int64 `json:"disk_free_mib"`
- MemTotalMiB int64 `json:"mem_total_mib"`
- DiskTotalMiB int64 `json:"disk_total_mib"`
- Awake int `json:"awake"`
+ MemFreeMiB int64 `json:"mem_free_mib"`
+ DiskFreeMiB int64 `json:"disk_free_mib"`
+ MemTotalMiB int64 `json:"mem_total_mib"`
+ DiskTotalMiB int64 `json:"disk_total_mib"`
+ Awake int `json:"awake"`
+ Apps map[string]int `json:"apps,omitempty"`
}
// Box is one box's edges file (control/edges/<box>.json, written by
diff --git a/internal/boxchoice/coldwake.go b/internal/boxchoice/coldwake.go
new file mode 100644
index 000000000..1e3367469
--- /dev/null
+++ b/internal/boxchoice/coldwake.go
@@ -0,0 +1,37 @@
+package boxchoice
+
+import "time"
+
+type WakeSnapshot struct {
+ Enabled bool
+ Usable bool
+ LocalDenied bool
+ Self string
+ Region string
+ Serving []Candidate
+ Running map[string]Load
+}
+
+type ColdChoice struct {
+ Ref string
+ OverCapacity bool
+}
+
+func ChooseColdWake(host, app, cleanReleaser string, s WakeSnapshot, now time.Time) (ColdChoice, bool) {
+ if s.Self == "" || len(s.Serving) == 0 {
+ return ColdChoice{}, false
+ }
+ eligible := Placeable(s.Serving, nil, now)
+ if cleanReleaser != "" {
+ for _, c := range eligible {
+ if c.BoxID == cleanReleaser {
+ return ColdChoice{Ref: c.BoxID}, true
+ }
+ }
+ }
+ if c, ok := ChooseRoomiest(host, eligible, s.Running, app); ok {
+ return ColdChoice{Ref: c.BoxID}, true
+ }
+ c, ok := ChooseRoomiest(host, s.Serving, nil, app)
+ return ColdChoice{Ref: c.BoxID, OverCapacity: true}, ok
+}
diff --git a/internal/boxchoice/coldwake_test.go b/internal/boxchoice/coldwake_test.go
new file mode 100644
index 000000000..a1b6cfa45
--- /dev/null
+++ b/internal/boxchoice/coldwake_test.go
@@ -0,0 +1,127 @@
+package boxchoice
+
+import (
+ "crypto/sha256"
+ "reflect"
+ "slices"
+ "testing"
+ "time"
+)
+
+var coldNow = time.Date(2026, 11, 1, 12, 0, 0, 0, time.UTC)
+
+func coldCandidate(ref string, free int64) Candidate {
+ return Candidate{BoxID: ref, MemTotalMiB: 1000, MemFreeMiB: free,
+ DiskTotalMiB: 1000, DiskFreeMiB: 100, Generation: coldNow.Format(time.RFC3339)}
+}
+
+func TestColdWakeCleanEligibleReleaser(t *testing.T) {
+ now := time.Date(2026, 11, 1, 12, 0, 0, 0, time.UTC)
+ c := func(ref string, free int64) Candidate {
+ return Candidate{BoxID: ref, MemTotalMiB: 1000, MemFreeMiB: free,
+ DiskTotalMiB: 1000, DiskFreeMiB: 100,
+ Generation: now.Format(time.RFC3339)}
+ }
+ s := WakeSnapshot{Self: "a", Region: "eu-west-1",
+ Serving: []Candidate{c("a", 150), c("b", 800)}}
+ got, ok := ChooseColdWake("h.example", "acct/shop", "a", s, now)
+ if !ok || got.Ref != "a" || got.OverCapacity {
+ t.Fatalf("%+v %v", got, ok)
+ }
+ s.Serving[0].MemFreeMiB = 149
+ got, ok = ChooseColdWake("h.example", "acct/shop", "a", s, now)
+ if !ok || got.Ref != "b" {
+ t.Fatalf("%+v %v", got, ok)
+ }
+ for _, tc := range []struct {
+ name string
+ change func(*Candidate)
+ }{
+ {"disk below ten percent", func(c *Candidate) { c.DiskFreeMiB = 99 }},
+ {"stale", func(c *Candidate) { c.Generation = now.Add(-15*time.Minute - time.Second).Format(time.RFC3339) }},
+ {"future", func(c *Candidate) { c.Generation = now.Add(time.Minute + time.Second).Format(time.RFC3339) }},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ s.Serving[0] = c("a", 150)
+ tc.change(&s.Serving[0])
+ got, ok := ChooseColdWake("h.example", "acct/shop", "a", s, now)
+ if !ok || got.Ref != "b" || got.OverCapacity {
+ t.Fatalf("%+v %v", got, ok)
+ }
+ })
+ }
+}
+
+func TestColdWakeRoomiestAndSpread(t *testing.T) {
+ s := WakeSnapshot{Self: "a", Serving: []Candidate{coldCandidate("a", 900), coldCandidate("b", 200), coldCandidate("c", 300)},
+ Running: map[string]Load{"a": {Apps: map[string]int{"acct/shop": 1}}}}
+ for _, reverse := range []bool{false, true} {
+ if reverse {
+ slices.Reverse(s.Serving)
+ }
+ got, ok := ChooseColdWake("h.example", "acct/shop", "missing", s, coldNow)
+ if !ok || got.Ref != "c" || got.OverCapacity {
+ t.Fatalf("spread then memory: %+v %v", got, ok)
+ }
+ }
+ s.Running = nil
+ got, ok := ChooseColdWake("h.example", "acct/shop", "", s, coldNow)
+ if !ok || got.Ref != "a" {
+ t.Fatalf("memory before hash: %+v %v", got, ok)
+ }
+ aHash := sha256.Sum256([]byte("h.example\x00a"))
+ bHash := sha256.Sum256([]byte("h.example\x00b"))
+ want := "a"
+ if slices.Compare(aHash[:], bHash[:]) < 0 {
+ want = "b"
+ }
+ s.Serving = []Candidate{coldCandidate("a", 500), coldCandidate("b", 500)}
+ for _, reverse := range []bool{false, true} {
+ if reverse {
+ slices.Reverse(s.Serving)
+ }
+ got, ok := ChooseColdWake("h.example", "acct/shop", "", s, coldNow)
+ if !ok || got.Ref != want {
+ t.Fatalf("exact HRW: %+v %v, want %s", got, ok, want)
+ }
+ }
+}
+
+func TestColdWakeMissingInputs(t *testing.T) {
+ for _, s := range []WakeSnapshot{{}, {Self: "a"}, {Serving: []Candidate{coldCandidate("a", 800)}}} {
+ if got, ok := ChooseColdWake("h.example", "acct/shop", "", s, coldNow); ok || got != (ColdChoice{}) {
+ t.Fatalf("missing input: %+v %v", got, ok)
+ }
+ }
+ s := WakeSnapshot{Self: "a", Serving: []Candidate{coldCandidate("a", 149), coldCandidate("b", 100)},
+ Running: map[string]Load{"a": {Apps: map[string]int{"acct/shop": 1}}}}
+ got, ok := ChooseColdWake("h.example", "acct/shop", "b", s, coldNow)
+ if !ok || got.Ref != "a" || !got.OverCapacity {
+ t.Fatalf("over capacity ignores spread/affinity: %+v %v", got, ok)
+ }
+ s.Serving = []Candidate{{BoxID: "a"}, {BoxID: "b"}}
+ got, ok = ChooseColdWake("h.example", "acct/shop", "", s, coldNow)
+ if !ok || got.Ref == "" || !got.OverCapacity {
+ t.Fatalf("unknown headroom refused: %+v %v", got, ok)
+ }
+ s.Serving = []Candidate{coldCandidate("a", 800), coldCandidate("b", 200)}
+ s.Running = map[string]Load{"a": {Apps: map[string]int{"acct/shop": -1}}}
+ got, ok = ChooseColdWake("h.example", "acct/shop", "", s, coldNow)
+ if !ok || got.Ref != "a" || got.OverCapacity {
+ t.Fatalf("negative count is zero: %+v %v", got, ok)
+ }
+}
+
+func TestColdWakeCopiesApps(t *testing.T) {
+ apps := map[string]int{"acct/shop": 1}
+ s := WakeSnapshot{Self: "a", Serving: []Candidate{coldCandidate("a", 800), coldCandidate("b", 200)},
+ Running: map[string]Load{"a": {Apps: apps}}}
+ before := slices.Clone(s.Serving)
+ got, ok := ChooseColdWake("h.example", "acct/shop", "", s, coldNow)
+ if !ok || got.Ref != "b" {
+ t.Fatalf("%+v %v", got, ok)
+ }
+ if !reflect.DeepEqual(s.Serving, before) || !reflect.DeepEqual(apps, map[string]int{"acct/shop": 1}) {
+ t.Fatalf("chooser mutated snapshot: %+v", s)
+ }
+}
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go
index cb9a2fedc..393a659a2 100644
--- a/internal/host/edgesfile.go
+++ b/internal/host/edgesfile.go
@@ -177,8 +177,9 @@ type edgeHeadroom struct {
// MemTotalMiB and DiskTotalMiB are what the free figures are shares
// of (region HA spec 2 §7). Additive and omitted when 0, a reading
// that failed: a reader takes absent and 0 alike, as unknown.
- MemTotalMiB int64 `json:"mem_total_mib,omitempty"`
- DiskTotalMiB int64 `json:"disk_total_mib,omitempty"`
+ MemTotalMiB int64 `json:"mem_total_mib,omitempty"`
+ DiskTotalMiB int64 `json:"disk_total_mib,omitempty"`
+ Apps map[string]int `json:"apps,omitempty"`
}
const capRegionHA1 = "region-ha-1"
diff --git a/internal/host/haawake_source.go b/internal/host/haawake_source.go
new file mode 100644
index 000000000..705d956c8
--- /dev/null
+++ b/internal/host/haawake_source.go
@@ -0,0 +1,23 @@
+package host
+
+import (
+ "maps"
+ "sync/atomic"
+)
+
+var haAwakeSource atomic.Pointer[func() map[string]int]
+
+func setHAAwakeApps(fn func() map[string]int) {
+ if fn == nil {
+ haAwakeSource.Store(nil)
+ return
+ }
+ haAwakeSource.Store(&fn)
+}
+
+func haAwakeApps() map[string]int {
+ if fn := haAwakeSource.Load(); fn != nil {
+ return maps.Clone((*fn)())
+ }
+ return nil
+}
diff --git a/internal/host/headroom.go b/internal/host/headroom.go
index 405d3b912..c5b1f8b7f 100644
--- a/internal/host/headroom.go
+++ b/internal/host/headroom.go
@@ -15,6 +15,7 @@ func headroomFor(caps []string, dataDir string, reg *registry.Registry) *edgeHea
return nil
}
h := readHeadroom(dataDir, awakeCount(reg))
+ h.Apps = haAwakeApps()
h.MemTotalMiB, h.DiskTotalMiB = capacityMiB(readMemBytes, func() (uint64, uint64, error) { return diskBytes(dataDir) })
return h
}
diff --git a/internal/host/headroom_test.go b/internal/host/headroom_test.go
index 738c42155..bbb28d43c 100644
--- a/internal/host/headroom_test.go
+++ b/internal/host/headroom_test.go
@@ -4,8 +4,12 @@ import (
"context"
"encoding/json"
"errors"
+ "reflect"
"testing"
+ "time"
+ "github.com/carlosframework/platform/internal/boxchoice"
+ "github.com/carlosframework/platform/internal/edgesfile"
"github.com/carlosframework/platform/internal/release"
)
@@ -22,6 +26,129 @@ func TestParseMemAvailable(t *testing.T) {
}
}
+func TestAwakeAppsRideTimedPublication(t *testing.T) {
+ previous := haAwakeSource.Load()
+ t.Cleanup(func() { haAwakeSource.Store(previous) })
+ count := 1
+ setHAAwakeApps(func() map[string]int { return map[string]int{"acct/shop": count} })
+ st := &egressCountingStore{Store: release.NewDirStore(t.TempDir())}
+ reg := edgesTestRegistry(t)
+ seedRoute(t, reg, "shop.example.com")
+ ident := edgesFile{Box: "a", Capabilities: []string{capRegionHA1}}
+ dataDir := t.TempDir()
+ ident.Headroom = headroomFor(ident.Capabilities, dataDir, reg)
+ var last []byte
+ if err := edgesFileWrite(context.Background(), st, reg, ident, "203.0.113.1", &last, false); err != nil {
+ t.Fatal(err)
+ }
+ st.seen = nil
+ count = 2
+ ident.Headroom = headroomFor(ident.Capabilities, dataDir, reg)
+ if err := edgesFileWrite(context.Background(), st, reg, ident, "203.0.113.1", &last, false); err != nil {
+ t.Fatal(err)
+ }
+ if len(st.seen) != 0 {
+ t.Fatalf("ordinary pass calls = %v", st.seen)
+ }
+ if err := edgesFileWrite(context.Background(), st, reg, ident, "203.0.113.1", &last, true); err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(st.seen, []string{"GET control/edges/a.json", "PUT control/edges/a.json"}) {
+ t.Fatalf("timed pass calls = %v, want one conditional replacement", st.seen)
+ }
+ body, _, err := st.Store.Get(context.Background(), "control/edges/a.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var published edgesFile
+ if err := json.Unmarshal(body, &published); err != nil {
+ t.Fatal(err)
+ }
+ if published.Headroom.Apps["acct/shop"] != 2 || published.Generation == "" {
+ t.Fatalf("published = %+v", published)
+ }
+ if _, err := time.Parse(time.RFC3339, published.Generation); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestAwakeAppsWireIsAdditive(t *testing.T) {
+ previous := haAwakeSource.Load()
+ t.Cleanup(func() { haAwakeSource.Store(previous) })
+ setHAAwakeApps(nil)
+ reg, dataDir := edgesTestRegistry(t), t.TempDir()
+ h := headroomFor([]string{capRegionHA1}, dataDir, reg)
+ oldBody, err := json.Marshal(edgesFile{V: 1, Box: "a", Headroom: h})
+ if err != nil {
+ t.Fatal(err)
+ }
+ setHAAwakeApps(func() map[string]int { return map[string]int{"acct/shop": 2} })
+ h.Apps = headroomFor([]string{capRegionHA1}, dataDir, reg).Apps
+ newBody, err := json.Marshal(edgesFile{V: 1, Box: "a", Headroom: h})
+ if err != nil {
+ t.Fatal(err)
+ }
+ var oldView, newView edgesfile.PlacementView
+ if err := json.Unmarshal(oldBody, &oldView); err != nil {
+ t.Fatal(err)
+ }
+ if err := json.Unmarshal(newBody, &newView); err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(oldView, newView) {
+ t.Fatalf("console view changed: %+v vs %+v", oldView, newView)
+ }
+ converted := (edgesfile.Snapshot{Files: []edgesfile.PlacementView{newView}}).BoxChoice()
+ if converted.Boxes[0].Headroom.Apps != nil {
+ t.Fatal("console conversion started consuming Apps")
+ }
+ for _, tc := range []struct {
+ body []byte
+ want string
+ }{{oldBody, ""}, {newBody, `{"acct/shop":2}`}} {
+ var raw struct {
+ Headroom map[string]json.RawMessage `json:"headroom"`
+ }
+ if err := json.Unmarshal(tc.body, &raw); err != nil {
+ t.Fatal(err)
+ }
+ if got := string(raw.Headroom["apps"]); got != tc.want {
+ t.Fatalf("apps = %q, want %q", got, tc.want)
+ }
+ var box boxchoice.Box
+ if err := json.Unmarshal(tc.body, &box); err != nil {
+ t.Fatal(err)
+ }
+ if tc.want != "" && box.Headroom.Apps["acct/shop"] != 2 {
+ t.Fatalf("boxchoice wire lost apps: %+v", box.Headroom)
+ }
+ }
+ setHAAwakeApps(nil)
+ if got := haAwakeApps(); got != nil {
+ t.Fatalf("unset source = %v", got)
+ }
+ if got := headroomFor([]string{capRegionHA1}, dataDir, reg); got.Apps != nil {
+ t.Fatalf("unset source published Apps: %v", got.Apps)
+ }
+}
+
+func TestColdWakeCopiesApps(t *testing.T) {
+ previous := haAwakeSource.Load()
+ t.Cleanup(func() { haAwakeSource.Store(previous) })
+ apps := map[string]int{"acct/shop": 2}
+ setHAAwakeApps(func() map[string]int { return apps })
+ reg, dataDir := edgesTestRegistry(t), t.TempDir()
+ h := headroomFor([]string{capRegionHA1}, dataDir, reg)
+ apps["acct/shop"] = 99
+ if h.Apps["acct/shop"] != 2 {
+ t.Fatal("caller mutation changed published snapshot")
+ }
+ h.Apps["acct/shop"] = 3
+ if got := haAwakeApps(); got["acct/shop"] != 99 {
+ t.Fatalf("snapshot mutation changed source: %v", got)
+ }
+}
+
func TestHeadroomOnlyPublishedWithTheCapability(t *testing.T) {
reg := edgesTestRegistry(t)
if got := headroomFor(nil, t.TempDir(), reg); got != nil {
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index b14a7a4e3..453a14607 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -56,3 +56,4 @@ plan14-root-reads-fix-set-aside-exdev.tsv f9d3016cc6803338f9db19311f3f598e20c37c
plan14-root-reads-durability-3a-escrow.tsv 03a92257beb9b8aac421559e247d191bd69f28a0b26243397a1344a90d59fc2a
plan14-root-reads-rootfs-default-home.tsv 7a0a3da3d6fe7e3c77abb22676db000af2a276c3d13ccae0f038190f51287ed5
plan14-root-reads-probe-burst-limit.tsv 5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc
+plan14-root-reads-region-ha-p1b3a.tsv 9be819eba3b4a4d2cb38a1ae4feaae4496cc057d1d93f9da6b1e950ce2dfccb8
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-p1b3a.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-p1b3a.tsv
new file mode 100644
index 000000000..79e764d83
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-region-ha-p1b3a.tsv
@@ -0,0 +1,8 @@
+# Census overlay region-ha-p1b3a, written by census-propose (#369). census-ruling-region-ha-p1b3a, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-region-ha-p1b3a.md.
+# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 1 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 2ffbb58e2568a1ea38d893670ab9498c6581af1aeba74e5a4d78cc5327e531cd internal/activator/awakeapps.go Service.AwakeApps legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b3a;basis=Count owned awake entries under the service mutex by release.RouteAccount(route)/route.App, validating the resolved account and app. Reads in-memory route values only; no store, registry or filesystem call and no new root authority. registry:App@242,whole:Route@234,whole:Route@244 1eb4a8a36fdcb246f031482676c6af586cb1ecbeabc07271c9d3021ecf355a60
+internal/activator/awakeapps.go Service.AwakeApps legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b3a;basis=Count owned awake entries under the service mutex by release.RouteAccount(route)/route.App, validating the resolved account and app. Reads in-memory route values only; no store, registry or filesystem call and no new root authority. registry:App@242,whole:Route@234,whole:Route@244 1eb4a8a36fdcb246f031482676c6af586cb1ecbeabc07271c9d3021ecf355a60
+@coverage internal/activator b9b984a8634f6783c82923f8e4736ef41aa8087dc2e748fc6e30f8645eb0ce7f
+@coverage internal/boxchoice 893e5d5af6d33ae731a34ba70c343836f5ae9f49f4da891a47a24d6a257bb7e1
+@coverage internal/host 827414424edca7b51415e327c5ce0c9d95a30a4bbe7f0eb418fdc03ddc77538b