carlos / platform Public

plan: path routes across boxes rev 3, one selection entry point (rule 2)

Paul's choice after plan round 2: one selection entry point guarded by
TestSelectUpstreamIsTheOnlySite, case 1 unchanged plus one guard, the
arrived-hop fallback settled in selection; remote selections dispatched
before any front HA step; pathmapcheck reads published maps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7240922da6290b01ed63328241759319d151a317 parent 647f2e9
1 file changed, +79 −69
  • docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md +79 −69
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 36267def6..05b73f50f 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).
+**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).
## Global Constraints
@@ -18,11 +18,11 @@
- No new hop header. The receiving box re-selects from `Host` and path.
- A target must be in the claim's account on every box (09-02 rule, spec §5.3).
- The matcher stays the 09-02 one: first segment, cleaned form then raw form, cleaned wins, one hop of indirection. One implementation, shared by the local and remote maps.
-- **Two eligibility rules, never mixed.** *Same-box* (case 1: the front and the target are both local, exactly as today): the target entry is a route's own entry (not alias, platform alias or regional) whose route is ready, not a sidecar or demo, and in the map's account; any kind, `service` included. *Cross-box* (cases 2 and 3): `PathFront` for the front, `PathTarget` for the target.
+- **Two eligibility rules, never mixed.** *Same-box* (case 1: the front and the target are both local): **today's `lookupUpstreamPath` answer, unchanged, plus one guard**: the target entry is refused when it is an attached alias (`alias && !platformAlias`) or its route's account differs from the front entry's route account. Platform-alias targets and every route kind (`service` included) keep working. *Cross-box* (cases 2 and 3): `PathFront` for the front, `PathTarget` for the target.
+- **One selection entry point.** `selectUpstream` is the only function that chooses a request's upstream, for the main dispatch and for the login re-selection alike. Its pinned branch stays first. `TestSelectUpstreamIsTheOnlySite` is extended so the new selection functions and the routing table's remote map can only be reached from it.
- `PathTarget(rt)`: `rt.Status == "ready"`, `rt.Kind` is `instance` or `static`, and not `IsForward()`, `IsDemo()` or `IsSidecar()`. `PathFront(rt)`: `rt.Kind` is `instance` or `static`, not `IsForward()`, `IsDemo()` or `IsSidecar()`. HA changes neither.
- No `path-hops-1` capability and no roll gate (spec §8, Paul's cut).
- New edges-file fields are additive and `omitempty`: `route_account`, `route_app`, `path_front`, `path_target`. Absent reads as false/empty.
-- Linked (pinned) requests never reach the new selection: `selectUpstream`'s pinned branch stays first and unchanged.
- Door calls never select across boxes (cases 2 and 3), and a door-marked hop never takes a remote-map answer.
- Cost budget (spec §6): at 10 hosts × 10,000 prefixes, the reconcile pass's path section, one `Fingerprint` and one `Reload` each under 100 ms on a dev box; an unchanged republish writes zero rows.
- Code health (AGENTS.md "Writing Go here"): `internal/edge/edge.go` is past 3,000 lines and `ServeHTTP` past 300, so neither may grow. New edge code goes in new files (`pathremote.go`, `pathselect.go`, `pathhop.go`); `ServeHTTP` gains calls, not bodies, and loses at least as many lines as it gains (extract existing blocks if needed). Run `make code-health` before pushing.
@@ -123,7 +123,7 @@ func (m *homeMap) exactPathRoute(host string) (pathRouteInfo, bool)
Writer rule: the four fields only on real route rows (not `*.`-prefixed, not a `platformSources` alias, not an attached alias); `RouteAccount = release.RouteAccount(r)`, `RouteApp = r.App`, `PathFront = registry.PathFront(r)`, `PathTarget = registry.PathTarget(r)`. Today's `account`/`app` untouched. Reader: the four values travel with the dial winner, never merged.
-- [ ] **Step 1: Write the failing tests.** Host: `TestEdgesFilePublishesRouteOwner` (instance route with path rows to other apps: `account`/`app` empty, route fields set, both marks true); `TestEdgesFileAliasRowsCarryNoRouteOwner`; **`TestEdgesFilePathMarksMatchPredicates`** (the spec §5.1 guard: for every `registry.PathEligibilityCases` entry, write that route through `edgesFileWriteClaims`, read the published row back, and assert `path_front`/`path_target` equal `PathFront`/`PathTarget` of the route; a forward row is never a target). The existing mixed-owner test stays green. Edge: `TestExactPathRouteIgnoresWildcard`; `TestExactPathRouteReadsWinner`; `TestExactPathRouteAbsentFieldsAreFalse`.
+- [ ] **Step 1: Write the failing tests.** Host: `TestEdgesFilePublishesRouteOwner` (instance route with path rows to other apps: `account`/`app` empty, route fields set, both marks true); `TestEdgesFileAliasRowsCarryNoRouteOwner`; **`TestEdgesFilePathMarksMatchPredicates`** (the spec §5.1 guard: for every `registry.PathEligibilityCases` entry, write that route through `edgesFileWriteClaims`; when the writer publishes the row, assert `path_front`/`path_target` equal `PathFront`/`PathTarget` of the route; when the writer excludes it by its existing filters (a non-ready route, a sidecar), assert the row is absent, and list which cases are absent in the test so a filter change shows up; a forward row is never a target). The existing mixed-owner test stays green. Edge: `TestExactPathRouteIgnoresWildcard`; `TestExactPathRouteReadsWinner`; `TestExactPathRouteAbsentFieldsAreFalse`.
- [ ] **Step 2: Run** `go test ./internal/host/ -run 'TestEdgesFile(PublishesRouteOwner|AliasRowsCarryNoRouteOwner|PathMarksMatchPredicates)' -count=1` and `go test ./internal/edge/ -run TestExactPathRoute -count=1` → FAIL.
- [ ] **Step 3: Implement** writer fields, reader fields, fold carry-through and `exactPathRoute` (via `resolveHomeName(host, nil, true, snap.hosts)`; require `State == NameDialable`, `Authority.Class == NameRoute`, the entry's `routeAccount != ""`).
- [ ] **Step 4: Run** → PASS.
@@ -152,7 +152,7 @@ type routeTable struct {
// Edge field becomes: upstreams atomic.Pointer[routeTable]
func (e *Edge) current() map[string]upstream // unchanged signature: table.hosts, nil before the first store
func (e *Edge) table() *routeTable // the whole snapshot; nil before the first store
-func (e *Edge) storeHosts(m map[string]upstream) // tests: publishes {hosts: m, remote: nil}
+func (e *Edge) storeHosts(m map[string]upstream) // in internal/edge/routetable_test.go only (TestReloadIsTheOnlyPublisher): publishes {hosts: m, remote: nil}
func buildRemotePaths(m map[string]upstream, rows []registry.RoutePath, forwardHosts, regional map[string]bool, demoReserved func(string) bool) map[string]remotePathMap
```
@@ -165,11 +165,11 @@ func buildRemotePaths(m map[string]upstream, rows []registry.RoutePath, forwardH
- [ ] **Step 5:** Switch `BenchmarkReloadPaths` to unserved hosts (rows land in `remote`), re-run all three benchmarks, record in the ledger. Over budget: stop and report.
- [ ] **Step 6: Commit** `edge: one routing snapshot with a remote path map (#186)`.
-### Task 6: One validated selection
+### Task 6: One selection entry point
**Files:**
- Create: `internal/edge/pathselect.go`
-- Modify: `internal/edge/edge.go` (`lookupUpstreamPath` and `selectUpstream` delegate to the new selection; `ServeHTTP` unchanged in this task)
+- Modify: `internal/edge/edge.go` (`lookupUpstreamPath` wraps the new match; `selectUpstream` returns the full selection), `internal/edge/linkpin_test.go` (`TestSelectUpstreamIsTheOnlySite`'s anchors and allowlists)
- Test: `internal/edge/pathselect_test.go`
**Interfaces:**
@@ -180,44 +180,55 @@ func buildRemotePaths(m map[string]upstream, rows []registry.RoutePath, forwardH
// matchPrefix is the 09-02 matcher: cleaned first segment, then raw; cleaned wins.
func matchPrefix(prefixes map[string]string, urlPath string) (prefix, target string, ok bool)
-type pathOutcome int
-const (
- pathNone pathOutcome = iota // Up is the front's own answer (today's), or nothing on a host miss
- pathLocal // Up is the validated target's local entry
- pathRemote // the target is on another box: Route says where
-)
+// 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)
+
type frontMark struct {
Host, Account, App string
Stamp int64
Incarnation uint64
}
-type pathSelection struct {
- Outcome pathOutcome
- Up upstream // pathNone with OK: the front's entry; pathLocal: the target's
- OK bool // Up is set
- Prefix string // the matched prefix, whenever one matched (Task 11 reads it)
- Target string // the matched target host, whenever one matched
- Route pathRouteInfo // pathRemote only
+type remoteTarget struct {
+ Target string // the target route's host
+ Route pathRouteInfo // its published row: Dial, Box, Owner
+}
+// requestSelection is everything a request's dispatch reads from selection.
+type requestSelection struct {
+ Up upstream // dispatch this through the normal stages when OK
+ OK bool
+ 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
}
-// selectPath is THE selection: spec §5.3's four cases, validation included,
-// over one table. hopped and door restrict it (Global Constraints).
-func (e *Edge) selectPath(t *routeTable, host, urlPath string, door, doorHop bool) pathSelection
+// selectUpstream is THE selection: pinned branch first and unchanged; then
+// pathMatch on the local map; then selectAcross for cases 2 and 3. The
+// arrived-hop rule is settled here: on a verified hop a remote answer never
+// leaves Remote set; it becomes the front's own entry when this box serves the
+// front (spec §5.4), else OK=false (the caller's existing stale-hop refusal).
+func (e *Edge) selectUpstream(r *http.Request, host, urlPath string) requestSelection
+// selectAcross runs cases 2 and 3 over one table; called only by selectUpstream.
+func (e *Edge) selectAcross(t *routeTable, host, urlPath string, front upstream, frontOK bool, prefix, target string, door, doorHop bool) requestSelection
```
-`upstream` gains one field, `front *frontMark`, set only on a case 3 `pathLocal` result (the front is not served here). Rules:
-- Host resolution as today (`lookupDemoAware`), front kept in hand.
-- **Case 1** (front in `t.hosts`, target in `t.hosts`): the same-box rule (Global Constraints). Fails → `pathNone` with the front's entry. This replaces `lookupUpstreamPath`'s unchecked `m[target]` (plan R1 P1-1: an attached alias of another account's route is never selected).
-- **Case 2** (front in `t.hosts` reached exactly, not alias/platform alias/regional, `PathFront`; target not in `t.hosts`, or in it but failing the same-box rule only because it is absent): `exactPathRoute(T)` with `Target` and `Account` equal to the front route's account → `pathRemote`. Else `pathNone` with the front.
-- **Case 3** (front not in `t.hosts`, `t.remote[host]` present, not door): `exactPathRoute(host)` with `Front` and `Account`/`App` equal to `t.remote[host]`'s. Prefix miss → `pathNone`, `OK=false`. Target in `t.hosts` passing the same-box entry-shape checks **and** `PathTarget` and account → `pathLocal` with `Up.front` set from the front's `pathRouteInfo`. Target remote with `exactPathRoute(T)` `Target` and account → `pathRemote`. Else `pathNone`, `OK=false`.
-- `door` (a door caller) → cases 2 and 3 return `pathNone`. `doorHop` (a verified door-marked hop) → case 3 is not consulted.
-- Each refusal logs once per host, throttled, key `path-skip <host>`, naming the reason (spec §5.6).
-- `selectUpstream(r, host, path)` keeps its pinned branch first; otherwise returns `selectPath(...)`'s `Up`/`OK` for `pathNone`/`pathLocal`. `lookupUpstreamPath` becomes `selectPath` with `door=false` returning `Up`/`OK` (`pathRemote` → the front's entry, as today), so every existing caller keeps its answer.
-
-- [ ] **Step 1: Write the failing tests** (home map from the edges-file helpers in `homemap_test.go`): `TestSelectPathCase1LocalTarget`; `TestSelectPathCase1ServiceTarget` (ready `service`: selected, as today); `TestSelectPathCase1AliasOfOtherAccountRefused` (P1-1: front's map names an attached alias of account B's route: `pathNone`, the front's entry); `TestSelectPathCase2RemoteTarget`; `TestSelectPathCase2TargetOtherAccount`; `TestSelectPathCase2TargetNotReady` (Review Focus 4); `TestSelectPathCase3LocalTarget` (front mark carries host, account, app, stamp, incarnation); `TestSelectPathCase3LocalTargetOtherAccount` (remote map selecting another account's local target: `pathNone`); `TestSelectPathCase3LocalServiceTargetRefused` (cross-box rule: `service` not a `PathTarget`); `TestSelectPathCase3FrontOwnerMismatch`; `TestSelectPathCase3PrefixMiss`; `TestSelectPathBothSpellings` (Review Focus 5, on case 3); `TestSelectPathWildcardFrontNeverAcross`; `TestSelectPathAliasFrontNeverAcross`; `TestSelectPathForwardTargetNeverSelected`; `TestSelectPathDoorNeverAcross`; `TestSelectPathDoorHopIgnoresRemoteMap`; `TestSelectPathHATarget` (HA target with `path_target` → `pathRemote`); `TestSelectUpstreamPinnedIgnoresPathMaps` (P2-5: a pinned request for an app whose hostname has local and remote prefixes gets the pinned entry with no path map, never a hop).
-- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestSelectPath|TestSelectUpstream|TestPathMatch' -count=1` → FAIL.
-- [ ] **Step 3: Implement.**
-- [ ] **Step 4: Run** `-run 'TestSelectPath|TestSelectUpstream|TestPath|TestFirstSegment|TestLinked'` → PASS.
-- [ ] **Step 5: Commit** `edge: one validated path selection, across boxes (#186)`.
+`upstream` gains `front *frontMark`, set only on a case 3 local target (the front is not served here). `door` and `doorHop` are read from `r.Context()` inside `selectUpstream` (`doorCallerFrom`, `hopDoorFrom`); `hopped` from `hopVerified`.
+
+Rules:
+- **Case 1** is `pathMatch`: today's code with one guard (Global Constraints). A refused target answers the front's entry, as a missing one does today.
+- **Case 2** (front served here, a prefix matched, target not local): the front must be reached by its exact key and be a route's own entry (`!alias && !platformAlias && regional == regionalNone`) with `PathFront(route)`; `exactPathRoute(T)` must have `Target` and `Account` equal to the front route's account → `Remote`. Otherwise the front's entry, as today.
+- **Case 3** (front not served here, `t.remote[host]` present, not a door caller, not a door hop): `exactPathRoute(host)` with `Front` and `Account`/`App` equal to the remote map's. Prefix miss → `OK=false` (today's backhaul to the front's home). Target local, a route's own entry with `PathTarget` and the map's account → `Up` = target entry with `front` set from `exactPathRoute(host)`. Target remote with `exactPathRoute(T)` `Target` and account → `Remote`. Anything else → `OK=false`.
+- 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`).
+
+- [ ] **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 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 4: Run** `-run 'TestSelect|TestPath|TestFirstSegment|TestLinked|TestReloadIsTheOnlyPublisher'` → PASS.
+- [ ] **Step 5: Commit** `edge: one selection entry point for path routes across boxes (#186)`.
### Task 7: A backhaul for a route under another Host
@@ -246,7 +257,7 @@ func (e *Edge) backhaulRouteTo(w http.ResponseWriter, r *http.Request, wireHost,
**Review:** Astra task review (the hop: rule 3).
-### Task 8: Wire selection into ServeHTTP
+### Task 8: Dispatch a remote selection in ServeHTTP
**Files:**
- Modify: `internal/edge/edge.go` (`ServeHTTP`: calls only, net lines not growing; the ownership block reads `up.front`)
@@ -258,26 +269,20 @@ func (e *Edge) backhaulRouteTo(w http.ResponseWriter, r *http.Request, wireHost,
- Produces:
```go
-// pathRequest is ServeHTTP's selection step, replacing its selectUpstream call:
-// it runs selectPath (pinned requests keep selectUpstream's pinned branch) and
-// returns the upstream to dispatch, ok, and a pending remote selection that
-// servePathRemote acts on later.
-func (e *Edge) pathRequest(r *http.Request, host string, isDoor, hopped bool) (up upstream, ok bool, remote *pathSelection)
-// servePathRemote answers a pending remote selection: on a non-hop request,
-// backhaulRouteTo(w, r, host, sel.Target, sel.Route.Dial, sel.Route.Box, sel.Route.Owner);
-// on a verified hop, never a dial: the front's own entry if this box serves the
-// front (spec §5.4, the home box's rule), else staleHopRefusal.
-func (e *Edge) servePathRemote(w http.ResponseWriter, r *http.Request, host string, sel *pathSelection, hopped bool) bool
+// servePathRemote answers a non-hop request whose selection is Remote:
+// backhaulRouteTo(w, r, host, rt.Target, rt.Route.Dial, rt.Route.Box, rt.Route.Owner).
+// Never reached on a verified hop (selectUpstream settles that).
+func (e *Edge) servePathRemote(w http.ResponseWriter, r *http.Request, host string, rt *remoteTarget) bool
```
-Placement (spec §5.5; plan R1 P1-2): `pathRequest` replaces the `selectUpstream` call, so a case 3 `pathLocal` target is the `up` that the demo, **admission**, replica-probe, regional, HA and ownership checks all see. A pending remote selection leaves `ok=false` for the checks above the miss arm and is acted on at the top of the miss arm, before `serveAssetFar` and `backhaul`; when the front is served here (case 2) it is acted on right after `regionalGate` and `routeHAIngress` for the front, before the ownership block. Ownership block: skip only when `up.front != nil` and `up.front.Host == host` and `exactPathRoute(host)` still returns `Front` with the same `Account`, `App`, `Stamp` and `Incarnation` (plan R1 P1-3). On a verified hop: `pathLocal` or a local answer is served; `pathRemote` goes to `servePathRemote`'s hop rule; a host miss whose only answer was the remote map is `staleHopRefusal`.
+Placement (spec §5.5): `ServeHTTP` reads `sel := e.selectUpstream(...)` where it calls `selectUpstream` today, so a case 3 local target is the `up` that the demo, **admission**, replica-probe, regional, HA and ownership checks all see. A `Remote` selection is dispatched **immediately after `regionalGate`** and before `routeHAIngress`, the ownership block, `frontForwardHA`, the far asset catch and the miss arm, whether or not the front is served here (plan R2 P1-1: no front HA step runs once a prefix selected a target elsewhere). The Task 6 adapter is removed. Ownership block: skip only when `up.front != nil`, `up.front.Host == host`, and `exactPathRoute(host)` still returns `Front` with the same `Account`, `App`, `Stamp` and `Incarnation`.
-Harness (plan R1 P2-8): a three-edge scene on the `BackhaulHolderScene` pattern: boxes A (hub), B (tenant), C (neither) at `127.0.0.1-3`, one TLS listener each, per-destination `DialContext` on every sender, every edge's home map and cert mirror refreshed after each edges-file publish. Backends record `r.Host`, `r.URL.Path`, and answer `X-Carlos-Version: tenant-1` or `hub-1`; a per-destination dial counter on each transport.
+Harness: a three-edge scene on the `BackhaulHolderScene` pattern: boxes A (hub), B (tenant), C (neither) at `127.0.0.1-3`, one TLS listener each, per-destination `DialContext` on every sender, every edge's home map and cert mirror refreshed after each edges-file publish. Backends record `r.Host` and `r.URL.Path` and answer `X-Carlos-Version: tenant-1` or `hub-1`; a per-destination dial counter on each transport.
-- [ ] **Step 1: Write the failing e2e tests:** `TestPathAcrossFromFrontBox` (request on A for `hub.example/acme/api/version`: backend on B saw `Host: hub.example`, path `/acme/api/version`; response `X-Carlos-Version: tenant-1`); `TestPathAcrossFromTenantBox` (on B: served locally, case 3, zero dials); `TestPathAcrossFromThirdBox` (on C: exactly one dial, to B); `TestPathAcrossPrefixMissGoesToHub`; `TestPathAcrossRemovedPrefixStopsWithinOneFold`; `TestPathAcrossReceiverMapDiffers` (Review Focus 2: B's rows point the prefix elsewhere: 503 `Retry-After: 2`, no dial from B); `TestPathAcrossHopToHubSelectingRemoteServesHub`; `TestPathAcrossWildcardDoesNotBeatExactName` (Review Focus 1); `TestPathAcrossDoorCallStaysSameBox`; `TestPathAcrossDoorHopMapsDiffer` (a door-marked hop to B whose maps differ from the sender's: never served from B's remote map); `TestPathAcrossAdmissionClosedRefusesCase3` (P1-2: B's tenant admission closed: request on B for the front's prefix is refused by admission, exemption judged against the tenant route); `TestPathAcrossFrontOwnerChangedBetweenChecks` (P1-3: front republished under another account with stamp and incarnation 0 between selection and the ownership check: no bypass); `TestPathAcrossNeverASecondHop`; `TestPathAcrossPageCacheExcludesCase3`.
+- [ ] **Step 1: Write the failing e2e tests:** `TestPathAcrossFromFrontBox` (request on A for `hub.example/acme/api/version`: B's backend saw `Host: hub.example`, path `/acme/api/version`; response `X-Carlos-Version: tenant-1`); `TestPathAcrossFromTenantBox` (on B: local, case 3, zero dials); `TestPathAcrossFromThirdBox` (on C: exactly one dial, to B); `TestPathAcrossPrefixMissGoesToHub`; `TestPathAcrossRemovedPrefixStopsWithinOneFold`; `TestPathAcrossReceiverMapDiffers` (Review Focus 2: 503 `Retry-After: 2`, no dial from B); `TestPathAcrossHopToHubSelectingRemoteServesHub`; `TestPathAcrossWildcardDoesNotBeatExactName` (Review Focus 1); `TestPathAcrossDoorCallStaysSameBox`; `TestPathAcrossDoorHopMapsDiffer`; `TestPathAcrossAdmissionClosedRefusesCase3` (B's tenant admission closed: refused by admission, exemption judged against the tenant route); `TestPathAcrossFrontOwnerChangedBetweenChecks`; `TestPathAcrossNeverASecondHop`; `TestPathAcrossPageCacheExcludesCase3`.
- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestPathAcross' -count=1` → FAIL.
- [ ] **Step 3: Implement.**
-- [ ] **Step 4: Run** `-run 'TestPathAcross|TestPath|TestSelectPath|TestBackhaul|TestSelectUpstreamIsTheOnlySite|TestAdmission'` → PASS. `make code-health`.
+- [ ] **Step 4: Run** `-run 'TestPathAcross|TestPath|TestSelect|TestBackhaul|TestAdmission|TestLinked'` → PASS. `make code-health`.
- [ ] **Step 5: Commit** `edge: path targets across boxes in ServeHTTP (#186)`.
**Review:** Astra task review (security gate and hop).
@@ -289,9 +294,9 @@ Harness (plan R1 P2-8): a three-edge scene on the `BackhaulHolderScene` pattern:
- 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`. Identity resolution (`ingressRoute`, `resolveName`, the servesExactly name) uses `routeName`; `frontForwardHAIngress(w, r, host, rt)` keeps `host` as the wire Host. The call site passes `up.route.Host` for a `pathLocal` selection (including a received hop re-selected to T), else `host`. `frontForwardHA` and `moveGate` already take identity from the route and wire from `host` (plan R1 confirmed); the tests below 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 `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.
-- [ ] **Step 1: Write the failing tests** on Task 8's three-edge 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's backend serves; holder remembered under T); `TestPathAcrossHAHandoverFollowKeyedOnTarget`; `TestPathAcrossHAFrontPrefixHitSkipsFrontForward`; `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`.
- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestPathAcrossHA' -count=1` → FAIL.
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run** `-run 'TestPathAcross|TestHAIngress|TestForwardHA|TestHandover'` → PASS.
@@ -323,26 +328,31 @@ Harness (plan R1 P2-8): a three-edge scene on the `BackhaulHolderScene` pattern:
- Test: `internal/edge/path_across_gate_test.go`
**Interfaces:**
-- Produces: `func (e *Edge) refuseLoginAcross(w http.ResponseWriter, r *http.Request, host, next string, isDoor bool) bool`: runs `selectPath` on `next`; when `Prefix != ""` and the outcome is not `pathLocal`, or is a `pathLocal` with `Up.front != nil`, writes the refusal (409, `Cache-Control: no-store`, the approved sentence) and returns true, before any password hash or cookie.
+- 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.
- [ ] **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`; `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`.
- [ ] **Step 3: Run** `go test ./internal/edge/ -run 'TestGateLogin' -count=1` → FAIL.
- [ ] **Step 4: Implement.**
-- [ ] **Step 5: Run** `-run 'TestGateLogin|TestGate'` → PASS.
+- [ ] **Step 5: Run** `-run 'TestGateLogin|TestGate|TestLinked'` → PASS.
- [ ] **Step 6: Commit** `edge: refuse a gate login whose page lives on another box (#186)`.
-### Task 12: Readers of route_paths, docs and the rollout order
+### Task 12: Readers of route_paths, the pre-roll checker, docs
**Files:**
-- Modify: `internal/console/apiroutes.go` (the comment near the `routeFor[p.Host]` filter: rows now exist for hosts on other boxes; behaviour already right), `internal/host/assetpolicy.go` (`pathHosts` comment: a superset is intended), `docs/superpowers/specs/2026-09-02-path-based-routing-design.md` (§6 "Same box" and §11 "Cross-box path targets": one paragraph each pointing at the new spec), any `docs/site` page stating the one-box limit (`grep -rn -i "same box" docs/site`), `docs/superpowers/runbooks/path-routes-across-boxes-rollout.md` (create: spec §8's three steps)
+- Modify: `internal/console/apiroutes.go` (comment near the `routeFor[p.Host]` filter: rows now exist for hosts on other boxes; behaviour already right), `internal/host/assetpolicy.go` (`pathHosts` comment), `docs/superpowers/specs/2026-09-02-path-based-routing-design.md` (§6 "Same box", §11 "Cross-box path targets": a paragraph each pointing at the new spec), `domains_cli.go` (~line 462: the help text saying non-local targets disappear from `routes`; reword for rows on every box), any `docs/site` page stating the one-box limit (`grep -rn -i "same box" docs/site`)
+- Create: `scripts/pathmapcheck/main.go`, `scripts/pathmapcheck/main_test.go`, `docs/superpowers/runbooks/path-routes-across-boxes-rollout.md`
- Test: `internal/console/apiroutes_paths_test.go`
-- [ ] **Step 1: Write the regression test** `TestRoutesListingOmitsOrphanPathRows` (path rows for a host not in the listing: none in `paths`). It passes today (plan R1 P3-12); it pins the behaviour now that every box holds every row.
-- [ ] **Step 2: Run** `go test ./internal/console/ -run TestRoutesListingOmitsOrphanPathRows -count=1` → PASS.
-- [ ] **Step 3: Update the comments and docs.** `docs/site` prose goes through copy review. The runbook names the pre-roll check, 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:** `go test ./internal/host/ -run 'TestAssetPolicy' -count=1` stays green.
-- [ ] **Step 5: Commit** `routes listing, docs, rollout runbook: path rows on every box (#186)`.
+**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.
+
+- [ ] **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 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.
+- [ ] **Step 5: Commit** `pathmapcheck, routes listing, docs, rollout runbook (#186)`.
### Task 13: Branch gate, census, pre-roll check, dev witness
@@ -351,7 +361,7 @@ Harness (plan R1 P2-8): a three-edge scene on the `BackhaulHolderScene` pattern:
- [ ] **Step 3: Census** (AGENTS.md "The census"; plan R1 P2-11). `make census-card`; write `$TMPDIR/claims-path-routes.tsv` (`<file>:<unit><TAB><what changed, which read if any>`, one line per changed unit); `make census-propose NAME=path-routes-across-boxes CLAIMS=$TMPDIR/claims-path-routes.tsv`; commit the overlay, chain line and card; an independent reviewer (Astra, brief from `REVIEW-BRIEF-TEMPLATE.md`, carrying this plan's review history) approves each unit and envelope; record the approved tip on discussion #280.
- [ ] **Step 4:** Push; `amadan ci status carlos/platform -branch path-routes-across-boxes` until green.
- [ ] **Step 5: Whole-branch review** by Astra (rule 1's budget), then its single fix wave.
-- [ ] **Step 6: Pre-roll check (spec §8 step 1), read-only.** For dev and flagship: path-routed hosts from `carlos routes`, each map from `carlos domains paths <host>`; confirm every target's home box equals its front's. Record on the branch; any cross-box target: stop and tell Paul.
+- [ ] **Step 6: Pre-roll check (spec §8 step 1), read-only.** Run `scripts/pathmapcheck` against dev's and flagship's control buckets (named AWS profiles: dev `kass`, flagship `keymail`). Record its output on the branch; exit 1 (any cross-box or unknown target): stop and tell Paul.
- [ ] **Step 7: Merge** only with Paul's go (`amadan branch merge carlos/platform path-routes-across-boxes -squash -expect <tip>` with a message file); release and roll by the release recipe with Paul's GO, dev first.
- [ ] **Step 8: Dev witness (spec §9, rule 6)** after the dev roll: a hub on one dev box, a tenant on another, `curl https://<hub>/<slug>/api/version` through each box's ingress returns the tenant's `X-Carlos-Version`. Record on #186. Tell the Rastrillo session the scaffold may now publish cross-box maps on dev.
@@ -364,16 +374,16 @@ Harness (plan R1 P2-8): a three-edge scene on the `BackhaulHolderScene` pattern:
| §5.1 | route owner + marks; door owner unchanged | Task 4 tests |
| §5.1 | one rule, published = local | `TestEdgesFilePathMarksMatchPredicates`, `TestPathPredicatesNameEveryKind` |
| §5.2 | remote map, filters, one snapshot | Task 5 tests |
-| §5.3 | four cases, front/target rules, accounts | Task 6 tests |
+| §5.3 | four cases, front/target rules, accounts, one entry point | Task 6 tests; `TestSelectUpstreamIsTheOnlySite` (extended) |
| §5.4 | wire Host vs route host, no second hop, receiver re-resolves, home box rule | Task 7 tests; `TestPathAcrossNeverASecondHop`, `TestPathAcrossReceiverMapDiffers`, `TestPathAcrossHopToHubSelectingRemoteServesHub` |
-| §5.5 | placement, admission, ownership mark, page cache | Task 8 tests |
+| §5.5 | placement, admission, ownership mark, page cache, no front HA for a remote selection | Task 8 tests; `TestPathAcrossHAFront*` |
| §5.6 | operator logs | Task 6 refusal tests assert the log key via `captureLog` |
| §5.7 | HA on the selected route | Task 9 tests |
| §6 | cost budget | Task 1 Step 5, Task 3 Step 5, Task 5 Step 5, Task 13 Step 1 |
| §7.1 | regional names | `TestRemotePathsSkipRegionalName` |
| §7.2 | purge | Task 10 tests |
-| §7.3 | gate refusal | Task 11 tests |
+| §7.3 | gate refusal (pinned, query, encoded) | Task 11 tests |
| §7.4 | door cut | `TestSelectPathDoorNeverAcross`, `TestSelectPathDoorHopIgnoresRemoteMap`, `TestPathAcrossDoorCallStaysSameBox`, `TestPathAcrossDoorHopMapsDiffer` |
| §7.5 | fleets | `TestSelectPathForwardTargetNeverSelected`, `TestRemotePathsSkipForwardHost` |
-| §8 | ordering rule | Task 12 runbook; Task 13 Steps 6-8 |
+| §8 | ordering rule | `pathmapcheck` tests; Task 12 runbook; Task 13 Steps 6-8 |
| §9 | dev witness | Task 13 Step 8 |