carlos / platform Public

host: arm the page cache with CARLOS_PAGE_CACHE

Arm the page index over the asset store from the edge ready hook, and give
the shared edge cache the exec backend's CurrentInputs. An index that will
not open leaves the page cache off without failing the agent.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c3cae0e3ce0276fe4e573515ece1e6cc13659266 parent 4598f3e
3 files changed, +166 −1
  • internal/host/agent.go +9 −1
  • internal/host/pagearm.go +60 −0
  • internal/host/pagearm_test.go +97 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>ad2816afb902f3f83</task-id> <tool-use-id>toolu_01SLdboZ9nXr5We2gdQNJGE9</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/ad2816afb902f3f83.output</output-file> <status>completed</status> <summary>Agent "Implement Task 9: reload hook and I2 sim" 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 Important findings are fixed in a new commit (no amend). Commits: - `4598f3e3 pageindex: fence the opt-in mark by the render's epoch; departure is one step` - `858caf1d edge: route changes reset pages; only departure and switch-off clear the mark` (unchanged) Fix 1: the recorder now marks through `MarkOptInFor(Ticket)`, which writes nothing once a Reset has ended the recording's epoch. Departure and `PagesOff` now call `ResetAndClearOptIn`, which does the reset and mark clear as one step under the scope's mark lock. The plain `MarkOptIn` is removed; only tests used it. The new edge regression test failed before the fix and passes now, and two new pageindex tests cover the fence and the lock. Fix 2: the simulation now undoes a disturbance when all five are active, so it never picks from an empty list. It passed 50 full seeds and 25 `-short` seeds with no failures. Tests: all of pageindex passes (full and `-short`, guard and simulation included), and the targeted edge run passes (45.6 s). The two fix mutations each make a test fail. The darwin and Windows builds pass. Concerns: the darwin and Windows `go vet ./internal/edge` checks fail on `undefined: readerConn` in three test files neither commit touches. Task 8's check found them already failing on base e231c7fd; the report lists them as failed checks, separate from the passing builds. At the edge level, only the pageindex test covers the window between the epoch check and the mark write. Report (fix report appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-page-cache-1/.superpowers/sdd/2026-11-08-edge-page-cache-plan-1-home/task-9-report.md</result> <usage><subagent_tokens>195156</subagent_tokens><tool_uses>13</tool_uses><duration_ms>472371</duration_ms></usage> </task-notification>

Human

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

Human

<task-notification> <task-id>a2b797c0b66c72edd</task-id> <tool-use-id>toolu_016a2SnUkPaZMco24a8gg5v5</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/a2b797c0b66c72edd.output</output-file> <status>completed</status> <summary>Agent "Implement Task 10: host arming" 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: STOPPED before building. Your stop condition applies, so I made no code changes and no commits. - There is one production `ExecBackend` in the agent, at `internal/host/agent.go:499`. The other literals, in `claimproduction.go:249` and `movesheldenv.go:51`, are separate helpers. - The wiring at 499 is conditional. It sits inside `if cfg != nil {` (the activator-armed branch, opened around line 488), and `eb` is out of scope at the ready hook near 1290. - `cache` (line 334) is in scope at 499. `cache.SetCurrentInputs(eb.CurrentInputs)` could go right after `eb` is built, inside that branch. - With no activator, the hook stays unset and `Cache.CurrentInputs` returns `("", false)`, which looks safe. I didn't check how the edge's page-cache code treats "unknown inputs", so I haven't confirmed that default is safe. Question for you: should I wire inside `if cfg != nil` right after `eb` is built, leaving the hook unset when there is no activator? If yes, I'll continue with `pagearm.go`, the two tests, and capturing the store from `armEdgeAssetCache` at about line 1290. 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-10-report.md</result> <usage><subagent_tokens>48214</subagent_tokens><tool_uses>5</tool_uses><duration_ms>34905</duration_ms></usage> </task-notification>

Attributed to this commit: 62.0 g CO₂e (8,067,724 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/host/agent.go b/internal/host/agent.go
index 5dd252a99..b020fac99 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -557,6 +557,11 @@ func runAgent(args []string, buildClaims ClaimFactory) {
eb.FilesStore = fs
demoData = fs
}
+ // The page cache asks the exec backend for a route's current inputs
+ // (edge page cache slice 1). On a box with no activator the hook
+ // stays unset, and the edge's pageRouteEligible treats unknown
+ // inputs as not eligible, so every request bypasses the page cache.
+ wireCurrentInputs(cache, eb)
// Durability 3a: an HA host's secrets publish sealed to this
// box's own key, and nothing publishes without one.
eb.EscrowKey = haEscrowKey(os.Getenv("CARLOS_SECRETS_KEY"))
@@ -1287,7 +1292,10 @@ func runAgent(args []string, buildClaims ClaimFactory) {
// anything: with CARLOS_ASSET_CACHE=1, the disk store under the data
// dir and the policy the edges file loop fills. Unarmed, or when the
// store will not open, the edge forwards as today.
- armEdgeAssetCache(os.Getenv, dataDir(), assetcache.Statfs, boxAssets, e.EnableAssetCache)
+ assetStore := armEdgeAssetCache(os.Getenv, dataDir(), assetcache.Statfs, boxAssets, e.EnableAssetCache)
+ // The page cache rides on the asset store, and is called from the
+ // ready hook because EnablePageCache reloads the edge.
+ armEdgePageCache(os.Getenv, dataDir(), assetStore, e.EnablePageCache)
}, edgeOpts...)
admission.Close()
diff --git a/internal/host/pagearm.go b/internal/host/pagearm.go
new file mode 100644
index 000000000..7823517c2
--- /dev/null
+++ b/internal/host/pagearm.go
@@ -0,0 +1,60 @@
+package host
+
+import (
+ "log"
+ "os"
+ "path/filepath"
+
+ "github.com/carlosframework/platform/internal/assetcache"
+ "github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/pageindex"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// pageCacheDirName is the page index's mark directory under
+// $CARLOS_DATA_DIR. Only marks live here; page bytes stay in asset-cache.
+const pageCacheDirName = "page-cache"
+
+// pageCacheArmed reports whether this box opted in with CARLOS_PAGE_CACHE=1.
+func pageCacheArmed(getenv func(string) string) bool {
+ return getenv("CARLOS_PAGE_CACHE") == "1"
+}
+
+// armEdgePageCache arms the page cache over the asset store: with
+// CARLOS_PAGE_CACHE=1 and a store it opens the index (marks under
+// dataDir/page-cache) and hands it to enable (the edge's EnablePageCache).
+// It returns the index, or nil when unarmed, with no store, or when the
+// index will not open; none of those fails the agent.
+func armEdgePageCache(getenv func(string) string, dataDir string, store *assetcache.Store, enable func(*pageindex.Index)) *pageindex.Index {
+ if !pageCacheArmed(getenv) {
+ return nil
+ }
+ if store == nil {
+ log.Printf("agent: page cache needs the asset cache")
+ return nil
+ }
+ dir := filepath.Join(dataDir, pageCacheDirName)
+ if err := os.MkdirAll(dir, 0o700); err != nil {
+ log.Printf("agent: page cache off: %v", err)
+ return nil
+ }
+ x, err := pageindex.Open(pageindex.Config{Store: store, MarkDir: dir})
+ if err != nil {
+ log.Printf("agent: page cache off: %v", err)
+ return nil
+ }
+ log.Printf("agent: page cache armed (marks at %s)", dir)
+ enable(x)
+ return x
+}
+
+// currentInputsSource is what answers a route's current inputs: the exec
+// backend.
+type currentInputsSource interface {
+ CurrentInputs(registry.Route) (string, bool)
+}
+
+// wireCurrentInputs gives the shared edge cache the backend's answer.
+func wireCurrentInputs(c *edge.Cache, src currentInputsSource) {
+ c.SetCurrentInputs(src.CurrentInputs)
+}
diff --git a/internal/host/pagearm_test.go b/internal/host/pagearm_test.go
new file mode 100644
index 000000000..5f3bbf778
--- /dev/null
+++ b/internal/host/pagearm_test.go
@@ -0,0 +1,97 @@
+package host
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/assetcache"
+ "github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/pageindex"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// Arming the edge page cache (edge page cache slice 1, Task 10). Not
+// acceptance: a real asset store on a temporary directory and a recorder in
+// place of EnablePageCache.
+
+func TestArmPageCacheNeedsFlagAndStore(t *testing.T) {
+ store, err := assetcache.Open(assetcache.Config{Dir: t.TempDir(), Budget: 1 << 20, FS: roomyFS})
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, tc := range []struct {
+ name string
+ env string
+ store *assetcache.Store
+ want bool
+ }{
+ {"unset", "", store, false},
+ {"zero", "0", store, false},
+ {"true", "true", store, false},
+ {"padded", " 1", store, false},
+ {"flag, no store", "1", nil, false},
+ {"flag and store", "1", store, true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ data := t.TempDir()
+ calls := 0
+ var got *pageindex.Index
+ x := armEdgePageCache(func(string) string { return tc.env }, data, tc.store, func(i *pageindex.Index) { calls++; got = i })
+ if tc.want {
+ if x == nil || calls != 1 || got != x {
+ t.Fatalf("index %v, %d call(s); want one call with the index", x, calls)
+ }
+ fi, err := os.Stat(filepath.Join(data, pageCacheDirName))
+ if err != nil || !fi.IsDir() || fi.Mode().Perm() != 0o700 {
+ t.Fatalf("mark dir = %v, %v; want a 0700 directory", fi, err)
+ }
+ return
+ }
+ if x != nil || calls != 0 {
+ t.Fatalf("index %v, %d call(s); want none", x, calls)
+ }
+ if _, err := os.Stat(filepath.Join(data, pageCacheDirName)); !os.IsNotExist(err) {
+ t.Fatalf("mark dir exists (%v)", err)
+ }
+ })
+ }
+}
+
+func TestArmPageCacheOpenFailureLeavesItOff(t *testing.T) {
+ store, err := assetcache.Open(assetcache.Config{Dir: t.TempDir(), Budget: 1 << 20, FS: roomyFS})
+ if err != nil {
+ t.Fatal(err)
+ }
+ data := t.TempDir()
+ // A file where the mark directory should be.
+ if err := os.WriteFile(filepath.Join(data, pageCacheDirName), []byte("x"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ calls := 0
+ x := armEdgePageCache(func(string) string { return "1" }, data, store, func(*pageindex.Index) { calls++ })
+ if x != nil || calls != 0 {
+ t.Fatalf("index %v, %d call(s); want none when the open fails", x, calls)
+ }
+}
+
+type fakeInputs struct{}
+
+func (fakeInputs) CurrentInputs(rt registry.Route) (string, bool) { return "fp:" + rt.Host, true }
+
+// The agent hands the cache the ExecBackend's own method; this keeps the
+// type honest.
+var _ currentInputsSource = (*activator.ExecBackend)(nil)
+
+func TestAgentWiresCurrentInputs(t *testing.T) {
+ c := edge.NewCache(edge.DefaultCacheMaxEntries, edge.DefaultCacheMaxBodyBytes)
+ rt := registry.Route{Host: "shop.example.com", Version: "v1"}
+ if _, ok := c.CurrentInputs(rt); ok {
+ t.Fatal("answers before the wiring")
+ }
+ wireCurrentInputs(c, fakeInputs{})
+ if got, ok := c.CurrentInputs(rt); !ok || got != "fp:shop.example.com" {
+ t.Fatalf("CurrentInputs = %q, %v after the wiring", got, ok)
+ }
+}