carlos / platform Public

plan: region HA G3 fixes (steering, departures, pooled region, startup)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev eb3b88a2528d651da3c050b727665974bf9bbc0c parent cf76222
1 file changed, +174 −0
  • docs/superpowers/plans/2026-11-07-region-ha-g3-fixes.md +174 −0

Intent

Human

<task-notification> <task-id>a35ee4b968625a667</task-id> <tool-use-id>toolu_01QnMXs5V38MnBHXhaUViXdM</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/a35ee4b968625a667.output</output-file> <status>completed</status> <summary>Agent "Investigate G3-F2 and G3-F1" 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>I wrote the findings to `.superpowers/sdd/region-ha-g3-fixes/inv/f2-f1.md`. Nothing was edited, committed or run against AWS. One F1 link is unproven, noted at the end. - **F2 cause:** the app-region default at `internal/console/apiinstances.go:1814-1825` is skipped because `m.Pool == ""` is false. The region stays "" (home ie), `haCreate("", ha)` is false (`seedmove.go:40-49`), and the record is legacy. The pooled exclusion came in with 3f4a9bfd (design-nearest-region, 2026-10-03). The spec (`2026-10-01-nearest-region-default-design.md:637`) says "a defaulted region with no box serving the pool mints nowhere". It predates `ha_pools`. - **F2 fix:** apply the app's region for a pooled manifest only when the pool is in that region's `ha_pools`, using a strict `len(s.haPools[r])&gt;0 &amp;&amp; slices.Contains(...)` test. Don't reuse `haCreate`: it is true for any pool when the region has no list. A pooled app whose region has no such pool stays on home, as today. That is about 15 lines in `apiinstances.go` plus a helper next to `haCreate`, low risk. Extend `regiondefault_test.go`, `apiinstances_test.go` (`TestAPIInstanceCreateUnplacedHonorsBodyRegion`), `hacreate_test.go` and `hacreatecapacity_test.go`. - **F1 mechanism:** `runHAIngressStartup` (`internal/host/haingress.go:145`) makes four attempts, each bounded by a 5 s deadline (`haIngressStartupAttempt`, line 141). `RecordView.Refresh` (`internal/provision/recordview.go:~179`) leaves failed scopes pending until the next `Refresh`. The 30-minute backstop loop only starts after startup ends. Admission needs `Reconciled`, set at `agent.go:2150-2152` only after a clean provision pass, and that pass shares `reconcileMu` with the startup attempts. - **F1 fix:** do both of these, about 25 lines across `internal/provision/recordview.go` and `internal/host/haingress.go`, low to medium risk. - Retry the failed scopes once inside `Refresh`. - Raise the first attempt's deadline, for example to 15 s or one sized to the record count. - The bigger option, not holding `reconcileMu` across the network read, is about 40 lines and medium risk because of lock order. - Tests to extend: `haingress_startup_test.go`, `haingress_test.go`, `recordview_test.go`, `recordview_sim_test.go`, `group_admission_test.go`. - **Not proven:** I found no explicit "admission waits for HA ingress" gate, and I didn't trace why the instance pass itself failed between 12:00:34 and 12:01:26. The link rests on the shared `reconcileMu` and the incomplete record view. Check the journal for pass errors in that window before committing to the fix.</result> <usage><subagent_tokens>74142</subagent_tokens><tool_uses>15</tool_uses><duration_ms>152329</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>af53dc019a896feba</task-id> <tool-use-id>toolu_01LUMaTheDhz8bqSCXA7nfjD</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/af53dc019a896feba.output</output-file> <status>completed</status> <summary>Agent "Root-cause G3-F4 steering batch" 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>Group members became DNS targets because `armedEdges` (`internal/steering/steering.go:119`) only checks for an EIP and an AWS-region-shaped `region`, and its file reader (`:73`) never reads `serves_shared_pool`. The specs say per-box latency steering stays off (two-box spec line 294; placement spec line 301, "spec 4's"). In group mode each region is reached through its NLB's one address, so group members are never targets. Findings are in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-g3-fixes/.superpowers/sdd/region-ha-g3-fixes/inv/f4.md`; nothing was run or edited besides that file. 1. **Why it wedges:** `applyChanges` (`internal/steering/route53.go:930-952`) sends changes in chunks of 100 and stops at the first failed chunk. Later chunks and the health-check cleanup never run, and nothing retries until the next 5-minute pass. The inputs are identical each pass, so chunk 0-100 fails every time. A health check per member EIP was created before the first batch failed (`:273-305`). Those checks will be deleted on the first pass that succeeds. 2. **No guard against the rule:** nothing enforces one latency record per (name, type, region). `dedupeRecords` keys on (name, box), and `conflictedNames` only catches CNAMEs, plain A records and other routing policies. The test fake's `validateZone` (`route53_test.go:81`) doesn't model the rule either, which is why tests never caught this. Other ways to hit it: two fixed shared-pool boxes in one AWS region (the platform box included), a dead or renamed box's stale edges file (steering has no freshness check), a box swap within one region (upserts go before deletes and can land in different chunks), or another latency record already in that region. 3. **Fix:** add `ServesSharedPool *bool` to the file reader and skip edges that publish `false`, logging the skip; treat a missing field as "keep" for older boxes. Don't use the `g-` name shape: the code itself notes fixed labels may also start with `g-`. On the flagship, adi publishes `served_pools ['']` and the members publish `false`, and the member records never landed, so nothing gets deleted. For resilience I recommend allowing at most one edge per AWS region in the same place, picked deterministically and logged loudly. A pre-send check or splitting the batch on InvalidChangeBatch would only be fallbacks. 4. **Tests:** the existing tests are in `internal/steering/steering_test.go`, `route53_test.go` (including `TestConvergeBatchesChanges` at `:1099`) and `deployment_test.go`. The `internal/host/steering_loop_test.go` tests use a recorder and never reach the real converge. A production-wired reproduction needs: - the closure at `steering_loop.go:237-241` pulled out into a named function that both the loop and the test call; - a Route 53 fake that applies batches atomically and rejects a second latency set in a region; - a world like G3: adi plus three `g-` files (one stale) and about 135 changes; - assertions that the unfixed code fails on batch 0-100 and the fixed code converges, writes no `g-` records or checks, and makes zero writes on a second pass.</result> <usage><subagent_tokens>110422</subagent_tokens><tool_uses>20</tool_uses><duration_ms>265817</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bb7xkdo7r</task-id> <tool-use-id>toolu_01GZNaS4wSdqC2EPgNz8USGS</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/bb7xkdo7r.output</output-file> <status>completed</status> <summary>Background command "cd /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-g3-fixes/.superpowers/sdd/region-ha-g3-fixes/inv &amp;&amp; for i in $(seq 1 120); do [ -s f4.md ] &amp;&amp; [ -s departure.md ] &amp;&amp; [ -s f2-f1.md ] &amp;&amp; break; sleep 10; done; ls -la" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>ab2fe5c09001e3efb</task-id> <tool-use-id>toolu_01CZPbAHWSQXFnuYrynDMBDf</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/f72ef775-81b3-4d2e-a18d-c8edb14aa192/tasks/ab2fe5c09001e3efb.output</output-file> <status>completed</status> <summary>Agent "Root-cause blocked HA departure" 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>The departure was most likely slow rather than stuck. One host waiting out the dead box's lease made the whole first scan of the deployment crawl at 5 minutes per page. One read-only check on adi would confirm it. Findings are in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-g3-fixes/.superpowers/sdd/region-ha-g3-fixes/inv/departure.md`. 1. **What fired:** the scan reads 32 records per pass, and its unresolved count adds up across the whole walk, resetting only when the walk ends (`hadepartures_scan.go:294`). The unexpired lease on g3-ha-1 (`:258-262`) marked every later page `blocked` (`:312`, `:328-330`), and `blocked` takes the failure backoff of 30 s, 1 m, 2 m, then 5 m (`ha_journal.go:487-497`). The scan covers every record in the deployment, about 260, so that is 9 pages. That matches the scan v9, `blocked`, RetryCount 3 state you saw at the end of the first walk. RetryCount 3 only caps the backoff at 5 min; it is not a stop. Pages are claimed at most once an hour (`ha_journal.go:507`), so the silence after 13:15 is expected. 2. **Ruled out:** - **Coverage-gap rule (`hadepartures.go:59`):** it compares raw region strings, with no "home" lookup. The region-less sidecar has "" and the departed box has "us", so it never matched. - **Hosts in other buckets:** their locks come back NoSuchKey, are treated as absent and skipped. g3-ha-1 was the only lock in carlos-data-us. - **Takeover race:** a higher-generation lock held by a known peer counts as recovery ("superseded", `:218-235`). 3. **Expected timing:** finalize around 13:40-13:46Z. Deleting g3-ha-1 at 13:44:56Z changed the inventory and restarted the walk, so adi alone should have finished a little later. **To confirm:** read adi's `ha_departure_scans` and `ha_departures` rows, grep its journal for `Recovered duties .* g-cfbd25eb`, and check whether the edges file is gone. If it is still `blocked` well past about 14:15Z, there is a real persistent blocker. Two latent candidates are in the file: - a once-seen lock that later disappears (`:178-181`); - the dead box's edges-file ETag going stale after its 13:00:28Z write, which would loop on `replacement_binding` in `complete` (`:463-467`). 4. **Dev:** the dead member held no lease, so every page was clean and paced at 30 s. A small inventory means a clean walk plus the rescan in about a minute. 5. **Fix, in `ScanPass`:** count lease-expiry waits separately from real blockers. Never back off or page an unfinished walk because of a wait. When only waits remain at the end of a walk, set the next attempt to just after the earliest lease expiry, with no page. Adopt-before-delete and "a peer's takeover by expiry counts as recovery" stay as they are, which matches spec §7.4/§9.3/§9.4. With the fix, G3 would have finalized around 13:24Z. 6. **Tests:** `TestDepartureWaitsExpiry` and the other scan tests use one page and a test clock that jumps 301 s per pass, so they never see the backoff. No test combines more than 32 records, an unexpired lease held by the dead box, a peer takeover and the real retry timing. The file lists the existing test names and what a production-wired reproduction needs: run passes only when the departure is due, take over with a known peer at expiry, and require completion within 2 × pages × 30 s. It fails on current code. I edited no tracked files, made no commits and did not touch AWS.</result> <usage><subagent_tokens>171364</subagent_tokens><tool_uses>37</tool_uses><duration_ms>537537</duration_ms></usage> </task-notification>

Attributed to this commit: 43.3 g CO₂e (4,802,744 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-g3-fixes, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/plans/2026-11-07-region-ha-g3-fixes.md b/docs/superpowers/plans/2026-11-07-region-ha-g3-fixes.md
new file mode 100644
index 000000000..4bb577212
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-07-region-ha-g3-fixes.md
@@ -0,0 +1,174 @@
+# Region HA G3 fixes — plan
+
+Branch `region-ha-g3-fixes` from origin/main cf762224. Spec:
+`docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md`
+(§7.4 scan and import, §9.3 after confirmation, §9.4 expiry), the two-box
+spec `2026-10-15-region-ha-two-box-regions-design.md` (line ~294: per-box
+latency steering stays off) and the nearest-region spec
+`2026-10-01-nearest-region-default-design.md` (:637, :945 pooled defaults).
+Evidence: the G3 flagship log (13:00-13:45Z 2026-11-07). Root-cause notes
+from read-only investigation are in the SDD workspace `inv/` (f4.md,
+departure.md, f2-f1.md); each task brief below carries what it needs.
+
+## Global constraints
+
+- Never rebase. Small commits; subjects < 80 chars; gofmt clean.
+- Local tests: run the FULL test set of each package you touch
+ (`go test ./internal/<pkg>/ -count=1`), not only `-run`; cross-package
+ census/inventory tests (e.g. `TestGroupNameClassCensus`,
+ `TestPlan14RootReadCensus` in internal/provision) must stay green or be
+ reported. Socket-binding packages (host, edge, activator) need
+ `TMPDIR=/tmp/g GOFLAGS=-buildvcs=false` (mkdir -p /tmp/g). GOCACHE default.
+- Production-wired witnesses: acceptance tests go through real constructors
+ and the real entry point a running box calls, not stand-ins of the seam
+ under test.
+- No AWS calls, no release, no apply.
+- No copy changes beyond log lines; user-facing strings unchanged unless the
+ task says so.
+
+## Task 1: steering never targets pool-only boxes, and one bad change cannot wedge the converge (G3-F4)
+
+Cause (internal/steering): `armedEdges` (steering.go:~119) accepts any edges
+file with an EIP and an AWS-region-shaped `region`; the file reader (~:73)
+never reads `serves_shared_pool`. Group members (`serves_shared_pool:false`,
+`named_pools:[ha]`) became latency targets in us-east-1 beside the fixed box
+adi, and Route 53 allows one latency RRSet per (name, type, region).
+`applyChanges` (route53.go:~930-952) sends chunks of 100 and stops at the
+first failed chunk (later chunks and the health-check cleanup never run), so
+every 5-minute pass failed on chunk 0-100 of 135. Nothing enforces one
+latency target per (name, AWS region); the test fake `validateZone`
+(route53_test.go:~81) does not model the rule either.
+
+Do:
+1. Membership: read `serves_shared_pool` (`*bool`) in the edges reader; an
+ edge that publishes `false` is never a steering target (log once per
+ pass which refs were skipped and why). Absent field = keep (older boxes).
+ Do not key on the `g-` name shape.
+2. Invariant, enforced in ONE place before building changes: at most one
+ steering target per AWS region. When several qualify, keep the one an
+ existing latency record in that region already points at (stability);
+ otherwise the lowest box ref. Log the dropped refs loudly (error level).
+3. Resilience: a failed chunk must not stop the others. On
+ InvalidChangeBatch, bisect the failed chunk down to the single offending
+ change(s), apply the rest, and log each refused change with its name,
+ set identifier and Route 53 message; deletes keep their order before
+ upserts within a chunk. The health-check cleanup runs whatever happened
+ to the record chunks, but never deletes a health check a surviving
+ record still references. Report the converge as partially failed (error
+ returned or counted) so it is visible.
+4. Test fake: make the Route 53 fake apply each ChangeBatch atomically and
+ reject a second latency RRSet for the same (name, type, region) with
+ InvalidChangeBatch, as Route 53 does.
+5. Production-wired test: extract the closure the housekeeper loop runs
+ (internal/host/steering_loop.go:~237-241) into a named function that the
+ loop and the test both call. Build the G3 world: fixed box adi (us-east-1
+ EIP, shared pool), three group-member edges files (serves_shared_pool
+ false, named_pools [ha], one of them the dead member), plus enough
+ steered hosts that the first pass needs ~135 changes. Assert: on the
+ unfixed membership the fake would refuse (prove the fake enforces the
+ rule with a direct test); with the fix, the first pass converges, writes
+ no record or health check for any g- ref, and a second pass writes
+ nothing. Separate test: a world with one conflicting change among 135
+ applies the other 134 and logs the one.
+
+Files: internal/steering/{steering.go,route53.go,*_test.go},
+internal/host/steering_loop.go (+ test). Review: own Opus review (DNS of
+every tenant).
+
+## Task 2: a departure waiting out a dead holder's lease finalizes promptly (G3 departure)
+
+Cause (internal/host/hadepartures_scan.go, `ScanPass`): the walk covers the
+whole deployment inventory (~260 records on the flagship, 32 per page = 9
+pages). A dead-owned, unexpired lock (:258-262) correctly sets `NotBefore`
+and counts as Unresolved, but `Unresolved` is cumulative across the walk
+(:294), so every later page ends `retryScan(..., "scan", page=true)` which
+maps to `"blocked"` (:312, :328-330), takes the failure backoff ladder
+30 s/1 m/2 m/5 m (internal/registry/ha_journal.go:487-497) and pages
+("Duties ... have not been recovered", hourly). Completion then needs a
+clean walk plus an independent rescan walk. On the flagship the dead file
+was still present 55 minutes after termination. Waiting for expiry is
+correct (spec §9.4); treating the wait as a failure is the bug.
+
+Do:
+1. Track lease-expiry waits separately from real blockers in the scan
+ state (e.g. `Waiting` and the earliest `NotBefore`), reset wherever
+ `Unresolved` resets (:132, :303).
+2. A page whose only unresolved items are waits ends with code `"scan"`
+ (no backoff, no page, RetryCount reset): the walk keeps moving at 30 s.
+3. At walk end with only waits left: no page, code `"scan"`, next attempt =
+ max(now + 30 s, earliest NotBefore + small margin) so the next walk
+ starts right after expiry.
+4. Unchanged: adopt-before-delete; a validated higher-generation successor
+ (a peer's takeover by expiry) counts as recovery (:218-235); real
+ blockers still back off and page.
+5. Production-wired test through `armHADepartures`/the real journal,
+ `ValidateSuccessor` and `Adopt` (see `testDepartureWiringImportMode` in
+ hadepartures_production_test.go): inventory of ~100 records (more than 3
+ pages; the others have no lock in the data bucket), the HA host on page 1
+ with lock.json owned by the dead bound group ref, HA owner, expiring in
+ 15 min; a test clock that runs a pass ONLY when the departure's
+ next_attempt is due. Variants: (a) a bound peer takes the lock over at
+ expiry + 5 s (gen+1); (b) no takeover, the scanner adopts after expiry;
+ (c) the successor is unbound: stays unresolved, backs off and pages.
+ For (a) and (b) assert: nothing adopted or deleted before expiry; no page
+ and no `blocked` while only waiting; then phase complete, the edges file
+ deleted on its ETag, the SQS receipt acked, within 2 × pages × 30 s +
+ 1 min of expiry. This test must fail on cf762224.
+6. Repeated fault family (departures not finalizing: G2 W3, G3): state the
+ invariant in a comment at the decision point — "a departure finalizes
+ within a bounded time after every dead-owned lease has expired, unless a
+ real blocker exists, and never deletes the edges file before every
+ dead-owned host is adopted or superseded" — and add ONE seeded
+ simulation (deterministic seeds, default ≤ 200 seeds, `-short`-friendly)
+ over random inventory sizes (1-300), random lease states per host (none,
+ released by dead box, dead-held unexpired with random expiry, peer
+ takeover after expiry, unbound successor), random page positions,
+ checking both halves of the invariant.
+
+Files: internal/host/hadepartures_scan.go, internal/registry/ha_journal.go
+only if the retry API needs the explicit next time, tests in internal/host.
+Review: own Opus review (termination path).
+
+## Task 3: a pooled app's instance auto-create honours the app's HA region (G3-F2)
+
+Cause: internal/console/apiinstances.go:~1814-1825 applies the app's region
+default only when `m.Pool == ""` (nearest-region spec :637, written before
+`ha_pools`). `carlos deploy` auto-create of a pooled HA app (app region us,
+pool ha, us has `ha_pools:[ha]`) therefore created a home-region legacy
+record nobody serves.
+
+Do: when the request has no region and the manifest names a pool, apply the
+app's region if and only if that pool is listed in that region's
+`ha_pools` (strict: `len(s.haPools[r]) > 0 && contains`; do NOT reuse
+`haCreate`, which is true for any pool when a region has no list). Everything
+else unchanged (a pooled app whose region does not list the pool stays on
+home as today). Add a small helper next to `haCreate` (seedmove.go). If the
+region-guess endpoint reports `pooled` for such an app, make it use the same
+predicate so the CLI and the door agree. Tests in internal/console
+(regiondefault_test.go, apiinstances_test.go, hacreate_test.go): pooled +
+ha_pools → region us, stamped HA; pooled with a pool not in the region's
+list → unchanged; explicit region still wins. Census: the console create
+path may be in the root-read census; run internal/provision's census tests.
+
+Review: covered by the whole-branch review.
+
+## Task 4 (if small): startup HA ingress does not hold admission on transient record re-reads (G3-F1)
+
+Evidence: on adi (74 hosts) the startup HA ingress pass
+(internal/host/haingress.go:~145, 4 attempts each bounded by
+`haIngressStartupAttempt = 5 s`, :141) failed twice with "incomplete record
+view" after `RecordView.Refresh` (internal/provision/recordview.go:~179)
+left 8 failed scopes pending "until the next refresh"; admission opened 57 s
+after start. The coupling to admission (`Reconciled`, agent.go:~2150) is via
+the shared `reconcileMu` and the shared view; it is not proven.
+
+Do: first write a test that reproduces the delay mechanism (a view with ~80
+scopes where a few reads fail once): show how many refreshes the startup
+pass needs today. Then: (1) inside `Refresh`, retry the scopes that failed
+once more within the same call while the context has time; (2) size the
+startup attempt deadline to the record count (e.g. 5 s + 50 ms per scope,
+capped at 20 s). If the test shows admission is not gated by this path at
+all, stop and report instead of changing it.
+
+Files: internal/provision/recordview.go, internal/host/haingress.go (+
+tests). Review: whole-branch review.