edge-roll-blip: spec rev 3, cut to option 2 (local-upstream hold)
Paul's ruling on #434 (2026-10-28): option 2, then option 3. The socket design (D1-D7, D9, the mix table, INV-R, edge-socket-check, W1/W2) leaves the body for a short "Later: option 3" section behind a version floor. Kept and revised: D10 loopback TCP dial hold sharing the unix retry loop and one localDialHold constant; D10b probed local routes wait for readmission, with the R2 P2 fix (allowance from the sequential probe schedule: R = r*G + T, G = max(I,T) + (N-1)*T, on clamped settings, 30 s cap, cases past it stated); D8 log line for a build with no socket; in-process witness test counting 502/503 across a local upstream restart. Review history and dispositions for R1 and R2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+289
−527
docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md+289 −527
Intent
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 6ce701464..3f2688343 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 |
| @@ -1,533 +1,295 @@ |
| # Edge roll blip (#434 part B): design |
| -Status: revised for review round 2 of at most 3, 2026-10-28, branch `edge-roll-blip`. |
| -Rulings are the brief's (`.superpowers/sdd/2026-10-27-edge-roll-blip/BRIEF.md`) and are |
| -not re-argued. Round 1 (`e0b2877a`): NOT READY, 2 P1, 4 P2. Fault families named there: |
| -**INV-R** (rollback compatibility, P1-1) and **INV-H** (restart admission, P1-2). A |
| -round-2 finding in either family stops the review for Paul's choice (AGENTS.md rule 2). |
| -Dispositions are in §11. |
| - |
| -Goal: a platform roll (`carlos system update` restarting `carlos-edge.service`; root's |
| -adopt restarting `console.service`) is a short queued wait for clients, with no refused |
| -connection and no 502/503 caused by the restart itself. |
| - |
| -In one paragraph: a `carlos-edge.socket` unit holds :80 and :443 in PID 1, and the edge |
| -takes them over through `LISTEN_FDS`, binding them itself when it is handed none (D1, D5). |
| -One invariant makes every binary/unit mix safe (INV-R, D4). It is enforced in one place: a |
| -drop-in on the edge service that, before every start of the edge, stops the socket unless |
| -the binary on disk understands it. The socket refuses to start until that drop-in is |
| -loaded, and only code from this build on writes the drop-in. So activation takes two |
| -rolls on an existing box (§4), and no old binary, old applier or old unit set can ever meet |
| -an active socket. Local upstreams are held for a bounded window instead of 502/503: |
| -unprobed loopback routes retry the dial (D10), and probed routes wait for a live upstream |
| -(D10b). |
| +Status: revision 3, 2026-10-28, branch `edge-roll-blip`. Cut to option 2 by Paul's ruling on |
| +amadan #434 ("2 then 3"), after review rounds 1 and 2 (§9). Any review of this text is round 3 |
| +of this design, the last one: a P1 there stops the work (AGENTS.md "Stopping rules" 1 and 2). |
| +The brief is `.superpowers/sdd/2026-10-27-edge-roll-blip/BRIEF.md`; the ruling narrows it. |
| + |
| +Goal: when a local upstream restarts (root's adopt restarting `console.service` once per roll, |
| +or any loopback or unix upstream restarting), clients of routes through the edge wait for it |
| +instead of getting 502 or 503. The edge's own listeners are not changed here: the edge still |
| +binds :80 and :443 itself, so its own restart still refuses connections for its gap. That |
| +part is option 3, a later slice (§8). |
| + |
| +Scope: D10 (unprobed local upstream: dial retried instead of 502), D10b (probed route with a |
| +local upstream: wait for readmission instead of 503), D8 (a startup log line) and the witness |
| +(§6). Numbers are kept from the reviewed revisions so the findings still point at the right |
| +decision; D1-D7 and D9 were the socket design (§8). No unit file, root, updater, install, |
| +bootstrap or rollback change. |
| ## 1. Evidence |
| -### 1.1 Public ports the edge binds |
| - |
| -There are two, both TCP, both bound by the agent process itself. `-http` defaults to `:80` |
| -(`internal/edge/edge.go:3550`) and serves ACME HTTP-01 and the redirect |
| -(`httpSrv.ListenAndServe()`, `:3819`). `-https` defaults to `:443` (`:3549`) and serves |
| -routes (`:3826`). Dev mode binds `-http` only (`:3646`). Both come only from argv: there is |
| -no environment override. The unit passes no flags (`ExecStart=/opt/carlos/carlos agent`, |
| -`internal/host/units/carlos-edge.service:19`); a guarded box replaces it with |
| -`/opt/carlos/system/guard/carlos system guard-exec edge` (`internal/host/guardarm.go:166`), |
| -which execs `/opt/carlos/carlos agent` (`guardexec.go:90-91`). |
| - |
| -Nothing else in the edge process is public. The door, the purge channel and `agentsock` |
| -are unix sockets (`internal/edge/door.go:182`, `purge_listen_unix.go:36`, |
| -`internal/agentsock/agentsock.go:286`). Backhaul only dials (`edge.go:3202`). There is no |
| -UDP, HTTP/3, metrics or admin port, and no `SO_REUSEPORT` in `internal/` or `cmd/`. The |
| -relay's listeners (`internal/relay/server.go:307,321`) belong to `carlos-relay.service`. |
| - |
| -### 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), the door |
| -(`:3712`) and the TLS chain (`:3793`). Only then does it serve (`:3814-3830`). #281 moved the |
| -agent's slow startup behind the `started` latch (`agent.go:646-650,701`). Activator-owned |
| -requests wait on it in `awaitStartup` (`internal/activator/activator.go:1572`), bounded by |
| -`wakeWaitBound = 30s` (`:1141`), then get 503 with `Retry-After: 5`. On SIGTERM both |
| -servers `Shutdown` with a 10 s drain (`edge.go:3835-3842`). |
| - |
| -### 1.3 How binaries and units reach a box |
| - |
| -**Units** are embedded in the binary (`internal/host/bootstrap.go:36`, `units/*.socket` |
| -included). `carlos bootstrap` writes them; `-root <dir>` writes them into a staging tree |
| -instead. `enabledUnits` (`:167-173`) is what gets enabled; `armedUnits` (`:218-227`) is what |
| -also gets started, today including every `.socket` (`:222`). |
| - |
| -**`carlos system update`.** `carlos-system-update.path` runs `system apply` as root from the |
| -installed binary, or from `carlos.prev` while a journal is open |
| -(`units/carlos-system-update.service:47`). `install` (`internal/host/systemapply.go:551`): |
| -`decidePrev` refreshes `carlos.prev` from the installed binary only when that binary is the |
| -recorded applied build, else keeps the old `carlos.prev` (`:851-875`); both builds' units are |
| -staged with `bootstrap -root <dir> -plan-json` (`stagePlan`); the journal records |
| -`UnitsAdded`/`UnitsRemoved` (`:610`); the candidate is renamed in (`:632`); `installUnits` |
| -(`:1379`) first runs `disable --now` on each removed unit, logging and ignoring a failure |
| -(`:1388-1391`), then copies the staged files, skipping directories (`:1408`), then sysusers, |
| -tmpfiles and `daemon-reload`; the edge is restarted (`restartEdge`, `:1490-1494`) and |
| -gated (20 s, 3 s HTTP probe, then an `NRestarts` soak); `finish`'s `arm` starts the plan's |
| -`Armed` list and refuses the edge (`:1748-1752`). |
| - |
| -**Rollback and recovery** share `restoreFiles` (`:1849`): it renames `carlos.prev` in |
| -(`:1892`), syncs the directory (`:1895`), restages the previous units if needed (`:1924`), |
| -and only then runs `installUnits(prevDir, UnitsAdded)` (`:1927`). Any error between the rename |
| -and the `disable` returns with the old binary on disk and the new units in place; |
| -`recoverIfNeeded` then returns (`:2061`). `carlos-system-recover.service` runs once per boot |
| -`Before=carlos-edge.service` and as the update's `OnFailure=`; with a journal open it runs |
| -**`carlos.prev`**, i.e. the older build's code (`units/carlos-system-recover.service:34,41`). |
| -At runtime it then issues `restart --no-block` on the edge (`:2082`). |
| - |
| -**The hand roll.** `scripts/update-platform-binary.sh` in platform-infrastructure is the |
| -documented way to put a release on one box (`README.md:289`). It installs the binary over |
| -`/opt/carlos/carlos`, runs `carlos bootstrap -root /tmp/carlos-unitstage`, `cp`s |
| -`etc/systemd/system/*` into place (files only; under `set -euo pipefail` a directory there |
| -would abort it), reloads and restarts the edge. It never touches `carlos.prev` and never |
| -removes a unit or a drop-in. |
| - |
| -**What no old code does.** No applier from v0.18.0 to today removes anything under |
| -`/etc/systemd/system` but the files named in `UnitsAdded`/`UnitsRemoved`: every `RemoveAll` |
| -in `systemapply.go` targets the staging directory (checked at v0.18.0, v0.22.0, v0.25.0, |
| -v0.28.30), and the copy loop skips directories. So a drop-in directory written by this |
| -build survives every old applier and the hand script. And every build exits non-zero on |
| -`carlos system edge-socket-check`: since v0.18.0 the `system` verb's default branch exits 2 |
| -(`system.go:116-121`, same at v0.18.0), and v0.17.0's `main` exits 2 on an unknown verb. |
| - |
| -**Version floors are not a baseline here.** `release.LayoutFloor` is v0.25.0 |
| -(`internal/release/layoutintent.go:211`), and `install` refuses below it only when |
| -`layoutReversalReasons()` is non-empty (`systemapply.go:583`), so it is no installation |
| -floor. The design does not need one: nothing in an old binary is load-bearing for INV-R. |
| - |
| -**The belt pass** (`ensureSystemUnits`, `internal/host/systemunits.go:53`) arms a fixed |
| -list (`:28,32`) without either edge unit. |
| - |
| -### 1.4 systemd on the boxes |
| - |
| -Debian 13 arm64 (`infra/modules/region-host/variables.tf:158`), **systemd 257** (257.13 on |
| -the AMI and on DOCS-T1, `docs/superpowers/plans/2026-10-24-rootfs-apps-2-verify.md:34`). |
| -The `LISTEN_FDS` protocol is the one the repo already implements |
| -(`internal/instancectl/peer_linux.go:90-104`, `testdata/echoapp/main.go:62-75`). Quotes |
| -below are from this machine's man pages. |
| - |
| -### 1.5 Local upstream dials today |
| - |
| -**Unix routes** (`dialUnixWithRetry`, `edge.go:2721,3509`; `dialGen`, `genproxy.go:86`) |
| -retry `ECONNREFUSED`/`ENOENT` every 100 ms for 13 s (`genproxy.go:40,86`), sized for "the |
| -instance drain (10s) plus rebind" (`edge.go:3502-3508`). |
| - |
| -**Addr routes** pick by `Health` (`edge.go:846-870`). Empty → `tcpProxy` (`:2736`), a zero |
| -`http.Transport`: a refused dial is a bare 502 (`:627-633`, `CauseRefused`). Set → |
| -`multiProxy` (`:2817`): it dials only the prober's live set; an empty set is |
| -`errNoLiveUpstream` (`:2839`), a refused upstream is ejected (`:2876`), and a pass with no |
| -connection answers 503 + `Retry-After: 2` (`:2892`). The prober readmits an upstream after |
| -`rise_after` consecutive passes at `interval_ms` (defaults 2 and 2000, |
| -`internal/provision/provision.go:295-325`; `prober.go:508-530`). Go 1.26 runs the dial on a |
| -context detached from the request (`$GOROOT/src/net/http/transport.go:1524-1529`); the |
| -waiting request returns on its own context at once. |
| - |
| -**The console** listens on `127.0.0.1:8090` (`cmd/console/main.go:758-759`) and exits on |
| -SIGTERM without a drain (`:592-601`); `console.service` is operator-run and not in this |
| -repo (`cli.go:1741`, `README.md:291`). Its route can have either shape, and the repo |
| -cannot say which a given box has. `carlos add --addr` has no health flag, and |
| -`carlos route --unit console.service` (`cli.go:610-616`) only stamps the unit, so a |
| -hand-added console route is **unprobed**. A route minted from a record with `Health` is |
| -**probed** (`provision/reconcile.go:573,627-650`). Root's named-unit proof expects |
| -`/healthz` for the console (`internal/host/proofnamed.go:140`), but that feeds root's |
| -proof, not the route row. D10 and D10b cover both shapes, so nothing waits on the answer. |
| - |
| -## 2. D1: the mechanism |
| - |
| -| | `carlos-edge.socket` | fd store (`FDSTORE=1`, `FileDescriptorStoreMax=`) | |
| +### 1.1 Local upstream dials today |
| + |
| +**Unix upstreams already hold.** Every unix dial the edge makes retries `ECONNREFUSED` and |
| +`ENOENT` every 100 ms for 13 s: `unixProxy` (`internal/edge/edge.go:2708`, dial `:2720-2721`) |
| +via `dialUnixWithRetry` (`:3509`); the generation transports (`genproxy.go:203,208`) via |
| +`dialUnixRetrying` (`:39-40`) and `dialGen` (`:85-86`); and `waitServingGen` (`:311-312`). |
| +The window is sized for "the instance drain (10s) plus rebind" (`edge.go:3502-3508`); the |
| +predicate is `isRetryableDialErr` (`:3513-3515`); the 13 s is three literals |
| +(`genproxy.go:40,86,312`). Unix upstreams need nothing new beyond naming the window. |
| + |
| +**Addr (TCP) routes do not hold.** The route's `Health` column selects the proxy |
| +(`edge.go:846-871`): |
| +- Empty: `tcpProxy` (`:2736`), whose `http.Transport` has no `DialContext`. A refused dial |
| + goes to `defaultProxyError` (`:627`): a bare 502, cause `CauseRefused` (`:604`). |
| +- Set: `multiProxy` (`:2817`). It dials only the prober's live set. An empty set returns |
| + `errNoLiveUpstream` at once (`:2836-2839`). A refused upstream is ejected (`:2876`). A |
| + pass with no connection answers 503 + `Retry-After: 2`, cause `CauseNoUpstream` |
| + (`:2889-2892`). |
| + |
| +**The prober** (`internal/edge/prober.go`). `Sync` normalizes each spec with |
| +`Health.WithDefaults` (`:265`; defaults `interval_ms` 2000, `rise_after` 2, |
| +`internal/provision/provision.go:295-325`). `newHostProber` then clamps non-positive values |
| +(`prober.go:188-232`, interval at `:216`, rise at `:222`). `run` ticks at the interval |
| +(`:421`). `tick` probes the host's addrs **in turn**, each bounded by `probeTimeout` = 2 s |
| +(`:50`, client at `:130,143`). So a tick can outlast the interval, and missed ticks collapse |
| +into one back-to-back tick (`:441-446`; `time.Ticker` keeps a one-element buffer, |
| +`$GOROOT/src/time/tick.go:40-42`). Readmission takes `rise_after` consecutive passes |
| +(`:525`). `Eject` and every failed probe reset the pass count (`:356`, `:534`). |
| + |
| +**Dial context.** Go 1.26 dials on a context detached from the request |
| +(`$GOROOT/src/net/http/transport.go:1524-1529`). The request still returns on its own |
| +context at once (`:1583`). A held dial keeps running after the client leaves, and ends at |
| +its hold. |
| + |
| +**The console** listens on `127.0.0.1:8090` (`cmd/console/main.go:758-759`). It exits on |
| +SIGTERM without a drain (`:592-601`). Its route is **unprobed** if hand-added with `carlos add |
| +--addr` and stamped with `carlos route --unit` (`cli.go:610-616`), **probed** if minted from a |
| +record with `Health` (`internal/provision/reconcile.go:573,634-650`). D10 and D10b cover both, |
| +so the design does not need to know which shape a box has. |
| + |
| +### 1.2 Other holds and paths it meets |
| + |
| +- **The wake hold.** Activator-owned requests wait on the startup latch (`awaitStartup`, |
| + `internal/activator/activator.go:1572`) and on wakes, bounded by `wakeWaitBound` = 30 s |
| + (`:1141`), then go to the edge's proxy (`:5874,5889`); the activator's own `socketClient` |
| + (`backend_exec.go:3430`) only health-checks a waking instance. Activator routes are unix |
| + (`addr with hibernate` is refused at mint, `provision.go:747`), so D10/D10b never stack on |
| + the wake hold and an activator route's worst case (30 s wake, then 13 s unix hold) is |
| + unchanged. |
| +- **The edge's servers** have no `WriteTimeout` (`edge.go:3811-3815`), so nothing cuts a held |
| + request. The update gate probes `http://127.0.0.1/` on :80, which redirects and never |
| + proxies (`internal/host/systemapply.go:214-226`): unaffected. |
| +- **Cause notes.** Past `clientGoneGrace` (5 s) a client that leaves is `CauseAbandoned` |
| + and filed; before it, `client_gone` (`internal/edge/answered.go:58-65`, `edge.go:594-612`). |
| + |
| +## 2. D10: unprobed local upstreams retry the dial |
| + |
| +- **One window.** `localDialHold = 13 * time.Second` replaces the three literals |
| + (`genproxy.go:40,86,312`); a package `var` only so tests can shorten it. |
| +- **One loop.** `dialUnixRetrying`'s loop becomes `retryLocalDial(ctx, attempt)`: retry while |
| + `isRetryableDialErr`, every 100 ms, until connected, a non-retryable error, the context |
| + ends, or `localDialHold` passes; then return the last error. `dialUnixRetrying` and the new |
| + TCP dial call it. `dialGen` keeps its own loop (each attempt also checks for a generation |
| + move) on the same constant. |
| +- **Which TCP addrs.** `tcpProxy(addr)` gets a `DialContext` (`retryLocalDial` over a plain |
| + `net.Dialer{}`, the zero transport's dialer) only when `isLocalUpstream(addr)`: the host is a |
| + loopback IP literal (`netip.Addr.IsLoopback`: 127/8, `::1`) or `localhost`. D10b shares the |
| + predicate. A non-local addr, including the box's own non-loopback IPs, keeps the instant 502: |
| + a refused remote box is an outage, not a restart. |
| +- **After the hold**, still refused: 502, `CauseRefused`, as today but 13 s later. |
| + |
| +## 3. D10b: probed routes with a local upstream wait for readmission |
| + |
| +**The rule.** `newHostProber` records, from its clamped values, `local` (any addr in |
| +`hp.order` passes `isLocalUpstream`) and `hold` (below); `proberSet.Hold(host) |
| +(time.Duration, bool)` returns them, so `multiProxy` still never sees the addr list. Its |
| +dialer works in passes: each reads `Live(host)` and walks it exactly as today (dial, eject on |
| +failure, return the first connection). When a pass ends with no connection and the host is |
| +`local`, it waits 100 ms and passes again until the hold ends, then returns |
| +`errNoLiveUpstream` (503 + `Retry-After: 2`, `CauseNoUpstream`). A host with no local addr |
| +answers at once, as today. |
| + |
| +**Admission is unchanged.** Only the live set is dialed and only the prober readmits; an |
| +ejected upstream is never dialed, and a held request only waits. A live upstream that answers |
| +serves at once; the hold starts only when nothing live connects. |
| + |
| +**The readmission allowance** comes from the schedule the prober actually runs: `N` = |
| +`len(hp.order)`, `I` = `hp.interval`, `r` = `hp.riseAt` (the normalized, clamped values |
| +`run` and `record` use), `T` = `probeTimeout`. One probe of a given addr starts at most `G` |
| +after the one before it: |
| + |
| + G = max(I, T) + (N − 1) × T |
| + |
| +When a tick fits in the interval, the next one starts `I` after it, and in the worst case |
| +the addrs probed before this one take `T` each. When a tick overruns, the next tick starts as |
| +soon as it ends (`prober.go:441-446`), and at most `N` probes of `T` each separate two |
| +probes of the same addr. Once the upstream answers again, its `r`-th pass completes within |
| + |
| + R = r × G + T |
| + |
| +and the request's hold is `hold = min(localDialHold + R, localHoldCap)`, `localHoldCap` = |
| +30 s: the time the upstream may be gone, plus its readmission once back, capped at |
| +`wakeWaitBound`'s value so no request through the edge waits longer than a wake would. |
| + |
| +| Defaults (I 2 s, r 2, T 2 s), every other addr black-holed | G | R | hold | |
| +|---|---|---|---| |
| +| one local upstream | 2 s | 6 s | 19 s | |
| +| local plus 1 | 4 s | 10 s | 23 s | |
| +| local plus 2 | 6 s | 14 s | 27 s | |
| +| local plus 3 or more | 8 s or more | 18 s or more | 30 s (capped) | |
| + |
| +**When readmission can take longer than the cap.** Two cases. First, when probing is slow: |
| +many addrs that time out rather than refuse, i.e. black-holed remote upstreams in a mixed |
| +set (three of them with defaults are already over the cap). Second, when the operator |
| +configured a long cadence (`I` 10 s and `r` 2 give `R` = 22 s). In both cases a request |
| +whose local upstream comes back late gets **503 + `Retry-After: 2`** at 30 s, the same answer |
| +as today, only later; a retry after readmission is served. The cap is not raised: 30 s is |
| +already the platform's longest client wait. `G` and `R` are bounds; a refusing local upstream |
| +is probed in milliseconds, so real readmission is near `r × I`. The bound only costs time when |
| +the upstream stays down: the request then waits the full hold before its 503. |
| + |
| +## 4. Safety (D10 and D10b) |
| + |
| +- **Any method.** A failed dial sent nothing, and `RoundTrip` writes no request and reads no |
| + body before it has a connection, so a retried dial is safe for POST or any method and the |
| + body arrives intact. **Upgrades** take the same dial and are held the same way. |
| +- **A client that leaves** is released at once (the request returns on its own context). The |
| + detached dial runs to its hold; a connection it makes then goes to `tcpProxy`'s idle pool |
| + or is closed (`multiProxy` has keep-alives off). A `multiProxy` pass whose context ends |
| + still returns without ejecting (`edge.go:2855-2870`). |
| +- **Causes** are unchanged: refused after the hold is `CauseRefused` (502), no live upstream |
| + after the hold is `CauseNoUpstream` (503), and a leaver is `client_gone` or, past 5 s, |
| + `CauseAbandoned`, exactly as a unix route's hold is filed today. The comment at |
| + `answered.go:58-64` gains loopback TCP and probed routes. |
| + |
| +## 5. D8: the startup log line, and D11: cross-compile |
| + |
| +**D8.** At serve time the edge binds before it serves: `net.Listen("tcp", *httpAddr)`, then |
| +`*httpsAddr` (outside dev mode), with today's fatal messages on failure (`edge: http listener |
| +%s: %v`, `edge: https listener %s: %v`, `edge.go:3820,3827`). Then it logs one line and calls |
| +`Serve(ln)` and `ServeTLS(ln, "", "")`. `ListenAndServeTLS` does exactly this internally, |
| +so the behaviour is unchanged. The line: |
| + |
| + edge: listeners: bound :80 and :443 itself |
| + edge: listeners: bound :80 itself (dev mode) |
| + |
| +Addresses are the flag values (`edge.go:3549-3550`). Unlike today's `serving N route(s)`, |
| +which prints before the bind, the line means both binds succeeded, so the journal gives the |
| +edge's own refused window per roll: old process's `edge: draining and shutting down` to the |
| +new one's `edge: listeners:`. The socket slice extends the prefix (`edge: listeners: inherited |
| +2 from systemd (:80 fd 3, :443 fd 4)`, mixed forms). Operator log, not member copy. Morning |
| +check: `journalctl -u carlos-edge -g 'edge: listeners:|draining and shutting down'`. |
| + |
| +**D11.** No linux-only code: `syscall.ECONNREFUSED`/`ENOENT`, `net/netip` and `net.Listen` |
| +already build on darwin and windows in this package. CI's cross-builds check it. |
| + |
| +## 6. Witness (local, CI, 127.0.0.1 only) |
| + |
| +`internal/edge/localhold_witness_test.go`, `TestLocalUpstreamRestartWitness`. It is skipped |
| +under `-short`; its subtests run in parallel, about 5 s in all. It runs the real proxy path |
| +in-process: an `Edge` from `New(openReg(t), nil)` served by `httptest.NewServer(e)` on |
| +127.0.0.1, routes Reloaded from the registry as in `edge_test.go:1684-1700`. No build, no |
| +sudo, no systemd. Subtests: `tcp`, an unprobed `Addr` route to `127.0.0.1:P`; `unix`, a |
| +`Socket` route under `shortSockDir` (`door_test.go:902`), skipped on windows; `probed`, an |
| +`Addrs` route to `127.0.0.1:P` with `Health{Path: "/healthz", IntervalMS: 100, FailAfter: 1, |
| +RiseAfter: 2}`. |
| + |
| +Each subtest's one upstream is an `http.Server` on a fixed address answering `/` and |
| +`/healthz` with 200. Eight workers send `GET /` (Host `shop.example.com`) through the edge on |
| +keep-alive clients. After 1 s of steady load (the baseline) the upstream restarts: |
| +`Shutdown` with a 5 s drain (as the instance drain does), a 1.5 s gap in which the port |
| +refuses or the socket is absent, then a new `http.Server` on the same address. Load runs 1 s |
| +more. Every response is counted by status, transport errors separately. |
| + |
| +**Pass:** zero 502, zero 503 and zero other failures. Each request's added wait is its |
| +latency minus the baseline p50. The max added wait must stay under gap + 1 s for `tcp` and |
| +`unix`, and under gap + `R` for `probed`. Each subtest reports one line: |
| + |
| + t.Logf("local-hold witness: route=%s gap=%v requests=%d ok=%d 502=%d 503=%d other=%d added_wait p50=%v p99=%v max=%v", ...) |
| + |
| +The #434 reply quotes these numbers. **Negative control:** the `tcp` case runs again with |
| +`localDialHold` set to 0, and its count of 502s must be above 0, so the witness can fail. |
| +The console's undrained `os.Exit` is not modelled: those resets are a known limit (§7), not |
| +the edge's. |
| + |
| +## 7. Known limits |
| + |
| +- **The edge's own restart** still refuses new connections from its `Shutdown` until the new |
| + process binds: option 3 (§8). D8 makes the gap measurable from the journal. |
| +- **In-flight requests** on a local upstream that exits undrained (the console's `os.Exit`) |
| + are reset and still 502, as is a request with a body on a pooled `tcpProxy` connection that |
| + dies under it (the transport replays only replayable requests on a reused connection). |
| +- **A local upstream that stays down** answers after the hold (13 s unprobed, 19-30 s |
| + probed), and each held request costs a goroutine and a loopback dial or live-set read every |
| + 100 ms until then. Unix routes already make both trades. |
| +- **WebSockets** on the edge drop when the edge restarts: part C. |
| + |
| +## 8. Later: option 3 (not built here) |
| + |
| +`carlos-edge.socket` holds :80 and :443 in PID 1, and the edge takes them through |
| +`LISTEN_FDS`. It ships as its own slice, in a release that **refuses any rollback or apply to |
| +a build older than the first socket-aware build**. That release refuses to install unless |
| +both the installed binary and `carlos.prev` are at or above that build. It also refuses |
| +`system update --file`, rollback and recovery targets below it. So no pre-socket rollback |
| +code, recovery unit or binary ever runs on a box where the socket can be active. |
| + |
| +The socket design reviewed in rounds 1 and 2 is at `dad8843b` (D1-D9, the §4 mix table, the |
| +witnesses). The slice keeps its evidence and must answer these findings: |
| +- **R1 P1-1** (rollback compatibility). Recovery can rename an old binary in |
| + (`systemapply.go:1892`) and return before socket removal (`:1927`, `:2061`). That leaves |
| + the old binary behind an active socket. Boot recovery runs `carlos.prev`'s code. |
| +- **R2 P1** (rollback compatibility, the same family). A guard that reads a failed |
| + `systemctl` status query as "inactive" admits an incompatible binary. Every check must |
| + fail closed on an unknown state (cf. `systemunits.go:101-108`). |
| +- **R1 P2 floor.** `release.LayoutFloor` (v0.25.0) is conditional (`systemapply.go:583`). |
| + The new floor must be unconditional, and enforced by the code that runs install, |
| + rollback and recovery. |
| +- **R1 P2s** on listener compatibility (absent vs incompatible inherited listeners), fd-store |
| + evidence (`FileDescriptorStorePreserve=yes`) and witness binary identity: resolved in the |
| + round-2 text; keep those resolutions. |
| +- The hand script (`scripts/update-platform-binary.sh`, platform-infrastructure) copies units |
| + and binaries outside the applier: the slice gates it or retires it. |
| + |
| +The slice is designed, reviewed and built under its own round budget, after this merges. |
| + |
| +## 9. Review history and dispositions |
| + |
| +R1 (brief `e0b2877a`): NOT READY, 2 P1, 4 P2. R2 (brief `dad8843b`): NOT READY, 1 P1 in the |
| +rollback-compatibility family again and 1 P2 in the restart-admission family again. Stopping |
| +rule 2 triggered; the choice went to #434; Paul ruled on 2026-10-28: option 2 now, then 3. |
| + |
| +| Finding | Family | Disposition | |
| |---|---|---| |
| -| `systemctl restart` | Separate unit, stays active; `FlushPending=no` keeps queued connections | Kept with the default `FileDescriptorStorePreserve=restart`: "as long as the unit is neither inactive nor failed, or a job is queued" | |
| -| `stop` then `start` | Kept | Lost with `restart`/`no`. Kept with `yes`: "until the unit is removed from memory (i.e. is not referenced anymore and inactive)" (254+) | |
| -| Boot, crash loop, edge never started | PID 1 listens from `sockets.target` | Nothing held until the edge has bound once and stored its fds | |
| -| INV-R: an older binary must not inherit the ports | The edge's `ExecStartPre=` can stop the socket, a separate unit (D4) | The store is handed to whatever starts next. Clearing it is `systemctl clean --what=fdstore`, and "the specified units must be stopped" (`man systemctl`), so the edge's own `ExecStartPre=` cannot. `yes` makes the store outlive a stop too | |
| -| Edge code | Read `LISTEN_FDS` | `sd_notify` with `SCM_RIGHTS` and `NotifyAccess=`, plus the same read | |
| - |
| -**Decision: the socket unit.** It holds the ports at boot and before the first bind, and it |
| -can be released from inside the edge's start, which is what INV-R needs. `SO_REUSEPORT` was |
| -rejected: `restart` never runs both processes, and an old binary does not set it. From |
| -`man systemd.socket`: the service "may be started without the socket, in which case it must |
| -be able to open sockets by itself", and `FlushPending=no` lets "the service … handle any |
| -pending connections after restart". |
| - |
| -## 3. Design |
| - |
| -**D2. The units.** New `internal/host/units/carlos-edge.socket`: |
| - |
| -``` |
| -[Unit] |
| -Description=carlos edge public listeners (:80, :443) |
| -[Socket] |
| -ListenStream=80 |
| -ListenStream=443 |
| -BindIPv6Only=both |
| -Accept=no |
| -ExecStartPre=/opt/carlos/carlos system edge-socket-check |
| -[Install] |
| -WantedBy=sockets.target |
| -``` |
| - |
| -A bare port with `BindIPv6Only=both` is the dual-stack wildcard Go's `net.Listen("tcp", |
| -":80")` opens today. `Backlog=` (capped by `somaxconn`, 4096), `FlushPending=no` and |
| -`TriggerLimit*` stay at their defaults. The check runs as root, like `system apply`: root |
| -already runs this binary, and the check needs PID 1's private socket (D4). No `User=`. |
| - |
| -`carlos-edge.service` gains `Wants=carlos-edge.socket` and `After=carlos-edge.socket`, and |
| -**no `Requires=`, `BindsTo=` or `PartOf=`** on the socket. D4 stops the socket during the |
| -edge's own start, and rollback stops it while the edge keeps serving; with `Requires=` "this |
| -unit will be stopped (or restarted) if one of the other units is explicitly stopped" |
| -(`man systemd.unit`). With `Wants=`, "if the listed units fail to start … this unit will |
| -still be started." |
| - |
| -**D3. Enabled, never armed.** The socket joins `enabledUnits` and stays out of |
| -`armedUnits`, every plan's `Armed`, `ensureSystemUnits`, and `arm` (which refuses it like |
| -the edge). A `start` while an edge process holds :80 itself fails with EADDRINUSE, and in a |
| -batched `start` that fails the whole arm. So the socket starts only through the edge's |
| -`Wants=` or at boot, and always through its check. |
| - |
| -**D4. INV-R and where it is enforced.** |
| - |
| -> **INV-R:** `carlos-edge.service` never runs its main process while `carlos-edge.socket` |
| -> is active unless `/opt/carlos/carlos system edge-socket-check` exits 0. |
| - |
| -*The predicate.* `carlos system edge-socket-check` is a new hidden verb. It exits 0 only |
| -when (a) `systemctl show carlos-edge.service` lists the guard drop-in below in |
| -`DropInPaths` (loaded, not just on disk) and the file is byte-equal to the copy this build |
| -embeds, and (b) that unit's effective `ExecStart` argv is exactly one of the two shipped |
| -command lines (§1.1), with no flags. Anything else exits 1 with one line naming why. With |
| -`-self` it exits 0 without checking (witnesses only). Every older build exits non-zero |
| -(§1.3). It reuses `systemdUnits.Show` (`unitsettle.go:60`), extended to keep `ExecStart`'s |
| -argv. As root, `systemctl` uses PID 1's private socket, not D-Bus, so the check also works |
| -at `sockets.target`, before `dbus.service` is up. |
| - |
| -*E-start, the enforcement point.* A drop-in, |
| -`/etc/systemd/system/carlos-edge.service.d/10-edge-socket-guard.conf`: |
| - |
| -``` |
| -[Service] |
| -ExecStartPre=+/bin/sh -c '/opt/carlos/carlos system edge-socket-check && exit 0; systemctl stop carlos-edge.socket || ! systemctl -q is-active carlos-edge.socket' |
| -``` |
| - |
| -It runs before every start of the edge's main process, however triggered (`restart`, |
| -`restart --no-block`, `Restart=always`, boot, socket activation), under any main unit file, |
| -old or new, and on guarded boxes too: a drop-in adds an `ExecStartPre=` without resetting |
| -the others. If the binary on disk fails the predicate, it stops the socket synchronously |
| -and the binary then binds by itself. If the stop fails and the socket is still active, the |
| -line fails, the start fails, and `Restart=always` tries again: fail closed. A socket unit |
| -that is no longer loaded (its file was removed and it is inactive) makes `stop` fail and |
| -`is-active` false, so the line passes. `+` runs this one command as root, exempt from |
| -`User=`, the capability bound and namespacing (`man systemd.service`, table of prefixes). |
| -The line has no `$` or `%`. |
| - |
| -*Why the stop cannot deadlock.* The edge's start job is running when the stop job for the |
| -socket is queued. `man systemd.unit`: "if one unit is shut down and the other is started |
| -up, the shutdown is ordered before the start-up … in all cases". The stop does not wait on |
| -the edge's start. W2 transition 4 checks this on 257. |
| - |
| -*The gate, so E-start is always there.* The socket's own `ExecStartPre=` runs the same |
| -predicate. A socket start fails until the drop-in is loaded. So whenever the socket is |
| -active, E-start runs at every later edge start. Nothing removes the drop-in: no old |
| -applier or script touches directories (§1.3), and this build never removes it. |
| - |
| -*Writers.* Only this build's root code writes the drop-in: `installUnits` (every install, |
| -rollback and recovery this build runs) and `carlos bootstrap` on the live root. Both write |
| -it durably before their `daemon-reload`. It is never written into a `-root` staging tree: |
| -old appliers skip directories there, and the hand script would abort on one. An older build |
| -never writes it. This is what makes activation two-step (§4). |
| - |
| -*Conflicting bind configuration* (an operator's drop-in giving the edge `-http |
| -127.0.0.1:80`, or `-dev`) fails clause (b). So the socket never activates for it, and an |
| -already active socket is stopped at the next edge start. |
| - |
| -**D5. Taking listeners.** |
| - |
| -*At process start.* `takeSystemdListeners` is the first statement of the `edge` and `agent` |
| -verbs (`main.go:65,189`). When `LISTEN_PID == os.Getpid()` and `LISTEN_FDS=N`, it takes |
| -fds 3 to 3+N−1. Each must be `SOCK_STREAM`, `AF_INET`/`AF_INET6` and listening |
| -(`SO_ACCEPTCONN`). It wraps each with `net.FileListener` (a close-on-exec dup, |
| -`$GOROOT/src/net/file_unix.go:18`), closes the original, and unsets `LISTEN_PID`, |
| -`LISTEN_FDS` and `LISTEN_FDNAMES`. It runs first because systemd passes the fds without |
| -close-on-exec and exec children get the agent's environment (`backend_exec.go:2997`). The |
| -guard's `syscall.Exec` keeps the pid (`internal/hostfloor/image_linux.go:61`). |
| - |
| -*At serve time.* Each wanted address (`-http`, plus `-https` outside dev mode) is classified |
| -against the inherited listeners by port: |
| -- **compatible**: same port, and the scope matches. A wanted address with no host takes |
| - a wildcard listener (`::` dual-stack or `0.0.0.0`); a wanted IP literal takes a listener |
| - bound to that IP. It is served with `Serve`/`ServeTLS("", "")`. |
| -- **absent**: no inherited listener on that port. The process binds it, with today's fatal |
| - message on failure (`edge: http listener %s: %v`). |
| -- **incompatible**: same port, different scope. PID 1 holds the port, so a self-bind would |
| - fail. The edge exits at once with `edge: listener %s: systemd passes %s; the socket and |
| - the flags disagree`. The D4 gate keeps this from activating on a box. It is reachable only |
| - by hand. |
| - |
| -An inherited listener on a port nothing wants is closed and logged. PID 1 keeps its copy; |
| -the gate's clause (b) means that cannot happen on a box. The fd code is `//go:build linux` |
| -(`internal/edge/listeners_linux.go`); a `!linux` stub returns nothing. |
| - |
| -**D6. Graceful stop leaves the shared socket alone.** `Shutdown` closes the edge's own dup |
| -(`close(2)`, `net/fd_posix.go:47-50` → `internal/poll/fd_unix.go:91-105`), never |
| -`shutdown(2)`. PID 1's copy keeps the accept queue through the drain and the next startup. |
| -`FileListener`'s `SetNonblock` (`file_unix.go:25`) changes the shared description; PID 1 |
| -only polls. A guard test forbids `shutdown(2)`, `SO_LINGER` and `SO_REUSEPORT` on edge |
| -listeners, and `FlushPending=yes` in the unit. |
| - |
| -**D7. `restartEdge`.** When `/etc/systemd/system/carlos-edge.socket` exists, `reset-failed` |
| -covers the socket as well as the service (a socket refused at an earlier roll is `failed`), |
| -then `restart carlos-edge` as before, like `restartInstanceControl`'s stat |
| -(`systemapply.go:1526-1536`). `Wants=` pulls the socket into the restart, and the old edge's |
| -stop is ordered before the socket's start. Socket state is logged, not gated. |
| - |
| -**D8. Log lines.** At serve time, one of `edge: listeners: inherited 2 from systemd (:80 fd |
| -3, :443 fd 4)`, `edge: listeners: bound :80 and :443 itself (no systemd sockets: LISTEN_PID |
| -unset)`, or a mixed form, plus one line per fd closed unused. The predicate's refusal line |
| -(`edge-socket-check: refused: <why>`) lands in the socket's or the edge's journal. The |
| -morning check is `journalctl -u carlos-edge -u carlos-edge.socket -g 'edge: listeners:|edge-socket-check'`. |
| -These are operator logs, not member copy. |
| - |
| -**D9. Hardening.** `CAP_NET_BIND_SERVICE` stays (`carlos-edge.service:32-33`), because D5 |
| -still binds by itself; dropping it is a later change. `RestrictAddressFamilies=` (`:51`) |
| -filters `socket(2)`, not inherited fds. `@system-service` covers `getsockname`, |
| -`getsockopt` and `fcntl`. E-start's `+` line is the only unconfined command in the edge |
| -unit. It runs the same root-owned binary that `system apply` and recovery already run as |
| -root. |
| - |
| -**D10. Unprobed loopback routes: retry the dial.** One constant, `localDialHold = 13 * |
| -time.Second`, replaces the literals at `genproxy.go:40,86`. `tcpProxy` gets a `DialContext` |
| -when its addr is local (a loopback IP literal by `netip.Addr.IsLoopback`, or `localhost`). |
| -It retries `isRetryableDialErr` (`edge.go:3513`) every 100 ms until it connects or the hold |
| -runs out, then returns the last error (502, `CauseRefused`). A non-local addr keeps the zero |
| -dialer. 13 s is the window already used for unix upstreams and covers the console's ~10 s |
| -gap. |
| - |
| -**D10b. Probed routes with a local upstream: wait for a live one.** The prober records, per |
| -host, whether any configured addr is local (same rule, computed in `newHostProber`; |
| -`multiProxy` still never sees the addr list). `multiProxy`'s dialer then works in passes. |
| -Each pass reads `Live(host)` and dials the live upstreams, ejecting a refused one exactly as |
| -today. When a pass ends with no connection (the live set was empty, or every live upstream |
| -failed) and the host has a local addr, it waits 100 ms and makes another pass. It stops |
| -when a dial succeeds or the hold ends, and then returns `errNoLiveUpstream` (503 + |
| -`Retry-After: 2`, as today). Hosts with no local addr answer at once, as today. |
| - |
| -- *Admission is unchanged.* Only the live set is dialed, and only the prober readmits: |
| - `rise_after` consecutive passing health probes at `interval_ms`. An ejected upstream is |
| - never dialed. A held request just waits for that. |
| -- *The hold:* `localDialHold + rise_after × interval`, capped at 30 s (`localHoldCap`, |
| - `wakeWaitBound`'s value). The first term is the time the upstream is gone. The second is |
| - the most the prober takes to readmit it once it is back, without probing faster than the |
| - operator configured. Defaults: 13 + 2 × 2 = 17 s. |
| -- *Both cases the review named.* A refusal that comes before the probe has noticed anything |
| - ejects the upstream, and the next passes wait for its readmission. A live set already |
| - empty when the request arrives waits from the first pass. |
| -- *Mixed sets.* A live remote upstream that answers serves the request at once. The hold |
| - begins only when nothing live connects. |
| - |
| -D10 and D10b are safe for any method: a failed dial sent nothing, and `RoundTrip` reads no |
| -body before it has a connection. Upgrades take the same dial. Because the dial context is |
| -detached, a client that leaves is released at once and the background dial ends at the |
| -hold. `client_gone`/abandoned rules (`answered.go:55-65`) are unchanged; the comment gains |
| -loopback TCP and probed routes. |
| - |
| -**D11. Cross-compile.** Only D5's fd code is linux-only, with a stub; the predicate verb |
| -shells out to `systemctl` and builds everywhere. CI's darwin and windows builds check it. |
| - |
| -## 4. Every binary/unit mix |
| - |
| -A = this build or later; O = any older build. "Gap" = refused during that restart, as |
| -today. **G** = the socket's gate (D4), **E** = E-start (D4). |
| - |
| -| # | How a box gets there | Socket | Serves? | INV-R held by | |
| -|---|---|---|---|---| |
| -| 1 | O × O units: today | none | Yes, gap | n/a | |
| -| 2 | A × O units: crash between rename `:632` and `installUnits` `:646`; hand-run `carlos agent` | not loaded or inactive | Yes, binds itself, gap | E (if the drop-in exists) | |
| -| 3 | A × A units with the drop-in: steady state, `restart`, `Restart=always`, `stop`+`start` | active throughout | **Yes, 0 refused** | G at start, E passes | |
| -| 4 | **Roll 1:** an O applier installs A (or the hand script does) | enabled by the plan; pulled in by the restart; **G refuses** (no drop-in) and the socket fails | Yes, binds itself, gap as today | G: never active, so nothing in this roll's rollback, recovery or boot can break INV-R, at any failure point | |
| -| 5 | **Roll 2:** an A applier installs A′ | A's `installUnits` writes the drop-in and reloads; `restartEdge` resets the failed socket (D7); A stops, G passes, A′ inherits | Yes. Refused only during A's drain (the switch-over). Row 3 from then on | G then E | |
| -| 6 | Rollback/recovery to an A `carlos.prev` | active throughout | Yes, 0 refused | E passes | |
| -| 7 | Rollback/recovery to an O `carlos.prev` while active (`decidePrev` can keep an old one, `:862-869`), by an A applier or by O running recovery; a failure anywhere in `restoreFiles`/`installUnits`, including a failed `disable --now` (`:1390`) | may stay active | Yes, gap. The next edge start, whatever unit file and however triggered, runs E: O fails, the socket stops, O binds | **E**: the drop-in survives the old unit set (§1.3) | |
| -| 8 | Boot with a journal open | started at `sockets.target` only if G passes for the binary on disk then; recovery may then rename another in | Yes | G, then E at the edge's start (`After=` recovery) | |
| -| 9 | Downgrade through `system update --file` (A applier, O target) | `UnitsRemoved` disables it; if that fails it stays active | Yes, gap | E | |
| -| 10 | Hand script or manual copy of O over an active-socket box | stays active (the script removes nothing) | Yes, gap: E stops it at the script's restart | **E** (formerly "box dark") | |
| -| 11 | Fresh `carlos bootstrap` with A | drop-in written, socket enabled; first `start carlos-edge` activates it | Yes, 0 refused from the first restart | G, E | |
| -| 12 | Live re-run of A's bootstrap on a pre-socket box | only `enable` (D3); drop-in written | The next restart is the switch-over | G | |
| -| 13 | `finish`/`arm`, by any applier | `Armed` never has the socket (D3) | Unchanged | G regardless: `start` cannot skip `ExecStartPre=` | |
| -| 14 | Operator overrides the edge's `ExecStart` with flags | G refuses; E stops an active socket at the next start | Binds per its flags | G, E (clause b) | |
| - |
| -**What is left.** Only someone deleting the drop-in by hand while the socket is active and |
| -then starting an older binary. That is off-road; the morning notes say not to. |
| - |
| -**Two-step activation, and why.** A box updated from a pre-socket build gets the socket at |
| -roll 2, and roll 3 is the first with 0 refused. Fresh boxes get it at once. One-step |
| -(activate at roll 1) would put the socket in front of rollback machinery we cannot change: |
| -the old `installUnits` logs and ignores a failed `disable --now`, its `restoreFiles` can |
| -stop between rename and `disable`, recovery runs `carlos.prev`'s code, and the hand script |
| -copies an old unit set over an active socket. Only a guard that survives an old unit set |
| -covers all of these, which means a drop-in, and only this build writes drop-ins. The cost |
| -is one roll. §10 has a one-roll-sooner variant for Paul. |
| - |
| -## 5. TLS readiness and the latch |
| - |
| -With the socket, the kernel completes the handshake and the connection waits until the new |
| -edge calls `Serve`, which still follows the cert chain (`edge.go:3793` before `:3814`). No |
| -TLS handshake is answered before the mirror, wildcard and autocert are in place. The latch |
| -is unchanged: early activator requests wait up to 30 s, then 503 with `Retry-After`. The |
| -update gate still needs an HTTP answer within its 3 s timeout; it is unchanged. |
| - |
| -## 6. Known limits |
| - |
| -- **Drain.** In-flight requests on the old edge get 10 s, then are cut, as today. New |
| - connections queue through the drain and the new edge's startup (worst case 20 s each for |
| - mirror and home map). A client with a shorter timeout times out. Beyond `somaxconn` |
| - (4096) SYNs are dropped and retransmitted (`tcp_abort_on_overflow=0`). |
| -- **WebSockets** on the old edge drop when it exits; instances restart with the edge |
| - (`BindsTo=`, `units/carlos-instance@.service:14`): part C. |
| -- **Console requests in flight** at its `os.Exit` are reset and still 502, as is a request |
| - with a body on a pooled connection that dies under it. |
| -- **Stopping the edge.** A stopped edge is socket-activated by the next connection; keeping |
| - it down means stopping the socket too. The shelved claim migration's runtime mask |
| - (`claimjournal_migration_linux.go:32`) makes the socket fail on the next connection; after |
| - the unmask the edge binds by itself (row 2). |
| -- **Held dials.** A local upstream that stays down now answers after the hold (13 s for |
| - unprobed routes, about 17 s by default for probed ones, at most 30 s) rather than at once. |
| - That is the trade unix routes already make. A client that leaves is released at once; its |
| - dial goroutine runs to the hold. |
| -- **Changing the socket's ports** later needs a socket restart, which is a gap. |
| - |
| -## 7. Local witness (no cloud, no sudo, 127.0.0.1 only) |
| - |
| -**W1: Go test 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 launches the child through `/bin/sh -c 'LISTEN_PID=$$ |
| -LISTEN_FDS=2 exec "$0" "$@"'` with `ExtraFiles` (`$$` survives `exec`). The child runs the |
| -real `RunWithActivatorReady` (non-dev) on a temp `CARLOS_DATA_DIR`, with `-http`/`-https` on |
| -exactly those addresses. About 8 workers send fresh-connection `GET`s to P and TLS dials to Q |
| -(any HTTP answer or TLS alert counts). Three times over, the parent sends SIGTERM, waits, and |
| -starts the next child after a 1 s delay. Pass: 0 refused, reset or timed-out requests, and |
| -every child logs `inherited 2`. Reported: the worst latency across a restart and each |
| -restart's length. A negative control (children inherit nothing) must count refusals > 0. |
| - |
| -**W2: script, run once by hand on DOCS-T1 with the sandbox off** |
| -(`scripts/edge-roll-witness.sh`; the user bus is closed in the sandbox). It builds this tree |
| -into `$T/new/carlos` and the merge base with main (pre-socket, from `git archive`) into |
| -`$T/old/carlos`, with `T=$(mktemp -d)` and `$T/current` a symlink to `new`. It writes user |
| -units under `$XDG_RUNTIME_DIR/systemd/user`, with every path written literally (no `$` in |
| -unit text), no `User=`/`Group=`: |
| -- `erb-R.socket`: `ListenStream=127.0.0.1:P` and `:Q`, `ExecStartPre=$T/current system |
| - edge-socket-check -self`. |
| -- `erb-R.service`: `Wants=`/`After=` the socket, `ExecStart=$T/current edge -http |
| - 127.0.0.1:P -https 127.0.0.1:Q -registry $T/registry.db -acme-cache $T/acme`. |
| -- `erb-R.service.d/10-guard.conf`: D4's E-start line with `$T/current … -self` and |
| - `systemctl --user` (no `+`). |
| - |
| -Before measuring, it asserts that the socket is active and that the journal shows |
| -`inherited 2`. A curl loop (`--max-time 30`) then runs through five transitions: |
| -1. `restart`: 0 refused. |
| -2. `stop`+`start`: 0 refused. |
| -3. The switch-over shape: the socket stopped, the service bound itself, then `restart`. |
| - It must serve, and the script reports which side bound first. |
| -4. `current` → old, `restart`: it must serve, the socket must be inactive afterwards, and |
| - the restart must return within 10 s (no job deadlock). |
| -5. `current` → new, `restart`: the socket is back and `inherited 2`. |
| - |
| -It reports refusals and worst latency per transition. A `trap` stops the units, removes the |
| -files, reloads and deletes `$T`. W2 exercises the job engine on the user manager of the |
| -same systemd 257; the system manager's `+` is covered by `systemd-analyze verify` and the |
| -unit test of the line. Its numbers go in the #434 reply. |
| - |
| -## 8. Test plan |
| - |
| -Locally only touched packages, with `-run`; CI runs the full set. |
| - |
| -- **INV-R simulation** (`internal/host`, production wiring): a model of PID 1 (unit files |
| - vs loaded state, drop-ins, `daemon-reload`, socket active/failed/enabled, job order) and |
| - of the disk (binary A/O, `carlos.prev`, units, journal). Actors: |
| - - the real `install`, `rollback` and `recoverIfNeeded` over a fake `sysOps` bound to the |
| - model; |
| - - the v0.25.0 `restoreFiles`/`installUnits` and the hand script, transcribed step by step; |
| - - boot: `sockets.target` (G), recovery, then the edge start. |
| - |
| - Each run injects a crash after any step, or a failed `systemctl` call at any step, |
| - including `disable --now`. Every edge start runs the line parsed from the embedded |
| - drop-in, and every socket start runs the real predicate. The invariant is checked at every |
| - modelled `ExecStart` of the edge: never socket active with O on disk. CI runs a fixed 200 |
| - seeds; one 3000-seed sweep by hand per revision (nice 19). |
| -- **Predicate:** passes only with the drop-in loaded and byte-equal, and the shipped argv |
| - (both forms); fails on file-only (not reloaded), a different body, extra flags or `-dev`; |
| - `-self` exits 0; hidden from usage. |
| -- **E-start line**, run under `/bin/sh` with a fake binary and `systemctl` on `PATH`: |
| - - pass: no stop; |
| - - fail with the socket active: stop; |
| - - fail and stop fails while still active: exits non-zero; |
| - - socket not loaded: exits 0. |
| - |
| - `systemd-analyze verify` on the units and the drop-in. |
| -- **Guard tests:** nothing writes into a `-root` staging tree's `carlos-edge.service.d`; |
| - no code removes the drop-in; both writers write it before `daemon-reload`. |
| -- **D2/D3:** embedded units pinned (no `User=`, no `Requires=`/`BindsTo=`/`PartOf=` naming |
| - the socket); socket enabled, never armed; `arm` refuses it. |
| -- **D5:** env and close-on-exec handling; compatible, absent and incompatible cases (wildcard |
| - inherited vs `-http 127.0.0.1:80` exits with the message); non-listening or non-TCP fds |
| - closed. **D8** forms pinned. |
| -- **D6** guard test; **D7** with and without the socket file. |
| -- **D10:** refused then listening within the hold gives 200; past a shortened hold, 502; a |
| - non-loopback addr gives 502 at once; a client cancel returns at once; a POST body arrives |
| - intact; a WebSocket upgrade works after a hold. |
| -- **D10b:** |
| - - a single local upstream refusing before the probe notices, then back: 200 once |
| - readmitted, never a dial to it while ejected; |
| - - the live set already empty: same; |
| - - still down past the hold: 503 with `Retry-After`; |
| - - remote-only route: 503 at once; |
| - - mixed set with a live remote: served at once; |
| - - the hold from `rise_after`/`interval_ms`, capped at 30 s. |
| -- **Witnesses:** W1 in CI; W2 once by hand before handoff. |
| - |
| -## 9. Out of scope |
| - |
| -Part C (`BindsTo=`, #440 item 1). Socket-activating `console.service`. The relay's ports. |
| -`Type=notify`. Dropping `CAP_NET_BIND_SERVICE`. Infra and the hand script. Any AWS, DNS or |
| -box change; release, roll, merge. A drain under 10 s. |
| - |
| -## 10. Open questions and Paul's option |
| - |
| -1. **The switch-over order (row 5).** Does the socket start only after the old edge has |
| - stopped? `man systemd.unit` says shutdown is ordered first, and W2 transition 3 shows it |
| - on 257. Both outcomes serve. |
| -2. **Does 17 s / 13 s cover a real console restart?** It is ~10 s observed; the dev roll |
| - measures it. Raising `localDialHold` (cap 30 s) is a one-line follow-up. |
| -3. **Paul's option, one roll sooner (not taken).** `bootstrap -root` runs as root with the |
| - candidate binary, under both an old applier and the hand script. Letting it also write the |
| - live drop-in (best-effort, root only) would make roll 1 the switch-over. The same INV-R |
| - argument holds, because E-start would exist before the restart. The cost is that a |
| - staging command changes the live box, before the journal and even for a candidate that |
| - is then refused. Not taken without Paul's say. |
| - |
| -## 11. Round 1 dispositions |
| - |
| -1. **P1-1, INV-R: fixed at the root.** INV-R is now stated and enforced in one place |
| - (E-start, a drop-in that survives old unit sets). The socket's gate keeps it from being |
| - active without E-start. Activation became two-step, so no old code meets an active |
| - socket (§4 rows 4-10). The false "active socket implies socket-aware binary" claim is |
| - gone. Every failure point in `restoreFiles`/`installUnits`, boot recovery (which runs |
| - `carlos.prev`'s code), runtime `OnFailure`, rollback by an old applier and the hand |
| - script is covered by row. An INV-R simulation is added (§8). |
| -2. **P1-2, INV-H: fixed.** D10b holds probed routes with a local upstream. It waits for |
| - readmission by the prober and never dials an ejected upstream, and its hold is derived |
| - from `rise_after × interval`. The console route's shape is settled from the repo as |
| - "either", and both are now covered (§1.5). |
| -3. **P2 D5: fixed.** Absent, compatible and incompatible listeners are distinct. An |
| - incompatible one exits with a message, and the gate refuses non-shipped argv before |
| - activation. The availability claim is gone. |
| -4. **P2 floor: fixed.** v0.25.0 and conditional (`systemapply.go:583`). It is no longer |
| - cited, and the design needs no applier baseline (§1.3). |
| -5. **P2 W2: fixed.** `$T/current` is used in every command, there is no `User=`/`Group=`, |
| - and socket active plus `inherited 2` are asserted before measuring. |
| -6. **P2 fd store: fixed.** The table distinguishes `restart`, `no` and `yes`. The deciding |
| - reason is now INV-R: an fd store cannot be cleared from the edge's own start. |
| - |
| -None declined. |
| +| R1 P1-1: recovery leaves an old binary behind an active socket | rollback compatibility | Out of scope by ruling (socket slice, §8) | |
| +| R1 P1-2: probed local upstreams still 503 | restart admission | Fixed here: D10b holds probed routes with a local addr, admission unchanged (§3) | |
| +| R1 P2: closing an unmatched inherited listener | listener ownership | Out of scope by ruling (socket slice) | |
| +| R1 P2: layout floor wrong and conditional | compatibility eligibility | Out of scope by ruling. §8 requires an unconditional floor | |
| +| R1 P2: W2 did not select the built binary | verification identity | Out of scope (W2 went with the socket). The new witness runs this tree's code in-process (§6) | |
| +| R1 P2: fd-store preservation setting | mechanism evidence | Out of scope by ruling (socket slice) | |
| +| R2 P1: guard treats a failed status query as inactive | rollback compatibility | Out of scope by ruling. Listed for the slice (§8) | |
| +| R2 P2: readmission allowance ignores probe timeout and sequential probing | restart admission | Fixed here: `R = r × G + T` with `G = max(I, T) + (N−1) × T`, from normalized and clamped settings. The 30 s cap is kept, and the cases past it are stated (§3). Tests for the delayed probe, the mixed set and past the cap are in §10 | |
| + |
| +## 10. Test plan |
| + |
| +Locally, only `internal/edge`, with `-run`. CI runs the full set. For speed, tests shorten |
| +`localDialHold`, `localHoldCap` and `probeTimeout`; `probeTimeout` becomes a package `var` |
| +for this, like `clientGoneGrace`. |
| + |
| +- **`isLocalUpstream`:** `127.0.0.1:p`, `127.9.9.9:p`, `[::1]:p` and `localhost:p` are local. |
| + `10.0.0.5:p`, `example.com:p` and a malformed addr are not. |
| +- **D10 (`tcp`):** refused then listening within the hold gives 200; past a shortened hold, |
| + 502 with `CauseRefused`; a non-loopback addr gives 502 at once with one dial attempt |
| + (instrumented dialer); a client cancel returns at once; a POST body arrives intact after a |
| + held dial; a WebSocket upgrade works after a hold. |
| +- **D10 (unix):** the existing `dialUnixWithRetry` and `dialGen` tests pass unchanged on the |
| + shared constant and loop. |
| +- **D10b:** a single local upstream refused before the probe notices, then back: 200 once |
| + readmitted, and no connection reaches it while ejected (the upstream counts them). The live |
| + set already empty on arrival: the same. Still down past the hold: 503 + `Retry-After: 2`. |
| + Remote-only route: 503 at once. Mixed set with a live upstream: served at once. |
| + **Delayed probe:** three upstreams whose `/healthz` blocks past a shortened `probeTimeout` |
| + are probed before one restarting local upstream; the request is served at readmission, |
| + inside its computed hold, and the measured readmission is at most `R`. **Past the cap:** |
| + `localDialHold + R` over a shortened `localHoldCap` gives 503 at the cap. `Hold` from raw |
| + `Health{}`, negative interval and negative rise matches the formula on clamped values. |
| +- **D8:** both log forms pinned. A bind failure keeps today's fatal message. |
| +- **Witness:** §6, in CI. |
| + |
| +## 11. Out of scope |
| + |
| +Part C (apps surviving an edge restart; `BindsTo=`, #440 item 1). The socket slice (§8) and |
| +any unit file, root, updater, install, bootstrap, recovery or rollback change. |
| +Socket-activating `console.service`; a console drain; the relay's ports. Any AWS, DNS, infra |
| +or box change, and the hand script. Release, roll and merge. |