plans: G6 pool path implementation plan
1 file changed,
+460
−0
docs/superpowers/plans/2026-11-12-g6-pool-path.md+460 −0
Intent
diff --git a/docs/superpowers/plans/2026-11-12-g6-pool-path.md b/docs/superpowers/plans/2026-11-12-g6-pool-path.md| new file mode 100644 |
| index 000000000..8a2d80c26 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-12-g6-pool-path.md |
| @@ -0,0 +1,460 @@ |
| +# G6 Pool Path (born-HA apps for allowed accounts) Implementation Plan |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** An account on `CONSOLE_HA_POOL_ACCOUNTS` can create an app with high availability in a region that has a scoped HA pool (CLI `carlos apps create --ha`, or the web form's checkbox), its first instance is born HA, and nobody else can put a record into a scoped HA pool by any door. |
| + |
| +**Architecture:** The HA choice is stored once, on the app row (`apps.ha_pool`, written in the same insert as the row). The existing person-only enable door is the only writer of the manifest's `Pool`, and it copies `Pool` and `Regions` from the live row on the manifest's first create only. One gate, `haPoolAllowed`, guards every door that can write a record into a scoped HA pool; the row binds the region, so the region doors, the place door and the swap door refuse changes for a born-HA app. |
| + |
| +**Tech Stack:** Go, SQLite (console store), `html/template` console pages, the `carlos` CLI (root package). |
| + |
| +**Spec:** `docs/superpowers/specs/2026-11-11-g6-pool-path-design.md` (rev 3). Also read `docs/superpowers/reviews/CODEX-FINDINGS-G6-R1.md` (G6-1.8, 1.9, 1.12) and `R2.md` (G6-2.5, 2.8), and `docs/superpowers/specs/2026-11-11-g6-us-capacity-design.md` §3 (swap concurrency held to 1 for born-HA apps). Region HA parent: `docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md` §23 (B10). |
| + |
| +## Spec corrections (verified against this tree, 3d332f24) |
| + |
| +The spec cites `origin/main` at 01d6ca78. Lines have moved; some claims were wrong. |
| + |
| +1. `apiinstances.go:1531` ("stamped from the MANIFEST") is now `:1573`; `:2160` (`Pool: m.Pool`) is `:2218`; the explicit-region handling cited as `:1871-1888` is `:1928-1955` (app-derived default) and `:2048-2055` (allow-list); `apiPerson` in the enable door is `:3545-3547`; the `os.ErrNotExist` first-create branch is `:3633-3634`; "Pool and Regions survive" is `:3650-3655`. |
| +2. `apicli.go:411` is `:412`; the route is `routedecls.go:490` (not 489); the enable route is `routedecls.go:613` (not 612). The browser create route is `routedecls.go:226`. |
| +3. The apps table is created at `store.go:209`; `store.go:828-856` is `migrateAppsKey`'s rebuild DDL. A column added in the main ALTER list (`store.go:540-644`) is DROPPED by that rebuild on a pre-accounts database, because the rebuild copies a fixed column list. New `apps` columns are added AFTER `migrateAppsKey` (precedent: `links_store.go:69-76`, called from `store.go:692`). Every row is inserted by `insertAppRow` (`lifetimes_store.go:478`). |
| +4. `server.go:5337-5343` (`claimTaken`) is `validateClaimAppName` `:5398-5404` and `claimNamePrefixes` `:5371`; the row insert is `claimAppWith` `:5532-5541` (`CreateAppInRegion`). `claimNamePrefixes` also lets an OWNER adopt objects already under the app's prefix (`adoptingExistingApp`); that is an existing app in all but row, so an HA create must refuse it (G6-1.9's "refuse unrelated existing apps"). |
| +5. `handleNewApp` is `server.go:5651`, not `:5590`; the form page is `handleNewAppForm` `:5627`. |
| +6. `appregionset.go:187` is not the PUT door: `handleAPIAppRegionSet` is `:228`, the browser door `handleAppRegionSet` `:420`, both through `setAppRegion` `:264-378`. The conditional update is `Store.SetAppRegion`, `store.go:1933-1950`. It is the only writer of `apps.region`. |
| +7. `regioncandidates.go:289-294` is inside `appPolicy` `:284-310`. |
| +8. The swap door has a SECOND, browser form: `appswap.go:20` (`handleAppSwap`). Both go through `setCopiesSwapPolicy` (`copiespublication.go:256`), which is where the refusal belongs. |
| +9. `cmd/console/main.go:1157-1191` is now `sidecarAccounts` at `:1178-1212`; it is called at `:358-363` (before the database opens) and wired into `Config` at `:637`. The header comment block for env vars is `:58-64`. |
| +10. `approved_region_ha_copy_test.go` does not exist. The approved-copy pattern is `approved_burst_copy_test.go` / `approved_protection_copy_test.go`. |
| +11. The domain-attach first route (`domainattach.go:308-313` and `:737-742`) always writes `Kind: "static"` with `Pool: ""`, and demo claims (`demo_claim_seed.go:176-188`) and demo publish (`demo_publish.go:179-193`) never set a pool. None of them can write into a scoped pool, so they get a guard test, not a gate call. The doors that can are the instance create door (plain, `--from`, import, restore, host-claim and lifetime arms all pass one point) and the standalone sidecar create door. |
| +12. A third door changes a born-HA app's effective region: `carlos apps place` (`placeAppTarget`, `fleets.go:809`, also the Settings > Placement form). A placed app's instances take the fleet as their region and skip the manifest's allow-list (`apiinstances.go:2048`). It is refused for an `ha_pool` row like the region doors (G6-2.5's invariant), and `apps create --ha --place` is refused. |
| +13. Spec §2 says dev IE carries `ha_pools: ["hapair"]`; RHA §23 says dev IE carries none. That is live configuration, checked under "After merge", not code. |
| + |
| +## Global Constraints |
| + |
| +- Paul's rulings 2026-11-12: US capacity 2 x t4g.medium; the pool allowlist is the env list `CONSOLE_HA_POOL_ACCOUNTS` (unset or empty = nobody); the create checkbox text names the 15-minute bound. Fence ~30 s. Fresh create, no migration of existing apps. |
| +- `CONSOLE_HA_POOL_ACCOUNTS` parses exactly like `CARLOS_SIDECAR_ACCOUNTS` (trim, lower-case, `domains.ValidSqid`, a bad entry or a value naming no sqid stops `serve` before the database opens), with one difference: unset or `""` is nil, and nil means NOBODY. |
| +- COPY: no user-facing or operator-facing string is written into code or docs until Paul approves it. The copy review is OPEN. Every string is a named constant holding `"COPY-PENDING:<copy id>"` (with `%s` kept where the string has one); tests assert on the constant, never the literal. Task 8 swaps in approved text. Copy ids: `console.app_new.ha.label`, `console.app_new.ha.explainer`, `console.app_new.ha.docs_link`, `console.app_settings.ha.status`, `console.refusal.ha_not_allowed`, `console.refusal.ha_region`, `console.refusal.ha_needs_region`, `console.refusal.ha_region_locked`, `console.refusal.ha_swap_concurrency`, `cli.apps_create.ha_flag`, `cli.route.replication_ha_refusal` (fence slice, not this plan). This plan adds two ids the deck lacks (see "Decisions"): `console.refusal.ha_pool_mismatch`, `cli.apps_create.ha_unconfirmed`. Log lines and `log.Fatalf` startup errors are journal text, not copy-gated. Existing sentences reused unchanged are not new copy. |
| +- The machine code `ha-pool-not-allowed` is not copy; it is fixed now. |
| +- The branch does not merge while any `COPY-PENDING:` string remains (Task 8 adds the test that enforces it): the settings status line would show a placeholder to the flagship canary account. |
| +- Tests: targeted only, `go test ./<pkg>/ -run 'TestX|TestY' -count=1`; never `go test ./...`, never the full suite (CI on amadan runs it). `internal/console`, `cmd/console` and the root package bind sockets: run them with the sandbox OFF and `d=$(mktemp -d /tmp/g/g6pool-tN.XXXX) && TMPDIR=$d go test ...; rm -rf "$d"` (remove that exact dir; never a glob in `/tmp/g`, `/tmp`, `$TMPDIR` or `~/.cache`). `GOCACHE` stays at its default. Add `GOFLAGS=-buildvcs=false` only if VCS stamping errors appear. |
| +- Mutation checks only on refusal, security and lifecycle paths, at most ~10 per task, each a targeted `-run`; revert each mutation. |
| +- Commit subjects under 80 characters. Implementers never create or remove worktrees, never `git worktree prune`, never `git stash`, never push, never touch amadan. |
| +- Census: the root package (`apps.go`, `apimode.go`) is in the root binary, so Task 5 makes `TestPlan14RootReadCensus` fail until Task 7 proposes the overlay; Task 8 reruns it. `internal/console` and `cmd/console` are out of census scope. The reviewer (Astra) decides. |
| +- Wire shapes are additive: the create request gains optional `"ha"`, the create answer gains `"ha_pool"`/`"ha_status"` only when set, the manifest shape is unchanged. The new SQLite column follows the after-`migrateAppsKey` pattern (Spec correction 3). |
| +- Provider-neutral: console configuration and the bucket only; no cloud API calls. |
| +- Console security gate order holds (AGENTS.md): session, CSRF, owner/membership (byte-identical 404), then this gate. The gate never answers a non-member. |
| +- Review budget: one Astra plan review round is planned; per-task review only for Tasks 1-3 (security gates, stopping rule 3); everything else is covered by the whole-branch review. Plan to merge on green after Tasks 8 and 9 (one copy pass covers both). |
| + |
| +## Review Focus |
| + |
| +1. **HA in the HOME region** (dev: IE is home and the HA region). The row stores `""`, the manifest gets `Regions: [""]`, and an instance create naming the home's code must pass while any other region is refused. Test: Task 3 `TestEnableHAHomeRegion`. |
| +2. **New CLI, older console.** An older console ignores `"ha"` and creates a plain app with a 200. The CLI must fail loudly, naming the app, not print success. Test: Task 5 `TestHAMismatchErr`. |
| +3. **Owner adoption with `--ha`.** An owner may adopt objects already under the name's prefix; with `ha` that would turn an existing app's history HA. Expect `409 that name is taken`, no row. Test: Task 2 case (g). |
| +4. **Placement.** `carlos apps create --ha --place fleet/x` and `carlos apps place` on a born-HA app must refuse, before and after enable. Test: Task 2 case (e), Task 4 `TestPlaceRefusesHAApp`. |
| +5. **Broken HA config** (`CONSOLE_HA_CAPACITY_CONFIG` invalid while `CONSOLE_HA_REGIONS` is set, `haScopeInvalid`). The pool's scope is unknown, so the gate fails closed for every named pool in an HA region, and an HA app create is refused (400). Plain (pool `""`) creates are untouched. Test: Task 1 `TestHAPoolScopedPredicate` invalid rows, Task 2 case (h). |
| + |
| +--- |
| + |
| +## Decisions this plan makes (the spec leaves them open; none needs Paul) |
| + |
| +- `haPoolScoped(region, pool)` is: pool non-empty, region in `CONSOLE_HA_REGIONS`, and (scope invalid OR pool in the region's `ha_pools`). Fail-closed on an invalid config matches B10's "an invalid document is not unscoped". |
| +- The enable door re-checks the allowlist and the region only on the manifest's FIRST create. An update writes no pool, so a removed account can still change its HA app's channel; its new instances are refused at the instance door. |
| +- A 409 for "existing manifest has another pool" has no sentence in the deck: new id `console.refusal.ha_pool_mismatch` (only an operator's store-mode write can cause it). |
| +- The CLI's "the console did not confirm HA" failure has no sentence in the deck: new id `cli.apps_create.ha_unconfirmed`. The CLI's success line reuses the console's status sentence (`console.app_settings.ha.status`), echoed by the console as `ha_status`, so the CLI adds no other copy. |
| +- The place door and `create --place` reuse `console.refusal.ha_region_locked` and `console.refusal.ha_region` respectively. |
| +- Web: when the region picker is absent (switch off or fewer than two eligible regions) and the HOME region has an HA pool, the form still shows the checkbox for a listed account, with a hidden `region` input carrying the home's code. Otherwise dev, if it shows no picker, could not run exit test step 1 from the web form. |
| +- Web: for an app with the status line (or an `ha_pool` row), Settings > General shows the line in place of the region control. The door refuses regardless. |
| +- Settings status line: shown when the MANIFEST's pool is a scoped HA pool (spec §3.2), so the flagship canaries (legacy pooled manifests) show it too. |
| + |
| +--- |
| + |
| +### Task 1: The allowlist and the gate at the record doors |
| + |
| +**Read first (traps):** |
| +- Empty means NOBODY. Every existing test that creates into a scoped pool for account `bab` breaks unless its fixture lists `bab`. Set `c.HAPoolAccounts = []string{"bab"}` in `haPoolWorldNew` (`ha_pool_scope_test.go:107`, set just before `tweak(c)` at `:139`), and in any fixture in `apiinstances_test.go`, `hacreate_test.go`, `regiondefault_test.go`, `demo_claim_ha_gate_test.go` whose test creates into a scoped pool. Run every test in those files (list below) before committing. |
| +- The instance door's gate goes AFTER the region is final (`region = placed` or validated, `:2048-2055`) and after `ValidateShape` + `haCreateShapeRefusal` (`:2332-2339`), and BEFORE `environmentBindingRefusal` (`:2344`). Everything after that point (store ceiling, leftover LISTs, capacity, the seed doors, every write) is behind it. The restore, `--from`, import, host-claim and lifetime arms all pass this point. |
| +- The sidecar gate goes immediately after `refuseSidecarsPaused` (`apisidecars.go:381-383`), before `planLock`. |
| +- Do not gate the domain-attach first route, demo claims or demo publish (Spec correction 11). Pin that with the guard test instead. |
| + |
| +**Files:** |
| +- Modify: `cmd/console/main.go` (header comment `:58-64`, parse beside `sidecarAccounts` `:358-363`, `Config` literal `:637`, new func after `:1212`) |
| +- Create: `cmd/console/hapoolaccounts_test.go`, `cmd/console/hapoolaccounts_serve_test.go` |
| +- Modify: `internal/console/server.go` (`Config`: add `HAPoolAccounts` after `SidecarAccounts` `:1009`) |
| +- Create: `internal/console/hapool.go`, `internal/console/hapoolcopy.go`, `internal/console/hapool_test.go` |
| +- Modify: `internal/console/apiinstances.go:~2339`, `internal/console/apisidecars.go:~383` |
| +- Modify (fixtures only): `internal/console/ha_pool_scope_test.go` and the other scoped-pool test files above; the existing domain-attach first-route test (find with `grep -n 'func TestAttach.*First\|first route' internal/console/domainattach*_test.go`) |
| + |
| +**Interfaces:** |
| +- Produces (cmd/console): `func haPoolAccounts(getenv func(string) string) ([]string, error)` |
| +- Produces (console `Config`): `HAPoolAccounts []string` (nil = nobody) |
| +- Produces (`hapool.go`): |
| + - `func (s *Server) haPoolScoped(region, pool string) bool` |
| + - `func (s *Server) haPoolFor(region string) string` — the region's first `ha_pools` entry when `s.haRegion(region)` and the scope is valid, else `""`; region is record vocabulary (`""` = home; look up `s.haPools[s.homeRegionOut(region)]`) |
| + - `func (s *Server) haPoolListed(acct *Account) bool` — `slices.Contains(s.cfg.HAPoolAccounts, acct.Sqid)` |
| + - `func (s *Server) haPoolAllowed(acct *Account, region, pool string) bool` — `!s.haPoolScoped(region, pool) || s.haPoolListed(acct)` |
| + - `type haDoorRefusal struct { Status int; Msg, Code string }` |
| + - `func writeHARefusal(w http.ResponseWriter, ref *haDoorRefusal)` — JSON `{"error": Msg}` plus `"code": Code` when non-empty |
| + - `func (s *Server) haPoolRefusal(acct *Account, app, door string) *haDoorRefusal` — logs `console: <door> <sqid>/<app>: refused, account not in CONSOLE_HA_POOL_ACCOUNTS`, returns `{403, haCopyNotAllowed, haPoolNotAllowedCode}` |
| + - `func (s *Server) refuseHAPool(w http.ResponseWriter, acct *Account, app, region, pool, door string) bool` — false when allowed; otherwise writes `haPoolRefusal` and returns true |
| +- Produces (`hapoolcopy.go`, all used by later tasks): |
| + `haCopyLabel`, `haCopyExplainer`, `haCopyDocsLink`, `haCopyStatus` (`%s` = region label), `haCopyNotAllowed`, `haCopyRegion` (`%s`), `haCopyNeedsRegion`, `haCopyRegionLocked`, `haCopySwapConcurrency`, `haCopyPoolMismatch`, each `"COPY-PENDING:<copy id>"` (`"COPY-PENDING:console.app_settings.ha.status:%s"` and `"...ha_region:%s"` keep the verb); `haPoolNotAllowedCode = "ha-pool-not-allowed"`; `haDocsURL = "https://carlosframework.com/docs/high-availability"`. |
| + |
| +- [ ] **Step 1: Write the failing parse tests** (`cmd/console/hapoolaccounts_test.go`) |
| + |
| +`TestHAPoolAccountsParsesTheList`, the table of `TestSidecarAccountsParsesTheList` (`sidecaraccounts_test.go:12-28`) against `CONSOLE_HA_POOL_ACCOUNTS`, same rows and wants. Add one assertion the sidecar test does not need: for `""`, `got == nil` and the doc comment says nil is nobody. |
| + |
| +`TestServeStopsOnABadHAPoolAccount` (`hapoolaccounts_serve_test.go`): copy of `TestServeStopsOnABadSidecarAccount` with `CONSOLE_HA_POOL_ACCOUNTS`; output must name `CONSOLE_HA_POOL_ACCOUNTS` and the bad entry; no `console.db` created. |
| + |
| +- [ ] **Step 2: Run, expect FAIL** (`undefined: haPoolAccounts`) |
| + |
| +Run (sandbox off): `d=$(mktemp -d /tmp/g/g6pool-t1.XXXX) && TMPDIR=$d go test ./cmd/console/ -run 'TestHAPoolAccountsParsesTheList|TestServeStopsOnABadHAPoolAccount' -count=1; rm -rf "$d"` |
| + |
| +- [ ] **Step 3: Implement `haPoolAccounts`** mirroring `sidecarAccounts`, error prefix `CONSOLE_HA_POOL_ACCOUNTS:`; the "names no sqid" error says "unset it for nobody, or list at least one sqid". Call it beside `sidecarAccounts` before `openServeDB`, `log.Fatalf` on error, set `Config.HAPoolAccounts`. Header comment: what the list gates, that unset/empty is nobody, that operators are not exempt, that changing it is a console restart. |
| + |
| +- [ ] **Step 4: Run, expect PASS** (same command). |
| + |
| +- [ ] **Step 5: Write the failing gate tests** (`internal/console/hapool_test.go`) |
| + |
| +```go |
| +// TestHAPoolScopedPredicate: HARegions {ie, us}, us scoped ["ha"], ie unscoped. |
| +// valid config rows: (us,ha)=true (us,"")=false (us,other)=false (ie,ha)=false (uk,ha)=false ("",ha)=false |
| +// invalid config (HACapacityConfig ""): (us,ha)=true (us,other)=true (ie,ha)=true (us,"")=false (uk,ha)=false |
| +// haPoolFor: valid → us:"ha", ie:"", "":"" ; invalid → "" everywhere |
| +// haPoolAllowed(bab,"us","ha"): list nil → false; list ["bab"] → true; list ["cdef"] → false |
| +// haPoolAllowed(bab,"us",""): true with list nil |
| +``` |
| + |
| +`TestHAPoolGateInstanceCreate` — `haPoolWorldNew(t, "us", "ha", func(c *Config){ c.HAPoolAccounts = nil })`, keys := `sidecarAppKeys`-style listing of `apps/bab/titogo/` before: |
| +- plain `w.post(t, false, w.body(false))` → 403; body decodes to `{Error: haCopyNotAllowed, Code: "ha-pool-not-allowed"}`; app keys unchanged; `w.data.counts()` is `(0, nil)` (no proof LIST ran); no record at `acme.go.tito.io`. |
| +- the same body plus `"from":{"host":"<an existing sibling host>"}` → 403 with the same body (the seed arm is behind the gate). |
| +- a non-member's token (a fresh `cliToken` for an address with no membership) → 404, body byte-identical to the door's existing non-member 404. |
| +- with `HAPoolAccounts = []string{"bab"}` → 201 and the record has `HA: true, Pool: "ha", Region: "us"` (as `TestHAPoolScopedBirth`). |
| + |
| +`TestHAPoolGateSidecarCreate` — the same four assertions through `w.post(t, true, w.body(true))` and `provision.GetSidecarRecord`. |
| + |
| +`TestHAPoolGateLeavesLegacyAlone` — list nil, account bab: |
| +- `haPoolWorldNew(t, "us", "", ...)` (manifest pool `""`): instance create → 201 legacy (`HA: false`); |
| +- `haPoolWorldNew(t, "ie", "ha", ...)` with ie's entry made unscoped (pass a tweak that sets `HACapacityConfig = haPoolRaw("ie", false)`): create → not 403 (answer equals what it was before this task: run it once on the base commit and pin the status). |
| + |
| +Guard: in the existing domain-attach first-route test, make the app's manifest `Pool: "ha"` in a scoped region and assert the written record's `Pool == ""` and `HA == false`, with a comment: the first route never carries a pool, so it needs no HA gate (Spec correction 11). |
| + |
| +- [ ] **Step 6: Run, expect FAIL** (`undefined: haPoolScoped` etc.) |
| + |
| +Run (sandbox off): `... go test ./internal/console/ -run 'TestHAPoolScopedPredicate|TestHAPoolGate' -count=1 ...` |
| + |
| +- [ ] **Step 7: Implement** `hapool.go`, `hapoolcopy.go`, `Config.HAPoolAccounts` (comment: "nil is nobody, the opposite of SidecarAccounts on purpose"), and the two gate calls: |
| + |
| +```go |
| +// apiinstances.go, after haCreateShapeRefusal |
| +if s.refuseHAPool(w, acct, app, region, rec.Pool, "api instances create") { |
| + return |
| +} |
| +// apisidecars.go, after refuseSidecarsPaused |
| +if s.refuseHAPool(w, acct, app, rec.Region, rec.Pool, "api sidecars create") { |
| + return |
| +} |
| +``` |
| + |
| +`hapool.go`'s package comment lists the doors and why only these two (Spec correction 11), the way `sidecarsgate.go`'s header does. |
| + |
| +- [ ] **Step 8: Run the new tests and every scoped-pool test, expect PASS** |
| + |
| +`... go test ./internal/console/ -run 'TestHAPool|TestSidecarsPaused|TestHACreate|TestRegionDefault|TestDemoClaimHA|TestAPIInstances.*HA|TestAttach' -count=1 ...` (widen `-run` to the exact test names in the files listed under "Read first" if a pattern misses one; `grep -n '^func Test' <file>`). |
| + |
| +- [ ] **Step 9: Mutation checks** (each one targeted `-run`, then revert): delete the instance gate call → `TestHAPoolGateInstanceCreate` fails; delete the sidecar call → `TestHAPoolGateSidecarCreate` fails; make `haPoolScoped` ignore `haScopeInvalid` → `TestHAPoolScopedPredicate` fails; make `haPoolAccounts("")` return a non-nil empty slice treated as "no gate" (`len==0 → allowed`) → predicate test fails. |
| + |
| +- [ ] **Step 10: Commit** |
| + |
| +```bash |
| +git add cmd/console/main.go cmd/console/hapoolaccounts_test.go cmd/console/hapoolaccounts_serve_test.go internal/console/server.go internal/console/hapool.go internal/console/hapoolcopy.go internal/console/hapool_test.go internal/console/apiinstances.go internal/console/apisidecars.go <fixture test files touched> |
| +git commit -m "console: CONSOLE_HA_POOL_ACCOUNTS gates creates into scoped HA pools" |
| +``` |
| + |
| +--- |
| + |
| +### Task 2: The app row's `ha_pool` and `"ha": true` at app create (API) |
| + |
| +**Read first (traps):** |
| +- The new column is ALTERed AFTER `migrateAppsKey` (Spec correction 3). Put `s.migrateAppHAPool()` in `Store.migrate` right after `s.migrateLinks()` (`store.go:692`). Do not touch `migrateAppsKey`'s column list. |
| +- `insertAppRow` is the only insert (`TestEveryAppInsertMintsALifetime` enforces it); add the column there, not a second insert. |
| +- The HA checks run AFTER `apiPrincipalAccount` (auth, membership, the app-scoped-service 404), the rate limit, `readJSON`, and the `place` validation (its foreign-fleet 404 must still come first), and BEFORE `newAppRegionReq` (otherwise `"@auto"` meets the region-unknown refusal instead of `ha_needs_region`). |
| +- Adoption: in `claimAppWith`, `rq.haPool != "" && adoptingExistingApp` returns `claimTaken` before any write. |
| +- An older CLI never sends `ha`; the answer gains `ha_pool` and `ha_status` ONLY when the row has a pool, so a plain create's body is byte-identical to today. |
| + |
| +**Files:** |
| +- Create: `internal/console/store_hapool.go` (migration, `CreateHAAppInRegion`, `AppHAPool`) |
| +- Modify: `internal/console/lifetimes_store.go:455-497` (`newAppRow.HAPool`, `insertAppRow`), `internal/console/store.go:692` (call the migration) |
| +- Modify: `internal/console/regionclaim.go:19-24` (`regionReq.haPool`), `internal/console/server.go:5532-5541` (`claimAppWith`) |
| +- Modify: `internal/console/hapool.go` (`haCreateChoice`), `internal/console/apicli.go:412-650` (`handleAPICreateApp`) |
| +- Create: `internal/console/store_hapool_test.go`, `internal/console/apicli_ha_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: Task 1's `haPoolFor`, `haPoolAllowed`, `haDoorRefusal`, `writeHARefusal`, copy constants. |
| +- Produces: |
| + - `func (s *Store) CreateHAAppInRegion(accountID int64, app, createdBy, region, source, haPool string, now time.Time) (created bool, err error)` |
| + - `func (s *Store) AppHAPool(ctx context.Context, accountID int64, app string) (pool, region string, err error)` — the LIVE row (`deleted_at = 0`); no live row is `"", "", nil` |
| + - `regionReq.haPool string` — set only by an HA create |
| + - `func (s *Server) haCreateChoice(p Principal, acct *Account, raw, place string) (pool string, ref *haDoorRefusal)` |
| + |
| +- [ ] **Step 1: Write the failing store test** (`store_hapool_test.go`) |
| + |
| +`TestStoreAppHAPool`: |
| +- fresh store: `CreateHAAppInRegion(OpsAccountID, "shop", "a@x", "us", "chosen", "ha", now)` → created; `AppHAPool` → `("ha", "us", nil)`; `AppRegion` → `("us", "chosen")`; lifetime non-empty. |
| +- `CreateAppInRegion` plain → `AppHAPool` → `("", <region>, nil)`. |
| +- the same name again via `CreateHAAppInRegion` → `created == false`. |
| +- trashed (`UPDATE apps SET deleted_at = 1`) → `AppHAPool` → `("", "", nil)`. |
| +- a pre-accounts database (the fixture `migrate_test.go:110-130` builds, PRIMARY KEY(app)) opened through `OpenStore` has the `ha_pool` column after open (`PRAGMA table_info(apps)` lists it), and opening twice is idempotent. |
| + |
| +- [ ] **Step 2: Run, expect FAIL.** `... go test ./internal/console/ -run 'TestStoreAppHAPool' -count=1 ...` |
| + |
| +- [ ] **Step 3: Implement** the migration (`ALTER TABLE apps ADD COLUMN ha_pool TEXT NOT NULL DEFAULT ''`, ignoring "duplicate column", comment naming why it runs after the rebuild), `newAppRow.HAPool` + the insert column, `CreateHAAppInRegion` (one `insertAppRow`, region + source + pool in the same statement), `AppHAPool`. |
| + |
| +- [ ] **Step 4: Run, expect PASS**, plus `TestEveryAppInsertMintsALifetime` and `migrate_test.go`'s tests (`grep -n '^func Test' internal/console/migrate_test.go`). |
| + |
| +- [ ] **Step 5: Write the failing API tests** (`apicli_ha_test.go`) |
| + |
| +Fixture: the one the existing region-create API tests use (`grep -n 'region' internal/console/regionclaim_test.go internal/console/apicli_test.go` for a create that sends `"region"` and passes `validateExplicitRegion`), with `Tweak`: `HomeRegion "ie"`, `HARegions {"us"}`, `HACapacityConfig = haPoolRaw("us", true)`, `HAPoolAccounts {"bab"}`, region switch on, and a published armed+hosting `us` box. POST `/api/cli/apps/bab/new`. `TestAPICreateAppHA` subtests: |
| +- (a) person, `{"name":"shop","region":"us","ha":true}` → 200; `AppHAPool` = `("ha","us")`; body `ha_pool == "ha"`, `ha_status == fmt.Sprintf(haCopyStatus, srv.offlinePlace("us"))`, `region == "us"`. |
| +- (b) a Publish service credential of bab (`grep -n 'svcrole.Publish' internal/console/*_test.go` for its helper) with `ha` → 403 `{haCopyNotAllowed, "ha-pool-not-allowed"}`, `HasAppIn` false; the same credential without `ha` → 200 and no `ha_pool` key in the body. |
| +- (c) `ha` with region absent, and with `"@auto"` → 400 `haCopyNeedsRegion`; nothing created. |
| +- (d) `ha` with region `"ie"` (the home, unscoped) → 400 `fmt.Sprintf(haCopyRegion, srv.offlinePlace(""))`. |
| +- (e) `ha` with `"place":"fleet/<own fleet>"` → 400 `fmt.Sprintf(haCopyRegion, "fleet/<own fleet>")`; a foreign fleet with `ha` → 404 (the existing answer, first). |
| +- (f) unlisted person (`HAPoolAccounts {"cdef"}`) → 403 with the code; nothing created. |
| +- (g) owner, objects already under `apps/bab/shop/` (put any object there), `ha` → 409 `"that name is taken"`, no row; the same without `ha` → 200 (adoption unchanged). |
| +- (h) `HACapacityConfig ""` (scope invalid) with `ha` → 400 `haCopyRegion`. |
| +- (i) a plain create by an unlisted person → 200, body has no `ha_pool` key. |
| + |
| +- [ ] **Step 6: Run, expect FAIL.** `... -run 'TestAPICreateAppHA' ...` |
| + |
| +- [ ] **Step 7: Implement.** |
| + - `haCreateChoice` checks, in this order: `p.Kind != PrincipalUser` → `{403, haCopyNotAllowed, code}`; trimmed `raw == ""` or `== autoRegion` → `{400, haCopyNeedsRegion}`; `place != ""` → `{400, fmt.Sprintf(haCopyRegion, place)}`; `code := s.homeRegionIn(raw)`; `(!s.appRegionsOn() && code != "") || s.haPoolFor(code) == ""` → `{400, fmt.Sprintf(haCopyRegion, s.offlinePlace(code))}`; `!s.haPoolAllowed(acct, code, pool)` → `s.haPoolRefusal(...)`. Returns the pool. |
| + - `handleAPICreateApp`: `HA bool \`json:"ha"\`` in the request; after the place checks, `if req.HA { pool, ref := s.haCreateChoice(p, acct, req.Region, place); if ref != nil { writeHARefusal(w, ref); return } }`; after `newAppRegionReq`, `rq.haPool = pool`. On `claimOK`, read `AppHAPool` back and, when non-empty, add `"ha_pool"` and `"ha_status"` (`fmt.Sprintf(haCopyStatus, s.offlinePlace(region))`). |
| + - `claimAppWith`: adoption refusal (above); insert through `CreateHAAppInRegion` when `rq.haPool != ""`; defensive: if `rq.haPool != ""` and the resolved region does not satisfy `s.poolInHAPools(region, rq.haPool)`, log and return `claimCreateFailed` before the insert (unreachable through both doors). |
| + |
| +- [ ] **Step 8: Run, expect PASS**, plus the existing create tests: `-run 'TestAPICreateApp|TestHAPool|TestNewApp|TestClaim'`. |
| + |
| +- [ ] **Step 9: Mutation checks:** drop the person check → (b) fails; drop the adoption refusal → (g) fails; drop `haPoolAllowed` in `haCreateChoice` → (f) fails. |
| + |
| +- [ ] **Step 10: Commit** — `git commit -m "console: apps create takes ha, stores ha_pool in the same insert"` |
| + |
| +--- |
| + |
| +### Task 3: The enable door binds Pool and Regions from the row |
| + |
| +**Read first (traps):** |
| +- Legacy apps (no `ha_pool` on the row, the canaries included) must behave EXACTLY as today on create and update (G6-2.8). The binding returns nil for them before reading anything else. |
| +- Read the row AFTER `beginCopiesMutation` (`apiinstances.go:3619`): it holds the app lock and pins the incarnation (`copiesStillApp`), so the row read is of the app this request resolved; a trashed-and-recreated name reads its own row. |
| +- Mark the first create with an explicit `created := true` in the `os.ErrNotExist` case; do not infer it from `etag == ""`. |
| +- The re-checks (allowlist, region still HA) run on first create only (see Decisions). Update with a matching pool is untouched; a different pool is 409 and writes nothing. |
| +- `Regions` is `[]string{row region}` in record vocabulary: `[""]` for the home. `instanceRegionAllowed` treats it correctly; no box reads `Manifest.Regions`. |
| + |
| +**Files:** |
| +- Modify: `internal/console/apiinstances.go:3544-3700` (`handleAPIInstanceEnable`; extract the `AppsDomain` + `ValidHostShape` checks `:3562-3616` into `instancesDomain`, keeping their exact messages and statuses) |
| +- Modify: `internal/console/hapool.go` (`haManifestBinding`, `enableHAManifest`) |
| +- Create: `internal/console/apiinstances_haenable_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: Task 1 (`haPoolAllowed`, `haPoolRefusal`, `haPoolFor`, refusal type, copy), Task 2 (`AppHAPool`, `CreateHAAppInRegion`). |
| +- Produces: |
| + - `func (s *Server) instancesDomain(acct *Account) (string, *doorRefusal)` |
| + - `func (s *Server) haManifestBinding(ctx context.Context, acct *Account, app string, m *provision.Manifest, created bool) *haDoorRefusal` — row pool `""` → nil. Created: allowlist (`haPoolRefusal`), then `s.haRegion(region) && s.poolInHAPools(region, pool)` else `{409, fmt.Sprintf(haCopyRegion, s.offlinePlace(region))}`, then `m.Pool, m.Regions = pool, []string{region}`. Not created: `m.Pool != pool` → `{409, haCopyPoolMismatch}`, else nil. A row read error → `{502, "could not read instance settings"}` (the door's existing sentence). |
| + - `func (s *Server) enableHAManifest(ctx context.Context, acct *Account, app, addr string) *haDoorRefusal` — for the browser create (Task 6): `instancesDomain`, `beginCopiesMutation`, `GetManifestETag`; absent → `{Schema:1, App, Domain}` + `haManifestBinding(created=true)` + `copiesChannelRefusal` + `PutManifestIfMatch(etag "")` + audit (`"enabled instances under "+domain+" (console)"`) + `bumpSerial`; present with another domain → the door's existing 409 sentence; present otherwise → `haManifestBinding(created=false)` and no write. |
| + |
| +- [ ] **Step 1: Write the failing tests** (`apiinstances_haenable_test.go`). World: `haPoolWorldNew(t, "us", "ha", nil)` (bab listed) plus a new app row `CreateHAAppInRegion(OpsAccountID, "haapp", ..., "us", "chosen", "ha", now)`, enabled through `PUT /api/cli/apps/bab/haapp/instances-manifest` with a person's token. |
| +- `TestEnableHAFirstCreateBindsPoolAndRegion`: PUT `{}` → 200; body `pool == "ha"`, `regions == ["us"]`; the bucket's manifest has the same; then `POST` an instance naming no region → 201, record `HA: true, Pool: "ha", Region: "us"`. |
| +- `TestEnableHAHomeRegion`: `haPoolWorldNew(t, "ie", "ha", nil)`, row region `""` → manifest `Regions == [""]`; instance create with `"region":"ie"` → 201 (`Region ""`, `HA: true`); with `"region":"us"` → 400 and no record. |
| +- `TestEnableHAInstanceOtherRegionRefused`: after the first test's enable, instance create with `"region":"ie"` → 400 naming the allow-list (`us`); no record. |
| +- `TestEnableHALegacyPooledUnchanged`: for manifests (store-mode written) with `Pool "other", Regions ["de"]` and with `Pool "ha", Regions nil` on rows WITHOUT `ha_pool`, PUT `{"channel":"beta"}` → 200, pool and regions exactly as before, channel `beta`. And a legacy row with no manifest → PUT creates `{Pool: "", Regions: nil}` as today. |
| +- `TestEnableHAExistingManifestOtherPool`: `ha_pool` row, store-mode manifest `Pool "other"` → PUT → 409 `haCopyPoolMismatch`; manifest bytes unchanged. Manifest `Pool "ha"` → PUT `{"channel":"beta"}` → 200, pool `ha` kept. |
| +- `TestEnableHARecreatedNameDoesNotInherit`: `ha_pool` row, then `DELETE FROM apps WHERE ...` (purge stand-in) and `CreateAppIn` the same name → PUT → manifest `Pool ""`, `Regions nil`. |
| +- `TestEnableHARemovedAccountRefused`: `HAPoolAccounts nil`, `ha_pool` row → PUT → 403 with code; no manifest key in the bucket. |
| +- `TestEnableHARegionNoLongerHA`: row `CreateHAAppInRegion(..., "uk", ..., "ha", ...)` → PUT → 409 `fmt.Sprintf(haCopyRegion, srv.offlinePlace("uk"))`; no manifest. |
| +- `TestEnableHAManifestForBrowser`: `enableHAManifest` on a fresh `ha_pool` row writes the bound manifest (domain `bab.<apps domain>`); a second call returns nil and writes nothing (the manifest's ETag is unchanged); on a row whose region is no longer HA it returns the 409 and writes nothing. |
| + |
| +- [ ] **Step 2: Run, expect FAIL.** `... -run 'TestEnableHA' ...` |
| + |
| +- [ ] **Step 3: Implement** `instancesDomain` (pure extraction), `haManifestBinding` called right after the `GetManifestETag` switch (refusal → `writeHARefusal`), `enableHAManifest`. Update the "Pool and Regions survive untouched" comment: still true for legacy apps; a born-HA app's are set once, here, from its row. |
| + |
| +- [ ] **Step 4: Run, expect PASS**, plus the door's existing tests: `-run 'TestEnableHA|TestAPIInstanceEnable|TestInstancesEnable|TestPrivateStorage'` (find exact names: `grep -n 'instances-manifest' internal/console/*_test.go | cut -d: -f1 | sort -u`). |
| + |
| +- [ ] **Step 5: Mutation checks:** skip the allowlist on first create → `TestEnableHARemovedAccountRefused` fails; apply the pool-mismatch rule to legacy rows → `TestEnableHALegacyPooledUnchanged` fails; drop `Regions` → `TestEnableHAInstanceOtherRegionRefused` fails. |
| + |
| +- [ ] **Step 6: Commit** — `git commit -m "console: enable binds a born-HA app's pool and region from its row"` |
| + |
| +--- |
| + |
| +### Task 4: Region binding: region doors, place door, swap concurrency |
| + |
| +**Read first (traps):** |
| +- Refuse from the ROW (`AppHAPool`), never the manifest: before enable there is no manifest and `appPolicy` reads that as unrestricted (G6-2.5). |
| +- `setAppRegion`'s refusal goes first, right after `demoMutationRefusal` (`appregionset.go:265`), so it answers before any choices or edges read. The store's conditional update ALSO gains `AND ha_pool = ''` (spec §3.1.4); it returns `ok == false` for an HA row even if a caller skipped the door check. |
| +- `placeAppTarget`'s refusal goes after `linkedRefusalFor` (`fleets.go:816`), before the hostname-history mode read. It covers `carlos apps place` and the Settings > Placement form (all three callers, `fleets.go:1093,1157,1206`). |
| +- The swap refusal lives in `setCopiesSwapPolicy` (`copiespublication.go:256`), before `beginCopiesMutation`, only when `concurrency > 1`, returned as `&statelessSelectionError{&doorRefusal{Status: 400, Msg: haCopySwapConcurrency}}`; both swap doors already render that type (`apiswap.go:78`, `appswap.go:65`). `concurrency == 0` means "unchanged" at the API door and is not refused. |
| + |
| +**Files:** |
| +- Modify: `internal/console/appregionset.go:264-270`, `internal/console/store.go:1942-1943`, `internal/console/fleets.go:809-819`, `internal/console/copiespublication.go:256` |
| +- Create: `internal/console/appregion_ha_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: Task 2's `AppHAPool`, `CreateHAAppInRegion`; Task 1's copy; Task 3's enable flow (for the "after enable" cases). |
| +- Produces: nothing new for later tasks. |
| + |
| +- [ ] **Step 1: Write the failing tests** (`appregion_ha_test.go`, on `newAppRegionFx` (`appregionset_test.go:39`) plus HA config `haPoolRaw("us", true)` and an `ha_pool` row `haapp` in `us`): |
| +- `TestAppRegionSetRefusesHAApp`: `fx.put(t, owner, "haapp", "uk")` → 409 `haCopyRegionLocked`; `fx.stored` unchanged; the same after enabling (manifest pool `ha`); the browser door `POST /a/bab/apps/haapp/region` → redirect whose flash is `sentenceCase(haCopyRegionLocked)`; a plain app in the same fixture still changes (200). |
| +- `TestStoreSetAppRegionSkipsHARow`: `inc` from `AppIncarnationContext`, `SetAppRegion(ctx, id, "haapp", inc, "us", "uk", now)` → `ok == false`, region `us`. |
| +- `TestHABindingRaceSimulation`: 20 rounds; each round a fresh name; three goroutines released together: API create `{"ha":true,"region":"us"}`, region PUT to `uk`, enable PUT. After the round, if the row exists: `AppHAPool == ("ha","us")`, and if the manifest exists: `Pool == "ha"` and `Regions == ["us"]`. (Answers may be 404/409 in any order; only the end state is asserted.) |
| +- `TestPlaceRefusesHAApp`: `apps place` API (`grep -n 'handleAPIPlace' internal/console/routedecls.go` for the path) with `fleet/<own fleet>` → 409 `haCopyRegionLocked`; `AppPlacement` unchanged; same with target `""`. |
| +- `TestSwapConcurrencyRefusedForHAApp`: `PUT .../haapp/swap {"swap_concurrency":2}` → 400 `haCopySwapConcurrency`, swap policy unchanged (`appconfig.GetSwapPolicy`); `{"swap_concurrency":1}` → 200; `{"swap":"hold"}` → not refused by this rule; browser `POST .../swap` with `swap_concurrency=2` → flash `haCopySwapConcurrency`; a plain app with 3 → 200. |
| + |
| +- [ ] **Step 2: Run, expect FAIL.** `... -run 'TestAppRegionSetRefusesHAApp|TestStoreSetAppRegionSkipsHARow|TestHABindingRaceSimulation|TestPlaceRefusesHAApp|TestSwapConcurrencyRefusedForHAApp' ...` |
| + |
| +- [ ] **Step 3: Implement** the four refusals (a row read error: `setAppRegion` → `{502, msgAppRegionUnreadable}`, `placeAppTarget` → 502 with its existing "could not check this app's placement" sentence, `setCopiesSwapPolicy` → return the error). |
| + |
| +- [ ] **Step 4: Run, expect PASS**, plus `-run 'TestAppRegionSet|TestPlace|TestAPISwap|TestAppSwap|TestAppsPlace'`. |
| + |
| +- [ ] **Step 5: Mutation checks:** drop the `setAppRegion` refusal → the race simulation or `TestAppRegionSetRefusesHAApp` fails; drop `AND ha_pool = ''` → `TestStoreSetAppRegionSkipsHARow` fails; drop the place refusal → `TestPlaceRefusesHAApp` fails. |
| + |
| +- [ ] **Step 6: Commit** — `git commit -m "console: a born-HA app's region, placement and swap width stay fixed"` |
| + |
| +--- |
| + |
| +### Task 5: CLI `carlos apps create --ha` |
| + |
| +**Read first (traps):** |
| +- The root package is in the root binary: this task makes `TestPlan14RootReadCensus` fail until Task 7. Do not try to fix the census here. |
| +- Follow the "what actually stuck" pattern (`apps.go:588-629`): the CLI checks the console's echo, because an older console ignores `"ha"` and answers 200 for a plain app. |
| +- `createAppAnalytics` keeps its signature (tests call it); it delegates to the new function with `ha == false`. `"ha"` is `omitempty`, so a plain create's request body is byte-identical. |
| +- No client-side `--ha needs --region` check: that would need a CLI sentence the deck does not have; the console answers it. |
| +- Cross-compile: `GOOS=darwin go build . && GOOS=windows go build .` |
| + |
| +**Files:** |
| +- Modify: `apps.go:511-630` (`runAppsCreate`), `apimode.go:1055-1135` (`apiCreateAppResult`, `createAppHA`) |
| +- Create: `apps_ha_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: the console answer from Task 2 (`ha_pool`, `ha_status`). |
| +- Produces: |
| + - `func (s *apiSession) createAppHA(ctx context.Context, a apiAcct, app, place string, controlPlane bool, buildProbe, region, timezone, analytics string, ha bool) (apiCreateAppResult, error)` |
| + - `apiCreateAppResult.HAPool string \`json:"ha_pool"\``, `.HAStatus string \`json:"ha_status"\`` |
| + - `func haMismatchErr(app string, asked bool, gotPool string) error` — nil unless `asked && gotPool == ""`, then `fmt.Errorf(appsCreateHAUnconfirmed, app)` |
| + - constants in `apps.go`: `flagHAAppsCreate = "COPY-PENDING:cli.apps_create.ha_flag"`, `appsCreateHAUnconfirmed = "COPY-PENDING:cli.apps_create.ha_unconfirmed:%s"` |
| + |
| +- [ ] **Step 1: Write the failing tests** (`apps_ha_test.go`, `httptest` server capturing the body, `newTestSession` as `apps_analytics_test.go:44` does): |
| +- `TestCreateAppHASendsTheFlag`: `createAppHA(..., "us", "", "", true)` → captured body has `"ha":true` and `"region":"us"`; `createAppAnalytics(...)` → body has no `"ha"` key; the server's `{"ha_pool":"ha","ha_status":"S"}` decodes to `HAPool "ha"`, `HAStatus "S"`. |
| +- `TestHAMismatchErr`: `(app, false, "")` → nil; `(app, true, "ha")` → nil; `(app, true, "")` → error whose text equals `fmt.Sprintf(appsCreateHAUnconfirmed, "shop")`. |
| + |
| +- [ ] **Step 2: Run, expect FAIL** (sandbox off): `d=$(mktemp -d /tmp/g/g6pool-t5.XXXX) && TMPDIR=$d go test . -run 'TestCreateAppHASendsTheFlag|TestHAMismatchErr' -count=1; rm -rf "$d"` |
| + |
| +- [ ] **Step 3: Implement:** `--ha` flag (`fs.Bool("ha", false, flagHAAppsCreate)`), `[--ha]` added to the usage line after `[--region <code>]`, call `createAppHA`, and after the analytics check: `if err := haMismatchErr(res.App, *ha, res.HAPool); err != nil { log.Fatalf("apps create: %v", err) }` then, when `*ha`, `fmt.Fprintf(stdout, " %s\n", res.HAStatus)`. |
| + |
| +- [ ] **Step 4: Run, expect PASS**, plus `-run 'TestAppsCreate|TestCreateApp|TestRegionCopy'` in the root package, and `GOOS=darwin go build . && GOOS=windows go build .` |
| + |
| +- [ ] **Step 5: Commit** — `git commit -m "cli: apps create --ha asks for a born-HA app and checks the echo"` |
| + |
| +--- |
| + |
| +### Task 6: Web UI: the create checkbox and the settings status line |
| + |
| +**Read first (traps):** |
| +- UX pass first, in the kit, before any template edit (AGENTS.md "Console mockups use the kit" and "Every UI change gets a UX pass"), and only for what the spec asks: one checkbox with its explainer and docs link under the region picker, and one status line in Settings > General's Region section. No new design, no new CSS unless the styleguide has nothing that fits. |
| +- The checkbox is server-rendered enabled; a small inline script disables it while the selected option lacks `data-ha` and re-enables on change. With JavaScript off it stays enabled and the server's refusal answers. Keep the existing picker script unchanged (it returns early without a timezone). |
| +- `handleNewApp`'s HA path: the web session is a person (`Principal{Kind: PrincipalUser, Address: addr}`). Run `haCreateChoice` after `pickedRegion` succeeds; refusals go through the existing `fail(sentenceCase(ref.Msg))`. After `claimOK`, call `enableHAManifest` (Task 3); on a refusal, the app exists: redirect to the app page with `setFlash(w, "err", sentenceCase(ref.Msg))` instead of the success flash. |
| +- Picker absent: see Decisions (hidden `region` input with the home's code when `haPoolFor("") != ""`). |
| +- Status line: from the MANIFEST (spec §3.2), only on the `general` section; `s.instancesManifest` (`reqmemo.go:257`) once. |
| + |
| +**Files:** |
| +- Modify: `internal/console/regionpicker.go` (`regionOption.HA`, `newAppPicker`) |
| +- Modify: `internal/console/server.go` (`page`: `NewAppHA bool`, `NewAppHAHomeRegion string`, `HAStatus string` near `:2271`; `handleNewAppForm` `:5627`; `handleNewApp` `:5651`; `populateAppSettings` `:5127-5141`) |
| +- Modify: `internal/console/hapool.go` (`haPoolCopyStrings`, `page.HAPoolCopy`, `haStatusLine`) |
| +- Modify: `internal/console/templates/app_new.html`, `internal/console/templates/app_settings.html:38-55` |
| +- Create: `internal/console/newapp_ha_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 1-3 (`haPoolListed`, `haPoolFor`, `haCreateChoice`, `enableHAManifest`, `AppHAPool`, copy). |
| +- Produces: |
| + - `regionOption{Value, Label string; HA bool}` (`appRegionPageChoices` keeps keyed literals, so it is unaffected) |
| + - `type haPoolCopyStrings struct{ Label, Explainer, DocsLink, DocsURL string }`; `func (p page) HAPoolCopy() haPoolCopyStrings` |
| + - `func (s *Server) haStatusLine(ctx context.Context, acct *Account, app string) (line string, locked bool)` — `line` when the manifest's pool is scoped in a region (the first of `m.Regions` where `s.haRegion(r) && s.poolInHAPools(r, m.Pool)`, or with no `Regions` the single HA region whose pools contain it): `fmt.Sprintf(haCopyStatus, s.offlinePlace(region))`; `locked` when `line != ""` or the row has `ha_pool` |
| + |
| +- [ ] **Step 1: UX pass in the kit.** `d=$(mktemp -d)`; copy `docs/console-mockup-kit/shell.html` twice; mock the create form (name, region picker, the checkbox with the explainer placeholder at its draft length from spec §5 string 2, docs link, analytics checkbox, Create app) and Settings > General's Region section with the status line in place of the region control. Screenshot at 390 and 1280, light and dark (README step 3). Fix wrapping and crowding using styleguide classes only. Note in the task report which classes were used. `rm -rf "$d"`. |
| + |
| +- [ ] **Step 2: Write the failing tests** (`newapp_ha_test.go`, on the fixtures in `regionpicker_test.go` (`newAppForm`, `:42`) and `appregionset_test.go` with HA config `haPoolRaw("us", true)`): |
| +- `TestNewAppHACheckboxOnlyForListedAccounts`: listed + picker with `us` → the form has `name="ha"`, `has(body, haCopyLabel)`, `has(body, haCopyExplainer)`, `haDocsURL`, and the `us` option carries `data-ha`; unlisted → no `name="ha"`; listed but no HA option in the picker and home not HA → no `name="ha"`; picker absent and home HA (`haPoolRaw("ie", true)`, home `ie`) → `name="ha"` and a hidden `region` input with value `ie`. |
| +- `TestNewAppHAForgedByUnlistedRefused`: unlisted `POST /a/bab/apps/new` with `ha=1®ion=us` → 303 to the form, flash `sentenceCase(haCopyNotAllowed)`, `HasAppIn` false. |
| +- `TestNewAppHANeedsRegion`: listed, `ha=1®ion=@auto` → flash `sentenceCase(haCopyNeedsRegion)`, nothing created. |
| +- `TestNewAppHANonHARegion`: listed, `ha=1®ion=<an eligible non-HA region>` → flash `sentenceCase(fmt.Sprintf(haCopyRegion, <its label>))`. |
| +- `TestNewAppHACreatesAndEnables`: listed, `ha=1®ion=us` → 303 to `/a/bab/apps/<name>`; `AppHAPool == ("ha","us")`; manifest `Pool "ha"`, `Regions ["us"]`. |
| +- `TestAppSettingsHAStatusLine`: app with manifest pool `ha` (store-mode, legacy row) → `/a/bab/apps/<app>/settings/general` has `fmt.Sprintf(haCopyStatus, label)` and no `action=".../region"` form; a plain app → no status line, the form present (as today for an owner). |
| + |
| +- [ ] **Step 3: Run, expect FAIL.** `... -run 'TestNewAppHA|TestAppSettingsHAStatusLine' ...` |
| + |
| +- [ ] **Step 4: Implement** the picker flag, `handleNewAppForm` (`p.NewAppHA = s.haPoolListed(acct) && (picker has an HA option || (picker == nil && s.haPoolFor("") != ""))`; set `NewAppHAHomeRegion = s.homeRegionOut("")` in the second case), the templates per the UX pass, `handleNewApp`'s HA path, and `populateAppSettings`: on `general`, `p.HAStatus, locked = s.haStatusLine(...)`; `CanSetRegion` only when not `locked`. |
| + |
| +- [ ] **Step 5: Run, expect PASS**, plus `-run 'TestNewApp|TestAppSettings|TestRegionPicker|TestAppRegionSet|TestConsoleStyleguideClassesExist'`. |
| + |
| +- [ ] **Step 6: Commit** — `git commit -m "console: HA checkbox on the create form, HA status line in settings"` |
| + |
| +--- |
| + |
| +### Task 7: Census card and the branch's targeted gate |
| + |
| +**Read first (traps):** |
| +- Only Task 5's root-package files changed the root binary. Check with the AGENTS.md `go list -deps` commands that no other changed file is in scope. |
| +- Never run the full suite locally; CI runs it. |
| + |
| +**Files:** |
| +- Create: `testdata/plan14-root-reads-g6-pool.tsv`, `docs/superpowers/notes/census-proposal-g6-pool.md` (written by `make census-propose`), the CLAIMS file in `$TMPDIR` (not committed) |
| + |
| +- [ ] **Step 1:** `make census-card` and read what it lists (expected: `apps.go`, `apimode.go` units and the root package envelope). |
| +- [ ] **Step 2:** Write the CLAIMS file, one line per changed unit: `<file>:<unit><TAB>apps create gains --ha: sends "ha" and checks the console's ha_pool echo; no new root read`. |
| +- [ ] **Step 3:** `make census-propose NAME=g6-pool CLAIMS=$TMPDIR/g6-pool-claims.tsv`; expect it to report the overlay leaves the census clean. |
| +- [ ] **Step 4:** Run (sandbox off) `go test ./internal/provision/ -run 'TestPlan14RootReadCensus|TestCensusScopeIsTheRootBinary' -count=1`, expect PASS. |
| +- [ ] **Step 5:** Branch check: `gofmt -l . | grep -v '^$'` prints nothing; `go vet ./internal/console/ ./cmd/console/ .`; `GOOS=darwin go build . && GOOS=windows go build .`; one targeted run of every test name added in Tasks 1-6 in their packages (sandbox off, `/tmp/g` dir as above). |
| +- [ ] **Step 6: Commit** — `git commit -m "census: g6-pool overlay for apps create --ha"` (the overlay, its chain line and the card). Brief the Astra census review from `docs/superpowers/reviews/REVIEW-BRIEF-TEMPLATE.md` with the whole-branch review. |
| + |
| +--- |
| + |
| +### Task 8: Wire the approved copy (GATED: starts only when Paul's copy review result exists) |
| + |
| +**Read first (traps):** |
| +- Use the approved text verbatim from the copy review's `result.json` (the controller gives its path). Paul's house rules apply to whatever he approved: no em dashes, curly quotes. Do not edit his text. |
| +- Strings 5 and 7 keep exactly one `%s`. If the approved text drops or moves it, stop and ask the controller. |
| +- If Paul rejects one of the two ids this plan added (`ha_pool_mismatch`, `ha_unconfirmed`), the controller decides the replacement; do not invent one. |
| + |
| +**Files:** |
| +- Modify: `internal/console/hapoolcopy.go`, `apps.go` (the two CLI constants) |
| +- Create: `internal/console/approved_ha_pool_copy_test.go` |
| +- Modify: `testdata/plan14-root-reads-g6-pool.tsv` and the card (rerun of Task 7 steps 1-4, same NAME) |
| + |
| +- [ ] **Step 1: Write the failing test** `approved_ha_pool_copy_test.go` (pattern: `approved_burst_copy_test.go`): `TestApprovedHAPoolCopy` asserts each console constant equals its approved literal (one row per copy id, the id in the row's comment); `TestNoCopyPendingStrings` walks `internal/console/*.go`, `internal/console/templates/*.html`, and `../../*.go` (root package, non-test files) and fails on any `COPY-PENDING:`. Add the two CLI constants' approved literals to a root-package test, `TestApprovedAppsCreateHACopy` in `apps_ha_test.go`. |
| +- [ ] **Step 2: Run, expect FAIL.** |
| +- [ ] **Step 3:** Replace the placeholder values with the approved text. |
| +- [ ] **Step 4: Run, expect PASS**, plus every test from Tasks 1-6 (they assert on the constants, so they pass unchanged). |
| +- [ ] **Step 5:** Rerun `make census-propose NAME=g6-pool CLAIMS=...` (`apps.go` changed) and the census tests. |
| +- [ ] **Step 6: Commit** — `git commit -m "console, cli: approved copy for the HA pool path"` |
| + |
| +--- |
| + |
| +### Task 9: Docs page and the CLI page's `--ha` (GATED on copy approval of spec §5 string 10) |
| + |
| +**Read first (traps):** |
| +- Write the page with the writing-pipeline skill from spec §4's table (every row, including the 503 exceptions, the storage-loss rows and "not covered"), and put it through the copy-review skill before it is committed. It is reviewed in the same pass as Task 8's strings (spec §5 item 10). |
| +- `internal/docsite` fails the gate on a `/docs` link whose page or fragment does not resolve, so the page and the CLI page's link land in this one commit. |
| +- The site shows the page only after `carlosframework/website` re-syncs at a release tag (README 11a). Until then the console's docs link 404s; that is in "After merge". |
| + |
| +**Files:** |
| +- Create: `docs/site/high-availability.md` |
| +- Modify: `docs/site/nav.json` (a Guides entry, slug `high-availability`, approved label and blurb), `docs/site/cli.md` (under `### carlos apps`, after the `--region` paragraph: the approved `--ha` paragraph with an example `carlos apps create --app hello --region us --ha` and a link to `/docs/high-availability`) |
| + |
| +- [ ] **Step 1:** Draft with writing-pipeline; run copy-review; apply Paul's edits verbatim. |
| +- [ ] **Step 2:** Run (sandbox off if needed) `go test ./internal/docsite/ -count=1 -run '.'` scoped to that package only, expect PASS (fenced examples, links, nav). |
| +- [ ] **Step 3: Commit** — `git commit -m "docs: high availability page and apps create --ha"` |
| + |
| +--- |
| + |
| +## After merge (not plan tasks) |
| + |
| +1. **Release and roll, dev first** (memory: platform-release-recipe, platform-roll-recipe, roll-order-dev-first). Ask 8a3d302 before any #421 lock during a window. |
| +2. **Set `CONSOLE_HA_POOL_ACCOUNTS` in the SAME window as the console roll** (drop-in written before the console restart): unset means nobody, so a roll without it stops the canaries' new instance creates in pool `ha` (flagship) and `hapair` (dev, if scoped) with a 403. Dev: the dev canary account. Flagship: `bab` plus the first app's account (still undecided). Live change: needs 8a3d302's GO. |
| +3. **Check dev's `CONSOLE_HA_CAPACITY_CONFIG`**: spec §2 expects IE to carry `ha_pools: ["hapair"]`; RHA §23 recorded none. Without it, dev has no scoped pool and exit-test step 1 cannot run on dev. |
| +4. **Docs**: sync `carlosframework/website` at the release tag (README 11a) so the form's docs link resolves. |
| +5. **Exit test (dev, then flagship)**, spec §6: (1) an allowed account creates an HA app in US (dev: IE, pool `hapair`) from the web form, deploys, and its default instance record has `ha: true`, the pool, the region, and serves from a group member; (2) an unlisted account sees no checkbox, a forged API request gets 403, and a store-mode manifest with the pool for it still gets 403 at instance create; (3) a plain create in US by any account stays legacy and lands on adi-knitting. |