carlos / platform Public

edge-held-cap: spec rev 4 §3.6, census card, bounded over-cap read

Spec §3.6 states the new caps with the measurements behind them and
records the proxy-past-the-cap alternative as weighed and not taken.
The follow-ups list gains the cross-region backhaul slot cap, the
unlanded live-streams page's "64" line, and the channel's other long
responses. The tunnel witness now fails within 5 s on a regression
rather than at MaxHold.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev cc07354138e1d1b84bf8e45088a10888c6242f32 parent 80d95fa
6 files changed, +76 −5
  • docs/superpowers/notes/census-proposal-edge-held-cap.md +19 −0
  • docs/superpowers/notes/edge-held-streams-followups.md +6 −0
  • docs/superpowers/specs/2026-10-28-edge-held-streams-design.md +40 −2
  • internal/edge/tunnel_e2e_test.go +5 −3
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv +5 −0

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/notes/census-proposal-edge-held-cap.md b/docs/superpowers/notes/census-proposal-edge-held-cap.md
new file mode 100644
index 000000000..b45400f4f
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-edge-held-cap.md
@@ -0,0 +1,19 @@
+# Census approval: edge-held-cap
+
+Ruling `census-ruling-edge-held-cap`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/edge/heldstream.go` `Edge.serveHeld` | body | unchanged (5) | register now takes whether a tunnel or link channel delivered the request (fromTunnel or linkedRequest on the request context, both set only by this process), so channel-delivered streams count against the new PerChannel cap. No read added; the caps themselves come from in-memory config (heldbudget.go reads Sysinfo and RLIMIT_NOFILE of its own process once at package start). |
+
+Envelopes re-pinned: `internal/edge`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/edge/heldstream.go` `Edge.serveHeld`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): new; runs one held stream. Registers it in the in-memory held set, checks holdsHost against the published map, and runs the heldTask, which opens legs through the activator's AdmitHeldLeg and the route's own proxy. Reads only the request and in-memory state; no bucket, registry or file read of tenant-writable input. Whole-branch fix: calls a nil-in-production test seam (afterMapCheck) after the map check; a reload closing a stream with no response yet now writes the empty event stream; each leg request carries its own in-memory outcome. No read added.
+
+Seal: `6c3e03c493dbca78fc128355f071caa2b2d5f22674b98994cd85a0cf63d40ca8` → `60feabafe92c0f9b9eed63f990b54c6e467dddcade8f4154433720127b41569d`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/edge-held-streams-followups.md b/docs/superpowers/notes/edge-held-streams-followups.md
index 7302127f0..c8f819c5d 100644
--- a/docs/superpowers/notes/edge-held-streams-followups.md
+++ b/docs/superpowers/notes/edge-held-streams-followups.md
@@ -8,3 +8,9 @@ P3s and parked items from the build's reviews (stopping rule 1: none starts a ro
- A multi-chunk, slow terminal-body witness for first-leg pass-through (401/5xx); no total-body cap is required by the spec.
- A stream closed right after it registers can race its first leg admission (the task ends and cancels the leg; no activity effect).
- swapsim mutant M5 panics (close of closed channel) on main as well; pre-existing.
+
+From `edge-held-cap` (rev 4 caps, 2026-11-20):
+
+- Cross-region backhaul: a held stream that enters through another region's edge rides the backhaul hop for its life and takes one of `backhaulMaxInflight`'s 64 slots toward its home box, which every app homed there shares. Past it the hop answers 503, which a native `EventSource` treats as fatal, and ordinary backhauled requests to that box get 503 too. Held streams on the backhaul want their own share of the slots, and the over-cap retry answer rather than a 503. Unchanged by rev 4, which raises only what the holding edge accepts; it matters once latency routing sends viewers to a region that does not home the app.
+- The unlanded docs page `docs/site/live-streams.md` (plan Task 9, copy approved 2026-11-02, never merged) says "Each instance can have 64 held streams open at once." It needs the rev 4 numbers, and a fresh copy review of that line, before it lands.
+- The fleet tunnel's 250 streams per channel are shared by held streams, other long responses and plain requests. Rev 4 caps held streams per channel at 64; ordinary long responses (an unmarked event stream, a slow download) still have no channel-level cap, and a plain request finding the channel full waits.
diff --git a/docs/superpowers/specs/2026-10-28-edge-held-streams-design.md b/docs/superpowers/specs/2026-10-28-edge-held-streams-design.md
index f6efd7e7c..37e484fea 100644
--- a/docs/superpowers/specs/2026-10-28-edge-held-streams-design.md
+++ b/docs/superpowers/specs/2026-10-28-edge-held-streams-design.md
@@ -1,7 +1,8 @@
# Edge-held event streams — design
Discussion: carlos/platform #432 (feature request from Rastrillo, with the
-amendment in post 835). Status: draft, rev 3, 2026-10-28.
+amendment in post 835). Status: rev 4, 2026-11-20 (rev 3, 2026-10-28, shipped
+as #432; rev 4 raises the caps in §3.6, branch `edge-held-cap`).
Review history: round 1 (Astra, `CODEX-FINDINGS-edge-held-streams.md`):
NOT READY, 4 P1 and 6 P2. All ten are accepted in rev 2 and marked
@@ -311,7 +312,44 @@ waits through it.
### 3.6 Bounds
-- **Per host:** 64 held streams. **Per box:** 4,096.
+- **Per host:** 1,000 held streams (rev 4; 64 before). A live event with
+ more than 64 viewers on one app left the rest on a page that never
+ updated. 1,000 is what Rastrillo's live hub serves per process
+ (`live.Config.MaxStreams`), and an app left at systemd's default soft
+ limit of 1,024 open files cannot take many more, so holding more would
+ only queue legs the app refuses.
+- **Per box:** sized from the box when the edge starts (rev 4; 4,096
+ before, fixed). Measured 2026-11-20 over TLS and HTTP/2, one connection
+ per browser, a held stream costs the edge about 95 KiB and one open file
+ while its host sleeps, and 232 KiB and two open files (the leg's
+ socket) with its leg open: three goroutines asleep, seven awake. The
+ cap is as many streams as fit in an eighth of the box's memory at
+ 256 KiB each, never fewer than the per-host cap (so every box can hold
+ one full host), and never more than the open-file limit allows at two
+ each after a reserve of 8,192 for everything else the edge does. That
+ is 1,000 on a 1 or 2 GiB box, about 2,000 at 4 GiB and about 8,000 at
+ 16 GiB. The edge's unit sets no `LimitNOFILE`, so it runs at systemd's
+ hard limit (524,288 on current boxes; Go raises the soft limit to it),
+ and memory is the bound that matters. The old fixed 4,096 could take
+ 930 MiB with every leg open, nearly half a 2 GiB box.
+- **Per channel:** 64 held streams, all hosts together, for requests a
+ tunnel or link channel delivered (fleet boxes, linked deployments;
+ rev 4). Each keeps one HTTP/2 stream of its channel open for its life,
+ and a channel serves 250 streams at once for every request the hub
+ sends (`tunnelclient.DefaultLimits`). With the hub's 128 upgrades
+ (`tunnelUpgradeCap`) that leaves 58 for plain requests; a plain request
+ that finds none waits for one, so without this cap one busy page could
+ stall every app on the box. Past it, the same retry answer as any cap.
+- **Not proxied past a cap (rev 4, weighed and kept).** Proxying a stream
+ as an ordinary request when the host is awake and the cap is full was
+ considered for busy events. It is not done: a proxied stream is
+ activity, so after the event every tab left open past the cap keeps the
+ instance awake until the plan's awake ceiling, which is the bill this
+ design exists to stop; it costs the edge the same memory and files as a
+ held stream while counting against no cap, so the box bound would no
+ longer bound anything; and it holds up a stop (G5). The anti-goal stands.
+ Raising the caps to what the box can afford gives the same viewers the
+ same stream without any of that.
- **Maximum hold:** 1 hour per browser connection, then the edge closes it
(at an event boundary). The browser reconnects and is held again; the
bound is a recycle, not a cut-off, and it limits how stale a held
diff --git a/internal/edge/tunnel_e2e_test.go b/internal/edge/tunnel_e2e_test.go
index 0069cce1a..496763c9e 100644
--- a/internal/edge/tunnel_e2e_test.go
+++ b/internal/edge/tunnel_e2e_test.go
@@ -388,10 +388,12 @@ func TestTunnelHeldStreamsCappedPerChannel(t *testing.T) {
if got, _ := readFor(first.Body, 300*time.Millisecond); first.StatusCode != http.StatusOK || !strings.Contains(got, ": ping\n") {
t.Fatalf("first: status %d body %q, want the box's held stream", first.StatusCode, got)
}
+ // The retry answer ends its response, so the read ends with io.EOF; a
+ // held stream would still be open when the bound passes.
second := open()
- body, err := io.ReadAll(second.Body)
- if err != nil || second.StatusCode != http.StatusOK || string(body) != "retry: 30000\n\n" {
- t.Fatalf("second: status %d body %q err %v, want the over-cap retry", second.StatusCode, body, err)
+ body, err := readFor(second.Body, 5*time.Second)
+ if err != io.EOF || second.StatusCode != http.StatusOK || body != "retry: 30000\n\n" {
+ t.Fatalf("second: status %d body %q err %v, want the over-cap retry, then the end", second.StatusCode, body, err)
}
if st := boxEdge.HeldStreamStats(); st.Held != 1 || st.OverCap != 1 {
t.Fatalf("box held-stream stats %+v, want 1 held and 1 over a cap", st)
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 5a1d2a9dc..db3e13055 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -263,3 +263,4 @@ plan14-root-reads-design-platform-accounts.tsv 4568bc8acc3ee632d7637cb27ca6838c7
plan14-root-reads-replica-wake-gap.tsv 837b586c0aa17936bc64201245a86c3fd66c58e7f1257436b31c75ac001ac00c
plan14-root-reads-replica-wake-gap-r3.tsv 460c6557a81afc8e5a73db79b8673a7495f84c67a0457e69a0e8443f17a265e7
plan14-root-reads-replica-wake-gap-ch.tsv 6c3e03c493dbca78fc128355f071caa2b2d5f22674b98994cd85a0cf63d40ca8
+plan14-root-reads-edge-held-cap.tsv 60feabafe92c0f9b9eed63f990b54c6e467dddcade8f4154433720127b41569d
diff --git a/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv b/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv
new file mode 100644
index 000000000..71b2ca82e
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv
@@ -0,0 +1,5 @@
+# Census overlay edge-held-cap, written by census-propose (#369). census-ruling-edge-held-cap, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-edge-held-cap.md.
+# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy 1688e98a17fa7ec7c0f1617d35f0ab89d400f19349ec0ff5388fc2d926da8a4d internal/edge/heldstream.go Edge.serveHeld legacy accepted-legacy accepted-legacy;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): new; runs one held stream. Registers it in the in-memory held set, checks holdsHost against the published map, and runs the heldTask, which opens legs through the activator's AdmitHeldLeg and the route's own proxy. Reads only the request and in-memory state; no bucket, registry or file read of tenant-writable input. Whole-branch fix: calls a nil-in-production test seam (afterMapCheck) after the map check; a reload closing a stream with no response yet now writes the empty event stream; each leg request carries its own in-memory outcome. No read added.;rev3=census-ruling-edge-held-cap;basis=register now takes whether a tunnel or link channel delivered the request (fromTunnel or linkedRequest on the request context, both set only by this process), so channel-delivered streams count against the new PerChannel cap. No read added; the caps themselves come from in-memory config (heldbudget.go reads Sysinfo and RLIMIT_NOFILE of its own process once at package start). registry:Host@245,registry:Host@793,registry:Host@996,whole:Route@1005,whole:Route@1009 59917cca66ea136fae16b1d04550937ec3ff26a2ea29f175aa90267c2684bf80
+internal/edge/heldstream.go Edge.serveHeld legacy accepted-legacy accepted-legacy;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): new; runs one held stream. Registers it in the in-memory held set, checks holdsHost against the published map, and runs the heldTask, which opens legs through the activator's AdmitHeldLeg and the route's own proxy. Reads only the request and in-memory state; no bucket, registry or file read of tenant-writable input. Whole-branch fix: calls a nil-in-production test seam (afterMapCheck) after the map check; a reload closing a stream with no response yet now writes the empty event stream; each leg request carries its own in-memory outcome. No read added.;rev3=census-ruling-edge-held-cap;basis=register now takes whether a tunnel or link channel delivered the request (fromTunnel or linkedRequest on the request context, both set only by this process), so channel-delivered streams count against the new PerChannel cap. No read added; the caps themselves come from in-memory config (heldbudget.go reads Sysinfo and RLIMIT_NOFILE of its own process once at package start). registry:Host@245,registry:Host@793,registry:Host@996,whole:Route@1005,whole:Route@1009 59917cca66ea136fae16b1d04550937ec3ff26a2ea29f175aa90267c2684bf80
+@coverage internal/edge 53dfb39bb0295d3826918334133b181e378b7a77bea382aeae1ef616351bb725