edge: end a proxied HTTP/1 body at its declared length (#1032)
The root db-forward e2e flake was a production bug in the edge's proxy.
After writing a request body's declared bytes upstream, net/http's
transport reads once more to confirm EOF; on HTTP/1.1 the server closes
the inbound body once the response head is written. When the upstream
streams its first line at once (a forwarded db read), the edge wrote the
head first, the confirming read hit the closed body, and the transport
closed the upstream connection mid-stream ("the read did not finish").
Edge.ServeHTTP now gives HTTP/1 requests with a declared length a body
that answers EOF itself at that length, with serialised reads; HTTP/2 is
left as it is.
Deterministic test fails on the old code; real carlos db query runs
under load went from 3/400 failures to 0/400. Reviewed by Astra (round
1 NOT READY: a counter race and the HTTP/2 scope, fixed in 398e5f62;
round 2 READY). Census approved on #280.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Squashed from fix-dbforward-reuse-1032 into main.
9 files changed,
+647
−1
docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md+23 −0docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R1.md+24 −0docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R2.md+44 −0docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032-R2.md+69 −0docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032.md+52 −0internal/edge/edge.go+65 −1internal/edge/proxybody_test.go+361 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-fix-dbforward-reuse-1032.tsv+8 −0
CI passed — run details
diff --git a/docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md b/docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md| new file mode 100644 |
| index 000000000..22ec31434 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md |
| @@ -0,0 +1,23 @@ |
| +# Census approval: fix-dbforward-reuse-1032 |
| + |
| +Ruling `census-ruling-fix-dbforward-reuse-1032`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/edge/edge.go` `Edge.ServeHTTP` | body | unchanged (65) | the drain tracking call now takes withDeclaredBodyEnd(r) instead of r: an HTTP/1 request with a declared Content-Length is served from there on with a body that answers EOF itself after those bytes (#1032), so a proxy transport's confirming read after sending the body upstream no longer lands on the server's closed request body and tears down the upstream connection; HTTP/2 requests are left as they are (Astra r1 P2); memory only, no read, dial or store access added | |
| + |
| +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/edge.go` `Edge.ServeHTTP`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the response cache, and on an upgrade trackUpgrade then planUpgradeAdmit (plans 4c, Astra findings 1 and 2); the new reads live in those units (plans-4c-units decision). The same read sites here.;rev3=census-ruling-plans-4d-lapse;basis=calls planDisabledAdmit right after the import gate, passing the final upstream's route and the request host; a turned-off route gets the fixed disabled page before the meter, gate, cache and activator (plans 4d). The new read lives in that unit (plans-4d-units decision); one more whole-row pass here.;rev3=census-ruling-edge-protection-2;basis=runs the guard, a pure in-memory matcher on r.URL.Path and RawQuery (internal/edgeguard), once per request after the meter and observer defer and before the password gate, the upgrade branch, the cache and the activator, for a request that is not a door call, a backhauled door hop or a tunnel delivery; a matched block answers a 404 itself through guardDecide; the two new sites are one expression, up.route.Kind == "static" (a static route this box serves checks only the hard tier here and leaves the probe tier to serveTree), a read of the route row the edge already resolved; no new kind of read;rev3=census-ruling-edge-asset-cache-3;basis=the asset cache's three hooks (asset cache plan 3): the request's reserved asset headers are deleted at entry (the fill assertion kept only beside a verified hop); on the exact-remote and lookup-miss branches the far catch (serveAssetFar) is tried before backhaulTo and backhaul; after the observer defer and main's hard and probe checks, a verified hop with a valid fill assertion is answered by serveAssetFillForHop; after the upgrade branch and before gzip and the shared cache, the local catch (serveAssetLocal); the observer defer skips only the usage meter for an acknowledged home fill (out.unbilled); the new reads live in the new units of the edge-asset-cache-3-decisions overlay; the same route row and read sites (25); no read added;rev3=census-ruling-regional-domains-447;basis=#447 Task 5: straight after lookupUpstreamPath it calls regionalGate (regional.go), which for an entry built from a regional_domains row answers 503 to a hop or a deny entry before any arm that can leave the box (the exact-home backhaul, the far asset catch, the door dial, the miss backhaul), and lets a star match through only to the exact-home arm when ExactHome names another box for that distinct exact name; after the exact-home arm a regional deny entry the arm did not answer is refused (regionalRefuse, 503); refusals only, on the route map the edge already holds; read sites unchanged (25);rev3=census-ruling-static-headers;basis=the shared response cache is no longer looked up or filled for a static-kind route: one more read of the route row the edge already resolved (up.route.Kind == "static") in the cacheable expression; a refusal only, nothing new opened or followed;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2 (N-HA10): one call, frontForwardHA, right after the route lookup's !ok block and before the login POST; same reads;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 4: loginPost and cacheable treat a forward row as not this box's to answer (IsForward(), +whole:Route x2): no login form and no shared cache for a forward host. Serving only.;rev3=census-ruling-tunnel-websockets;basis=Deletes the Carlos-Upgrade marker header from incoming requests and puts the upgrade admission (host, path, the entry tenancy, all in hand) on a tunnel arm request. For a login POST on an ungated ArmTunnel row it reads the visitor request body (bounded by gate.MaxFormBody, 413 past it; a request body, not a file) and resolves next against the entry Reload built (Gate, Route); the bytes pass on only when loginPassesThrough holds (spec 7, Tasks 3, 5 and 6).;rev3=census-ruling-console-protection-tab;basis=one more call in the observer defer, observeGuardCount(up.route, out), beside the observeRecords call that files the guard Match: it passes on the route row the defer already holds (+whole:Route) and the request outcome to the usage meter, which counts the check in memory. Called whether or not the request was unbilled, as observeRecords is. Nothing is opened, read or followed; no new kind of read; no check, refusal or serving decision changes.;rev3=census-ruling-probe-burst-limit;basis=answers a probe-burst notice POST (serveBurstNotice) ahead of every route for a non-door caller; builds the guard state for up.route and stamps its account and app (RouteAccount, App) for the cool-down's this-app/other-app label; for a catalogue match on a non-static or tunnelled route, offers the burst rule (in-memory limiter, burstDecide: 429 or a watch verdict, never a block for a fleet or forward row); the observer defer calls noteBurst(up.route, ...); the added sites are the route value already in hand (+registry:App, +whole:Route x5); no new root read or write kind;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): parses the request's query once (stripHoldMarker) to record the carlos_hold=1 mark in the request context; calls classifyHold on the upstream already resolved from the loaded map (the +whole:Route is that in-memory Route), including a second pass for a login POST; gives a marked request on a door-refused route the plain 404; adds the hold branch (planThrottleAdmit, rateAdmit, serveHeld) after the gate; and excludes marked requests from the shared cache. Reads only the request and the already-loaded upstream map; no registry or bucket read added.;rev3=census-ruling-region-ha-p3a;basis=Complete the P3a cut: an exact peer name with no dial target answers the approved admission 503 before local wildcard dispatch or asset serving. ExactHome and lookupHome stop fallback at a present non-dial entry; backhaulTo refuses an empty target before signing or dialing. Retain Task 3 local admission and fixed platform/unit exemptions. Two added whole Route uses feed the local in-memory admission predicate; existing Route values and store/path reads are unchanged.;rev3=census-ruling-stateless-coordinator-route;basis=P24/P25: POST only, exact /api/fleet/replicas/ prefix on the reserved tunnel host calls the existing local console proxy only for an unescaped, already-clean path; malformed forms remain on the hub. No new read sites relative to origin/main. Merge with main 3487d6f6 retains its region HA admission checks before routing and after login target lookup, its empty-home refusal, and their two existing whole:Route reads; these change this unit's digest relative to the previously approved branch tip 92b24a7d.;rev3=census-ruling-stateless-replicas-3;basis=Task 1a: pass the already-resolved Route to the reserved replica-probe handler after acceptHop and existing admissionRefuses, requiring tunnel context plus private marker and refusing door/backhaul ingress. Added whole Route use only; scrub marker before forwarding; HA calls remain unchanged.;rev3=census-ruling-region-ha-p3b;basis=Resolve local aliases/catch-alls with cached peer name ownership before serving. Add registry Account/App/ClaimStamp/Host/Incarnation/ServingSeq and six whole Route references for NameClaim; inputs are agent registry rows/edges publications used by unprivileged edge, not root permits. Closed owners retain names and return 503; aware remote owner cannot fall through on missing transport, while legacy hop/door behavior remains. Merge 45cebde4 retains authenticated replica probes after local admission and before ordinary name resolution; probe authentication still requires the tunnel context.;rev3=census-ruling-agent-start-demo-2;basis=edge.go:1901 enters the protected demo path before ordinary exits; :2012-2015 rechecks the selected marked Route after lookup. Added whole Route use routes demos through serving checks, counters and policy; no new registry query or file open in this unit.;rev3=census-ruling-demo-api-site-route;basis=Reserve the configured site API namespace after hop verification and control-header scrubbing, before ordinary static, cache, billing and tenant dispatch. Validate hop field shape and delegate only allowlisted operations to the dedicated console path with verified client attribution and console admission. The alias helper enables HTTP/1.1 full duplex so an early console refusal does not wait for upload EOF. Existing 56 read sites unchanged; no new registry, bucket or file read.;rev3=census-ruling-region-ha-g2-fixes;basis=Consult HA ingress after region admission and before miss/alias backhaul; no new direct read; routing-only metadata does not create an upstream.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3/W4: backhaul and door calls pass the owner the door checked into backhaulTo; the §6.5 holder follow (once, GET/HEAD or an unswitched upgrade, no body) and one connect-failure fallback dial only boxes in the holder region's view (same Region/Placement/DataBucket, HomeEligible, fresh) for that owner. Holder name comes only from the TLS-verified signed hop answer; app-set X-Carlos-Holder stays stripped. Routing only; the receiving box still re-checks the lease. No new read site.;rev3=census-ruling-edge-page-cache-1;basis=attaches an in-memory page mark holder to every request to an instance route (the +registry:Kind check of up.route.Kind), wraps the hold and upgrade branches in pageDiagnostics, asks servePage after the plan throttle (a hit answered from the page index over the asset store), keeps an opted-in instance out of the LRU (pagesOptedIn), wraps the response in the page writer, and wraps the proxy's writer in assetInformationalScrub on the remaining arms; the page reads are in the new pagecache.go units;rev3=census-ruling-region-ha-held-build;basis=first branch: a request for the reserved control paths /.carlos/ha-drain and /.carlos/ha-take goes to serveHAControl and returns (refused unless a signed ask); no request on those paths reaches a route, a forward or an app; no read added here. region HA held-requests Task 2: X-Carlos-Replayable is read from verified hops only and deleted from every request; just before frontForwardHA, moveGate runs for an HA hibernating route (route HA, Host and the whole Route passed in memory) and can only hold, refuse with an existing answer or front-forward to the confirmed holder; ReleaseMoveTicket before serveHeld; no store or filesystem read added; region HA held-requests Task 5: after the HA control-path branch, every request is counted by the connection drain (conns.track: a cancellable request context, and Connection: close only while draining); memory only; no read added; Task 5 fix 1: after the drain's final barrier a new request is refused at once through handoverExit with the existing answerHolderUnreachable, never forwarded; the tracked request also carries its connection (from ConnContext) so the drain can close it at its bound; memory only; no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 3: the inbound strip also deletes tunnelclient.LinkAppHeader (Carlos-Link-App) from every client request, beside Carlos-Tunnel-Upgrade; a header delete, no read added; linked deployments slice 1 Task 8: a request carrying a link pin (ServeLinked, set only by the home agent's link handler from its own registry's published set) skips the edge's own handlers (HA control, demo handling, the steering probe, the tunnel hub, hop acceptance, the burst notice, the demo API alias, the replica probe), takes its upstream from selectUpstream (the pinned exact entry or a 502), never enters the alias/catch-all backhaul block, the HA front forward, the local asset catch, the page cache or the response LRU; the two lookupUpstreamPath calls become selectUpstream; no read added;rev3=census-ruling-stateless-replicas-4-r28;basis=R28 (#511): for a request whose host has no entry (the lookup miss), after the replica-probe branch, calls refuseRetiredCopy(r, host): within the grace of a host whose replica copy this box retired, the fleet tunnel stream is refused with REFUSED_STREAM (tunnelclient.Refuse) and nothing is written; any other miss gets the unknown-host answer as before; memory only, a refusal only, no read added;rev3=census-ruling-static-site-geo-962;basis=discussion #962: after planDisabledAdmit and before the page mark holder and the observer, a request whose cleaned path is /.carlos/geo (not a linked request) is answered by serveGeoAnswer from the request's geo answer already on the context (decideGeo), 200 JSON no-store or 405, and returns; merged with main (no new read);rev3=census-ruling-fleet-unrouted-503;basis=a request the hub tunnel delivered (tunnelclient mark, not a link channel) for a host this box neither routes nor backhauls answers 503 Retry-After 2 instead of the unknown-host 404; no new read, dial or store access; unmarked requests unchanged (#1008);rev3=census-ruling-fleet-unrouted-503-fix1;basis=a request the hub delivered over this fleet box's channel (MarkFleetChannel, set by the box's own tunnel loop for a "<fleet>/<label>" channel, plus the tunnel client mark) for a host this box neither routes nor backhauls, and not under a platform domain, answers 503 Retry-After 2 instead of the unknown-host 404; fixed log key; no new read, dial or store access; every other request unchanged (#1008) |
| + |
| +New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| + |
| +- new `internal/edge/edge.go:declaredBody.Read`: reads +file:Read ×2; written legacy, accepted-legacy, frozen |
| + |
| +Seal: `33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc820c5fe7b44c870e671565e1063` → `ec3c40098ec0a652c735d54925f334b9b9680c9e2b6cd0c3d9497b8a615fb86f`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-fix-dbforward-reuse-1032.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R1.md b/docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R1.md| new file mode 100644 |
| index 000000000..09705c208 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R1.md |
| @@ -0,0 +1,24 @@ |
| +Astra round 1 on fix-dbforward-reuse-1032 at 6f2938d0: NOT READY. |
| +(Reconstructed from the reviewing session's transcript: the original |
| +output file was lost when the session's scratch directory was deleted.) |
| + |
| +1. P1: the remaining-byte counter races with early-answer cleanup |
| + (internal/edge/edge.go ~2292). For an HA-forwarded upload larger than |
| + the replay limit, finishEarlyAnswer's discard read (replay.go ~186) |
| + overlaps the transport's pending read; both enter declaredBody.Read, |
| + which reads and modifies `left` outside net/http's body lock. Fix: |
| + serialise the whole wrapper Read; keep Close able to unblock a pending |
| + read; add an overlapping-read test; run the early-answer tests under |
| + -race. |
| +2. P2: the synthetic EOF bypasses HTTP/2 stream completion (edge.go |
| + ~2278, ~2301): on HTTP/2 the declared bytes do not end the stream; |
| + trailers and errors come on a later read; the store door |
| + (storedoor.go ~293) could act before END_STREAM. Fix: restrict to |
| + HTTP/1, or track a real underlying EOF; add HTTP/2 tests (delayed |
| + END_STREAM, trailers, extra DATA). |
| + |
| +Confirmed: the HTTP/1 root cause against Go 1.26.10's source; HTTP/1 edge |
| +cases sound (chunked and zero length unchanged, short bodies keep |
| +io.ErrUnexpectedEOF, CL/TE handling, 100-continue, MaxBytesReader, Close). |
| +Census: Edge.ServeHTTP, declaredBody.Read and the internal/edge envelope |
| +rejected pending these fixes. |
diff --git a/docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R2.md b/docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R2.md| new file mode 100644 |
| index 000000000..9f6e8bece |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R2.md |
| @@ -0,0 +1,44 @@ |
| +Round-1 P1 — **resolved**: [edge.go:2305](/home/paulca/amadan.net/carlos/platform-fix-dbforward-reuse-1032/internal/edge/edge.go:2305) holds the mutex across the remaining-length checks, underlying read and decrement. `Close` remains delegated without taking that mutex. |
| + |
| +Round-1 P2 — **resolved**: [edge.go:2285](/home/paulca/amadan.net/carlos/platform-fix-dbforward-reuse-1032/internal/edge/edge.go:2285) excludes HTTP/2, preserving its END_STREAM, trailer and excess-DATA handling. |
| + |
| +Reviewed `origin/main...bd4c787e82c7d4ebc0eb0ea6ee80af761fca05cf`, with merge base `a23423b7c8b5f5c4105e7a797feaf4d88061054b`. |
| + |
| +**Findings:** no outstanding P1, P2 or P3 findings in the branch diff. |
| + |
| +The claimed HTTP/1 root cause is correct. Go 1.26.10’s [transfer.go:371](/home/paulca/.local/go-dist/src/net/http/transfer.go:371) copies the declared body length, then reads again for excess bytes. Its [server.go:1392](/home/paulca/.local/go-dist/src/net/http/server.go:1392) can consume and close the inbound body while emitting response headers. A subsequent body-read error makes the transport close the upstream connection, including an unfinished response. The wrapper prevents that confirming read from reaching the closed server body. |
| + |
| +The placement at [edge.go:2341](/home/paulca/amadan.net/carlos/platform-fix-dbforward-reuse-1032/internal/edge/edge.go:2341) covers TCP, Unix, multi-upstream, backhaul, HA forwarding, tunnel and upgrade dispatch. Linked requests also enter this point. Held-stream legs and asset fills construct bodyless requests; cache misses retain the wrapped request where they proxy it. Cache hits introduce no upstream body read. The earlier HA control-path return does not proxy. |
| + |
| +The body semantics remain sound: |
| + |
| +- Unknown-length, chunked, zero-length and HTTP/2 requests are unchanged. |
| +- A short HTTP/1 body retains the underlying `io.ErrUnexpectedEOF`. Non-EOF errors are preserved. |
| +- Excess HTTP/1 bytes remain subject to the server’s existing request framing; the wrapper cannot consume the next request. |
| +- Content-Length and Transfer-Encoding parsing still occurs before this helper. Go rejects conflicting duplicate lengths; for accepted chunked-plus-length requests it removes Content-Length and sets the length to `-1`, bypassing the wrapper. |
| +- `Expect: 100-continue` still reaches the original reader. `MaxBytesReader` still detects overflow because the wrapper permits reads beyond the configured limit whenever the declared body exceeds that limit. |
| +- `GetBody` and retry eligibility are unchanged. Existing replay paths create fresh readers. |
| +- `Close` still reaches the underlying body. Returning EOF after the declared bytes, including after closure, is the intended change. |
| +- Hijacking and upgraded connection I/O are unchanged. |
| + |
| +I found no unintended tenant-visible change. The intended difference is that an otherwise valid streaming response survives the transport’s trailing body check. |
| + |
| +The existing full-duplex calls need separate treatment. [handover.go:297](/home/paulca/amadan.net/carlos/platform-fix-dbforward-reuse-1032/internal/edge/handover.go:297) closes ordinary HTTP/1 connections and sets a cleanup deadline, avoiding normal keep-alive reuse. [demo_api.go:132](/home/paulca/amadan.net/carlos/platform-fix-dbforward-reuse-1032/internal/edge/demo_api.go:132) lacks equivalent cleanup guarantees. Its early-response/upload interaction merits a separate reproduction and follow-up; this patch does not establish that it is safe. I did not demonstrate a panic there, and enabling full duplex alone is insufficient evidence to report one. |
| + |
| +The deterministic streaming test correctly forces the old failure: it releases the trailing read only after the client receives response headers. Without the fix, that read reaches the closed inbound body. The new HTTP/2 tests exercise trailers, delayed END_STREAM and excess DATA; the overlapping-read test addresses the counter race. |
| + |
| +**Validation limitation:** I could not execute the tests. The prescribed invocation was blocked when Go attempted to update `go.mod`; a read-only-module retry was blocked creating its build directory. Consequently, the `-count=20`, race-test and 0/400 results remain author-reported, not independently reproduced. `git diff --check` passed, and the worktree remained unchanged. |
| + |
| +**Census verdicts at the reviewed tip:** |
| + |
| +| Unit or envelope | Verdict | Basis | |
| +|---|---|---| |
| +| `Edge.ServeHTTP`, lines 2322–3267 | APPROVE | The change at line 2341 installs an in-memory body wrapper. Existing routing, authorization and storage decisions remain intact. Retain `legacy / accepted-legacy`. | |
| +| `declaredBody.Read`, lines 2305–2320 | APPROVE | Reads only the existing request body, with serialized accounting. Adds no filesystem, registry, bucket or root-authority access. Accept `legacy / accepted-legacy`. | |
| +| `internal/edge` envelope | APPROVE | Reviewed both changed production functions and the new helper. No new root-controlled input or weakened trust boundary. | |
| + |
| +Both unit digests, their legacy fingerprints, the Linux source envelope and the complete legacy-seal chain match the proposal. The final seal is `72771689d131a1baeabf32439316ea924e595ab29d13bd7d8c664f1a71da9921`. This was a direct fingerprint verification, not execution of the census tests. |
| + |
| +Round 2 has no P1; the stopping rule ends the review here. |
| + |
| +READY |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032-R2.md b/docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032-R2.md| new file mode 100644 |
| index 000000000..6dd41bde8 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032-R2.md |
| @@ -0,0 +1,69 @@ |
| +# Review brief: branch fix-dbforward-reuse-1032, round 2 of 3 |
| + |
| +Repo carlos/platform, branch `fix-dbforward-reuse-1032` (tip in the prompt). |
| +Under review: the diff `origin/main...<tip>` (base a23423b7). |
| +Authorities: amadan #1032, AGENTS.md ("The census", "Stopping rules"). |
| + |
| +You are the independent reviewer and census reviewer (card: |
| +`docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md`: |
| +Edge.ServeHTTP body change, new unit declaredBody.Read). This is the |
| +**tenant request path** of every edge. |
| + |
| +Claimed root cause: net/http's transport, after writing a request body's |
| +declared bytes upstream, reads once more to confirm EOF; on HTTP/1.1 the |
| +server closes the inbound request body when the response head is written; |
| +when the upstream streams its first line at once, the edge writes the |
| +head before that confirming read, the read gets "invalid Read on closed |
| +Body", and the transport closes the upstream connection mid-stream. The |
| +fix: Edge.ServeHTTP hands the drain tracker a request whose body reports |
| +EOF at its declared length (withDeclaredBodyEnd / declaredBody). |
| + |
| +## What to check |
| + |
| +1. Is the root cause right (read the Go 1.26.10 net/http transport and |
| + server code it cites)? Is the fix complete for every edge proxy path |
| + (unix, tcp, backhaul, multi, held, tunnel, WebSocket upgrade, asset |
| + cache, page cache)? |
| +2. Correctness of declaredBody: ContentLength -1 / chunked bodies, |
| + ContentLength 0, a client sending fewer bytes than declared (must |
| + still error, not silently truncate), more bytes than declared, |
| + Expect: 100-continue, request smuggling (CL/TE conflicts must still |
| + be rejected as before), hijack/upgrade paths, GetBody/retries, body |
| + size limits (MaxBytesReader) still enforced, Close semantics. |
| +3. Any behaviour change on a request path a tenant would notice? |
| +4. EnableFullDuplex was rejected (panics); demo_api.go and handoverExit |
| + still use it: real risk to file? |
| +5. Tests: the new deterministic test fails on the old code; the |
| + -count=20 runs and the 0/400 loop. |
| +6. Census verdicts. |
| + |
| +## Round 2 |
| + |
| +Earlier rounds: round 1, Astra, |
| +`docs/superpowers/reviews/FINDINGS-fix-dbforward-reuse-1032-R1.md` (NOT |
| +READY: one P1, one P2). First give one line per round-1 P1 and P2: |
| +resolved, partly, or not. Carry unresolved ones forward, then add new |
| +findings. The verdict covers everything outstanding. |
| + |
| +Fix since round 1 (398e5f62): declaredBody.Read holds a mutex across the |
| +length checks, the inner Read and the decrement (Close does not take it, |
| +so it still unblocks a pending read); withDeclaredBodyEnd wraps HTTP/1 |
| +requests only. New tests: TestDeclaredBodySerialisesOverlappingReads |
| +(-race) and TestEdgeLeavesAnHTTP2BodyToItsStream (trailers, END_STREAM |
| +after the answer starts, extra DATA); the early-answer tests pass under |
| +-race; the 400-run loop failed 0 of 400. Census re-proposed (card |
| +updated). Give fresh census verdicts at this tip. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| +- **P2**: wrong or missing. Fixed without reopening this review (request |
| + path and census changes in the fix still get a scoped check). |
| +- **P3**: clarity or polish. Follow-up list only. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3 with file:line, failure scenario and fix, and |
| +the invariant each breaks. Then census verdicts. End with exactly one |
| +verdict: READY, READY AFTER FIXES, or NOT READY. Do not edit files, spawn |
| +reviewers or run full suites. |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032.md b/docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032.md| new file mode 100644 |
| index 000000000..6f7273028 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-fix-dbforward-reuse-1032.md |
| @@ -0,0 +1,52 @@ |
| +# Review brief: branch fix-dbforward-reuse-1032, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `fix-dbforward-reuse-1032`, commit 3b3d2235446a630b9e77b19588769c9b44d89122. |
| +Under review: the diff `origin/main...3b3d2235446a630b9e77b19588769c9b44d89122` (base a23423b7). |
| +Authorities: amadan #1032, AGENTS.md ("The census", "Stopping rules"). |
| + |
| +You are the independent reviewer and census reviewer (card: |
| +`docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md`: |
| +Edge.ServeHTTP body change, new unit declaredBody.Read). This is the |
| +**tenant request path** of every edge. |
| + |
| +Claimed root cause: net/http's transport, after writing a request body's |
| +declared bytes upstream, reads once more to confirm EOF; on HTTP/1.1 the |
| +server closes the inbound request body when the response head is written; |
| +when the upstream streams its first line at once, the edge writes the |
| +head before that confirming read, the read gets "invalid Read on closed |
| +Body", and the transport closes the upstream connection mid-stream. The |
| +fix: Edge.ServeHTTP hands the drain tracker a request whose body reports |
| +EOF at its declared length (withDeclaredBodyEnd / declaredBody). |
| + |
| +## What to check |
| + |
| +1. Is the root cause right (read the Go 1.26.10 net/http transport and |
| + server code it cites)? Is the fix complete for every edge proxy path |
| + (unix, tcp, backhaul, multi, held, tunnel, WebSocket upgrade, asset |
| + cache, page cache)? |
| +2. Correctness of declaredBody: ContentLength -1 / chunked bodies, |
| + ContentLength 0, a client sending fewer bytes than declared (must |
| + still error, not silently truncate), more bytes than declared, |
| + Expect: 100-continue, request smuggling (CL/TE conflicts must still |
| + be rejected as before), hijack/upgrade paths, GetBody/retries, body |
| + size limits (MaxBytesReader) still enforced, Close semantics. |
| +3. Any behaviour change on a request path a tenant would notice? |
| +4. EnableFullDuplex was rejected (panics); demo_api.go and handoverExit |
| + still use it: real risk to file? |
| +5. Tests: the new deterministic test fails on the old code; the |
| + -count=20 runs and the 0/400 loop. |
| +6. Census verdicts. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| +- **P2**: wrong or missing. Fixed without reopening this review (request |
| + path and census changes in the fix still get a scoped check). |
| +- **P3**: clarity or polish. Follow-up list only. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3 with file:line, failure scenario and fix, and |
| +the invariant each breaks. Then census verdicts. End with exactly one |
| +verdict: READY, READY AFTER FIXES, or NOT READY. Do not edit files, spawn |
| +reviewers or run full suites. |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 86e490c37..afca1bd0e 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -2257,6 +2257,68 @@ func firstSegmentClean(p string) string { |
| return firstSegment(path.Clean(p)) |
| } |
| +// withDeclaredBodyEnd gives an HTTP/1 request with a declared |
| +// Content-Length a body that answers EOF itself once those bytes have been |
| +// read (#1032). |
| +// |
| +// After a proxy's transport has sent the declared bytes upstream, it reads |
| +// the body once more to confirm EOF before it counts the request as |
| +// written. On HTTP/1.1 net/http may close the server's request body when it |
| +// flushes the response head, so an upstream that answers the moment it has |
| +// the body (a forwarded db read streams at once) can make that read land on |
| +// a closed body. The read fails ("invalid Read on closed Body"), the |
| +// transport closes the upstream connection, and the streamed answer is cut |
| +// after its first bytes. With the end answered here, the confirming read |
| +// never reaches the server's body. On HTTP/1 the server's framing has |
| +// already ended the body at that length, so the EOF is the one it would |
| +// give. |
| +// |
| +// HTTP/2 is left alone: there the declared bytes arriving do not end the |
| +// stream (trailers, a reset or excess DATA come on a later read), and the |
| +// server never closes the body under a handler, so the race does not exist. |
| +// |
| +// Full duplex (ResponseController.EnableFullDuplex) would also keep the |
| +// body open, but then a transport goroutine still reading the body after |
| +// the handler returns races the server's read of the next request on the |
| +// same connection, which net/http answers with a panic. |
| +func withDeclaredBodyEnd(r *http.Request) *http.Request { |
| + if r.ProtoMajor != 1 || r.ContentLength <= 0 || r.Body == nil || r.Body == http.NoBody { |
| + return r |
| + } |
| + out := r.WithContext(r.Context()) |
| + out.Body = &declaredBody{ReadCloser: r.Body, left: r.ContentLength} |
| + return out |
| +} |
| + |
| +// declaredBody is a request body that ends after its declared length. |
| +// |
| +// Reads are serialised, as net/http's own body serialises them: the |
| +// transport and an early answer's cleanup (finishEarlyAnswer) may read at |
| +// the same time, and left must count both. Close does not take mu, so it |
| +// reaches the body under a pending read exactly as it did before. |
| +type declaredBody struct { |
| + io.ReadCloser |
| + mu sync.Mutex |
| + left int64 |
| +} |
| + |
| +func (b *declaredBody) Read(p []byte) (int, error) { |
| + b.mu.Lock() |
| + defer b.mu.Unlock() |
| + if b.left <= 0 { |
| + return 0, io.EOF |
| + } |
| + if int64(len(p)) > b.left { |
| + p = p[:b.left] |
| + } |
| + n, err := b.ReadCloser.Read(p) |
| + b.left -= int64(n) |
| + if b.left <= 0 && err == nil { |
| + err = io.EOF |
| + } |
| + return n, err |
| +} |
| + |
| func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| // A linked request (ServeLinked) is pinned to one published app: every |
| // handler below that is the edge's own, rather than a stage on the way |
| @@ -2274,7 +2336,9 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| // flight here is one the drain waits for, and ends at its bound. |
| // After the drain's final barrier a new request is refused at once |
| // through the bounded exit, with today's answer: never forwarded. |
| - r, untrack, admitted := e.conns.track(w, r) |
| + // The tracked request's body ends at its declared length |
| + // (withDeclaredBodyEnd, #1032): everything below may proxy it. |
| + r, untrack, admitted := e.conns.track(w, withDeclaredBodyEnd(r)) |
| if !admitted { |
| handoverExit(w, r, answerHolderUnreachable) |
| return |
diff --git a/internal/edge/proxybody_test.go b/internal/edge/proxybody_test.go| new file mode 100644 |
| index 000000000..c494af943 |
| --- /dev/null |
| +++ b/internal/edge/proxybody_test.go |
| @@ -0,0 +1,361 @@ |
| +package edge |
| + |
| +import ( |
| + "bufio" |
| + "bytes" |
| + "crypto/tls" |
| + "io" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/http/httptrace" |
| + "strings" |
| + "sync" |
| + "sync/atomic" |
| + "testing" |
| + |
| + "golang.org/x/net/http2" |
| + "golang.org/x/net/http2/hpack" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// trailingReadGate is a request body that holds any read after its |
| +// Content-Length bytes have been delivered until open is closed. net/http's |
| +// Transport makes exactly one such read: once it has written the declared |
| +// bytes, it reads the body again to confirm EOF before it calls the write |
| +// finished. Holding that read is the interleaving CI's load produced on |
| +// #1032, made certain: the upstream answers, the edge writes the answer's |
| +// head to the client, and only then does the transport look for EOF. |
| +type trailingReadGate struct { |
| + io.ReadCloser |
| + left int64 |
| + open <-chan struct{} |
| +} |
| + |
| +func (g *trailingReadGate) Read(p []byte) (int, error) { |
| + if g.left <= 0 { |
| + <-g.open |
| + } |
| + n, err := g.ReadCloser.Read(p) |
| + g.left -= int64(n) |
| + return n, err |
| +} |
| + |
| +// #1032: a POST through the edge whose upstream starts streaming its answer |
| +// as soon as it has read the body. net/http's server closes an HTTP/1.1 |
| +// request body when the response head is written, and the edge's proxy |
| +// transport may still be about to read that body once more to confirm EOF. |
| +// That read failed ("invalid Read on closed Body"), the transport counted |
| +// the request as not written and closed the upstream connection, and the |
| +// client's stream ended after its first line. The edge's request body now |
| +// answers EOF itself at its declared length (withDeclaredBodyEnd), so the |
| +// confirming read never reaches the closed body and the stream arrives whole. |
| +func TestEdgeStreamSurvivesTheTransportsEOFCheck(t *testing.T) { |
| + finish := make(chan struct{}) |
| + upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if _, err := io.ReadAll(r.Body); err != nil { |
| + t.Errorf("upstream read the body: %v", err) |
| + return |
| + } |
| + w.Header().Set("Content-Type", "application/x-ndjson") |
| + io.WriteString(w, "first\n") |
| + http.NewResponseController(w).Flush() |
| + select { |
| + case <-finish: |
| + case <-r.Context().Done(): |
| + return |
| + } |
| + io.WriteString(w, "last\n") |
| + })) |
| + t.Cleanup(upstream.Close) |
| + reg := openReg(t) |
| + if err := reg.Upsert(registry.Route{Host: "app.example.com", Kind: "service", Addr: upstream.Listener.Addr().String(), Status: "ready", App: "web"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + open := make(chan struct{}) |
| + wrote := make(chan error, 1) |
| + front := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + r = r.WithContext(httptrace.WithClientTrace(r.Context(), &httptrace.ClientTrace{ |
| + WroteRequest: func(info httptrace.WroteRequestInfo) { |
| + select { |
| + case wrote <- info.Err: |
| + default: |
| + } |
| + }, |
| + })) |
| + // On a copy: the server still sees its own body, as in production. |
| + r.Body = &trailingReadGate{ReadCloser: r.Body, left: r.ContentLength, open: open} |
| + e.ServeHTTP(w, r) |
| + })) |
| + t.Cleanup(front.Close) |
| + release, end := sync.OnceFunc(func() { close(open) }), sync.OnceFunc(func() { close(finish) }) |
| + t.Cleanup(func() { release(); end() }) |
| + |
| + req, err := http.NewRequest(http.MethodPost, front.URL+"/reads", bytes.NewReader([]byte(`{"sql":"SELECT 1"}`))) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Host = "app.example.com" |
| + req.Header.Set("Content-Type", "application/json") |
| + client := &http.Client{Transport: &http.Transport{}} |
| + res, err := client.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer res.Body.Close() |
| + br := bufio.NewReader(res.Body) |
| + if line, err := br.ReadString('\n'); err != nil || line != "first\n" { |
| + t.Fatalf("first line %q: %v", line, err) |
| + } |
| + // The client has the answer's head: the edge's server has made its |
| + // choice about the request body. Now let the transport look for EOF. |
| + release() |
| + if err := <-wrote; err != nil { |
| + t.Fatalf("the edge's transport did not finish writing the request: %v", err) |
| + } |
| + end() |
| + rest, err := io.ReadAll(br) |
| + if err != nil || string(rest) != "last\n" { |
| + t.Fatalf("the stream after its first line: %q, %v", rest, err) |
| + } |
| +} |
| + |
| +// overlapReader serves data, holding its first read until release. It |
| +// notes a read that starts while another is in progress. |
| +type overlapReader struct { |
| + mu sync.Mutex |
| + data []byte |
| + active atomic.Int32 |
| + overlap atomic.Bool |
| + calls atomic.Int32 |
| + entered chan struct{} |
| + release chan struct{} |
| +} |
| + |
| +func (o *overlapReader) Read(p []byte) (int, error) { |
| + if o.active.Add(1) > 1 { |
| + o.overlap.Store(true) |
| + } |
| + defer o.active.Add(-1) |
| + if o.calls.Add(1) == 1 { |
| + close(o.entered) |
| + <-o.release |
| + } |
| + o.mu.Lock() |
| + defer o.mu.Unlock() |
| + if len(o.data) == 0 { |
| + return 0, io.EOF |
| + } |
| + n := copy(p, o.data) |
| + o.data = o.data[n:] |
| + return n, nil |
| +} |
| + |
| +func (o *overlapReader) Close() error { return nil } |
| + |
| +// An early answer's cleanup (finishEarlyAnswer) reads the request body while |
| +// the transport's read of it is still pending. net/http's body serialises |
| +// the two; declaredBody must too, and count what both read (Astra #1032 r1, |
| +// P1). Run with -race: an unserialised wrapper races on left. |
| +func TestDeclaredBodySerialisesOverlappingReads(t *testing.T) { |
| + inner := &overlapReader{data: []byte("abcdef"), entered: make(chan struct{}), release: make(chan struct{})} |
| + b := &declaredBody{ReadCloser: inner, left: 6} |
| + type result struct { |
| + n int |
| + err error |
| + } |
| + first, second := make(chan result, 1), make(chan result, 1) |
| + go func() { |
| + n, err := b.Read(make([]byte, 4)) |
| + first <- result{n, err} |
| + }() |
| + <-inner.entered |
| + go func() { |
| + n, err := b.Read(make([]byte, 16)) |
| + second <- result{n, err} |
| + }() |
| + close(inner.release) |
| + a, c := <-first, <-second |
| + if inner.overlap.Load() { |
| + t.Fatal("two reads reached the request body at once") |
| + } |
| + if a.n+c.n != 6 || a.err != nil || c.err != io.EOF { |
| + t.Fatalf("first %d %v, second %d %v: want 6 bytes in all, the second ending at EOF", a.n, a.err, c.n, c.err) |
| + } |
| + if n, err := b.Read(make([]byte, 1)); n != 0 || err != io.EOF || b.left != 0 { |
| + t.Fatalf("after the declared bytes: %d %v, left %d", n, err, b.left) |
| + } |
| +} |
| + |
| +// h2Edge is an edge behind an HTTP/2 front for app.example.com, whose |
| +// upstream reads the body, answers "ok" and flushes it, then, when hold is |
| +// not nil, ends its answer with "done" once hold is closed. wrote says, for |
| +// each proxied request, how the edge's transport ended its write of the |
| +// request body and which X-Check trailer the edge's server had by then. |
| +func h2Edge(t *testing.T, hold <-chan struct{}) (front *httptest.Server, wrote <-chan h2Wrote) { |
| + t.Helper() |
| + upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + io.ReadAll(r.Body) |
| + io.WriteString(w, "ok\n") |
| + if hold == nil { |
| + return |
| + } |
| + http.NewResponseController(w).Flush() |
| + select { |
| + case <-hold: |
| + io.WriteString(w, "done\n") |
| + case <-r.Context().Done(): |
| + } |
| + })) |
| + t.Cleanup(upstream.Close) |
| + reg := openReg(t) |
| + if err := reg.Upsert(registry.Route{Host: "app.example.com", Kind: "service", Addr: upstream.Listener.Addr().String(), Status: "ready", App: "web"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ch := make(chan h2Wrote, 1) |
| + front = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + in := r |
| + r = r.WithContext(httptrace.WithClientTrace(r.Context(), &httptrace.ClientTrace{ |
| + WroteRequest: func(info httptrace.WroteRequestInfo) { |
| + ch <- h2Wrote{err: info.Err, trailer: in.Trailer.Get("X-Check")} |
| + }, |
| + })) |
| + e.ServeHTTP(w, r) |
| + })) |
| + front.EnableHTTP2 = true |
| + front.StartTLS() |
| + t.Cleanup(front.Close) |
| + return front, ch |
| +} |
| + |
| +type h2Wrote struct { |
| + err error |
| + trailer string |
| +} |
| + |
| +// On HTTP/2 the declared bytes arriving do not end the request body: the |
| +// stream's end, its trailers or its error come on a later read. The edge |
| +// leaves an HTTP/2 body as it is, so each still reaches whoever reads the |
| +// body, here the proxy's transport (Astra #1032 r1, P2). |
| +// h2Post opens an HTTP/2 connection to front and sends the headers of a |
| +// POST to app.example.com declaring a 5-byte body. The caller writes the |
| +// DATA frames itself, so it decides when, and whether, the stream ends. |
| +func h2Post(t *testing.T, front *httptest.Server) *http2.Framer { |
| + t.Helper() |
| + cfg := front.Client().Transport.(*http.Transport).TLSClientConfig.Clone() |
| + cfg.NextProtos = []string{"h2"} |
| + conn, err := tls.Dial("tcp", front.Listener.Addr().String(), cfg) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { conn.Close() }) |
| + if _, err := io.WriteString(conn, http2.ClientPreface); err != nil { |
| + t.Fatal(err) |
| + } |
| + fr := http2.NewFramer(conn, conn) |
| + if err := fr.WriteSettings(); err != nil { |
| + t.Fatal(err) |
| + } |
| + var block bytes.Buffer |
| + enc := hpack.NewEncoder(&block) |
| + for _, f := range [][2]string{{":method", "POST"}, {":scheme", "https"}, {":authority", "app.example.com"}, {":path", "/reads"}, {"content-length", "5"}} { |
| + enc.WriteField(hpack.HeaderField{Name: f[0], Value: f[1]}) |
| + } |
| + if err := fr.WriteHeaders(http2.HeadersFrameParam{StreamID: 1, BlockFragment: block.Bytes(), EndHeaders: true}); err != nil { |
| + t.Fatal(err) |
| + } |
| + return fr |
| +} |
| + |
| +// h2ReadUntil reads frames until stream 1's DATA so far contains want. |
| +func h2ReadUntil(t *testing.T, fr *http2.Framer, want string) { |
| + t.Helper() |
| + var got []byte |
| + for !bytes.Contains(got, []byte(want)) { |
| + f, err := fr.ReadFrame() |
| + if err != nil { |
| + t.Fatalf("waiting for %q (have %q): %v", want, got, err) |
| + } |
| + if d, ok := f.(*http2.DataFrame); ok && d.StreamID == 1 { |
| + got = append(got, d.Data()...) |
| + } |
| + } |
| +} |
| + |
| +func TestEdgeLeavesAnHTTP2BodyToItsStream(t *testing.T) { |
| + t.Run("trailers", func(t *testing.T) { |
| + front, wrote := h2Edge(t, nil) |
| + req, err := http.NewRequest(http.MethodPost, front.URL+"/reads", strings.NewReader("hello")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Host = "app.example.com" |
| + req.ContentLength = 5 |
| + req.Trailer = http.Header{"X-Check": {"yes"}} |
| + res, err := front.Client().Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer res.Body.Close() |
| + if b, err := io.ReadAll(res.Body); err != nil || res.ProtoMajor != 2 || string(b) != "ok\n" { |
| + t.Fatalf("HTTP/%d answer %q: %v", res.ProtoMajor, b, err) |
| + } |
| + if got := <-wrote; got.err != nil || got.trailer != "yes" { |
| + t.Fatalf("write ended %v with trailer %q, want nil and yes", got.err, got.trailer) |
| + } |
| + }) |
| + |
| + t.Run("a stream that ends after its answer starts", func(t *testing.T) { |
| + hold := make(chan struct{}) |
| + release := sync.OnceFunc(func() { close(hold) }) |
| + t.Cleanup(release) |
| + front, wrote := h2Edge(t, hold) |
| + fr := h2Post(t, front) |
| + if err := fr.WriteData(1, false, []byte("hello")); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The upstream has the declared bytes and has started its answer; |
| + // the stream is still open, so the body has not ended. |
| + h2ReadUntil(t, fr, "ok\n") |
| + select { |
| + case got := <-wrote: |
| + t.Fatalf("the transport finished the body (%v) before its stream ended", got.err) |
| + default: |
| + } |
| + if err := fr.WriteData(1, true, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := <-wrote; got.err != nil { |
| + t.Fatalf("write ended %v after the stream ended", got.err) |
| + } |
| + release() |
| + h2ReadUntil(t, fr, "done\n") |
| + }) |
| + |
| + t.Run("more DATA than declared", func(t *testing.T) { |
| + hold := make(chan struct{}) |
| + t.Cleanup(sync.OnceFunc(func() { close(hold) })) |
| + front, wrote := h2Edge(t, hold) |
| + fr := h2Post(t, front) |
| + if err := fr.WriteData(1, false, []byte("hello")); err != nil { |
| + t.Fatal(err) |
| + } |
| + h2ReadUntil(t, fr, "ok\n") |
| + // The transport has sent the declared bytes and is waiting for the |
| + // stream's end; what comes is one byte too many. |
| + if err := fr.WriteData(1, true, []byte("!")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := <-wrote; got.err == nil { |
| + t.Fatal("the transport took a body with more DATA than declared as whole") |
| + } |
| + }) |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index c664be3b0..8229c3b70 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -247,3 +247,4 @@ plan14-root-reads-bounded-systemctl.tsv 16cae3931aadfa57a5293d69becf318645681400 |
| plan14-root-reads-mail-submission-followups.tsv c9cd3c8fdf31240b83affa0b2798422f3a99e1d0d400dbaf68665c1127996448 |
| plan14-root-reads-staticcheck-sa4006.tsv 33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc820c5fe7b44c870e671565e1063 |
| plan14-root-reads-aws-followups-1143.tsv 33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc820c5fe7b44c870e671565e1063 |
| +plan14-root-reads-fix-dbforward-reuse-1032.tsv ec3c40098ec0a652c735d54925f334b9b9680c9e2b6cd0c3d9497b8a615fb86f |
diff --git a/internal/provision/testdata/plan14-root-reads-fix-dbforward-reuse-1032.tsv b/internal/provision/testdata/plan14-root-reads-fix-dbforward-reuse-1032.tsv| new file mode 100644 |
| index 000000000..199ffcec8 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-fix-dbforward-reuse-1032.tsv |
| @@ -0,0 +1,8 @@ |
| +# Census overlay fix-dbforward-reuse-1032, written by census-propose (#369). census-ruling-fix-dbforward-reuse-1032, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-fix-dbforward-reuse-1032.md. |
| +# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 1 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +@legacy a9300a80296cf9b3f49441074cb1b70e1877cf1c1ffa40f87124739bccec79a2 internal/edge/edge.go Edge.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the response cache, and on an upgrade trackUpgrade then planUpgradeAdmit (plans 4c, Astra findings 1 and 2); the new reads live in those units (plans-4c-units decision). The same read sites here.;rev3=census-ruling-plans-4d-lapse;basis=calls planDisabledAdmit right after the import gate, passing the final upstream's route and the request host; a turned-off route gets the fixed disabled page before the meter, gate, cache and activator (plans 4d). The new read lives in that unit (plans-4d-units decision); one more whole-row pass here.;rev3=census-ruling-edge-protection-2;basis=runs the guard, a pure in-memory matcher on r.URL.Path and RawQuery (internal/edgeguard), once per request after the meter and observer defer and before the password gate, the upgrade branch, the cache and the activator, for a request that is not a door call, a backhauled door hop or a tunnel delivery; a matched block answers a 404 itself through guardDecide; the two new sites are one expression, up.route.Kind == "static" (a static route this box serves checks only the hard tier here and leaves the probe tier to serveTree), a read of the route row the edge already resolved; no new kind of read;rev3=census-ruling-edge-asset-cache-3;basis=the asset cache's three hooks (asset cache plan 3): the request's reserved asset headers are deleted at entry (the fill assertion kept only beside a verified hop); on the exact-remote and lookup-miss branches the far catch (serveAssetFar) is tried before backhaulTo and backhaul; after the observer defer and main's hard and probe checks, a verified hop with a valid fill assertion is answered by serveAssetFillForHop; after the upgrade branch and before gzip and the shared cache, the local catch (serveAssetLocal); the observer defer skips only the usage meter for an acknowledged home fill (out.unbilled); the new reads live in the new units of the edge-asset-cache-3-decisions overlay; the same route row and read sites (25); no read added;rev3=census-ruling-regional-domains-447;basis=#447 Task 5: straight after lookupUpstreamPath it calls regionalGate (regional.go), which for an entry built from a regional_domains row answers 503 to a hop or a deny entry before any arm that can leave the box (the exact-home backhaul, the far asset catch, the door dial, the miss backhaul), and lets a star match through only to the exact-home arm when ExactHome names another box for that distinct exact name; after the exact-home arm a regional deny entry the arm did not answer is refused (regionalRefuse, 503); refusals only, on the route map the edge already holds; read sites unchanged (25);rev3=census-ruling-static-headers;basis=the shared response cache is no longer looked up or filled for a static-kind route: one more read of the route row the edge already resolved (up.route.Kind == "static") in the cacheable expression; a refusal only, nothing new opened or followed;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2 (N-HA10): one call, frontForwardHA, right after the route lookup's !ok block and before the login POST; same reads;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 4: loginPost and cacheable treat a forward row as not this box's to answer (IsForward(), +whole:Route x2): no login form and no shared cache for a forward host. Serving only.;rev3=census-ruling-tunnel-websockets;basis=Deletes the Carlos-Upgrade marker header from incoming requests and puts the upgrade admission (host, path, the entry tenancy, all in hand) on a tunnel arm request. For a login POST on an ungated ArmTunnel row it reads the visitor request body (bounded by gate.MaxFormBody, 413 past it; a request body, not a file) and resolves next against the entry Reload built (Gate, Route); the bytes pass on only when loginPassesThrough holds (spec 7, Tasks 3, 5 and 6).;rev3=census-ruling-console-protection-tab;basis=one more call in the observer defer, observeGuardCount(up.route, out), beside the observeRecords call that files the guard Match: it passes on the route row the defer already holds (+whole:Route) and the request outcome to the usage meter, which counts the check in memory. Called whether or not the request was unbilled, as observeRecords is. Nothing is opened, read or followed; no new kind of read; no check, refusal or serving decision changes.;rev3=census-ruling-probe-burst-limit;basis=answers a probe-burst notice POST (serveBurstNotice) ahead of every route for a non-door caller; builds the guard state for up.route and stamps its account and app (RouteAccount, App) for the cool-down's this-app/other-app label; for a catalogue match on a non-static or tunnelled route, offers the burst rule (in-memory limiter, burstDecide: 429 or a watch verdict, never a block for a fleet or forward row); the observer defer calls noteBurst(up.route, ...); the added sites are the route value already in hand (+registry:App, +whole:Route x5); no new root read or write kind;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): parses the request's query once (stripHoldMarker) to record the carlos_hold=1 mark in the request context; calls classifyHold on the upstream already resolved from the loaded map (the +whole:Route is that in-memory Route), including a second pass for a login POST; gives a marked request on a door-refused route the plain 404; adds the hold branch (planThrottleAdmit, rateAdmit, serveHeld) after the gate; and excludes marked requests from the shared cache. Reads only the request and the already-loaded upstream map; no registry or bucket read added.;rev3=census-ruling-region-ha-p3a;basis=Complete the P3a cut: an exact peer name with no dial target answers the approved admission 503 before local wildcard dispatch or asset serving. ExactHome and lookupHome stop fallback at a present non-dial entry; backhaulTo refuses an empty target before signing or dialing. Retain Task 3 local admission and fixed platform/unit exemptions. Two added whole Route uses feed the local in-memory admission predicate; existing Route values and store/path reads are unchanged.;rev3=census-ruling-stateless-coordinator-route;basis=P24/P25: POST only, exact /api/fleet/replicas/ prefix on the reserved tunnel host calls the existing local console proxy only for an unescaped, already-clean path; malformed forms remain on the hub. No new read sites relative to origin/main. Merge with main 3487d6f6 retains its region HA admission checks before routing and after login target lookup, its empty-home refusal, and their two existing whole:Route reads; these change this unit's digest relative to the previously approved branch tip 92b24a7d.;rev3=census-ruling-stateless-replicas-3;basis=Task 1a: pass the already-resolved Route to the reserved replica-probe handler after acceptHop and existing admissionRefuses, requiring tunnel context plus private marker and refusing door/backhaul ingress. Added whole Route use only; scrub marker before forwarding; HA calls remain unchanged.;rev3=census-ruling-region-ha-p3b;basis=Resolve local aliases/catch-alls with cached peer name ownership before serving. Add registry Account/App/ClaimStamp/Host/Incarnation/ServingSeq and six whole Route references for NameClaim; inputs are agent registry rows/edges publications used by unprivileged edge, not root permits. Closed owners retain names and return 503; aware remote owner cannot fall through on missing transport, while legacy hop/door behavior remains. Merge 45cebde4 retains authenticated replica probes after local admission and before ordinary name resolution; probe authentication still requires the tunnel context.;rev3=census-ruling-agent-start-demo-2;basis=edge.go:1901 enters the protected demo path before ordinary exits; :2012-2015 rechecks the selected marked Route after lookup. Added whole Route use routes demos through serving checks, counters and policy; no new registry query or file open in this unit.;rev3=census-ruling-demo-api-site-route;basis=Reserve the configured site API namespace after hop verification and control-header scrubbing, before ordinary static, cache, billing and tenant dispatch. Validate hop field shape and delegate only allowlisted operations to the dedicated console path with verified client attribution and console admission. The alias helper enables HTTP/1.1 full duplex so an early console refusal does not wait for upload EOF. Existing 56 read sites unchanged; no new registry, bucket or file read.;rev3=census-ruling-region-ha-g2-fixes;basis=Consult HA ingress after region admission and before miss/alias backhaul; no new direct read; routing-only metadata does not create an upstream.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3/W4: backhaul and door calls pass the owner the door checked into backhaulTo; the §6.5 holder follow (once, GET/HEAD or an unswitched upgrade, no body) and one connect-failure fallback dial only boxes in the holder region's view (same Region/Placement/DataBucket, HomeEligible, fresh) for that owner. Holder name comes only from the TLS-verified signed hop answer; app-set X-Carlos-Holder stays stripped. Routing only; the receiving box still re-checks the lease. No new read site.;rev3=census-ruling-edge-page-cache-1;basis=attaches an in-memory page mark holder to every request to an instance route (the +registry:Kind check of up.route.Kind), wraps the hold and upgrade branches in pageDiagnostics, asks servePage after the plan throttle (a hit answered from the page index over the asset store), keeps an opted-in instance out of the LRU (pagesOptedIn), wraps the response in the page writer, and wraps the proxy's writer in assetInformationalScrub on the remaining arms; the page reads are in the new pagecache.go units;rev3=census-ruling-region-ha-held-build;basis=first branch: a request for the reserved control paths /.carlos/ha-drain and /.carlos/ha-take goes to serveHAControl and returns (refused unless a signed ask); no request on those paths reaches a route, a forward or an app; no read added here. region HA held-requests Task 2: X-Carlos-Replayable is read from verified hops only and deleted from every request; just before frontForwardHA, moveGate runs for an HA hibernating route (route HA, Host and the whole Route passed in memory) and can only hold, refuse with an existing answer or front-forward to the confirmed holder; ReleaseMoveTicket before serveHeld; no store or filesystem read added; region HA held-requests Task 5: after the HA control-path branch, every request is counted by the connection drain (conns.track: a cancellable request context, and Connection: close only while draining); memory only; no read added; Task 5 fix 1: after the drain's final barrier a new request is refused at once through handoverExit with the existing answerHolderUnreachable, never forwarded; the tracked request also carries its connection (from ConnContext) so the drain can close it at its bound; memory only; no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 3: the inbound strip also deletes tunnelclient.LinkAppHeader (Carlos-Link-App) from every client request, beside Carlos-Tunnel-Upgrade; a header delete, no read added; linked deployments slice 1 Task 8: a request carrying a link pin (ServeLinked, set only by the home agent's link handler from its own registry's published set) skips the edge's own handlers (HA control, demo handling, the steering probe, the tunnel hub, hop acceptance, the burst notice, the demo API alias, the replica probe), takes its upstream from selectUpstream (the pinned exact entry or a 502), never enters the alias/catch-all backhaul block, the HA front forward, the local asset catch, the page cache or the response LRU; the two lookupUpstreamPath calls become selectUpstream; no read added;rev3=census-ruling-stateless-replicas-4-r28;basis=R28 (#511): for a request whose host has no entry (the lookup miss), after the replica-probe branch, calls refuseRetiredCopy(r, host): within the grace of a host whose replica copy this box retired, the fleet tunnel stream is refused with REFUSED_STREAM (tunnelclient.Refuse) and nothing is written; any other miss gets the unknown-host answer as before; memory only, a refusal only, no read added;rev3=census-ruling-static-site-geo-962;basis=discussion #962: after planDisabledAdmit and before the page mark holder and the observer, a request whose cleaned path is /.carlos/geo (not a linked request) is answered by serveGeoAnswer from the request's geo answer already on the context (decideGeo), 200 JSON no-store or 405, and returns; merged with main (no new read);rev3=census-ruling-fleet-unrouted-503;basis=a request the hub tunnel delivered (tunnelclient mark, not a link channel) for a host this box neither routes nor backhauls answers 503 Retry-After 2 instead of the unknown-host 404; no new read, dial or store access; unmarked requests unchanged (#1008);rev3=census-ruling-fleet-unrouted-503-fix1;basis=a request the hub delivered over this fleet box's channel (MarkFleetChannel, set by the box's own tunnel loop for a "<fleet>/<label>" channel, plus the tunnel client mark) for a host this box neither routes nor backhauls, and not under a platform domain, answers 503 Retry-After 2 instead of the unknown-host 404; fixed log key; no new read, dial or store access; every other request unchanged (#1008);rev3=census-ruling-fix-dbforward-reuse-1032;basis=the drain tracking call now takes withDeclaredBodyEnd(r) instead of r: an HTTP/1 request with a declared Content-Length is served from there on with a body that answers EOF itself after those bytes (#1032), so a proxy transport's confirming read after sending the body upstream no longer lands on the server's closed request body and tears down the upstream connection; HTTP/2 requests are left as they are (Astra r1 P2); memory only, no read, dial or store access added file:ReadAll@20389,registry:Account@11147,registry:App@11171,registry:App@28184,registry:ClaimStamp@11201,registry:Gate@19363,registry:Gate@32575,registry:Gate@32635,registry:Gate@32693,registry:HA@15098,registry:HA@15440,registry:Host@11378,registry:Host@15479,registry:Host@32678,registry:ImportGate@41529,registry:Incarnation@11236,registry:Kind@25218,registry:Kind@27046,registry:Kind@30484,registry:Kind@41471,registry:Kind@41500,registry:ServingSeq@11270,whole:Route@11150,whole:Route@11174,whole:Route@11204,whole:Route@11239,whole:Route@11273,whole:Route@11381,whole:Route@15101,whole:Route@15195,whole:Route@15443,whole:Route@15482,whole:Route@19258,whole:Route@19369,whole:Route@22186,whole:Route@22970,whole:Route@23428,whole:Route@23620,whole:Route@25221,whole:Route@27049,whole:Route@28110,whole:Route@28176,whole:Route@28187,whole:Route@28440,whole:Route@28535,whole:Route@28611,whole:Route@28655,whole:Route@28957,whole:Route@28987,whole:Route@30487,whole:Route@30772,whole:Route@32578,whole:Route@32638,whole:Route@32681,whole:Route@32696,whole:Route@33907,whole:Route@36195,whole:Route@41474,whole:Route@41503,whole:Route@41532,whole:Route@41564,whole:Route@44009,whole:Route@8563,whole:Route@8662,whole:Route@8768 68f139634762585f25438c5fea17378901841e1ef50dd30cdb8ebb01d1d47b4b |
| +@legacy a6c215eb108146fdb11875273af962d5a6010f0c05792da5f714ef91baeab884 internal/edge/edge.go declaredBody.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-fix-dbforward-reuse-1032;basis=new: reads at most the declared remaining bytes from the wrapped request body (the visitor's request body, not a file) and answers io.EOF once they are read; the whole Read (length checks, inner read, decrement) holds the wrapper's mutex so the transport and finishEarlyAnswer's overlapping reads are serialised as net/http's body serialises them, and Close does not take it (Astra r1 P1); the two +file:Read sites are the wrapped body's Read; no file, registry or bucket read file:Read@187,file:Read@23 5fdb194f00006c4179a6f88a9dec733f307c9b1ef820810b7356294e6c719f16 |
| +internal/edge/edge.go Edge.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the response cache, and on an upgrade trackUpgrade then planUpgradeAdmit (plans 4c, Astra findings 1 and 2); the new reads live in those units (plans-4c-units decision). The same read sites here.;rev3=census-ruling-plans-4d-lapse;basis=calls planDisabledAdmit right after the import gate, passing the final upstream's route and the request host; a turned-off route gets the fixed disabled page before the meter, gate, cache and activator (plans 4d). The new read lives in that unit (plans-4d-units decision); one more whole-row pass here.;rev3=census-ruling-edge-protection-2;basis=runs the guard, a pure in-memory matcher on r.URL.Path and RawQuery (internal/edgeguard), once per request after the meter and observer defer and before the password gate, the upgrade branch, the cache and the activator, for a request that is not a door call, a backhauled door hop or a tunnel delivery; a matched block answers a 404 itself through guardDecide; the two new sites are one expression, up.route.Kind == "static" (a static route this box serves checks only the hard tier here and leaves the probe tier to serveTree), a read of the route row the edge already resolved; no new kind of read;rev3=census-ruling-edge-asset-cache-3;basis=the asset cache's three hooks (asset cache plan 3): the request's reserved asset headers are deleted at entry (the fill assertion kept only beside a verified hop); on the exact-remote and lookup-miss branches the far catch (serveAssetFar) is tried before backhaulTo and backhaul; after the observer defer and main's hard and probe checks, a verified hop with a valid fill assertion is answered by serveAssetFillForHop; after the upgrade branch and before gzip and the shared cache, the local catch (serveAssetLocal); the observer defer skips only the usage meter for an acknowledged home fill (out.unbilled); the new reads live in the new units of the edge-asset-cache-3-decisions overlay; the same route row and read sites (25); no read added;rev3=census-ruling-regional-domains-447;basis=#447 Task 5: straight after lookupUpstreamPath it calls regionalGate (regional.go), which for an entry built from a regional_domains row answers 503 to a hop or a deny entry before any arm that can leave the box (the exact-home backhaul, the far asset catch, the door dial, the miss backhaul), and lets a star match through only to the exact-home arm when ExactHome names another box for that distinct exact name; after the exact-home arm a regional deny entry the arm did not answer is refused (regionalRefuse, 503); refusals only, on the route map the edge already holds; read sites unchanged (25);rev3=census-ruling-static-headers;basis=the shared response cache is no longer looked up or filled for a static-kind route: one more read of the route row the edge already resolved (up.route.Kind == "static") in the cacheable expression; a refusal only, nothing new opened or followed;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2 (N-HA10): one call, frontForwardHA, right after the route lookup's !ok block and before the login POST; same reads;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 4: loginPost and cacheable treat a forward row as not this box's to answer (IsForward(), +whole:Route x2): no login form and no shared cache for a forward host. Serving only.;rev3=census-ruling-tunnel-websockets;basis=Deletes the Carlos-Upgrade marker header from incoming requests and puts the upgrade admission (host, path, the entry tenancy, all in hand) on a tunnel arm request. For a login POST on an ungated ArmTunnel row it reads the visitor request body (bounded by gate.MaxFormBody, 413 past it; a request body, not a file) and resolves next against the entry Reload built (Gate, Route); the bytes pass on only when loginPassesThrough holds (spec 7, Tasks 3, 5 and 6).;rev3=census-ruling-console-protection-tab;basis=one more call in the observer defer, observeGuardCount(up.route, out), beside the observeRecords call that files the guard Match: it passes on the route row the defer already holds (+whole:Route) and the request outcome to the usage meter, which counts the check in memory. Called whether or not the request was unbilled, as observeRecords is. Nothing is opened, read or followed; no new kind of read; no check, refusal or serving decision changes.;rev3=census-ruling-probe-burst-limit;basis=answers a probe-burst notice POST (serveBurstNotice) ahead of every route for a non-door caller; builds the guard state for up.route and stamps its account and app (RouteAccount, App) for the cool-down's this-app/other-app label; for a catalogue match on a non-static or tunnelled route, offers the burst rule (in-memory limiter, burstDecide: 429 or a watch verdict, never a block for a fleet or forward row); the observer defer calls noteBurst(up.route, ...); the added sites are the route value already in hand (+registry:App, +whole:Route x5); no new root read or write kind;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): parses the request's query once (stripHoldMarker) to record the carlos_hold=1 mark in the request context; calls classifyHold on the upstream already resolved from the loaded map (the +whole:Route is that in-memory Route), including a second pass for a login POST; gives a marked request on a door-refused route the plain 404; adds the hold branch (planThrottleAdmit, rateAdmit, serveHeld) after the gate; and excludes marked requests from the shared cache. Reads only the request and the already-loaded upstream map; no registry or bucket read added.;rev3=census-ruling-region-ha-p3a;basis=Complete the P3a cut: an exact peer name with no dial target answers the approved admission 503 before local wildcard dispatch or asset serving. ExactHome and lookupHome stop fallback at a present non-dial entry; backhaulTo refuses an empty target before signing or dialing. Retain Task 3 local admission and fixed platform/unit exemptions. Two added whole Route uses feed the local in-memory admission predicate; existing Route values and store/path reads are unchanged.;rev3=census-ruling-stateless-coordinator-route;basis=P24/P25: POST only, exact /api/fleet/replicas/ prefix on the reserved tunnel host calls the existing local console proxy only for an unescaped, already-clean path; malformed forms remain on the hub. No new read sites relative to origin/main. Merge with main 3487d6f6 retains its region HA admission checks before routing and after login target lookup, its empty-home refusal, and their two existing whole:Route reads; these change this unit's digest relative to the previously approved branch tip 92b24a7d.;rev3=census-ruling-stateless-replicas-3;basis=Task 1a: pass the already-resolved Route to the reserved replica-probe handler after acceptHop and existing admissionRefuses, requiring tunnel context plus private marker and refusing door/backhaul ingress. Added whole Route use only; scrub marker before forwarding; HA calls remain unchanged.;rev3=census-ruling-region-ha-p3b;basis=Resolve local aliases/catch-alls with cached peer name ownership before serving. Add registry Account/App/ClaimStamp/Host/Incarnation/ServingSeq and six whole Route references for NameClaim; inputs are agent registry rows/edges publications used by unprivileged edge, not root permits. Closed owners retain names and return 503; aware remote owner cannot fall through on missing transport, while legacy hop/door behavior remains. Merge 45cebde4 retains authenticated replica probes after local admission and before ordinary name resolution; probe authentication still requires the tunnel context.;rev3=census-ruling-agent-start-demo-2;basis=edge.go:1901 enters the protected demo path before ordinary exits; :2012-2015 rechecks the selected marked Route after lookup. Added whole Route use routes demos through serving checks, counters and policy; no new registry query or file open in this unit.;rev3=census-ruling-demo-api-site-route;basis=Reserve the configured site API namespace after hop verification and control-header scrubbing, before ordinary static, cache, billing and tenant dispatch. Validate hop field shape and delegate only allowlisted operations to the dedicated console path with verified client attribution and console admission. The alias helper enables HTTP/1.1 full duplex so an early console refusal does not wait for upload EOF. Existing 56 read sites unchanged; no new registry, bucket or file read.;rev3=census-ruling-region-ha-g2-fixes;basis=Consult HA ingress after region admission and before miss/alias backhaul; no new direct read; routing-only metadata does not create an upstream.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3/W4: backhaul and door calls pass the owner the door checked into backhaulTo; the §6.5 holder follow (once, GET/HEAD or an unswitched upgrade, no body) and one connect-failure fallback dial only boxes in the holder region's view (same Region/Placement/DataBucket, HomeEligible, fresh) for that owner. Holder name comes only from the TLS-verified signed hop answer; app-set X-Carlos-Holder stays stripped. Routing only; the receiving box still re-checks the lease. No new read site.;rev3=census-ruling-edge-page-cache-1;basis=attaches an in-memory page mark holder to every request to an instance route (the +registry:Kind check of up.route.Kind), wraps the hold and upgrade branches in pageDiagnostics, asks servePage after the plan throttle (a hit answered from the page index over the asset store), keeps an opted-in instance out of the LRU (pagesOptedIn), wraps the response in the page writer, and wraps the proxy's writer in assetInformationalScrub on the remaining arms; the page reads are in the new pagecache.go units;rev3=census-ruling-region-ha-held-build;basis=first branch: a request for the reserved control paths /.carlos/ha-drain and /.carlos/ha-take goes to serveHAControl and returns (refused unless a signed ask); no request on those paths reaches a route, a forward or an app; no read added here. region HA held-requests Task 2: X-Carlos-Replayable is read from verified hops only and deleted from every request; just before frontForwardHA, moveGate runs for an HA hibernating route (route HA, Host and the whole Route passed in memory) and can only hold, refuse with an existing answer or front-forward to the confirmed holder; ReleaseMoveTicket before serveHeld; no store or filesystem read added; region HA held-requests Task 5: after the HA control-path branch, every request is counted by the connection drain (conns.track: a cancellable request context, and Connection: close only while draining); memory only; no read added; Task 5 fix 1: after the drain's final barrier a new request is refused at once through handoverExit with the existing answerHolderUnreachable, never forwarded; the tracked request also carries its connection (from ConnContext) so the drain can close it at its bound; memory only; no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 3: the inbound strip also deletes tunnelclient.LinkAppHeader (Carlos-Link-App) from every client request, beside Carlos-Tunnel-Upgrade; a header delete, no read added; linked deployments slice 1 Task 8: a request carrying a link pin (ServeLinked, set only by the home agent's link handler from its own registry's published set) skips the edge's own handlers (HA control, demo handling, the steering probe, the tunnel hub, hop acceptance, the burst notice, the demo API alias, the replica probe), takes its upstream from selectUpstream (the pinned exact entry or a 502), never enters the alias/catch-all backhaul block, the HA front forward, the local asset catch, the page cache or the response LRU; the two lookupUpstreamPath calls become selectUpstream; no read added;rev3=census-ruling-stateless-replicas-4-r28;basis=R28 (#511): for a request whose host has no entry (the lookup miss), after the replica-probe branch, calls refuseRetiredCopy(r, host): within the grace of a host whose replica copy this box retired, the fleet tunnel stream is refused with REFUSED_STREAM (tunnelclient.Refuse) and nothing is written; any other miss gets the unknown-host answer as before; memory only, a refusal only, no read added;rev3=census-ruling-static-site-geo-962;basis=discussion #962: after planDisabledAdmit and before the page mark holder and the observer, a request whose cleaned path is /.carlos/geo (not a linked request) is answered by serveGeoAnswer from the request's geo answer already on the context (decideGeo), 200 JSON no-store or 405, and returns; merged with main (no new read);rev3=census-ruling-fleet-unrouted-503;basis=a request the hub tunnel delivered (tunnelclient mark, not a link channel) for a host this box neither routes nor backhauls answers 503 Retry-After 2 instead of the unknown-host 404; no new read, dial or store access; unmarked requests unchanged (#1008);rev3=census-ruling-fleet-unrouted-503-fix1;basis=a request the hub delivered over this fleet box's channel (MarkFleetChannel, set by the box's own tunnel loop for a "<fleet>/<label>" channel, plus the tunnel client mark) for a host this box neither routes nor backhauls, and not under a platform domain, answers 503 Retry-After 2 instead of the unknown-host 404; fixed log key; no new read, dial or store access; every other request unchanged (#1008);rev3=census-ruling-fix-dbforward-reuse-1032;basis=the drain tracking call now takes withDeclaredBodyEnd(r) instead of r: an HTTP/1 request with a declared Content-Length is served from there on with a body that answers EOF itself after those bytes (#1032), so a proxy transport's confirming read after sending the body upstream no longer lands on the server's closed request body and tears down the upstream connection; HTTP/2 requests are left as they are (Astra r1 P2); memory only, no read, dial or store access added file:ReadAll@20389,registry:Account@11147,registry:App@11171,registry:App@28184,registry:ClaimStamp@11201,registry:Gate@19363,registry:Gate@32575,registry:Gate@32635,registry:Gate@32693,registry:HA@15098,registry:HA@15440,registry:Host@11378,registry:Host@15479,registry:Host@32678,registry:ImportGate@41529,registry:Incarnation@11236,registry:Kind@25218,registry:Kind@27046,registry:Kind@30484,registry:Kind@41471,registry:Kind@41500,registry:ServingSeq@11270,whole:Route@11150,whole:Route@11174,whole:Route@11204,whole:Route@11239,whole:Route@11273,whole:Route@11381,whole:Route@15101,whole:Route@15195,whole:Route@15443,whole:Route@15482,whole:Route@19258,whole:Route@19369,whole:Route@22186,whole:Route@22970,whole:Route@23428,whole:Route@23620,whole:Route@25221,whole:Route@27049,whole:Route@28110,whole:Route@28176,whole:Route@28187,whole:Route@28440,whole:Route@28535,whole:Route@28611,whole:Route@28655,whole:Route@28957,whole:Route@28987,whole:Route@30487,whole:Route@30772,whole:Route@32578,whole:Route@32638,whole:Route@32681,whole:Route@32696,whole:Route@33907,whole:Route@36195,whole:Route@41474,whole:Route@41503,whole:Route@41532,whole:Route@41564,whole:Route@44009,whole:Route@8563,whole:Route@8662,whole:Route@8768 68f139634762585f25438c5fea17378901841e1ef50dd30cdb8ebb01d1d47b4b |
| +internal/edge/edge.go declaredBody.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-fix-dbforward-reuse-1032;basis=new: reads at most the declared remaining bytes from the wrapped request body (the visitor's request body, not a file) and answers io.EOF once they are read; the whole Read (length checks, inner read, decrement) holds the wrapper's mutex so the transport and finishEarlyAnswer's overlapping reads are serialised as net/http's body serialises them, and Close does not take it (Astra r1 P1); the two +file:Read sites are the wrapped body's Read; no file, registry or bucket read file:Read@187,file:Read@23 5fdb194f00006c4179a6f88a9dec733f307c9b1ef820810b7356294e6c719f16 |
| +@coverage internal/edge 48835da88ac7cd2c06b5916d7df5e208de2412eb8270b175ee94311c127d45e9 |