carlos / platform Public

app-region-set: Astra review brief, round 1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev f686d3d5e26efd000f144e10a94318f96a7f65e5 parent 1e9b8b3
1 file changed, +149 −0
  • docs/superpowers/specs/CODEX-REVIEW-BRIEF-APP-REGION-SET.md +149 −0

CI failed — run details

diff --git a/docs/superpowers/specs/CODEX-REVIEW-BRIEF-APP-REGION-SET.md b/docs/superpowers/specs/CODEX-REVIEW-BRIEF-APP-REGION-SET.md
new file mode 100644
index 000000000..86c7516fe
--- /dev/null
+++ b/docs/superpowers/specs/CODEX-REVIEW-BRIEF-APP-REGION-SET.md
@@ -0,0 +1,149 @@
+# Review brief: branch app-region-set (carlos apps region), round 1 of 3
+
+Repo carlos/platform, branch `app-region-set`, commit named in the prompt
+(the commit that adds this brief).
+Under review: the diff `origin/main..app-region-set`
+(`git diff origin/main...HEAD`).
+Authorities: AGENTS.md (the security gate order, the Stopping rules, the
+census section); `docs/superpowers/specs/2026-10-01-nearest-region-default-design.md`
+(the app region and its readers); `docs/superpowers/specs/2026-10-25-region-labels-design.md`
+(labels). All MERGED on main. The member-moves design is on an unmerged
+branch: do not review against it; its §18 Q5 ruling is quoted below as a
+ruling, nothing more.
+
+You are an independent reviewer. Read the diff, then the code it names, and
+check every claim against that code.
+
+## What the branch does
+
+An app's stored region (`apps.region` in the console's SQLite) is the
+default region for the app's NEW instances. Until now only create set it.
+The branch adds:
+
+- `GET` and `PUT /api/cli/apps/{account}/{app}/region`
+ (`internal/console/appregionset.go`), registered with `svcrole.Set{}`
+ (closed to every service credential).
+- `POST /a/{sqid}/apps/{app}/region`, the browser form on Settings >
+ General's Region section (`app_settings.html`).
+- `carlos apps region --app <x> [--set <code>]` (`apps_region_cmd.go`).
+- `apps.region_set_at`, read by the placement discrepancy log
+ (`regiondrift.go` via `Store.NonHomeAppRegions`).
+
+## Fixed: do not re-argue
+
+Paul's design (2026-10-26, relayed in the task):
+
+- Only the default for new instances changes. Existing instances never
+ move. Deploy `--region` keeps comparing against the stored region.
+- Who may change it: the account's owner and deployment operators.
+ Members and service credentials are refused, using the existing
+ owner-only gate pattern.
+- Refusals checked up front: unknown or not-offered region; an app on a
+ fleet (use `carlos apps place`); an app in the Trash; temporary apps if
+ pinned; the `CONSOLE_APP_REGIONS` switch per the create-time behaviour.
+- An audit line with the old and the new region. No new polling.
+
+The builder's rulings (record a P1 only if one is unsafe or breaks
+something, with evidence):
+
+1. "Deployment operator" is `platformOperator`: an owner of the ops
+ account or an address on `CARLOS_SYSTEM_OPERATORS`, as the app policy
+ door and the platform-domain door use. An operator reaches any account
+ by sqid without being a member; anyone else goes through
+ `apiPrincipalAccount` (byte-identical 404 for a non-member). A member
+ gets a 403 with the owner sentence, as `apiOwnerAccountFor` does. Any
+ member may READ the region.
+2. The switch: the write is allowed with `CONSOLE_APP_REGIONS` off. The
+ instance create door reads the stored region with the switch off
+ (`apiinstances.go`, the app-derived region branch has no switch check),
+ and member moves §18 Q5 (Paul) accepted writing it with the switch off.
+3. Temporary apps are not pinned (create takes a region for them), so they
+ are allowed.
+4. Extra refusals the code shows are needed: a pooled app (the create door
+ ignores the app region for a pooled manifest), a region the app's
+ manifest allow-list excludes, a region that cannot start an instance
+ now by the create door's own positive test (so a no-region create after
+ the change is not refused), and a host-claim console (no claim operation
+ gates the row write; host claims are shelved).
+5. The write is SQLite only: no bucket object and no serial bump, because
+ no box reads `apps.region`.
+6. The Settings control's options come from the in-memory region name map,
+ so a page view reads no store; the door validates the choice on submit.
+
+## What to check
+
+1. **Authorization, the security gate (focus here).** For both the API and
+ the browser door: can anyone other than an account owner or a
+ deployment operator change an app's region? Walk every principal kind
+ (person member, person owner, person non-member, ops owner, listed
+ system operator, service credential of every role, an app-bound
+ service credential, a revoked or expired token), every account
+ reference form (sqid, name, `?exact=sqid`, a name that collides with
+ another account's sqid), and the operator branch's fall-through to the
+ member path. Is the non-member answer byte-identical to the family's
+ 404 in every case, so the door is no membership or existence oracle?
+ Does the trashed-app 409 leak anything to a caller who could not
+ otherwise see the app? Is the browser gate order session, CSRF, then
+ owner/operator (404), as AGENTS.md requires?
+2. **The write.** `setAppRegion` holds `lockApp`, re-reads the
+ incarnation, and `Store.SetAppRegion` pins `created_at` and the region
+ it read. Can a rename, a purge and re-create, a trash, a placement or
+ another change in between make it write the wrong row or a stale value?
+ Is anything written or audited on any refusal path?
+3. **Every reader of `apps.region`** (grep `AppRegion(`, `appRegion(`,
+ `region_source`, `NonHomeAppRegions`): the instance create door, the
+ `/regions` app_default that `carlos deploy --region` and `carlos canary
+ --region` compare against, seeded instance creates, region labels, the
+ app create echo, the discrepancy log. Does any of them move, retire or
+ rewrite an existing instance or route when the value changes, or break
+ on the new `region_source` value `changed`?
+4. **Migration.** `region_set_at` in the ALTER list and in
+ `migrateAppsKey`'s rebuild. A console rolled back to main must still
+ start and work on the migrated database.
+5. **Refusals and request budget.** Each refusal fires before the write,
+ in an order that never reveals more than the caller may see. Requests
+ per change: one manifest GET (appPolicy), the edges reads of
+ `readExplicitGate` and `liveEdges`; per GET and per page view: none of
+ the bucket. Is any new polling or per-view store read added?
+6. **Tests.** `internal/console/appregionset_test.go` and
+ `apps_region_cmd_e2e_test.go` run a real console. Do they prove the
+ authorization matrix, each refusal, that existing instances do not move,
+ and deploy `--region` after a change? Name any gap that would hide a
+ defect.
+7. **The census approval** (AGENTS.md, "The census"). The card is
+ `docs/superpowers/notes/census-proposal-app-region-set.md`. Give a
+ verdict per unit and per re-pinned envelope (`.`, `internal/console`,
+ `internal/console/templates`, `internal/regionlabel`), citing the lines
+ you read: approve, or escalate if root can now open, run, query or
+ follow anything from a tenant-, app- or box-writable path or input, or
+ a check the basis relies on is weakened.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the area, the problem, the evidence
+(file:line, verified), the failure scenario, a concrete fix and the
+invariant or trust boundary it breaks (that is its fault family). Then the
+census verdicts. End with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites; a targeted `go test -run` on a
+package is fine (leave GOCACHE unset).