carlos / platform Public

test: cover born-HA sidecar duties in I6

Model stamped sidecars through the production duty and departure predicates. Check unattended recovery, served-pool selection and legacy departure isolation with deterministic witnesses and three caught mutations. Apply the approved sidecar refusal copy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 1813846b93dbbc571f4087e12c70ab578b555b2f parent 746caf4
7 files changed, +188 −9
  • internal/console/apisidecars.go +2 −2
  • internal/console/sidecar_ha_test.go +4 −0
  • internal/sim/regionha/duties_model_test.go +21 −7
  • internal/sim/regionha/rules_test.go +3 −0
  • internal/sim/regionha/sidecar_duties_test.go +147 −0
  • internal/sim/regionha/witness_test.go +3 −0
  • internal/sim/regionha/world_test.go +8 −0

Intent

Human

<task-notification> <task-id>bx8daezlq</task-id> <tool-use-id>toolu_018mnn43Kh7BfoeuTmHGjvnE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a26a0e24-c72d-4660-abab-b54e6b2b72b5/tasks/bx8daezlq.output</output-file> <status>completed</status> <summary>Background command "W=/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b3b-s/.superpowers/sdd/2026-11-03-region-ha-p1b3b-duties; L=$W/task-B6-astra-a.log; prev=0; idle=0; while [ ! -f $W/task-B6-astra-a.done ]; do sleep 120; s=$(stat -c %s $L); if [ "$s" = "$prev" ]; then idle=$((idle+1)); else idle=0; fi; prev=$s; if ! pgrep -f "task-B6-astra-a" &gt;/dev/null &amp;&amp; [ ! -f $W/task-B6-astra-a.done ]; then echo DEAD; exit 0; fi; [ $idle -ge 10 ] &amp;&amp; { echo STALLED; exit 0; }; done; cat $W/task-B6-astra-a.done" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/console/apisidecars.go b/internal/console/apisidecars.go
index 2377b5796..1718c3e24 100644
--- a/internal/console/apisidecars.go
+++ b/internal/console/apisidecars.go
@@ -346,7 +346,7 @@ func (s *Server) handleAPISidecarCreate(w http.ResponseWriter, r *http.Request)
// in the bucket. The message is ValidateSidecarShape's own.
rec.HA = s.haRegion(rec.Region)
if rec.HA && !m.HibernateOrDefault() {
- jsonError(w, http.StatusBadRequest, "high availability sidecars must allow hibernation")
+ jsonError(w, http.StatusBadRequest, "high availability sidecars must allow hibernation.")
return
}
if err := provision.ValidateSidecarShape(rec); err != nil {
@@ -758,7 +758,7 @@ func (s *Server) handleAPISidecarEnable(w http.ResponseWriter, r *http.Request)
}
for _, rec := range recs {
if rec.HA {
- jsonError(w, http.StatusBadRequest, "high availability sidecars must allow hibernation")
+ jsonError(w, http.StatusBadRequest, "high availability sidecars must allow hibernation.")
return
}
}
diff --git a/internal/console/sidecar_ha_test.go b/internal/console/sidecar_ha_test.go
index 695d2a96a..26b760ccd 100644
--- a/internal/console/sidecar_ha_test.go
+++ b/internal/console/sidecar_ha_test.go
@@ -6,6 +6,7 @@ import (
"github.com/carlosframework/platform/internal/activator"
"github.com/carlosframework/platform/internal/provision"
"net/http"
+ "strings"
"testing"
)
@@ -95,6 +96,9 @@ func TestSidecarHARefusals(t *testing.T) {
control := &haCreateStore{Store: fx.srv.cfg.Releases}
fx.srv.cfg.Releases = control
code, _, out := rawReq(t, http.MethodPost, sidecarsURL(fx.consoleFixture, "bab", "titogo"), fx.token, `{"name":"bot","region":"`+region+`"}`)
+ if mode == "no-hibernate" && !strings.Contains(string(out), "high availability sidecars must allow hibernation.") {
+ t.Errorf("unapproved refusal copy: %s", out)
+ }
if code != want {
t.Errorf("%s got %d %s want %d", mode, code, out, want)
}
diff --git a/internal/sim/regionha/duties_model_test.go b/internal/sim/regionha/duties_model_test.go
index e08bdf7ee..fec5847dc 100644
--- a/internal/sim/regionha/duties_model_test.go
+++ b/internal/sim/regionha/duties_model_test.go
@@ -7,6 +7,7 @@ import (
"github.com/carlosframework/platform/internal/activator"
"github.com/carlosframework/platform/internal/boxid"
+ "github.com/carlosframework/platform/internal/edgesfile"
"github.com/carlosframework/platform/internal/groupadmission"
"github.com/carlosframework/platform/internal/hadeparture"
"github.com/carlosframework/platform/internal/hafresh"
@@ -51,6 +52,7 @@ type dutyBox struct {
self hafresh.Self
alive, running bool
pools []string
+ servedPools edgesfile.PoolEvidence
placement string
local map[int]map[string]dutyTimer
scans map[int]*dutyScan
@@ -91,7 +93,7 @@ func newDutyWorld(w *world, seed int64) *dutyWorld {
return d
}
func (d *dutyWorld) addBox(i int) {
- d.boxes = append(d.boxes, &dutyBox{self: hafresh.Self{Ref: fmt.Sprintf("box%d", i), IID: fmt.Sprintf("i-%017x", i+1), Account: "111122223333", Region: "eu-west-1"}, alive: true, running: true, pools: []string{"", "hapair"}, local: map[int]map[string]dutyTimer{}, scans: map[int]*dutyScan{}, cache: map[int]int{}, proofs: map[int]bool{}})
+ d.boxes = append(d.boxes, &dutyBox{self: hafresh.Self{Ref: fmt.Sprintf("box%d", i), IID: fmt.Sprintf("i-%017x", i+1), Account: "111122223333", Region: "eu-west-1"}, alive: true, running: true, pools: []string{"", "hapair"}, servedPools: edgesfile.PoolEvidence(`["","hapair"]`), local: map[int]map[string]dutyTimer{}, scans: map[int]*dutyScan{}, cache: map[int]int{}, proofs: map[int]bool{}})
}
func (d *dutyWorld) at(n int) time.Time { return epoch.Add(time.Duration(n) * 30 * time.Second) }
func (d *dutyWorld) fail(f string, args ...any) { d.parent.fail("I6", f, args...) }
@@ -250,12 +252,12 @@ func (d *dutyWorld) scan(b *dutyBox, s *dutyScan) {
hi := s.cursor
s.cursor++
h := d.hosts[hi]
- if h.record.Kind == "sidecar" && h.record.Placement == b.placement {
+ if h.record.Kind == provision.SidecarKind && (!h.record.HA || !on("sidecar-stamp-ignored")) && h.record.Placement == d.boxes[s.dead].placement {
if !on("coverage-stops-consumer") {
b.running = false
}
- if on("sidecar-absence-means-covered") {
+ if on("sidecar-absence-means-covered") && on("legacy-sidecar-counted-covered") {
s.unresolved++
continue
}
@@ -438,11 +440,11 @@ func (d *dutyWorld) deliver(b *dutyBox) {
for hi, h := range d.hosts {
eligible := []string{}
for _, other := range d.boxes {
- if other.alive && hostpkg.CanAdopt(h.record, hostpkg.LocalPolicy{Scope: hadeparture.Scope{Placement: other.placement}, Pools: other.pools}) {
+ if other.alive && dutyEligible(h.record, other) {
eligible = append(eligible, other.self.Ref)
}
}
- in := activator.DutyInput{HA: true, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: eligible, Observed: &h.lock}
+ in := activator.DutyInput{HA: h.record.HA, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: eligible, Observed: &h.lock}
decision := activator.DecideDuty(in)
if !on("duty-ignores-owner") {
decision = activator.DutyAttempt
@@ -505,7 +507,7 @@ func (d *dutyWorld) restart(b int) {
}
func (d *dutyWorld) checkDelivered() {
for _, h := range d.hosts {
- if h.record.Kind != "instance" {
+ if !h.record.HA {
continue
}
for name, timer := range h.wake {
@@ -707,7 +709,7 @@ func dutyPoolWitness(w *world) {
h := d.hosts[0]
eligible := []string{d.boxes[1].self.Ref}
for _, b := range d.boxes {
- input := activator.DutyInput{HA: true, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: eligible, Observed: &hafresh.View{Absent: true}}
+ input := activator.DutyInput{HA: h.record.HA, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: eligible, Observed: &hafresh.View{Absent: true}}
if !on("hrw-ignores-pool") {
input.Eligible = []string{b.self.Ref}
}
@@ -716,3 +718,15 @@ func dutyPoolWitness(w *world) {
}
}
}
+
+func dutyEligible(h provision.DepartureHost, b *dutyBox) bool {
+ if h.Kind == provision.SidecarKind {
+ if !on("sidecar-ignores-served-pools") {
+ return h.HA && h.Placement == b.placement
+ }
+ if !b.servedPools.Serves(h.Pool) {
+ return false
+ }
+ }
+ return hostpkg.CanAdopt(h, hostpkg.LocalPolicy{Scope: hadeparture.Scope{Placement: b.placement}, Pools: b.pools})
+}
diff --git a/internal/sim/regionha/rules_test.go b/internal/sim/regionha/rules_test.go
index 733d4bab1..26ff4e3fe 100644
--- a/internal/sim/regionha/rules_test.go
+++ b/internal/sim/regionha/rules_test.go
@@ -39,6 +39,9 @@ func on(rule string) bool {
// model hands them or does with their answer, the way a regression in a
// caller would.
var allRules = []string{
+ "sidecar-stamp-ignored",
+ "sidecar-ignores-served-pools",
+ "legacy-sidecar-counted-covered",
"start-before-client",
"started-waits-for-inventory",
"ack-with-dead-releaser",
diff --git a/internal/sim/regionha/sidecar_duties_test.go b/internal/sim/regionha/sidecar_duties_test.go
new file mode 100644
index 000000000..9ae073b9b
--- /dev/null
+++ b/internal/sim/regionha/sidecar_duties_test.go
@@ -0,0 +1,147 @@
+package regionha
+
+import (
+ "testing"
+
+ "github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/hafresh"
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+func dutySidecarWorld(w *world, seed int64) *dutyWorld {
+ d := newDutyWorld(w, seed)
+ h := d.hosts[0]
+ rec := provision.SidecarRecord{Schema: 1, Name: "bot", Account: "bab", App: "shop", Host: provision.SidecarHost("bot", "shop", "bab"), Channel: "stable", HA: true, CreatedAt: epoch}
+ lifetime, err := provision.SidecarLifetimeEntryOf(rec)
+ if err != nil {
+ d.fail("invalid sidecar record: %v", err)
+ return d
+ }
+ h.record = provision.DepartureHost{Account: rec.Account, App: rec.App, Host: rec.Host, Kind: provision.SidecarKind, HA: lifetime.HA, Lifetime: lifetime.ID, Placement: rec.Region, Pool: rec.Pool, SidecarPlacement: provision.PlacementAny}
+ return d
+}
+
+func dutySidecarRecoveryWitness(w *world, seed int64) {
+ d := dutySidecarWorld(w, seed)
+ d.marker(0, 0, true)
+ d.terminate(0)
+ d.advance(250)
+ if !d.hosts[0].wake["once"].Delivered {
+ d.fail("stamped sidecar lost its synced timer after termination")
+ }
+ for _, b := range d.boxes[1:] {
+ if s := b.scans[0]; s == nil || !s.complete {
+ d.fail("stamped sidecar kept departure open after recovery")
+ }
+ }
+}
+
+func dutySidecarPoolWitness(w *world, seed int64) {
+ d := dutySidecarWorld(w, seed)
+ d.chaos = false
+ d.hosts = d.hosts[:1]
+ h := d.hosts[0]
+ h.record.Pool = "hapair"
+ h.lock = hafresh.View{Absent: true}
+ // Find the actual raw HRW winner, then make only it shared-only.
+ refs := []string{}
+ for _, b := range d.boxes {
+ refs = append(refs, b.self.Ref)
+ }
+ var rawWinner *dutyBox
+ for _, b := range d.boxes {
+ in := activator.DutyInput{HA: true, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: refs, Observed: &h.lock}
+ if activator.DecideDuty(in) == activator.DutyAttempt {
+ rawWinner = b
+ }
+ b.local[0] = map[string]dutyTimer{"once": h.wake["once"]}
+ }
+ if rawWinner == nil {
+ d.fail("no raw HRW winner")
+ return
+ }
+ rawWinner.pools = []string{""}
+ rawWinner.servedPools = []byte(`[""]`)
+ d.now = 90
+ d.deliver(rawWinner)
+ if h.wake["once"].Delivered {
+ d.fail("never-woken hapair sidecar delivered on shared-only raw winner")
+ }
+ for _, b := range d.boxes {
+ if b != rawWinner {
+ d.deliver(b)
+ }
+ }
+ if !h.wake["once"].Delivered {
+ d.fail("never-woken hapair sidecar not delivered by eligible survivor")
+ }
+}
+
+func dutyLegacySidecarWitness(w *world, seed int64) {
+ d := dutySidecarWorld(w, seed)
+ if len(d.boxes) < 3 {
+ d.addBox(2)
+ }
+ // A legacy home sidecar blocks the home departure, not a different scope.
+ d.hosts = append(d.hosts, &dutyHost{record: provision.DepartureHost{Host: provision.SidecarHost("old", "shop", "bab"), Kind: provision.SidecarKind}, lock: hafresh.View{Absent: true}})
+ d.boxes[1].placement = "other"
+ d.marker(0, 0, true)
+ d.terminate(0)
+ d.terminate(1)
+ d.advance(300)
+ for _, b := range d.boxes[2:] {
+ if !b.running {
+ d.fail("legacy sidecar stopped consumer")
+ }
+ if s := b.scans[0]; s == nil || s.complete || s.ack {
+ d.fail("legacy sidecar counted covered")
+ }
+ if s := b.scans[1]; s == nil || !s.complete {
+ d.fail("legacy sidecar blocked unrelated departure")
+ }
+ }
+ if !d.hosts[0].wake["once"].Delivered {
+ d.fail("legacy sidecar blocked stamped sidecar delivery")
+ }
+}
+
+func TestI6SidecarDuties(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ run func(*world, int64)
+ }{
+ {"stamped-synced-timer-after-termination", dutySidecarRecoveryWitness},
+ {"never-woken-hapair-excludes-shared-raw-winner", dutySidecarPoolWitness},
+ {"legacy-blocks-only-its-departure", dutyLegacySidecarWitness},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ w := newWitness()
+ tc.run(w, 7)
+ if len(w.violations) > 0 {
+ t.Fatal(w.violations)
+ }
+ })
+ }
+}
+
+func TestI6SidecarPoolEvidence(t *testing.T) {
+ for _, tc := range []struct {
+ name, raw, pool string
+ want bool
+ }{
+ {"absent", "", "hapair", false}, {"null", "null", "hapair", false},
+ {"empty", "[]", "", false}, {"explicit-shared", `[""]`, "", true},
+ {"named", `["hapair"]`, "hapair", true}, {"shared-only", `[""]`, "hapair", false},
+ {"malformed", `[null,"hapair"]`, "hapair", false},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ d := dutySidecarWorld(newWitness(), 7)
+ h, b := d.hosts[0], d.boxes[0]
+ h.record.Pool = tc.pool
+ b.servedPools = []byte(tc.raw)
+ if got := dutyEligible(h.record, b); got != tc.want {
+ t.Fatalf("eligible=%v want %v", got, tc.want)
+ }
+ })
+ }
+}
diff --git a/internal/sim/regionha/witness_test.go b/internal/sim/regionha/witness_test.go
index 88404a8ac..79dc96165 100644
--- a/internal/sim/regionha/witness_test.go
+++ b/internal/sim/regionha/witness_test.go
@@ -39,6 +39,9 @@ type witness struct {
}
var witnesses = []witness{
+ {"sidecar-stamp-ignored", "sidecar-stamp-ignored", "I6", "stamped-synced-timer-after-termination", func(t *testing.T, w *world) { dutySidecarRecoveryWitness(w, 7) }},
+ {"sidecar-ignores-served-pools", "sidecar-ignores-served-pools", "I6", "never-woken-hapair-excludes-shared-raw-winner", func(t *testing.T, w *world) { dutySidecarPoolWitness(w, 7) }},
+ {"legacy-sidecar-counted-covered", "legacy-sidecar-counted-covered", "I6", "legacy-blocks-only-its-departure", func(t *testing.T, w *world) { dutyLegacySidecarWitness(w, 7) }},
{"start-before-client", "start-before-client", "I6", "production boundary", func(t *testing.T, w *world) { dutyStartupWitness(t, w) }},
{"started-waits-for-inventory", "started-waits-for-inventory", "I6", "production boundary", func(t *testing.T, w *world) { dutyInventoryStartupWitness(t, w) }},
{"ack-with-dead-releaser", "ack-with-dead-releaser", "I6", "production boundary", func(t *testing.T, w *world) { dutyRescanWitness(w) }},
diff --git a/internal/sim/regionha/world_test.go b/internal/sim/regionha/world_test.go
index cb3057978..3ccd911d1 100644
--- a/internal/sim/regionha/world_test.go
+++ b/internal/sim/regionha/world_test.go
@@ -715,6 +715,14 @@ func runSeed(seed int64, verbose bool) *world {
w.final()
scenarios := []string{"held", "released", "scanner-death", "duplicate-import", "lost-event", "unsynced", "future", "sequential", "coverage", "pool", "missing-edges", "interim", "delete-denied", "inventory", "fixed", "early"}
runDutyScenario(w, scenarios[int(seed)%len(scenarios)], seed)
+ switch seed % 3 {
+ case 0:
+ dutySidecarRecoveryWitness(w, seed)
+ case 1:
+ dutySidecarPoolWitness(w, seed)
+ case 2:
+ dutyLegacySidecarWitness(w, seed)
+ }
runGroupScenario(w, seed)
return w
}