edge-held-cap: Astra R1 fixes (no P1; two P2, one P3)
P2-1: the 64-slot hop cap also binds the in-region HA forward (forwardHAFollow calls hopTo); the follow-up and spec §3.6 now say so. P2-2: the 200-stream witness no longer races idle expiry: it runs with a 5-minute idle and shortens it through SetIdleFor only after every browser has its event. P3: sizing comments say reported memory and "just under the hard limit". Census re-proposed for the comment-only edge change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+67
−14
docs/superpowers/notes/edge-held-streams-followups.md+1 −1docs/superpowers/specs/2026-10-28-edge-held-streams-design.md+12 −4docs/superpowers/specs/CODEX-FINDINGS-edge-held-cap.md+39 −0internal/activator/heldstream_e2e_test.go+8 −3internal/edge/heldbudget.go+3 −2internal/edge/heldbudget_linux.go+3 −3internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv+1 −1
CI passed — run details
Intent
diff --git a/docs/superpowers/notes/edge-held-streams-followups.md b/docs/superpowers/notes/edge-held-streams-followups.md| index c8f819c5d..8832901b9 100644 |
| --- a/docs/superpowers/notes/edge-held-streams-followups.md |
| +++ b/docs/superpowers/notes/edge-held-streams-followups.md |
| @@ -11,6 +11,6 @@ P3s and parked items from the build's reviews (stopping rule 1: none starts a ro |
| 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. |
| +- Hops cap held streams at 64 per destination box (Astra R1 P2-1). A held stream that reaches its holder through another box's edge rides the hop for its life and takes one of `backhaulMaxInflight`'s 64 slots toward that box, counted on the sending edge and shared by every app on the destination. That covers the in-region HA forward as well as the cross-region backhaul: `forwardHAFollow` calls `hopTo` (`forwardha.go`), which takes the slot in `backhaulAdmit` and keeps it for the response's life (`edge.go` `hopTo`), and the busy-client share (`backhaulClientShare`, once the box is half full) applies too. Past it the hop answers 503, which a native `EventSource` treats as fatal, and ordinary hopped requests to that box get 503 as well. So in a region HA pool, viewers whose connection lands on a box that is not the holder are limited to 64 per sending box across all apps, well under the holder's 1,000. Held streams on a hop want their own share of the slots, and the over-cap retry answer rather than a 503; that touches the egress containment ruling (2026-08-24), so it is Paul's call. Unchanged by rev 4, which raises only what the holding edge accepts. |
| - 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 37e484fea..f6df8208e 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 |
| @@ -326,10 +326,12 @@ waits through it. |
| 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), |
| + each after a reserve of 8,192 for everything else the edge does. By the |
| + memory the kernel reports (a little under the instance size) 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 near systemd's |
| + hard limit (524,288 on current boxes; Go raises the soft limit to just |
| + under 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 |
| @@ -350,6 +352,12 @@ waits through it. |
| 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. |
| +- **Hops are not raised (rev 4).** A held stream that reaches its holder |
| + through another box's edge (in-region HA forward, cross-region |
| + backhaul) still takes one of the hop's 64 slots toward that box for its |
| + life (`backhaulMaxInflight`), shared by every app there, and past it gets |
| + a 503. In a region HA pool that is the binding limit for viewers who |
| + land on a box other than the holder. See the follow-ups note. |
| - **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/docs/superpowers/specs/CODEX-FINDINGS-edge-held-cap.md b/docs/superpowers/specs/CODEX-FINDINGS-edge-held-cap.md| new file mode 100644 |
| index 000000000..a0cce3bcc |
| --- /dev/null |
| +++ b/docs/superpowers/specs/CODEX-FINDINGS-edge-held-cap.md |
| @@ -0,0 +1,39 @@ |
| +Reviewed `cdf98181..53c039755834feaf21bbd4934ec1f37e9555b17c`, round 1. No P1 found. Two P2 findings: |
| + |
| +1. **P2 — Brief §4: the forwarding limitation also affects same-region HA.** |
| + The [follow-up note, line 14](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/docs/superpowers/notes/edge-held-streams-followups.md:14) describes the 64-slot restriction as cross-region only. However, HA forwarding calls `hopTo` at [forwardha.go:485](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/edge/forwardha.go:485), which acquires the same backhaul slot and retains it for the response’s lifetime at [edge.go:4847](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/edge/edge.go:4847). |
| + |
| + **Failure scenario:** 64 held streams forwarded to a same-region holder exhaust the sending edge’s allowance toward that box. Subsequent streams and ordinary requests receive 503 despite capacity remaining under the holder’s new caps. This is pre-existing behavior, not a new merge blocker. |
| + |
| + **Fix:** extend the follow-up to cover same-region HA forwarding; remove the implication that this matters only after cross-region latency routing. Include the shared path’s busy-client restriction at `edge.go:4717–4729`. |
| + |
| + **Fault family:** end-to-end capacity claims must account for intermediate admission limits. |
| + |
| +2. **P2 — Brief §5: idle expiry races the 200-stream witness.** |
| + The test sets a three-second idle period at [heldstream_e2e_test.go:603](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/activator/heldstream_e2e_test.go:603), then wakes once and allows thirty seconds for event delivery at [line 627](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/activator/heldstream_e2e_test.go:627). Meanwhile, its harness sweeps every 50 ms, and idle expiry stops the instance at `activator.go:6069–6083`. |
| + |
| + **Failure scenario:** on a loaded shard, some admissions or child handlers take longer than three seconds. The instance correctly sleeps before those browsers receive the event. Held streams cannot wake it, so the thirty-second wait cannot recover. This is a source-established flake risk; I could not execute the test here. |
| + |
| + **Fix:** control idle expiry in the witness. First observe all 200 events, then trigger expiry through a test-controlled sweep or clock and verify that sleep preserves every stream. |
| + |
| + **Fault family:** test success must depend on observed lifecycle transitions rather than scheduler speed. |
| + |
| +**P3 — Brief §§1/3: minor sizing inaccuracies.** |
| +[heldbudget.go:49](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/edge/heldbudget.go:49) says 2 GiB gives the 1,000 floor; an exact 2 GiB input gives 1,024, as the new test correctly expects. Also, [heldbudget_linux.go:6](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/edge/heldbudget_linux.go:6) says Go raises the soft limit to the hard limit; this toolchain normally raises it to `Max−1` ([syscall/rlimit.go:30](/home/paulca/.local/go-dist/src/syscall/rlimit.go:30)). Readers predicting exact values get different results. Clarify nominal box RAM versus reported RAM and say “near the hard limit.” **Fault family:** sizing descriptions match the implementation. Follow-up only. |
| + |
| +The remaining checks found no additional blocker: |
| + |
| +- Budget division, guarded subtraction and integer clamp are sound. Linux initialization follows `syscall` initialization; the non-Linux implementation avoids Linux-only symbols. |
| +- Channel registration and release balance, including the unmanaged return. Tunnel, fleet, replica and link delivery retain the tunnel mark; direct requests do not acquire it. The implemented cap conservatively aggregates all channel-delivered streams on one edge. |
| +- The 250-stream limit, 128-upgrade cap and full-channel waiting behavior match the code. Memory measurements were not independently reproduced. |
| +- Wake, close and leg cancellation scan streams during lifecycle transitions. Event delivery has no shared-set scan; idle checks are constant-time per stream. Rate slots return at response headers. |
| +- The tunnel witness exercises actual delivery and retry refusal. The unit witnesses cover arithmetic, host/box boundaries and channel-slot reuse. |
| + |
| +Targeted tests could not start because the read-only sandbox denied Go’s work-directory creation. `GOCACHE` was unset. No full suites, cross-builds or census tests ran. `git diff --check` passed; no files changed. |
| + |
| +**Census verdicts** |
| + |
| +- **APPROVE — `Edge.serveHeld`.** Reviewed [heldstream.go:334](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-held-cap/internal/edge/heldstream.go:334) through line 370 and the context-marker producers. The change adds in-memory accounting; route ownership checks, activator admission and proxy selection remain intact. No new tenant-controlled root input is followed. |
| +- **APPROVE — `internal/edge` envelope.** Reviewed the changed configuration, registration, release and budget functions, including `heldbudget_linux.go:9–18` and `heldbudget_other.go:1–7`. New reads obtain kernel memory information and this process’s resource limit. No new file, executable or tenant-selected input is opened, and no authority check is weakened. |
| + |
| +**READY AFTER FIXES** |
| \ No newline at end of file |
diff --git a/internal/activator/heldstream_e2e_test.go b/internal/activator/heldstream_e2e_test.go| index d21e087b4..53596c8fe 100644 |
| --- a/internal/activator/heldstream_e2e_test.go |
| +++ b/internal/activator/heldstream_e2e_test.go |
| @@ -599,9 +599,13 @@ const heldLoadStreams = 200 |
| // request wakes the host: every stream opens its leg on the one child and |
| // every browser gets the next event. The streams are still not activity: |
| // the instance sleeps again under all of them, and they stay open. |
| +// |
| +// The idle window is long enough that the host cannot sleep while a loaded |
| +// machine is still opening legs; once every browser has its event, the |
| +// plans idle hook (SetIdleFor, which can only shorten it) lets the next |
| +// sweep put it to sleep. |
| func TestHeldE2EManyStreamsOneHost(t *testing.T) { |
| - idle := 3 * time.Second |
| - h := newHeldE2E(t, heldE2EOpts{idle: idle}) |
| + h := newHeldE2E(t, heldE2EOpts{idle: 5 * time.Minute}) |
| if h.cfg.PerHost != edge.DefaultHeldConfig.PerHost || h.cfg.PerHost < heldLoadStreams { |
| t.Fatalf("PerHost %d: the witness runs the production cap, at least %d", h.cfg.PerHost, heldLoadStreams) |
| } |
| @@ -635,7 +639,8 @@ func TestHeldE2EManyStreamsOneHost(t *testing.T) { |
| t.Fatalf("%d legs on the woken child, want one per stream, %d", len(legs), heldLoadStreams) |
| } |
| - waitE2E(t, 10*idle, "the instance to sleep under the open streams", h.asleep) |
| + h.a.SetIdleFor(func(registry.Route) time.Duration { return time.Millisecond }) |
| + waitE2E(t, 30*time.Second, "the instance to sleep under the open streams", h.asleep) |
| h.shutdownOf(pid, 10*time.Second) |
| for i, c := range cs { |
| if c.ended() { |
diff --git a/internal/edge/heldbudget.go b/internal/edge/heldbudget.go| index def06c4a2..7361e457b 100644 |
| --- a/internal/edge/heldbudget.go |
| +++ b/internal/edge/heldbudget.go |
| @@ -46,8 +46,9 @@ const ( |
| // the open-file limit nofile leaves room for after heldFileReserve. A zero |
| // memBytes or nofile means unknown, and that bound is left out. |
| // |
| -// For scale: 1 or 2 GiB of memory gives 1,000 (the floor), 4 GiB about 2,000, |
| -// 8 GiB about 4,000 and 16 GiB about 8,000. |
| +// For scale, by the memory the kernel reports (a little under the instance |
| +// size): a 1 or 2 GiB box gets 1,000 (the floor), 4 GiB about 2,000, 8 GiB |
| +// about 4,000 and 16 GiB about 8,000. |
| func heldPerBox(memBytes, nofile uint64) int { |
| n := uint64(heldPerHost) |
| if m := memBytes / heldMemoryShare / heldStreamCost; m > n { |
diff --git a/internal/edge/heldbudget_linux.go b/internal/edge/heldbudget_linux.go| index 3a9441071..89b0f0e77 100644 |
| --- a/internal/edge/heldbudget_linux.go |
| +++ b/internal/edge/heldbudget_linux.go |
| @@ -3,9 +3,9 @@ package edge |
| import "syscall" |
| // heldBoxLimits reads the box's memory and this process's open-file limit |
| -// for heldPerBox, once, when the package starts. The Go runtime has already |
| -// raised the soft limit to the hard one by then. Either is 0 when it cannot |
| -// be read. |
| +// for heldPerBox, once, when the package starts. By then the syscall package |
| +// has raised the soft limit to just under the hard one. Either is 0 when it |
| +// cannot be read. |
| func heldBoxLimits() (memBytes, nofile uint64) { |
| var si syscall.Sysinfo_t |
| if syscall.Sysinfo(&si) == nil { |
diff --git a/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv b/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv| index 71b2ca82e..f249c16dd 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-edge-held-cap.tsv |
| @@ -2,4 +2,4 @@ |
| # 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 |
| +@coverage internal/edge 70d6216036dea9403349b631794f447bd3a914640495513d5514689230b81af9 |