| index c00cc5097..36267def6 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 |
| @@ -4,26 +4,31 @@ |
| |
| **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. |
| +**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), validates front and target in one place, and either serves a local target or 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. |
| |
| +**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). |
| + |
| ## 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. |
| +- **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. |
| +- `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. |
| -- `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. |
| +- 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`, `pathhop.go`); `ServeHTTP` gains calls, not bodies, and loses at least as many lines as it gains. Run `make code-health` before pushing. |
| +- 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. |
| - 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. |
| +- 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 handoff. |
| +- 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 |
| |
| @@ -35,21 +40,25 @@ |
| |
| --- |
| |
| -### Task 1: Measure the fleet-wide cost, and diff the path writes |
| +### Task 1: Diff the path writes, and the cost benchmarks |
| |
| **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`. |
| +- Produces: the write loop upserts only rows whose `(target, account, app)` differs from `existingPaths`; three benchmarks later tasks re-run. |
| |
| -- [ ] **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 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 (local host, local ready targets), set the hook to count, reconcile again with the same claim, assert 0 calls and that all 3 rows remain. |
| - [ ] **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 3: Implement.** Build `existingByKey` 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 5: Add the benchmarks**, each at 1, 5 and 10 hosts × 10,000 prefixes, workload built so it **survives the code under test** (local front routes and local ready targets until Task 3; Task 3 and Task 5 switch them to non-local, see their last steps): |
| + - `BenchmarkReconcilePathSection` (domains): times one `ReconcileAliases` call **after** an initial derivation, i.e. the unchanged steady state; a sub-benchmark `initial` times the first derivation into an empty table. Each asserts after timing that the row count equals hosts × 10,000. |
| + - `BenchmarkFingerprintPaths` (registry): times one `Fingerprint()` over the populated table. |
| + - `BenchmarkReloadPaths` (edge): times one `Reload()` over the populated registry; asserts the live map holds every path row afterwards. |
| + Run `go test ./internal/domains/ ./internal/registry/ ./internal/edge/ -run XXX -bench 'PathSection|FingerprintPaths|ReloadPaths' -benchtime 5x`. |
| +- [ ] **Step 6: Record** the numbers, the CPU model (`lscpu | grep 'Model name'`) and Go version in the ledger and the branch description. Over 100 ms at 10 hosts: stop the plan and report with the numbers (spec §6). |
| - [ ] **Step 7: Commit** `domains: write only changed path rows; path cost benchmarks`. |
| |
| ### Task 2: The shared eligibility predicates |
| @@ -59,10 +68,10 @@ |
| - Test: `internal/registry/pathroute_test.go` |
| |
| **Interfaces:** |
| -- Produces: `func PathFront(rt Route) bool`, `func PathTarget(rt Route) bool` in package `registry`. |
| +- Produces: `func PathFront(rt Route) bool`, `func PathTarget(rt Route) bool` in package `registry`; `var PathEligibilityCases []PathEligibilityCase` (exported test table: `struct{ Name string; Route Route; Front, Target bool }`) for Task 4's equivalence guard. |
| |
| -- [ ] **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 1: Write the failing tests.** `PathEligibilityCases` covers: ready `instance` (T,T); ready `static` (T,T); starting `instance` (front T, target F); ready `service` (F,F); ready `sidecar` (F,F); ready `KindForward` (F,F); ready instance with `DemoID` set so `IsDemo()` (F,F); ready instance `HA:true` (T,T); ready instance `Replica:true` (T,T); ready instance `Hibernate:true` (T,T). `TestPathEligibility` runs the table through both functions. `TestPathPredicatesNameEveryKind`: every kind named in the comment on `Route.Kind` plus `KindForward` appears in the table, so a new kind fails until classified. |
| +- [ ] **Step 2: Run** `go test ./internal/registry/ -run 'TestPathEligibility|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`. |
| @@ -74,57 +83,57 @@ |
| - 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.` |
| +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 checks unchanged** (refuse cross-account; unready counts as unresolved; any kind, so a `service` target keeps working). Target not local → derive; the edge validates it (Task 6). Cap and sorted truncation unchanged. The unresolved log 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 ready (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 1: Change the existing tests to the new rules.** `TestReconcileSkipsUnknownTarget` becomes `TestReconcileDerivesNonLocalTarget`. `TestReconcileSkipsWhenClaimHostIsNotALocalRoute` becomes `TestReconcileDerivesRowsForNonLocalHost` (rows carry the claim's account/app). `TestReconcileSkipsUnreadyTarget`, `TestReconcileRefusesCrossTenantTarget`, the sidecar refusals stay. `TestReconcileLogsUnresolvedTargetsOncePerHost` asserts the new wording. Add `TestReconcileKeepsLocalServiceTarget` (ready `service` target: row present) and `TestReconcileCapIdenticalForNonLocalHost`. |
| +- [ ] **Step 2: Run** `go test ./internal/domains/ -run 'TestReconcile' -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)`. |
| +- [ ] **Step 4: Run** → PASS; `go test ./internal/registry/ -run TestFingerprint -count=1` stays green. |
| +- [ ] **Step 5:** Switch `BenchmarkReconcilePathSection`'s workload to non-local hosts and targets and re-run it; record in the ledger. Over budget: stop and report. |
| +- [ ] **Step 6: 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`) |
| +- Modify: `internal/host/edgesfile.go` (`edgeHost`; the route loop in `edgesFileWriteClaims` ~line 733) |
| +- Modify: `internal/edge/homemap.go` (`edgesHostView`, `homeEntry`, `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`: |
| +- Consumes: `registry.PathFront`, `registry.PathTarget`, `registry.PathEligibilityCases`. |
| +- Produces: edges-file fields `route_account`, `route_app`, `path_front`, `path_target`; 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 |
| + 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. |
| +// exactPathRoute answers the exact (never wildcard) dialable route row another |
| +// box published for host, from one snapshot. false when absent, held, an alias |
| +// or "*." 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. |
| +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` (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 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 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. |
| - [ ] **Step 5: Commit** `edges file: publish route owner and path eligibility (#186)`. |
| |
| -### Task 5: The remote map in the edge |
| +### Task 5: One routing snapshot with a remote map |
| |
| **Files:** |
| - Create: `internal/edge/pathremote.go` |
| -- Modify: `internal/edge/edge.go` (`Edge` struct: one field; `Reload`: one call before `e.upstreams.Store(&m)`) |
| +- Modify: `internal/edge/edge.go` (`upstreams` field type; `Reload`'s store; `current()`), `internal/edge/certsettle.go`, `internal/edge/demo_api.go`, `internal/edge/replicaconsole.go` and `holdsHost` (each `e.upstreams.Load()` reader), and every test that calls `e.upstreams.Store` (24 sites; replace with `e.storeHosts(m)`) |
| - Test: `internal/edge/pathremote_test.go` |
| |
| **Interfaces:** |
| @@ -132,41 +141,39 @@ Writer rule: set the four fields only on rows of real routes: not `strings.HasPr |
| |
| ```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 |
| + prefixes map[string]string // prefix -> target host |
| + account, app string // the claim's, from the rows |
| } |
| -// 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 { |
| +// routeTable is the one atomically published routing snapshot. |
| +type routeTable struct { |
| hosts map[string]upstream |
| remote map[string]remotePathMap |
| } |
| -func (e *Edge) view() routingView |
| +// 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 buildRemotePaths(m map[string]upstream, rows []registry.RoutePath, forwardHosts, regional map[string]bool, demoReserved func(string) bool) map[string]remotePathMap |
| ``` |
| |
| -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). |
| +`Reload` builds `remote` from the rows it already read, `forwardHosts` from its routes list (`IsForward()`), `regional` from the names its regional fold put in `m` with `regional != regionalNone`, and stores one `&routeTable{hosts: m, remote: remote}`. Skipped rows: host present in `m`; host in `forwardHosts`; host or target `demoReserved`; host in `regional`. A host whose rows disagree on account/app is dropped and logged. Pointer-identity readers (`certsettle.go`'s `own == a.own`) compare `*routeTable` pointers. |
| |
| -- [ ] **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)`. |
| +- [ ] **Step 1: Write the failing tests.** `TestRemotePathsBuiltForUnservedHosts`; `TestRemotePathsSkipRegionalName` (Review Focus 3); `TestRemotePathsSkipForwardHost`; `TestRemotePathsSkipDemoReserved`; `TestReloadPublishesOneSnapshot` (concurrently: a reader goroutine loops `e.table()` while `Reload` runs N times on an unchanged registry; every observed table has `remote["hub.example"]` populated; the reader stops on a channel, no sleeps). |
| +- [ ] **Step 2: Run** `go test ./internal/edge/ -run 'TestRemotePaths|TestReloadPublishesOneSnapshot' -count=1` → FAIL. |
| +- [ ] **Step 3: Implement**, including the mechanical `storeHosts` replacement in tests. |
| +- [ ] **Step 4: Run** `go test ./internal/edge/ -run 'TestRemotePaths|TestReloadPublishesOneSnapshot|TestPath|TestCertSettle|TestDemoAPI|TestReplicaConsole' -count=1` → PASS; `go vet ./internal/edge/`. |
| +- [ ] **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: Selection |
| +### Task 6: One validated selection |
| |
| **Files:** |
| - Create: `internal/edge/pathselect.go` |
| -- Modify: `internal/edge/edge.go` (`lookupUpstreamPath`: its match block moves into `matchPrefix`; behaviour for existing callers unchanged) |
| +- Modify: `internal/edge/edge.go` (`lookupUpstreamPath` and `selectUpstream` delegate to the new selection; `ServeHTTP` unchanged in this task) |
| - Test: `internal/edge/pathselect_test.go` |
| |
| **Interfaces:** |
| -- Consumes: `view()`, `exactPathRoute`, `registry.PathFront/PathTarget`. |
| +- Consumes: `e.table()`, `exactPathRoute`, `registry.PathFront/PathTarget`. |
| - Produces: |
| |
| ```go |
| @@ -175,35 +182,42 @@ func matchPrefix(prefixes map[string]string, urlPath string) (prefix, target str |
| |
| 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 |
| + 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 |
| ) |
| -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 |
| +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 |
| +} |
| +// 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 |
| ``` |
| |
| -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)`. |
| +`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)`. |
| |
| ### Task 7: A backhaul for a route under another Host |
| |
| @@ -216,48 +230,54 @@ Rules (spec §5.3): front route on the host's box = exact entry `v.hosts[host]` |
| - 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, ...). |
| +// 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. |
| +`backhaulTarget`, `backhaulAlternative`, `handoverAlternative`, `backhaulHolders.get/remember/drop`, `dropBackhaulHolder` and their 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 1: Write the failing tests** using the `BackhaulHolderScene` pattern (`backhaul_holder_export_test.go`: distinct `127.0.0.N` box addresses, per-destination `backhaulTransport(ip).DialContext`): `TestBackhaulRouteToSignsWireHost` (the receiving edge verifies the MAC for `hub.example` and the backend sees `r.Host == "hub.example"`); `TestBackhaulRouteToKeysHolderOnRoute` (a holder refusal naming box C is remembered under `tenant.example`, not `hub.example`); `TestBackhaulRouteToRefusesArrivedHop`. Existing `-run 'TestBackhaul'` tests stay green. |
| - [ ] **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). |
| +**Review:** Astra task review (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`) |
| +- Modify: `internal/edge/edge.go` (`ServeHTTP`: calls only, net lines not growing; the ownership block reads `up.front`) |
| +- Modify: `internal/edge/pathhop.go`, `internal/edge/pagecache.go` (lines ~244 and ~277: `up.front != nil` is not eligible) |
| +- Test: `internal/edge/path_across_e2e_test.go` (create) |
| |
| **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) |
| +// 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 |
| ``` |
| |
| -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. |
| +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`. |
| + |
| +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. |
| |
| -- [ ] **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 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 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 3: Implement.** |
| +- [ ] **Step 4: Run** `-run 'TestPathAcross|TestPath|TestSelectPath|TestBackhaul|TestSelectUpstreamIsTheOnlySite|TestAdmission'` → PASS. `make code-health`. |
| - [ ] **Step 5: Commit** `edge: path targets across boxes in ServeHTTP (#186)`. |
| |
| **Review:** Astra task review (security gate and hop). |
| @@ -265,33 +285,33 @@ Placement (spec §5.5): after `selectUpstream` and the demo/admission/replica-pr |
| ### 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 |
| +- Modify: `internal/edge/haingress.go` (`routeHAIngress` gains `routeName string`), `internal/edge/edge.go` (its one call site) |
| - 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. |
| +- 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. |
| |
| -- [ ] **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 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 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). |
| +**Review:** Astra task review (HA). |
| |
| ### 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) |
| +- Modify: `internal/edge/purge_header.go` (`purgeOwns`, `resolvePurgeOwnersIn` and their callers at ~747, ~789), `internal/edge/pagecache.go` (`ownsHost`) |
| - 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. |
| +- Produces: `func (e *Edge) purgeOwnsIn(t *routeTable, owner registry.Route, host string) bool` replacing the free `purgeOwns` (a method, so it can read `e.homes`); callers pass the `*routeTable` they already loaded (`e.table()`). New branch for `host` not in `t.hosts`: true only when `t.remote[host]` has a prefix whose target is `owner.Host`, `t.remote[host].account == release.RouteAccount(owner)`, `e.homes.Load().exactPathRoute(host)` returns `Front` with matching account/app, and `t.hosts[owner.Host]` is `sameInstance` as `owner`. `resolvePurgeOwnersIn` takes `*routeTable` 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 1: Write the failing tests.** `TestPurgeAcrossEvictsExactURL`, `TestPurgeAcrossEvictsPath`, `TestPurgeAcrossEvictsWholeHost` (tenant here, 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 4: Run** `-run 'TestPurge|TestPageCache'` → PASS. |
| - [ ] **Step 5: Commit** `edge: a path target purges its pages under the front host (#186)`. |
| |
| **Review:** Astra task review (cache, security gate). |
| @@ -299,35 +319,61 @@ Placement (spec §5.5): after `selectUpstream` and the demo/admission/replica-pr |
| ### 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`) |
| +- Modify: `internal/edge/edge.go` (the login POST block, ~line 2784: call only), `internal/edge/pathhop.go` (helper and copy constant `copyPathGateAcross`) |
| - 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. |
| +- 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. |
| |
| -- [ ] **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 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 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 |
| +### Task 12: Readers of route_paths, docs and the rollout order |
| |
| **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`) |
| +- 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) |
| - 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. |
| +- [ ] **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)`. |
| + |
| +### Task 13: Branch gate, census, pre-roll check, dev witness |
| + |
| +- [ ] **Step 1: Benchmarks, final.** Re-run Task 1's three benchmarks on the branch tip (non-local workloads); record in the ledger and branch description. Over budget: stop and report. |
| +- [ ] **Step 2: Gate.** `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 ./...`. |
| +- [ ] **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 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. |
| + |
| +## Spec requirement → test matrix |
| + |
| +| Spec | Requirement | Test(s) | |
| +|---|---|---| |
| +| §5.1 | rows on every box; local checks unchanged | Task 3 tests | |
| +| §5.1 | diffed writes | `TestReconcileUnchangedPathsWritesNothing` | |
| +| §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.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.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.4 | door cut | `TestSelectPathDoorNeverAcross`, `TestSelectPathDoorHopIgnoresRemoteMap`, `TestPathAcrossDoorCallStaysSameBox`, `TestPathAcrossDoorHopMapsDiffer` | |
| +| §7.5 | fleets | `TestSelectPathForwardTargetNeverSelected`, `TestRemotePathsSkipForwardHost` | |
| +| §8 | ordering rule | Task 12 runbook; Task 13 Steps 6-8 | |
| +| §9 | dev witness | Task 13 Step 8 | |