backhaul streams (#1535): round 2 findings
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+130
−0
docs/superpowers/reviews/backhaul-streams-1535/ASTRA-FINDINGS-R2.md+53 −0docs/superpowers/reviews/backhaul-streams-1535/FABLE-FINDINGS-R2.md+60 −0docs/superpowers/reviews/backhaul-streams-1535/LUNA-COPY-RESULT-2.md+17 −0
diff --git a/docs/superpowers/reviews/backhaul-streams-1535/ASTRA-FINDINGS-R2.md b/docs/superpowers/reviews/backhaul-streams-1535/ASTRA-FINDINGS-R2.md| new file mode 100644 |
| index 000000000..69faf4bbf |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/backhaul-streams-1535/ASTRA-FINDINGS-R2.md |
| @@ -0,0 +1,53 @@ |
| +- **Astra R1 P1, memory defaults: partly resolved.** Defaults fell to 512 streams/128 requests; aggregate home-box safety remains unestablished. |
| +- **Astra R1 P1, failed publication: resolved.** The watch commits its baseline only after successful publication; the regression test passes. |
| +- **Astra R1 P2, contention test: resolved in source.** Barriers now coordinate 24 contenders for eight slots and check refusals, shares and releases. Execution remains sandbox-blocked. |
| +- **Fable R1 P2-1, client-controlled classification: resolved.** Admission takes a request slot; only a 101 triggers the swap. |
| +- **Fable R1 P2-2, 1024 default’s classification assumption: resolved as framed.** Classification is corrected and the default reduced; Astra’s aggregate-memory finding remains. |
| +- **Fable R1 P2-3, unscaled share: resolved.** Both shares scale to `min(share, max(1, cap/4))`. |
| + |
| +Reviewed `583fac44fb7e..fb535ebb5dd50fd0c6fd90fbdf799350ad18cd0a`, round 2. |
| + |
| +1. **P1 — The revised defaults still permit home-box memory exhaustion.** |
| + |
| + **Evidence:** [edge.go:4711](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/edge.go:4711) bounds inbound traffic only by summing siblings’ caps. [edge.go:4743](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/edge.go:4743) estimates socket memory but establishes neither a supported sibling count nor a receiving-side budget; [edge.go:4758](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/edge.go:4758) sets 512 streams. The shared edge/instance slice has [MemoryMax=80%](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/host/units/carlos.slice:24). |
| + |
| + **Failure scenario:** 64 senders can maintain 32,768 upgraded hops to one home. The two 32-KiB proxy copy buffers alone require **2 GiB**, before TLS state, goroutine stacks, ordinary requests and applications. A 2-GiB home reaches memory pressure before these admission limits protect it. The existing absence of a direct-upgrade cap does not establish safety for this enlarged backhaul allowance. |
| + |
| + **Fix:** The R1 recommendation remains a conservative **128 streams/64 requests**, conditional on an explicit fleet-size and measured memory budget. No fixed per-sender default establishes safety for arbitrarily many siblings. |
| + |
| + **Fault family:** Aggregate home-box resource containment — repeated in rounds 1 and 2. The stopping rule now requires a decision before another fix attempt: enforce a fleet-size/memory gate, cut the capacity increase, or enforce one aggregate receiving-side budget. I recommend the aggregate budget. |
| + |
| +2. **P2 — Refusing a 101 skips the forwarder’s healthy-response observation.** |
| + |
| + **Evidence:** [edge.go:5085](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/edge.go:5085) returns a stream-admission error before invoking the existing response callback. That callback [records the upstream status and holder](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/forwardha.go:463). Without it, `forwardHANoted` [reports status zero](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/forwardha.go:326); the placement classifier [treats that as failure](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/activator/haplacement_peers.go:101). |
| + |
| + **Failure scenario:** A placement target successfully answers 101, but the sender’s stream cap or client share refuses it. The healthy destination is then marked suspect. For a holder already reported silent during a slow handshake, the confirming response is likewise lost. |
| + |
| + **Fix:** Preserve the upstream-response observation before returning the local stream refusal. Keep the refusal interception that prevents retries. Add a regression covering a successful upstream 101 rejected by local stream admission. |
| + |
| + **Fault family:** Local admission failures contaminating destination-health observations. |
| + |
| +No P3 findings. |
| + |
| +Census verdicts for the reviewed commit: |
| + |
| +| Unit | Verdict | Basis | |
| +|---|---|---| |
| +| `RunWithActivatorReady` | APPROVED | [edge.go:5438](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/edge.go:5438): numeric environment configuration; existing read sites and disposition preserved. | |
| +| `runAgent` | APPROVED | [agent.go:1407](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/host/agent.go:1407): publishes an in-process getter; no new root input or authority. | |
| +| `sampler.tick` | APPROVED | [metrics_loop.go:155](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/host/metrics_loop.go:155): adds in-memory counters to the existing sample; no new external read. | |
| + |
| +| Envelope / additional pin | Verdict | Basis | |
| +|---|---|---| |
| +| `internal/alerting` | APPROVED | [ruletext.go:89](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/alerting/ruletext.go:89): rule metadata and copy only. | |
| +| `internal/edge` | APPROVED | [edge.go:4832](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/edge/edge.go:4832): pool accounting, response handling and counters introduce no new root input or execution authority. Operational findings remain above. | |
| +| `internal/host` | APPROVED | [metrics_loop.go:671](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/host/metrics_loop.go:671): observation and publication ordering use existing paths and authority. | |
| +| `internal/hostenv` | APPROVED | [hostenv.go:89](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/hostenv/hostenv.go:89): one specific numeric setting added. | |
| +| `internal/metrics` | APPROVED | [backhaul.go:12](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/metrics/backhaul.go:12), [alert.go:491](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/metrics/alert.go:491): additive data and in-memory evaluation; no I/O authority. | |
| +| `serveAssetFar` group-name pin | APPROVED | [group_names_test.go:533](/home/paulca/amadan.net/carlos/platform-backhaul-1535/internal/host/group_names_test.go:533): both the function and pin are unchanged from the review base after R2. | |
| + |
| +**Overall census verdict: APPROVED.** This does not clear the operational findings. |
| + |
| +Targeted census, group-name census, metrics, host, hostenv, default-value and console-registration checks passed, as did the enabled code-health gate. Socket-based tests were blocked by sandbox listener permissions; their runtime behavior remains unverified here. No files were edited; tracked working-tree and index diffs remain empty. |
| + |
| +**NOT READY** |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/backhaul-streams-1535/FABLE-FINDINGS-R2.md b/docs/superpowers/reviews/backhaul-streams-1535/FABLE-FINDINGS-R2.md| new file mode 100644 |
| index 000000000..e683f9d4d |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/backhaul-streams-1535/FABLE-FINDINGS-R2.md |
| @@ -0,0 +1,60 @@ |
| +# Review R2: backhaul stream pool (#1535), commit fb535ebb5 |
| + |
| +No P1. One new P2, in the 101 swap. Targeted tests pass in `internal/edge` (`Backhaul|AssetFar|Handover`), `internal/metrics`, `internal/host`, `internal/hostenv` and `internal/console`. I did not run `-race`. Census skipped as instructed. |
| + |
| +## Round 1 findings |
| + |
| +| Finding | Status | Evidence | |
| +|---|---|---| |
| +| Astra P1-1, home-box memory defaults | Partly | Now 512 streams and 128 requests (`internal/edge/edge.go:4758`, `4726`), not the 128 and 64 asked for. No aggregate receiving-side budget, and the cost is estimated, not measured (`edge.go:4743`). The parity argument holds: the home edge does not cap direct upgrades. Residue is P3-1 and P3-2, not a blocker. | |
| +| Astra P1-2, alert lost on failed publish | Resolved | The watch commits only when `alertTick` returns nil (`internal/host/metrics_loop.go:671-681`), and `alertTick` returns only the publish error (`metrics_loop.go:630`). Pinned by `TestBackhaulShedFiresAfterAFailedPublish` (`internal/host/metrics_backhaul_test.go:203`). | |
| +| Astra P2-3, contention test | Resolved | 24 contenders on 8 slots behind a barrier, checking holders, shares, zero counts and refusal counts (`internal/edge/backhaul_streams_test.go:331`). | |
| +| Fable P2-1, client-controlled classification | Resolved | Every hop is admitted on a request slot and swaps at the 101 (`edge.go:5084-5098`). Pinned by `TestBackhaulUpgradeRequestAnswered200StaysInRequestPool` (`backhaul_streams_test.go:674`). | |
| +| Fable P2-2, 1024 default | Resolved | 512, with the per-socket cost in the doc (`edge.go:4743-4751`). | |
| +| Fable P2-3, unscaled share | Resolved | `backhaulShare` caps the share at a quarter of the limit (`edge.go:4807`). Tested at a small cap (`backhaul_streams_test.go:220`, `718`). | |
| + |
| +## P1 |
| + |
| +None. |
| + |
| +## P2 |
| + |
| +**P2-1. A full stream pool no longer refuses without dialling, so socket retries spend request slots.** |
| +- **Problem:** the stream refusal now happens only after the home has answered 101. Every over-cap socket attempt holds a request slot for the whole handshake and opens a fresh TLS connection across the region. It also reaches the app, which accepts the socket and is then cut off. |
| +- **Evidence:** |
| + - Admission is request-pool only (`edge.go:5045`), and the stream pool is first consulted inside `ModifyResponse` (`edge.go:5085-5089`). |
| + - The test requires the dial: "it must be refused at the 101, not at admission" (`backhaul_streams_test.go:648-650`). |
| + - The containment ruling still says a hop at the limit is answered "rather than dialling" (`edge.go:4692`). |
| + - The handshake wait is bounded only by `backhaulHeaderTimeout`, 30 s (`edge.go:4994`). |
| +- **Failure scenario:** 512 sockets are open toward one home box and several hundred more clients reconnect on backoff. Each attempt holds a request slot until the app answers the handshake. If the app is slowed by that churn to about a second per handshake, around 128 attempts a second fill the request pool and ordinary requests get 503. That is the incident's shape again, driven by sockets. Short of that, a sleeping instance is woken by sockets that are refused straight away. |
| +- **Fix:** keep the slot swap at the 101, and add an advisory check at admission. If the request is upgrade-shaped and the box's stream counter is already at the cap, answer `backhaul-streams-busy` with no dial and count it as a stream shed. The header only gets a client refused earlier, so Fable P2-1 stays closed. Re-pin the test: no dial when the pool is already full, with the 101 refusal kept for the race. |
| +- **Fault family:** refusal placed after the cost it bounds. |
| + |
| +## P3 |
| + |
| +- **P3-1. Unbounded catch-up in the shed watch.** The comment says a held-back count "may count two minutes" (`metrics_loop.go:669-670`). A store outage of any length fails every tick that has an event, so `prev` never advances. A trickle of 11 refusals over hours then fires "more than 10 in a minute" on recovery. Either cap the carry to the pending firing transition or correct the comment. |
| +- **P3-2. Sender-side sum missing from the doc.** The `backhaulMaxStreams` doc sums the cost over siblings for the home box (`edge.go:4749-4751`). It does not say the sender pays about 50 MB per destination box, so its worst case scales with the number of home boxes. |
| +- **P3-3. No reason given for 128.** The doc says the request pool "holds no open sockets, and its default is 128" (`edge.go:4700`). With sockets gone, 64 already has more headroom than before. The doubling of the 2026-08-24 bulk-transfer bound needs its reason stated (presumably SSE and long polls) or should go back to 64. |
| +- **P3-4. Stale value while firing.** `RuleState.Value` keeps the first reading for as long as the rule fires (`internal/metrics/alert.go:498-500`), so a worsening shed shows the opening count. |
| +- **P3-5. Two upgrade predicates remain.** The R1 P3 on `isUpgradeRequest` still stands and is now harmless, since classification is by response. The P2-1 fix should reuse it, not add a third. |
| + |
| +## Checked and clean |
| + |
| +- **101 swap.** |
| + - It acquires the stream slot before releasing the request slot, on the `ServeHTTP` goroutine, with one deferred release of whichever slot is held (`edge.go:5054-5055`, `5090-5092`). |
| + - A refusal returns before `onResponse` or the scrub runs, and the stdlib closes the backend connection. |
| + - A 101 that the proxy then rejects for a protocol mismatch releases its stream slot through the defer. |
| +- **Holder and forward hooks.** |
| + - Stream errors are answered before `onError`, so the holder path sets no retry target and drops no holder (`internal/edge/backhaul_holder.go:298-317`). |
| + - On the forward path the result keeps status 0 with no holder, which the holder cache treats as no information (`internal/activator/hacache.go:516-521`). |
| + - Holder and handover retries fire only on a 503 at the transport, never on a 101. |
| +- **Accounting.** Each refusal is counted once: request-pool refusals in `backhaulAdmit`, stream-pool refusals in `backhaulStreamAt101`. Door callers stay unkeyed (`backhaul_streams_test.go:755`). |
| +- **Alert.** |
| + - It holds through two quiet minutes and clears on the third (`alert.go:491-503`). |
| + - A nil reading holds the state. |
| + - A restored fire clears because the loop reads the counters directly, not the sample's nil-when-zero copy (`metrics_loop.go:1107-1113`). |
| + - Fair-share 429s are excluded from the rule (`internal/metrics/backhaul.go:20`). |
| + - Quiet boxes' samples are unchanged (`internal/host/agent.go:4938-4944`). |
| +- **Console.** Level, order, valued entry, value text and copy are all registered, and the console tests pass. |
| + |
| +**Verdict: READY AFTER FIXES** |
diff --git a/docs/superpowers/reviews/backhaul-streams-1535/LUNA-COPY-RESULT-2.md b/docs/superpowers/reviews/backhaul-streams-1535/LUNA-COPY-RESULT-2.md| new file mode 100644 |
| index 000000000..e1d69f7d2 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/backhaul-streams-1535/LUNA-COPY-RESULT-2.md |
| @@ -0,0 +1,17 @@ |
| +Verdict: changes required before approval. |
| + |
| +| Key | New text or approved | Why | |
| +|---|---|---| |
| +| `BackhaulShedWhatToDo` plain-text adjustment | Approved | The alert string uses quotes/plain text and no backticks. | |
| +| `BackhaulShedWhen` | Approved | Clearly identifies refusals caused by a reached destination limit. | |
| +| `BackhaulShedThreshold` | “Fixed at more than 10 forwarded requests refused because a limit was reached in one minute. Clears after three minutes with none. Not configurable.” | “Refused at the limit” is awkward and less direct. | |
| +| README defaults | Approved | 128 ordinary requests and 512 sockets are clear. | |
| +| README socket explanation | “Once the destination box accepts the upgrade, the socket keeps its place until it closes, using the socket pool rather than ordinary-request capacity. The request to open it counts against ordinary-request capacity until acceptance. If the socket pool is full when the destination accepts it, the request gets `503` with `Retry-After: 2`.” | Makes the request-slot-to-socket-slot handoff unambiguous. | |
| +| README fair-share sentence | “While `CARLOS_RATE_LIMIT` is `enforce`, once the relevant backhaul pool is at least half full, one visitor address may hold at most 8 ordinary requests in the request pool or 64 sockets in the stream pool. If one quarter of that pool's limit is lower, the lower value applies. Requests over the share get `429`.” | The current “that limit” and “that is fewer” are ambiguous about which pool they describe. | |
| +| README exclusion sentence | “Requests refused because a visitor exceeded its share do not count toward it.” | A visitor is not itself refused; its requests are. | |
| + |
| +Substance flags: |
| + |
| +- The current fair-share wording could make an operator apply the request share to sockets or vice versa. |
| +- The socket wording should state explicitly that the request occupies ordinary-request capacity until the destination accepts the upgrade. |
| +- No files were edited. |
| \ No newline at end of file |