carlos / platform Public

edge: page mark holder before every proxying branch; per-leg holders

ServeHTTP attached the holder at the LRU gate, after the hop asset fill,
the hold branch, the upgrade branch and the local asset catch had already
proxied. It is now attached once the final upstream is settled, before
all of them. Held legs get a holder each (their context derives from the
browser request's, so they would otherwise share one), and the demo
traffic path attaches one before its proxy.

A pageMarkSeen test seam on responseModifier lets
TestPageMarkHolderOnEveryProxiedPath observe the holder on each path. The
scrub guard now checks announced trailer names right after the hook,
before the body is read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1ce5ed54d3e7733a9eda6e865367dc27a2cf7cf0 parent b5ae1ad
6 files changed, +268 −13
  • internal/edge/cookiescope.go +3 −0
  • internal/edge/demo_traffic.go +5 −0
  • internal/edge/edge.go +17 −7
  • internal/edge/heldstream.go +7 −0
  • internal/edge/pagemark_test.go +221 −2
  • internal/edge/scrub_guard_test.go +15 −4

CI failed — run details

Intent

Human

<task-notification> <task-id>aa0066cb4064bd83e</task-id> <tool-use-id>toolu_01RZCLAdneDz74dBgbAxzovh</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/aa0066cb4064bd83e.output</output-file> <status>completed</status> <summary>Agent "Implement Task 5: scrub list and marker" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. Both scrub guards failed under mutation as they should. Commit: `b5ae1ad1 edge: one client scrub list; read and strip Carlos-Page-Cache everywhere` Tests: the 8 brief tests and 1 extra pass (90 PASS lines). The brief's `-run 'Asset.*Scrub|Vocabulary|Trailer|Backhaul'` and two wide neighbour batches pass too. The only failure, one purge-socket test, was a too-long socket path and passed when re-run with a shorter TMPDIR. Concerns: 1. A malformed marker counts as no marker, so it can still enter the LRU. This follows the brief literally and a test pins it; refusing it is a one-line change. 2. Parsing is case-insensitive for `on` and `ignore-cookies`; a space around `=` counts as malformed. Copy review settles the exact syntax. 3. The LRU refusal only works if each transport passes the request through to the response. All current ones do; a future transport that doesn't would silently lose the mark. 4. No test can see the holder on POST and other non-GET methods until Task 7 uses it. 5. Extra scrub found: `assetStoredHeader` had its own `"carlos-cache"` check; it now uses the shared list. The demo API alias filters every `carlos-*` header by prefix, which already removes the marker, so I left it out of the guard table. 6. Use `~/.cache/e.XXX` as TMPDIR for socket tests; `epc.XXXX` is too long for one of them. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-page-cache-1/.superpowers/sdd/2026-11-08-edge-page-cache-plan-1-home/task-5-report.md</result> <usage><subagent_tokens>208885</subagent_tokens><tool_uses>79</tool_uses><duration_ms>2051402</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>blwynmevh</task-id> <tool-use-id>toolu_018Us4cs52LWwZkkYGdqU4Cc</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/blwynmevh.output</output-file> <status>completed</status> <summary>Background command "Run Astra review of Task 5" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 32.6 g CO₂e (4,234,816 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on edge-page-cache-1, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/edge/cookiescope.go b/internal/edge/cookiescope.go
index bfb0d3db6..2f42a1298 100644
--- a/internal/edge/cookiescope.go
+++ b/internal/edge/cookiescope.go
@@ -91,6 +91,9 @@ func (e *Edge) responseModifier(rt registry.Route) func(*http.Response) error {
return err
}
takePageMark(resp)
+ if e.pageMarkSeen != nil {
+ e.pageMarkSeen(resp)
+ }
stripAssetResponseHeaders(resp.Header)
stripAssetTrailers(resp)
stripAppHolder(resp)
diff --git a/internal/edge/demo_traffic.go b/internal/edge/demo_traffic.go
index 78e065246..6b509c95d 100644
--- a/internal/edge/demo_traffic.go
+++ b/internal/edge/demo_traffic.go
@@ -322,6 +322,11 @@ func (e *Edge) serveDemoTraffic(dst http.ResponseWriter, r *http.Request, up ups
serveDemoPlain(policy, r, 503, "DEMO-UNAVAILABLE")
return
}
+ // The page mark holder every proxied instance request carries
+ // (pagemark.go), as ServeHTTP attaches it on the ordinary path.
+ if up.route.Kind == "instance" {
+ r = withPageMarkHolder(r)
+ }
if up.hibernating && e.act != nil {
// The activator's own answers are platform refusals. A successful wake
// invokes the app proxy with the normal counted writer instead.
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index c0d6883cd..3d731d1f0 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -437,6 +437,10 @@ type Edge struct {
hooks *reloadHooks
reloadSeq atomic.Uint64
watchTick <-chan time.Time
+ // pageMarkSeen is a test seam, nil in production: responseModifier
+ // hands it each response once takePageMark has read it, so a test can
+ // see which proxied requests carried a page mark holder.
+ pageMarkSeen func(*http.Response)
}
// reloadHooks are Reload's and Watch's test hooks (#471 spec §8.2 case
@@ -2369,6 +2373,19 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !e.planDisabledAdmit(w, r, host, up.route) {
return
}
+ // Every proxied request to an instance route carries a page mark holder
+ // (pagemark.go), whatever its method: here, once the final upstream is
+ // settled (the login re-resolution, the door's scope), and before every
+ // branch below that proxies (the hop's asset fill, the hold branch, the
+ // upgrade branch, the local asset catch, the activator and the plain
+ // proxy). The response hook records the app's Carlos-Page-Cache in it,
+ // and a marked response never enters the LRU (maybeStore). Every
+ // context below derives from this request's, so the holder rides each
+ // proxied request; a held stream's legs, which may overlap, get one
+ // each (legRequest).
+ if up.route.Kind == "instance" {
+ r = withPageMarkHolder(r)
+ }
// Observe every route this box serves except the platform's own status
// host (not billable, and not a member's app) — wrapping w here, once,
@@ -2660,13 +2677,6 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !e.planThrottleAdmit(w, r, up) {
return
}
- // Every proxied request to an instance route carries a page mark holder
- // (pagemark.go), whatever its method, before the activator or the proxy
- // runs: the response hook records the app's Carlos-Page-Cache in it, and
- // a marked response never enters the LRU (maybeStore).
- if up.route.Kind == "instance" {
- r = withPageMarkHolder(r)
- }
// A forward row is never cached here (fleet public routes spec §4.8): the
// hub cannot see the fleet edge's gate, so a gated page stored here would
// be served without the cookie, and an app's Carlos-Purge stops at its
diff --git a/internal/edge/heldstream.go b/internal/edge/heldstream.go
index bccc48e3f..f94d106b6 100644
--- a/internal/edge/heldstream.go
+++ b/internal/edge/heldstream.go
@@ -633,6 +633,13 @@ func (t *heldTask) legRequest(ctx context.Context) (*http.Request, *outcome) {
req.Body, req.GetBody, req.ContentLength = http.NoBody, nil, 0
req.URL.RawQuery, _ = stripHoldMarker(t.r.URL.RawQuery)
req.RequestURI = req.URL.RequestURI()
+ // Each leg gets its own page mark holder (pagemark.go). Its context
+ // derives from the browser request's, which carries one from ServeHTTP;
+ // sharing that one would let a retired leg, still finishing, write the
+ // holder its replacement is writing.
+ if t.rt.Kind == "instance" {
+ req = withPageMarkHolder(req)
+ }
removeHeldHopHeaders(req.Header)
req.Header.Del("X-Carlos-Sidecar")
req.Header.Set("Accept-Encoding", "identity")
diff --git a/internal/edge/pagemark_test.go b/internal/edge/pagemark_test.go
index 600f09480..ccbb91ce9 100644
--- a/internal/edge/pagemark_test.go
+++ b/internal/edge/pagemark_test.go
@@ -1,8 +1,10 @@
package edge
import (
+ "bufio"
"fmt"
"io"
+ "net"
"net/http"
"net/http/httptest"
"net/http/httptrace"
@@ -11,6 +13,7 @@ import (
"strings"
"sync"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/registry"
)
@@ -263,8 +266,12 @@ func pmFetch(t *testing.T, front *httptest.Server, method, host, path string) (*
}
// A mock older home returns the marker on an ordinary backhaul, in a 103,
-// the final headers and a trailer. The visitor sees it nowhere, whether this
-// box's caches are armed (the far asset catch's paths) or not.
+// the final headers and a trailer. The visitor sees it nowhere, armed or
+// not. Page caching has no arming of its own yet (that is Task 10), so
+// "armed" here means this box's asset cache is armed and the far asset
+// catch's paths (its uncached forward, its non-canonical fallback, its
+// unacknowledged fill) carry the request; "unarmed" stores no asset state,
+// so every request is a plain backhaul.
func TestPageMarkStrippedThroughBackhaul(t *testing.T) {
for _, tc := range []struct {
name, path string
@@ -479,3 +486,215 @@ func TestUnmarkedResponseStillUsesLRU(t *testing.T) {
}
}
}
+
+// markLog records, for each response responseModifier hands the
+// pageMarkSeen seam, whether its request carried a holder and what the
+// holder then said.
+type markLog struct {
+ mu sync.Mutex
+ seen []markSeen
+}
+
+type markSeen struct {
+ path string
+ status int
+ holder bool
+ marked bool
+ mark *pageMark
+}
+
+func (l *markLog) hook(resp *http.Response) {
+ s := markSeen{status: resp.StatusCode}
+ if resp.Request != nil {
+ s.path = resp.Request.URL.Path
+ if m := pageMarkOf(resp.Request); m != nil {
+ s.holder, s.marked, s.mark = true, m.Marked, m
+ }
+ }
+ l.mu.Lock()
+ l.seen = append(l.seen, s)
+ l.mu.Unlock()
+}
+
+// want waits briefly for a response to path, then requires that every one
+// seen carried a holder and that the holder's Marked is marked.
+func (l *markLog) want(t *testing.T, path string, marked bool) {
+ t.Helper()
+ deadline := time.Now().Add(2 * time.Second)
+ for {
+ l.mu.Lock()
+ var got []markSeen
+ for _, s := range l.seen {
+ if s.path == path {
+ got = append(got, s)
+ }
+ }
+ l.mu.Unlock()
+ if len(got) > 0 {
+ for _, s := range got {
+ if !s.holder {
+ t.Fatalf("a proxied request to %s (status %d) carried no page mark holder (seen %+v)", path, s.status, got)
+ }
+ if s.marked != marked {
+ t.Fatalf("the holder for %s (status %d) says Marked=%v, want %v", path, s.status, s.marked, marked)
+ }
+ }
+ return
+ }
+ if time.Now().After(deadline) {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ t.Fatalf("no response to %s reached the response hook (seen %+v)", path, l.seen)
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+}
+
+// Every proxied request to an instance route carries a page mark holder,
+// whatever the method and whichever branch of ServeHTTP proxies it: the
+// ordinary, plain and activator paths, the upgrade branch, a held stream's
+// legs, the local asset catch's fill and fallback, and the home side of a
+// far edge's asset fill (R2-6).
+func TestPageMarkHolderOnEveryProxiedPath(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ hibernate bool
+ method string
+ }{
+ {"GET", false, http.MethodGet},
+ {"POST", false, http.MethodPost},
+ {"DELETE", false, http.MethodDelete},
+ {"activator GET", true, http.MethodGet},
+ {"activator POST", true, http.MethodPost},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ const host = "pm-holder.example.com"
+ e, _ := purgeEdge(t, host, tc.hibernate, markApp("on"))
+ log := &markLog{}
+ e.pageMarkSeen = log.hook
+ e.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(tc.method, "http://"+host+"/p", nil))
+ log.want(t, "/p", true)
+ })
+ }
+
+ t.Run("upgrade answered without switching", func(t *testing.T) {
+ const host = "pm-holder.example.com"
+ e, _ := purgeEdge(t, host, false, markApp("on"))
+ log := &markLog{}
+ e.pageMarkSeen = log.hook
+ req := httptest.NewRequest(http.MethodGet, "http://"+host+"/ws", nil)
+ req.Header.Set("Connection", "Upgrade")
+ req.Header.Set("Upgrade", "websocket")
+ rec := httptest.NewRecorder()
+ e.ServeHTTP(rec, req)
+ wantNoPageMark(t, "the answer", rec.Header())
+ log.want(t, "/ws", true)
+ })
+
+ t.Run("upgrade switched", func(t *testing.T) {
+ const host = "pm-holder.example.com"
+ e, _ := purgeEdge(t, host, false, func(w http.ResponseWriter, r *http.Request) {
+ c, bw, err := w.(http.Hijacker).Hijack()
+ if err != nil {
+ return
+ }
+ defer c.Close()
+ bw.WriteString("HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: websocket\r\n" +
+ pageCacheHeader + ": on\r\n\r\n")
+ bw.Flush()
+ io.Copy(io.Discard, c)
+ })
+ log := &markLog{}
+ e.pageMarkSeen = log.hook
+ front := httptest.NewServer(e)
+ t.Cleanup(front.Close)
+ conn, err := net.Dial("tcp", front.Listener.Addr().String())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer conn.Close()
+ io.WriteString(conn, "GET /ws HTTP/1.1\r\nHost: "+host+"\r\nConnection: Upgrade\r\nUpgrade: websocket\r\n\r\n")
+ conn.SetReadDeadline(time.Now().Add(5 * time.Second))
+ resp, err := http.ReadResponse(bufio.NewReader(conn), nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if resp.StatusCode != http.StatusSwitchingProtocols {
+ t.Fatalf("status %d, want 101", resp.StatusCode)
+ }
+ wantNoPageMark(t, "the 101", resp.Header)
+ // A 101 is a 1xx: the holder is there, and takePageMark leaves it
+ // unmarked.
+ log.want(t, "/ws", false)
+ })
+
+ t.Run("held stream leg", func(t *testing.T) {
+ up := newDispatchUpstream(t, func(w http.ResponseWriter, _ *http.Request) {
+ w.Header().Set("Content-Type", "text/event-stream")
+ w.Header().Set(pageCacheHeader, "on")
+ io.WriteString(w, "data: one\n\n")
+ w.(http.Flusher).Flush()
+ })
+ act := &scriptActivator{}
+ e, _, front := newDispatchEdge(t, act, heldTestConfig(), heldRoute(up.addr()))
+ log := &markLog{}
+ e.pageMarkSeen = log.hook
+ resp := dispatchDo(t, front, http.MethodGet, heldTestHost, "/live?carlos_hold=1", sseAccept, nil)
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("status %d, want 200", resp.StatusCode)
+ }
+ // Each leg ends after one event, so the task reopens: several legs.
+ readFor(resp.Body, 600*time.Millisecond)
+ if up.hits.Load() < 2 || act.admits.Load() < 2 {
+ t.Fatalf("want at least two legs (hits %d, admits %d): the test proves nothing", up.hits.Load(), act.admits.Load())
+ }
+ wantNoPageMark(t, "the held stream", resp.Header)
+ log.want(t, "/live", true)
+ // A leg's context derives from the browser request's, so without a
+ // holder of its own each leg would write the browser's: a retired
+ // leg still finishing would share it with its replacement.
+ log.mu.Lock()
+ defer log.mu.Unlock()
+ holders := map[*pageMark]bool{}
+ legs := 0
+ for _, s := range log.seen {
+ if s.path == "/live" {
+ legs++
+ if holders[s.mark] {
+ t.Fatalf("two legs shared one page mark holder (seen %+v)", log.seen)
+ }
+ holders[s.mark] = true
+ }
+ }
+ if legs < 2 {
+ t.Fatalf("the hook saw %d legs, want at least two", legs)
+ }
+ })
+
+ t.Run("local asset catch", func(t *testing.T) {
+ s := newLAScene(t, assetOK(laBody, pageCacheHeader, "on"))
+ log := &markLog{}
+ s.e.pageMarkSeen = log.hook
+ wantCache(t, s.get(t, "/assets/app.js"), "miss")
+ log.want(t, "/assets/app.js", true)
+ wantCache(t, s.get(t, "/assets//app.js"), "bypass")
+ log.want(t, "/assets//app.js", true)
+ })
+
+ t.Run("home side of a far fill", func(t *testing.T) {
+ var home *laScene
+ log := &markLog{}
+ s := newFarEdge(t, func(key []byte, m *homeMap) http.Handler {
+ home = newLAScene(t, assetOK(laBody, pageCacheHeader, "on"))
+ hm := newHomeMap(m.s, "betty")
+ refreshHomeMap(t, hm)
+ home.e.homes.Store(hm)
+ home.e.pageMarkSeen = log.hook
+ return home.e
+ })
+ rec := s.get(t, "/assets/app.js")
+ wantCache(t, rec, "miss")
+ wantNoPageMark(t, "the far answer", rec.Header())
+ log.want(t, "/assets/app.js", true)
+ })
+}
diff --git a/internal/edge/scrub_guard_test.go b/internal/edge/scrub_guard_test.go
index c16099111..57927150b 100644
--- a/internal/edge/scrub_guard_test.go
+++ b/internal/edge/scrub_guard_test.go
@@ -190,6 +190,19 @@ func TestEveryScrubRemovesEveryVocabularyEntry(t *testing.T) {
w.WriteHeader(http.StatusOK)
resp.Header = w.Header()
}
+ surf := surfUnannounced
+ if announced {
+ surf = surfAnnounced
+ }
+ // The announced names, as the hook leaves them: the proxy
+ // builds the Trailer header it sends from resp.Trailer's
+ // keys right after ModifyResponse, before the body is read,
+ // so a name scrubbed only at close is already announced.
+ if covers[surf] && announced {
+ if _, ok := resp.Trailer[canon]; ok {
+ t.Errorf("%s: %s still announced after the hook: %v", s.name, name, resp.Trailer)
+ }
+ }
if resp.Body != nil {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
@@ -199,10 +212,8 @@ func TestEveryScrubRemovesEveryVocabularyEntry(t *testing.T) {
t.Errorf("%s: %s left on the %s: %q", s.name, name, surfHeader, v)
}
}
- surf := surfUnannounced
- if announced {
- surf = surfAnnounced
- }
+ // The values, announced or not, once the body is read and
+ // closed.
if covers[surf] {
if _, ok := resp.Trailer[canon]; ok {
t.Errorf("%s: %s left as an %s: %v", s.name, name, surf, resp.Trailer)