carlos / platform Public

edge: reset pages when a reload takes serving off this box

applyPageRoutes reset an instance's pages only when its registry row
failed pageRowEligible, which ignores tunnel dispatch. A local -> tunnel
-> local move with unchanged inputs kept the old local pages, so a
clear made on the remote box in between never reached them.

One predicate, pageServedHere, now answers the routing half of the page
rule over one snapshot of the live table (row eligible; the primary
entry is the same instance, not via a tunnel, no path rows). The
request rule and the reload hook both ask it. The reset draws a new
epoch, fencing outstanding tickets; the opt-in mark stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 79558e57ced96ea06a9f06e454aa2a69c63fb07e parent c08469a
2 files changed, +94 −15
  • internal/edge/pagecache.go +31 −15
  • internal/edge/pagecache_reload_test.go +63 −0

Intent

Human

<task-notification> <task-id>a3db2713c91dc5e8a</task-id> <tool-use-id>toolu_01HMtDrspzRuqZXViVJNCKUC</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/a3db2713c91dc5e8a.output</output-file> <status>completed</status> <summary>Agent "Census inventories for the branch" 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. I re-ran the census on the set-pages tip (5978469b, after docs commit 84b21622), and every census test passes again. No production code changed and nothing was pushed. Commits: c08469a8 `census: re-propose after set-pages`, on top of 953cdb61. Tests on c08469a8: in internal/provision, TestPlan9B8RecordWriteCensus, TestPlan14RootReadCensus and TestCensusScopeIsTheRootBinary pass, and `-run Census` is ok. TestRouteWriterInventoryIsComplete (internal/registry) and TestGroupNameClassCensus (internal/host) never failed on this tip and are still ok. What changed in the card since 953cdb61: one unit, `cli.go:runInstances`, class body, read sites unchanged (13). It keeps its legacy disposition. The root package `.` is now re-pinned as an envelope. No new `reads`, `new` or `other` unit appeared. The seal is now `4a9c3610...`, and I re-proposed under the same NAME. Hand inventory: the record-write census now has new digests for `runInstances` and `handleAPIInstanceUpdate`, with their classes unchanged. It also has the new client `apiSession.instanceSetPages`, classed key-site on `lit:instances` like `instanceSetAssets`. Concerns: none root-side. Nothing in this change runs as root or reads a path a tenant can write. One small thing: the header comment in instances_pages.go says "built as set-pages is" and probably means set-assets. I left it alone. Report, with the new section at the end: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-page-cache-1/.superpowers/sdd/2026-11-08-edge-page-cache-plan-1-home/census-report.md`</result> <usage><subagent_tokens>247801</subagent_tokens><tool_uses>13</tool_uses><duration_ms>260442</duration_ms></usage> </task-notification>

Human

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

Human

<task-notification> <task-id>b8q3tyzw5</task-id> <tool-use-id>toolu_01AW2E4LJSTkpcWs1RWTwQxB</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/b8q3tyzw5.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on c08469a8" completed (exit code 0)</summary> </task-notification>

Human

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

diff --git a/internal/edge/pagecache.go b/internal/edge/pagecache.go
index e29ff3455..f59fcd550 100644
--- a/internal/edge/pagecache.go
+++ b/internal/edge/pagecache.go
@@ -61,9 +61,13 @@ func (e *Edge) EnablePageCache(x *pageindex.Index) {
// - the page switch is off (PagesOff): the same;
// - the row is there but is not one the page cache serves, for any other
// reason (HA, a forward row, a gate, an import gate, a sidecar, a status
-// that is not ready): its pages are reset and the mark stays, so the LRU
-// stays off for the instance. Absence from the live table alone is this
-// case, never a departure.
+// that is not ready, or a live entry that is served over a tunnel, has
+// path rows or is missing): its pages are reset and the mark stays, so
+// the LRU stays off for the instance. Absence from the live table alone
+// is this case, never a departure. The test is pageServedHere over the
+// table this reload published, the one a request's eligibility asks
+// too, so the pages of an instance another box served for a while (a
+// tunnel move and back, with unchanged inputs) never come back.
//
// A release or a config change is not handled here: a page is served and
// stored only from the route's current inputs (servePage, stillCurrent).
@@ -83,6 +87,7 @@ func (e *Edge) applyPageRoutes() {
if len(scopes) == 0 {
return
}
+ m := e.current()
rows := make(map[string]registry.Route, len(e.pageRoutes))
for _, rt := range e.pageRoutes {
rows[rt.Host] = rt
@@ -97,7 +102,7 @@ func (e *Edge) applyPageRoutes() {
e.logThrottled("page-unmark "+s.Instance, fmt.Sprintf(
"page cache: could not clear the opt-in of %s (account %s, app %s), retrying at the next reload: %v", s.Instance, s.Account, s.App, err))
}
- case !pageRowEligible(rt):
+ case !pageServedHere(m, rt):
x.Reset(s)
}
}
@@ -195,7 +200,9 @@ func (e *Edge) pagesOptedIn(up upstream) bool {
// - the box is armed (EnablePageCache);
// - the route is a ready instance this box runs: not a forward row, not
// HA, not a sidecar, not unit-backed, not served over a tunnel, with no
-// password gate, no import gate and the page switch on;
+// password gate, no import gate and the page switch on (pageServedHere,
+// which the reload hook asks too, and the request's own entry is not a
+// tunnel's);
// - no plan throttle is active for the account, as the installed hook
// says, whether or not this request was let through (R3-9);
// - neither host's own entry nor the route's primary has path rows, and
@@ -210,7 +217,8 @@ func (e *Edge) pageRouteEligible(host, path string, up upstream) (inputs string,
return "", false
}
rt := up.route
- if !pageRowEligible(rt) || up.viaTunnel {
+ m := e.current()
+ if !pageServedHere(m, rt) || up.viaTunnel {
return "", false
}
if f := e.planThrottle.Load(); f != nil {
@@ -218,14 +226,10 @@ func (e *Edge) pageRouteEligible(host, path string, up upstream) (inputs string,
return "", false
}
}
- m := e.current()
own, ok := lookupIn(m, host)
if !ok || own.paths != nil || own.route.Host != rt.Host {
return "", false
}
- if primary, ok := m[rt.Host]; !ok || primary.paths != nil {
- return "", false
- }
st := e.assets.Load()
if st == nil || st.store == nil {
return "", false
@@ -245,11 +249,23 @@ func (e *Edge) pageRouteEligible(host, path string, up upstream) (inputs string,
return in, true
}
-// pageRowEligible is the row half of pageRouteEligible's second rule: a
-// ready instance this box runs, not a forward row, not HA, not a sidecar,
-// not unit-backed, with no password gate, no import gate and the page
-// switch on. The reload hook (applyPageRoutes) asks it of the registry's
-// rows; pageRouteEligible adds the live entry's own test (a tunnel).
+// pageServedHere is the routing half of the page rule over one snapshot m
+// of the live table: rt passes pageRowEligible, and m's entry for rt's
+// primary host is rt's own instance, served by this box (not over a
+// tunnel) with no path rows. The request rule (pageRouteEligible) and the
+// reload hook (applyPageRoutes) both ask it, so a reload resets an
+// instance's pages exactly when its requests would stop being served them.
+func pageServedHere(m map[string]upstream, rt registry.Route) bool {
+ if !pageRowEligible(rt) {
+ return false
+ }
+ primary, ok := m[rt.Host]
+ return ok && sameInstance(primary.route, rt) && !primary.viaTunnel && primary.paths == nil
+}
+
+// pageRowEligible is the row half of pageServedHere: a ready instance this
+// box runs, not a forward row, not HA, not a sidecar, not unit-backed, with
+// no password gate, no import gate and the page switch on.
func pageRowEligible(rt registry.Route) bool {
return rt.Kind == "instance" && !rt.IsForward() && !rt.HA && !rt.IsSidecar() && rt.Backing != registry.BackingUnit &&
rt.Status == "ready" && rt.Gate == "" && rt.ImportGate == "" && !rt.PagesOff
diff --git a/internal/edge/pagecache_reload_test.go b/internal/edge/pagecache_reload_test.go
index 3df1efa3c..95b9016ac 100644
--- a/internal/edge/pagecache_reload_test.go
+++ b/internal/edge/pagecache_reload_test.go
@@ -16,6 +16,7 @@ import (
"testing"
"time"
+ "github.com/carlosframework/platform/internal/assetcache"
"github.com/carlosframework/platform/internal/gate"
"github.com/carlosframework/platform/internal/pageindex"
"github.com/carlosframework/platform/internal/registry"
@@ -677,3 +678,65 @@ func TestPageMarkFencedAgainstInFlightRecording(t *testing.T) {
})
}
}
+
+// TestTunnelMoveResetsPagesKeepsMark (final review finding 1): a reload that
+// moves the instance behind a tunnel, with its row, build and config all
+// unchanged, takes its serving off this box, so its pages are reset and the
+// mark stays (the move is temporary ineligibility, not a departure). Moving
+// it back serves no page from before the move: another box served it in
+// between, and a clear made there never reached this index.
+func TestTunnelMoveResetsPagesKeepsMark(t *testing.T) {
+ s := newPCScene(t, reloadApp)
+ s.e.EnableTunnels(NewTunnelHub("tunnel.test", map[string]string{"pi-box": "sekrit"}))
+ s.reload()
+ s.optIn()
+ tunnel := func(name string) {
+ t.Helper()
+ if err := s.reg.SetTunnel(pcHost, name); err != nil {
+ t.Fatal(err)
+ }
+ s.reload()
+ if up, ok := s.e.current()[pcHost]; !ok || up.viaTunnel != (name != "") {
+ t.Fatalf("tunnel %q: the live entry is %+v (present %v)", name, up, ok)
+ }
+ }
+ tunnel("pi-box")
+ s.wantMarked(true, "behind the tunnel")
+ if n := s.pages(); n != 0 {
+ t.Fatalf("%d pages survived the move behind the tunnel", n)
+ }
+ tunnel("")
+ s.wantMarked(true, "back on this box")
+ wantCache(t, s.wantFromApp("/p"), "miss")
+ wantCache(t, s.get("/p"), "hit")
+}
+
+// TestTunnelMoveFencesInFlightRecording: a recording that began while the
+// instance was served here, and whose response is still being written when
+// a reload moves it behind a tunnel, never publishes, even once the
+// instance is back with the same inputs before the recording ends.
+func TestTunnelMoveFencesInFlightRecording(t *testing.T) {
+ s := newPCScene(t, reloadApp)
+ s.e.EnableTunnels(NewTunnelHub("tunnel.test", map[string]string{"pi-box": "sekrit"}))
+ s.reload()
+ tk := s.idx.Begin(s.scope(), s.inputs())
+ if err := s.reg.SetTunnel(pcHost, "pi-box"); err != nil {
+ t.Fatal(err)
+ }
+ s.reload()
+ if err := s.reg.SetTunnel(pcHost, ""); err != nil {
+ t.Fatal(err)
+ }
+ s.reload()
+ pend, err := s.idx.Reserve(tk, pageindex.Key{Host: pcHost, Path: "/p"}, int64(len(pcBody)))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := io.WriteString(pend, pcBody); err != nil {
+ t.Fatal(err)
+ }
+ published, err := pend.Finish(assetcache.Meta{Header: http.Header{}, Lifetime: time.Hour, Expires: time.Now().Add(time.Hour)}, nil)
+ if err != nil || published || s.pages() != 0 {
+ t.Fatalf("a recording begun before the move published: %v %v (%d pages)", published, err, s.pages())
+ }
+}