| new file mode 100644 |
| index 000000000..0b2339d6b |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-05-region-ha-g3-b10.md |
| @@ -0,0 +1,70 @@ |
| +# Region HA G3-B10: born HA only in a named HA pool |
| + |
| +Plan, 2026-11-05. Spec: `2026-10-26-region-ha-without-claims-design.md` §23 (addendum B10). Branch `region-ha-g3-b10` from origin/main ddbc0297. Review budget: one Astra review of addendum and plan, at most three rounds; Opus task and branch reviews, at most three rounds (stopping rules). Ledger: `.superpowers/sdd/2026-11-05-region-ha-g3-b10/`. |
| + |
| +**Finish line.** A console on this branch, given `CONSOLE_HA_REGIONS=us` and a capacity config whose `us` entry has `"ha_pools":["ha"]`, creates a born-HA instance in app pool `ha` in `us` (proof against the configured US data bucket), creates a plain US instance exactly as with `us` not listed, and still refuses moves and imports touching `us`. Dev's config (no `ha_pools`) behaves as on main. No release, apply or drill. |
| + |
| +## Rulings |
| + |
| +| # | Ruling | |
| +|---|---| |
| +| R1 | Paul 2026-11-05: only named-HA-pool creates are born HA in a scoped region; plain creates stay legacy; no customer notice. | |
| +| R2 | Controller: the scope lives in `CONSOLE_HA_CAPACITY_CONFIG` (`regions.<code>.ha_pools`), the document that already names the region's data bucket. No new env var. | |
| +| R3 | Controller: create-path gates move to `haCreate(region, pool)`; transfer gates (moves, seed `--from`, import, placement changes, `haTransferRegion`, `refuseHAImport`, `apiplacements.go`) stay on `haRegion` (N-HA4). | |
| +| R4 | Controller: the non-home proof is two bounded LISTs (one key each) of whole prefixes, not the LTX level walk: stricter, and the console holds no litestream client for remote buckets. | |
| +| R5 | Controller: new or changed refusal sentences name regions by label (`offlinePlace`), not code. The no-room sentence (`nocapacity.go`) is in a touched file, so its "ie" is fixed too. One Luna pass, applied verbatim. | |
| + |
| +## Task 1: config and the predicate |
| + |
| +Files: `internal/console/hacapacity.go`, `internal/console/seedmove.go`, `internal/console/server.go`. |
| + |
| +- [ ] `haCoordinates` gains `HAPools []string \`json:"ha_pools,omitempty"\``; `haOnlyFields` for a region allows `ha_pools`. Present means: a JSON array, non-empty, each entry matches the pool-name rule the manifest uses for `Pool` (find it; do not invent one), distinct, never the shared pool (`""` or `@shared`). Anything else: `errHACapacity`. Absent: unscoped. `null` is already refused by `haJSON`. |
| +- [ ] Server start (`New` or where config is first read) parses `cfg.HACapacityConfig` once with `parseHACapacityConfig(raw, cfg.HARegions, cfg.HomeRegion)` and keeps `map[region code]pools` for scoped regions. Parse failure or empty raw: no scoped regions (log once). The observer's own parse is unchanged. |
| +- [ ] `func (s *Server) haCreate(region, pool string) bool`: `haRegion(region)` and (region unscoped or `pool` in its list). The home region `""` is looked up by `cfg.HomeRegion`, as `haRegion` does. |
| +- [ ] `shouldStampHA` uses `haCreate(rec.Region, rec.Pool)`. |
| +- [ ] Unit tests: parser accepts/refuses `ha_pools` shapes (absent, `[]`, duplicate, shared, bad name, non-array, case-variant key); `haCreate` matrix (unscoped home, scoped us with `ha`/""/other pool, non-HA region). |
| + |
| +## Task 2: create-path gates |
| + |
| +Files: `internal/console/apiinstances.go`, `hacreate.go`, `nocapacity.go`, `apisidecars.go`, `domainattach.go`. |
| + |
| +- [ ] Switch to `haCreate(region, <pool>)`, pool = `m.Pool` or `rec.Pool` as the line already has: `apiinstances.go` app-derived eligibility (~1839), `checkPlacement`'s `roomIn` skip (~1957), the placement order (~2010, ~2345), the HA duplicate read (~2281); `haCreateShapeRefusal` (F1, uses `rec.Pool`); `requireHACreateCapacity` (its `pool` argument); `apisidecars.go` `rec.HA` (~369) and the duplicate read (~418); `domainattach.go` `haRegion("")` (~228, pool of the record it would write, `""`). |
| +- [ ] Leave on `haRegion`: `seedmove.go` transfer helpers, `apiinstances.go` seeded block (~2330), `apiplacements.go`, the observer and metrics. Grep every `haRegion(` caller and list each with its class in the ledger. |
| +- [ ] `noCapacityRefusal` / `noRoom`: user-facing region becomes the label (`offlinePlace`); the alert and log keep the code. |
| + |
| +## Task 3: the proof outside home |
| + |
| +Files: `internal/console/createleftovers.go`, `internal/console/server.go`, `cmd/console/main.go`. |
| + |
| +- [ ] `Config.HADataStores map[string]release.Store` (region code to the region's data bucket). `cmd/console/main.go` builds one per scoped, non-home region from the parsed config (`release.NewS3StoreIn(ctx, data_bucket, data_bucket_region)`, wrapped like `seedData`). Build failure: no store for that region (creates there answer 503). Put the construction in a named function so a test drives it. |
| +- [ ] `leftoverReplicaRefusal`, HAData branch: F5 stays only for unscoped regions (non-home or pooled, as today). For a scoped region: |
| + - home: today's proof (SeedData whole prefix, then the moves LTX walk); the pool no longer blocks authority. Authority = `HibernateBucket != ""`, `SeedData != nil`, record region equals `cfg.Region`. |
| + - non-home: store = `HADataStores[region]`; nil or not a `PageLister` is 503 `unsure`. `firstHALeftover(store, <HibernatePrefix(host)>/)`, then `firstHALeftover(store, moves/<host>/)`. Either error is 503; any key is 409 naming the class (reuse `firstHALeftover`'s class; staging is "replica"). Log errors with the host, never return the bucket name. |
| +- [ ] Sentences: `unsure` and the F5 sentence name the region by label. F5's text is otherwise unchanged (approved copy). |
| + |
| +## Task 4: witnesses (production wiring) |
| + |
| +Files: new `internal/console/ha_pool_scope_test.go`; `cmd/console/` test for the store builder. |
| + |
| +Through the real handlers (`POST /api/cli/apps/<acct>/<app>/instances`, sidecar create), real `Server` construction, a DirStore or fake-S3 deployment store, and a counting `PageLister` fake for the US store. Config: home `ie`, `CONSOLE_HA_REGIONS=us`, capacity config with `us.ha_pools=["ha"]`, an observation allowing pool `ha` in `us`. |
| +- [ ] Pool `ha` in `us`: 201, record `ha:true`, region `us`, pool `ha`; the US store saw exactly `instances/<host>/` then `moves/<host>/`, limit 1 each; the home store saw nothing. |
| +- [ ] Unpooled in `us`: 201, `ha:false`; no HA capacity decision, no US store call; same answer and record as with `CONSOLE_HA_REGIONS` empty (compare the two responses). |
| +- [ ] Pool `other` in `us`: legacy, as above. |
| +- [ ] Leftover under `instances/<host>/` and under `moves/<host>/`: 409, zero writes (record, lifetime, store grant, index). |
| +- [ ] US store missing, list error: 503, zero writes. |
| +- [ ] Non-hibernating binary socket in pool `ha`: F1 400; unpooled: allowed as legacy. |
| +- [ ] Move into `us` and out of `us` of a legacy record, and seed import into `us`: still refused with the existing sentences. |
| +- [ ] Dev shape (`ie` home, `CONSOLE_HA_REGIONS=ie`, no `ha_pools`): existing `ha_born_test.go`, `hacreate_test.go`, `hacreatecapacity_test.go`, `sidecar_ha_test.go` pass unmodified; a pooled `ie` HAData create still gets F5. |
| +- [ ] Store builder test: config with `us` (bucket, region) and `ie` home yields one store for `us`, none for home, with the configured bucket and region. |
| + |
| +Run: `nice -n 19 go test ./internal/console -run 'HA|Leftover|Sidecar|Capacity|Rootfs' -count=1` and `go test ./cmd/console -run <builder test> -count=1`. `go vet ./internal/console ./cmd/console`. GOOS=darwin and windows `go build ./...`. |
| + |
| +## Task 5: copy, docs, census |
| + |
| +- [ ] Extract every new or changed user-facing sentence; one Luna pass; apply verbatim (no em dashes). |
| +- [ ] `docs/site/cli.md` lines that quote F5 or describe HA creates: update if the behaviour they state changed. |
| +- [ ] If CI's census fails, `make census-card`, CLAIMS, `make census-propose NAME=region-ha-g3-b10`; Opus approval recorded on #280. |
| + |
| +## Out of scope |
| + |
| +IAM (G3 card item 3), the release, the console drop-ins (card item 10, which gains `"ha_pools":["ha"]`), dev, moves and imports into HA regions (P4, P5), box-side changes. |