plan: path routes across boxes (#186), 13 tasks
Spec rev 5 approved by Paul 2026-11-19; recorded in the spec header.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+334
−1
docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md+333 −0docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md+1 −1
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| new file mode 100644 |
| index 000000000..c00cc5097 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-19-path-routes-across-boxes.md |
| @@ -0,0 +1,333 @@ |
| +# Path Routes Across Boxes 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:** A path route's prefix reaches its target route on any box of the deployment, whichever box the request arrives on, with one hop at most. |
| + |
| +**Architecture:** Every box derives every path-routed host's `route_paths` rows. The ingress box selects the prefix itself (local map, or a new remote map for hosts it does not serve), checks front and target eligibility against new edges-file fields, and makes one signed backhaul to the target's box with wire `Host` unchanged and every holder/HA decision keyed on the target. The receiving box re-selects and serves only a local answer. |
| + |
| +**Tech Stack:** Go; SQLite registry (`internal/registry`); edges files in the bucket (`internal/host`, `internal/edge/homemap.go`); edge proxy (`internal/edge`). |
| + |
| +**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. |
| + |
| +## Global Constraints |
| + |
| +- One hop, ever: no code path may forward a verified hop (`hopVerified(ctx)`) onward. Existing guards in `backhaul`/`backhaulTo` stay first in their functions. |
| +- 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. |
| +- 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. |
| +- `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. |
| +- 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`, `pathhop.go`); `ServeHTTP` gains calls, not bodies, and loses at least as many lines as it gains. Run `make code-health` before pushing. |
| +- Tests wait on signals, never `time.Sleep`. Errors compared with `errors.Is`/`errors.As`. Tests in `internal/edge` that read the standard log use `captureLog`. |
| +- Local runs are targeted only: `go test ./internal/<pkg>/ -run '<Names>' -count=1`. No full suites, no `-race` loops locally (CI runs them on amadan). `gofmt -l .` clean. `GOOS=darwin go build ./...` and `GOOS=windows go build ./...` once before the branch is handed off. |
| +- User-facing copy (the gate refusal, log lines are not copy) goes through the copy-review skill before it is written into a file. |
| + |
| +## Review Focus |
| + |
| +1. **A wildcard catch-all whose primary has a prefix map, hit for another account's exact hostname homed elsewhere.** Expect the ownership block to send it to the exact name's box, never the wildcard's prefix target. Test in Task 8. |
| +2. **Sender and receiver maps disagree for a few seconds after a republish** (prefix moved from T1 on box B to T2 on box C). Expect the receiver to answer `staleHopRefusal` or serve its own local answer, never forward. Test in Task 8. |
| +3. **A path-routed host that is also a regional name on some box.** Expect no remote map and no cross-box selection for it. Test in Task 5. |
| +4. **A target route that exists but is not ready on its box.** Expect today's fall-through (host's route / backhaul to host's home), not a 502. Test in Task 6. |
| +5. **`/paulca/../bob` and `//paulca/x` on a host this box does not serve.** Expect the same selection the home box makes (both spellings, cleaned wins). Test in Task 6. |
| + |
| +--- |
| + |
| +### Task 1: Measure the fleet-wide cost, and diff the path writes |
| + |
| +**Files:** |
| +- Modify: `internal/domains/aliases.go` (the `route_paths` write loop near the end of `ReconcileAliasesReport`) |
| +- Test: `internal/domains/paths_cost_test.go` (create), `internal/registry/registry_paths_bench_test.go` (create), `internal/edge/path_reload_bench_test.go` (create) |
| + |
| +**Interfaces:** |
| +- Produces: nothing new for later tasks; changes the write loop to upsert only rows whose `(target, account, app)` differs from `existingPaths`. |
| + |
| +- [ ] **Step 1: Write the failing test** `TestReconcileUnchangedPathsWritesNothing` in `paths_cost_test.go`. Add `var upsertPathHook func(registry.RoutePath)` to `aliases.go` (nil in production, called just before each `UpsertPath`). Reconcile once with one claim of 3 prefixes, set the hook to count, reconcile again with the same claim, assert 0 calls. |
| +- [ ] **Step 2: Run it.** `go test ./internal/domains/ -run TestReconcileUnchangedPathsWritesNothing -count=1` → FAIL (3 calls). |
| +- [ ] **Step 3: Implement.** Build `existingByKey := map[string]registry.RoutePath` from `existingPaths` before the upsert loop; skip `UpsertPath(p)` when the existing row equals `p`. |
| +- [ ] **Step 4: Run it** → PASS. |
| +- [ ] **Step 5: Add three benchmarks** with 1, 5 and 10 hosts × 10,000 prefixes (`BenchmarkReconcilePathSection`, `BenchmarkFingerprintPaths`, `BenchmarkReloadPaths`), all targets non-local so rows exist for hosts this box does not serve (they will after Task 3; until then seed `route_paths` directly with `UpsertPath`). Run `go test ./internal/registry/ ./internal/edge/ ./internal/domains/ -run XXX -bench 'PathSection|FingerprintPaths|ReloadPaths' -benchtime 5x`. |
| +- [ ] **Step 6: Record the numbers** in the branch description, and re-run Step 5 after Task 3 (when the reconcile pass derives non-local rows) and record again. If any exceeds 100 ms at 10 hosts, stop and report with the numbers (spec §6); do not start Task 2. |
| +- [ ] **Step 7: Commit** `domains: write only changed path rows; path cost benchmarks`. |
| + |
| +### Task 2: The shared eligibility predicates |
| + |
| +**Files:** |
| +- Create: `internal/registry/pathroute.go` |
| +- Test: `internal/registry/pathroute_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: `func PathFront(rt Route) bool`, `func PathTarget(rt Route) bool` in package `registry`. |
| + |
| +- [ ] **Step 1: Write the failing tests.** `TestPathTargetEligibility` table: `{Kind:"instance",Status:"ready"}`→true; `{Kind:"static",Status:"ready"}`→true; `{Kind:"instance",Status:"starting"}`→false; `{Kind:"service",Status:"ready"}`→false; `{Kind:"sidecar",Status:"ready"}`→false; `{Kind: KindForward, Status:"ready"}`→false; an instance with `DemoID` set so `IsDemo()` is true→false; `{Kind:"instance",Status:"ready",HA:true}`→true. `TestPathFrontEligibility`: same rows without the readiness rule (`starting` instance → true). `TestPathPredicatesNameEveryKind`: for every kind in the comment on `Route.Kind` plus `KindForward`, assert one of the two tables above covers it, so a new kind fails the test until classified. |
| +- [ ] **Step 2: Run** `go test ./internal/registry/ -run 'TestPath(Target|Front)Eligibility|TestPathPredicatesNameEveryKind' -count=1` → FAIL (undefined). |
| +- [ ] **Step 3: Implement** both functions as specified in Global Constraints. |
| +- [ ] **Step 4: Run** → PASS. |
| +- [ ] **Step 5: Commit** `registry: PathFront and PathTarget, the shared path eligibility rule`. |
| + |
| +### Task 3: Derive path rows on every box |
| + |
| +**Files:** |
| +- Modify: `internal/domains/aliases.go` (the `if len(c.Paths) > 0` block, ~line 627-740) |
| +- Test: `internal/domains/aliases_paths_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: `registry.PathTarget` (Task 2). |
| +- Produces: `route_paths` rows for every claim with `Paths`, on every box. |
| + |
| +Rules (spec §5.1): sidecar-suffix refusals unchanged. Host local → today's tenancy check, refuse on mismatch. Host not local → derive. Target local → today's account check (refuse cross-account) and `registry.PathTarget(tgtRt)` (replaces `Status != "ready"`; unresolved count as today). Target not local → derive. Cap and sorted truncation unchanged. The unresolved log line drops "a path target must be homed on the SAME box as %s" and reads: `domains: paths on %s: %d prefix(es) name a local route that is not a path target yet (e.g. %s). Those prefixes serve %s's own route.` |
| + |
| +- [ ] **Step 1: Change the existing tests to the new rules.** `TestReconcileSkipsUnknownTarget` becomes `TestReconcileDerivesNonLocalTarget` (row present, `Target` = the unknown name). `TestReconcileSkipsWhenClaimHostIsNotALocalRoute` becomes `TestReconcileDerivesRowsForNonLocalHost` (rows present with the claim's account/app). `TestReconcileSkipsUnreadyTarget` stays (local unready target: no row). `TestReconcileRefusesCrossTenantTarget` stays. `TestReconcileLogsUnresolvedTargetsOncePerHost` asserts the new wording. Add `TestReconcileRefusesLocalForwardTarget` (a local `KindForward` ready route as target: no row) and `TestReconcileCapIdenticalForNonLocalHost` (10,001 prefixes on a non-local host: the same 10,000 sorted prefixes as for a local host). |
| +- [ ] **Step 2: Run** `go test ./internal/domains/ -run 'TestReconcile.*Path|TestReconcile(Derives|Skips|Refuses|Caps|Logs)' -count=1` → the changed tests FAIL. |
| +- [ ] **Step 3: Implement** the rules above. |
| +- [ ] **Step 4: Run** → PASS. Also run `go test ./internal/registry/ -run TestFingerprint -count=1` (unchanged, must stay green). |
| +- [ ] **Step 5: Commit** `domains: derive path rows on every box (#186)`. |
| + |
| +### Task 4: Route owner and eligibility in the edges file |
| + |
| +**Files:** |
| +- Modify: `internal/host/edgesfile.go` (`edgeHost` struct; the route loop in `edgesFileWriteClaims` ~line 733) |
| +- Modify: `internal/edge/homemap.go` (`edgesHostView`, `homeEntry`, the fold in `foldHomes`) |
| +- Create: `internal/edge/pathroute_home.go` |
| +- Test: `internal/host/edgesfile_pathroute_test.go`, `internal/edge/pathroute_home_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: `registry.PathFront`, `registry.PathTarget`. |
| +- Produces: edges-file fields `route_account`, `route_app`, `path_front`, `path_target` (all `omitempty`); in package `edge`: |
| + |
| +```go |
| +type pathRouteInfo struct { |
| + Account, App string |
| + Front, Target bool |
| + Dial, Box string |
| + Owner backhaulOwner // backhaulOwnerOf(resolution.Authority) |
| + Stamp int64 |
| + Incarnation uint64 |
| +} |
| +// exactPathRoute answers the exact (never wildcard) dialable route row |
| +// another box published for host, from one snapshot. false when absent, |
| +// held, an alias row, or published without route_account. |
| +func (m *homeMap) exactPathRoute(host string) (pathRouteInfo, bool) |
| +``` |
| + |
| +Writer rule: set the four fields only on rows of real routes: not `strings.HasPrefix(r.Host, "*.")`, not a platform alias (`platformSources[r.Host]`), not an attached alias. `RouteAccount = release.RouteAccount(r)`, `RouteApp = r.App`, `PathFront = registry.PathFront(r)`, `PathTarget = registry.PathTarget(r)`. Today's `account`/`app` (door owner) untouched. Reader: the four values travel with the dial winner like `account`/`app`, never merged across entries. |
| + |
| +- [ ] **Step 1: Write the failing tests.** Host: `TestEdgesFilePublishesRouteOwner` (an instance route with two path rows to other apps: `account`/`app` empty as today, `route_account`/`route_app` the route's, `path_front` and `path_target` true); `TestEdgesFileForwardRowIsNotAPathTarget` (forward row: `path_target` false, `path_front` false); `TestEdgesFileAliasRowsCarryNoRouteOwner` (attached alias and `*.` row: fields absent). The existing mixed-owner test (`edgesfile_test.go` ~1195) stays green. Edge: `TestExactPathRouteIgnoresWildcard` (only `*.example.com` published → `exactPathRoute("t.example.com")` false); `TestExactPathRouteReadsWinner` (two files, the dial winner's fields returned); `TestExactPathRouteAbsentFieldsAreFalse` (old-shape row → ok false). |
| +- [ ] **Step 2: Run** `go test ./internal/host/ -run 'TestEdgesFile(PublishesRouteOwner|ForwardRowIsNotAPathTarget|AliasRowsCarryNoRouteOwner)' -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`, and the entry's `routeAccount != ""`). |
| +- [ ] **Step 4: Run** → PASS. |
| +- [ ] **Step 5: Commit** `edges file: publish route owner and path eligibility (#186)`. |
| + |
| +### Task 5: The remote map in the edge |
| + |
| +**Files:** |
| +- Create: `internal/edge/pathremote.go` |
| +- Modify: `internal/edge/edge.go` (`Edge` struct: one field; `Reload`: one call before `e.upstreams.Store(&m)`) |
| +- Test: `internal/edge/pathremote_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: |
| + |
| +```go |
| +type remotePathMap struct { |
| + prefixes map[string]string // prefix -> target host |
| + account, app string // the claim's, from the rows |
| +} |
| +type remotePathTable struct { |
| + hosts *map[string]upstream // the m this table was built beside |
| + byHost map[string]remotePathMap |
| +} |
| +// Edge field: remotePaths atomic.Pointer[remotePathTable] |
| +func buildRemotePaths(m map[string]upstream, rows []registry.RoutePath, regional map[string]bool, demoReserved func(string) bool) map[string]remotePathMap |
| +// routingView is one consistent read: remote is nil when the stored table |
| +// was not built beside hosts (a reload landed between the two loads). |
| +type routingView struct { |
| + hosts map[string]upstream |
| + remote map[string]remotePathMap |
| +} |
| +func (e *Edge) view() routingView |
| +``` |
| + |
| +Reload stores the remote table **before** `e.upstreams.Store(&m)`; `view()` loads `upstreams` first, then `remotePaths`, and drops `remote` when `table.hosts != p`. Rows skipped: host present in `m`; host is a forward row anywhere in the routes list; host or target `demoReserved`; host in `regional` (the names the regional table holds on this box). Rows whose `Account`/`App` differ within one host: the host's map is dropped and logged (the reconcile pass never writes that). |
| + |
| +- [ ] **Step 1: Write the failing tests.** `TestRemotePathsBuiltForUnservedHosts` (rows for an unserved host land in `byHost`, rows for a served host do not); `TestRemotePathsSkipRegionalName` (Review Focus 3); `TestRemotePathsSkipDemoReserved`; `TestViewDropsMismatchedRemote` (store a table built beside one map, then store a different map: `view().remote == nil`); `TestReloadPublishesRemotePaths` (registry with rows for an unserved host, `Reload`, `view().remote["hub.example"]` holds them). |
| +- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestRemotePaths|TestViewDropsMismatchedRemote|TestReloadPublishesRemotePaths' -count=1` → FAIL. |
| +- [ ] **Step 3: Implement** as specified. |
| +- [ ] **Step 4: Run** → PASS; also `-run 'TestPath'` (existing path tests unchanged). |
| +- [ ] **Step 5: Commit** `edge: remote path map beside the route table (#186)`. |
| + |
| +### Task 6: Selection |
| + |
| +**Files:** |
| +- Create: `internal/edge/pathselect.go` |
| +- Modify: `internal/edge/edge.go` (`lookupUpstreamPath`: its match block moves into `matchPrefix`; behaviour for existing callers unchanged) |
| +- Test: `internal/edge/pathselect_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: `view()`, `exactPathRoute`, `registry.PathFront/PathTarget`. |
| +- Produces: |
| + |
| +```go |
| +// 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 // no path selection: today's answer for the host |
| + pathLocal // up is the target's local entry |
| + pathRemote // target is on another box |
| +) |
| +type pathSelection struct { |
| + Outcome pathOutcome |
| + Up upstream // pathLocal only |
| + Prefix string // the matched prefix, set whenever one matched |
| + Target string // the matched target host, set whenever one matched |
| + Route pathRouteInfo // pathRemote only: the target's published row |
| + FrontMark frontMark // pathLocal for an unserved front (case 3) only |
| +} |
| +type frontMark struct { |
| + Host, Account, App string |
| + Stamp int64 |
| + Incarnation uint64 |
| +} |
| +// selectAcross runs spec §5.3's four cases for a request this box resolved |
| +// to hostUp (ok=false on a host miss). door=true never selects across boxes. |
| +func (e *Edge) selectAcross(v routingView, host, urlPath string, hostUp upstream, ok, door bool) pathSelection |
| +``` |
| + |
| +Rules (spec §5.3): front route on the host's box = exact entry `v.hosts[host]` (not reached via wildcard) with `!alias && !platformAlias && regional == regionalNone && registry.PathFront(route)`. Front off the host's box = `exactPathRoute(host)` with `Front` and `Account/App` equal to `v.remote[host].account/app`. Target local = `v.hosts[T]` with `!alias && !platformAlias && regional == regionalNone && registry.PathTarget(route)` and route account equal to the map's account. Target remote = `exactPathRoute(T)` with `Target` and `Account` equal to the map's account. Anything failing → `pathNone`, with a throttled log naming the reason (spec §5.6; key `path-remote-skip <host>`). |
| + |
| +- [ ] **Step 1: Write the failing tests** (a fake home map via the existing edges-file test helpers in `homemap_test.go`): `TestSelectAcrossCase1LocalTarget`; `TestSelectAcrossCase2RemoteTarget` (Outcome pathRemote, Route.Box = B); `TestSelectAcrossCase2TargetOtherAccount` (pathNone); `TestSelectAcrossCase2TargetNotReady` (published `path_target` false → pathNone; Review Focus 4); `TestSelectAcrossCase3LocalTarget` (FrontMark set); `TestSelectAcrossCase3FrontOwnerMismatch` (pathNone); `TestSelectAcrossCase3PrefixMiss` (pathNone); `TestSelectAcrossCase3BothSpellings` (`/paulca/../bob` hits `paulca` via raw when `bob` is unmapped; `//paulca/x` hits `paulca`; Review Focus 5); `TestSelectAcrossWildcardFrontNeverRemote`; `TestSelectAcrossAliasFrontNeverRemote`; `TestSelectAcrossForwardTargetNeverSelected`; `TestSelectAcrossDoorNeverAcross` (door=true: cases 2 and 3 → pathNone); `TestSelectAcrossHATargetSelected` (HA target with `path_target` → pathRemote). |
| +- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestSelectAcross|TestPathMatch' -count=1` → FAIL. |
| +- [ ] **Step 3: Implement** `matchPrefix` (moved from `lookupUpstreamPath`, which now calls it) and `selectAcross`. |
| +- [ ] **Step 4: Run** → PASS, plus `-run 'TestPath|TestFirstSegment'`. |
| +- [ ] **Step 5: Commit** `edge: select a path target across boxes (#186)`. |
| + |
| +### Task 7: A backhaul for a route under another Host |
| + |
| +**Files:** |
| +- Modify: `internal/edge/edge.go` (`backhaulTo` becomes a one-line wrapper), `internal/edge/backhaul_holder.go` (`backhaulTarget`, `backhaulAttempt`), `internal/edge/backhaul_retry.go` callers |
| +- Create: `internal/edge/pathhop.go` |
| +- Test: `internal/edge/pathhop_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: |
| + |
| +```go |
| +// backhaulRouteTo is backhaulTo for a request whose wire Host (signed, |
| +// SNI, sent) is wireHost while every holder, alternative and handover |
| +// decision is keyed on routeHost. backhaulTo(w, r, h, ...) == backhaulRouteTo(w, r, h, h, ...). |
| +func (e *Edge) backhaulRouteTo(w http.ResponseWriter, r *http.Request, wireHost, routeHost, eip, box string, owner backhaulOwner) bool |
| +``` |
| + |
| +`backhaulTarget(routeHost, ...)`, `backhaulAlternative(routeHost, ...)`, `handoverAlternative(routeHost, ...)`, `backhaulHolders.get/remember/drop(routeHost, ...)` and log keys use `routeHost`; `hopTo`/`signHop`/`backhaulProxy` use `wireHost`. The `hopVerified` guard stays first. |
| + |
| +- [ ] **Step 1: Write the failing tests.** `TestBackhaulRouteToSignsWireHost` (the receiving test server verifies the MAC against `hub.example` and sees `Host: hub.example`); `TestBackhaulRouteToKeysHolderOnRoute` (a holder refusal naming box C is remembered under `tenant.example`, not `hub.example`); `TestBackhaulRouteToRefusesArrivedHop` (a verified hop context → `staleHopRefusal`, no dial). Existing `-run 'TestBackhaul'` tests stay green unchanged. |
| +- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestBackhaulRouteTo' -count=1` → FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** `-run 'TestBackhaul'` → PASS. |
| +- [ ] **Step 5: Commit** `edge: backhaul a route under its front Host (#186)`. |
| + |
| +**Review:** Astra task review (touches the hop: rule 3). |
| + |
| +### Task 8: Wire selection into ServeHTTP |
| + |
| +**Files:** |
| +- Modify: `internal/edge/edge.go` (`ServeHTTP`: calls only; net lines must not grow) |
| +- Modify: `internal/edge/pathhop.go` (add the helpers) |
| +- Test: `internal/edge/path_across_e2e_test.go` (create; uses `newBackhaulSceneWith` from `backhaul_e2e_test.go`) |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 5-7. |
| +- Produces: |
| + |
| +```go |
| +// servePathAcross runs after selectUpstream and before the regional gate's |
| +// result is acted on; it answers (true) for a pathRemote selection by |
| +// backhaulRouteTo(w, r, host, T, Route.Dial, Route.Box, Route.Owner), and for a |
| +// hopped request whose selection is pathRemote by serving the host's own |
| +// route (spec §5.4), and returns the upstream to continue with otherwise. |
| +func (e *Edge) servePathAcross(w http.ResponseWriter, r *http.Request, host string, up upstream, ok, hopped, isDoor bool) (upstream, bool, bool) |
| +``` |
| + |
| +Placement (spec §5.5): after `selectUpstream` and the demo/admission/replica-probe branches, before `regionalGate`. A `pathLocal` case 3 result sets `ok = true` and `up = sel.Up` with the front mark carried on the request context (`withFrontMark(ctx, frontMark)`); the ownership block skips only when `frontMarkFrom(ctx)` names `host` and `exactPathRoute(host)` still has the same `Stamp` and `Incarnation`. On a verified hop: only `pathLocal` or today's local answer is served; `pathRemote` or a remote-map-only miss → `staleHopRefusal`; a door-marked hop (`hopDoorFrom`) is selected with `door=true`. The far asset catch and backhaul in the miss arm run only when `servePathAcross` did not answer. The page cache's path-host exclusion (`pagecache.go:244, 277`) must return "not eligible" for a case 3 upstream; add the front mark check there. |
| + |
| +- [ ] **Step 1: Write the failing e2e tests** (two edges A and B, shared store, edges files published by both): `TestPathAcrossFromFrontBox` (hub on A, tenant on B; request on A for `hub.example/acme/api/version` gets B's tenant body with `Host: hub.example`); `TestPathAcrossFromTenantBox` (same request on B: served locally, case 3); `TestPathAcrossFromThirdBox` (a third edge C with neither: one hop to B); `TestPathAcrossPrefixMissGoesToHub`; `TestPathAcrossRemovedPrefixStopsWithinOneFold`; `TestPathAcrossReceiverMapDiffers` (B's rows point the prefix elsewhere: B answers 503 `Retry-After: 2`, no second dial; Review Focus 2); `TestPathAcrossHopToHubSelectingRemoteServesHub` (an old-shape sender backhauls to A: A serves the hub's route); `TestPathAcrossWildcardDoesNotBeatExactName` (Review Focus 1); `TestPathAcrossDoorCallStaysSameBox`; `TestPathAcrossNeverASecondHop` (count dials on the test transport: never more than one per request outside holder/handover follows); `TestPathAcrossPageCacheExcludesCase3`. |
| +- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestPathAcross' -count=1` → FAIL. |
| +- [ ] **Step 3: Implement** `servePathAcross`, `withFrontMark`/`frontMarkFrom`, the ownership-block skip and the page-cache check, and the `ServeHTTP` calls. |
| +- [ ] **Step 4: Run** `-run 'TestPathAcross|TestPath|TestBackhaul|TestSelectUpstreamIsTheOnlySite'` → PASS. Run `make code-health`. |
| +- [ ] **Step 5: Commit** `edge: path targets across boxes in ServeHTTP (#186)`. |
| + |
| +**Review:** Astra task review (security gate and hop). |
| + |
| +### Task 9: Region HA on the selected route |
| + |
| +**Files:** |
| +- Modify: `internal/edge/haingress.go` (`routeHAIngress` gains `routeName string`), `internal/edge/edge.go` (its one call site), `internal/edge/handover.go` if `moveGate` keys on `host` for identity |
| +- 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` when the request was path-selected (a `pathLocal` selection or a received hop re-selected to T), else `host`. `frontForwardHA(w, r, host, up, ...)` already reads `up.route` and signs `host`; confirm with a test, no change expected. `moveGate`: identity from `rt`, wire from `host`; change only if a test shows it reads `host` for identity. |
| + |
| +- [ ] **Step 1: Write the failing tests** (spec §5.7, §9 HA list): `TestPathAcrossHATargetFromFrontBox`; `TestPathAcrossHATargetFromNonHolderPoolBox` (B is in T's pool but not holder: B's 503 holder hint names C; A follows to C with wire `Host: hub.example`; C serves); `TestPathAcrossHAHandoverFollowKeyedOnTarget`; `TestPathAcrossHAFrontPrefixHitSkipsFrontForward` (hub HA with lease elsewhere; prefix selects T: hub's front forward never runs); `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. |
| +- [ ] **Step 5: Commit** `edge: HA dispatch follows the selected path route (#186)`. |
| + |
| +**Review:** Astra task review (HA, termination-adjacent). |
| + |
| +### Task 10: Purge for a front host this box does not serve |
| + |
| +**Files:** |
| +- Modify: `internal/edge/purge_header.go` (`purgeOwns`, `resolvePurgeOwnersIn`, `purgeHostInTenancy` callers), `internal/edge/pagecache.go` (`ownsHost`, `instanceHosts` callers) |
| +- Test: `internal/edge/purge_across_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: `func purgeOwns(v routingView, owner registry.Route, host string) bool` (signature change; callers pass `e.view()` or the view they already hold). New branch: `host` not in `v.hosts` → true only when `v.remote[host]` has a prefix whose target is `owner.Host`, `v.remote[host].account == release.RouteAccount(owner)`, `exactPathRoute(host)` has `Front` with matching account/app, and `v.hosts[owner.Host]` is `sameInstance` as `owner`. `resolvePurgeOwnersIn` takes the same view and accepts `Carlos-Purge-Host: <front>` under the same rule. |
| + |
| +- [ ] **Step 1: Write the failing tests.** `TestPurgeAcrossEvictsExactURL`, `TestPurgeAcrossEvictsPath`, `TestPurgeAcrossEvictsWholeHost` (tenant on this box, front not served here, entries cached under the front host: each purge drops them); `TestPurgeAcrossRefusedAfterPrefixMoves`; `TestPurgeAcrossRefusedForOtherAccount`. Existing `-run 'TestPurge'` tests stay green. |
| +- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestPurgeAcross' -count=1` → FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** `-run 'TestPurge'` → PASS. |
| +- [ ] **Step 5: Commit** `edge: a path target purges its pages under the front host (#186)`. |
| + |
| +**Review:** Astra task review (cache, security gate). |
| + |
| +### Task 11: Refuse a gate login for a cross-box target |
| + |
| +**Files:** |
| +- Modify: `internal/edge/edge.go` (the login POST block, ~line 2784: call only), `internal/edge/pathhop.go` (helper), `internal/edge/pathhop.go` (one new constant `copyPathGateAcross`, beside the helper, as `copyLD51` sits in `linkoffline.go`) |
| +- 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 `selectAcross` on `next`; when a prefix matched (`Prefix != ""`) and the outcome is not `pathLocal`, writes the refusal (status 409, `Cache-Control: no-store`, the approved sentence) and returns true, before any password hash or cookie. |
| + |
| +- [ ] **Step 1: Draft the refusal sentence and run the copy-review skill on it.** Starting 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 route's gate never consulted); `TestGateLoginRefusedWhenTargetIneligible` (prefix matched, target not ready → refused, not judged by the front); `TestGateLoginSameBoxUnchanged`. |
| +- [ ] **Step 3: Run** `go test ./internal/edge/ -run 'TestGateLogin' -count=1` → FAIL. |
| +- [ ] **Step 4: Implement.** |
| +- [ ] **Step 5: Run** `-run 'TestGateLogin|TestGate'` → PASS. |
| +- [ ] **Step 6: Commit** `edge: refuse a gate login whose page lives on another box (#186)`. |
| + |
| +### Task 12: Readers of route_paths, and the operator's view |
| + |
| +**Files:** |
| +- Modify: `internal/console/apiroutes.go` (path rows only under listed hosts), `internal/host/assetpolicy.go` (comment: 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), the platform docs page that states the one-box limit if any (`grep -rn "same box" docs/site`) |
| +- Test: `internal/console/apiroutes_paths_test.go` |
| + |
| +- [ ] **Step 1: Write the failing test** `TestRoutesListingOmitsOrphanPathRows` (registry with path rows for a host not in the routes list: the response's `paths` holds none of them). |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run TestRoutesListingOmitsOrphanPathRows -count=1` → FAIL. |
| +- [ ] **Step 3: Implement**, then update the two docs. Docs prose for `docs/site` goes through copy review. |
| +- [ ] **Step 4: Run** → PASS; `go test ./internal/host/ -run 'TestAssetPolicy' -count=1` stays green. |
| +- [ ] **Step 5: Commit** `routes listing, docs: path rows on every box (#186)`. |
| + |
| +### Task 13: Branch gate, pre-roll check, dev witness |
| + |
| +- [ ] **Step 1:** `gofmt -l .`, `go vet ./internal/edge/ ./internal/domains/ ./internal/host/ ./internal/registry/ ./internal/console/`, `make code-health`, `GOOS=darwin go build ./...`, `GOOS=windows go build ./...`. Push; read `amadan ci status carlos/platform -branch path-routes-across-boxes` until it is green. |
| +- [ ] **Step 2: Whole-branch review** by Astra (brief from `docs/superpowers/reviews/REVIEW-BRIEF-TEMPLATE.md`, rule 1's budget). |
| +- [ ] **Step 3: Pre-roll check (spec §8 step 1), read-only.** For dev and flagship, list path-routed hosts (`carlos routes` shows path rows) and each one's map (`carlos domains paths <host>`); for each target, confirm its home box equals the front host's. Record the result on the branch. Any cross-box target: stop and tell Paul. |
| +- [ ] **Step 4: Merge** (`amadan branch merge carlos/platform path-routes-across-boxes -squash -expect <tip> -message-file ...`) only with Paul's go; release and roll follow the release recipe with Paul's GO (memory: no release coordinator). |
| +- [ ] **Step 5: Dev witness (spec §9, rule 6)** after the dev roll completes: 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. Only then may the Rastrillo hub scaffold publish cross-box maps on that deployment. |
diff --git a/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md| index 1b14ccaf1..2e841f59b 100644 |
| --- a/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| +++ b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| @@ -1,6 +1,6 @@ |
| # Path routes across boxes: a prefix whose target lives on another box |
| -Rev 5, 2026-11-19. Discussion #186. Builds on the path-routing design |
| +Rev 5, 2026-11-19. **Approved by Paul, 2026-11-19.** Discussion #186. Builds on the path-routing design |
| (`2026-09-02-path-based-routing-design.md`, "the 09-02 design" below) and |
| changes none of its rulings except the one it was written to lift: §6's |
| "a prefix's target route must be homed on the same box as the hostname's |