spec: path routes across boxes (#186), rev 1
The ingress box selects the prefix and makes its one hop straight to the target's box; the receiving box re-resolves. Docs only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+408
−0
docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md+408 −0
CI cancelled — superseded by a newer push — run details
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| new file mode 100644 |
| index 000000000..b85515852 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| @@ -0,0 +1,408 @@ |
| +# Path routes across boxes: a prefix whose target lives on another box |
| + |
| +Rev 1, 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 |
| +own route". |
| + |
| +Written without a live session with Paul. Every decision he did not make is |
| +marked **my call** and listed in §11. |
| + |
| +## 1. Intent |
| + |
| +A path route (`PUT /api/cli/apps/{account}/{app}/domains/{host}/paths`) |
| +today reaches a target only when the target's route lives on the same box as |
| +the hostname's own route. A prefix whose target lives elsewhere derives no |
| +row anywhere and silently serves the hostname's own route. A path-routed |
| +product is therefore one box big. |
| + |
| +**What a user gets:** a subdirectory-routed product (`example.com/acme` |
| +served by acme's own instance) that can grow past one box. Tenants can be |
| +placed wherever the platform puts instances, including other regions. |
| + |
| +**Who is asking:** Paul, for Seamus (an events CMS) and Patrix (a blogging |
| +platform). Both are Rastrillo "hub" products: the user-models design |
| +(pegamento `design-user-models`, §3C, §7.4, approved 2026-09-28) recommends |
| +the hub, and §7.4 names this as platform request 2. |
| + |
| +**When it switches on:** in the first release that carries it, with no |
| +switch of its own (§8). Its first user is Rastrillo's |
| +`rastrillo new --scaffold hub`; `provision.PublishPaths` already publishes |
| +the map and the scaffold already checks that each prefix answers with the |
| +tenant's `X-Carlos-Version`. |
| + |
| +## 2. Goals, non-goals, anti-goals |
| + |
| +Goals: |
| + |
| +- A prefix whose target is homed on any box of the deployment reaches the |
| + target, whichever box the request arrives on. |
| +- The target sees exactly what it sees today on the same box: the original |
| + `Host`, the original path bytes (no stripping), and its own route's |
| + attribution (metering, version header, activator, gate, purge tenancy). |
| +- At most one hop between edges, as today. |
| + |
| +Non-goals: |
| + |
| +- No change to the wire, the write door, the cap, or the matcher (the |
| + two-spelling first-segment rule, 09-02 §6). |
| +- No multi-segment prefixes, no per-prefix settings, no path-aware certs, |
| + DNS or placement. The hostname stays the unit of all three. |
| +- No password gate on a target selected across boxes (§7.3). |
| + |
| +Anti-goals (would be a failure even if requests got through): |
| + |
| +- **A second hop.** The edge's "one hop, ever" rule is its structural loop |
| + guard (`backhaul`, `backhaulTo`). Nothing here relaxes it. |
| +- **The tenant seeing a different request depending on placement.** Same box |
| + and cross box must be indistinguishable to the app: same `Host`, same |
| + cache key, same purge vocabulary. |
| +- **Another tenant's traffic reaching a backend.** The 09-02 account rule (a |
| + target must be in the claim's account) holds on every box, including boxes |
| + that cannot see either route locally. |
| +- **A 503 where today gives a 200 during a roll.** A mixed-version fleet |
| + must behave at least as well as today's fall-through. |
| + |
| +## 3. How it works today |
| + |
| +1. **Derivation** (`internal/domains/aliases.go`, `ReconcileAliasesReport`). |
| + Every box reads every claim. A claim's `Paths` become `route_paths` rows |
| + only on the box whose registry holds the claim's host route (the |
| + "hostname's own route is not on this box; another box derives these |
| + rows" branch), and only for targets that are a **local ready route** in |
| + the claim's account. Anything else is counted as unresolved and logged. |
| +2. **Fold** (`Edge.Reload`, edge.go ~1440). Each row is attached to the host's |
| + entry in the live map as `up.paths[prefix] = target`. A row whose host has |
| + no entry is skipped. Forward hosts, demo routes and demo-reserved targets |
| + are filtered out. |
| +3. **Lookup** (`lookupUpstreamPath`). Host first; for a host with a map, |
| + first segment (raw and cleaned); a hit returns `m[target]` wholesale; any |
| + miss returns the host's own entry. Regional entries never select by path. |
| +4. **Elsewhere.** A request for `example.com/acme` that arrives on a box not |
| + homing `example.com` is a host miss and is backhauled, signed for |
| + `example.com`, to the host's home box, which then runs step 3. The home |
| + box cannot hop again, so even if it knew where the target lived it could |
| + not send the request there. |
| + |
| +So the fix cannot live on the host's home box alone: by the time a |
| +non-home ingress box has backhauled the request there, its one hop is spent. |
| +**The path has to be selected on the box the request arrives on.** |
| + |
| +## 4. Approaches |
| + |
| +**A. The ingress box selects; one hop to the selected route's box |
| +(chosen).** Every box knows every path-routed host's map. The box a request |
| +arrives on selects the target exactly as the home box does today, then |
| +serves it locally or makes its one hop straight to the box that serves the |
| +target. The receiving box re-runs the same selection from `Host` and path |
| +and serves the target. One hop, `Host` preserved, the target's box does all |
| +the per-request work, as it does for any backhauled host. |
| + |
| +**B. Two hops: ingress → host's home → target's box.** Keeps today's |
| +derivation. Rejected: it relaxes "one hop, ever", which is the loop guard; |
| +doubles cross-box latency for every tenant request arriving off the hub's |
| +box; and makes the hub's box a relay for every tenant's traffic. |
| + |
| +**C. Rewrite `Host` to the target and backhaul as an ordinary hop** (the |
| +literal reading of "keyed on the target host" in #186). Rejected: the |
| +tenant would see `Host: acme.<...>.oncarlos.com` across boxes and |
| +`Host: example.com` on the same box; the response cache would key the |
| +tenant's pages under the target's hostname, so one target behind two front |
| +hosts would share entries; the hub-session cookie (`__Host-`, user-models |
| +§6.3) and every absolute URL the tenant builds depend on the front host. It |
| +also still needs ingress-side selection to avoid a second hop, so it saves |
| +nothing. |
| + |
| +**D. Keep co-location and enforce it** (place tenants on the hub's box, or |
| +refuse cross-box targets at the door). Rejected: it is the ceiling #186 asks |
| +to remove. |
| + |
| +## 5. Design |
| + |
| +### 5.1 Derivation: every box derives every path-routed host's rows |
| + |
| +`route_paths` keeps its schema and its "wholly pass-owned" rule. What |
| +changes is which box derives which rows: |
| + |
| +- **The host gate.** If the claim's host is a local route, today's check |
| + stands (route account and app match the claim). If it is not local, the |
| + rows are still derived; the host's ownership is checked at request time |
| + against the home map instead (§5.3). The sidecar-suffix refusals stand |
| + unchanged on every box. |
| +- **The target gate.** Prefix validity and the sidecar-target refusal stand. |
| + If the target is a local route, today's account and readiness checks |
| + stand. If it is not local, the row is derived and the account check moves |
| + to request time (§5.3). |
| +- **The unresolved log** loses its "must be homed on the SAME box" advice. |
| + The reconcile pass can no longer tell "missing" from "elsewhere"; the edge |
| + can, and logs (§5.6). |
| +- The cap and its deterministic sorted truncation are unchanged, and now |
| + matter more: every box must truncate identically or the same URL would |
| + select differently by ingress. |
| + |
| +Every `ListPaths` reader must then be checked against rows whose host is not |
| +local (**the builder's audit**, a required plan task): |
| + |
| +| Reader | Today's assumption | Needed | |
| +|---|---|---| |
| +| `Edge.Reload` fold | rows' hosts are in `m` | rows whose host is not in `m` go to the remote map (§5.2), not dropped | |
| +| `servedOwners` (`internal/host/edgesfile.go`) | skips hosts it does not serve | unchanged; a remote target is not added as an owner (§7.4) | |
| +| `assetpolicy` `pathHosts` | marks local path hosts | harmless superset; confirm | |
| +| `apiroutes` (`carlos routes`) | rows hang under listed hosts | show rows only under hosts the listing has, as now; confirm no orphan rows render | |
| +| `Fingerprint` | hashes all rows | unchanged; it must still move on every row change | |
| +| reconcile's own delete-unlisted pass | — | unchanged | |
| + |
| +**My call:** one table, not a second "remote paths" table. The rows are the |
| +same fact (a claim's prefix map); only the reader decides what locality |
| +means, and the reload fold is where that already happens. |
| + |
| +### 5.2 The live map: a remote map beside `m` |
| + |
| +`Reload` builds, from rows whose host has no entry in `m`, a |
| +`remotePaths map[host]map[prefix]target` stored in the same snapshot as `m`, |
| +so one `current()` read sees both. The same filters as the local fold apply: |
| +no forward hosts, demo-reserved hosts and targets dropped |
| +(`filterDemoRoutes`' rules), and no map for any name the regional table |
| +holds on this box (regional names never select by path, 09-02 and #447). |
| + |
| +Rows whose host **is** in `m` fold into `up.paths` exactly as today, with one |
| +change: a row whose target is **not** in `m` is kept, not silently missing |
| +at lookup. That is what lets the host's own box send a prefix to a remote |
| +target (§5.3, case 1). |
| + |
| +### 5.3 Selection |
| + |
| +`lookupUpstreamPath(host, path)` keeps its signature for every caller that |
| +only wants a local upstream, and selection gains a third outcome. The |
| +result of selecting is one of: |
| + |
| +- **local**: an upstream on this box (today's two outcomes, host route or |
| + path target); |
| +- **remote**: "this request belongs to route T, served on box B" (new); |
| +- **none**: a host miss with no path selection (today's backhaul to the |
| + host's home, unchanged). |
| + |
| +The matcher (both spellings, cleaned wins, one segment, one hop of |
| +indirection) is shared, not copied: one function produces the selected |
| +prefix and target for a host's map whichever map it came from. |
| + |
| +Cases, on the box the request arrives on: |
| + |
| +1. **The host is local, a prefix hits, the target is local.** Today's |
| + answer, unchanged. |
| +2. **The host is local, a prefix hits, the target is not local.** Look up the |
| + target's owner in the home map (`homes.Owner(T)`). Selected as **remote** |
| + only when all hold: the owner is dialable; its account equals the row's |
| + account (the 09-02 tenancy rule, now enforced where the facts are); its |
| + serving box publishes the `path-hops-1` capability (§8). Otherwise the |
| + request serves the host's own route, as today, and the edge logs (§5.6). |
| +3. **The host is not local and has a remote map.** First check the host's |
| + owner (`homes.Owner(host)`): its account and app must equal the row's |
| + account and app, or the remote map is ignored for this request and it is |
| + backhauled to the host's home as today. Then match the path: |
| + - prefix misses → backhaul to the host's home, as today; |
| + - prefix hits and the target is local → serve the target here, as case 1 |
| + would on the home box; |
| + - prefix hits and the target is remote → as case 2, and if case 2's |
| + checks fail, backhaul to the host's home as today. |
| +4. **The host is not local and has no remote map.** Today's answer. |
| + |
| +The account check on case 3's target is the one that matters most: no box |
| +may send a prefix to a route in another account, whichever box it is and |
| +whatever it can see locally. |
| + |
| +**My call:** request-time ownership checks rather than reload-time ones. |
| +The home map refreshes on its own 30-second cycle, independent of reload; |
| +checking at request time means a moved or re-owned route is judged against |
| +the freshest view, at the cost of two map reads on a request for a remote |
| +path-routed host. |
| + |
| +### 5.4 The hop, and the box that receives it |
| + |
| +A remote selection makes the ordinary signed backhaul (`backhaulTo`) with: |
| + |
| +- **`Host` unchanged and the MAC over the request's `Host`**, as every hop is |
| + signed today (`signHop(key, host, now)`). SNI is the request's host; every |
| + edge serves every cert (`certsync`'s mirror), so the receiving box |
| + presents it. |
| +- **Dialled to the target's serving box**, and every sender-side table that |
| + is keyed by host today (the HA holder cache, suspect boxes, |
| + `backhaulAlternative`, the backhaul owner) keyed by the **target**, since |
| + that is the route the hop is for. |
| + |
| +**No new hop header.** The receiving box does not take the sender's word for |
| +which route was selected; it runs the same selection itself, from `Host` and |
| +path, against its own maps, and on a verified hop accepts only a **local** |
| +answer: |
| + |
| +- local answer → serve it (the target's entry wholesale, as on the same box); |
| +- remote or none → `staleHopRefusal` (503, `Retry-After: 2`), never onward. |
| + |
| +Both boxes derive the same rows from the same claims within one fast-converge |
| +tick, so they agree outside a few seconds after a republish. **My call:** |
| +re-resolution over a signed "selected target" header, because it adds no |
| +vocabulary to the hop, keeps "a hop is a request for `Host`" true, and makes |
| +the receiving box's own tenancy view the last word. |
| + |
| +**The host's home box receiving a hop that selects a remote target.** This |
| +happens when the sender did not select the prefix: an old binary mid-roll, |
| +or a sender whose map is a tick behind. The home box cannot hop again. It |
| +serves the **host's own route**, exactly today's answer, and logs. **My |
| +call**, over a 503: a 503 there would turn today's 200 into an error for |
| +every request arriving through an old box during a roll (§2's last |
| +anti-goal), and the window after a republish is the same few seconds today |
| +already has. |
| + |
| +### 5.5 ServeHTTP placement |
| + |
| +Selection stays where `selectUpstream` is today. A remote selection is |
| +handled on the miss arm's side, before the far asset catch, so a request |
| +that belongs to a target is never answered from the host's declared assets. |
| +Every arm above the lookup (`acceptHop`, the regional gate, the HA ingress |
| +alias) is unchanged. |
| + |
| +Case 3's "target is local" answer serves a host this box does not serve |
| +exactly. The alias and catch-all ownership block (the |
| +`!e.servesExactly(host)` branch after the regional gate) must not treat it |
| +as a wildcard match: a path-selected upstream carries a mark, and that block |
| +skips marked upstreams. The host's ownership was already checked in §5.3. |
| + |
| +Downstream of selection, nothing changes: the target's entry carries |
| +metering, the version header, the activator, admission, rate limits and |
| +the response cache. The cache keys on the requested host (09-02 §6), and the |
| +target's entries now live on the target's box. The page cache's exclusion of |
| +path-routed hosts (`pagecache.go`) must hold for case 3 too. |
| + |
| +### 5.6 What the operator sees |
| + |
| +- The reconcile log keeps its per-host aggregated "names no local ready |
| + route" count, reworded so it no longer tells anyone to co-locate. |
| +- The edge logs, throttled per host, when a prefix names a target with no |
| + dialable owner anywhere, a target in another account, or a serving box |
| + without `path-hops-1`. These are the three "it still falls through" |
| + reasons, and they are the ones an operator can act on. |
| +- **My call:** no new CLI surface in this slice. `carlos domains paths` |
| + already lists the map; the hub scaffold's version check is the end-to-end |
| + test of reachability. |
| + |
| +## 6. Latency |
| + |
| +- **Republishing a map** on its own: unchanged, about five seconds (09-02 |
| + §7), now on every box rather than one. |
| +- **A brand-new target on another box** (a tenant just created): reachable |
| + from other boxes once its box republishes its edges file (seconds) and |
| + the sender's home map polls it (`homeMapInterval`, 30 s). Up to about 35 |
| + seconds, during which the prefix serves the host's own route. This is the |
| + same delay any new hostname has today when it arrives on a box that does |
| + not home it. The Rastrillo hub scaffold's step 6 version poll must allow |
| + at least a minute before marking a tenant `failed`. |
| + |
| +## 7. What changes for adjacent features |
| + |
| +### 7.1 Regional names (#447) |
| + |
| +Unchanged. A regional entry still never selects by path, and no remote map |
| +is built for a name the regional table holds on the box. A cross-box target |
| +may be in another region; that hop is an ordinary cross-region backhaul. |
| + |
| +### 7.2 Purge |
| + |
| +A target app emits `Carlos-Purge-Host: <front host>` (09-02's "what an app |
| +must do"). Its box now holds the front host's entries for that target, and |
| +`resolvePurgeHost`'s path-routing branch must accept the front host when this |
| +box's remote map has a prefix on it selecting the purging route, with the |
| +same account requirement. A hub's whole-host purge drops the hub box's |
| +entries only; tenant pages cached on other boxes are purged by their own |
| +apps. **My call:** acceptable, and arguably more correct than today, where a |
| +hub's `Carlos-Purge: *` also drops every co-located tenant's pages. |
| + |
| +### 7.3 The password gate |
| + |
| +A login POST is re-resolved by its `next` path (`gate.LoginPath`), but it |
| +arrives at the host's route, not the prefix's, so on a box that does not |
| +serve the target it cannot be sent to the target without reading the body |
| +before the hop. **Out of scope** (**my call**): a gated target under a |
| +cross-box prefix is not supported in this slice. The receiving box never |
| +judges the password with the wrong route: a login POST whose `next` selects |
| +a remote target answers a refusal with a sentence, not the host's gate. |
| +Hub tenants authenticate with the hub session (user-models §6.3), so the |
| +hub model does not need the gate. |
| + |
| +### 7.4 Door callers |
| + |
| +A door caller's own app selected through a prefix is served as on the same |
| +box (the door scope compares against the selected route). The edges file's |
| +owner set for a front host still lists only local targets, so a remote |
| +target app calling the **front host's own route** through the door is not |
| +admitted. **My call:** unchanged in this slice; a tenant calls the hub on the |
| +hub's own hostname. |
| + |
| +### 7.5 Region HA and fleets |
| + |
| +A born-HA target is dialled at its serving box as `Owner(T)` resolves it, |
| +with the holder logic keyed by the target (§5.4). A target that is a fleet |
| +forward row is unchanged from today (the 09-02 design never covered it). |
| + |
| +## 8. Rollout and the mixed-version fleet |
| + |
| +No feature switch (**my call**): publishing a map that names a remote target |
| +is the opt-in, and the scaffold that does so has not shipped. |
| + |
| +A box running this release publishes `path-hops-1` in its edges file's |
| +capabilities. A sender selects a remote target only when the target's |
| +serving box publishes it (§5.3), so a new ingress box never hops a prefix |
| +to an old box that would refuse it. An old ingress box backhauls to the |
| +host's home as today, and §5.4's rule keeps that answer a 200. |
| + |
| +**Behaviour change on release:** any live map that already names a target on |
| +another box starts reaching that target. Before the roll, list path maps on |
| +dev and flagship and confirm nobody relies on today's fall-through. None is |
| +expected: `ti.to` is not behind the edge and the hub scaffold has not shipped. |
| + |
| +## 9. Tests the plan must carry |
| + |
| +- Derivation: rows for a non-local host and non-local targets are written on |
| + every box; cross-account local targets still refused; sorted truncation |
| + identical across boxes. |
| +- Fingerprint moves when a non-local host's row changes. |
| +- Selection, all four cases of §5.3, each with the account check failing. |
| +- **The tenancy guard:** a remote map whose target's owner is another |
| + account never selects it, on the host's box and off it. |
| +- One hop: a verified hop never leaves the receiving box, whatever its maps |
| + say (an extension of the existing "one hop, ever" tests). |
| +- The home box receiving a hop that selects a remote target serves the |
| + host's route. |
| +- `path-hops-1` absent on the target's box → no remote selection. |
| +- An end-to-end test with two edges and a shared fake store: a request on the |
| + hub's box and one on the tenant's box both get the tenant's version header |
| + with the front `Host`; a removed prefix stops selecting within one fold. |
| +- Purge: a target's `Carlos-Purge-Host: <front host>` purges on its own box. |
| +- **Witness on dev** (rule 6, the slice's observable result): a hub on one dev |
| + box, a tenant on another, `curl https://<hub>/<slug>/api/version` from |
| + outside answers with the tenant's version, through either box's ingress. |
| + |
| +## 10. What is left to the builder |
| + |
| +- Where the remote map lives in the snapshot type, and the mark that tells |
| + the ownership block a path selection made the upstream (§5.5). |
| +- How the shared matcher returns the selected target without changing |
| + `lookupUpstreamPath`'s callers that want a local upstream only |
| + (`TestSelectUpstreamIsTheOnlySite` stays true). |
| +- The copy for the gate refusal in §7.3 goes through copy review. |
| + |
| +## 11. Calls I made (for Paul to confirm or overturn) |
| + |
| +1. Approach A: the ingress box selects, one hop, receiver re-resolves (§4). |
| +2. One `route_paths` table derived on every box, not a second table (§5.1). |
| +3. Ownership and account checks for remote hosts and targets at request |
| + time against the home map (§5.3). |
| +4. No new hop header; the receiving box re-runs selection (§5.4). |
| +5. The host's home box, receiving a hop that selects a remote target, serves |
| + the host's own route rather than 503 (§5.4). |
| +6. No new CLI surface (§5.6). |
| +7. A hub's whole-host purge stops reaching tenants on other boxes (§7.2). |
| +8. Password-gated targets under a cross-box prefix are out of scope (§7.3). |
| +9. Door calls from a remote target to the front host's own route stay |
| + refused (§7.4). |
| +10. No feature switch; a `path-hops-1` capability protects the roll (§8). |