edge-roll-blip: tighten the design spec
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+100
−156
docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md+100 −156
CI failed — run details
diff --git a/docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md b/docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md| index 152cfa0ca..e84694215 100644 |
| --- a/docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md |
| +++ b/docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md |
| @@ -38,14 +38,10 @@ no `SO_REUSEPORT` anywhere in `internal/` or `cmd/`. The relay's UDP and TCP lis |
| ### 1.2 Listen-first (#281) and the admission latch |
| -The edge configures fully before it binds: |
| - |
| -- the cert mirror's synchronous refresh (`edge.go:3686`, up to 20 s, `certsync.go:423`); |
| -- the home map (`:3699`, 20 s, `homemap.go:125`); |
| -- the door (`:3712`); |
| -- the TLS chain (`tlsCfg.GetCertificate = getCert`, `:3793`). |
| - |
| -Only then does it serve (`:3814-3830`). #281 moved the agent's slow startup (sweep, layout |
| +The edge configures fully before it binds: the cert mirror's synchronous refresh |
| +(`edge.go:3686`, up to 20 s, `certsync.go:423`), the home map (`:3699`, 20 s, |
| +`homemap.go:125`), the door (`:3712`) and the TLS chain (`tlsCfg.GetCertificate = getCert`, |
| +`:3793`). Only then does it serve (`:3814-3830`). #281 moved the agent's slow startup (sweep, layout |
| recovery, moves, runs) into the background, because "the edge below must listen within the |
| update gate" (`agent.go:646-650`). That startup is behind the `started` latch, which `Ready` |
| closes (`agent.go:701`). Every activator-owned request waits on the latch in `awaitStartup` |
| @@ -67,21 +63,17 @@ both servers `Shutdown` with a 10 s drain (`edge.go:3835-3842`). |
| **Update.** `carlos-system-update.path` runs `carlos system apply` as root, from the binary |
| installed at that moment, which is the OLD one (`units/carlos-system-update.service:47`). |
| -`install` (`internal/host/systemapply.go:551`) then: |
| - |
| -1. stages both builds' unit sets with `bootstrap -root <dir> -plan-json` (`stagePlan`, |
| - `:1259`); |
| -2. journals `UnitsAdded`/`UnitsRemoved` (`:610`); |
| -3. renames the candidate over `/opt/carlos/carlos` (`:632`); |
| -4. runs `installUnits(newDir, UnitsRemoved)` (`:646`): `disable --now` for each removed |
| - unit (`:1388-1390`), copy, sysusers, tmpfiles, `daemon-reload` (`:1478`); |
| -5. restarts instance-control, then the edge (`:658`). `restartEdge` is `reset-failed` |
| - then `systemctl restart carlos-edge` (`:1490-1494`); |
| -6. runs the gate: within 20 s (`:59`) the edge must be active, answer |
| - `http://127.0.0.1/` under a 3 s client timeout (`:214-224`) and report the target. A |
| - soak follows, during which `NRestarts` must stay 0 (`:1569-1614`); |
| -7. `finish`, whose `arm` starts the new plan's `Armed` list (`:1728-1764`). `arm` already |
| - refuses to start the edge (`:1751`). |
| +`install` (`internal/host/systemapply.go:551`) then: (1) stages both builds' unit sets with |
| +`bootstrap -root <dir> -plan-json` (`stagePlan`, `:1259`); (2) journals |
| +`UnitsAdded`/`UnitsRemoved` (`:610`); (3) renames the candidate over `/opt/carlos/carlos` |
| +(`:632`); (4) runs `installUnits(newDir, UnitsRemoved)` (`:646`), which does `disable --now` |
| +for each removed unit (`:1388-1390`), copies, runs sysusers and tmpfiles, and |
| +`daemon-reload` (`:1478`); (5) restarts instance-control, then the edge (`:658`), where |
| +`restartEdge` is `reset-failed` then `systemctl restart carlos-edge` (`:1490-1494`); (6) |
| +gates: within 20 s (`:59`) the edge is active, answers `http://127.0.0.1/` under a 3 s |
| +client timeout (`:214-224`) and reports the target, then a soak keeps `NRestarts` at 0 |
| +(`:1569-1614`); (7) `finish`, whose `arm` starts the new plan's `Armed` list |
| +(`:1728-1764`) and already refuses to start the edge (`:1751`). |
| **Gate rollback.** `rollback` (`:1776`) calls `restoreFiles` (`:1849`). `restoreFiles` |
| renames `carlos.prev` back (`:1892`), then runs `installUnits(prevDir, j.UnitsAdded)` |
| @@ -148,9 +140,8 @@ Every dial refused between that exit and the next `net.Listen` is part of today' |
| | Old binary after a rollback | Already handled: rollback runs `disable --now` on the added socket before it restarts the edge (§1.3) | A store kept across the rollback's `restart` job is handed back to an old binary that binds by itself, so it gets EADDRINUSE. Clearing the store needs `systemctl clean --what=fdstore` (254+), which no old applier runs | |
| | Edge code | Read `LISTEN_FDS` (a pattern already in the repo) | `sd_notify` with `SCM_RIGHTS` and `NotifyAccess=`, plus the same read | |
| -**Decision: the socket unit.** It is the only option that survives `stop`+`start` and boot. |
| -The code that removes it on rollback is already in every binary a box can roll back to. |
| - |
| +**Decision: the socket unit.** It is the only option that survives `stop`+`start` and boot, |
| +and the code that removes it on rollback is already in every binary a box can roll back to. |
| An `SO_REUSEPORT` handoff was rejected too. `restart` never runs the two processes |
| together, and an old binary does not set the option, so a mixed pair cannot share the |
| port. |
| @@ -186,11 +177,8 @@ WantedBy=sockets.target |
| A bare port is "read as port number to listen on via IPv6", and with `both` it is reachable |
| "via both IPv4 and IPv6" (`man systemd.socket`). That is the same dual-stack wildcard that |
| Go's `net.Listen("tcp", ":80")` opens today. Everything else stays at its default: |
| - |
| -- `Backlog=` is capped by `net.core.somaxconn`, which is 4096 here; |
| -- `FlushPending=` is no; |
| -- `TriggerLimit*` is unchanged. If it trips, the socket fails, and the edge binds by itself |
| - (D5). |
| +`Backlog=` (capped by `net.core.somaxconn`, 4096 here), `FlushPending=no`, and |
| +`TriggerLimit*`; if that trips, the socket fails and the edge binds by itself (D5). |
| `User=`/`Group=` reach only the `ExecStartPre=` ("the execution environment the |
| ExecStartPre= … commands are executed in", `man systemd.socket`). PID 1 still binds the |
| @@ -245,9 +233,7 @@ IP when the flag names one. A match is served with `Serve` or `ServeTLS("", "")` |
| what `ListenAndServe*` does after its bind. An unmatched address is bound by the process |
| itself, with today's fatal message on failure (`edge: http listener %s: %v`; the large-box |
| tests grep it). An inherited fd that matches nothing or fails a check is closed and logged. |
| -A malformed handoff costs the blip, never the box. |
| - |
| -*Layout.* The fd code is `//go:build linux` (`internal/edge/listeners_linux.go`, using |
| +A malformed handoff costs the blip, never the box. The fd code is `//go:build linux` (`internal/edge/listeners_linux.go`, using |
| `golang.org/x/sys/unix`). A `!linux` stub returns nothing, so every address binds itself as |
| today. |
| @@ -255,12 +241,9 @@ today. |
| rule. `Shutdown` closes the edge's listener, and on Linux that is `close(2)` of the edge's |
| own dup (`net/fd_posix.go:47-50` → `internal/poll/fd_unix.go:91-105`), never `shutdown(2)`. |
| PID 1's copy keeps the socket and its accept queue, so connections arriving during the drain |
| -and the new process's startup queue up. |
| - |
| -`FileListener`'s `SetNonblock` (`file_unix.go:25`) changes the open file description that |
| -PID 1 shares. That is harmless: PID 1 only polls. |
| - |
| -The rule, enforced by a guard test: no `shutdown(2)`, `SO_LINGER` or `SO_REUSEPORT` on edge |
| +and the new process's startup queue up. (`FileListener`'s `SetNonblock`, `file_unix.go:25`, |
| +changes the description PID 1 shares; harmless, PID 1 only polls.) The rule, enforced by a |
| +guard test: no `shutdown(2)`, `SO_LINGER` or `SO_REUSEPORT` on edge |
| listeners, and never `FlushPending=yes` in the unit. |
| **D7. `restartEdge` in this build.** When `/etc/systemd/system/carlos-edge.socket` exists, |
| @@ -279,47 +262,35 @@ sockets: LISTEN_PID unset)`, or a mixed form. There is also one line per fd clos |
| The morning check is `journalctl -u carlos-edge -g 'edge: listeners:'`. These are operator |
| logs, not member copy. |
| -**D9. Hardening is unchanged.** |
| - |
| -- `AmbientCapabilities=`/`CapabilityBoundingSet=CAP_NET_BIND_SERVICE` stay |
| - (`carlos-edge.service:32-33`), because D5's fallback binds :80 itself. Dropping them is a |
| - later change, once every box runs the socket. |
| -- `RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX` (`:51`) restricts `socket(2)`, not |
| - inherited fds. The edge still needs all three for its outbound dials. |
| -- `@system-service` covers `getsockname`, `getsockopt` and `fcntl`. |
| -- The socket unit runs only the one-shot check, as `carlos`. |
| +**D9. Hardening is unchanged.** `AmbientCapabilities=`/`CapabilityBoundingSet= |
| +CAP_NET_BIND_SERVICE` stay (`carlos-edge.service:32-33`), because D5's fallback binds :80 |
| +itself; dropping them is a later change, once every box runs the socket. |
| +`RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX` (`:51`) restricts `socket(2)`, not |
| +inherited fds, and the edge still needs all three to dial out. `@system-service` covers |
| +`getsockname`, `getsockopt` and `fcntl`. The socket unit runs only the one-shot check, as |
| +`carlos`. |
| **D10. Local upstreams are held, not 502'd.** One constant, `localDialHold = 13 * |
| -time.Second`, replaces the two literals at `genproxy.go:40,86`. |
| - |
| -`tcpProxy` gets a `DialContext` when the addr is local, meaning a literal loopback IP |
| -(`netip.Addr.IsLoopback`) or `localhost`. The dial retries `ECONNREFUSED` every 100 ms until |
| -it connects, its context ends, or the hold runs out, and then returns the last error. |
| -Non-local addrs keep the zero dialer: a refusal from another machine is not a restart on |
| -this box. |
| - |
| -This covers every loopback addr route, the console included, and activator TCP routes |
| -through `tcpProxy`, with no console special case. Probed `multiProxy` routes keep their |
| -eject and 503 behaviour. |
| - |
| -Why 13 s: |
| - |
| -- it is the window already in production for unix upstreams, sized for drain plus rebind; |
| -- the console's measured gap (~10 s) fits inside it; |
| -- it is under the wake hold's 30 s; |
| -- one policy for "a local upstream is briefly absent", not two. |
| - |
| -Safety. A dial that fails never reached the upstream, so a retry is safe for any method. |
| -`RoundTrip` reads no body before it has a connection, so a POST arrives intact. Upgrade |
| +time.Second`, replaces the literals at `genproxy.go:40,86`. `tcpProxy` gets a `DialContext` |
| +when the addr is local (a literal loopback IP by `netip.Addr.IsLoopback`, or `localhost`): |
| +it retries `ECONNREFUSED` every 100 ms until it connects, its context ends or the hold runs |
| +out, then returns the last error. Non-local addrs keep the zero dialer; a refusal from |
| +another machine is not a restart on this box. This covers every loopback addr route, the |
| +console included, and activator TCP routes, with no console special case. Probed |
| +`multiProxy` routes keep their eject-and-503 behaviour. Why 13 s: it is the window already |
| +in production for unix upstreams, sized for drain plus rebind; the console's ~10 s gap fits |
| +inside it; it is under the wake hold's 30 s; and one policy beats two for "a local upstream |
| +is briefly absent". |
| + |
| +Safety: a failed dial never reached the upstream, so a retry is safe for any method. |
| +`RoundTrip` reads no body before it has a connection, so a POST arrives intact; upgrade |
| requests (WebSockets) take the same dial and are held the same way. Go 1.26 detaches the |
| dial from the request ("The dial should proceed even if the request is canceled", |
| -`$GOROOT/src/net/http/transport.go:1524-1529`). So a client that leaves is released at once |
| -on its own context, the background dial ends at the cap, and a late success goes to the |
| -idle pool. That is how unix routes already behave. |
| - |
| -A dial still refused at the cap stays `CauseRefused`, answered with a 502. The |
| -`client_gone` and abandoned rules (`answered.go:55-65`) are unchanged, and their comment |
| -gains loopback TCP. |
| +`$GOROOT/src/net/http/transport.go:1524-1529`): a client that leaves is released at once on |
| +its own context, the background dial ends at the cap, and a late success goes to the idle |
| +pool, as for unix routes today. A dial still refused at the cap stays `CauseRefused` and |
| +502; the `client_gone`/abandoned rules (`answered.go:55-65`) are unchanged, and their |
| +comment gains loopback TCP. |
| **D11. Cross-compile.** Only D5's fd code is linux-only, and it has a stub. D10 goes through |
| the existing `isRetryableDialErr` (`edge.go:3513`), which already builds for darwin and |
| @@ -386,93 +357,66 @@ proves nothing. The gate is unchanged. |
| ## 7. Local witness (no cloud, no sudo, 127.0.0.1 only) |
| -**W1: a Go test, run in CI, linux only.** `internal/edge/listeners_witness_linux_test.go`, |
| -in the subprocess pattern of `internal/edge/startup_test.go:18-60`. |
| - |
| -- The parent plays PID 1. It binds `127.0.0.1:0` twice and keeps both fds. |
| -- It launches the child through `/bin/sh -c 'LISTEN_PID=$$ LISTEN_FDS=2 exec "$0" "$@"'` |
| - with `ExtraFiles` set to the two fds. `$$` survives the `exec`, as systemd's post-fork |
| - `LISTEN_PID` does. |
| -- The child runs the **real** `RunWithActivatorReady` (non-dev) on a temp |
| - `CARLOS_DATA_DIR`, with `-http`/`-https` set to those addresses and no store |
| - environment. |
| -- About 8 workers send fresh-connection `GET http://127.0.0.1:P/` (any HTTP answer counts, |
| - as for the gate probe) and TLS dials to Q (a TLS alert counts as answered). |
| -- Three times over, the parent sends SIGTERM, waits for the exit, and starts the next child |
| - after an injected 1 s delay. |
| - |
| -Pass: 0 refused, reset or timed-out requests, and every child logs `inherited 2`. The test |
| -reports the measured gap (the worst latency across a restart) and each restart's duration. |
| -A negative control runs children that inherit nothing and bind by themselves; it must count |
| -refusals greater than 0. |
| - |
| -**W2: a script, run once by hand on DOCS-T1 with the sandbox off.** File: |
| -`scripts/edge-roll-witness.sh`. `systemd-socket-activate` cannot restart its child, and the |
| -user bus is closed inside the sandbox, so this uses `systemctl --user`. |
| - |
| -- It builds `carlos` into `mktemp -d`. |
| -- It writes `erb-<rand>.socket` and `.service` into `$XDG_RUNTIME_DIR/systemd/user`, with |
| - D2's lines except: listening on `127.0.0.1:P`/`Q`, no `User=`, and running |
| - `carlos edge -http 127.0.0.1:P -https 127.0.0.1:Q -registry … -acme-cache …`. |
| -- It drives a curl load loop (`--max-time 30`) through four transitions: |
| - 1. `restart`: 0 refused; |
| - 2. `stop`+`start`: 0 refused; |
| - 3. the first-install shape: the service running without the socket and binding itself, |
| - then `restart` with `Wants=`. It must serve, and the script reports which bound first; |
| - 4. the rollback shape: `disable --now` the socket, remove it, `daemon-reload`, `restart`. |
| - It must serve, with `bound … itself`. |
| -- It reports refusals and the worst latency for each transition. |
| -- A `trap` stops the units, removes the files, reloads and deletes the temp dir. |
| - |
| -W2's numbers go in the #434 reply. A dev-box measurement is Paul's call in the morning. |
| +**W1: a Go test, run in CI, linux only** (`internal/edge/listeners_witness_linux_test.go`, |
| +in the subprocess pattern of `internal/edge/startup_test.go:18-60`). The parent plays PID 1: |
| +it binds `127.0.0.1:0` twice, keeps both fds, and launches the child through |
| +`/bin/sh -c 'LISTEN_PID=$$ LISTEN_FDS=2 exec "$0" "$@"'` with `ExtraFiles` set to them (`$$` |
| +survives the `exec`, as systemd's post-fork `LISTEN_PID` does). The child runs the **real** |
| +`RunWithActivatorReady` (non-dev) on a temp `CARLOS_DATA_DIR`, `-http`/`-https` on those |
| +addresses, no store environment. About 8 workers send fresh-connection |
| +`GET http://127.0.0.1:P/` (any HTTP answer counts, as for the gate probe) and TLS dials to Q |
| +(a TLS alert counts as answered). Three times over, the parent sends SIGTERM, waits for the |
| +exit and starts the next child after an injected 1 s delay. Pass: 0 refused, reset or |
| +timed-out requests, and every child logs `inherited 2`. Reported: the measured gap (worst |
| +latency across a restart) and each restart's duration. A negative control, whose children |
| +inherit nothing and bind by themselves, must count refusals > 0. |
| + |
| +**W2: a script, run once by hand on DOCS-T1 with the sandbox off** |
| +(`scripts/edge-roll-witness.sh`; `systemd-socket-activate` cannot restart its child, and the |
| +user bus is closed inside the sandbox). It builds `carlos` into `mktemp -d` and writes |
| +`erb-<rand>.socket`/`.service` into `$XDG_RUNTIME_DIR/systemd/user`: D2's lines, except |
| +listening on `127.0.0.1:P`/`Q`, no `User=`, and `ExecStart=carlos edge -http 127.0.0.1:P |
| +-https 127.0.0.1:Q -registry … -acme-cache …`. A curl load loop (`--max-time 30`) runs |
| +through four transitions: `restart` (0 refused); `stop`+`start` (0 refused); the |
| +first-install shape, the service binding itself with no socket and then `restart` with |
| +`Wants=` (must serve; reports which side bound first); and the rollback shape, `disable |
| +--now` the socket, remove it, `daemon-reload`, `restart` (must serve, `bound … itself`). It |
| +reports refusals and worst latency per transition, and a `trap` stops the units, removes |
| +the files, reloads and deletes the temp dir. W2's numbers go in the #434 reply; a dev-box |
| +measurement is Paul's call in the morning. |
| ## 8. Test plan |
| -Run locally only for touched packages, with `-run`. CI does the full run. |
| - |
| -- **D5** (linux, via subprocess re-exec): |
| - - `LISTEN_PID` unset or naming another pid: nothing is taken; |
| - - two fds matched by port, with the IP honoured when the flag names one; |
| - - the originals are closed and the dups are close-on-exec (`F_GETFD`); |
| - - the env is unset; |
| - - a non-listening, non-TCP or wrong-port fd is closed and logged; |
| - - a missing port is bound by the process itself. |
| -- **D8:** each log form is pinned. |
| -- **D2/D3:** |
| - - the embedded units are pinned: the socket's lines, and the service's `Wants=`/`After=` |
| - with no `Requires=`/`BindsTo=`/`PartOf=` naming the socket; |
| - - the socket is in `enabledUnits` and absent from `armedUnits`, |
| - `currentBootstrapPlan().Armed` and `ensureSystemArmed`; |
| - - `arm` refuses it. |
| -- **D4:** `carlos system edge-socket-check` exits 0 with no output and is not in the usage. |
| -- **D7** (fake `sysOps`): with the socket file present, `restartEdge` runs `reset-failed` |
| - on both, then `restart`. Without the file it touches only the edge. |
| -- **Rollback invariant** (fake `sysOps`): with `UnitsAdded` naming the socket, `rollback` |
| - and `recoverIfNeeded` run `disable --now carlos-edge.socket` before any |
| - `restart carlos-edge`. This pins the order the old binaries already follow. |
| +Run locally only for touched packages, with `-run`; CI does the full run. |
| + |
| +- **D5** (linux, subprocess re-exec): `LISTEN_PID` unset or another pid takes nothing; two |
| + fds matched by port, IP honoured when the flag names one; originals closed and dups |
| + close-on-exec (`F_GETFD`); env unset; a non-listening, non-TCP or wrong-port fd closed and |
| + logged; a missing port bound by the process. **D8:** each log form pinned. |
| +- **D2/D3:** the embedded units pinned (the socket's lines; the service's `Wants=`/`After=` |
| + with no `Requires=`/`BindsTo=`/`PartOf=` naming the socket); the socket in `enabledUnits` |
| + and absent from `armedUnits`, `currentBootstrapPlan().Armed` and `ensureSystemArmed`; |
| + `arm` refuses it. **D4:** `carlos system edge-socket-check` exits 0, prints nothing, and |
| + is not in the usage. |
| +- **D7** (fake `sysOps`): with the socket file, `restartEdge` runs `reset-failed` on both |
| + then `restart`; without it, only the edge is touched. **Rollback invariant** (fake |
| + `sysOps`): with `UnitsAdded` naming the socket, `rollback` and `recoverIfNeeded` run |
| + `disable --now carlos-edge.socket` before any `restart carlos-edge`. This pins the order |
| + the old binaries already follow. |
| - **D6:** a guard test finds no `shutdown`, `SO_LINGER` or `SO_REUSEPORT` on listener code |
| in `internal/edge`. |
| -- **D10:** |
| - - a loopback upstream that is refused, then listens within the hold, gives 200; |
| - - one refused past a shortened hold gives 502 at about the hold; |
| - - a non-loopback addr gives 502 at once; |
| - - a client cancel returns at once; |
| - - a POST body arrives intact after a hold; |
| - - a WebSocket upgrade works after a hold; |
| - - `multiProxy` is unchanged. |
| -- **Witnesses:** W1 in CI. W2 once by hand before handoff, with its output in the #434 |
| - reply. |
| +- **D10:** refused then listening within the hold gives 200; refused past a shortened hold |
| + gives 502 at about the hold; a non-loopback addr gives 502 at once; a client cancel |
| + returns at once; a POST body arrives intact after a hold; a WebSocket upgrade works after |
| + a hold; `multiProxy` is unchanged. |
| +- **Witnesses:** W1 in CI; W2 once by hand before handoff, its output in the #434 reply. |
| ## 9. Out of scope |
| -- Part C (instances surviving an edge restart: `BindsTo=`, #440 item 1). |
| -- Socket-activating `console.service`, which is not in this repo. |
| -- The relay's ports. |
| -- `Type=notify` readiness. |
| -- Dropping `CAP_NET_BIND_SERVICE`. |
| -- The infra script (row 14). |
| -- Any AWS, DNS or box change; release, roll and merge. |
| -- A drain shorter than 10 s. |
| +Part C (instances surviving an edge restart: `BindsTo=`, #440 item 1). Socket-activating |
| +`console.service` (not in this repo). The relay's ports. `Type=notify` readiness. Dropping |
| +`CAP_NET_BIND_SERVICE`. The infra script (row 14). Any AWS, DNS or box change; release, |
| +roll and merge. A drain shorter than 10 s. |
| ## 10. Open questions (not settled by evidence here) |