carlos / platform Public

plan: tunnel WebSockets (#471), rev 2 (Astra plan R1)

Astra plan round 1 NOT READY (2 P1, 4 P2), every finding taken with the
controller's rulings (platform-60):
- P1-1: the real-loop witnesses re-run their test binary as a child with
  SSL_CERT_FILE naming a fixture CA (runTrustedChild, linux only);
  tunnelclient.Dial unchanged; the child first proves a connected
  channel, and an unknown-CA control never connects.
- P1-2: the sample's script submits "Enqueue a job" with fetch (same
  POST, the form's CSRF token, no navigation); PingJob broadcasts done
  and total, so the page updates from the broadcast alone.
- P2-3: Config.Limits reaches serveUntilDead/ServeWith, tested through
  the real Loop; Loop and NewTunnelHub/EnableTunnels callers listed;
  EnableTunnels in Task 5's census; nil-edge hub fails closed.
- P2-4: case 2b, case 2 in full through a static -tunnel route.
- P2-5: ship --check with the guide's placeholders, then a container
  started from processes.json's release and web commands on PORT 3000
  and a handshake with an https origin.
- P2-6: carlos apps delete --account bab cable; cleanup is the Trash's
  30-day expiry, no purge.
R1 findings committed alongside.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 8d3bd5f1dd655d68149c6719711a002fcacaca29 parent 937bdd7
2 files changed, +51 −14
  • docs/superpowers/plans/2026-10-30-tunnel-websockets.md +38 −14
  • docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-plan-R1.md +13 −0
diff --git a/docs/superpowers/plans/2026-10-30-tunnel-websockets.md b/docs/superpowers/plans/2026-10-30-tunnel-websockets.md
index 980e4e41a..6c1569424 100644
--- a/docs/superpowers/plans/2026-10-30-tunnel-websockets.md
+++ b/docs/superpowers/plans/2026-10-30-tunnel-websockets.md
@@ -8,7 +8,7 @@
**Tech Stack:** Go 1.26.10; `golang.org/x/net v0.60.0` (`http2`, and `websocket` in tests only, both already in the module); `internal/tunnelclient` (leaf: stdlib and x/net only); `internal/edge`; `internal/apperr`; the rootfs sample `examples/rails-shop` (Rails 8.1, Solid Cable).
-**Status:** rev 1, for Astra plan review round 1 of 3.
+**Status:** rev 2, for Astra plan review round 2 of 3. Round 1 (`docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-plan-R1.md`, NOT READY, 2 P1 and 4 P2): every finding taken with the controller's rulings (platform-60); dispositions below.
**Spec:** `docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md`, rev 4, APPROVED by Paul 2026-10-30 (recorded on amadan #471). Read §4.3 (the handshake), §4.4 (headers and the trust rule), §4.6 (enforcement, tenancy, the reservation, the reload mutex and the sweep inventory) and §4.8 (limits) before any task. Every section number below is the spec's. The spec's file:line evidence is on `65fd8060`; this plan's is on the branch after merging main `c24e7a04` (merge `4c4bc976`), so lines differ by a few in `edge.go` (`Reload` :729, swap :1231, `SetDynamicAuth` :1209, upgrade branch :2114, `Watch` :2819, `tunnelProxy` :3184, `fleetProxy` :3240).
@@ -44,6 +44,17 @@
4. An app that answers 101 with `Sec-WebSocket-Extensions: permessage-deflate` and then sends compressed frames: bytes must cross unchanged both ways. Test in Task 2 (`TestUpgradeCarriesBytesVerbatim`, a 1 MiB random payload each way).
5. A hub Reload that fails halfway (registry read error) while a socket is open: the socket stays, nothing is half-swept, and the next successful Reload judges it. Test in Task 4 (`TestFailedReloadSweepsNothing`).
+## Review dispositions (Astra plan R1)
+
+| finding | disposition | where |
+|---|---|---|
+| P1-1 the real loop cannot trust the TLS fixture | Checked: `Dial` builds its own `tls.Config` with no `RootCAs` (`internal/tunnelclient/tunnelclient.go:206-209`), so it verifies against the system pool, and Go's Linux pool reads `SSL_CERT_FILE` when it first loads (`crypto/x509/root_unix.go:36`). No production trust seam: the witnesses re-run their own test binary as a child with `SSL_CERT_FILE` naming a fixture CA, set before the process starts, so before anything loads the system roots; `Dial` is unchanged and verification stays on. The helper is `runTrustedChild` (Task 6); the child's first assertion is a connected channel, and a negative control without the CA never connects | Tasks 6, 7 |
+| P1-2 "Enqueue a job" reloads the page | Checked: `button_to` posts a normal form (`show.html.erb:8`) and `PingsController#create` redirects (`pings_controller.rb:4`). The inline script now intercepts the form's submit and sends the same POST with `fetch` (its `FormData` carries the form's `authenticity_token`; no navigation). The page changes only from the broadcast, which now carries both counts so the page needs no reload. No new visible words | Tasks 8, 10 |
+| P2-3 caller and configuration inventory | `Config.Limits` reaches the server: `serveUntilDead` gains a `Limits` parameter and calls `ServeWith`; `Loop` resolves `cfg.Limits`; a test through the real `Loop` reads the advertised SETTINGS. `Loop`'s callers now include `fleet_public_routes_e2e_test.go:500`. Every `NewTunnelHub` and `EnableTunnels` caller is listed (20 files) and unchanged in signature; `EnableTunnels` is in Task 5's changed functions and census, and a hub built without it fails closed | Tasks 1, 3, 5 |
+| P2-4 the `-tunnel` arm lacks case 2 | Task 6 adds case 2b: case 2 in full (gate, login, protocol, messages both ways, the cookie stripped, `X-Forwarded-Proto: https`) through a static `-tunnel` route served by the real box edge and shim | Task 6 |
+| P2-5 the local container check does not start the server | Checked: no `CMD` (`Dockerfile`), the web command lives in `processes.json:2`, puma binds `CARLOS_SOCKET` or `PORT` (`config/puma.rb`), the database is `CARLOS_DB` (`config/database.yml:32`), and production sets `force_ssl` and `assume_ssl` (`production.rb:28-31`). Task 8 now runs `carlos ship --check` with the guide's placeholders (`docs/site/rails.md:153-161`), then a separate container started with the release and web commands from `processes.json`, `PORT=3000`, `CARLOS_DB` and the same placeholders, and a handshake whose `Origin` is `https://127.0.0.1:3000` (the scheme `assume_ssl` reports) | Task 8 |
+| P2-6 the delete command and the purge | Checked: `carlos apps delete` takes the app positionally (`apps.go:240-248`) and there is no purge verb (`apps.go:140-145`). Task 10 runs `carlos apps delete --account bab cable`; cleanup is the Trash's 30-day expiry; no purge step | Task 10 |
+
## Plan rulings (choices the spec leaves open, with cost if wrong)
- P-1. The old-box log line (§4.9 says "logged once per channel per hour") uses the edge's existing `logThrottled` (first occurrence, then every 300th; `edge.go:1287`), one shared mechanism rather than a new time-based limiter. Task 5 amends spec §4.9's wording in its commit. Cost if wrong: one limiter and a test.
@@ -105,7 +116,7 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
**Files:**
- Create: `internal/tunnelclient/upgrade.go`, `internal/tunnelclient/upgrade_box_test.go`
- Modify: `internal/tunnelclient/tunnelclient.go` (`Config` :66-79, `Loop` :87-139, `Dial` :190-262, `Mark` :279-288, `Serve` :290-293)
-- Callers checked, unchanged signatures: `Dial` (`tunnelclient_test.go:58`, `:73`; `Loop`), `Serve` (`tunnelclient_test.go:62`; `serveUntilDead` :168), `Mark` (`mark_test.go:16`, `internal/edge/reqrecords_test.go:65`, `internal/edge/guard_test.go:251`, `Loop` :120), `Loop` (`internal/host/tunnel_client.go:49`, `internal/edge/fleet_e2e_test.go:172`, `internal/edge/tunnel_e2e_test.go:197`). None needs a change: a `Config` with no `Limits` gets `DefaultLimits`, and a request with no marker passes through `Mark` byte for byte (pinned below).
+- Callers checked: `Dial` (`tunnelclient_test.go:58`, `:73`; `Loop` :105), unchanged; `Serve` (`tunnelclient_test.go:62`; `serveUntilDead` :168), unchanged signature; `serveUntilDead` (`Loop` :120, its only caller) **changes**: it takes the resolved `Limits` and calls `ServeWith` (P2-3); `Mark` (`mark_test.go:16`, `internal/edge/reqrecords_test.go:65`, `internal/edge/guard_test.go:251`, `Loop` :120), unchanged; `Loop` (`internal/host/tunnel_client.go:49`, `internal/edge/fleet_e2e_test.go:172`, `internal/edge/tunnel_e2e_test.go:197`, `fleet_public_routes_e2e_test.go:500`), unchanged: a `Config` with no `Limits` gets `DefaultLimits`, and a request with no marker passes through `Mark` byte for byte (pinned below).
**Interfaces:**
- Produces:
@@ -113,6 +124,7 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- `type Limits struct { MaxStreams uint32; StreamWindow, ConnWindow int32 }`; `var DefaultLimits = Limits{MaxStreams: 250, StreamWindow: 1 << 20, ConnWindow: 160 << 20}`; `const PlainHeadroom = 32 << 20`.
- `func ValidUpgradeToken(tok string) bool`: non-empty, at most `MaxUpgradeTokenLen` bytes, every byte an RFC 7230 tchar (`httpguts.IsTokenRune`).
- `Config.Limits *Limits` (nil means `DefaultLimits`); `func ServeWith(conn net.Conn, handler http.Handler, l Limits)`; `Serve(conn, handler)` calls `ServeWith(conn, handler, DefaultLimits)`. The server sets `MaxConcurrentStreams`, `MaxUploadBufferPerStream` and `MaxUploadBufferPerConnection` from `l`.
+ - `func serveUntilDead(ctx context.Context, conn net.Conn, handler http.Handler, l Limits)`, calling `ServeWith(conn, handler, l)`; `Loop` passes `*cfg.Limits` or `DefaultLimits` (P2-3).
- `Dial` adds `CapsHeader: CapUpgrade` to the registration request.
- `Mark(h)` serves through `upgradeShim{h}` inside the mark: a request with `UpgradeHeader` set and valid gets the header deleted, `Connection: Upgrade` and `Upgrade: <token>` set, `Body` = `http.NoBody`, `ContentLength` 0, and a writer whose `Hijack` answers HTTP/2 `200` with `UpgradedHeader: 1`, flushes, and returns a `net.Conn` reading the original body and writing with a flush per `Write`. Every response the handler writes without hijacking has `UpgradedHeader` deleted at `WriteHeader`. A request without the header is passed through unchanged. An invalid token answers 400 and does not reach the handler.
@@ -122,12 +134,13 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- `TestShimStripsAnAppSetUpgradedMarker`: a handler that sets `Carlos-Tunnel-Upgraded: 1` on a plain 200: the client sees no such header.
- `TestShimRefusesABadToken`: marker `"web socket"` and a 65-byte token: 400, the handler never runs; a 64-byte token: reaches the handler (control).
- `TestRegistrationCarriesTheCapability`: an `httptest` server records `/register`'s headers from `Dial`: `Carlos-Tunnel-Caps == "upgrade/1"`.
+ - `TestLoopAppliesConfigLimits` (P2-3): an `httptest` server answers `/register` with the 101 and then reads the box's first frames with an x/net `Framer` (after writing the client preface and an empty SETTINGS); `Loop` with `Config.Limits = &Limits{8, 64<<10, 768<<10}`: SETTINGS `MaxConcurrentStreams == 8`, `InitialWindowSize == 64<<10`, connection WINDOW_UPDATE `768<<10 - 65535`; `Loop` with no `Limits`: 250, `1<<20`, `160<<20 - 65535` (control).
- `TestServerAdvertisesTheLimits` (§8.1 case 6): an x/net `Framer` client on the raw pipe end writes the client preface and an empty SETTINGS, then reads the server's first frames: the SETTINGS frame has `SettingMaxConcurrentStreams == 250` and `SettingInitialWindowSize == 1<<20`; the next frame is a WINDOW_UPDATE on stream 0 with increment `160<<20 - 65535`. With `ServeWith(..., Limits{8, 64<<10, 768<<10})`: 8, `64<<10`, `768<<10 - 65535`.
- Mutation to show: drop the `UpgradedHeader` delete; `TestShimStripsAnAppSetUpgradedMarker` fails.
- [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/tunnelclient/ -count=1`. Expected: FAIL on the new tests only.
- [ ] **Step 3: Implement** as the Interfaces block says. Keep the package's imports to stdlib and `golang.org/x/net/...` (its header's rule, `tunnelclient.go:7-14`).
- [ ] **Step 4: Run** Step 2, plus `TMPDIR=/tmp/g nice -n 19 go test ./internal/edge/ -run 'TestTunnel|TestFleet|TestReqRecords|TestGuard' -count=1`. Expected: PASS.
-- [ ] **Step 5: Census.** Expect `Dial`, `Serve`, `markedHandler.ServeHTTP` (body), `ServeWith`, `ValidUpgradeToken`, the shim (new), the `tunnelclient` envelope; reconcile with spec §7.
+- [ ] **Step 5: Census.** Expect `Dial`, `Serve`, `serveUntilDead`, `Loop`, `markedHandler.ServeHTTP` (body), `ServeWith`, `ValidUpgradeToken`, the shim (new), the `tunnelclient` envelope; reconcile with spec §7.
- [ ] **Step 6: Commit.**
### Task 2: The hub half: `RoundTripUpgrade`
@@ -163,7 +176,7 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
**Files:**
- Create: `internal/edge/upgrades.go`, `internal/edge/upgrades_test.go`
- Modify: `internal/edge/tunnel.go` (`tunnelConn` :72-79, `ServeHTTP` :122-217, `conn` :348-355 -> `channel`, `State` :360-365, `transportFor` :393-401, `NewTunnelHub` :96-98), `internal/edge/edge.go` (`upstream` :417, `Reload`'s three tunnel arms :849-855, :891-895, :916-925; `ServeHTTP` near the hop accept, `Edge` struct), `fleetProxy` :3240 and `tunnelProxy` :3184 `Rewrite`
-- Callers migrated: `h.conn(name)` at `tunnel.go:361` (`State`) and `:395` (`transportFor`) -> `h.channel(name)`; `NewTunnelHub` callers keep their signature (`edge.go` `enableTunnelsFromEnv`; tests `fleetforward_test.go:102`, `fleet_route_test.go`, `tunnel_e2e_test.go`, `fleet_e2e_test.go`, `fleetapi_e2e_test.go`, `tunnel_test.go`; grep `NewTunnelHub(` and confirm none constructs `TunnelHub{}` literally).
+- Callers migrated: `h.conn(name)` at `tunnel.go:361` (`State`) and `:395` (`transportFor`) -> `h.channel(name)`; `NewTunnelHub` keeps its signature and sets `upgradeCap`; its callers (grep `NewTunnelHub(` and `.EnableTunnels(` over the module, 20 files on `4c4bc976`): `internal/edge/edge.go` (`enableTunnelsFromEnv`), and the tests `fleet_public_routes_e2e_test.go`, `internal/edge/alias_test.go`, `door_test.go`, `edgeerrors_test.go`, `edge_test.go`, `fleetapi_e2e_test.go`, `fleet_e2e_test.go`, `fleetforward_test.go`, `fleet_route_test.go`, `fleetverdict_test.go`, `ratelimit_test.go` (`:790`), `storedoor_test.go`, `tunnel_e2e_test.go`, `tunnel_geo_e2e_test.go`, `tunnel_test.go`, `internal/fleetapi/fleetapi_test.go`, `internal/host/edgesfile_forward_test.go`, `fleetbind_door_test.go`, `fleet_secrets_key_test.go`. None needs an edit; the task re-runs each package's tests that use them, and confirms none builds `TunnelHub{}` literally (which would leave `upgradeCap` 0).
**Interfaces:**
- Consumes: Task 1's `CapsHeader`, `CapUpgrade`, `UpgradeHeader`, `UpgradedHeader`.
@@ -188,7 +201,7 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- `TestLimitsInvariant` (§8.1 case 7): `tunnelUpgradeCap < int(tunnelclient.DefaultLimits.MaxStreams)` and `int64(DefaultLimits.ConnWindow) >= int64(tunnelUpgradeCap)*int64(DefaultLimits.StreamWindow) + tunnelclient.PlainHeadroom`.
- `TestUpgradesStillRefusedBeforeSwitchOn`: `polUpgrade` (`fleetforward_policy_test.go:146`) through `policyScene`: 502, and the app saw 0 upgrades (pins this task's dormancy; Task 5 changes it to 101).
- Mutations to show: drop the tenancy comparison in `reserveUpgrade` (the stale case passes); drop the `Once` (`TestReleaseIsExactlyOnce` sees a double decrement).
-- [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/edge/ -run 'TestTenancy|TestReserveUpgrade|TestReleaseIs|TestBackstop|TestRegistrationRecordsCaps|TestTheMarkers|TestLimitsInvariant|TestUpgradesStillRefused|TestTunnel|TestFleet|TestForward' -count=1`. Expected: FAIL on the new tests only.
+- [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/edge/ -run 'TestTenancy|TestReserveUpgrade|TestReleaseIs|TestBackstop|TestRegistrationRecordsCaps|TestTheMarkers|TestLimitsInvariant|TestUpgradesStillRefused|TestTunnel|TestFleet|TestForward' -count=1`. Expected: FAIL on the new tests only. Step 4 also runs `TMPDIR=/tmp/g nice -n 19 go test ./internal/fleetapi/ ./internal/host/ -run 'Fleet|Edges|Door|SecretsKey' -count=1` and `go test . -run 'TestFleetAppServesThroughTheHub' -count=1` (the other `NewTunnelHub` callers).
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run** Step 2. Expected: PASS.
- [ ] **Step 5: Census** (`TunnelHub.ServeHTTP`, `TunnelHub.State`, `transportFor`, `channel` replacing `conn`, `NewTunnelHub`, `Edge.Reload`, `Edge.ServeHTTP`, `fleetProxy`, `tunnelProxy`; new: `tenancy`, `upgradeAdmission` and its two functions, `openUpgrades`, `upgradeReservation` and its methods, `reserveUpgrade`, the sentinels); reconcile.
@@ -227,6 +240,7 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- Modify: `internal/edge/tunnel.go` (`transportFor`), `internal/edge/edge.go` (upgrade branch :2114-2140; `fleetProxy` and `tunnelProxy` error handlers), `internal/apperr/availability.go`, `approved_tunnel_websockets_copy_test.go` (`tunnelWebSocketsCopyBuilt` += `TWS-C01`, `TWS-C02`, `TWS-C03`), spec §4.9 (P-1's wording)
- Migrate: `internal/edge/fleetforward_policy_test.go`: `TestForwardUpgradeIsLimitedAtTheHub` (:200) asserts exactly 101 for handshakes 1 and 2 and `ups == 2`; `TestForwardPlanThrottleAndUpgradeClose` (:224) keeps its in-hook close and adds a socket held open: `CloseAccountUpgrades` returns 1 and the backend's `closed` channel fires within 2 s; `TestForwardUpgradeCloseCancelsTheRequest` (:340) loses its "(#471)" comment and keeps its assertions; Task 3's `TestUpgradesStillRefusedBeforeSwitchOn` is deleted (its job is done). `polBackend` (:37-87) already answers 101 and echoes.
- Callers of `transportFor`: `edge.go:3194` (`tunnelProxy`), `:3255` (`fleetProxy`); no test calls it directly.
+- `EnableTunnels` **changes** (P2-3): it also sets `hub.edge = e`. Signature unchanged; callers are Task 3's list (the same 20 files), none edited. A `TunnelHub` used without `EnableTunnels` (tests that drive `NewTunnelHub` directly, e.g. `tunnel_test.go`) has `edge == nil`, and `transportFor` refuses an upgrade on it with `errNoAdmission` rather than dereferencing it.
**Interfaces:**
- Consumes: Task 2's `RoundTripUpgrade`, `UpgradeConn`; Task 3's admission, `reserveUpgrade`, `channel`, sentinels; Task 4's sweep.
@@ -243,12 +257,13 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- `TestOldBoxKeepsThe502`: the box registers by hand without the capability (as Task 3's `TestRegistrationRecordsCaps`) and serves its `Edge` with `tunnelclient.ServeWith`: an upgrade gets 502 with cause `tunnel_upgrade_unsupported` (the request's noted cause); a plain GET 200 (control).
- `TestCapAnswers503`: hub `upgradeCap = 2`: two sockets open, the third handshake 503 with `Retry-After: 5` and the TWS-C03 body; a plain GET 200 while both are open; closing one admits a new handshake.
- `TestHungHandshakeReleasesAtRequestEnd` (Review Focus 1): the box's app accepts the TCP connection and never answers; the client gives up after 1 s (closes); within 2 s the channel's count is 0 and a plain GET to another host on the same box answers 200.
+ - `TestHubWithoutEdgeRefusesUpgrades` (P2-3): a `NewTunnelHub` with a connected capable channel and no `EnableTunnels`: `transportFor(name).RoundTrip` of an upgrade request returns `errNoAdmission`, no panic; a plain request on the same hub succeeds (control).
- `TestStaleAdmissionIsRefused`: the admission seam from Task 4's `beforeReserve` with a revoking Reload in between: 502 and the app saw no handshake.
- Mutations to show: write the marker without checking the admission (a direct `transportFor` call with an upgrade request and no admission reaches the box; the test calls it and asserts `errNoAdmission`); drop the caps check (`TestOldBoxKeepsThe502` gets the old box's plain-GET answer instead of 502).
- [ ] **Step 3: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/edge/ ./internal/apperr/ -run 'TestForward|TestUpgrade|TestOldBox|TestCap|TestHung|TestStale|TestTunnel|TestFleet|Availability' -count=1` and `nice -n 19 go test . -run 'TestTunnelWebSocketsCopy' -count=1`. Expected: FAIL on the new tests only.
- [ ] **Step 4: Implement**, with the TWS rows' approved text.
- [ ] **Step 5: Run** Step 3. Expected: PASS.
-- [ ] **Step 6: Census** (`transportFor`, `Edge.ServeHTTP`, `fleetProxy`, `tunnelProxy`, the `apperr` envelope); reconcile.
+- [ ] **Step 6: Census** (`transportFor`, `Edge.EnableTunnels`, `Edge.ServeHTTP`, `fleetProxy`, `tunnelProxy`, the `apperr` envelope); reconcile, writing `Edge.EnableTunnels` into spec §7's `body` list in this commit if the card shows it and §7 does not.
- [ ] **Step 7: Commit.**
### Task 6: The production-wired witness
@@ -257,11 +272,13 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- Create: `internal/edge/tunnel_ws_e2e_test.go`
**Interfaces:**
+- The trusted child (P1-1), in `internal/edge/trusted_child_test.go` (new): `func runTrustedChild(t *testing.T) (child bool, fx tlsFixture)`. In the parent (env `CARLOS_TEST_TRUSTED_CHILD` unset): `newTLSFixture(t, dir)` writes a fresh ECDSA CA and a leaf for `127.0.0.1`, `::1`, `example.com`, `*.example.com` signed by it into a `t.TempDir()`; the parent runs `exec.Command(os.Args[0], "-test.run", "^"+t.Name()+"$", "-test.count=1", "-test.v")` with the environment plus `SSL_CERT_FILE=<ca.pem>`, `SSL_CERT_DIR=<empty temp dir>`, `CARLOS_TEST_TRUSTED_CHILD=1` and the leaf's paths, streams its output into `t.Log`, fails on a non-zero exit, and returns `false`. In the child it returns `true` and the fixture, whose `tls.Config` the hub's server uses. The variables are set before the child process starts, so before anything in it loads the system roots; `tunnelclient.Dial` is unchanged and verifies normally. Linux only: the test file carries `//go:build linux` (macOS and Windows do not read `SSL_CERT_FILE`; CI runs Linux). Every Task 6 and Task 7 test that runs the real `Loop` over TLS starts with `child, fx := runTrustedChild(t); if !child { return }` and serves the hub with `fx.ServerTLS` (assigned to the unstarted server's `TLS` before `StartTLS`, which keeps a config's own certificates), the tracking listener set as the server's `Listener` first.
- Consumes, all production: `New`, `EnableTunnels(NewTunnelHub(host, nil))` and `Reload` for the hub, on a registry with fleet `home` of `bah` and active `box-1`, the forward row through `PutForward`; served by an `http.Server` on a TLS listener (`httptest.NewUnstartedServer(hub)`, `StartTLS`) wrapped in a tracking listener that records every accepted `net.Conn`; the box: `New` on a second registry whose instance row for `shop.example.com` has a unix `Socket`, a `Gate` (bcrypt hash of `right`, as `TestForwardLoginThroughTheRealFleetGate` sets one) and `Account`/`App` `bah`/`shop`, served by `tunnelclient.Loop` dialing the hub over `https` as `home/box-1`; the app: an `x/net/websocket` server on that socket, Action Cable shaped (accepts only subprotocol `actioncable-v1-json` and only when `Origin == X-Forwarded-Proto + "://" + Host`, sends `{"type":"welcome"}`, `{"type":"ping","message":<n>}` every 200 ms, answers `{"command":"subscribe",...}` with `confirm_subscription`, broadcasts on a test channel, echoes `{"command":"message"}` data); the client: `x/net/websocket` against the hub with `Origin: https://shop.example.com`. A counting store wraps the hub's and the box's static stores.
-- [ ] **Step 1: Write** `TestTunnelWebSocketEndToEnd` with spec §8.2 cases 1-8, 10-12, 14-16 as sub-tests on one scene, each with its exact values from the spec:
+- [ ] **Step 1: Write** `TestTunnelWebSocketEndToEnd` with spec §8.2 cases 1-8, 10-12, 14-16 as sub-tests on one scene, each with its exact values from the spec. First, in the child: `hub.tunnels.State("home/box-1") == "connected"` within 5 s, the proof that the real `Loop` trusted the fixture over real TLS. A separate test, `TestTrustedChildIsNeeded`, runs the same scene in a child given `SSL_CERT_FILE` pointing at an unrelated CA: the state is never `"connected"` within 5 s and the box's log shows `x509: certificate signed by unknown authority` (verification is on).
1. No cookie: the gate's answer, not 101; the app saw nothing. Extended (Review Focus 3): with a cookie whose expiry has passed, the same.
2. Log in (`POST /.carlos/gate`, urlencoded, `password=right&next=%2Fcable`), then the handshake: 101, `Sec-WebSocket-Protocol: actioncable-v1-json`; welcome, two pings, subscribe and confirm, a broadcast, 100 echoes each way byte for byte; the app saw no `carlos_gate` cookie and saw `X-Forwarded-Proto: https`.
+ 2b. Case 2 in full through the third arm (P2-4): the hub's static client `t1` (`NewTunnelHub(host, map[string]string{"t1": tok})`), a hub row `t.example.com` with `Tunnel: "t1"`, account `bah`, app `shop`; a second `Loop` named `t1` serving the same box `Edge`, whose row for `t.example.com` carries the same gate and socket; login, handshake 101 with `actioncable-v1-json`, welcome, pings, subscribe and confirm, a broadcast, 100 echoes each way byte for byte, no `carlos_gate` cookie at the app, `X-Forwarded-Proto: https`.
3. `SetPlanGovernedFor(bah)`, `CloseAccountUpgrades("bah")` returns 1 while open; client and app both see the close within 2 s; a second call returns 0.
4. Plan throttle awake: a new handshake 429, `Retry-After: 60`, the app saw nothing.
5. The hub's rate limit (burst 2) refuses the third handshake with `Retry-After: 1`; the box's own row has burst 1 and never applies.
@@ -284,6 +301,7 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- Create: `internal/edge/tunnel_ws_load_e2e_test.go`
**Interfaces:**
+- Every test here runs the real `Loop` over TLS and so starts with Task 6's `runTrustedChild` (P1-1).
- Consumes: Task 6's scene builder (factor it into an unexported `wsScene(t, opts)` in Task 6's file when this task needs a second shape; Task 6's sub-tests then call it, migrated in this commit).
- [ ] **Step 1: Write**:
@@ -297,14 +315,19 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
**Files:**
- Create: `examples/rails-shop/app/channels/application_cable/connection.rb`, `examples/rails-shop/app/channels/application_cable/channel.rb`, `examples/rails-shop/app/channels/pings_channel.rb`
-- Modify: `examples/rails-shop/app/views/pages/show.html.erb`, `examples/rails-shop/app/jobs/ping_job.rb` (unchanged broadcast name `"pings"`; read it to confirm)
+- Modify: `examples/rails-shop/app/views/pages/show.html.erb`, `examples/rails-shop/app/jobs/ping_job.rb`
**Interfaces:**
- `ApplicationCable::Connection < ActionCable::Connection::Base` and `ApplicationCable::Channel < ActionCable::Channel::Base`, both empty (the Rails 8 generator's files).
- `PingsChannel < ApplicationCable::Channel` with `subscribed` calling `stream_from "pings"`.
-- The page: wrap the "Jobs done" count in `<span id="done">`; an inline `<script>` (no new asset pipeline: the sample has no importmap) opens `new WebSocket((location.protocol == "https:" ? "wss://" : "ws://") + location.host + "/cable", "actioncable-v1-json")`, sends `{"command":"subscribe","identifier":"{\"channel\":\"PingsChannel\"}"}` on open, and on a message whose `message.id` is set increments `#done`. No new visible words (sample copy unchanged).
-- [ ] **Step 1: Build the image** as `docs/site/rails.md` says (`docker buildx build --platform linux/arm64`), then `carlos ship --check` on it. Expected: check passes.
-- [ ] **Step 2: Run locally**: start the image with `docker run --rm -p 127.0.0.1:3000:80` (bind loopback only) and `SECRET_KEY_BASE` set, then the §1 curl handshake against `http://127.0.0.1:3000/cable` with `Origin: http://127.0.0.1:3000`: 101 and the welcome frame. Stop the container.
+- `PingJob#perform` broadcasts `{ id: id, done: Ping.where.not(done_at: nil).count, total: Ping.count }` on `"pings"` (P1-2: the page's two counts then come from the broadcast alone).
+- The page: the two counts in "Jobs done: X of Y" become `<span id="done">` and `<span id="total">`, same words. An inline `<script>` (the sample has no importmap or JS bundle):
+ - opens `new WebSocket((location.protocol == "https:" ? "wss://" : "ws://") + location.host + "/cable", "actioncable-v1-json")`, sends `{"command":"subscribe","identifier":"{\"channel\":\"PingsChannel\"}"}` on its `welcome`, and on a message whose `message` has `done` and `total` sets both spans;
+ - intercepts the "Enqueue a job" form's `submit` (the form `button_to` renders, found by its `action` ending in `/pings`): `event.preventDefault()`, then `fetch(form.action, {method: "POST", body: new FormData(form), credentials: "same-origin", redirect: "manual"})`, so the same POST with the form's `authenticity_token` goes out and the page does not navigate. Nothing on the page changes from the fetch's answer.
+- No new visible words: the script adds no text, and the two spans wrap the existing numbers. If any wording changes during the build, it is listed for copy review before it is written.
+
+- [ ] **Step 1: Build and check as the guide does** (`docs/site/rails.md:155-161`): `docker buildx build --platform linux/arm64 --load -t shop:ws .`, `docker save -o $TMPDIR/shop-ws.tar shop:ws`, then `carlos ship --rootfs $TMPDIR/shop-ws.tar --processes processes.json --check --env SECRET_KEY_BASE=placeholder --env CARLOS_STORE_BUCKET=placeholder --env CARLOS_STORE_REGION=eu-west-1 --env CARLOS_STORE_ACCESS_KEY=placeholder --env CARLOS_STORE_SECRET_KEY=placeholder`. Expected: the check passes (web answers on its socket, release and worker run).
+- [ ] **Step 2: Handshake against a running container** (P2-5). The check removes its containers, so start one the way a box runs the release and web processes, with puma on a port instead of a socket: `docker run -d --rm --name shop-ws-check --platform linux/arm64 -p 127.0.0.1:3000:3000 -e PORT=3000 -e CARLOS_DB=/tmp/shop.sqlite3 -e SECRET_KEY_BASE=placeholder -e CARLOS_STORE_BUCKET=placeholder -e CARLOS_STORE_REGION=eu-west-1 -e CARLOS_STORE_ACCESS_KEY=placeholder -e CARLOS_STORE_SECRET_KEY=placeholder -w /rails --entrypoint /bin/sh shop:ws -c '/rails/bin/rails db:migrate && exec bundle exec puma -C config/puma.rb'` (the two commands of `processes.json`'s `release` and `web`; `PORT` because `config/puma.rb` binds `CARLOS_SOCKET` or `PORT`; bound to loopback only). Then `curl --http1.1 -i -N --max-time 10 -H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' -H 'Sec-WebSocket-Protocol: actioncable-v1-json' -H 'Origin: https://127.0.0.1:3000' http://127.0.0.1:3000/cable`. The `Origin` is `https` because production sets `assume_ssl` (`production.rb:28`), so Rails reports the request as https and Action Cable compares the origin with that. Expected: `101 Switching Protocols`, `Sec-WebSocket-Protocol: actioncable-v1-json`, then the bytes of `{"type":"welcome"}`. Also `curl -s http://127.0.0.1:3000/ | grep -c 'id="done"'` prints 1. Then `docker stop shop-ws-check`; delete `$TMPDIR/shop-ws.tar`.
- [ ] **Step 3: Commit** (example files only; no census, no copy).
### Task 9: Census, whole-branch review, merge
@@ -318,8 +341,8 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
- [ ] **Step 1:** A release containing the merge, rolled dev first: dev boxes including r10r's `box-1`, then the dev console box (sophie, the hub), the CLI on DOCS-T1. No flagship until Paul says.
- [ ] **Step 2:** Ship the Task 8 sample to `shop` on dev (`carlos ship --rootfs`, promote, `carlos deploy` verification by `X-Carlos-Version`).
-- [ ] **Step 3:** From DOCS-T1, the spec §1 handshake against `https://shop.bab.dev.oncarlos.com/cable` with `curl --http1.1 -i -N --max-time 10`: `HTTP/1.1 101 Switching Protocols`, `Sec-WebSocket-Protocol: actioncable-v1-json`, then the bytes of `{"type":"welcome"}` and a `{"type":"ping",...}` about every 3 s. In a browser, "Enqueue a job" updates the count without a reload.
-- [ ] **Step 4:** Revocation, per D-1 as ruled. With (a): `carlos apps create --app cable --place fleet/r10r --account bab`, ship and promote the same image, instance `cable.bab.dev.oncarlos.com`; open its `/cable` with a client that logs frames; `carlos apps delete --app cable --account bab`; the socket closes within 30 s (the instance pass's convergence plus the 2 s watch); then purge `cable`.
+- [ ] **Step 3:** From DOCS-T1, the spec §1 handshake against `https://shop.bab.dev.oncarlos.com/cable` with `curl --http1.1 -i -N --max-time 10`: `HTTP/1.1 101 Switching Protocols`, `Sec-WebSocket-Protocol: actioncable-v1-json`, then the bytes of `{"type":"welcome"}` and a `{"type":"ping",...}` about every 3 s. In a browser (P1-2): open the page, note the counts, press "Enqueue a job": the page does not navigate (the browser's network panel shows one `fetch` POST to `/pings` and no document load; the `/cable` socket stays the same connection), and "Jobs done" and its total change once the job runs, from the broadcast.
+- [ ] **Step 4:** Revocation, per D-1 as ruled. With (a): `carlos apps create --app cable --place fleet/r10r --account bab`, ship and promote the same image, instance `cable.bab.dev.oncarlos.com`; open its `/cable` with a client that logs frames; `carlos apps delete --account bab cable` (the app is positional, `apps.go:240-248`); the socket closes within 30 s (the instance pass's convergence plus the 2 s watch). Cleanup is the Trash's own expiry: `cable` stays in the Trash for 30 days (`docs/site/cli.md:141-142`) and is then purged; there is no purge verb (`apps.go:140-145`) and no purge step. While it waits it runs nothing: its routes drop at delete and the box's pass retires its instance, so it holds only its release image in the fleet's store and keeps the name `cable` reserved.
- [ ] **Step 5:** Plain HTTP unchanged: `curl -sI https://shop.bab.dev.oncarlos.com/up` 200 with one `x-carlos-version`; `railsdemo.bab.dev.oncarlos.com/up` 200.
- [ ] **Step 6:** Report on #471 with the transcript. No flagship roll until Paul says so.
@@ -327,7 +350,8 @@ Upgrades stay refused exactly as today (the hub's 502) through Task 4. Tasks 1 a
## Self-review
-1. **Spec coverage.** §4.3 handshake: Tasks 1, 2 (halves), 5 (switch-on). §4.4 headers and trust rule: Task 1 (shim strip), Task 3 (scrub, inbound delete), Task 5 (admission required). §4.4.1 `X-Forwarded-Proto`: Task 6 case 2. §4.5 gate: Task 6 cases 1-2. §4.6 enforcement and `CloseAccountUpgrades`: Task 5 migration, Task 6 case 3. §4.6.1 tenancy and sweep: Tasks 3, 4; witness Task 6 cases 15-16. §4.6.2 reservation: Task 3; terminal paths Task 6 case 12. §4.6.3 inventory: Task 4's guard and caller list. §4.7 lifetimes: Task 6 cases 3, 6, 7, 8, 15; Task 7 hub restart. §4.8 limits: Task 1 (server), Task 3 (cap, invariant), Task 7 (maximum load). §4.9 compatibility: Task 1 (capability), Task 5 (`TestOldBoxKeepsThe502`). §5 provider: nothing to build. §6 budget: Task 6 case 14. §7 census and copy: every task's census step, Task 0, Task 9. §8.1: Tasks 1, 2, 3. §8.2: Tasks 3-7. §8.3 live: Task 10. §11 item 4 sample: Task 8. §12 rollout: Task 10.
+0. **Round 1.** Every finding re-checked against the code it cites before the fix (dispositions table).
+1. **Spec coverage.** §4.3 handshake: Tasks 1, 2 (halves), 5 (switch-on). §4.4 headers and trust rule: Task 1 (shim strip), Task 3 (scrub, inbound delete), Task 5 (admission required). §4.4.1 `X-Forwarded-Proto`: Task 6 case 2. §4.5 gate: Task 6 cases 1-2. §4.6 enforcement and `CloseAccountUpgrades`: Task 5 migration, Task 6 case 3. §8.2's "a `-tunnel` row gets case 2": Task 6 case 2b. §4.6.1 tenancy and sweep: Tasks 3, 4; witness Task 6 cases 15-16. §4.6.2 reservation: Task 3; terminal paths Task 6 case 12. §4.6.3 inventory: Task 4's guard and caller list. §4.7 lifetimes: Task 6 cases 3, 6, 7, 8, 15; Task 7 hub restart. §4.8 limits: Task 1 (server), Task 3 (cap, invariant), Task 7 (maximum load). §4.9 compatibility: Task 1 (capability), Task 5 (`TestOldBoxKeepsThe502`). §5 provider: nothing to build. §6 budget: Task 6 case 14. §7 census and copy: every task's census step, Task 0, Task 9. §8.1: Tasks 1, 2, 3. §8.2: Tasks 3-7. §8.3 live: Task 10. §11 item 4 sample: Task 8. §12 rollout: Task 10.
2. **Step scan.** Every test names its assertions and values; code steps give signatures and the values the spec pins; no body beyond those.
3. **Type consistency.** `Limits{MaxStreams uint32; StreamWindow, ConnWindow int32}` (Tasks 1, 3, 7); `RoundTripUpgrade(ctx, cc, req) (*http.Response, error)` (Tasks 2, 5); `reserveUpgrade(inbound, a, tc, capN) (*upgradeReservation, context.Context, error)` (Tasks 3, 4, 5); `release(by releaser)`, `firstReleaser()` (Tasks 3, 4, 6); `channel(name) *tunnelConn` (Tasks 3, 5); `tenancy` and `upgradeAdmission` (Tasks 3, 4, 5); `reloadHooks` (Tasks 4, 7).
4. **Review Focus.** Five lines, each with its test in its owning task (Tasks 2, 4, 5, 5, 6).
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-plan-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-plan-R1.md
new file mode 100644
index 000000000..e7783f0c0
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-tunnel-websockets-plan-R1.md
@@ -0,0 +1,13 @@
+1. **P1 — Task 6: the real tunnel loop cannot authenticate the TLS fixture.** [Plan:260](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/plans/2026-10-30-tunnel-websockets.md:260) uses `httptest.StartTLS` with the real `tunnelclient.Loop`, but specifies no certificate trust setup. [Dial:206](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/internal/tunnelclient/tunnelclient.go:206) constructs its own TLS configuration with system roots; it cannot use the trusted client returned by `httptest`. The loop therefore retries certificate failures, and the production witness never gets a connected channel. **Fix:** specify isolated test trust through a helper subprocess with its CA configured before root initialization, or add explicit CA configuration through the real dial path and inventory its callers. Keep certificate verification enabled. **Fault family:** the acceptance fixture must reach the production transport it claims to exercise.
+
+2. **P1 — Task 8: pressing “Enqueue a job” still reloads the page.** The subscription in [Plan:305](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/plans/2026-10-30-tunnel-websockets.md:305) leaves the existing form submission unchanged. [show.html.erb:8](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/examples/rails-shop/app/views/pages/show.html.erb:8) submits a normal form, and [pings_controller.rb:4](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/examples/rails-shop/app/controllers/pings_controller.rb:4) redirects to the root page. The layout loads no JavaScript that intercepts that navigation. Consequently, Task 10’s claimed update “without a reload” cannot result from the prescribed change. **Fix:** submit the form without navigating, preserving its CSRF token, and verify that the existing document and socket receive the broadcast and update the count. **Fault family:** the visible acceptance behavior must be implemented by the sample.
+
+3. **P2 — Tasks 1, 3 and 5: the caller and configuration inventory is incomplete.** [Task 1:108–115](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/plans/2026-10-30-tunnel-websockets.md:108) adds `Config.Limits`, but does not specify its propagation through `serveUntilDead`, which currently calls default-only `Serve` at [tunnelclient.go:168](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/internal/tunnelclient/tunnelclient.go:168). Without that migration, Task 7’s scaled real-loop fixture uses production limits. The inventory also misses the `Loop` caller at [fleet_public_routes_e2e_test.go:500](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/fleet_public_routes_e2e_test.go:500), and `NewTunnelHub` callers including [ratelimit_test.go:790](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/internal/edge/ratelimit_test.go:790). Task 5 changes `EnableTunnels` to install `hub.edge`, but omits that function from its changed-function inventory and census list. **Fix:** state the limits propagation, test it through `Loop`, complete the caller lists, and include `EnableTunnels` in Task 5’s census reconciliation. **Fault family:** changed contracts must reach every production and test caller.
+
+4. **P2 — Task 6: the required full `ArmTunnel` witness is missing.** The spec explicitly requires a `-tunnel` row to receive case 2 at [spec:1189](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/specs/2026-10-30-tunnel-websockets-design.md:1189). [Task 6:260–275](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/plans/2026-10-30-tunnel-websockets.md:260) specifies that complete handshake and message exchange only for a forward row; its `-tunnel` coverage concerns scrubbing and revocation. Those checks do not establish case 2’s gate, protocol and bidirectional-message behavior through the third arm. **Fix:** explicitly repeat case 2 through a static `-tunnel` route using the real box edge and shim. **Fault family:** every supported dispatch arm needs its required production-wired witness.
+
+5. **P2 — Task 8: the prescribed local container check does not start the sample web server.** [Plan:307](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/plans/2026-10-30-tunnel-websockets.md:307) publishes container port 80 and supplies only `SECRET_KEY_BASE`. The [Dockerfile](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/examples/rails-shop/Dockerfile:19) supplies no web command; CARLOS normally gets that command from [processes.json:2](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/examples/rails-shop/processes.json:2). Even when started explicitly, [puma.rb:8](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/examples/rails-shop/config/puma.rb:8) defaults to port 3000. Production also assumes HTTPS, conflicting with the proposed HTTP Origin. **Fix:** provide the actual boot command, matching port, database/migrations and required environment, plus an Origin consistent with the production scheme. **Fault family:** verification instructions must run the artifact under the conditions being asserted.
+
+6. **P2 — Task 10: the live revocation command is invalid, and cleanup requires an unavailable CLI operation.** [Plan:322](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/docs/superpowers/plans/2026-10-30-tunnel-websockets.md:322) runs `carlos apps delete --app cable --account bab`. [runAppsDelete:240–248](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/apps.go:240) has no `--app` flag and requires a positional app name, so revocation stops at flag parsing. The subsequent “purge” is explicitly console-only at [apps.go:143](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/apps.go:143). **Fix:** use `carlos apps delete --account bab cable`; retain D-1(a), and specify cleanup through the existing trash expiry or a separately identified console step. **Fault family:** the approved live experiment must be executable through its stated interfaces.
+
+NOT READY
\ No newline at end of file