| index 93d717276..6e88ce005 100644 |
| --- a/docs/superpowers/specs/2026-11-25-hub-ha-design.md |
| +++ b/docs/superpowers/specs/2026-11-25-hub-ha-design.md |
| @@ -1,6 +1,8 @@ |
| # Hub HA: fleet traffic through hub restarts and hub loss (#1388, #908) |
| |
| -Design, 2026-11-25, **rev 1** (draft for Astra round 1). Asked for by agent manager 8a3d302 with Paul's go, relayed through Tito. Branch `design-hub-ha`, cut from `origin/main` at bac71e00. Nothing here is built. Review budget: at most three Astra rounds (AGENTS.md stopping rules); a P1 in round three means cut scope and go to Paul. |
| +Design, 2026-11-25, **rev 2**. Asked for by agent manager 8a3d302 with Paul's go, relayed through Tito. Branch `design-hub-ha`, cut from `origin/main` at bac71e00. Nothing here is built. Review budget: at most three Astra rounds (AGENTS.md stopping rules); a P1 in round three means cut scope and go to Paul. |
| + |
| +- **Rev 1** (dfd46a8e) was reviewed by Astra round 1 (`CODEX-FINDINGS-hub-ha-R1.md`): NOT READY, 6 P1 and 5 P2. **Rev 2** answers all eleven; §7 maps each one. The largest change is §2: on a W6-armed hub the listeners close at the **start** of W6's 30 s connection wait, so today's gap through other edges is about a minute on dev, not seconds. Part 1 gains S0 (a hub keeps accepting through its drain) and moves S3's hold inside connection acquisition. Part 2 drops the hub-to-hub forward for per-channel claims and the §25 handover answer, signs the hub view, and gives every hub's fleet credentials a lease. |
| |
| Line citations are to `origin/main` at bac71e00. |
| |
| @@ -18,254 +20,276 @@ So the hub's edge process is a single point of failure for every fleet app in th |
| |
| ### 2.1 The dev hub (sophie), six restarts on 2026-11-24 |
| |
| -Read-only journal of `carlos-edge` on sophie (i-05498eada6f0afd23), which has W6 armed for two target groups and `CARLOS_GROUP_ADMISSION=1`: |
| +Read-only journal of `carlos-edge` on sophie (i-05498eada6f0afd23). Sophie has W6 armed for two target groups and `CARLOS_GROUP_ADMISSION=1`. Every drain report said `1 cut` or `2 cut`, which means W6's 30 s connection wait (`internal/host/ingressdrain.go:51`) ran to its bound. W6 closes the listeners at the **start** of that wait and logs "drain done" at its end (`ingressdrain.go:399`), so the listeners closed about 30 s before the logged time. |
| + |
| +| Restart | Drain began | Listeners closed (≈ done − 30 s) | Drain done | New edge started | Tunnel back | Tenant admission open | |
| +|---|---|---|---|---|---|---| |
| +| 10:32 | 10:31:39.05 | ≈10:32:12 | 10:32:42.18 | 10:32:43.04 | 10:32:44.25 | 10:33:13.74 | |
| +| 10:48 | 10:47:02.84 | ≈10:47:38 | 10:48:08.01 | 10:48:08.03 | 10:48:09.22 | 10:48:38.66 | |
| +| 12:31 | 12:30:20.32 | ≈12:30:56 | 12:31:25.51 | 12:31:26.58 | 12:31:27.71 | 12:31:57.32 | |
| +| 12:46 | 12:45:44.44 | ≈12:46:20 | 12:46:49.65 | 12:46:51.00 | 12:46:52.21 | 12:47:21.73 | |
| +| 13:01 | 13:00:56.15 | ≈13:01:29 | 13:01:59.30 | 13:01:59.32 | 13:02:00.51 | 13:02:30.05 | |
| +| 18:51 | 18:50:20.33 | ≈18:50:56 | 18:51:25.52 | 18:51:27.33 | 18:51:28.46 | 18:51:57.99 | |
| |
| -| Restart | Drain began | Listeners closed | New edge started | Tunnel `demo/box-1` back | Tenant admission open | |
| -|---|---|---|---|---|---| |
| -| 10:32 | 10:31:39.05 | 10:32:42.18 | 10:32:43.04 | 10:32:44.25 (+1.2 s) | 10:33:13.74 (+30.7 s) | |
| -| 10:48 | 10:47:02.84 | 10:48:08.01 | 10:48:08.03 | 10:48:09.22 (+1.2 s) | 10:48:38.66 (+30.6 s) | |
| -| 12:31 | 12:30:20.32 | 12:31:25.51 | 12:31:26.58 | 12:31:27.71 (+1.1 s) | 12:31:57.32 (+30.7 s) | |
| -| 12:46 | 12:45:44.44 | 12:46:49.65 | 12:46:51.00 | 12:46:52.21 (+1.2 s) | 12:47:21.73 (+30.7 s) | |
| -| 13:01 | 13:00:56.15 | 13:01:59.30 | 13:01:59.32 | 13:02:00.51 (+1.2 s) | 13:02:30.05 (+30.7 s) | |
| -| 18:51 | 18:50:20.33 | 18:51:25.52 | 18:51:27.33 | 18:51:28.46 (+1.1 s) | 18:51:57.99 (+30.7 s) | |
| +Admission waited on `Reconciled, RolePublished, TerminationStarted, hosting, activator` every time. |
| |
| -Times after "+" are from the new process's start. Admission waited on `Reconciled, RolePublished, TerminationStarted, hosting, activator` every time. |
| +Reading it, for a fleet request that enters through another edge: |
| +1. **About 31 to 33 s refused.** From the listener close to the new process binding, every hop is refused, and the sender answers 502 (§2.3). Tenant units stop and the agent shuts down inside this window too; on dev that took about 1 s (drain done to new start), but its budgets are 18 s per tenant unit (`internal/host/units/carlos-instance@.service:14`) and 90 s for the agent's duties and activator (`internal/host/agent.go:1469`). |
| +2. **Tunnels come back fast:** about 1.1 s after start. The box's backoff starts at 250 ms (`internal/tunnelclient/tunnelclient.go:42-43`) and the hub loads fleet credentials before it listens (`edge.go:1060,1541`). |
| +3. **Then about 30 s more.** Until admission opens, sophie's edges file says `booting, admitted=false` (`internal/host/group_admission.go:150`). Every home claim needs `HomeEligible()` (`internal/edge/homemap.go:1070`, `internal/edgesfile/admission.go:19-27`), so senders treat the fleet names as having no eligible server. Locally, forward and replica-set rows are not exempt from tenant admission (`internal/host/group_admission.go:100` exempts only platform and unit-backed rows), so the hub itself answers 503 `Retry-After: 10` (`internal/edge/group_admission.go:10-24`). A fleet row needs neither the activator, a lease nor a reconcile. |
| |
| -Reading it: |
| -1. **The listener gap is about 1 to 2 s** (listeners closed to new process start, plus about 1 s to bind). Every hop from another edge in that window is refused. |
| -2. **Tunnels come back fast:** about 1.1 s after start, because the box's backoff starts at 250 ms (`internal/tunnelclient/tunnelclient.go:42-43`) and the hub loads its fleet credentials before it listens (`edge.go:1060,1541`). |
| -3. **Then 30 s of 503 for fleet apps on an admission-gated hub.** Forward and replica-set rows are tenant rows. A fixed box exempts only platform and unit-backed rows from tenant admission (`internal/host/group_admission.go:100`), so the fleet arm answers 503 `Retry-After: 10` until admission opens (`internal/edge/group_admission.go:10-24`), although nothing about a fleet row needs the activator, a lease or a reconcile. This is the largest part of the gap on dev and on any hub with region HA's fixed admission. No fleet probe ran during these restarts, so this is read from the code and the admission log lines, not counted at a client. |
| +So a dev hub restart costs fleet traffic about **a minute** through other edges. This is read from the code and the journal; no fleet probe ran during these restarts. The witness (§3.9) counts it at a client before and after. |
| |
| ### 2.2 Tito's hub (no NLB, no W6, no tenant admission) |
| |
| -Tito's 15 s is not visible from here; this is the reconstruction from code, to be confirmed by the witness (§3.8): |
| -- **SIGTERM closes the listeners at once,** then waits up to 10 s for in-flight requests (`edge.go:5236-5248`). A tunnel is a hijacked connection, so `Shutdown` neither waits for it nor closes it; it dies at process exit. The tunnels keep serving in-flight work, but nothing new can reach the hub for the whole wait. Any long response (a proxied SSE stream, a slow download) makes the wait the full 10 s. |
| -- **Restart and bind:** about 1 s (`carlos-edge.service`, `Restart=always`, `RestartSec=1`; dev above). |
| +Tito's 15 s is not visible from here. Reconstructed from code, to be confirmed by Tito's witness: |
| +- **SIGTERM closes the listeners at once,** then waits up to 10 s for in-flight requests (`edge.go:5236-5248`). A tunnel is a hijacked connection, so `Shutdown` neither waits for it nor closes it; it dies at process exit. Any long response through the hub (a proxied SSE stream, a slow download) makes the wait the full 10 s. |
| +- **Agent shutdown and restart:** about 1 s typical (`carlos-edge.service`, `Restart=always`, `RestartSec=1`). |
| - **Tunnels:** about 1 s. |
| -- **Replica copies:** a fresh process has no probe history. A copy is live after two passing probes one second apart (`internal/edge/replicaprober.go:18-21`), so about 2 s more. Until then a replica-set row answers 503 `Retry-After: 2` (`internal/edge/replicaproxy.go:57-60`). The fallback to the previous forward row's box needs a previous map entry, which a new process does not have. |
| +- **Replica copies:** a fresh process has no probe history. A copy is live after two passing probes one second apart (`internal/edge/replicaprober.go:18-21`). Until then a replica-set row answers 503 `Retry-After: 2` (`internal/edge/replicaproxy.go:57-60`). The fallback to the previous forward row's box needs a previous map entry, which a new process does not have. |
| |
| -That is about 10 + 1 + 1 + 2 = 14 s, which matches the 15 s Tito saw. |
| +About 10 + 1 + 1 + 2 = 14 s, which matches the 15 s Tito saw. |
| |
| ### 2.3 What each client gets during the gap |
| |
| | Where the request entered | Answer today | |
| |---|---| |
| -| Another edge (another region, a region HA member, a fixed box) | **502 with no `Retry-After`** while the hub refuses (`internal/edge/backhaul_holder.go:298-316`; the alternative lookup finds no second claimant for a fleet name). Then whatever the hub answers. | |
| +| Another edge (another region, a region HA member, a fixed box) | **502 with no `Retry-After`** while the hub refuses (`internal/edge/backhaul_holder.go:298-316`; the alternative lookup finds no second claimant for a fleet name). While the hub's file says booting, no eligible server. Then whatever the hub answers. | |
| | The hub's own listener (DNS straight to the hub's address) | connection refused | |
| | The hub, after start, no tunnel yet | 503 `Retry-After: 2`, "fleet unreachable: no connected box" (`edge.go:4337-4340`) | |
| | The hub, after start, copies not yet risen | 503 `Retry-After: 2`, "no healthy copy is available" | |
| | The hub, admission closed | 503 `Retry-After: 10` | |
| |
| -Nothing on the hub waits for a tunnel to come back, and nothing on a sending edge waits for the hub. |
| - |
| -W6 does not help fleet traffic. It withdraws the hub from the NLB so the NLB sends it no new flows (`internal/host/ingressdrain.go:137-167`), but hops from other edges dial the hub's own address and never read the health answer. |
| +Nothing on the hub waits for a tunnel to come back, and nothing on a sending edge waits for the hub. W6 withdraws the hub from the NLB, but hops from other edges dial the hub's own address and never read its health answer. |
| |
| ## 3. Part 1: a hub restart that drops no fleet request |
| |
| -### 3.1 Guarantee |
| +### 3.1 The critical path, and the guarantee |
| |
| -For a **planned** restart of the hub's edge (a roll, `carlos system apply` or `rollback`, a host.env change, an operator `systemctl restart`), a fleet request gets **no error and a pause of at most about 15 s, typically 3 to 5 s**, when: |
| -- the fleet box serving it stays connected before and after, and its copy was healthy before; |
| -- the request entered through another edge, or through the region's NLB with W6 armed on the hub, or through the hub's own listener with socket handoff (S4); |
| -- it is not already running on the hub when the old process exits. A request in flight through a tunnel at exit keeps today's rule: it gets the 10 s drain, then it is cut and never retried. |
| +For a planned restart of the hub's edge (a roll, `carlos system apply` or `rollback`, a host.env change, `systemctl restart`), the time during which a new fleet request cannot be served is: |
| |
| -An unplanned hub death is not covered by Part 1; it is Part 2's job. |
| +> **T = (listener closed → new process accepting) + (accepting → the request's tunnel back and its copy live)** |
| |
| -### 3.2 S1: fleet rows are exempt from tenant admission |
| +Part 1 makes the first term as short as the process restart itself (S0, S4), makes the second about 1 to 2 s and waits through it (S2), keeps fleet names eligible while the new process boots (S1), and makes senders wait through T instead of failing (S3). |
| |
| -`fixedAdmission.exempt` (`internal/host/group_admission.go:100`) also returns true for a row the fleet arm serves: a forward row or a replica-set row (`FleetBoxes != ""`) that `FleetServeEligible` accepts on a hub. The activator's start refusal (`internal/activator/group_admission.go:15`) is unaffected, because the fleet arm never starts a local unit. |
| +**Guarantee.** A fleet request gets no error, and waits about T, when all of these hold: |
| +- the fleet box serving it stays connected before and after the restart, and its copy was healthy before; |
| +- it entered through another edge, through the NLB with W6 armed on the hub, or (with S4) through the hub's own listener; |
| +- T is under the **hold budget: 20 s at the sender plus 10 s at the hub, inside the hop's 30 s response-header timeout** (`edge.go:4580-4581`). On dev T is expected to be 2 to 4 s; on Tito about 12 s without S4 (the 10 s in-flight wait at SIGTERM, §2.2) and 2 to 4 s with it; |
| +- it is not already in flight through a tunnel when the old process exits. That keeps today's rule: the 10 s drain, then cut and never retried. |
| |
| -Why it is safe: tenant admission protects lease acquisition, local wakes and placement on a box that has not finished its first reconcile. A fleet row has none of these. Its only readiness inputs are the routing map and the fleet credentials, both loaded before the listeners bind (`edge.go:4947,5314-5341`), and the tunnel, which S2 waits for. Group members never take the exemption (`a.group` stays authoritative), and a group member is never a hub (`HubArmed` needs `CARLOS_FLEET` unset and the box is fixed under H24). |
| +Outside the budget, the answer is a retryable 503, never a bare 502. An unplanned hub death is not covered; it is Part 2's job. |
| |
| -### 3.3 S2: the hub waits for a tunnel and a copy instead of refusing |
| +### 3.2 S0: a hub keeps accepting through its W6 drain |
| |
| -A **warm-up window** starts when the edge starts serving and lasts 60 s. In that window, a request the fleet arm would answer with "no connected box" or "no healthy copy" is **held** instead: |
| -- it waits for the event that would let it through: the fleet's channel registering (forward row) or the copy rising (replica-set row), or the bound; |
| -- the hub reads none of its body while it waits; |
| -- when the event comes it is served as normal; at the bound it gets today's answer. |
| +W6 step 3 (`CloseIngress`, `internal/edge/ingressdrain.go:147`) closes the public listeners and then waits up to 30 s. On a hub that refuses every hop for the whole wait (§2.1). On a box where `TunnelsArmed` holds, step 3 changes: |
| +- it does **not** close the listeners; they close at SIGTERM, as on a box without W6; |
| +- it still sends `Connection: close` on every response, closes idle keep-alives and edge-held SSE streams at an event boundary (`closeAllHeld`), and waits up to 30 s for in-flight requests, counting those cut, as today; |
| +- the 3-minute self-exit after step 3 stays. |
| + |
| +After step 2 the NLB sends no new flows, so what still arrives is hops from other edges and direct clients, which the hub can serve: fleet traffic does not depend on the tenant units that stop next. Requests for the hub's own tenants (the console, home-box apps) that arrive during the tenant stop get today's answer for a stopping host; those hosts are single-box and down for the restart anyway. W6's guarantee for NLB flows is unchanged, and a late NLB flow is now served rather than refused. |
| + |
| +### 3.3 S1: fleet rows ignore tenant admission, locally and in the edges file |
| + |
| +Two halves, both needed (R1-1): |
| +- **Local.** `fixedAdmission.exempt` (`internal/host/group_admission.go:100`) returns true for a row the fleet arm serves on a hub: a forward row or a replica-set row (`FleetBoxes != ""`) that `FleetServeEligible` accepts. Group members never take it (`a.group` stays authoritative). |
| +- **Published.** The edges file gains a box-level field, `fleet_serving: true`, written by a hub whose fleet state is loaded (§4.4: for the console's box, from its first Reload). A fleet claim's eligibility is `fleet_serving && addr != ""`, **not** `HomeEligible()`. `HomeEligible` stays the rule for every other claim, so ordinary tenants keep their admission. The booting write that admission already makes (`RolePublished`) carries `fleet_serving`, so a restarting hub's fleet names stay eligible throughout. |
| |
| -To shorten the replica wait, a copy whose channel registered in the warm-up window rises on its **first** passing probe instead of two. A fresh channel and a passing probe are both positive proof the copy answers now; the second probe guards against flapping, which a new process has no history of. Outside the window the rise stays at two. |
| +Why it is safe: tenant admission protects lease acquisition, local wakes and placement on a box that has not finished its first reconcile. A fleet row has none of these. Its readiness inputs are the routing map and fleet credentials, loaded before the listeners bind (`edge.go:4947,5314-5341`), and the tunnel, which S2 waits for. |
| |
| -Bounds (builder may tune the values, not the shapes): |
| +Test: the real path from the hub's edges-file writer through a sender's home map to a request, during startup, with admission closed. |
| + |
| +### 3.4 S2: the hub waits for a tunnel and a copy instead of refusing |
| + |
| +A **warm-up window** starts when the edge starts serving and lasts 60 s. In it, a request the fleet arm would answer "no connected box" or "no healthy copy" is **held**, at the front of the fleet arm, before any body preparation (R1-10: `replicaReplayableBody`, `replicaproxy.go:96`, reads known-length bodies up to 64 KiB, so the wait must come first): |
| +- it waits for the fleet's channel to register (forward row) or a copy to rise (replica-set row), or the bound; |
| +- the hub reads none of its body while it waits; |
| +- then it is served by a fresh selection: a new prober snapshot, then body preparation as today. At the bound it gets today's 503 `Retry-After: 2`. |
| + |
| +A copy whose channel registered inside the window rises on its **first** passing probe instead of two. A fresh channel and a passing probe both prove the copy answers now; the second probe guards against flapping, and a new process has no history of it. Outside the window the rise stays at two. |
| |
| | Bound | Value | When exceeded | |
| |---|---|---| |
| -| Hold per request | 10 s | today's 503 `Retry-After: 2` | |
| +| Hold per request | 10 s, or the hop's remaining header time less 2 s if shorter | today's 503 `Retry-After: 2` | |
| | Held per host | 64 | the new request gets today's answer | |
| | Held per hub | 1,024 | the same | |
| -| Warm-up window | 60 s from first serve | no holds; today's behaviour | |
| +| Warm-up window | 60 s from first serve | no holds | |
| |
| -Holds are one place: a `fleetWarmHold` call in front of `fleetProxy` (`edge.go:4289`) and the replica transport's no-copy branch. Registration (`tunnel.go:326`) and the prober's rise signal a condition variable per fleet. A fleet box that is really gone costs a request at most 10 s once per restart, then today's answer. |
| +One place: `fleetWarmHold`, called first in `fleetProxy` (`edge.go:4289`) and in the replica arm before `replicaReplayableBody`. Registration (`tunnel.go:326`) and the prober's rise signal a per-fleet condition. |
| |
| -### 3.4 S3: a sending edge holds a request while the hub restarts |
| +### 3.5 S3: a sending edge waits inside connection acquisition |
| |
| -On any edge, a backhaul whose dial to the destination fails **at connect** (refused, reset before the TLS handshake ends, or the 5 s dial timeout, `edge.go:4732-4745`) and for which `backhaulAlternative` finds no other claimant, is **held and re-dialled** instead of answered 502: |
| -- re-dial the same box after 250 ms, 500 ms, then every 1 s, for at most 15 s from the first failure; |
| -- the client's request body is not read while held (nothing was sent: the dial failed before any byte of the request left), so any method and any body may be held; this is not a replay and spends no forward attempt (`replay.go:34`, I4 unchanged); |
| -- each re-dial goes through the normal path: if the home map now names another claimant (Part 2), the hold ends and the request goes there; |
| -- at the bound, the answer is **503 `Retry-After: 5`** through `edge.Unavailable` with a new site name, `backhaul-unreachable`, instead of today's bare 502. |
| +R1-2: on a dial failure Go's transport closes the request body (`net/http/transport.go`, `req.closeBody()` on connection-acquisition failure), and re-entering `backhaulAttempt` spends an attempt (`backhaul_holder.go:209`). So the hold cannot be a retry of the request. It is a wait **inside the dial**: the backhaul transport's dialer itself retries, and the transport sees one connection or one final error. |
| |
| -This applies to every backhaul, not only to fleet names: any single-claimant name whose box refuses connections gets a pause of up to 15 s and then a retryable 503, where today it gets an instant bare 502. That is better for a dead fixed box's clients too, and it is how a non-hub fixed box's planned restart (leo) also stops costing hops. |
| +- The backhaul dialer, on a refused connection, a reset before the TLS handshake ends, or the 5 s dial or handshake timeout, does not return. It first asks the home map for another eligible claimant of the same name with the same owner, class and target (`backhaulAlternative`'s rule, `backhaul_retry.go:54-93`); if there is one, it dials that box. Otherwise it waits 250 ms, 500 ms, then 1 s between tries, and re-dials. |
| +- It gives up at the **sender hold bound, 20 s** from the first failure, or when the request's context ends. Only then does the transport see an error, and the answer is **503 `Retry-After: 5`** through `edge.Unavailable` with a new site name, `backhaul-unreachable`, instead of today's bare 502. |
| +- The request is one attempt throughout: the attempt counter is untouched and I4 holds. No byte of the request has been written and the body has not been read, because the transport writes the request only on a connection it has. `Expect: 100-continue` is unaffected: the inbound server sends `100` only when the handler reads the body. |
| +- If the dialer switches to another box, the attempt's box, its suspect mark and its log name follow the box actually dialled. The hop signature binds the host, not the box (`mesh.go`), so it stays valid. |
| +- Bounds: 64 waiting per destination host, 1,024 per sending edge. Over a bound, the new request gets the 503 at once. Held counts are logged once per episode per destination. |
| |
| -Bounds: 64 held per destination host, 1,024 per sending edge, 15 s per request. Over a bound, the request gets the new 503 at once. The backhaul suspect mark (`backhaul_retry.go:11`) is still set on the first failure. It only steers the choice among alternatives, so a held request re-dials its box whether or not it is suspect. The builder logs held counts per destination once per hold episode, not per request. |
| +This applies to every backhaul, not only fleet names. A single-claimant name whose box refuses connections now gets a wait of up to 20 s and then a retryable 503, instead of an instant bare 502 (Q2). A fixed box's planned restart (leo) also stops costing hops. |
| |
| -### 3.5 S4: the hub's own listener survives the restart (socket handoff) |
| +Tests: slow, chunked and `Expect: 100-continue` POSTs held across a refused period, delivered once with the body intact; a cancelled client mid-hold; an alternative appearing mid-hold; a box that never returns gives the 503 at 20 s; a connection that succeeded and then failed is not held (today's rules). |
| |
| -S3 covers traffic from other edges, and W6 covers NLB traffic. A client whose DNS points straight at the hub's address (Tito today: no NLB) still meets a closed listener. S4 closes that: |
| +### 3.6 S4: the hub's own listener survives the restart (socket handoff) |
| |
| -- A new unit, `carlos-edge.socket`, owns `:80` and `:443` (`ListenStream=`, `FileDescriptorName=http`/`https`, `Service=carlos-edge.service`). The edge takes its listeners from systemd (`LISTEN_FDS`, by name) when they are present and binds itself otherwise, so a box without the socket unit is unchanged. |
| -- During a restart the sockets stay open in systemd. New connections complete the TCP handshake in the kernel and wait in the accept queue, and the new process accepts them. Clients see a pause, not a refusal. |
| -- On SIGTERM the old process stops accepting and, before the 10 s in-flight wait, closes edge-held SSE streams at an event boundary (`closeAllHeld`, as W6 step 3 does), so a long stream no longer pins the wait at 10 s. |
| -- W6 still works: `CloseIngress` closes the process's own copy of the listener; systemd's stays open. A late NLB flow now queues for the new process instead of being refused. |
| -- PPv2 wraps the inherited listener the same way it wraps a bound one. |
| +S0 and S3 cover traffic from other edges and the NLB. A client whose DNS points straight at the hub (Tito today: no NLB) still meets a closed listener between SIGTERM and the new process's bind, about 12 s on Tito. S4 closes that. |
| |
| -**Rollback across S4 is the risk.** A binary below the S4 floor binds `:443` itself and fails while the socket unit holds it. So the socket unit is installed and enabled only by a root `apply` of a release at or above the floor, and `rollback` to a release below the floor first stops and disables the socket unit, then swaps the binary, in one root verb. The floor goes in `release` beside the other floors. The accept backlog is raised to 4,096 (`Backlog=`), so about 15 s of arrivals at a few hundred per second fit. |
| +- **Two socket units** (R1-11: `FileDescriptorName=` names every descriptor of one unit): `carlos-edge-http.socket` (`ListenStream=80`, `FileDescriptorName=http`) and `carlos-edge-https.socket` (`ListenStream=443`, `FileDescriptorName=https`), each `Service=carlos-edge.service`, `Backlog=4096`. The edge takes its two listeners from `LISTEN_FDS` by name when present, and binds itself otherwise, so a box without the units is unchanged (`edge.go:5196`). |
| +- During a restart the sockets stay open in systemd. New connections complete the TCP handshake in the kernel and wait in the accept queue for the new process. Clients see a pause. |
| +- On SIGTERM the old process stops accepting and closes edge-held SSE streams at an event boundary **before** the 10 s in-flight wait, so a long stream no longer holds the wait at 10 s. |
| +- **The queue does not shorten the agent's own shutdown** (R1-3): duties and the activator still have their 90 s budget. A queued connection waits through it; a sender's TLS handshake times out at 5 s and S3's dialer re-dials. The pause is T, and the guarantee in §3.1 states the budget, not a promise that shutdown is short. |
| +- W6 (S0 applies on a hub, so `CloseIngress` does not close listeners there; on a non-hub fixed box it closes the process's copy and systemd's stays open, so a late NLB flow queues). |
| +- PPv2 wraps an inherited listener the same way it wraps a bound one. |
| +- **Rollback.** A binary below the S4 floor binds `:443` itself and fails while a socket unit holds it. So the root installs and enables the socket units only when it applies a release at or above the floor, and `rollback` to a release below the floor stops and disables both socket units first, then swaps the binary, in the one root verb. The floor goes in `release` beside the other floors. |
| +- **Tests on real systemd** (the root runner): first activation, restart under load, rollback below the floor, and the two named descriptors. |
| |
| -S4 is the largest piece of Part 1 and only matters where clients reach the hub directly. It is listed separately in the estimate (§5) so Paul can take Part 1 without it; Tito would then put an NLB (#908's draft carlos-infrastructure #58) or the UK edge in front of fleet app names. |
| +S4 is the largest piece of Part 1 and matters only where clients reach the hub directly. It is listed separately in §5 so Paul can take Part 1 without it; Tito would then put its fleet app names on its NLB (#908's draft carlos-infrastructure #58) or the UK edge. |
| |
| -### 3.6 Request budget |
| +### 3.7 Request budget |
| |
| -No new store requests: S1 to S4 are memory and process changes. S3's re-dials go to the box, not to S3. Steady state per box per day with nothing changing: **0 additional requests.** A store-call counting test covers the hold paths (they must read nothing). |
| +No new store requests: S0 to S4 are memory, process and unit changes. S3's re-dials go to boxes, not to S3. Steady state per box per day with nothing changing: **0 additional requests.** A store-call counting test covers the hold paths. |
| |
| -### 3.7 Tests |
| +### 3.8 Tests |
| |
| -- S1: a fixed-admission hub before admission opens serves a forward row and a replica-set row; a group member still refuses; a hibernating ordinary tenant row on the hub still gets 503. |
| -- S2: a request arriving before the channel registers is served once it registers; one at the bound gets 503 `Retry-After: 2`; caps; no body read while held; the warm-up rise of one probe; outside the window two probes. |
| -- S3: refused dial then success within the bound serves the request once, POST included, body intact; a box that never comes back gives 503 `Retry-After: 5` at 15 s; a dial that connected and then failed is not held (today's rules); caps; a new claimant appearing mid-hold ends the hold there; the attempt counter is untouched. |
| -- S4: inherited listeners by name; fallback to binding; restart under load with an in-process fake systemd (pass fds to a child); rollback below the floor removes the socket unit first; `TestExecSandbox…` binary-size guard still passes. |
| -- `unavailable_guard_test.go` gains the two site names. |
| +- S0: a hub's W6 drain keeps accepting and serves a hop arriving during the 30 s wait; a non-hub fixed box still closes. |
| +- S1: as in §3.3; a group member still refuses; an ordinary tenant row on a booting hub still gets 503 and stays ineligible to senders. |
| +- S2: served on registration; the bound; caps; no body read while held (a POST whose body is blocked until a copy rises); the one-probe warm-up rise; two probes outside the window. |
| +- S3 and S4: as in §3.5 and §3.6. |
| +- `unavailable_guard_test.go` gains the new site names. |
| |
| -### 3.8 Dev witness (after a release, in a booked window on #421) |
| +### 3.9 Dev witness (after a release, in a booked window on #421) |
| |
| -Probes from an in-region host, one address only (RELEASE-ROLL-CARD rule), at about 20 requests a second each, against a fleet app on dev (a replica-set app with two copies and a forward-row app): |
| -- **P1** through leo's edge (another edge, backhaul); |
| -- **P2** through the IE NLB (W6 armed on sophie); |
| +Probes from an in-region host, one address only (RELEASE-ROLL-CARD rule), about 20 requests a second each, against a fleet app on dev with two copies and against a forward-row app: |
| +- **P1** through leo's edge (backhaul); |
| +- **P2** through the IE NLB; |
| - **P3** straight at sophie's EIP (only with S4). |
| |
| -Restart sophie's edge three times. Pass: 0 non-2xx, 0 timeouts, longest request under 15 s, median pause under 5 s, and every POST landed exactly once. Control run first on the old release to put a number on today's gap for each probe. Then Tito repeats P1 and P3 on staging before production. |
| +First a control on the current release, three restarts of sophie's edge, to count today's gap per probe. Then the same on the Part 1 release. Pass: 0 non-2xx, 0 timeouts, longest request under 10 s on dev, every POST landed exactly once. Tito repeats P1 and P3 on staging before production. |
| |
| -### 3.9 Floor and rollout |
| +### 3.10 Floor and rollout |
| |
| -S1 and S2 are hub-local: they act when the hub runs the release. S3 acts on each sending edge as it gets the release. Order: dev boxes, dev console, witness, flagship, Tito staging, Tito production (Tito rolls its own). No host.env changes, except S4's socket unit, which the root installs itself. |
| +S0, S1 and S2 act when the hub runs the release; S1's published half acts on senders that read `fleet_serving`, so senders roll first. S3 acts on each sending edge as it gets the release. Order: dev boxes, dev console box (the hub), witness, flagship, Tito staging, Tito production (Tito rolls its own). No host.env changes; S4's units are installed by the root. |
| |
| ## 4. Part 2: more than one hub per region |
| |
| ### 4.1 The model |
| |
| -A region has a **hub set**: two or more boxes, each a hub by today's definition (`CARLOS_TUNNEL_HOST` set, `CARLOS_FLEET` unset). Every fleet box keeps **one tunnel to every hub** in its home region. Every hub serves every fleet's forward and replica-set rows over its own tunnels, and publishes those names in its edges file. A sending edge picks any eligible hub and falls over to another on a connect failure, through the alternative lookup it already has. |
| +A region has a **hub set**: two or more boxes, each a hub by today's definition. Every fleet box at the Part 2 floor keeps **one tunnel to every hub** in its home region. A hub publishes a fleet name only while it can serve it over its own tunnels, and senders choose among the hubs that publish it. So no tunnel or route has a single owner to fail over: losing a hub removes one of several equal paths. |
| |
| -So no tunnel or route has a single owner to fail over. Losing a hub, planned or not, removes one of several equal paths. |
| - |
| -Rejected alternatives: |
| -- **One tunnel per box, failing over between hubs.** Which hub holds a box's tunnel would have to be published, and every sender would learn it late. The publication lag is the outage. |
| -- **Non-hub edges dialling fleet boxes directly.** Fleet boxes accept no inbound connections, by design (#53). |
| -- **Hubs behind the NLB for tunnels.** The NLB picks the target per flow, so a box cannot choose to reach each hub once. |
| +Rejected: |
| +- **One tunnel per box, failing over between hubs:** the publication lag of "which hub has the box now" is the outage. |
| +- **Non-hub edges dialling fleet boxes directly:** fleet boxes accept no inbound connections (#53). |
| +- **Hubs behind the NLB for tunnels:** the NLB picks the target per flow, so a box cannot reach each hub once. |
| +- **A hub forwarding a hop to another hub** (rev 1 §4.6): a hop cannot be forwarded again under I4 (R1-6). Per-channel claims (§4.5) make it unnecessary. |
| |
| ### 4.2 Which boxes are hubs |
| |
| -v1: the hub set is the region's **fixed boxes with elastic IPs** that the operator names. On dev that is sophie and leo; for Tito, the IE home box plus one new small box in IE in another AZ. Group members are not hubs in v1: their public addresses are not stable, and a group member's edge restarts on every roll. |
| +v1: fixed boxes with elastic IPs that the operator names. On dev, sophie and leo; for Tito, the IE home box plus one new small box in IE in another AZ. Group members are not hubs in v1: their public addresses are not stable. |
| |
| -A hub that is not the console's box must not run tenants: it serves fleet traffic and nothing else that needs a lease. It is set up with `CARLOS_POOLS=@none`, a new reserved token that serves no pool (`provision.ParseBoxPools`, `internal/provision/reconcile.go:3523`), so it adopts no tenant record in a flat or nested region. This works without region HA, so Tito's flat production can have two hubs before any HA migration. |
| +A hub that is not the console's box runs no tenants. It is set up with `CARLOS_POOLS=@none`, a new reserved token that serves no pool (`provision.ParseBoxPools`, `internal/provision/reconcile.go:3523`), so it adopts no tenant record, flat or nested. This works without region HA, so Tito's flat production can have two hubs before any HA migration. |
| |
| ### 4.3 Fleet boxes reach every hub |
| |
| -- The tunnel hostname resolves to the address of every hub. That record is operator DNS today (no code here writes it; `infra/remote-host.md:59-62`). The operator adds one A record per hub. |
| +- The tunnel hostname resolves to every hub's address. That record is operator DNS (no code here writes it; `infra/remote-host.md`). The operator adds one A record per hub. |
| - The box resolves the name on each dial pass and runs **one `tunnelclient.Loop` per address**, each with today's backoff and handshake bounds, TLS server name = the tunnel hostname. Every hub holds that certificate through the shared certificate mirror. |
| -- The hub's `101` answer adds `Carlos-Hub: <box ref>`. The box keys its loops by hub ref, so two addresses of one hub collapse to one tunnel, and a hub that moved address is not dialled twice. |
| -- The box re-resolves every 60 s while connected, so a hub added or removed in DNS is picked up within a minute plus the record's TTL. A loop whose address left DNS ends after its connection ends. |
| -- The box's status reports each hub's state; "connected" means at least one hub, "degraded" means some but not all. |
| -- **Capacity:** each hub enforces its upgrade cap (128 per channel) on its own tunnel, so a box may carry up to 128 upgrades per hub. The box's HTTP/2 stream limits apply per tunnel connection, unchanged. |
| +- The hub's `101` answer adds `Carlos-Hub: <box ref>`. The box keys its loops by hub ref, so two addresses of one hub collapse to one tunnel. |
| +- The box re-resolves every 60 s, so a hub added or removed in DNS is picked up within a minute plus the record's TTL. A loop whose address left DNS ends with its connection. |
| +- The box's status reports each hub; "degraded" means some hubs but not all. |
| +- Each hub enforces its own upgrade cap (128 per channel), so a box may carry up to 128 upgrades per hub. |
| + |
| +A fleet box below the floor keeps one tunnel, to whichever address DNS gave it. Only that hub publishes its names (§4.5), so senders reach it there. |
| + |
| +### 4.4 Every hub has the fleet state, signed and leased |
| |
| -A fleet box below the Part 2 floor keeps one tunnel to whichever address DNS gave it. §4.6's hub-to-hub hop keeps it reachable from every hub. |
| +The fleet state a hub needs lives today only in the console box's registry, written by the console (`internal/console/fleets.go:258`, `hostsused.go:386-435`, `managedhistory.go:111`): the fleets table, fleet boxes with the sha256 of each bearer token (the credential set for `SetDynamicAuth` and the store door), and replica assignments. Forward rows are already derived on any hub by its bindings pass (`internal/host/fleetbind.go`). |
| |
| -### 4.4 Every hub has the fleet state |
| +**The hub view.** After every committed change to those tables, the console publishes `control/fleet-hub/view.json` under a new change-index scope. It holds, per fleet: owner, the active boxes with label and token hash, and each replica host's assignment, plus a monotonic revision and a timestamp. Every hub that is not the console's box folds it into its registry, as the only writer of those tables there. |
| |
| -Today the fleet state a hub needs lives only in the console box's registry, written by the console (`internal/console/fleets.go:258`, `hostsused.go:386-435`, `managedhistory.go:111`): |
| -- the fleets table (name to owning account); |
| -- fleet boxes and the sha256 of each bearer token (`internal/registry/fleets.go`), which become `SetDynamicAuth`'s credential set; |
| -- replica assignments (the box set of each replica-set row). |
| +- **Authority is a signature, not a storage path** (R1-5). Box roles can write deployment-wide objects (`infra/modules/region-host/main.tf:184`), and legacy direct-S3 fleet credentials exist (`internal/edge/replicaconsole.go:25`), so the object's location proves nothing. The console signs the view with an Ed25519 key that only the console holds (in its secrets, beside its other keys). Each extra hub carries the public half in host.env, `CARLOS_FLEET_HUB_VIEW_KEY`. A hub folds only a view whose signature verifies and whose revision is higher than the last it folded; anything else is logged and ignored. |
| +- **Token hashes in the store** are sha256 of 256-bit random tokens. They cannot be reversed; the plaintext never leaves the console's mint. |
| +- **The lease** (R1-4, R1-8). A hub's fleet credentials are valid only while its view is **fresh**: within 5 minutes of a successful check that the view's change-index generation is the one it has folded. The box already reads the change index on every pass (`internal/host/changeindex.go`); a successful read with an unchanged generation renews freshness, and a changed generation renews it once the new view is folded. A failed read does not. When a hub's view is stale, it removes every fleet credential (registrations and store-door access), closes every fleet tunnel, and publishes no fleet names, until a check succeeds. Fleet traffic then goes to the other hubs. |
| +- **Revocation.** When the console removes or rotates a fleet box's credential, it updates its own table, publishes the new view, then sends a signed `/.carlos/fleet-revoke` hop (mesh key, bound to method, path, body and time, as `/.carlos/ha-take` is) to every hub in its edges view. A hub applies it atomically under the tunnel hub's lock: it removes the credential from the table that registration **and** the store door authenticate against (`tunnel.go:473`), records the revision, and only then closes the matching tunnel (`tunnel.go:624`). A later fold of an older view cannot restore it. The console's command reports "revoked on every hub" when all have acknowledged; otherwise it names the hubs that did not, and the time by which their lease ends. |
| |
| -Forward rows themselves are already derived on the hub by its bindings pass from `fleets/<fleet>/` bindings (`internal/host/fleetbind.go`). Every hub runs that pass, since every hub is `HubArmed`. |
| +**H-1:** once the console's revoke returns, no acknowledged hub admits the credential, and no other hub admits it after its lease ends (at most 5 minutes after it last saw the old generation). |
| |
| -**The hub view.** The console publishes one object, `control/fleet-hub/view.json`, after every committed change to those three tables, under a new change-index scope (`release.ChangeScope`). It holds, per fleet: owner, the active boxes with label and token hash, and each replica host's assignment, plus a revision. Every hub that is not the console box folds it into its own registry: it is the only writer of those tables there. The console's box keeps reading its own tables, which are the source. |
| +### 4.5 Hubs publish only what they can serve |
| |
| -- **Who may write it:** only the console. It is outside every fleet-writable prefix (`fleets/<fleet>/`), so no fleet box can write it through the store door (`internal/edge/storedoor.go:711,824`). A hub never reads fleet state from a fleet-writable key (the census rule). |
| -- **Token hashes in the store:** they are sha256 of 256-bit random tokens, which cannot be reversed. The plaintext never leaves the console's mint. |
| -- **Revocation** must not wait for a fold. When the console removes or rotates a fleet box's credential, it also sends a signed `/.carlos/fleet-revoke` hop (mesh key, bound to method, path, body and time, as `/.carlos/ha-take` is) to every hub in the edges view. A hub applies it at once (`TunnelHub.CloseChannel`) and records the revision, so a later fold of an older view cannot restore the credential. A hub that cannot be reached gets the revocation at its next fold, and the console logs the unreached hubs. A hub that has not completed a fold in 10 minutes refuses **new** registrations (existing tunnels stay) until it does; a stale hub then fails closed for new credentials rather than admitting a revoked one. |
| -- **Fresh hub:** it serves fleet rows only after its first fold succeeds. Until then it publishes no fleet names, so no sender picks it. |
| +Each hub's edges file publishes a fleet name only while it can serve it over its own tunnels: |
| +- a forward row: when the row's bound box (or, unlabelled, any box of the fleet) is connected to this hub; |
| +- a replica-set row: when at least one assigned copy's box is connected to this hub. |
| |
| -### 4.5 Every hub publishes fleet names, and senders choose |
| +Fleet claims are unstamped, like a static site's (`homemap.go:1140-1146`: unstamped duplicates are normal), with S1's `fleet_serving` eligibility. Name authority already accepts several claimants of a name with the same owner, class and target, and `backhaulAlternative` picks another eligible claimant (`backhaul_retry.go:54-93`). Among eligible hubs a sender prefers its own region and AZ, then spreads by a rendezvous hash of the host, so one hub's restart moves only its share. |
| |
| -Each hub's edges file publishes the fleet names it serves, as the single hub does today. The name-authority resolution already accepts several claimants of one name with the same owner, class and target (`internal/edgesfile/nameauthority.go`, `homemap.go:1140-1146`: unstamped duplicates are normal), and `backhaulAlternative` (`backhaul_retry.go:54-93`) already picks another eligible claimant after a connect failure. Part 2 relies on both and adds: |
| -- hubs publish fleet names **unstamped**, like a static site, so two hubs never tie on a stamp; |
| -- among eligible hub claimants, a sender prefers a hub in its own region and AZ, then any hub, and spreads by rendezvous hash of the host over the eligible hubs, so one hub's restart moves only its share; |
| -- S3's hold (§3.4) is what covers the moment between a hub going away and the sender's home map noticing; with a second claimant the first re-dial already goes there. |
| +A sender's view lags a hub's file by up to the home map's poll (30 s, plus a change-watch). Two stale cases: |
| +- **The hub went away:** S3's dialer moves to the other claimant at the first refused connection. |
| +- **The hub is up but no longer has the box's tunnel:** it answers as §25 does for a moving host. A replayable first attempt (`X-Carlos-Replayable: 1`, body empty or copied whole up to 64 KiB, H2/H3) gets 503 with `X-Carlos-Handover: holder=<hub ref>` naming a hub whose current file lists the box connected, and the sender sends its second and last attempt there (`internal/edge/handover.go:44`). Any other request is held at that hub for up to 10 s for the tunnel to return (S2's hold), then gets today's 503 `Retry-After: 2`. |
| |
| -The builder confirms with a table test that two hubs' claims on one fleet name resolve to `NameDialable` with both eligible, and that withdrawing one hub's file leaves the other serving. |
| +A request that reached a hub **from a client** (the NLB or DNS), for a name the hub publishes but cannot serve at that moment, is that hub's first forward: it may send it once to a hub that can, by ordinary backhaul. A hop is never forwarded again (I4). |
| |
| -### 4.6 A hub without the box's tunnel forwards once |
| +The builder confirms with a table test that two hubs' fleet claims resolve `NameDialable` with both eligible, that a hub that loses the box's tunnel drops the name on its next write, and that withdrawing one hub's file leaves the other serving. |
| |
| -A request can reach hub B while the fleet box has no tunnel to B (B just started, the box is below the floor, or the box's tunnel to B is mid-reconnect). Then B sends it **once** to a peer hub over the ordinary signed backhaul, choosing a hub whose edges file lists the box's channel as connected (a new edges field, `fleet_channels`, the set of connected `<fleet>/<label>` names, refreshed on the edges file's normal cadence). Rules: |
| -- I4 holds: a hub never forwards a request it received as a hop, and this is the request's one forward; |
| -- the body is streamed, not copied; the forward is made only after B's own S2 hold (if in warm-up) ends without a channel; |
| -- if no peer lists the channel, today's 503 `Retry-After: 2`. |
| +### 4.6 Replica routing with several hubs |
| |
| -### 4.7 Replica routing with several hubs |
| +Each hub runs its own replica prober over its own tunnels and its own round robin (`replicaprober.go`, `replicaproxy.go`). Copies see one probe a second per hub (tunnel traffic, no store requests). GET and HEAD retries stay within one hub. Placement and assignment stay the console's; extra hubs read the assignment from the view. |
| |
| -Each hub runs its own replica prober over its own tunnels and its own round robin (`replicaprober.go`, `replicaproxy.go`). Copies see N times the probe traffic (one probe a second per copy per hub; tunnel traffic, no store requests). GET and HEAD retries stay within one hub. Placement and assignment stay the console's; hubs read the assignment from the hub view. |
| +### 4.7 The control doors fleet boxes use |
| |
| -### 4.8 The control doors fleet boxes use |
| +- **The store door** (`internal/edge/storedoor.go`) is served by any hub with its own role and holds no state; it authenticates against the leased credential table (§4.4). |
| +- **The replica coordinator door** (R1-7). The console's box proxies it to its loopback console (`CARLOS_REPLICA_CONSOLE_ADDR`, which accepts only a literal loopback address, `replicaconsole.go:52`, and speaks plain HTTP to it, `:134`). An extra hub does not proxy to the console itself. It relays the call to the **console box's edge** over the ordinary signed backhaul (TLS, mesh-signed hop to that box's address), and that edge applies its own coordinator door and loopback proxy as today. The loopback rule and its guarantees are unchanged; the fleet box's bearer token only ever travels inside TLS. |
| +- **Interactive sessions and other console doors** stay on the console's box, relayed the same way where a fleet box calls them through the tunnel host. |
| |
| -- **The store door** (`internal/edge/storedoor.go`) is served by any hub with its own role; it holds no state. A fleet box uses the hub its call happens to reach. |
| -- **The replica coordinator door** proxies to the console (`CARLOS_REPLICA_CONSOLE_ADDR=127.0.0.1:8090` on the console's box). A hub that is not the console's box sets it to the console box's private address (same region), so coordinator calls work from every hub. When the console is down, coordinator calls fail on every hub, as they do today; serving does not depend on them. |
| -- **Interactive sessions and other console doors** stay on the console's box. |
| +When the console's box is down, coordinator calls fail on every hub, as today; serving does not depend on them. |
| |
| -### 4.9 Planned and unplanned hub loss |
| +### 4.8 Planned and unplanned hub loss |
| |
| -- **Planned restart of one hub:** Part 1 applies to it, and senders mostly do not notice: at the first refused dial the alternative is the other hub. Its tunnels end at exit, and fleet boxes keep serving through the others; each box re-dials the restarted hub with today's backoff. |
| -- **Hub death:** senders mark it suspect on the first connect failure and use the other hub for 60 s at a time (`backhaul_retry.go:11`); its edges file goes stale and it drops out of the claim set on the normal age rule. A hung hub (accepts, never answers) costs requests already sent to it up to the 30 s header timeout, as any hung box does today; that is not new. |
| -- **The console's box dies:** fleet apps keep serving through the other hubs. The control plane (deploys, scaling, the coordinator, revocations by fold) waits for the console. Console HA is region HA G6's pool console path, not this spec. |
| +- **Planned restart of one hub:** Part 1 applies to it, and most senders do not notice: at the first refused connection S3's dialer moves to another claimant. Its tunnels end at exit; fleet boxes keep serving through the others and re-dial it with today's backoff. |
| +- **Hub death:** senders move away at the first refused connection and mark it suspect for 60 s at a time (`backhaul_retry.go:11`). Its edges file ages out of the claim set by the normal rule. A hung hub (accepts, never answers) costs requests already sent to it up to the 30 s header timeout, as any hung box does today. |
| +- **The console's box dies:** fleet apps keep serving through the other hubs, whose leases stay fresh as long as they can read the store. The control plane (deploys, scaling, the coordinator, new fleet boxes) waits for the console. Console HA is region HA G6's pool console path, not this spec. |
| |
| -### 4.10 What this gives #908 |
| +### 4.9 What this gives #908 |
| |
| | #908 ask | After Part 2 | |
| |---|---| |
| | 1. The console and the home box's apps on more than one box | **Not covered.** Console HA is G6. Home-box apps (Tito Go) stay single-box until the existing-host migration slice (region HA N-HA7). | |
| | 2. Existing hosts and fleet traffic entering through any box | Fleet traffic: yes, through any edge and any hub, surviving one hub's loss. Existing placed hosts already enter through any edge by backhaul; their home box stays their single point. | |
| -| 3. Migration path for a flat home region | Part 2 needs no HA migration: add one fixed box with `CARLOS_POOLS=@none`, give it `CARLOS_TUNNEL_HOST`, add its A record. No moves or imports are refused while it runs. | |
| -| 4. DNS on the NLB | Unchanged guidance: hairpin redirect A21 covers a box reaching its own region's NLB. Part 2 does not need fleet app names on the NLB; any edge works. | |
| +| 3. Migration path for a flat home region | Part 2 needs no HA migration: add one fixed box with `CARLOS_POOLS=@none`, `CARLOS_TUNNEL_HOST` and `CARLOS_FLEET_HUB_VIEW_KEY`, then its A record. No moves or imports are refused while it runs. | |
| +| 4. DNS on the NLB | Unchanged: the hairpin redirect (region HA A21) covers a box reaching its own NLB. Part 2 does not need fleet app names on the NLB. | |
| |
| -### 4.11 Request budget |
| +### 4.10 Request budget |
| |
| -Per hub that is not the console's box, steady state with nothing changing: |
| -- the hub view: one generation check rides the existing change-index read; one GET per change; the 30-minute backstop is 48 conditional GETs a day; |
| -- the bindings pass: as on today's hub, scoped by the change index (already budgeted under #336), so N hubs cost N times it. |
| +Per extra hub, steady state with nothing changing: |
| +- **The hub view:** freshness rides the change-index read the box already makes; one GET per change; no timer of its own. About **0 to 10 requests a day**. |
| +- **The fleet bindings pass** (R1-9): today it runs every 5 to 6 minutes, ungated (`internal/host/agent.go:4673`): one LIST of `fleets/`, one LIST per fleet, one GET per binding (`fleetbind.go:269`). That is 288 × (1 + F + B) a day for F fleets and B bindings, about 860 for one fleet with one binding, and it already costs that on today's single hub. Part 2 would multiply it by the number of hubs, so Part 2 first puts it behind a change-index scope that every binding write bumps (the store door's writes go through the hub's store wrapper, which bumps the index; the builder confirms, or adds the bump), with the 30-minute backstop. After that: about 48 × (1 + F + B) a day per hub, about **150 for one fleet with one binding**. |
| |
| -The console's publish is one PUT per committed change (fleet and box changes are rare). Probes and tunnels make no store requests. Total: about **50 requests per extra hub per day** idle. A store-call counting test pins the fold. |
| +A store-call counting test runs an idle extra hub for a simulated day and pins both. |
| |
| -### 4.12 Tests |
| +### 4.11 Tests |
| |
| -- Seeded simulation of two or three hubs and several fleet boxes under restarts, deaths, revocations and folds, with invariants: (H-1) no revoked credential is ever admitted after the console's revoke returned, unless that hub was unreached and is then refusing new registrations; (H-2) a request is forwarded at most once between hubs and at most twice overall; (H-3) with one hub down and one fleet box connected to the other, every request is served. Each has a mutation that must fail the sweep. |
| -- Tunnel client: one loop per resolved address, dedupe by `Carlos-Hub`, a removed address's loop ends, DNS changes within the re-resolve. |
| -- Edges: two hubs' unstamped claims resolve with both eligible; sender preference and spread. |
| -- Hub view: console-only writer, fold, stale-fold refusal of new registrations, revision ordering against a revoke hop. |
| +- Seeded simulation of two or three hubs and several fleet boxes under restarts, deaths, store outages, revocations and folds. Invariants, each with a mutation that must fail the sweep: |
| + - **H-1** as in §4.4; |
| + - **H-2** a request is forwarded at most twice overall, and never after arriving as a hop; |
| + - **H-3** with one hub down, every request for a fleet whose box is connected to a live hub is served within the hold budget. |
| +- Tunnel client: one loop per resolved address, dedupe by `Carlos-Hub`, DNS changes picked up. |
| +- Edges: per-channel publication, unstamped claims, sender preference and spread, the handover answer from a hub that lost the tunnel. |
| +- Hub view: an unsigned, wrongly signed or lower-revision view is refused; the lease expires on failed reads and renews on unchanged generations; a revoke cannot be undone by an older fold; the store door refuses a revoked credential. |
| - `CARLOS_POOLS=@none` adopts no record. |
| -- Census card for the new key `control/fleet-hub/view.json` (writer: console; readers: hubs). |
| +- Census card for `control/fleet-hub/view.json` (writer: the console; readers: hubs, by signature). |
| |
| -### 4.13 Dev drill |
| +### 4.12 Dev drill |
| |
| -Add leo to dev's hub set. Probes as §3.8 P1 and P2. Pass: |
| -1. restart sophie's edge: 0 errors; |
| -2. restart leo's edge: 0 errors; |
| -3. stop sophie's EC2 instance (the console's box) under load: fleet apps serve through leo with 0 errors after at most one held pause; deploys wait; start it again; |
| -4. revoke a throwaway fleet box's credential while sophie is reachable: both hubs drop its tunnel within 2 s; |
| -5. a pre-floor fleet box (one tunnel) stays reachable through both hubs. |
| +Add leo to dev's hub set. Probes as §3.9 P1 and P2. Pass: |
| +1. restart sophie's edge, then leo's: 0 errors; |
| +2. stop sophie's EC2 instance (the console's box) under load: fleet apps serve through leo with 0 errors after at most one held pause; deploys wait; start it again; |
| +3. revoke a throwaway fleet box's credential: both hubs drop its tunnel and refuse its store-door calls within 2 s; |
| +4. block leo's store access (a test-only deny) for 6 minutes: leo stops publishing fleet names and traffic stays on sophie with 0 errors; unblock, and leo returns; |
| +5. a pre-floor fleet box (one tunnel) stays reachable. |
| |
| -### 4.14 Rollout and floor |
| +### 4.13 Rollout and floor |
| |
| 1. Release with Part 2 on every box; inert until a second hub exists. |
| -2. Fleet boxes at the floor (they then dial every address). |
| -3. Operator: the second hub box (fixed, EIP, `CARLOS_POOLS=@none`, `CARLOS_TUNNEL_HOST`, `CARLOS_REPLICA_CONSOLE_ADDR`), then the A record. |
| +2. Fleet boxes reach the floor (they then dial every address). |
| +3. Console signing key minted; the second hub box (fixed, EIP, `CARLOS_POOLS=@none`, `CARLOS_TUNNEL_HOST`, `CARLOS_FLEET_HUB_VIEW_KEY`); then its A record. |
| 4. Dev drill, then flagship, then Tito staging, then Tito production. |
| |
| ## 5. Estimate |
| @@ -274,28 +298,46 @@ Rough, build only, Opus implementing with Astra reviewing, after approval: |
| |
| | Piece | Work | Notes | |
| |---|---|---| |
| -| Part 1 S1 admission exemption | ½ day | | |
| -| Part 1 S2 hub warm-up hold | 2 days | | |
| -| Part 1 S3 sender hold | 3 days | touches backhaul; §25/§7.5 boundary tests in CI | |
| -| Part 1 S4 socket handoff | 4 days | optional; root apply and rollback ordering | |
| +| S0 hub keeps accepting through W6 | 1 day | | |
| +| S1 admission exemption and `fleet_serving` | 2 days | sender-side eligibility, real-path test | |
| +| S2 hub warm-up hold | 2 days | | |
| +| S3 hold inside the backhaul dialer | 3 days | §25/§7.5 boundary tests in CI | |
| +| S4 socket handoff (optional) | 4 days | root apply and rollback ordering, real systemd | |
| | Part 1 dev witness and release | 2 days | one booked dev window | |
| -| **Part 1 total** | **about 1½ weeks** (1 week without S4) | | |
| -| Part 2 hub view and revoke hop | 4 days | census card | |
| -| Part 2 multi-hub tunnel client | 3 days | | |
| -| Part 2 edges claims, sender choice, hub hop | 4 days | | |
| -| Part 2 `@none`, coordinator door, simulation | 3 days | | |
| -| Part 2 infra (second hub module, DNS) and drill | 3 days | operator repos | |
| -| **Part 2 total** | **about 3½ weeks** | | |
| +| **Part 1 total** | **about 2 weeks** (1½ without S4) | | |
| +| Bindings pass behind the change index | 2 days | worth doing for today's single hub too | |
| +| Signed hub view, lease, revoke hop | 5 days | census card | |
| +| Multi-hub tunnel client | 3 days | | |
| +| Per-channel claims, sender choice, handover from a hub | 4 days | | |
| +| `@none`, coordinator relay, simulation | 4 days | | |
| +| Infra (second hub module, DNS) and drill | 3 days | operator repos | |
| +| **Part 2 total** | **about 4 weeks** | | |
| |
| -So Part 1 on dev about a week and a half after approval, Part 2 on dev about five weeks after approval. Both fit Tito's target of about two months before Classic and Pro cut over, with a margin of a few weeks for the release train and Tito's own rolls. |
| +Part 1 on dev about two weeks after approval; Part 2 on dev about six weeks after approval. Both fit Tito's target of about two months before Classic and Pro cut over, with a thin margin for the release train and Tito's own rolls. If the date is tight, Part 1 without S4 plus Tito's fleet app names on its NLB is the fastest relief. |
| |
| ## 6. Open questions for Paul |
| |
| -1. **S4 (socket handoff): build it, or require fleet app names to enter through an NLB or another edge?** Recommendation: build it. Tito has no NLB today, and a planned restart then needs nothing from the client's path. |
| -2. **S3 applies to every backhaul, not only fleet names.** A dead single-home box's clients then wait up to 15 s and get a retryable 503, instead of an instant 502. Recommendation: yes, everywhere. |
| -3. **Part 2's hub set is fixed boxes with EIPs.** For Tito that is one more small always-on box in IE (about $15 to $30 a month for a t4g.small or medium). Recommendation: yes; group members as hubs later, if ever. |
| -4. **Order:** Part 1 first, then Part 2, as written? Recommendation: yes. Part 1 is small, helps single-hub regions forever, and Part 2 relies on S3. |
| +1. **S4 (socket handoff): build it, or require fleet app names to enter through an NLB or another edge?** Recommendation: build it. Tito has no NLB today, and it removes Tito's 10 s in-flight wait from the gap. |
| +2. **S3 applies to every backhaul, not only fleet names.** A dead single-home box's clients then wait up to 20 s and get a retryable 503, instead of an instant 502. Recommendation: yes, everywhere. |
| +3. **Part 2's hub set is fixed boxes with EIPs.** For Tito that is one more small always-on box in IE (roughly $15 to $30 a month). Recommendation: yes; group members as hubs later, if ever. |
| +4. **Order:** Part 1 first, then Part 2. Recommendation: yes. Part 1 is small, helps single-hub regions for good, and Part 2 relies on S1 and S3. |
| |
| ## 7. Review record |
| |
| -Astra round 1: pending. |
| +### Astra round 1 (dfd46a8e, NOT READY): where each finding went |
| + |
| +| Finding | Sev | Disposition | Where | |
| +|---|---|---|---| |
| +| R1-1 S1 local only; senders still see a booting hub ineligible | P1 | Accepted: `fleet_serving` publication and fleet-claim eligibility separate from `HomeEligible`; real-path test. | §3.3 | |
| +| R1-2 a failed dial closes the body; re-entry spends an attempt | P1 | Accepted: the hold moved inside the backhaul dialer; one attempt, body untouched; slow/chunked/100-continue tests. | §3.5 | |
| +| R1-3 gap and guarantee omit shutdown work; listeners close before W6's wait | P1 | Accepted: §2 corrected (about a minute on dev); S0 keeps a hub accepting through W6; the guarantee is stated as a hold budget on T, with shared deadlines. | §2.1, §3.1, §3.2, §3.6 | |
| +| R1-4 revocation cannot satisfy H-1 | P1 | Accepted: atomic credential removal covering registration and the store door, then close; acknowledgements or a 5-minute lease; H-1 restated. | §4.4 | |
| +| R1-5 hub view authority not established | P1 | Accepted: console Ed25519 signature, public key in hub host.env, monotonic revision. | §4.4 | |
| +| R1-6 hub-to-hub forward breaks I4; pre-floor reachability | P1 | Accepted: hub-to-hub forward of hops removed; hubs publish only names they can serve; §25 handover answer for stale senders; a client-entered request may be forwarded once. | §4.1, §4.5 | |
| +| R1-7 coordinator address must be loopback | P2 | Accepted: extra hubs relay to the console box's edge over signed TLS backhaul; loopback rule unchanged. | §4.7 | |
| +| R1-8 freshness rule closes idle hubs | P2 | Accepted: an unchanged generation read renews freshness. | §4.4 | |
| +| R1-9 bindings scan ungated | P2 | Accepted: budgeted honestly; put behind a change-index scope first. | §4.10 | |
| +| R1-10 replica hold after body preparation | P2 | Accepted: hold before `replicaReplayableBody`, then reselect. | §3.4 | |
| +| R1-11 one socket unit cannot name two descriptors | P2 | Accepted: two socket units; tests on real systemd. | §3.6 | |
| + |
| +Astra round 2: pending. |