carlos / platform Public

console: retain fixed DNS addresses and ignore proven retired status rows

Limit shared-pool DNS exclusions to HA regions while excluding proven members
in every region. Ignore retained platform heartbeats only after signed identity
binding and a missing edges record, preserving fixed and uncertain rows.
Exercise DNS, GeoIP, layout and alert paths through serving constructors and
real entry points, including the S3 transport.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1aed0fce8b485780bc47bdfd57256c7e527dcf3f parent 2da5808
9 files changed, +320 −13
  • docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md +5 −3
  • internal/console/alertsignals.go +9 −7
  • internal/console/apisystemgeoip.go +3 −0
  • internal/console/apisystemupdate.go +7 −0
  • internal/console/edgesdns.go +1 −1
  • internal/console/edgesreaders_g3_test.go +28 −0
  • internal/console/layoutguard.go +2 −2
  • internal/console/statusrows.go +67 −0
  • internal/console/statusrows_g3_test.go +198 −0

Intent

Human

<task-notification> <task-id>blf2leaat</task-id> <tool-use-id>toolu_016pfjqdFwXviwm1dPiwkAk6</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/blf2leaat.output</output-file> <status>completed</status> <summary>Background command "sleep 15; .superpowers/sdd/2026-11-07-region-ha-g3-fixes/wait.sh t7" completed (exit code 0)</summary> </task-notification>

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="f00422ef-3964-4a03-aea2-4493b0c9e24a"> Agent manager 8a3d302: one more finding for your audit (T5; it reads the same records): after the G3 switch-off, the FLAGSHIP status still lists group member g-26c6d74550f302168da1 as UNREACHABLE (status/boxes/ row), although its edges file retired at 14:54Z. Check whether retirement also removes a departed member&apos;s status/boxes record, and whether any reader (the console&apos;s eligible capacity or placement reads, hostops, the hosts-used roster) counts a stale member status row. Fix it in this branch if it&apos;s in scope, or file it. </paseo-system>

Human

<task-notification> <task-id>aa343c83823120586</task-id> <tool-use-id>toolu_01SSbU7x5WQUPp8Y7m2E6BRG</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/aa343c83823120586.output</output-file> <status>completed</status> <summary>Agent "Investigate stale member status rows" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Nothing ever deletes a `status/boxes` record, so a departed member's row stays UNREACHABLE for about 24 hours. More importantly, during that day it fires a false paging incident and blocks two console checks. The full write-up is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-g3-fixes/.superpowers/sdd/2026-11-07-region-ha-g3-fixes/inv/status-rows.md`. 1. **Writer:** only the box itself writes the row, every 5 minutes (`internal/host/agent.go:5012`, `internal/status/snapshot.go:1255`), under its `g-` ref. "Unreachable" depends only on age: the last report is more than 15 minutes old (`internal/status/fleet.go:138`). The one way a row goes away is that listings skip objects not written for 24 hours (`fleet.go:258`, and `alertsignals.go:49` for the alert engine). 2. **No deleter:** the departure's `complete()` deletes only the edges file (`internal/host/hadepartures_scan.go:633`). Spec §9.3, §13 and §24 never mention status rows. Group IAM allows the delete; the bucket deny covers only `control/boxes` and three similar prefixes. 3. **Harmless readers:** every reader that starts from the edges files and looks up status never reaches an orphan row. That covers capacity observation, seeds, lifetimes, offline moves, placement and the edges join. Readers that skip stale rows are also fine: team floor, rootfs, domains, instances, egress, updates gate. The size door (`policysize.go`) can count the dead box only in the first 15 minutes, and that is conservative. 4. **Display only:** `carlos system status` (where you saw it), `carlos status --live`, the ops boxes page and the status layout API. 5. **Wrong, paging:** the alert engine (`internal/console/alertsignals.go:396`) fires a `box_silent` incident 15 minutes after termination ("if it is down, every app on it is down too"). It closes only when the row ages out at 24 hours. With automatic replacement, every departure produces one false incident. 6. **Wrong, blocking:** GeoIP readiness (`apisystemgeoip.go:323`) reports `ready:false` and tells you to delete an edges file that is already gone. The layout guard (`layoutguard.go:31`, `:80`) refuses `layout migrate` and rollback to a pre-layout release because the dead member "is stale". Both last up to 24 hours. 7. **Fix:** in `complete()`, after the edges file is deleted and indexed and before saving "complete", delete `status/boxes/&lt;ref&gt;.json` on its ETag, for group refs only. Fixed refs must keep their row because a replacement can reuse the label. A missing row counts as done, and a conflicting ETag is treated as an identity fault. No reader changes are needed. A display-only filter is not enough: it can't tell a member from a fixed box by name alone, and it wouldn't stop the page or the two blocks. 8. **Ordering and wiring:** - The status row must go after the edges file. If an edges file exists with no status row, the live join counts that box's state as unknown and marks the whole read incomplete, so automatic placement and the size door would refuse. - The departure opens the deployment store, but status is written to `CARLOS_STATUS_BUCKET` when that is set. Either pass the status store into the controller or skip the delete when the two buckets differ. - `fixed` is local to one block (`hadepartures_scan.go:577`) and needs recomputing. 9. **Census:** `Controller.complete` is accepted-legacy and frozen in `census-proposal-region-ha-g3-fixes.md:25`. This is a new production delete on the termination path, so it needs a census-card entry and a reviewer ruling. The family is already allowed to take deletes (`mutation_classifier.go:52`). Spec §9.3 step 2 also needs one line. 10. **Size, risk, tests:** about 30 lines plus wiring; low to medium risk, because it runs after every existing effect, can safely re-run, and a permission failure leaves the departure at "indexed" and pages through the existing path. Tests to extend: - `TestDepartureG3Production` and `TestDepartureG3RollbackCheckpoint`: the row is deleted, and deleting again after a crash is harmless. - `TestGroupDepartureStepAndComplete`. - `hadepartures_retained_test.go`: a fixed ref keeps its row. - `TestDepartureDeleteDenied` and `TestDepartureDeletionRace`. - Alongside `TestEnginePassHeartbeatPastTheHorizonCloses`: a deleted row closes `box_silent` as "box gone". Outside this question: the departure also leaves the dead member's `alerts/boxes/` and `metrics/boxes/` objects behind, so any of its alerts that were firing stay open.</result> <usage><subagent_tokens>133040</subagent_tokens><tool_uses>44</tool_uses><duration_ms>298754</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>abc23d2a125fb8a00</task-id> <tool-use-id>toolu_01Gcg7Ujrr3HBhZYYqECWAFy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/abc23d2a125fb8a00.output</output-file> <status>completed</status> <summary>Agent "Whole-branch review R3 (additions)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Nothing further is outstanding: the findings are written, the worktree is clean, and the scratch directory is removed. Verdict: **READY AFTER FIXES** Written to `.superpowers/sdd/2026-11-07-region-ha-g3-fixes/final-review-r3.md`. Checks run: gofmt clean; darwin/arm64 and windows/amd64 cross-builds plus `go vet` of the four changed packages ok; focused tests in lease, edge, host (incl. replay, listing, five-minute, prefix safety, simulation -short) and console (G3, size door, perf budget) all pass. Tofu not re-run locally (installed 1.12.5 cannot parse the tests; module pins &gt;= 1.10; T9 recorded 92/92 on 1.13.1), reviewed statically. - **P1**: none. - **P2-1 (T5, C15)**: `dnsAddressSnapshot` (edgesdns.go:9-18) drops any fixed box publishing `serves_shared_pool:false`, even outside HA regions where no member can exist; a named-pool-only fixed deployment with no ingress/env edge IPs ends with empty DNS advice and "no-address" placements. Fix: apply the pool exclusion only when `s.haRegion(f.Placement)`; keep the proven-member exclusion everywhere (or release-note the rule if kept). - **P3-1 (T5, C11)**: size door now skips every stale box including one whose file lists the record's host (policysize.go:119); a live box with a 15-min status outage can be bypassed. Sanctioned by the audit; narrower rule is "keep stale host claims unless proven member". - **P3-2 (T7)**: replay member shape has 4 hosts; the zero-host flagship shape is only in unit tests. - **P3-3 (T7/C2)**: a retained member file older than 15 min stops being proven and history coverage waits for it; blocked departures reopen the window (record on #421). - **P3-4 (T9)**: `infra/modules/README.md:78` still describes `alerts_email` as the only alert input. - **P3-5 (T9)**: validation references `data.aws_region.current.region`; needs OpenTofu &gt;= 1.9 (module pins &gt;= 1.10), note only. - **P3-6 (T6)**: `lockListings` entries for departures leaving by other routes persist (already deferred). - T6 safety/liveness, T8 request-count enforcement, T9 create-path address/count stability and census safety: confirmed, no findings.</result> <usage><subagent_tokens>243782</subagent_tokens><tool_uses>42</tool_uses><duration_ms>2430161</duration_ms></usage> </task-notification>

diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
index 2fc7c23b2..1739d77a4 100644
--- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
+++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
@@ -887,9 +887,9 @@ the same rule for every box.
| C10 | Database read forwarding | Blind: requires the published capability, whoever serves it. |
| C11 | Instance size door (`policysize.go`) | Aware through `served_pools`. Fresh boxes count when region and pool match a record, or they publish its host. A stale host claim never counts. With no records, use the app manifest's pool across regions. Unknown or malformed pool evidence retains inclusion. |
| C12 | Lifetimes cutover and watch | Blind: every file needs the release floor and fresh status. A stale member blocks until retired. |
-| C13 | GeoIP readiness | Blind readiness check: members serve traffic and need GeoIP. A stale file blocks. The remedy text suggesting manual deletion is deferred; member files require the departure protocol. |
+| C13 | GeoIP readiness | Members with edges files serve traffic and need GeoIP. Ignore a retained status row only with verified group identity and an absent edges file; unavailable proof retains the existing readiness checks. The remedy text suggesting manual deletion is deferred; member files require the departure protocol. |
| C14 | Egress grants and fleet-address report | Blind: all published addresses conservatively refuse an allow, including stale files. |
-| C15 | DNS guidance, domain placements and purchased-zone apex | Aware: suppress addresses from files publishing `serves_shared_pool:false` or bound to proven members by the capacity observation. Reuse the proof without new identity reads. Configured ingress still replaces box-derived DNS addresses. Status freshness excludes dead boxes; a complete empty refresh clears cached addresses. |
+| C15 | DNS guidance, domain placements and purchased-zone apex | Aware: suppress addresses from files publishing `serves_shared_pool:false` in HA regions or bound to proven members by the capacity observation. Reuse the proof without new identity reads. Configured ingress still replaces box-derived DNS addresses. Status freshness excludes dead boxes; a complete empty refresh clears cached addresses. |
| C16 | Console and CLI region names | Blind: any member can name its AWS region. |
| C17 | Asset status home election | Blind, with the same member routing rules as E2. |
| C18 | Domain attach conflict check | Blind: live member routes reserve names, as H2. |
@@ -901,10 +901,12 @@ sets retain the all-box check. An unreadable app manifest cannot narrow the
set. Fleet roster handling is unchanged.
For C15, proof unavailable means there is no identity-based exclusion;
-explicit shared-pool exclusion still applies. An unproven `g-` label alone
+explicit shared-pool exclusion still applies in HA regions. An unproven `g-` label alone
never removes a fixed address. The configured public ingress and explicit
edge-address lists remain operator-owned stable address inputs.
+The alert engine heartbeat pass, GeoIP readiness and layout downgrade/migrate guards ignore a platform status row only when its signed identity binds its reference to a group member and its edges file is absent; fixed boxes, fleet rows and unavailable proof retain the existing checks.
+
### 24.3 The rule for a new reader
A new reader states in its doc comment and this table whether it is
diff --git a/internal/console/alertsignals.go b/internal/console/alertsignals.go
index 891270980..7b83b5279 100644
--- a/internal/console/alertsignals.go
+++ b/internal/console/alertsignals.go
@@ -1,10 +1,12 @@
package console
-// The alert engine's reads and signals (fleet alerts spec §7, §9). Every
-// bucket read the engine makes goes through engineReads, its own ETag cache:
+// The alert engine's reads and signals (fleet alerts spec §7, §9). Alert
+// source reads go through engineReads, its own ETag cache:
// after an object's first read, each read is a conditional GET, so an
// unchanged object costs a 304. LIST calls are alerts/boxes/ every pass and
-// status/boxes/ every 5th pass, nothing else (spec §9).
+// status/boxes/ every 5th pass, nothing else (spec §9). The heartbeat pass
+// also checks retained group rows against identity and edges records through
+// the bounded HA reader before deriving signals.
//
// A pass turns what it read into alertSignals: one signal per (scope, rule,
// subject) a source reported this pass, and, for each source it read, which
@@ -365,7 +367,7 @@ func (s *Server) heartbeatSignals(ctx context.Context, settings map[string]alert
if boxes, err := r.boxes(ctx, s.cfg.Releases, now); err != nil {
alertReadFailed(ctx, fmt.Errorf("list %s: %w", alertStatusBoxesPrefix, err))
} else {
- heartbeatBoxSignals(boxes, r.unreadBoxes, settings, now, sig)
+ heartbeatBoxSignals(s.activeStatusRows(ctx, boxes), r.unreadBoxes, settings, now, sig)
}
if f, err := r.fleet(ctx, s.cfg.Releases); err != nil {
alertReadFailed(ctx, fmt.Errorf("read %s: %w", alertFleetKey, err))
@@ -384,9 +386,9 @@ func alertReadFailed(ctx context.Context, err error) {
jobFailed(ctx, err)
}
-// heartbeatBoxSignals adds, for each box with a heartbeat object, box_silent
-// (Review Focus 3: every box with an object is a member, whether or not it
-// ever fired anything) and alert_delivery_broken, and cert_expiring for
+// heartbeatBoxSignals adds, for each retained heartbeat row, box_silent
+// (including boxes that never fired anything) and alert_delivery_broken,
+// and cert_expiring for
// every host the fresh boxes serve. Certificates are judged only when every
// heartbeat was read. While a listed box is stale, the fresh boxes' hosts
// are still judged, but a host missing from their readings does not go
diff --git a/internal/console/apisystemgeoip.go b/internal/console/apisystemgeoip.go
index e9f675622..ce561744d 100644
--- a/internal/console/apisystemgeoip.go
+++ b/internal/console/apisystemgeoip.go
@@ -260,6 +260,9 @@ func (s *Server) geoipInventory(ctx context.Context) (geoipInventoryRead, error)
if !complete {
inv.heartbeatsComplete = false
}
+ if fleet == "" {
+ boxes = s.activeStatusRows(ctx, boxes)
+ }
for _, b := range boxes {
inv.boxes[geoipBoxKey{fleet, b.Label}] = b
}
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go
index d2de4f651..46fb008a6 100644
--- a/internal/console/apisystemupdate.go
+++ b/internal/console/apisystemupdate.go
@@ -268,6 +268,10 @@ func (s *Server) systemFeed() publicrelease.Feed {
// cannot be opened, or one whose fleets cannot be listed, is a fleet set this
// console cannot see.
func (s *Server) systemBoxes(ctx context.Context, strict bool) ([]status.Box, bool, error) {
+ return s.systemBoxesFiltered(ctx, strict, false)
+}
+
+func (s *Server) systemBoxesFiltered(ctx context.Context, strict, skipRetiredGroups bool) ([]status.Box, bool, error) {
_, fleets, fleetsErr := s.systemFleets()
// The platform's heartbeats and each fleet's are read at once, then
// taken in the order they were always taken: the platform's, then the
@@ -291,6 +295,9 @@ func (s *Server) systemBoxes(ctx context.Context, strict bool) ([]status.Box, bo
if err != nil {
return nil, false, err
}
+ if skipRetiredGroups {
+ boxes = s.activeStatusRows(ctx, boxes)
+ }
if fleetsErr != nil {
return s.systemFleetsUnreadable(boxes, strict, fleetsErr)
}
diff --git a/internal/console/edgesdns.go b/internal/console/edgesdns.go
index c9db4624f..6943c0d8c 100644
--- a/internal/console/edgesdns.go
+++ b/internal/console/edgesdns.go
@@ -9,7 +9,7 @@ import "github.com/carlosframework/platform/internal/edgesfile"
func (s *Server) dnsAddressSnapshot(snap edgesfile.Snapshot) edgesfile.Snapshot {
files := append([]edgesfile.PlacementView(nil), snap.Files...)
for i, f := range files {
- if isFalse(f.ServesSharedPool) || s.provenGroupTarget(snap, f.Placement, "box:"+f.Box) {
+ if (s.haRegion(f.Placement) && isFalse(f.ServesSharedPool)) || s.provenGroupTarget(snap, f.Placement, "box:"+f.Box) {
files[i].EIP = ""
}
}
diff --git a/internal/console/edgesreaders_g3_test.go b/internal/console/edgesreaders_g3_test.go
index fa98deb52..82783eb02 100644
--- a/internal/console/edgesreaders_g3_test.go
+++ b/internal/console/edgesreaders_g3_test.go
@@ -48,6 +48,7 @@ func TestG3DomainReadersExcludeMemberAddresses(t *testing.T) {
t.Run(map[bool]string{false: "without-ingress", true: "configured-ingress"}[ingress], func(t *testing.T) {
fx, token, _ := rootfsDoorWorldToken(t, "g3-dns")
fx.srv.cfg.EdgeIPs = nil
+ fx.srv.cfg.HomeRegion, fx.srv.cfg.HARegions = "ie", []string{"ie"}
g3DNSWorld(t, fx.rel, "route.example.net")
attachShopClaim(t, fx, fx.sqid, "shop", "alias.example.com", "route.example.net")
want := "192.0.2.10"
@@ -88,6 +89,7 @@ func TestG3BoughtZoneExcludesMemberAddresses(t *testing.T) {
t.Run(map[bool]string{false: "without-ingress", true: "configured-ingress"}[ingress], func(t *testing.T) {
f := newPurchaseFixture(t)
f.srv.cfg.EdgeIPs = nil
+ f.srv.cfg.HomeRegion, f.srv.cfg.HARegions = "ie", []string{"ie"}
g3DNSWorld(t, f.rel, "")
want := "192.0.2.10"
if ingress {
@@ -167,6 +169,7 @@ func TestG3DNSExcludesProvenMemberServingSharedPool(t *testing.T) {
func TestG3DNSClearsPreviouslyEligibleAddress(t *testing.T) {
fx, token, _ := rootfsDoorWorldToken(t, "g3-dns-refresh")
+ fx.srv.cfg.HomeRegion, fx.srv.cfg.HARegions = "ie", []string{"ie"}
fx.srv.cfg.EdgeIPs = nil
attachShopClaim(t, fx, fx.sqid, "shop", "alias.example.com", "route.example.net")
get := func() string {
@@ -192,6 +195,7 @@ func TestG3DNSClearsPreviouslyEligibleAddress(t *testing.T) {
func TestG3RegionalPlacementsExcludeMemberAddresses(t *testing.T) {
w := newRegionalWorld(t, "g3-regional")
w.putRegionalWorldClaim(t, time.Now())
+ w.fx.srv.cfg.HomeRegion, w.fx.srv.cfg.HARegions = "ie", []string{"ie"}
putG3Edges(t, w.fx.rel, "g-bbbbbbbbbbbbbbbbbbbb", "192.0.2.11", "hapair", rdIE, 927, time.Now())
putSizeReport(t, w.fx.rel, "g-bbbbbbbbbbbbbbbbbbbb", "", time.Now(), &status.BoxMetrics{Release: rdFloor(), AliasesRead: true})
code, _, out := rawReq(t, http.MethodGet, placementsURL(w.fx, "shop", rdHost), w.token, "")
@@ -240,3 +244,27 @@ func TestG3SizeDoorPreservesUnknownPoolAndFreshHostEvidence(t *testing.T) {
})
}
}
+
+func TestG3DNSKeepsNamedPoolFixedBoxOutsideHA(t *testing.T) {
+ fx, token, _ := rootfsDoorWorldToken(t, "g3-dns-non-ha")
+ fx.srv.cfg.EdgeIPs = nil
+ putG3Edges(t, fx.rel, "fixed", "192.0.2.10", "named", "route.example.net", 8192, time.Now())
+ attachShopClaim(t, fx, fx.sqid, "shop", "alias.example.com", "route.example.net")
+ code, _, out := rawReq(t, http.MethodGet, domainGetURL(fx, fx.sqid, "shop", "alias.example.com"), token, "")
+ if code != 200 || !strings.Contains(out, "192.0.2.10") {
+ t.Fatalf("non-HA guidance = %d %s", code, out)
+ }
+ p := getPlacements(t, fx, token, "alias.example.com")
+ if !p.Placements[0].Ready || !strings.Contains(string(p.Placements[0].Boxes), "192.0.2.10") {
+ t.Fatalf("non-HA placement = %+v", p)
+ }
+ f := newPurchaseFixture(t)
+ f.srv.cfg.EdgeIPs = nil
+ putG3Edges(t, f.rel, "fixed", "192.0.2.10", "named", "", 8192, time.Now())
+ purchase := f.start(t)
+ f.authorise(t, purchase)
+ f.until(t, purchase.ID, PurchaseZoneReady)
+ if got := f.zone.Managed[purchase.Domain].Apex; !reflect.DeepEqual(got, []zonehost.ApexTarget{{IP: "192.0.2.10"}}) {
+ t.Fatalf("non-HA apex = %+v", got)
+ }
+}
diff --git a/internal/console/layoutguard.go b/internal/console/layoutguard.go
index a2f3ea488..74fc368c4 100644
--- a/internal/console/layoutguard.go
+++ b/internal/console/layoutguard.go
@@ -28,7 +28,7 @@ func (s *Server) layoutDowngradeBlocked(ctx context.Context, target string) stri
// Every fleet's boxes, the union carlos system status reads. Strict:
// a fleet whose heartbeats cannot be read is a fleet whose rows are
// unknown, and unknown blocks.
- boxes, _, err := s.systemBoxes(ctx, true)
+ boxes, _, err := s.systemBoxesFiltered(ctx, true, true)
if err != nil {
return target + " predates the instance layout and the fleet's layout is unknown: could not read the boxes' snapshots: " + err.Error()
}
@@ -77,7 +77,7 @@ func (s *Server) layoutDowngradeBlocked(ctx context.Context, target string) stri
// A named box that no snapshot knows is refused too: an intent for a box
// nobody can see is one nobody can check.
func (s *Server) layoutMigrateBlocked(ctx context.Context, box string) string {
- boxes, _, err := s.systemBoxes(ctx, true)
+ boxes, _, err := s.systemBoxesFiltered(ctx, true, true)
if err != nil {
return "layout migrate refused: could not read the boxes' snapshots: " + err.Error()
}
diff --git a/internal/console/statusrows.go b/internal/console/statusrows.go
new file mode 100644
index 000000000..ad5215ab8
--- /dev/null
+++ b/internal/console/statusrows.go
@@ -0,0 +1,67 @@
+package console
+
+import (
+ "context"
+ "errors"
+ "os"
+ "time"
+
+ "github.com/aws/smithy-go"
+ "github.com/carlosframework/platform/internal/boxid"
+ "github.com/carlosframework/platform/internal/edgesfile"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// activeStatusRows keeps uncertain rows. A departed member is absent from
+// capacity's edges-driven snapshot, so verify its retained identity directly
+// with the same verifier and reference binding. Only platform rows belong here;
+// fleet labels have their own namespace and cannot prove platform membership.
+func (s *Server) activeStatusRows(ctx context.Context, boxes []status.Box) []status.Box {
+ o := s.haCapacity.Load()
+ if o == nil || o.config == nil {
+ return boxes
+ }
+ ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
+ defer cancel()
+ kept := make([]status.Box, 0, len(boxes))
+ for _, b := range boxes {
+ if !o.retiredGroupStatus(ctx, b.Label) {
+ kept = append(kept, b)
+ }
+ }
+ return kept
+}
+
+func (o *haObserver) retiredGroupStatus(ctx context.Context, ref string) bool {
+ if !edgesfile.IsGroupReference(ref) {
+ return false
+ }
+ if _, fixed := o.config.FixedBoxes[ref]; fixed {
+ return false
+ }
+ raw, err := boxid.Load(ctx, o.store, ref)
+ if err != nil {
+ return false
+ }
+ proven := false
+ for _, region := range o.config.Regions {
+ ev, code := o.enrollIdentity(raw, ref, region.AWSRegion)
+ if code == "" && ref == haGroupReference(ev.Cloud.Account, ev.Cloud.InstanceID) {
+ proven = true
+ break
+ }
+ }
+ if !proven {
+ return false
+ }
+ _, _, err = o.store.Get(ctx, edgesfile.Key(ref))
+ missing := errors.Is(err, os.ErrNotExist)
+ var apiErr smithy.APIError
+ if errors.As(err, &apiErr) {
+ switch apiErr.ErrorCode() {
+ case "NoSuchKey", "NotFound", "404":
+ missing = true
+ }
+ }
+ return missing && ctx.Err() == nil
+}
diff --git a/internal/console/statusrows_g3_test.go b/internal/console/statusrows_g3_test.go
new file mode 100644
index 000000000..33adfa425
--- /dev/null
+++ b/internal/console/statusrows_g3_test.go
@@ -0,0 +1,198 @@
+package console
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/boxid"
+ "github.com/carlosframework/platform/internal/boxid/boxidtest"
+ "github.com/carlosframework/platform/internal/edgesfile"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// Use the serving constructor and observer startup, with a local deployment
+// bucket and a test certificate as the only cloud substitutes.
+func g3StatusWorld(t *testing.T, mode string) (*consoleFixture, string, string) {
+ t.Helper()
+ root := t.TempDir()
+ var store release.Store = release.NewDirStore(root)
+ ref := haGroupReference(moveTestAccount, groupTestInstance)
+ if mode == "fixed" {
+ ref = "fixed"
+ }
+ cfg := haTestConfig
+ if mode == "pinned" {
+ cfg = strings.Replace(cfg, `"fixed_boxes":{`, `"fixed_boxes":{"`+ref+`":{"region_code":"ie","instance_id":"`+groupTestInstance+`"},`, 1)
+ }
+ options := consoleFixtureOptions{WithKey: true, Releases: store, Tweak: func(c *Config) {
+ c.HARegions, c.HomeRegion = []string{"ie"}, "ie"
+ c.HACapacityConfig, c.HACapacityDirectory = cfg, root
+ c.AWSAccount, c.SecretsPub = moveTestAccount, testKeyPub
+ }}
+ if strings.HasPrefix(mode, "s3-") {
+ options.Releases = nil
+ options.S3 = &perfLatency{}
+ }
+ fx := newConsoleFixtureWith(t, options)
+ if strings.HasPrefix(mode, "s3-") {
+ store = fx.rel
+ root = fx.rel.(*deletableStore).root
+ }
+ signer := boxidtest.NewSigner(t)
+ fx.srv.boxCerts = signer.Certs()
+ instance := groupTestInstance
+ if mode == "wrong-binding" {
+ instance = "i-0123456789abcdef0"
+ }
+ _, raw := signer.Record(t, ref, moveTestAccount, "eu-west-1", instance)
+ switch mode {
+ case "no-proof":
+ case "identity-read-error":
+ if err := os.MkdirAll(filepath.Join(root, boxid.Key(ref)), 0700); err != nil {
+ t.Fatal(err)
+ }
+ case "invalid-proof":
+ haPut(t, store, boxid.Key(ref), []byte(`{"v":1}`))
+ default:
+ haPut(t, store, boxid.Key(ref), raw)
+ }
+ if mode == "edges-present" || mode == "s3-edges-present" {
+ putMemberEdges(t, store, ref, "", "test-data")
+ }
+ if mode == "edges-read-error" {
+ if err := os.MkdirAll(filepath.Join(root, edgesfile.Key(ref)), 0700); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if mode != "no-observer" {
+ ctx, cancel := context.WithCancel(context.Background())
+ done := fx.srv.StartHACapacityObservation(ctx)
+ t.Cleanup(func() { cancel(); haAwait(t, done) })
+ haAwait(t, fx.srv.haCapacity.Load().ready)
+ }
+ return fx, ref, root
+}
+
+func TestG3StatusReadersRetainUncertainRows(t *testing.T) {
+ for _, mode := range []string{"retired", "s3-retired", "s3-edges-present", "no-proof", "fixed", "pinned", "wrong-binding", "invalid-proof", "identity-read-error", "edges-read-error", "edges-present", "no-observer"} {
+ t.Run(mode, func(t *testing.T) {
+ fx, ref, _ := g3StatusWorld(t, mode)
+ owner := cliToken(t, fx, "paul@keymail.dev", "g3-status")
+ b := status.Box{Label: ref, GeneratedAt: time.Now().Add(-time.Hour), Metrics: &status.BoxMetrics{Release: "v0.25.0", Layout: &status.LayoutReport{Mode: "flat"}}}
+ if err := status.WriteBox(context.Background(), fx.rel, b); err != nil {
+ t.Fatal(err)
+ }
+ ignored := mode == "retired" || mode == "s3-retired"
+ st, out := getJSON(t, fx.ts.URL+"/api/cli/system/geoip", owner)
+ rows, _ := out["boxes"].([]any)
+ wantRows := 1
+ if ignored {
+ wantRows = 0
+ }
+ wantReady := mode != "edges-present" && mode != "s3-edges-present"
+ if st != http.StatusOK || out["ready"] != wantReady || len(rows) != wantRows {
+ t.Fatalf("GeoIP = %d %v, ignored=%v", st, out, ignored)
+ }
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/layout", map[string]string{"mode": "nested"}, owner)
+ want := http.StatusConflict
+ if ignored {
+ want = http.StatusOK
+ }
+ if st != want {
+ t.Fatalf("migrate = %d %v, want %d", st, out, want)
+ }
+ if !ignored && !strings.Contains(str(t, out, "error"), ref+" is stale") {
+ t.Fatalf("wrong migrate refusal: %v", out)
+ }
+ // Seed the real signed pointer history, then use the rollback door.
+ for _, version := range []string{"v0.19.0", "v0.25.0"} {
+ if _, err := release.PromoteSystem(context.Background(), fx.rel, release.RootSigner(fx.priv), "router", "canary", release.SystemRelease{Version: version, Artifacts: map[string]release.SystemArtifact{"linux-arm64": {Key: release.SystemArtifactKey(version, "linux-arm64"), SHA256: strings.Repeat("a", 64)}}}, release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ if version == "v0.19.0" {
+ time.Sleep(1100 * time.Millisecond)
+ }
+ }
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/rollback", map[string]string{"channel": "canary"}, owner)
+ if st != want {
+ t.Fatalf("rollback = %d %v, want %d", st, out, want)
+ }
+ if !ignored && !strings.Contains(str(t, out, "error"), ref+" is stale") {
+ t.Fatalf("wrong rollback refusal: %v", out)
+ }
+ if ignored {
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/layout", map[string]string{"mode": "nested", "box": ref}, owner)
+ if st != http.StatusConflict || !strings.Contains(str(t, out, "error"), "has not reported") {
+ t.Fatalf("named retired migrate = %d %v", st, out)
+ }
+ }
+ ef := &engineFixture{notifyFixture: newNotifyFixtureOn(t, fx)}
+ ef.heartbeat(t, ref, alertT0.Add(-time.Hour), nil)
+ ef.passesTo(t, 0, 5*time.Minute)
+ count := ef.count(t, `SELECT COUNT(*) FROM alert_incidents WHERE closed_at IS NULL AND rule = 'box_silent'`)
+ wantCount := 1
+ if ignored {
+ wantCount = 0
+ }
+ if count != wantCount {
+ t.Fatalf("box_silent incidents = %d, want %d", count, wantCount)
+ }
+ })
+ }
+}
+
+func TestG3RetiredHeartbeatClosesIncident(t *testing.T) {
+ fx, ref, root := g3StatusWorld(t, "edges-present")
+ ef := &engineFixture{notifyFixture: newNotifyFixtureOn(t, fx)}
+ ef.operator(t, opA)
+ ef.heartbeat(t, ref, alertT0.Add(-time.Hour), nil)
+ ef.passesTo(t, 0, 5*time.Minute)
+ if n := ef.count(t, `SELECT COUNT(*) FROM alert_incidents WHERE closed_at IS NULL AND rule = 'box_silent'`); n != 1 {
+ t.Fatalf("open incidents = %d", n)
+ }
+ if err := os.Remove(filepath.Join(root, edgesfile.Key(ref))); err != nil {
+ t.Fatal(err)
+ }
+ ef.passesTo(t, 6*time.Minute, 10*time.Minute)
+ if n := ef.count(t, `SELECT COUNT(*) FROM alert_incidents WHERE rule = 'box_silent' AND close_reason = 'box gone'`); n != 1 {
+ t.Fatalf("closed as box gone = %d", n)
+ }
+ if _, _, err := fx.rel.Get(context.Background(), "status/boxes/"+ref+".json"); err != nil {
+ t.Fatalf("status record changed: %v", err)
+ }
+ got := ef.mailsTo(opA)
+ if len(got) != 2 || !strings.Contains(got[1], "No further reports of box silent on "+ref) {
+ t.Fatalf("mail = %v", got)
+ }
+}
+
+func TestG3RetiredPlatformProofDoesNotHideFleetRow(t *testing.T) {
+ fx, ref, _ := g3StatusWorld(t, "retired")
+ owner := cliToken(t, fx, "paul@keymail.dev", "g3-fleet-status")
+ sizeFleet(t, fx, "same-label", fx.sqid)
+ _, fleets, err := fx.srv.systemFleets()
+ if err != nil || len(fleets) == 0 {
+ t.Fatalf("fleets = %v %v", fleets, err)
+ }
+ b, err := json.Marshal(status.Box{Label: ref, GeneratedAt: time.Now().Add(-time.Hour)})
+ if err != nil {
+ t.Fatal(err)
+ }
+ haPut(t, fx.rel, "fleets/"+fleets[0].Name+"/status/boxes/"+ref+".json", b)
+ st, out := getJSON(t, fx.ts.URL+"/api/cli/system/geoip", owner)
+ rows, _ := out["boxes"].([]any)
+ if st != http.StatusOK || out["ready"] != true || len(rows) != 1 {
+ t.Fatalf("fleet GeoIP = %d %v", st, out)
+ }
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/layout", map[string]string{"mode": "nested"}, owner)
+ if st != http.StatusConflict || !strings.Contains(str(t, out, "error"), ref+" is stale") {
+ t.Fatalf("fleet migrate = %d %v", st, out)
+ }
+}