plan: path routes across boxes rev 4, plan round 3 fixes
Paul: fix and build, no fourth plan round. LocalTarget outcome, all five selectUpstream callers and exact guard allowlists, fail-closed claim inventory in pathmapcheck, pathMatch over the demo-aware lookup.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+26
−14
docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md+26 −14
CI passed — run details
diff --git a/docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md b/docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md| index 05b73f50f..6f1b6591b 100644 |
| --- a/docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md |
| +++ b/docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md |
| @@ -10,7 +10,7 @@ |
| **Spec:** `docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md` (rev 5, approved by Paul 2026-11-19). Read it first; section numbers below are its. |
| -**Plan history.** Rev 1 reviewed by Astra (`docs/superpowers/reviews/ASTRA-FINDINGS-path-routes-across-boxes-plan-R1.md`: 4 P1, 7 P2, 1 P3). Rev 2 answers each: P1-1 one validated selection (Task 6), P1-2 selection before admission (Task 8), P1-3 owner in the front mark (Tasks 6, 8), P1-4 same-box eligibility kept (Global Constraints, Tasks 3, 6), P2-5 pinned requests (Task 6), P2-6 one atomic snapshot (Task 5), P2-7 benchmark boundaries (Tasks 1, 5, 13), P2-8 harness addresses (Task 8), P2-9 test matrix and guard (Tasks 4, 6, 8, 9, end), P2-10 interfaces (Tasks 5, 8, 10), P2-11 census (Task 13), P3-12 (Task 12). Rev 2 reviewed (`...-plan-R2.md`: 4 P1, 3 P2). Three families repeated, so rule 2 applied and Paul chose its third option (2026-11-20): **one selection entry point**, enforced by the existing structural guard; case 1 is today's code plus one guard; the arrived-hop fallback is settled inside selection (Task 6). The new families are fixed directly: a remote selection is dispatched before any front HA step (Tasks 8, 9), and the pre-roll check reads published maps, not derived rows (Task 12's `pathmapcheck`, Task 13). |
| +**Plan history.** Rev 1 reviewed by Astra (`docs/superpowers/reviews/ASTRA-FINDINGS-path-routes-across-boxes-plan-R1.md`: 4 P1, 7 P2, 1 P3). Rev 2 answers each: P1-1 one validated selection (Task 6), P1-2 selection before admission (Task 8), P1-3 owner in the front mark (Tasks 6, 8), P1-4 same-box eligibility kept (Global Constraints, Tasks 3, 6), P2-5 pinned requests (Task 6), P2-6 one atomic snapshot (Task 5), P2-7 benchmark boundaries (Tasks 1, 5, 13), P2-8 harness addresses (Task 8), P2-9 test matrix and guard (Tasks 4, 6, 8, 9, end), P2-10 interfaces (Tasks 5, 8, 10), P2-11 census (Task 13), P3-12 (Task 12). Rev 2 reviewed (`...-plan-R2.md`: 4 P1, 3 P2). Three families repeated, so rule 2 applied and Paul chose its third option (2026-11-20): **one selection entry point**, enforced by the existing structural guard; case 1 is today's code plus one guard; the arrived-hop fallback is settled inside selection (Task 6). The new families are fixed directly: a remote selection is dispatched before any front HA step (Tasks 8, 9), and the pre-roll check reads published maps, not derived rows (Task 12's `pathmapcheck`, Task 13). Rev 3 reviewed (`...-plan-R3.md`: 3 P1, 1 P2, 1 P3); Paul chose to fix and build without a fourth plan round (2026-11-20). Rev 4: an explicit `LocalTarget` outcome for HA and login (R3 P1-1), all five `selectUpstream` callers and exact guard allowlists (R3 P1-2), a fail-closed claim inventory in `pathmapcheck` (R3 P1-3), `pathMatch` as an `Edge` method over the demo-aware lookup (R3 P2-4), matrix names (R3 P3-5). |
| ## Global Constraints |
| @@ -183,8 +183,11 @@ func matchPrefix(prefixes map[string]string, urlPath string) (prefix, target str |
| // pathMatch is today's lookupUpstreamPath over one map, plus case 1's guard, |
| // reporting what it matched: up/ok are exactly what lookupUpstreamPath returns |
| // (the target's entry on a valid local hit, else the front's), prefix/target |
| -// are set whenever a prefix matched, local says the target was served here. |
| -func pathMatch(m map[string]upstream, host, urlPath string) (up upstream, ok bool, prefix, target string, local bool) |
| +// are set whenever a prefix matched, local says the TARGET's entry was answered |
| +// (true for a platform-alias target too, whose route.Host is its instance's). |
| +// A method: the host half is e.lookupDemoAware, exactly as today, so demo |
| +// namespace rules hold (demo_test.go's reserved-apex witness stays green). |
| +func (e *Edge) pathMatch(m map[string]upstream, host, urlPath string) (up upstream, ok bool, prefix, target string, local bool) |
| type frontMark struct { |
| Host, Account, App string |
| @@ -202,6 +205,11 @@ type requestSelection struct { |
| Remote *remoteTarget // non-nil: hop to the target instead (Task 8); Up/OK then hold nothing |
| Prefix string // the matched prefix, whenever one matched |
| Target string // the matched target host, whenever one matched |
| + // LocalTarget: Up is the matched target's own entry, served here (case 1 |
| + // or case 3). The ONLY signal downstream consumers (HA identity, login) |
| + // use for "a target was selected"; never compare Target with Up.route.Host, |
| + // which differ for a platform-alias target. |
| + LocalTarget bool |
| } |
| // selectUpstream is THE selection: pinned branch first and unchanged; then |
| // pathMatch on the local map; then selectAcross for cases 2 and 3. The |
| @@ -222,11 +230,15 @@ Rules: |
| - A door caller never gets cases 2 or 3 (front's entry, or `OK=false`). |
| - Each cross-box refusal logs once per host, throttled, key `path-skip <host>`, naming the reason (spec §5.6). |
| - `lookupUpstreamPath(host, path)` keeps its signature and answer: `pathMatch`'s `up, ok`. |
| -- The guard: `TestSelectUpstreamIsTheOnlySite` anchors on `selectUpstream` calling `pathMatch`; `pathMatch`, `selectAcross` and reads of `routeTable.remote` are allowed only inside `selectUpstream`, `selectAcross`, `Reload`/`buildRemotePaths` and the purge functions of Task 10 (each listed with its reason, as `mapReadSites` already does). `storeHosts` lives in a `_test.go` file (`TestReloadIsTheOnlyPublisher`). |
| +- The guard, `TestSelectUpstreamIsTheOnlySite`, with three exact allowlists (each entry carries its reason, as `mapReadSites` does): |
| + - **selection entry**: callers of `selectAcross`: `selectUpstream` only. Callers of `pathMatch`: `selectUpstream` and `lookupUpstreamPath` (the compatibility wrapper, which stays restricted to `lookupNonRequestSites` as today). The anchor check becomes "`selectUpstream` calls `pathMatch`". |
| + - **lookup primitives**: `mapReadSites["lookupDemoAware"]` gains `pathMatch`; `lookupUpstreamPath` stays in it while it still calls `lookupDemoAware` indirectly only through `pathMatch` (drop it if it no longer reads directly). |
| + - **remote-map reads** (new kind `routeTable.remote`): `selectAcross`, `buildRemotePaths`, `Reload`, `purgeOwnsIn`, `resolvePurgeOwnersIn`. |
| + `storeHosts` lives in a `_test.go` file (`TestReloadIsTheOnlyPublisher`). |
| -- [ ] **Step 1: Write the failing tests** (home map from the edges-file helpers in `homemap_test.go`): `TestSelectCase1LocalTarget`; `TestSelectCase1ServiceTarget`; `TestSelectCase1PlatformAliasTarget` (plan R2 P1-2: a same-account platform-minted target keeps working); `TestSelectCase1AttachedAliasRefused` (an attached alias of account B's route: the front's entry); `TestSelectCase1OtherAccountRefused`; `TestSelectCase2RemoteTarget`; `TestSelectCase2TargetOtherAccount`; `TestSelectCase2TargetNotReady` (Review Focus 4); `TestSelectCase2ForwardFrontNeverRemote`; `TestSelectCase3LocalTarget` (front mark carries host, account, app, stamp, incarnation); `TestSelectCase3LocalTargetOtherAccount`; `TestSelectCase3RemoteTargetOtherAccount`; `TestSelectCase3LocalServiceTargetRefused`; `TestSelectCase3FrontOwnerMismatch`; `TestSelectCase3PrefixMiss`; `TestSelectBothSpellings` (Review Focus 5, case 3); `TestSelectWildcardFrontNeverAcross`; `TestSelectAliasFrontNeverAcross`; `TestSelectForwardTargetNeverSelected`; `TestSelectDoorNeverAcross`; `TestSelectDoorHopIgnoresRemoteMap`; `TestSelectHATarget`; `TestSelectArrivedHopRemoteServesFront` (front served here: front's entry, `Remote == nil`); `TestSelectArrivedHopRemoteNotServed` (`OK=false`, `Remote == nil`); `TestSelectPinnedIgnoresPathMaps` (a pinned request whose app's hostname has local and remote prefixes: the pinned entry, no `Prefix`, no `Remote`). Extend `TestSelectUpstreamIsTheOnlySite` as above. |
| +- [ ] **Step 1: Write the failing tests** (home map from the edges-file helpers in `homemap_test.go`): `TestSelectCase1LocalTarget`; `TestSelectCase1ServiceTarget`; `TestSelectCase1PlatformAliasTarget` (plan R2 P1-2: a same-account platform-minted target keeps working, `LocalTarget` true); `TestSelectDemoApexNotViaCatchAll` (R3 P2-4: the reserved demo apex is never resolved through a parent catch-all, as `demo_test.go` asserts today); `TestSelectCase1AttachedAliasRefused` (an attached alias of account B's route: the front's entry); `TestSelectCase1OtherAccountRefused`; `TestSelectCase2RemoteTarget`; `TestSelectCase2TargetOtherAccount`; `TestSelectCase2TargetNotReady` (Review Focus 4); `TestSelectCase2ForwardFrontNeverRemote`; `TestSelectCase3LocalTarget` (front mark carries host, account, app, stamp, incarnation); `TestSelectCase3LocalTargetOtherAccount`; `TestSelectCase3RemoteTargetOtherAccount`; `TestSelectCase3LocalServiceTargetRefused`; `TestSelectCase3FrontOwnerMismatch`; `TestSelectCase3PrefixMiss`; `TestSelectBothSpellings` (Review Focus 5, case 3); `TestSelectWildcardFrontNeverAcross`; `TestSelectAliasFrontNeverAcross`; `TestSelectForwardTargetNeverSelected`; `TestSelectDoorNeverAcross`; `TestSelectDoorHopIgnoresRemoteMap`; `TestSelectHATarget`; `TestSelectArrivedHopRemoteServesFront` (front served here: front's entry, `Remote == nil`); `TestSelectArrivedHopRemoteNotServed` (`OK=false`, `Remote == nil`); `TestSelectPinnedIgnoresPathMaps` (a pinned request whose app's hostname has local and remote prefixes: the pinned entry, no `Prefix`, no `Remote`). Extend `TestSelectUpstreamIsTheOnlySite` as above. |
| - [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestSelect|TestPathMatch' -count=1` → FAIL. |
| -- [ ] **Step 3: Implement.** `ServeHTTP` and the login block adapt to the new return type in this task with no behaviour change: they read `sel.Up`/`sel.OK` and ignore `Remote` until Task 8 (a `Remote` selection is treated as the front's entry, today's answer, by a one-line adapter that Task 8 removes). |
| +- [ ] **Step 3: Implement.** Migrate all five production callers of `selectUpstream` to the new return type with no behaviour change: `ServeHTTP` (~edge.go:2485), the login block (~edge.go:2789), `demo.go:94`, `demo.go:120`, `pagecache.go:533`. Each reads `sel.Up`/`sel.OK`; until Task 8, a `Remote` selection is treated as the front's entry (today's answer) by a one-line adapter in `ServeHTTP` that Task 8 removes; the other four never dispatch a remote and treat it the same way permanently. |
| - [ ] **Step 4: Run** `-run 'TestSelect|TestPath|TestFirstSegment|TestLinked|TestReloadIsTheOnlyPublisher'` → PASS. |
| - [ ] **Step 5: Commit** `edge: one selection entry point for path routes across boxes (#186)`. |
| @@ -294,9 +306,9 @@ Harness: a three-edge scene on the `BackhaulHolderScene` pattern: boxes A (hub), |
| - Test: `internal/edge/path_across_ha_test.go` |
| **Interfaces:** |
| -- Produces: `func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host, routeName string, up upstream, local bool) bool`. Every identity lookup in it uses `routeName`: `ingressRoute`, `resolveName`, the servesExactly name, and the `haIngressBlocked` check (today `[host] || [rt.Host]`, becomes `[routeName] || [rt.Host]`; plan R2 P1-1). `frontForwardHAIngress(w, r, host, rt)` keeps `host` as the wire Host. The call site passes `up.route.Host` when the selection matched a prefix and answered a target (`sel.Target != "" && sel.Up.route.Host == sel.Target`), else `host`. A `Remote` selection never reaches it (Task 8). `frontForwardHA` and `moveGate` already take identity from the route and wire from `host`; the tests pin that. |
| +- Produces: `func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host, routeName string, up upstream, local bool) bool`. Every identity lookup in it uses `routeName`: `ingressRoute`, `resolveName`, the servesExactly name, and the `haIngressBlocked` check (today `[host] || [rt.Host]`, becomes `[routeName] || [rt.Host]`; plan R2 P1-1). `frontForwardHAIngress(w, r, host, rt)` keeps `host` as the wire Host. The call site passes `sel.Up.route.Host` when `sel.LocalTarget`, else `host` (a platform-alias target's identity is its instance's route, which is what `Up.route.Host` holds). A `Remote` selection never reaches it (Task 8). `frontForwardHA` and `moveGate` already take identity from the route and wire from `host`; the tests pin that. |
| -- [ ] **Step 1: Write the failing tests** on Task 8's scene with T born-HA, B and C in T's pool: `TestPathAcrossHATargetFromFrontBox`; `TestPathAcrossHATargetFromThirdBox`; `TestPathAcrossHATargetFromNonHolderPoolBox` (B not holder: B's 503 names C; A follows to C with wire `Host: hub.example`; C serves; holder remembered under T); `TestPathAcrossHAHandoverFollowKeyedOnTarget`; `TestPathAcrossHAFrontRemoteTargetSkipsFrontHA` (hub HA, its lease elsewhere and its name in `haIngressBlocked`; a prefix selects remote T: the request reaches T, no front forward, no HA refusal); `TestPathAcrossHAFrontLocalTargetSkipsFrontHA` (same with T local); `TestPathAcrossHAFrontNoPrefixAsToday`. |
| +- [ ] **Step 1: Write the failing tests** on Task 8's scene with T born-HA, B and C in T's pool: `TestPathAcrossHATargetFromFrontBox`; `TestPathAcrossHATargetFromThirdBox`; `TestPathAcrossHATargetFromNonHolderPoolBox` (B not holder: B's 503 names C; A follows to C with wire `Host: hub.example`; C serves; holder remembered under T); `TestPathAcrossHAHandoverFollowKeyedOnTarget`; `TestPathAcrossHAFrontRemoteTargetSkipsFrontHA` (hub HA, its lease elsewhere and its name in `haIngressBlocked`; a prefix selects remote T: the request reaches T, no front forward, no HA refusal); `TestPathAcrossHAFrontLocalTargetSkipsFrontHA` (same with T local); `TestPathAcrossHAFrontNoPrefixAsToday`; `TestPathAcrossHAFrontPlatformAliasTarget` (R3 P1-1: HA front H, same-box platform-alias target P backed by instance I: `routeHAIngress` gets I, the request is served by I, H's blocked state does not refuse it). |
| - [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestPathAcrossHA' -count=1` → FAIL. |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run** `-run 'TestPathAcross|TestHAIngress|TestForwardHA|TestHandover'` → PASS. |
| @@ -329,10 +341,10 @@ Harness: a three-edge scene on the `BackhaulHolderScene` pattern: boxes A (hub), |
| **Interfaces:** |
| - Consumes: Task 6's `selectUpstream` (the login block already re-selects through it, with `lookupPath` parsed from `next` by `url.ParseRequestURI`). |
| -- Produces: `func refuseLoginAcross(w http.ResponseWriter, sel requestSelection) bool`: true (and the refusal written: 409, `Cache-Control: no-store`, the approved sentence) when `sel.Prefix != ""` and the answer is not a same-box target: `sel.Remote != nil`, or `sel.Up.front != nil`, or `!sel.OK`, or `sel.Up.route.Host != sel.Target`. Called on the login block's existing selection result, before `admissionRefuses`, any password hash or cookie. A pinned login has no `Prefix` (Task 6) and is never refused. |
| +- Produces: `func refuseLoginAcross(w http.ResponseWriter, sel requestSelection) bool`: true (and the refusal written: 409, `Cache-Control: no-store`, the approved sentence) when `sel.Prefix != ""` and the answer is not a same-box target: `!sel.LocalTarget`, or `sel.Up.front != nil`. Called on the login block's existing selection result, before `admissionRefuses`, any password hash or cookie. A pinned login has no `Prefix` (Task 6) and is never refused. |
| - [ ] **Step 1: Draft the refusal sentence and run the copy-review skill on it.** Draft: "This page's sign-in isn't available here. Open the page again from its own address." Write only the approved text. |
| -- [ ] **Step 2: Write the failing tests.** `TestGateLoginRefusedForRemoteTarget` (409, the copy, no `Set-Cookie`, the front's gate never consulted); `TestGateLoginRefusedWhenTargetIneligible`; `TestGateLoginRefusedWithQueryString` (`next=/acme?tab=1`); `TestGateLoginRefusedWithEncodedPrefix` (`next=/%61cme/x`); `TestGateLoginPinnedNotRefused`; `TestGateLoginSameBoxUnchanged`. |
| +- [ ] **Step 2: Write the failing tests.** `TestGateLoginRefusedForRemoteTarget` (409, the copy, no `Set-Cookie`, the front's gate never consulted); `TestGateLoginRefusedWhenTargetIneligible`; `TestGateLoginRefusedWithQueryString` (`next=/acme?tab=1`); `TestGateLoginRefusedWithEncodedPrefix` (`next=/%61cme/x`); `TestGateLoginPinnedNotRefused`; `TestGateLoginSameBoxUnchanged`; `TestGateLoginSameBoxPlatformAliasTarget` (R3 P1-1: not refused). |
| - [ ] **Step 3: Run** `go test ./internal/edge/ -run 'TestGateLogin' -count=1` → FAIL. |
| - [ ] **Step 4: Implement.** |
| - [ ] **Step 5: Run** `-run 'TestGateLogin|TestGate|TestLinked'` → PASS. |
| @@ -346,9 +358,9 @@ Harness: a three-edge scene on the `BackhaulHolderScene` pattern: boxes A (hub), |
| - Test: `internal/console/apiroutes_paths_test.go` |
| **Interfaces:** |
| -- Produces: `scripts/pathmapcheck` (plan R2 P1-4), a read-only Go program: `go run ./scripts/pathmapcheck -bucket <control bucket> -region <region>` (AWS credentials from `AWS_PROFILE`). It lists every claim with `domains.ListClaims`, keeps those with `Paths`, reads every edges file under `control/edges/` and, for each front and each target, folds its home with `edge.FoldedHome`. It prints one line per map: `front`, prefix count, cross-box target count, and up to three examples, and exits 1 when any target's home box differs from its front's, or is unknown. Core logic in `func check(ctx context.Context, s release.Store) (report, error)` so the test runs against a fake store. |
| +- Produces: `scripts/pathmapcheck` (plan R2 P1-4), a read-only Go program: `go run ./scripts/pathmapcheck -bucket <control bucket> -region <region>` (AWS credentials from `AWS_PROFILE`). It lists every key under `domains.ClaimsPrefix` with the store's own listing and reads each with `domains.GetClaim`, **failing closed** (R3 P1-3): any listing error, failed GET or undecodable claim is reported and makes the verdict exit 1 (`domains.ListClaims` is not used: it skips unreadable claims). It keeps claims with `Paths`, reads every edges file under `control/edges/` and, for each front and each target, folds its home with `edge.FoldedHome`. It prints one line per map: `front`, prefix count, cross-box target count, and up to three examples, and exits 1 when any target's home box differs from its front's, or is unknown. Core logic in `func check(ctx context.Context, s release.Store) (report, error)` so the test runs against a fake store. |
| -- [ ] **Step 1: Write the tests.** `TestRoutesListingOmitsOrphanPathRows` (regression; passes today, plan R1 P3-12). `TestPathMapCheckFindsAllRemoteMap` (a claim whose every target is homed on another box, with no derived rows anywhere: reported, exit status 1); `TestPathMapCheckSameBoxMapClean`; `TestPathMapCheckUnknownTargetReported`. |
| +- [ ] **Step 1: Write the tests.** `TestRoutesListingOmitsOrphanPathRows` (regression; passes today, plan R1 P3-12). `TestPathMapCheckFindsAllRemoteMap` (a claim whose every target is homed on another box, with no derived rows anywhere: reported, exit status 1); `TestPathMapCheckSameBoxMapClean`; `TestPathMapCheckUnknownTargetReported`; `TestPathMapCheckFailedClaimReadFails` (one claim GET errors: exit 1, the key named); `TestPathMapCheckMalformedClaimFails`. |
| - [ ] **Step 2: Run** `go test ./internal/console/ -run TestRoutesListingOmitsOrphanPathRows -count=1` (PASS) and `go test ./scripts/pathmapcheck/ -count=1` (FAIL). |
| - [ ] **Step 3: Implement** `pathmapcheck`; update the comments, help text and docs (`docs/site` prose through copy review). The runbook names: the pre-roll `pathmapcheck` run on dev and flagship, the full roll, and that the Rastrillo hub scaffold publishes cross-box maps only after it, with its version poll allowing at least a minute (spec §6). |
| - [ ] **Step 4: Run** both again → PASS; `go test ./internal/host/ -run 'TestAssetPolicy' -count=1` stays green. |
| @@ -383,7 +395,7 @@ Harness: a three-edge scene on the `BackhaulHolderScene` pattern: boxes A (hub), |
| | §7.1 | regional names | `TestRemotePathsSkipRegionalName` | |
| | §7.2 | purge | Task 10 tests | |
| | §7.3 | gate refusal (pinned, query, encoded) | Task 11 tests | |
| -| §7.4 | door cut | `TestSelectPathDoorNeverAcross`, `TestSelectPathDoorHopIgnoresRemoteMap`, `TestPathAcrossDoorCallStaysSameBox`, `TestPathAcrossDoorHopMapsDiffer` | |
| -| §7.5 | fleets | `TestSelectPathForwardTargetNeverSelected`, `TestRemotePathsSkipForwardHost` | |
| +| §7.4 | door cut | `TestSelectDoorNeverAcross`, `TestSelectDoorHopIgnoresRemoteMap`, `TestPathAcrossDoorCallStaysSameBox`, `TestPathAcrossDoorHopMapsDiffer` | |
| +| §7.5 | fleets | `TestSelectForwardTargetNeverSelected`, `TestRemotePathsSkipForwardHost` | |
| | §8 | ordering rule | `pathmapcheck` tests; Task 12 runbook; Task 13 Steps 6-8 | |
| | §9 | dev witness | Task 13 Step 8 | |