| index 157dad7e0..7d9892730 100644 |
| --- a/docs/superpowers/plans/2026-11-08-edge-page-cache-plan-1-home.md |
| +++ b/docs/superpowers/plans/2026-11-08-edge-page-cache-plan-1-home.md |
| @@ -2,14 +2,27 @@ |
| |
| > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| |
| -Plan rev 2, after Astra plan round 1 |
| -(`CODEX-FINDINGS-PAGE-CACHE-PLAN1-R1.md`). Marks like **(P1-3)** point |
| -at the finding a passage answers. |
| +Plan rev 3, after Astra plan rounds 1 and 2 |
| +(`CODEX-FINDINGS-PAGE-CACHE-PLAN1-R1.md`, `-R2.md`). Marks like |
| +**(P1-3)** point at a round-1 finding, and **(R2-1)** at a round-2 one. |
| + |
| +Stopping rule 2 fired after round 2 in two families. Paul chose, on |
| +2026-11-08: |
| +- **Release and config invalidation:** "One invariant + gate units". |
| + One function computes an instance's current inputs. A page is served |
| + only while its tag matches them, and stored only when the answering |
| + process started from exactly those inputs. Unit-backed instances are |
| + refused in v1. |
| +- **Marker stripping:** "One list, every scrub". Every client-boundary |
| + scrub iterates one vocabulary list, and a guard test checks each |
| + scrub against every entry. |
| + |
| +Round 3 is the last in the plan's budget. |
| |
| **Goal:** An app marks a response with `Carlos-Page-Cache: on`, and its |
| home box keeps the page on disk and serves it without waking the app, |
| -until the app clears it or the process answering for the instance |
| -changes build or config. |
| +until the app clears it or the instance's installed build or delivered |
| +config changes. |
| |
| **Architecture:** |
| - **`internal/pageindex`** is the spec's page index (§6.1). It is the |
| @@ -23,11 +36,25 @@ changes build or config. |
| responses through the index, and routes both purge channels into it. |
| - **Opted-in instances** (holding a durable opt-in mark) skip the LRU |
| entirely. |
| -- **Every page carries its serving identity:** the build and config the |
| - answering process was started with, recorded at the activator's |
| - existing spawn points. A hit needs the current identity, so a new |
| - release or config invalidates without a separate clear, while a wake |
| - of the same build and config keeps the pages **(P1-3, P1-4)**. |
| +- **One invariant decides release and config freshness (Paul's |
| + choice; R2-1, R2-2):** |
| + - **The current inputs.** `currentInputs(route)` is computed from |
| + box-local state only: the installed build (`route.Version`) and a |
| + fingerprint of the instance's delivered config files. |
| + - **Serving.** A page is served only while its tag equals the current |
| + inputs. A sleeping instance whose build or config changed misses at |
| + once and wakes. |
| + - **Storing.** A page is stored only when the process answering was |
| + started from exactly the current inputs, both when the render began |
| + and when it finished. The activator publishes a process's inputs at |
| + the moment it becomes current (`noteCurrent`, or a non-staged spawn), |
| + never at staging. |
| + - **What follows:** a same-build, same-config wake keeps its pages, |
| + and an old process still serving during a staged switch never |
| + stores. |
| +- **Unit-backed instances** (`route.Backing == registry.BackingUnit`) |
| + are refused in v1: always `bypass` and documented, with a follow-up |
| + for a root-to-agent inputs signal (R2-3). |
| - **Not in this slice:** |
| - far boxes, leases and pushes; |
| - single-flight: the spec's Join (§6.1) arrives with far fills in |
| @@ -43,10 +70,12 @@ repo root. |
| - **Coverage:** slice 1 is §11 item 1. The sections it builds are §4, |
| §5, §6, §8.1 (home side), §8.6 and §10. |
| - **One change of mechanism:** §8.6's "clear on a new release or config" |
| - is implemented as serving-identity tagging. Entries from an earlier |
| - identity become unreachable at the moment the new process answers, |
| - which is the same guarantee without a hook that could fire early or |
| - late. Plan round 1 showed both hooks did. |
| + is implemented as the current-inputs invariant above. Entries tagged |
| + with earlier inputs are unreachable as soon as the inputs change, |
| + whether or not the instance is awake. That is the same guarantee |
| + without a hook that could fire early or late. Plan round 1 showed both |
| + hooks did. |
| +- **One cut:** unit-backed instances are left out of v1 (Paul's choice). |
| |
| **Branch:** `edge-page-cache-1`, cut from `main` after |
| `design-edge-page-cache` (spec and this plan) has merged (stopping rule |
| @@ -58,7 +87,10 @@ repo root. |
| - The marker header is exactly `Carlos-Page-Cache`. Value `on`, with an |
| optional `; ignore-cookies="a,b"` parameter. |
| - The edge strips it from every final response, every 1xx response and |
| - every trailer, on every box, armed or not **(P1-7)**. |
| + every trailer, on every box, armed or not, local or backhauled |
| + **(P1-7, R2-4)**. |
| +- **One list:** every client-boundary scrub iterates |
| + `clientScrubVocabulary`, and nothing keeps a list of its own. |
| - Lifetime is `s-maxage`, else `max-age`. It must be positive and is |
| capped at 365 days. `private`, `no-store` and `no-cache` refuse. |
| |
| @@ -81,14 +113,16 @@ repo root. |
| |
| **Eligible requests** (`pageRouteEligible`): |
| - **The route:** `Kind == "instance"`, not `IsForward()`, not `HA`, not |
| - `IsSidecar()`, `Status == "ready"`, `Gate == ""`, `ImportGate == ""`, |
| - `!PagesOff`. |
| + `IsSidecar()`, `Backing != registry.BackingUnit`, `Status == "ready"`, |
| + `Gate == ""`, `ImportGate == ""`, `!PagesOff`. |
| - **No path rows (P1-6):** neither the requested hostname's own entry in |
| `e.current()` nor its primary has path rows. The request was not |
| dispatched by path to another instance. |
| - **Asset prefixes:** the path is not under a prefix the serving build |
| declares, and the declaration is known **(P2-9)**. |
| -- **Identity:** the instance has a known serving identity. |
| +- **Inputs:** `currentInputs(route)` is known. |
| +- **Storing also needs** the answering process's published inputs to |
| + equal `currentInputs(route)`, both at Begin and at Finish. |
| |
| **Keys and scopes:** |
| - A **scope** is (account, app, instance), where the instance is the |
| @@ -112,8 +146,9 @@ resets page contents but keeps the mark, so the LRU stays off. |
| as absent (still stripped; a marked response still never enters the |
| LRU). |
| - **`Carlos-Cache: hit|miss|bypass`** goes on every response of an |
| - opted-in instance, and on every marked response, whether or not a body |
| - was recorded **(P2-10)**: |
| + opted-in instance, and on every marked response, whatever the method, |
| + eligibility or inputs, and whether or not a body was recorded |
| + **(P2-10, R2-6)**: |
| - `hit`: served from the index; |
| - `miss`: the request was storable and the response was considered; |
| - `bypass`: everything else. |
| @@ -212,9 +247,9 @@ type Clear struct { |
| Hosts []string // nil = every host of the scope |
| Targets []Target // nil = everything on Hosts |
| } |
| -type Ticket struct{ Scope Scope; Epoch, Seq uint64; Identity string } |
| -type Info struct{ ValidAt uint64; Ignore []string; Identity string } |
| -type Miss int // MissNone (a hit), MissAbsent, MissCookies, MissIdentity |
| +type Ticket struct{ Scope Scope; Epoch, Seq uint64; Inputs string } |
| +type Info struct{ ValidAt uint64; Ignore []string; Inputs string } |
| +type Miss int // MissNone (a hit), MissAbsent, MissCookies, MissInputs |
| type Config struct { |
| Store *assetcache.Store |
| MarkDir string |
| @@ -225,14 +260,15 @@ type Config struct { |
| } |
| const MaxBody = 8 << 20 |
| func Open(cfg Config) (*Index, error) |
| -func (x *Index) Begin(s Scope, identity string) Ticket |
| +func (x *Index) Begin(s Scope, inputs string) Ticket |
| func (x *Index) Reserve(t Ticket, k Key, contentLength int64) (*Pending, error) |
| func (p *Pending) Write(b []byte) (int, error) |
| func (p *Pending) Abort() |
| func (p *Pending) Finish(m assetcache.Meta, ignore []string) (published bool, err error) |
| func (x *Index) Clear(s Scope, c Clear) (seq uint64) |
| func (x *Index) Reset(s Scope) |
| -func (x *Index) Lookup(s Scope, k Key, identity string, cookieNames []string) (*assetcache.Entry, Miss) |
| +func (x *Index) Lookup(s Scope, k Key, inputs string, cookieNames []string) (*assetcache.Entry, Miss) |
| +func (x *Index) Sweep() int // drops records whose physical object the store no longer has; returns how many |
| func (x *Index) MarkOptIn(s Scope) error |
| func (x *Index) ClearOptIn(s Scope) error |
| func (x *Index) OptedIn(s Scope) bool |
| @@ -262,8 +298,8 @@ func (x *Index) Scopes() []Scope |
| - no clear in that range matches the logical key; |
| - **if it indexes:** it replaces the logical key's record. The |
| previous physical object is deleted after the lock is released. |
| - `Info.ValidAt` is set to the current sequence, and `Info.Identity` |
| - to `t.Identity`; |
| + `Info.ValidAt` is set to the current sequence, and `Info.Inputs` to |
| + `t.Inputs`; |
| - **if it doesn't:** it deletes only its own physical object and |
| returns `false`. |
| - **`Clear`:** |
| @@ -280,8 +316,7 @@ func (x *Index) Scopes() []Scope |
| - `Targets == nil` means everything. |
| - **`Lookup`:** |
| - finds the logical key's record under the current epoch; |
| - - requires `record.Identity == identity`, otherwise returns |
| - `MissIdentity`; |
| + - requires `record.Inputs == inputs`, otherwise returns `MissInputs`; |
| - requires every cookie name to be in `Ignore`, otherwise |
| `MissCookies`; |
| - then calls `Store.Get(physical key)`. A miss there (evicted or |
| @@ -289,6 +324,10 @@ func (x *Index) Scopes() []Scope |
| - **`Open`** runs `Store.Retain(func(k) bool { return |
| !assetcache.IsPageKey(k) })` once, because an earlier process's |
| epochs are gone. |
| +- **`Sweep` (R2-8)** checks every record against `Store.Get` and drops |
| + the dangling ones. The edge calls it on the asset sweep's tick |
| + (`assetSweepEvery`). Records are then bounded by the store's own |
| + entries plus what was published since the last sweep. |
| - **Opt-in marks:** |
| - each is one file per scope in `MarkDir`, named by the hex sha256 |
| of `Account + "\x00" + App + "\x00" + Instance`; |
| @@ -298,10 +337,10 @@ func (x *Index) Scopes() []Scope |
| |
| - [ ] **Step 1: Write failing tests** (a temp-dir store): |
| - **Publish and look up:** |
| - - `TestPublishThenLookup`: a hit with the same identity, and its |
| - body reads back. |
| - - `TestLookupNeedsIdentity`: publish under identity `b1`, then |
| - Lookup with `b2` → `MissIdentity`. |
| + - `TestPublishThenLookup`: a hit with the same inputs, and its body |
| + reads back. |
| + - `TestLookupNeedsInputs`: publish under inputs `b1`, then Lookup |
| + with `b2` → `MissInputs`. |
| - **Clears:** |
| - `TestClearRemovesMatching`: `/a`, `/a?x=1` and `/b` with path and |
| URL targets, as in rev 1. |
| @@ -327,6 +366,9 @@ func (x *Index) Scopes() []Scope |
| behind the index's back, then Lookup → `MissAbsent`, and the |
| record is gone. |
| - `TestOpenDropsEarlierPages`. |
| + - `TestSweepBoundsRecords` (R2-8): with a store budget for about 10 |
| + entries, publish 500 distinct query keys and call `Sweep`. The |
| + record count is ≤ the store's page entries, with no Reset. |
| - **Marks and size:** |
| - `TestOptInMarkSurvivesOpen`. |
| - `TestTooLargeAborts`. |
| @@ -349,7 +391,7 @@ func (x *Index) Scopes() []Scope |
| - **The setup:** 8 goroutines run 2000 random operations (300 under |
| `-short`) over 3 scopes. The scopes differ in account, app or |
| instance, with 2 hosts each, overlapping host names across scopes, |
| - 6 paths and 2 identities. |
| + 6 paths and 2 input values. |
| - **The operations:** Begin + Reserve + Write + Finish, where |
| `afterCommit` randomly yields or sleeps 0–2 ms; Clear with random |
| targets; Reset; Lookup; MarkOptIn and ClearOptIn. |
| @@ -364,7 +406,7 @@ func (x *Index) Scopes() []Scope |
| seq > the body's ticket seq, matches its key; |
| - **I3:** the body's scope, host, path and query equal the Lookup's |
| arguments; |
| - - the identity equals the Lookup's identity. |
| + - the inputs equal the Lookup's inputs. |
| - **Seeding:** the seed comes from `-seed` (default the time), and is |
| printed on failure. |
| - [ ] **Step 2: Write `TestStoreHoldsNoUnindexedPages`.** After the |
| @@ -426,120 +468,153 @@ func (x *Index) Scopes() []Scope |
| - [ ] **Step 5: Commit:** `registry: per-instance pages switch, mirrored |
| on assets_off`. |
| |
| -### Task 5: The marker is read once, stripped everywhere, kept out of the LRU |
| +### Task 5: One scrub list; the marker is read once, stripped everywhere, kept out of the LRU |
| |
| **Files:** |
| - Create: `internal/edge/pagemark.go`. |
| +- Modify `internal/edge/assetcatch.go` (Paul's choice, "One list, every |
| + scrub"; R2-4): |
| + - rename `assetVocabulary` (:966) to `clientScrubVocabulary` and add |
| + `pageCacheHeader` to it; |
| + - `stripAssetResponseHeaders`, `stripAssetTrailers`, |
| + `assetInformationalScrub` and `scrubBackhaulResponse` (:1362) all |
| + iterate it; |
| + - `scrubBackhaulResponse` keeps only the entries its `assetFill` |
| + argument names (the ack and expiry headers), by an explicit keep set |
| + rather than a list of its own. |
| - Modify: |
| - - `internal/edge/assetcatch.go:966`: add `pageCacheHeader` to |
| - `assetVocabulary`, so `stripAssetResponseHeaders`, |
| - `stripAssetTrailers` and `assetInformationalScrub` all remove it; |
| - `internal/edge/cookiescope.go:85`: in `responseModifier`, call |
| - `takePageMark(resp)` before `stripAssetResponseHeaders`; |
| + `takePageMark(resp)` before the scrub; |
| - `internal/edge/edge.go`: |
| - wrap the local proxy and activator calls (:2707–2730) in |
| - `assetInformationalScrub{w}`, as `edge.go:4285` already does for |
| - hops, so a local route's 1xx is scrubbed too; |
| + `assetInformationalScrub{w}`, as `edge.go:4285` does for hops; |
| - `maybeStore` (:2907) refuses when `pageMarkOf(rec.request)` is |
| `Marked`. |
| -- Test: `internal/edge/pagemark_test.go`. |
| +- Test: `internal/edge/pagemark_test.go`, |
| + `internal/edge/scrub_guard_test.go`. |
| |
| **Interfaces:** |
| - Produces: |
| ```go |
| +var clientScrubVocabulary = []string{assetFillHeader, assetAckHeader, assetExpiresHeader, assetCacheHeader, pageCacheHeader} |
| type pageMark struct{ Marked bool; Ignore []string; Bad bool } |
| func withPageMarkHolder(r *http.Request) *http.Request |
| func pageMarkOf(r *http.Request) *pageMark // nil when no holder |
| -func takePageMark(resp *http.Response) // parses the final response's header into the holder; never reads trailers or 1xx |
| +func takePageMark(resp *http.Response) // final response header only; never trailers or 1xx |
| const pageCacheHeader = "Carlos-Page-Cache" |
| ``` |
| - **Parsing:** |
| - `on` gives `Marked`; |
| - `on; ignore-cookies="a,b"` adds the names; |
| - anything else sets `Bad`. |
| -- **Where the holder goes:** ServeHTTP attaches it at the LRU point for |
| - every GET and HEAD it may cache or page-cache, before the activator or |
| - proxy runs. |
| +- **Where the holder goes (R2-6):** ServeHTTP attaches it for **every** |
| + proxied request to a `Kind == "instance"` route, whatever the method, |
| + before the activator or proxy runs. |
| |
| - [ ] **Step 1: Write failing tests** |
| + - **`TestEveryScrubRemovesEveryVocabularyEntry`** (the guard). For |
| + each scrub function and each entry in `clientScrubVocabulary`: |
| + - set the entry as a header, a trailer (announced and not) and on a |
| + 1xx; |
| + - run the scrub, and assert it's gone. `scrubBackhaulResponse` with |
| + `assetFill=true` may keep only the ack and expiry headers. |
| + - **The table of scrub functions** is listed in the test. A comment |
| + says a new client-boundary scrub must be added to it. |
| - `TestPageMarkStrippedFinalHeader`: on an edge with no page index, |
| - the app sends the marker, and the visitor's response lacks it. |
| - - `TestPageMarkStripped103`: the app writes a `103` carrying the |
| - marker, then a 200. The client's informational response lacks it |
| - (use `httptrace.ClientTrace.Got1xxResponse`). |
| - - `TestPageMarkStrippedTrailers`: the app announces `Trailer: |
| - Carlos-Page-Cache` and sets it, and separately sets an unannounced |
| - trailer of that name. The client sees neither, and neither marks |
| - the page. |
| - - `TestPageMarkParses`: a table of values. |
| + the visitor never sees the marker. |
| + - `TestPageMarkStrippedThroughBackhaul` (R2-4): a mock older home |
| + returns the marker on an ordinary backhaul. The visitor never sees |
| + it, with page caching armed and unarmed. |
| + - `TestPageMarkStripped103` (use |
| + `httptrace.ClientTrace.Got1xxResponse`). |
| + - `TestPageMarkStrippedTrailers`: announced and unannounced. Neither |
| + marks the page. |
| + - `TestPageMarkParses`. |
| - `TestMarkedResponseNeverEntersLRU`. |
| - `TestUnmarkedResponseStillUsesLRU`. |
| - [ ] **Step 2: Run them to see them fail.** |
| - [ ] **Step 3: Implement as above.** |
| -- [ ] **Step 4: Run them to see them pass,** plus `-run |
| - 'Asset.*Scrub|Vocabulary|Trailer'` for the neighbours. |
| -- [ ] **Step 5: Commit:** `edge: read and strip Carlos-Page-Cache |
| - everywhere; marked responses skip the LRU`. |
| +- [ ] **Step 4: Watch the guard fail** when one scrub reverts to a |
| + private list. Restore it. |
| +- [ ] **Step 5: Run them to see them pass,** plus `-run |
| + 'Asset.*Scrub|Vocabulary|Trailer|Backhaul'`. |
| +- [ ] **Step 6: Commit:** `edge: one client scrub list; read and strip |
| + Carlos-Page-Cache everywhere`. |
| + |
| +### Task 6: The current inputs, and the inputs each process was started from |
| |
| -### Task 6: The serving identity, recorded where processes start |
| +This is the invariant Paul chose ("One invariant + gate units"; R2-1, |
| +R2-2, R2-3). |
| |
| **Files:** |
| -- Modify: `internal/edge/cache.go`: add the identity table, beside the |
| - existing indexes. |
| -- Modify: every activator site that calls `b.Cache.PurgeHost` on a |
| - process start: |
| - - `internal/activator/backend_exec.go:2298, :2573, :2852`; |
| - - `internal/activator/rootfs.go:427`; |
| - - `internal/activator/genbackend.go:362` (GenSwitched). |
| - Each also calls `b.Cache.NoteServing(rt.Host, identity)`. |
| -- Create: `internal/activator/servingidentity.go`. |
| -- Test: `internal/activator/servingidentity_test.go`, |
| - `internal/edge/cache_test.go`. |
| +- Create: `internal/activator/inputs.go`, holding the one function both |
| + sides use. |
| +- Modify: `internal/activator/genservice.go:96` (`noteCurrent`), and |
| + the exec spawn site that makes a process current without staging |
| + (`backend_exec.go:2565–2575`, the `exe == ""` branch). |
| + - **When a process is staged:** its inputs are captured when it |
| + starts, and carried with it (on `genMember`, or the `Gen` the |
| + staging returns). |
| + - **When they are published:** only when it becomes current. |
| +- Modify: `internal/edge/cache.go`: a table of published inputs. |
| +- Test: `internal/activator/inputs_test.go`, `internal/edge/cache_test.go`. |
| |
| **Interfaces:** |
| - Produces: |
| ```go |
| -func (c *Cache) NoteServing(host, identity string) |
| -func (c *Cache) ServingIdentity(host string) (string, bool) // false until a start was noted in this agent process |
| -func servingIdentity(build string, configFiles []string) (string, error) // hex sha256 over the build and each config file's path and bytes, in a stable order |
| +// in internal/activator: |
| +func CurrentInputs(rt registry.Route, configFiles func(registry.Route) []string) (string, bool) |
| +// hex sha256 over rt.Version and each config file's path and bytes, in |
| +// a stable order; false when a file cannot be read. A missing file is |
| +// fingerprinted as absent, which is a valid state. |
| +func (b *ExecBackend) configFilesFor(rt registry.Route) []string |
| +// exactly the env files the spawn reads (readEnvFile at backend_exec.go:2421 |
| +// and the sidecar env at :3355), so both sides fingerprint the same set |
| +// in internal/edge: |
| +func (c *Cache) NoteProcessInputs(host, inputs string) // the current process's launch inputs |
| +func (c *Cache) ProcessInputs(host string) (string, bool) // false until noted in this agent process |
| +func (c *Cache) SetCurrentInputs(f func(registry.Route) (string, bool)) // the host wires CurrentInputs here |
| +func (c *Cache) CurrentInputs(rt registry.Route) (string, bool) |
| ``` |
| |
| -**What goes into the identity:** |
| -- **The build:** the build that process was started from. At |
| - GenSwitched it is the generation's build; at the other sites, the |
| - build the spawn launches. |
| -- **The config files:** every config file the activator hands that |
| - process, read at the start. |
| - |
| -**Rules:** |
| -- **Unreadable config:** `NoteServing(host, "")`. An empty identity |
| - means "unknown", and pages bypass for that instance. |
| -- **Wakes:** a wake of the same build and config computes the same |
| - identity. |
| -- **Other starts:** a site that starts a process but doesn't call |
| - `PurgeHost` today gets no identity, so its pages bypass. Name any such |
| - site in the commit message. |
| +**The rules:** |
| +- **The fingerprint cache:** `CurrentInputs` is called on every page |
| + lookup. It caches each file's fingerprint by (path, size, mtime, |
| + inode) and re-hashes only when those change. A lookup costs one |
| + `stat` per config file. |
| +- **Unit-backed routes** never reach these. `pageRouteEligible` refuses |
| + them (Task 7). |
| +- **The two sides must agree:** the inputs a process launches from are |
| + computed by `CurrentInputs` over the same files, read at launch. |
| |
| - [ ] **Step 1: Write failing tests** |
| - - `TestServingIdentityStableAcrossWake`: the same build and files give |
| - the same identity. |
| - - `TestServingIdentityChangesWithBuildOrConfig`: each change gives a |
| - different identity. |
| - - `TestUnreadableConfigGivesEmpty`. |
| - - `TestCacheNoteServing`: round-trip, and an unknown host → `false`. |
| - - **A focused activator test per start site, through the real |
| - backend:** |
| - - `TestExecSpawnNotesIdentity`; |
| - - `TestGenSwitchNotesNewIdentity`: a staged successor doesn't change |
| - the identity until the switch. |
| + - **The function:** |
| + - `TestCurrentInputsStable`: the same version and files give the |
| + same value, twice. |
| + - `TestCurrentInputsChanges`: a version change, a file edit, and a |
| + file removal each give a new value. |
| + - `TestCurrentInputsStatCache`: an unchanged stat doesn't read the |
| + file again (count reads with a seam). |
| + - **Through the real exec backend:** |
| + - `TestNonStagedSpawnPublishesInputs`: a fresh spawn publishes |
| + inputs equal to `CurrentInputs` at launch. |
| + - `TestWakeSameInputsSameValue`: sleep, then wake with nothing |
| + changed. The published inputs are unchanged. |
| + - `TestStagedSuccessorPublishesAtSwitch`: stage a successor with new |
| + inputs (native nested and rootfs backends). Until the switch, |
| + `ProcessInputs` still returns the incumbent's inputs. After the |
| + switch it returns the successor's, which are its launch-time |
| + inputs, even if config changed again after it launched. |
| + - **The table:** `TestCacheProcessInputs`, a round-trip, and an |
| + unknown host → `false`. |
| - [ ] **Step 2: Run them to see them fail:** `go test |
| - ./internal/activator -run 'ServingIdentity|SpawnNotesIdentity|GenSwitchNotes' |
| + ./internal/activator -run 'CurrentInputs|PublishesInputs|WakeSameInputs|StagedSuccessor' |
| -count=1` (with the task-owned `TMPDIR`). |
| - [ ] **Step 3: Implement as above.** |
| -- [ ] **Step 4: Run them to see them pass,** plus `-run 'Purge|Gen'` in |
| - `internal/activator`. |
| -- [ ] **Step 5: Commit:** `activator: record each instance's serving |
| - identity at process start`. |
| +- [ ] **Step 4: Run them to see them pass,** plus `-run |
| + 'Purge|Gen|Swap'` in `internal/activator`. |
| +- [ ] **Step 5: Commit:** `activator: current inputs and per-process |
| + launch inputs, published when current`. |
| |
| ### Task 7: Serving and storing pages on the home box |
| |
| @@ -547,10 +622,12 @@ func servingIdentity(build string, configFiles []string) (string, error) // hex |
| - Create: `internal/edge/pagecache.go`, `internal/edge/pagerecord.go`. |
| - Modify: `internal/edge/edge.go`, at the LRU gate (:2673–2690) and the |
| proxy calls (:2707–2729). |
| -- Modify: `internal/host/assetpolicy.go`: add `DeclaresPrefix` |
| - **(P2-9)**. |
| -- Modify: `internal/edge/assettypes.go`: an optional interface for it. |
| +- Modify: `internal/host/assetpolicy.go`: add `DeclaresPrefix` and a |
| + background declaration loader **(P2-9, R2-5)**. |
| +- Modify: `internal/edge/assettypes.go`: an optional interface for |
| + `DeclaresPrefix`. |
| - Test: `internal/edge/pagecache_test.go`, |
| + `internal/edge/pagecache_sim_test.go`, |
| `internal/host/assetpolicy_test.go`. |
| |
| **Interfaces:** |
| @@ -558,59 +635,71 @@ func servingIdentity(build string, configFiles []string) (string, error) // hex |
| - Tasks 2, 5 and 6; |
| - `serveAssetEntry` (`assetserve.go:37`), `parseMaxAge` |
| (`edge.go:3110`), `canonicalAssetPath` (`assetcatch.go:47`); |
| - - `lookupUpstreamPath` (`edge.go:1761`). |
| + - `assetManifestCache.cached` (`assetmanifests.go:64`). |
| - Produces: |
| ```go |
| func (e *Edge) EnablePageCache(x *pageindex.Index) |
| func pageScopeOf(up upstream) pageindex.Scope // Account via release.RouteAccount(up.route), App, Instance = up.route.Host |
| -func (e *Edge) pageRouteEligible(host, path string, up upstream) (identity string, ok bool) |
| +func (e *Edge) pageRouteEligible(host, path string, up upstream) (inputs string, ok bool) |
| func pageReadable(r *http.Request) (cookieNames []string, ok bool) |
| func pageStorable(r *http.Request) bool |
| func pageAdmit(status int, h http.Header, mark *pageMark) (lifetime time.Duration, ok bool) |
| func (e *Edge) pagesOptedIn(up upstream) bool |
| -// host side, read through an optional edge interface: |
| type assetDeclarations interface{ DeclaresPrefix(host, build, path string) (declared, known bool) } |
| func (p *assetPolicy) DeclaresPrefix(host, build, path string) (declared, known bool) |
| +func (p *assetPolicy) WantDeclarations(acct, app, build string) // queue a background manifest read |
| ``` |
| |
| -**Two details:** |
| -- **`DeclaresPrefix`** reads the release manifest through |
| - `p.manifests.paths`, whatever `AssetsOff`, the asset generation or the |
| - catch snapshot say. When the manifest hasn't been read, it returns |
| - `known=false`, and the page cache bypasses. |
| -- **`pageRouteEligible`** checks the requested hostname's own |
| - `e.current()[host]` entry for path rows, not only the dispatched |
| - upstream. It also refuses when that entry's `route.Host` differs from |
| - the dispatched `up.route.Host` (a path dispatch) **(P1-6)**. |
| +**Declarations (R2-5):** |
| +- **On requests:** `DeclaresPrefix` reads only |
| + `p.manifests.cached(acct, app, build)`, with `build = route.Version`, |
| + whatever `AssetsOff` says. It never reads storage on a request. |
| +- **When the cache has no entry:** it returns `known=false` and calls |
| + `WantDeclarations`. That queues a background `p.manifests.paths` read |
| + on the policy's own schedule, deduplicated and bounded. |
| +- **After the read:** later requests know the answer. An assets-off |
| + instance goes from bypass to cacheable without a request-time read. |
| + |
| +**Eligibility:** |
| +- **Path rows (P1-6):** `pageRouteEligible` checks the requested |
| + hostname's own `e.current()[host]` entry for path rows, and refuses a |
| + path dispatch: that entry's `route.Host` differs from `up.route.Host`. |
| +- **Unit-backed routes** are refused. |
| +- **The inputs it returns** are `Cache.CurrentInputs(up.route)`. Not |
| + known means not eligible. |
| |
| **At the LRU gate:** |
| -1. **Whenever `pagesOptedIn(up)` holds,** whatever the path or |
| - eligibility, the LRU is off: `cacheable = false`. This is the one |
| - place §5.3's rule is checked. |
| -2. **When `pageRouteEligible` holds and `pageReadable` passes,** call |
| - `idx.Lookup(scope, key, identity, cookies)`. |
| - - On a hit, `serveAssetEntry(w, r, entry, now, "hit")`. Return only |
| - if it returned nil. On an error the writer is untouched, so |
| - continue down the miss path **(P1-8)**. |
| - - The Miss reason feeds the diagnostic in step 4. |
| -3. **When it is also `pageStorable`,** `t := idx.Begin(scope, |
| - identity)`. A `pageRecorder` reserves at WriteHeader if `pageAdmit` |
| - passes and `Content-Length` (when present) ≤ `MaxBody`, then tees. |
| - After the proxy returns: |
| - - a `Set-Cookie` trailer, an error or an overflow means `Abort`; |
| - - otherwise `MarkOptIn` (durable), then `Finish`; |
| - - Finish's meta uses `assetStoredHeader`, `Lifetime`, and |
| - `Expires = now + lifetime`. |
| -4. **The diagnostic writer** wraps every response of an eligible route, |
| - whatever the method. At WriteHeader it sets `Carlos-Cache` when the |
| +1. **Whenever `pagesOptedIn(up)` holds,** whatever the path, eligibility |
| + or inputs, the LRU is off: `cacheable = false`. This is the one place |
| + §5.3's rule is checked. |
| +2. **When eligible and `pageReadable`,** call `idx.Lookup(scope, key, |
| + inputs, cookies)`. On a hit, call `serveAssetEntry(w, r, entry, now, |
| + "hit")`, and return only if it returned nil. Otherwise continue down |
| + the miss path **(P1-8)**. |
| +3. **When eligible and `pageStorable`,** and only when |
| + `Cache.ProcessInputs(host) == inputs` (the answering process started |
| + from the current inputs): |
| + - `t := idx.Begin(scope, inputs)`; |
| + - a `pageRecorder` reserves at WriteHeader if `pageAdmit` passes and |
| + `Content-Length` (when present) ≤ `MaxBody`, then tees. |
| + - **After the proxy returns:** |
| + - abort on a `Set-Cookie` trailer, an error or an overflow; |
| + - abort also if `CurrentInputs` or `ProcessInputs` no longer equal |
| + `inputs`; |
| + - otherwise `MarkOptIn` (durable), then `Finish`. Its meta uses |
| + `assetStoredHeader`, `Lifetime`, and `Expires = now + lifetime`. |
| +4. **The diagnostic writer (R2-6)** wraps every proxied response of a |
| + `Kind == "instance"` route on an armed box, independent of |
| + eligibility and inputs. At WriteHeader it sets `Carlos-Cache` when the |
| instance is opted in or the holder says `Marked`: |
| - - `miss` when step 3 ran; |
| - - `bypass` otherwise, including a cookie miss, a POST and a HEAD |
| - miss. |
| - It never sets the header on other apps' responses. |
| + - `miss` when step 3 recorded; |
| + - `bypass` otherwise. |
| |
| - [ ] **Step 1: Write failing tests** (a `newLAScene`-style scene with |
| - an asset store, a page index, and `NoteServing(host, "id1")`): |
| + an asset store, a page index, and a fake config file): |
| + - **The scene's inputs:** `SetCurrentInputs` wired to a test |
| + `CurrentInputs`, and `NoteProcessInputs(host, CurrentInputs(rt))` |
| + as a spawn would publish them. |
| - **The core path:** |
| - `TestPageMissThenHitWithoutApp`. |
| - `TestPageHitOnHibernatingRouteDoesNotWake`. |
| @@ -623,43 +712,80 @@ func (p *assetPolicy) DeclaresPrefix(host, build, path string) (declared, known |
| - `TestPageCookieRequestNotStoredAnywhere` (Review Focus 4). |
| - `TestPageIgnoredCookieHits`, `TestPageAuthorizationBypasses`. |
| - **Hit behaviour:** `TestPageHeadRangeConditional` (Review Focus 1). |
| - - **Identity:** |
| - - `TestPageNewIdentityMisses`: a hit under `id1`, then |
| - `NoteServing(host, "id2")` → `miss` that reaches the app. |
| - - `TestPageUnknownIdentityBypasses`: with no `NoteServing`, the |
| + - **Inputs (R2-1, R2-2):** |
| + - `TestPageSleepingNewBuildMisses`: |
| + - cache a page, then mark the route hibernating; |
| + - set `route.Version` to a new build without any spawn, and |
| + Reload; |
| + - request only the cached URL. It misses, and the activator is |
| + asked to wake. |
| + - `TestPageSleepingConfigChangeMisses`: the same, editing the config |
| + file. A second variant removes it. |
| + - `TestPageSameInputsWakeKeepsHits`: a wake with nothing changed |
| + still hits. |
| + - `TestPageOldProcessDuringStagingNotStored`: the current inputs |
| + change while `ProcessInputs` still returns the old ones. A marked |
| response is `bypass` and isn't stored. |
| - - **Failed delivery:** `TestPageEvictedBetweenLookupAndOpenFallsThrough` |
| - (P1-8). Pause between Lookup and Open with a seam, delete the store |
| - object, and the response is the app's 200 with a body. |
| - - **Opt-in and the LRU:** `TestOptedInInstanceSkipsLRU`. A seeded LRU |
| - entry and an unmarked `s-maxage` path under a declared asset prefix |
| - both reach the app after opt-in. |
| - - **Path routing:** `TestPagePathRoutedHostRefused` (P1-6). Host A |
| - routes `/blog` to instance B, with B's own path map empty, and an |
| - alias of A. A marked answer through A or its alias is never stored, |
| - under either scope. |
| + - `TestPageUnitBackedBypasses` (R2-3): `Backing: BackingUnit`. A |
| + marked response is `bypass` and isn't stored. |
| + - **Failed delivery:** |
| + `TestPageEvictedBetweenLookupAndOpenFallsThrough` (P1-8). |
| + - **Opt-in and the LRU:** `TestOptedInInstanceSkipsLRU`. |
| + - **Path routing:** `TestPagePathRoutedHostRefused` (P1-6). |
| - **Asset prefixes:** |
| - - `TestPageAssetPrefixWinsWhenAssetsOff` (P2-9): an `AssetsOff` |
| - route whose release declares `/assets/`. A marked `/assets/x` is |
| - not stored. |
| - - `TestPageUnknownDeclarationBypasses`. |
| - - **Diagnostics:** `TestPageDiagnostics` (P2-10), a table: |
| + - `TestPageAssetPrefixWinsWhenAssetsOff` (P2-9). |
| + - `TestPageDeclarationsLoadInBackground` (R2-5). An assets-off |
| + instance's first marked request is `bypass`, with no storage read |
| + on the request path (assert with a counting manifest store). |
| + After the background load, the next one is stored, and a marked |
| + `/assets/x` never is. |
| + - **Diagnostics:** `TestPageDiagnostics` (P2-10, R2-6), a table: |
| - hit → `hit`; |
| - stored miss → `miss`; |
| - a cookie-rejected lookup → `bypass`; |
| - - a marked POST → `bypass`; |
| + - the first marked POST on a not-yet-opted-in instance → `bypass`; |
| + - a marked GET with unknown inputs → `bypass`; |
| - a HEAD miss → `bypass`; |
| + - an opted-in instance made temporarily ineligible → `bypass`; |
| - an unrelated app → no header. |
| - **Ineligible routes:** `TestPageIneligibleRoutes`, the table from |
| - rev 1. |
| + rev 1 plus unit-backed. |
| - **Host side:** `TestDeclaresPrefixIgnoresAssetsOff`. |
| -- [ ] **Step 2: Run them to see them fail:** `go test ./internal/edge |
| - -run 'TestPage|TestOptedIn' -count=1` (with the task-owned `TMPDIR`), |
| - and `go test ./internal/host -run DeclaresPrefix -count=1`. |
| -- [ ] **Step 3: Implement as above.** |
| -- [ ] **Step 4: Run them to see them pass,** then `-run |
| +- [ ] **Step 2: Write `TestEdgeSimulationNoPersonalLeak` (I2; |
| + R2-7).** |
| + - **The setup:** a fake app whose every body names the request's |
| + provenance (a request id, plus whether it carried `Cookie` or |
| + `Authorization`). |
| + - **The run:** 1000 random requests (200 under `-short`) over 2 |
| + instances and 4 paths, mixing: |
| + - anonymous requests, requests with ignorable cookies, requests with |
| + session cookies, and requests with `Authorization`; |
| + - marked and unmarked `s-maxage` responses; |
| + - LRU entries stored before opt-in; |
| + - opt-in transitions; |
| + - gate add and remove reloads; |
| + - clears. |
| + - **The assertion:** whenever a response comes from either cache (no |
| + app call for that request), its body's provenance is anonymous. The |
| + one exception is a request carrying only ignorable cookies, which |
| + may get an anonymous body. |
| + - **Seeding:** the seed is printed on failure. |
| +- [ ] **Step 3: Run them to see them fail:** `go test ./internal/edge |
| + -run 'TestPage|TestOptedIn|TestEdgeSimulation' -count=1` (with the |
| + task-owned `TMPDIR`), and `go test ./internal/host -run DeclaresPrefix |
| + -count=1`. |
| +- [ ] **Step 4: Implement as above.** |
| +- [ ] **Step 5: Watch each guard fail under its own mutation,** then |
| + restore: |
| + - drop `maybeStore`'s marked refusal → the simulation or |
| + `TestMarkedResponseNeverEntersLRU` fails; |
| + - drop the opted-in LRU gate → the simulation or |
| + `TestOptedInInstanceSkipsLRU` fails; |
| + - drop the inputs check in Lookup → `TestPageSleepingNewBuildMisses` |
| + fails. |
| +- [ ] **Step 6: Run them to see them pass,** then `-run |
| 'Cache|Asset|Purge'` for the neighbours. |
| -- [ ] **Step 5: Commit:** `edge: home-box page cache at the LRU point`. |
| +- [ ] **Step 7: Commit:** `edge: home-box page cache at the LRU point`. |
| |
| ### Task 8: Clears reach the index (header, socket and `all`) |
| |
| @@ -695,7 +821,8 @@ today, then calls `clearPages` for each host with the same targets: |
| |
| **Socket channel.** `{"path":"all"}` does the same, and every other |
| socket path also calls `clearPages`. Activator start sites still call |
| -only `PurgeHost`, plus Task 6's `NoteServing`. They never clear pages. |
| +only `PurgeHost`, plus Task 6's `NoteProcessInputs`. They never clear |
| +pages. |
| |
| - [ ] **Step 1: Write failing tests** |
| - `TestPurgeHeaderClearsPage`. |
| @@ -726,8 +853,8 @@ only `PurgeHost`, plus Task 6's `NoteServing`. They never clear pages. |
| gate, a sidecar, a status that isn't ready): `Reset` only. The mark |
| stays, so the LRU stays off. |
| |
| -Releases and config are not handled here: Task 6's identity covers |
| -them. |
| +Releases and config are not handled here. Task 6's current-inputs |
| +invariant covers them, checked on every lookup and store. |
| |
| - [ ] **Step 1: Write failing tests** |
| - `TestRouteDepartureResetsAndClearsMark`. |
| @@ -766,9 +893,17 @@ func armEdgePageCache(getenv func(string) string, dataDir string, store *assetca |
| - **Declarations:** the asset policy's `DeclaresPrefix` reaches the edge |
| through the same `LocalAssets` value already passed to |
| `EnableAssetCache`. |
| +- **Current inputs:** the host wires `e.cache.SetCurrentInputs` to |
| + `activator.CurrentInputs` with the exec backend's `configFilesFor`, at |
| + the point the activator and the cache are both built |
| + (`agent.go:334`). |
| +- **The sweep:** `EnablePageCache` registers `idx.Sweep` on the asset |
| + sweep's tick (`assetSweepEvery`). |
| |
| -- [ ] **Step 1: Write a failing test:** |
| - `TestArmPageCacheNeedsFlagAndStore`, a table. |
| +- [ ] **Step 1: Write failing tests** |
| + - `TestArmPageCacheNeedsFlagAndStore`, a table. |
| + - `TestAgentWiresCurrentInputs`: a focused agent test. After the |
| + wiring, `Cache.CurrentInputs` answers for an exec route. |
| - [ ] **Step 2: Run it to see it fail.** |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run it to see it pass.** |
| @@ -798,8 +933,9 @@ func armEdgePageCache(getenv func(string) string, dataDir string, store *assetca |
| asset paragraph (:285–289). It covers the marker, lifetimes, the |
| `max-age=0` advice, ignorable cookies, what is never cached, |
| `Carlos-Cache`, the clear targets including `all`, that a new |
| - release or config stops old pages being served, and that asset |
| - paths win; |
| + release or config stops old pages being served, that asset paths |
| + win, and that unit-backed instances (`carlos-app@` units) are not |
| + page-cached yet; |
| - a `### carlos instances set-pages` section; |
| - the `CARLOS_PURGE` row (:1186); |
| - `docs/site/rootfs.md:46` if needed. |