carlos / platform Public

edge-roll-blip: spec rev 4, round-3 P2 fixes (hold deadline, per-Edge settings, D8 bind, wake-wait claim)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 91e351a10a211861e1ce93ac63eb507fe407514f parent 72aa7d9
1 file changed, +87 −42
  • docs/superpowers/specs/2026-10-27-edge-roll-blip-design.md +87 −42
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 3f2688343..00f287647 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,8 +1,8 @@
# Edge roll blip (#434 part B): design
-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).
+Status: revision 4, 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). Round 3, the last, was READY AFTER
+FIXES; this revision applies its four P2s and the review is closed (AGENTS.md "Stopping rules" 1).
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,
@@ -62,11 +62,14 @@ 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
+ `internal/activator/activator.go:1572`) and on wakes, then go to the edge's proxy
+ (`:5874,5889`); the activator's own `socketClient` (`backend_exec.go:3430`) only
+ health-checks a waking instance. An ordinary wake wait is bounded by `wakeWaitBound` = 30 s
+ (`:1141`). A first wake extends that to its own budget (`awaitWake`, `:1780`): 55 s for a
+ binary row (`wakeplan.go:231`), a rootfs row's health bound plus the kill reserve
+ (`rootfs_service.go:44`). So 30 s is not a platform maximum. 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
+ the wake hold and an activator route's worst case (its wake wait, 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
@@ -76,16 +79,31 @@ so the design does not need to know which shape a box has.
## 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
+- **One window.** The const `localDialHold = 13 * time.Second` replaces the three literals
+ (`genproxy.go:40,86,312`).
+- **Settings per Edge, not globals.** `New` stores `localHold{dial: localDialHold, cap:
+ localHoldCap, probe: probeTimeout, dialer: nil}` on the Edge and builds its prober set with
+ `newProberSet(hold)`, which uses `probe` for its client and all three for `Hold` (§3).
+ `tcpProxy` and `multiProxy` take them from their Edge at Reload; `dialer` is a test seam
+ (nil means a `net.Dialer`); the consts are the defaults. Unix paths keep the const. A test
+ sets its own Edge's values before its first Reload. No test changes a package global, so
+ parallel witnesses cannot see each other's settings, and a detached dial that outlives its
+ test touches only its own Edge.
+- **One deadline.** `dialUnixRetrying`'s loop becomes `retryLocalDial(ctx, deadline, attempt)`.
+ The caller fixes `deadline` once, on entry, before the first attempt. Each attempt runs on
+ `context.WithDeadline(ctx, deadline)` and each wait is min(100 ms, time left), so no attempt
+ or wait outlives the hold. It retries while `isRetryableDialErr`. Outcomes: connected; a
+ non-retryable error, at once; the deadline passes after a retryable error, which is
+ returned (502, `CauseRefused`); the deadline cuts an attempt that had not failed on its
+ own, giving `errHoldExpired` wrapping `context.DeadlineExceeded` (502, `CauseTimeout`, by
+ `proxyCause`'s existing rule, `edge.go:605`). A client cancel never reaches the dial (it is
+ detached, §1.1); `proxyCause` checks the request's context first (`:595`), so a leaver
+ stays `client_gone` or `CauseAbandoned`. `dialUnixRetrying` and the new TCP dial call it.
+ `dialGen` keeps its own loop (each attempt also checks for a generation move) with the same
+ deadline and per-attempt context.
+- **Which TCP addrs.** `tcpProxy(addr, hold)` 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.
@@ -101,13 +119,22 @@ failure, return the first connection). When a pass ends with no connection and t
`errNoLiveUpstream` (503 + `Retry-After: 2`, `CauseNoUpstream`). A host with no local addr
answers at once, as today.
+**One deadline.** For a local host the dialer fixes `deadline = entry + hold` once, before the
+first pass. Each dial runs on `context.WithDeadline(ctx, deadline)` and keeps
+`multiDialTimeout`, so an attempt ends at the earlier of 3 s and the deadline. Each wait
+between passes is min(100 ms, time left). An attempt the deadline cuts (its own context done,
+the dial context not) is budget exhaustion, not upstream failure: no `Eject`, and the dialer
+returns `errNoLiveUpstream` (503, `CauseNoUpstream`). An attempt that fails on its own
+(refused, or its 3 s timeout before the deadline) ejects as today. A non-local host gets no
+deadline.
+
**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`
+`run` and `record` use), `T` = the set's `probe`. One probe of a given addr starts at most `G`
after the one before it:
G = max(I, T) + (N − 1) × T
@@ -119,9 +146,10 @@ probes of the same addr. Once the upstream answers again, its `r`-th pass comple
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.
+and the request's hold is `hold = min(dial + R, cap)` (defaults 13 s and `localHoldCap` =
+30 s): the time the upstream may be gone, plus its readmission once back. The cap is D10b's own
+policy, set equal to the ordinary wake wait (`wakeWaitBound`); first wakes can wait longer
+(§1.2). The hold bounds the wait for a connection; the response then takes what it takes.
| Defaults (I 2 s, r 2, T 2 s), every other addr black-holed | G | R | hold |
|---|---|---|---|
@@ -135,8 +163,8 @@ many addrs that time out rather than refuse, i.e. black-holed remote upstreams i
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
+as today, only later; a retry after readmission is served. The cap is not raised: a request
+held longer than an ordinary wake wait is worse than an early 503 the client can retry. `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.
@@ -146,7 +174,7 @@ the upstream stays down: the request then waits the full hold before its 503.
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
+ detached dial runs to its hold and never past it (§2, §3); 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
@@ -156,16 +184,19 @@ the upstream stays down: the request then waits the full hold before its 503.
## 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:
+**D8.** At serve time the edge binds before it serves. `listenAddr(flag, def)` first maps an
+empty flag to `:http` or `:https`, as `ListenAndServe` and `ListenAndServeTLS` do
+(`$GOROOT/src/net/http/server.go:3372,3727`); then `net.Listen("tcp", ...)` for http, then
+https (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, "", "")`, which is what `ListenAndServe(TLS)` does after its own
+normalization and bind, so the behaviour is unchanged. The line gives each listener's actual
+address (`ln.Addr()`, so a `:0` flag shows the allocated port), then the flags (`edge.go:3549-3550`):
- edge: listeners: bound :80 and :443 itself
- edge: listeners: bound :80 itself (dev mode)
+ edge: listeners: bound http [::]:80 and https [::]:443 itself (flags ":80" ":443")
+ edge: listeners: bound http 127.0.0.1:8080 itself (dev mode; flag "127.0.0.1:8080")
-Addresses are the flag values (`edge.go:3549-3550`). Unlike today's `serving N route(s)`,
+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
@@ -178,7 +209,7 @@ 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
+under `-short`; its subtests run in parallel, each on its own Edge (§2), 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
@@ -199,8 +230,8 @@ latency minus the baseline p50. The max added wait must stay under gap + 1 s for
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 #434 reply quotes these numbers. **Negative control:** the `tcp` case runs again on its own Edge with
+a dial hold of 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.
@@ -261,30 +292,44 @@ rule 2 triggered; the choice went to #434; Paul ruled on 2026-10-28: option 2 no
| 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 |
+R3 (brief `70a10389`): READY AFTER FIXES, no P1, 4 P2, no P3. P2s fixed:
+- Hold deadline (bounded dial lifetime): one absolute deadline from entry bounds every attempt
+ and wait; budget exhaustion is its own outcome, never ejects (§2, §3; tests §10).
+- Witness isolation (verification isolation): hold settings and probe timeout live on each
+ Edge, injected by tests; no package global is mutated (§2, §6, §10).
+- D8 binding (startup bind compatibility): empty flags normalized to `:http`/`:https` before
+ binding; the line logs `ln.Addr()` beside the flags (§5).
+- Wake-wait claim (timeout-contract accuracy): 30 s is the ordinary wake wait and D10b's own
+ cap; first wakes extend beyond it (§1.2, §3).
+
## 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`.
+their own Edge's dial hold, cap and probe timeout (§2); no test changes a package global.
- **`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.
+ held dial; a WebSocket upgrade works after a hold. **Blocking attempt:** an attempt that blocks until its
+ context ends returns at the deadline (502, `CauseTimeout`), not after it.
- **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`
+ Remote-only route: 503 at once. Mixed set with a live upstream: served at once. **Deadline mid-pass:** a mixed set whose
+ live remote addr's dial blocks (instrumented dialer) gives 503 `CauseNoUpstream` at the
+ hold, and that addr is still live afterwards (not ejected).
+ **Delayed probe:** three upstreams whose `/healthz` blocks past a shortened `probe`
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
+ `dial + R` over a shortened `cap` 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.
+- **D8:** `listenAddr` maps `""` to `:http`/`:https` and keeps an explicit addr; a
+ `127.0.0.1:0` bind logs the allocated port; both log forms pinned. A bind failure keeps
+ today's fatal message.
- **Witness:** §6, in CI.
## 11. Out of scope