design: tunnel WebSockets (#471), spec rev 4 (Astra R3 P2s)
Astra round 3 READY AFTER FIXES (no P1). Its two P2s applied with no further round: - R3-1: case 12's backstop witness uses a writer whose Hijack returns http.ErrNotSupported (passed through unchanged by countingWriter and slotWriter), asserts the body stays open until the request context is cancelled and that the AfterFunc releases it; the §4.6.2 table and §3.5 tell unsupported hijacking apart from other hijack errors. - R3-2: case 18 made deterministic: TryLock contention while A is paused, explicit hook barriers around publication, sweep and the watcher's fingerprint record, an exact event sequence, a test tick channel for Watch; removing the lock fails at the TryLock step. Status: awaiting Paul's approval. R3 findings committed alongside.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-R3.md+29 −0docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md+85 −37
CI failed — run details
Intent
<task-notification> <task-id>ae788846b0095491a</task-id> <tool-use-id>toolu_01AdePa67KNao35o2beQc9q5</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/ae788846b0095491a.output</output-file> <status>completed</status> <summary>Agent "Draft #471 WebSocket tunnel spec" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Spec rev 3 answers both round-2 findings. It is pushed, and `ls-remote` confirms the branch tip on amadan is **623160c0**. - **54105d75**: spec rev 3, plus the R2 findings file committed alongside it. - **623160c0**: `CODEX-REVIEW-BRIEF-tunnel-websockets-R3.md`. It is round 3 of 3, carries the dispositions for R1 and R2 and your rulings from both rounds, and says that a NOT READY must state whether its P1s share one cause and whether refusing or cutting would remove them. Stopping rule 2 has triggered: R1-1 and R2-1 are the same fault family (an open socket must not outlive the tenancy that admitted it). Your ruling takes its third option: enforce the invariant in one place and check it with a deterministic witness and a guard test. The spec's review history records this. **R2-1 (P1, concurrent Reloads can publish a stale map):** - `e.reloadMu` is taken as the first statement of `Reload` and held until it returns. That covers the registry reads, the build, `SetDynamicAuth`, the map swap and the upgrade sweep. Because the lock sits inside `Reload`, all six callers take it automatically: startup in `New`, `EnableStatic`, `enableTunnelsFromEnv`, `Watch`, SIGHUP, and the layout pass. - `Watch` already records a fingerprint only after its own `Reload` returns nil. With the lock, that return now means its Reload has swapped and swept. - Lock order: `reloadMu` is outermost. `TunnelHub.mu`, the prober and activator locks, and the upgrade registry's lock are taken under it one at a time, never nested. Admission and request serving never take `reloadMu`. - The sweep removes stale reservations under the registry lock, then closes them on separate goroutines, so no network teardown happens under a lock. - New test, case 18: two Reloads interleaved deterministically through hooks, in both orders, including the watcher's fingerprint bookkeeping. It fails on rev 2's code. - New test, case 19: a guard test that keeps one publication site for the map, inside `Reload` and after the lock. **R2-2 (P2, `ModifyResponse` failure closes the body):** - Confirmed at `reverseproxy.go:395-397`. §3.5 and the release table in §4.6.2 are corrected. - The test for the fallback release on request end now uses a path where the body really stays open: the hub behind a writer that cannot hijack (`:854-857`). The test checks that the fallback was what released it. - A separate test case checks that a `ModifyResponse` failure releases through the body. - The other two body-left-open paths (upgrade-type mismatch, body not writable) cannot be reached from this transport. `RoundTripUpgrade` refuses a mismatched token itself, and always returns a writable body. **What my own sweep found** (new spec §4.6.3, which lists every path that publishes or reads the routing map): - **The only real hole was the unlocked `Reload`**, now fixed by R2-1. - **Only `Reload` publishes the map:** `e.upstreams.Store` has one call site, and `SetDynamicAuth` (detach, rotation) is called only from `Reload`. - **Re-registration:** when a box reconnects, its old connection's streams end and release their slots. The map is untouched. - **Fingerprint:** it covers routes (account, app, region, tunnel), fleet owners, and fleet-box tokens and status, so every tenancy change moves it. - **Registry reads:** the reads that decide tenancy (`List`, `FleetChannelAuth`, `ListFleets`) all use fresh connections. - **`ListRegional` (pre-existing, left as is):** it reads through the registry's long-lived connection, so it can return stale rows. That cannot re-authorise a socket, because regional rows only copy or deny entries already in the map, and refused hosts are removed after that step (`edge.go:1208`). - **Hub restart:** the new process starts with an empty registry, so no stale reservation can survive. **Earlier findings:** R1-2 to R1-5 were resolved in round 2. R1-1 was partly resolved and is carried forward as R2-1. Scratch: none.</result> <usage><subagent_tokens>336410</subagent_tokens><tool_uses>22</tool_uses><duration_ms>279547</duration_ms></usage> </task-notification>
<task-notification> <task-id>a98789208013c1a20</task-id> <tool-use-id>toolu_01T34mzDfYUFH5DvzA1jm5af</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a98789208013c1a20.output</output-file> <status>completed</status> <summary>Agent "Fleet routes deferred minors branch" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I've closed every follow-up on your list on branch `fleet-routes-followups`, in a worktree off `origin/main` 65fd8060. All the touched packages' tests pass at the tip. The census fails without its overlay, so I wrote one; it is committed and waits for a reviewer. Nothing is pushed or merged, nothing is posted on amadan, and no reviewer was briefed. Worktree: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/fleet-routes-followups` **Commits** | commit | area | |---|---| | `e25a0b37` | registry (Tasks 1 and 2) | | `ad3f0587` | edge (Task 5) | | `ae399312` | console (Task 11) | | `f356645e` | host (Task 12) | | `27fe53bb` | one owner-map fold, `Registry.FleetOwners` (spans registry, edge and host) | | `894f6fba` | e2e (Task 13) | | `f9577127` | docs | | `931ba8d3` | census overlay | `27fe53bb` is one item you didn't name: Astra's R2 triage marked "Reload's inline owner-map construction" as a follow-up. The edge's `Reload` and the hub's `hubFleetOwners` both built the fleet-to-account map by hand. Both now call `Registry.FleetOwners`. There is no behaviour change, but it adds `Edge.Reload` and a new unit to the census card. **Done, with RED/GREEN or mutations** - **Task 1:** new test `TestSetFleetBoxIfMembershipIsTheRowsOwnFleet`. Dropping the subquery's `fleet = ?` fails only this test. - **Task 2:** - `PutForward`'s update list is now built from one production list, `forwardKept`. It is checked with `ForwardForbidden` against PRAGMA, and a new test reads the generated SQL back. - `dns_checked_at` is now asserted to survive a put. - `PutForward` now refuses a non-forward kind, an empty Host or a non-fleet Region with a new sentinel, `ErrNotForward`, added to `remoteErrors`. - RED was the build failing on the missing symbols. Four mutations were each caught: dropping a kept column, taking `dns_checked_at` from the call, admitting an empty host, admitting a non-fleet region. - The 50-vs-51 count: no committed doc said 51. The plan now says "50 fields", which matches the code. - **Task 5:** - The upgrade-close test now checks the request's context is actually cancelled. A close that counts but never cancels passed the old test and fails the new one. - New test for the plain HTTP plan-throttle path on a forward row. A mutation skipping the throttle only on that path is caught only by it. - New test for the fleet box's plan-throttle exemption for tunneled requests. Dropping the exemption fails it. - The long comment in `ratelimit.go` is rewrapped. - **Task 11:** fixed the stale `fleetFromRoutes` comment (and the same phrase in `view.go`), merged the duplicate loop into `firstFleetPlacement`, and rewrapped the long `sealkey.go` comment. New test `TestFleetFromRoutesSplitOnForwardRows`: the display reader keeping forward rows was not pinned before, and a mutation making it skip them passed every console test. - **Task 12:** - `hub.go`, the budget test and spec §7 no longer say the phase and edge cannot disagree. They now say the two converge and fail closed. - The budget test now checks the edges-file PUT when the row goes. A writer that skips PUTs which only shrink the file passed the old test and fails the new one. - The counting-store note is in the test doc, and the §6 baseline clause is in the spec. - **Task 13:** - Step 6 now checks the catch-all name is refused right after the trash, with a precondition that it served just before. A stale-alias mutation is caught only by this. - Step 3 has the `oks <= 6` upper bound. A path rule admitting two over its burst passed the old check and fails this one. - The first dial is quieter: the hub's pass runs before the box dials, so there is no 401. The test now fails on that 401, and the old order fails it. - Step 2 pins that the box drew the login form: the request is counted on both edges. This one has no mutation. - Step 4 now gets the owner map from `FleetOwners` and passes Region, which it omitted. - The carry about a foreign account's record in the edges file: Task 6's tests already cover it, no change. **Skipped, and why** - **#471 WebSockets:** the vacuous `ups > 2` check, the 101-or-502 acceptance, and the box-side upgrade exemption. - **Needs copy (stopped there):** C08 has no fitting wording for the case where there is no fleet to name. No user-facing strings were touched anywhere else. - **Task 13, certificates:** a retired name with an existing certificate still completes the TLS handshake and is refused only at HTTP. That is a TLS-layer behaviour change, not a minor. - **Task 13, the `status/boxes` 404:** the fleet box's store door answers 404 to that read in production too, so the test keeps the noise. - **Others:** the test-report noise is not a code item, and the unhashed Runtime in the fingerprint is pre-existing. - All dispositions are recorded at the end of `docs/superpowers/reviews/fleet-public-routes-deferred-minors.md`. **Census** - `TestPlan14RootReadCensus` failed with 13 discrepancies; Plan9B8 passed, so no record-write re-pin was needed. I ran `make census-propose NAME=fleet-routes-followups`, and with the overlay `go test ./internal/provision/ -run 'Census|Plan14|Plan9B8'` passes. - Card: `docs/superpowers/notes/census-proposal-fleet-routes-followups.md`. Seal `bca6ef74…` → `1379d066…`. It lists five units: - `Edge.Reload`: the owner map now comes from `FleetOwners`. - `Registry.PutForward`: the new up-front Host and Region checks. - `var putForwardSQL`: now reads `forwardKept`. - `Registry.FleetOwners`: new. - `hubFleetOwners`: no longer reads anything itself. - It also re-pins the registry field list (adds `OnConflict`) and the `internal/edge`, `internal/host` and `internal/registry` envelopes. - Claims file: `/home/paulca/.cache/tmp/claude-1001/fleet-routes-followups/claims.tsv`, kept in case the proposal needs rerunning. All other scratch is deleted. **Checks:** gofmt is clean, `go build ./...` and vet pass, and the darwin (amd64 and arm64), windows/amd64 and linux/arm64 builds pass. The full e2e test and the root package's forward tests pass.</result> <usage><subagent_tokens>262721</subagent_tokens><tool_uses>118</tool_uses><duration_ms>2436703</duration_ms></usage> </task-notification>
<task-notification> <task-id>b7ub6hkiz</task-id> <tool-use-id>toolu_01NjHh64tMA2GeD2hCsEGZYg</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/b7ub6hkiz.output</output-file> <status>completed</status> <summary>Background command "Run Astra round 3 on the #471 spec" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 43.1 g CO₂e (5,648,627 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-tunnel-websockets-471, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-R3.md b/docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-R3.md| new file mode 100644 |
| index 000000000..cafb53702 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-R3.md |
| @@ -0,0 +1,29 @@ |
| +- **R1-1 (P1): resolved.** Serializing registry reads, publication and sweep closes the stale-map race. |
| +- **R1-2 (P2): resolved.** Exactly-once reservation cleanup remains sound. |
| +- **R1-3 (P2): resolved.** The restart witness closes established connections and exercises re-registration. |
| +- **R1-4 (P2): resolved.** Production-cap saturation and separate SETTINGS/WINDOW_UPDATE checks remain specified. |
| +- **R1-5 (P2): resolved.** The unsupported TLS claim remains withdrawn. |
| +- **R2-1 (P1): resolved.** The mutex inside every `Reload` fixes publication ordering; the regression witness needs the P2 correction below. |
| +- **R2-2 (P2): partly resolved.** The `ModifyResponse` classification is correct; the replacement backstop witness still exercises body cleanup. |
| + |
| +1. **P2 — §8.2 case 12: the non-hijacking wrapper does not isolate the backstop.** |
| + |
| + **Evidence:** [Spec:1070](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md:1070) expects the unsupported-hijacking return. But the edge unconditionally installs `countingWriter` at [edge.go:2009](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/internal/edge/edge.go:2009). Its `Hijack` returns a plain `fmt.Errorf` when the underlying writer lacks hijacking ([usagemeter.go:138](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/internal/edge/usagemeter.go:138)). That error does not match `http.ErrNotSupported`: the proxy installs its body closer before returning through the generic hijack-error branch ([reverseproxy.go:854](/home/paulca/.local/go-dist/src/net/http/httputil/reverseproxy.go:854), [reverseproxy.go:860](/home/paulca/.local/go-dist/src/net/http/httputil/reverseproxy.go:860)). |
| + |
| + **Failure scenario:** Body cleanup races the request-context backstop. The first-releaser assertion becomes nondeterministic, and cleanup still works with the backstop disabled. |
| + |
| + **Fix:** Use a test writer whose `Hijack` explicitly returns `http.ErrNotSupported`, which the edge wrappers propagate unchanged. Assert the body stays open until request cancellation, then assert `AfterFunc` releases it. Qualify §4.6.2’s table to distinguish unsupported hijacking from other hijack errors. |
| + |
| + **Fault family:** R2-2 — cleanup-witness accuracy. |
| + |
| +2. **P2 — §8.2 case 18: the stated schedule does not deterministically reject rev 2.** |
| + |
| + **Evidence:** [Spec:1113](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md:1113) starts B, then resumes A. Both proposed hooks occur after registry reads. A hook “never firing” does not establish that B reached lock acquisition. The existing unsynchronized publication is at [edge.go:1234](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/internal/edge/edge.go:1234). |
| + |
| + **Failure scenario:** Without the mutex, A can finish publication and sweep before B runs. B then publishes the revoking map and closes the socket. Every final assertion passes despite the missing serialization. |
| + |
| + **Fix:** Add a deterministic contention assertion while A is paused—for example, assert `reloadMu.TryLock` fails—and explicit barriers around publication, sweep and fingerprint recording. Verify that removing the lock fails the witness without depending on scheduling delays. |
| + |
| + **Fault family:** Regression coverage for the R1-1/R2-1 tenancy invariant. The serialization mechanism itself is sound. |
| + |
| +READY AFTER FIXES |
| \ No newline at end of file |
diff --git a/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md b/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md| index 0247109fd..0dd80a2dc 100644 |
| --- a/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md |
| +++ b/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md |
| @@ -1,6 +1,6 @@ |
| # Tunnel WebSockets: upgraded connections through the fleet tunnel |
| -Status: DRAFT rev 3, 2026-10-30. Discussion: amadan carlos/platform #471. |
| +Status: DRAFT rev 4, 2026-10-30. Discussion: amadan carlos/platform #471. |
| Branch `design-tunnel-websockets-471`, cut from main `65fd8060` (fleet |
| public routes, #457 Phase 1a). Every repo file:line below is on that |
| commit. Library lines are `golang.org/x/net v0.60.0` (`go.mod:28`) and the |
| @@ -32,19 +32,26 @@ Revisions: |
| leave the body open (R2-2, §3.5, §4.6.2, §8.2 case 12). Also the |
| author's sweep of every path that publishes or reads the routing map |
| relative to the upgrade registry (§4.6.3). |
| +- Rev 4: Astra round 3 (`CODEX-FINDINGS-tunnel-websockets-R3.md`, READY |
| + AFTER FIXES, no P1; R1-1 to R1-5 and R2-1 resolved, R2-2 partly). Its |
| + two P2s applied with no further round, marked **(R3-n)**: case 12's |
| + backstop witness uses a writer whose `Hijack` returns |
| + `http.ErrNotSupported`, and the §4.6.2 table tells that apart from |
| + other hijack errors (R3-1); case 18 is made deterministic with a |
| + `TryLock` contention check and explicit barriers around publication, |
| + the sweep and the fingerprint record (R3-2). |
| Review history: Astra R1 NOT READY (1 P1, 4 P2); R2 NOT READY (1 P1, |
| 1 P2). R1-1 and R2-1 are one fault family (an open socket cannot outlive |
| its admitting tenancy), so stopping rule 2 has triggered; the |
| controller's ruling takes its third option: state the invariant, enforce |
| it in one place (the reload mutex), and check it with a deterministic |
| -interleaving witness and a guard test (§8.2 cases 18 and 19). This is the |
| -text for round 3 of 3, the last. |
| +interleaving witness and a guard test (§8.2 cases 18 and 19). Astra R3 |
| +READY AFTER FIXES; its P2s are applied in rev 4 with no further round. |
| ## 0. Status |
| -Rev 3. Astra R1 and R2 NOT READY; every finding taken. No open |
| -questions: the controller ruled on all five (§11) and on both rounds. |
| +rev 4. Astra R1 NOT READY, R2 NOT READY, R3 READY AFTER FIXES (P2s applied); awaiting Paul's approval. |
| ## 1. Intent |
| @@ -224,8 +231,14 @@ From 1a's Task 5 (fleet public routes spec §4.8): |
| handler (`modifyResponse`, `:395-397`), on a 101 (`:590`) as on any |
| response. On a 101 the proxy drops the response **without** closing |
| its body when the upgrade types differ (`:842-845`), when the body is |
| - not writable (`:847-851`) or when the writer cannot hijack |
| - (`:854-857`). An ordinary response's body is closed by a defer |
| + not writable (`:847-851`) or when the writer's hijack fails with |
| + `http.ErrNotSupported` (`:854-857`). Any other hijack error comes |
| + after the proxy has installed its body closer (`:860-870`, `:872-875`), |
| + so that body is closed. The edge's own wrappers turn a writer with no |
| + `Hijack` at all into a plain error (`countingWriter.Hijack`, |
| + `usagemeter.go:138-144`; `slotWriter.Hijack`, `ratelimit.go:235-242`), |
| + which takes the closing branch; they pass a real `Hijack`'s |
| + `ErrNotSupported` through unchanged. **(R3-1)** An ordinary response's body is closed by a defer |
| (`:620`). **(R2-2)** What does always happen: `net/http` cancels |
| the inbound request's context when `ServeHTTP` returns, hijacked or not |
| (`net/http/server.go:2087-2089`). **(R1-2)** |
| @@ -712,7 +725,8 @@ Who calls `release()`, by terminal path: |
| | ordinary refusal or any response without the marker | the wrapped body's `Close`, which the proxy defers (`reverseproxy.go:620`) | |
| | 101, then the socket closes | the upgraded body's `Close` (proxy, `reverseproxy.go:860-870`) | |
| | `ModifyResponse` fails, on a 101 or any other response **(R2-2)** | the body's `Close`: the proxy closes it before its error handler (`reverseproxy.go:395-397`) | |
| -| 101 dropped by the proxy with its body open: the writer cannot hijack (`reverseproxy.go:854-857`) | the backstop | |
| +| 101 dropped by the proxy with its body open: the writer's `Hijack` returns `http.ErrNotSupported` (`reverseproxy.go:854-857`) **(R3-1)** | the backstop | |
| +| 101 with any other hijack error, including the edge wrappers' error for a writer with no `Hijack` (`usagemeter.go:138-144`) | the body's `Close`: the proxy installed its closer first (`reverseproxy.go:860-870`, `:872-875`) | |
| | 101 dropped for an upgrade-type mismatch or a body that is not writable (`:842-851`) | not reachable from this transport: `RoundTripUpgrade` refuses a mismatched token itself (§4.3 step 9, released by `transportFor`) and always returns a writable body; the backstop would cover them if it were | |
| | the sweep (§4.6.1), `CloseAccountUpgrades`, client gone | the sweep calls it on its own goroutine after removing the reservation; the others through the backstop | |
| @@ -889,7 +903,10 @@ release floor is needed. |
| (take, `release` once, backstop), `tenancy`, and `Edge.sweepUpgrades` |
| **(R1-1, R1-2)**. |
| - `internal/edge/edge.go`: `Edge` gains `reloadMu`; Reload takes it |
| - first and holds it to the end **(R2-1)**, sets `upstream.tenancy` in |
| + first and holds it to the end **(R2-1)**, with nil-by-default test |
| + hooks at `enter`, `afterRead`, `beforePublish`, `afterPublish` and |
| + `afterSweep`, and `Watch` a test tick channel and record hooks |
| + (**R3-2**, §8.2 case 18); sets `upstream.tenancy` in |
| the three tunnel arms and calls `sweepUpgrades` right after the map |
| swap (`:1234`); the upgrade branch puts the admission on the context; |
| `fleetProxy` and `tunnelProxy` scrub the two marker headers in |
| @@ -1067,14 +1084,21 @@ Cases, each against the same scene: |
| - `ModifyResponse` failing on the 101: released by the body's |
| `Close`, observed from inside the proxy's error handler, before the |
| request ends (`reverseproxy.go:395-397`); |
| - - the backstop, on a path that really leaves the body open: the hub |
| - served through its real `http.Server` behind a wrapper whose |
| - `ResponseWriter` does not implement `http.Hijacker`, so the proxy |
| - takes `reverseproxy.go:854-857` and returns without closing the |
| - 101's body. The count stays 1 while the handler runs, is 0 once |
| - `net/http` cancels the request context, and the first releaser is |
| - the `AfterFunc`. The box sees its stream reset and closes the |
| - app's socket. |
| + - the backstop, on a path that really leaves the body open |
| + **(R3-1)**: the hub served through its real `http.Server` behind a |
| + wrapper whose `ResponseWriter` implements `Hijack` and returns |
| + `http.ErrNotSupported`. The edge's `countingWriter` and |
| + `slotWriter` pass that error through unchanged, so the proxy takes |
| + `reverseproxy.go:854-857` and returns before installing its body |
| + closer. The wrapper's handler then blocks on a test barrier, so |
| + the request is still live: asserted, the 101's body has not been |
| + closed (the reservation's first-releaser record is empty and the |
| + count is 1). The test releases the barrier; `net/http` cancels the |
| + request context; asserted, the count is 0 and the first releaser |
| + is the `AfterFunc`. The box sees its stream reset and closes the |
| + app's socket. A second variant, a writer with no `Hijack` at all, |
| + asserts the other row: released through the body, not the |
| + backstop. |
| 13. Maximum load **(R1-4)**, at the production values (`MaxStreams` 250, |
| `StreamWindow` 1 MiB, `ConnWindow` 160 MiB, cap 128), on one tunnel: |
| - 128 upgrades open, every app side not reading, and each client |
| @@ -1107,26 +1131,50 @@ Cases, each against the same scene: |
| handshake resumes and is refused at reservation (502), and the app |
| sees nothing. With the hook pausing between reservation and the |
| stream instead, the sweep closes it. |
| -18. Two Reloads interleave **(R2-1)**, deterministically, with test hooks |
| - in `Reload` after the build (before taking the swap path) and after |
| - the swap (before the sweep). A socket is open on a forward row. |
| - Reload A starts while the fleet's owner is the row's account and is |
| - paused after its build; the owner changes in the registry; Reload B |
| - is started; A resumes. Asserted with the reload mutex: B cannot read |
| - the registry until A has swapped and swept (B blocks on `reloadMu`, |
| - observed through the hook never firing for B while A is paused); |
| - after both, the current map is B's (the host refused), the socket is |
| - closed at both endpoints within 2 s, and a new handshake is refused. |
| - Fingerprint bookkeeping: the same interleaving with B driven by the |
| - real `Watch` loop (A from a direct call standing in for SIGHUP); |
| - `Watch` records the new fingerprint only after B's Reload has |
| - swapped and swept (a hook on the record), and a Reload that fails |
| - after the owner change records nothing, so the next tick retries and |
| - closes the socket. The same case with the order reversed (B revoking |
| - first, A authorising after, reading the newer registry) ends with |
| - the host refused too, because A's read happens after B's swap. The |
| - test fails on rev 2's code (no `reloadMu`): there A publishes its |
| - stale map after B and the socket survives. |
| +18. Two Reloads interleave **(R2-1, R3-2)**, with no sleeps and no |
| + timing assumptions. `Reload` has nil-by-default test hooks at five |
| + points: `enter` (before taking `reloadMu`), `afterRead` (after the |
| + registry reads), `beforePublish`, `afterPublish` (after the swap) |
| + and `afterSweep`; `Watch` has a test tick channel in place of its |
| + ticker and hooks `beforeRecord` and `afterRecord` around |
| + `last = fp`. Each hook appends its event to a shared log and, where |
| + the test installs one, blocks on a barrier until the test releases |
| + it. A socket is open on a forward row. |
| + 1. Reload A (a direct call, standing in for SIGHUP) runs while the |
| + fleet's owner is the row's account and stops at its `afterRead` |
| + barrier. |
| + 2. The owner changes in the registry. |
| + 3. Contention: `e.reloadMu.TryLock()` returns false. This step alone |
| + decides the mutation check: with the `Lock` call removed, |
| + `TryLock` succeeds here and the case fails at once, before |
| + anything that depends on scheduling. |
| + 4. The test ticks `Watch`. It reads the new fingerprint and calls |
| + Reload B, whose `enter` event appears in the log. `TryLock` |
| + still returns false, and the log holds no `afterRead` for B: B |
| + has not read the registry. |
| + 5. The test releases A's barriers one at a time and checks the log |
| + after each: A `beforePublish`, A `afterPublish` (the current map |
| + is A's, authorising), A `afterSweep` (the socket's reservation is |
| + still current, which is right for A's map). A returns. |
| + 6. B proceeds: the log shows B `afterRead`, `beforePublish`, |
| + `afterPublish` (the current map is B's: the host refused), |
| + `afterSweep` (the reservation is gone from the registry), then |
| + `Watch` `beforeRecord` with the new fingerprint, then |
| + `afterRecord`. The exact event sequence is asserted, so |
| + publication, the sweep and the record cannot be reordered. |
| + 7. The socket is closed at both endpoints (each observed close is an |
| + event the test waits for, with a 2 s failure bound), and a new |
| + handshake is refused. |
| + 8. Failure bookkeeping: the same schedule with B's `afterRead` hook |
| + returning a registry error. The log shows no `beforePublish` for |
| + B and no `beforeRecord`; the next test tick starts Reload C, which |
| + swaps, sweeps and closes the socket, and only then is the |
| + fingerprint recorded. |
| + 9. Reversed order: B (revoking) runs to its `afterSweep` first, then |
| + A is started after the owner change; A's `afterRead` follows B's |
| + return in the log, A reads the newer registry, and the host stays |
| + refused. |
| + |
| 19. Guard test: a go/ast check over `internal/edge` that |
| `e.upstreams.Store` has exactly one call site, inside `Reload`, and |
| that `Reload`'s first statement locks `e.reloadMu` with a deferred |