| index 051d82933..80bb63cdc 100644 |
| --- a/docs/superpowers/specs/2026-11-08-edge-page-cache-design.md |
| +++ b/docs/superpowers/specs/2026-11-08-edge-page-cache-design.md |
| @@ -1,9 +1,11 @@ |
| # Edge page cache: design |
| |
| -Status: draft rev 1, 2026-11-08. Branch `design-edge-page-cache`. |
| +Status: draft rev 2, 2026-11-08. Branch `design-edge-page-cache`. |
| Builds on the edge asset cache (`2026-10-24-edge-asset-cache-design.md`, |
| merged and armed on dev and flagship) and on today's `Carlos-Purge` |
| channel (`internal/edge/purge_header.go`, `internal/edge/purge.go`). |
| +Review history is in §16. Marks like **(astra R1-3)** point at the finding |
| +a passage answers. |
| |
| ## 1. Why |
| |
| @@ -35,6 +37,12 @@ could switch to this and drop its own workarounds (§13). |
| - On how fast a clear must reach a far reader: "Ideally low seconds if |
| not instant." |
| |
| +**Words used here.** An *instance* is one deployed copy of an app, with |
| +its own record, route and hosts (what `carlos assets purge --app` walks |
| +over). The *home* is the box whose route table serves the instance |
| +directly. Clear state, leases and switches are all per instance |
| +**(astra R1 builder Q3)**. |
| + |
| ## 2. What exists today |
| |
| Facts the design leans on. File references are to `main` at 06bb3f7e. |
| @@ -43,14 +51,18 @@ Facts the design leans on. File references are to `main` at 06bb3f7e. |
| (`internal/edge/cache.go`). It holds 4096 entries of up to 1 MiB each, |
| and every lifetime is cut to `DefaultCacheMaxTTL`, 5 minutes |
| (`edge.go:82-88`). Five minutes is there because a purge only reaches |
| - the box that saw it, so a lost purge must heal itself quickly. A |
| - response is stored when it is 2xx with a positive `s-maxage` or |
| - `max-age`, has no `Set-Cookie`, and does not vary on `Cookie` or `*` |
| - (`maybeStore`, `edge.go:2879-2970`). The request's own `Cookie` header |
| - is not checked. The lookup sits after the plan throttle and before the |
| - rate limit and the activator (`edge.go:2673-2690`), so a hit never |
| - wakes the app. Far edges never use it: they backhaul before reaching |
| - it. |
| + the box that saw it, so a lost purge must heal itself quickly. |
| + - **What it stores:** a response that is 2xx with a positive |
| + `s-maxage` or `max-age`, has no `Set-Cookie`, and does not vary on |
| + `Cookie` or `*` (`maybeStore`, `edge.go:2879-2970`). |
| + - **What it doesn't check:** the request's own `Cookie` header. It |
| + allows a request with `Authorization` when the response says |
| + `public`. |
| + - **Where the lookup sits:** after the password gate |
| + (`edge.go:2498-2505`) and the plan throttle, and before the rate |
| + limit and the activator (`edge.go:2673-2690`). A hit never wakes the |
| + app. |
| + - **Far edges** never use it: they backhaul before reaching it. |
| - **The purge channel.** |
| - **Header.** The app sends `Carlos-Purge: <targets>` on any response: |
| - `*` clears the host; |
| @@ -64,25 +76,38 @@ Facts the design leans on. File references are to `main` at 06bb3f7e. |
| unit-backed (DynamicUser) instance has no socket (`purge.go:115-125`). |
| - **Reach.** Both channels act on the local LRU only. Nothing forwards |
| a purge to another box. |
| + - **A known race.** A response in flight while a purge runs can |
| + resurrect what the purge removed (`purge_header.go:266`). |
| - **The edge asset cache** keeps immutable, declared-prefix, non-HTML |
| - responses in a disk store (`internal/assetcache`): a budget, a per-app |
| - share, eviction, reserved fills and gzip at serve time. Far edges |
| - catch a declared path, ask the home for it with a signed fill |
| - (`X-Carlos-Asset-Fill`, HMAC under the mesh key, `assetfill.go`), and |
| - store only what the home acknowledges (`X-Carlos-Asset-Fill-Ack`). |
| - Purge is a per-instance generation in the key, written to the record, |
| - and reaches far edges through the 30-second home-map poll: "within a |
| - minute" (`homemap.go:124`, asset spec §6). HTML is refused |
| - (`assetadmit.go:95`). |
| + responses in a disk store (`internal/assetcache`). The store has a |
| + budget, a per-app share, eviction, reserved fills, and gzip at serve |
| + time. |
| + - **Fills.** Far edges catch a declared path and ask the home for it |
| + with a signed fill (`X-Carlos-Asset-Fill`, HMAC under the mesh key). |
| + They store only what the home acknowledges. The acknowledgement |
| + MACs the original assertion (`assetfill.go:120`). |
| + - **Which hosts may serve.** The home decides with one predicate, |
| + `assetPolicy.decide` (`internal/host/assetpolicy.go:291-320`). It |
| + refuses: |
| + - a row that isn't ready, or is a sidecar; |
| + - the record's opt-out; |
| + - a password gate or an import gate; |
| + - hostnames with path rows; |
| + - a throttled or lapsed account. |
| + - **Purge.** A per-instance generation in the key, written to the |
| + record. It reaches far edges through the 30-second home-map poll, |
| + "within a minute" (`homemap.go:124`, asset spec §6). |
| + - **HTML is refused** (`assetadmit.go:95`). |
| - **Box-to-box push exists once:** probe-burst notices, |
| `POST /.carlos/burst-notice`, sealed with AES-GCM under an HKDF of the |
| - mesh key. They go over `backhaulTransport` with a bounded queue per |
| - peer, and a notice not sent within 10 s is dropped |
| - (`burst_notice.go`). Everything else between boxes is pulled from the |
| - bucket. |
| + mesh key. Each one is receiver-bound and replay-checked, with bounded |
| + reads and acceptance limits (`burst_notice.go:444-520`). Everything |
| + else between boxes is pulled from the bucket. |
| - **Several boxes can serve one app.** |
| - - **Region HA:** a request that reaches a non-holder is forwarded to |
| - the lease holder before the cache (`forwardha.go`). |
| + - **Region HA.** A request that reaches a non-holder is forwarded to |
| + the holder before the cache, except for verified hops, door calls |
| + and tunnel deliveries (`forwardha.go:175-180`). A hibernating |
| + holder releases its serving lease (`activator.go:5253`). |
| - **Stateless replicas and managed fleets** use forward rows, which |
| the hub never caches (`edge.go:2663-2675`). |
| |
| @@ -94,32 +119,47 @@ Facts the design leans on. File references are to `main` at 06bb3f7e. |
| - G2. A cached page lasts as long as the app's `Cache-Control` says, up |
| to a year. No 5-minute ceiling for opted-in pages. |
| - G3. Clear one page, a list of pages, one host, or every host of the |
| - app, from a response header, from the control socket, or from the CLI. |
| -- G4. Once a clear reaches the home box, no edge serves a page it covers |
| - more than L seconds later (§8, invariant I1). L is a few seconds. In |
| + instance, from a response header, from the control socket, or from |
| + the CLI. |
| +- G4. Once a clear reaches the home, no edge serves a page it covers |
| + more than L seconds later (§8.4, invariant I1). L is a few seconds. In |
| the usual case the clear lands on every edge in well under a second. |
| - G5. Far boxes serve cached pages to readers near them, without waking |
| the app and without new S3 requests. |
| -- G6. Requests from signed-in readers (cookies or `Authorization`) never |
| - read from or write to the cache. |
| -- G7. A new release of the app clears its pages automatically. |
| +- G6. Requests with a cookie the app hasn't declared harmless, or with |
| + `Authorization`, never read from or write to the page cache. A |
| + response marked for the page cache never enters the LRU (§5.3). |
| +- G7. A new release of the instance clears its pages automatically. |
| |
| **Non-goals (v1)** |
| -- Pages served through forward rows: stateless replicas, managed |
| - fleets and fleet public routes. The hub never caches these today, and |
| - this spec doesn't change that. |
| -- Variants other than `Accept-Encoding` (geo country, language |
| - headers). A response with any other `Vary` is not stored. |
| -- Caching statuses other than 200: no 404s and no redirects. |
| -- Giving unit-backed instances a control socket. Today they can clear |
| +- **Region HA routes** (`route.HA`): refused up front, so their pages |
| + are never page-cached **(astra R1-2)**. The serving authority moves |
| + between members, and a hibernating holder gives up its lease, so no |
| + box can vouch for an entry while the app sleeps. HA apps keep today's |
| + LRU. A follow-up can tie page authority to the HA lease once there is |
| + a use for it. |
| +- **Forward rows:** stateless replicas, managed fleets and fleet public |
| + routes. The hub never caches these today, and this spec doesn't change |
| + that. |
| +- **Hosts the asset policy refuses** (§2): password gates, import |
| + gates, path-routed hostnames, sidecars, and throttled or lapsed |
| + accounts **(astra R1-4)**. |
| +- **Variants** other than `Accept-Encoding`: no geo country, no |
| + language headers. A response with any other `Vary` is not stored. |
| +- **Statuses** other than 200: no 404s and no redirects. |
| +- **A control socket for unit-backed instances.** Today they can clear |
| only from a response header (§4.4). |
| -- Clearing the copies browsers keep. The edge can't reach them; §4.2 |
| - tells apps what to send. |
| -- Static sites (`kind:static`) and the asset cache keep their own rules. |
| +- **Browser copies.** The edge can't clear them; §4.2 tells apps what to |
| + send. |
| +- **Static sites and the asset cache** keep their own rules. |
| +- **The LRU's cookie gap** (§2) is older than this feature, and this |
| + design doesn't change unmarked responses. It goes on a follow-up |
| + discussion for the LRU's own owner. |
| |
| **Anti-goals** (failures even if everything else works) |
| - A reader sees a page drawn for someone else: a signed-in view, a paid |
| - member's view, or another account's page. |
| + member's view, a page behind a password gate, or another account's |
| + page. |
| - An author publishes, a reader reloads a few seconds later and sees the |
| old homepage, and nothing will ever fix it short of a manual clear. |
| - The edge keeps serving copies it can't vouch for while the home is |
| @@ -145,9 +185,13 @@ Cache-Control: public, s-maxage=31536000, max-age=0 |
| - **Lifetime.** `s-maxage`, else `max-age`. It must be positive and is |
| capped at 365 days. `private`, `no-store` and `no-cache` refuse. |
| - **Ignorable cookies.** An optional parameter names cookies that don't |
| - change the page, such as a consent cookie: |
| - `Carlos-Page-Cache: on; ignore-cookies="consent"`. A request whose |
| - cookies are all on that list still counts as anonymous (§5.1). |
| + change this page, such as a consent cookie: |
| + `Carlos-Page-Cache: on; ignore-cookies="consent"`. |
| + - **Scope:** the list belongs to the stored entry only. It is not a |
| + host-wide policy, and no box learns or carries it from one entry to |
| + another **(astra R1 builder Q2)**. |
| + - **Effect:** it lets a request carrying only those cookies *hit* |
| + that entry (§5.1). |
| - **Exact syntax.** The plan settles the syntax, with copy review. The |
| two parts, the marker and an ignore list, are fixed. |
| |
| @@ -176,20 +220,20 @@ on repeat views. |
| - **Targets** keep today's meaning: `*` for the host, a path for every |
| query under it, `path?query` for one URL. `Carlos-Purge-Host` keeps |
| today's rules. |
| -- **New: an app-wide clear.** One target clears every host the app |
| - serves on that box: its own host, aliases and custom domains. Today |
| - the socket's `*` can't reach aliases (`purge.go:38-41`). The plan |
| - names the token and the socket field. A bare word is unambiguous |
| - because path targets must start with `/`. |
| +- **New: an instance-wide clear.** One target clears every host the |
| + instance serves: its own host, aliases and custom domains. Today the |
| + socket's `*` can't reach aliases (`purge.go:38-41`). The plan names |
| + the token and the socket field. A bare word is unambiguous because |
| + path targets must start with `/`. |
| - **Channels:** the response header, the control socket, and a CLI and |
| - console door (`carlos pages clear --app shop [--path /p]`, name to |
| - copy review). The CLI is for operators and agents working from |
| - outside the app. |
| -- **What a clear touches:** on the home box, it clears the page store |
| - and the LRU (as today), then reaches far boxes (§8). A clear that |
| - arrives on a response applies before that response is considered for |
| - storing, as today. |
| -- **What doesn't change:** the LRU's behaviour for unmarked responses. |
| + console door. The CLI is |
| + `carlos pages clear --app shop [--instance …] [--path /p]`, with names |
| + to copy review, for operators and agents working from outside the |
| + app. |
| +- **What a clear touches:** on the home it clears the page store and the |
| + LRU (as today), then reaches far boxes (§8). A clear that arrives on a |
| + response applies before that response is considered for storing, as |
| + today. |
| |
| ### 4.4 What the app must still do |
| |
| @@ -202,32 +246,44 @@ approval all arrive as admin POSTs whose responses can carry the clear. |
| |
| ## 5. What is kept, and when |
| |
| -### 5.1 Which requests may use the cache |
| +### 5.1 Which requests may use the page cache |
| + |
| +**Host eligibility.** The host must pass the page predicate, which is the |
| +asset policy's host predicate (`assetPolicy.decide`) with two changes: |
| +- the page switch replaces the assets opt-out and generation; |
| +- it adds: the route is not HA and not a forward row. |
| |
| -A request may read from or be stored into the page cache only when all |
| -of these hold: |
| +The home evaluates the predicate: |
| +- for every home hit; |
| +- for every fill it acknowledges; |
| +- for every host it lists in a lease answer. |
| |
| +So a policy change takes effect on the home at once, and on far boxes at |
| +their next renewal **(astra R1-4)**. |
| + |
| +**Request eligibility.** A request may read from the page store only when |
| +all of these hold: |
| - it is GET or HEAD, with no `Range`, not an upgrade, not a door call; |
| - it is not a request held for a stream (`carlos_hold`, as the LRU |
| already excludes); |
| -- the route is an instance route: not `static`, not `status`, not a |
| - forward row, no import gate; |
| - it carries no `Authorization` header; |
| - it carries no `Cookie` header, or every cookie name in it is on the |
| - ignore list the app declared for that host (§4.1); |
| + ignore list of the entry it would hit; |
| - the path is canonical (the asset cache's rule; anything else is |
| `bypass`). |
| |
| +A request may be *stored* (or fill) only when it carries no `Cookie` and |
| +no `Authorization` at all. A request with ignorable cookies can hit an |
| +entry, but never creates one. |
| + |
| A HEAD is answered from a stored GET and is never stored itself. |
| -Everything else is a bypass: forwarded as today, never stored. |
| |
| ### 5.2 Which responses are kept |
| |
| -A response is kept only when all of these hold: |
| - |
| +A response goes into the page store only when all of these hold: |
| - the response carries the marker; |
| - the status is 200; |
| -- the request was eligible (§5.1); |
| +- the request was storable (§5.1); |
| - there is no `Set-Cookie`, as a header or as a trailer; |
| - the lifetime is valid (§4.1); |
| - `Vary` is absent or exactly `Accept-Encoding`; |
| @@ -241,18 +297,31 @@ Pages are stored identity-encoded and compressed at serve time, as |
| assets are. The stored headers follow the asset cache's list. The |
| `Carlos-*` control headers are never stored or replayed. |
| |
| -### 5.3 The key and the entry |
| +### 5.3 The two caches never mix (astra R1-3) |
| + |
| +- A response that carries the marker never enters the LRU, whether or |
| + not the page store kept it, and whatever the request carried. A |
| + marked response the page store refused is simply not cached. |
| +- The page store is looked up before the LRU. A request the page store |
| + bypasses still reaches the LRU, which keeps today's rules for |
| + unmarked responses. |
| +- An instance whose page switch is on gets one more rule (my call): the |
| + LRU neither stores nor serves for a request that carries `Cookie` or |
| + `Authorization`. That closes the cookie gap from §2 for every app |
| + that opts in, without changing apps that don't. |
| + |
| +### 5.4 The key and the entry |
| |
| -- **Key:** account, app, host, path and raw query exactly as sent. No |
| - query normalisation in v1. |
| +- **Key:** account, app, instance, host, path and raw query exactly as |
| + sent. No query normalisation in v1. |
| - **Each entry also records:** |
| - - the serving home box and that box's clear epoch (§8); |
| - - the clear sequence at the time the page was rendered; |
| + - the home box and its clear epoch for the instance (§8); |
| + - the clear sequence the entry is valid at (§6); |
| - the absolute expiry; |
| - the ignore list; |
| - the `ETag`, if any. |
| |
| -### 5.4 Where it lives |
| +### 5.5 Where it lives |
| |
| Pages live in the asset cache's disk store (`internal/assetcache`). They |
| use the same budget, and each app's share covers its assets and its |
| @@ -263,121 +332,159 @@ instance whose page switch is on (§10). |
| |
| ## 6. Serving on the home box |
| |
| -At the point where the LRU lookup happens today (after the plan throttle, |
| -before the rate limit and the activator), an eligible request is looked |
| -up in the page store first. |
| - |
| -- **A hit** is a live entry whose epoch is this box's current epoch for |
| - the app. It is served with `Carlos-Cache: hit`. |
| -- **A miss** goes to the app as today. A response kept under §5.2 is |
| - stored in the page store, not the LRU. |
| -- **Storing races a clear.** Note the app's clear sequence when the |
| - request starts. Store the response only if no clear for the app |
| - happened before the response arrived. That check is coarse, but it |
| - can't keep a page rendered before a clear (Tito's page cache uses the |
| - same idea). |
| -- **Single-flight per key** (my call). A render that isn't kept (a 500, |
| - a redirect, a response without the marker) sends its waiters to the |
| +At the point where the LRU lookup happens today (after the password gate |
| +and the plan throttle, before the rate limit and the activator), an |
| +eligible request is looked up in the page store first. |
| + |
| +**A hit** is a live entry whose epoch is this box's current epoch for the |
| +instance, on a host the page predicate allows right now. It is served |
| +with `Carlos-Cache: hit`. |
| + |
| +A miss goes to the app as today. |
| + |
| +**Clears fence publication (astra R1-1).** Clearing and publishing take |
| +the same per-instance lock: |
| +- **Clearing:** under the lock, the box increments the sequence, |
| + records the clear in its log, removes the matching entries and |
| + rejects matching pending fills. |
| +- **Publishing:** writing the file happens outside the lock. Indexing |
| + it, the step that makes it servable, happens under the lock, and only |
| + if no clear since the render started matches the entry's key. A |
| + matching clear means the file is discarded and nothing is indexed. |
| + The store's existing compress, sync and rename steps |
| + (`assetcache/fill.go:474`) all sit before that check. |
| +- **Validity:** an entry indexed this way is valid at the sequence |
| + current when it was indexed. An entry still present later is valid at |
| + every later sequence, because any clear that matched it would have |
| + removed it under the same lock. |
| + |
| +**Single-flight per key** (my call): |
| +- **Who may join:** a request may join a render only if no clear |
| + matching the key has happened since that render started. Later |
| + requests start a new render. |
| +- **When nothing is kept:** a render that isn't kept (a 500, a |
| + redirect, no marker, or a clear fenced it) sends its waiters to the |
| app for themselves, never an error or an empty body. |
| |
| +**Losing authority.** When the instance's route leaves this box, or the |
| +page switch turns off, the box ends the epoch and drops the instance's |
| +entries **(astra R1-2)**. When the route arrives again, a new epoch |
| +starts with nothing in it. |
| + |
| ## 7. Serving on far boxes |
| |
| A far box today backhauls every request for a host homed elsewhere. With |
| page caching armed on the far box and the request eligible: |
| |
| -1. **A hit:** the far box has a live entry for the key, a valid lease |
| - for that home and app (§8), the home is still the home map's dial |
| - target for the host, and the host is in the lease's host set. It |
| - serves the entry with `Carlos-Cache: hit`. Neither the home nor the |
| - app is contacted, except for a background lease renewal (§8.3). |
| -2. **Otherwise it fills:** the far box sends the request to the home as |
| - a signed page fill. This is a normal signed hop plus an assertion, |
| - modelled on `X-Carlos-Asset-Fill`, in its own MAC domain |
| - (`carlos-page-fill-v1`). The assertion binds the host, path and |
| - query, the account, the app and the far box's lease epoch. The home |
| - runs its ordinary pipeline: page store, throttle, wake, app. |
| -3. **The home's acknowledgement.** If the response is kept under §5.2, |
| - the home stores it and answers with a signed acknowledgement in its |
| - own domain. The acknowledgement carries the expiry, the epoch, the |
| - sequence at render, the ignore list and the account and app from the |
| - home's own route table, not from the far box's claim. |
| -4. **What the far box stores.** It stores the response only if the |
| - acknowledgement's epoch and sequence equal its lease's current ones. |
| - Otherwise it serves the response once and doesn't store it. Account |
| - and app come from the acknowledgement. |
| -5. **Cookies on a fill.** The far box learns each host's ignore list |
| - from the acknowledgements, and keeps it in bounded memory. A request |
| - carrying only ignorable cookies may fill, with those cookies passed |
| - to the app unchanged, because the app declared they don't change the |
| - page. Until the far box knows a host's list, any cookie means a plain |
| - backhaul. |
| - |
| -Fill limits (waiters, deadlines, concurrency per box and per app) follow |
| -the asset cache's. Fills the home acknowledged are unbilled at the home, |
| -and the delivering edge meters them, as for assets. |
| +1. **A hit.** The far box serves the entry with `Carlos-Cache: hit` when |
| + all of these hold: |
| + - it has a live entry for the key; |
| + - its lease for that home and instance is valid (§8); |
| + - the home is still the home map's dial target for the host; |
| + - the host is in the lease's host list; |
| + - the home map's account and app for the host match the entry's. |
| + |
| + Neither the home nor the app is contacted, except for a background |
| + lease renewal (§8.3). |
| +2. **A fill.** Otherwise, if the request is storable (no cookies, no |
| + `Authorization`), the far box sends it to the home as a signed page |
| + fill. This is a normal signed hop plus an assertion, modelled on |
| + `X-Carlos-Asset-Fill`, in its own MAC domain (`carlos-page-fill-v1`). |
| + The assertion binds: |
| + - the host, path and query; |
| + - the account, app and instance; |
| + - the far box's lease epoch; |
| + - a nonce. |
| + |
| + The home runs its ordinary pipeline: the predicate, the page store, |
| + the throttle, the wake and the app. A request with cookies goes as a |
| + plain backhaul. |
| +3. **The home's acknowledgement.** The home acknowledges only an entry |
| + it holds valid under the §6 lock: a fresh render it just indexed, or |
| + a retained entry it still holds. The acknowledgement is signed in its |
| + own domain and MACs the assertion, as asset acks do. It carries: |
| + - the expiry and the epoch; |
| + - the **validated sequence**: the home's sequence when it read the |
| + entry under the lock; |
| + - the ignore list; |
| + - the account, app and instance from the home's own route table, not |
| + from the far box's claim. |
| +4. **What the far box stores (astra R1-5).** Let `a` be the |
| + acknowledgement's validated sequence and `f` the sequence the far |
| + box's lease has applied, on the same epoch: |
| + - **`a == f`:** store. |
| + - **`a < f`:** store only if no clear in `(a, f]`, from the far box's |
| + own copy of recent clears, matches the key. |
| + - **`a > f`:** serve this response once, don't store it, and renew the |
| + lease in the background. |
| + - **A different epoch:** serve once, don't store. |
| + |
| + Account, app and instance come from the acknowledgement. |
| + |
| +Fill limits (waiters, deadlines, concurrency per box and per instance) |
| +follow the asset cache's. Fills the home acknowledged are unbilled at the |
| +home, and the delivering edge meters them, as for assets. |
| |
| ## 8. Clearing across boxes |
| |
| ### 8.1 Epoch and sequence |
| |
| -For each app it serves as home, a box keeps a clear epoch and a clear |
| -sequence. |
| +For each instance it serves as home, a box keeps a clear epoch and a |
| +clear sequence. |
| - **Epoch:** a random 64-bit value, drawn when the box starts serving |
| - the app's route (process start, route arrival, or taking the HA |
| - lease). |
| + the instance's route (process start or route arrival). |
| - **Sequence:** starts at 0 and goes up by one for every clear of that |
| - app, whatever its target. |
| -- **Clear log:** the box keeps a bounded log of recent clears per app: |
| - the sequence, the hosts and the targets. The size is the builder's |
| - call. Something like the last 256 clears or 10 minutes, whichever |
| - holds less. |
| -- **Starting a new epoch:** the box drops its own page entries for that |
| - app. A box that wasn't serving the app can't know which clears it |
| - missed. |
| + instance, whatever its target. |
| +- **Clear log:** a bounded log of recent clears: the sequence, the |
| + hosts and the targets. The size is the builder's call. Something like |
| + the last 256 clears or 10 minutes, whichever holds less. |
| +- **Far boxes** keep the same bounded log per (home, instance) for what |
| + they've applied (§7 step 4). |
| +- **Starting a new epoch:** the box holds no entries for the instance |
| + (§6, losing authority). |
| |
| ### 8.2 Push |
| |
| -After applying a clear locally, the home pushes it to every far box that |
| -holds, or recently held, a lease for that app: renewed within L plus a |
| -small margin. The push is modelled on burst notices: |
| - |
| +After applying a clear locally, the home pushes it to every far box with |
| +a live or recent lease for the instance, renewed within L plus a small |
| +margin. The push is modelled on burst notices: |
| - `POST /.carlos/page-clear` over `backhaulTransport`; |
| - sealed and signed under an HKDF of the mesh key in its own domain; |
| - a bounded queue per peer; |
| - dropped if not sent within about 2 s. The lease covers a lost push. |
| |
| -The body carries the account, the app, the home box, the epoch, the |
| -sequence, and the hosts and targets. |
| +The body carries the destination box, the account, app and instance, the |
| +home box, the epoch, the sequence, and the hosts and targets. |
| |
| **On the far box:** |
| - **Next in order** (the next sequence on the same epoch): apply it. |
| -- **Any gap or a different epoch:** stop serving hits for that home and |
| - app until a lease renewal resolves it. |
| +- **Already applied:** ignore it. A replay is a no-op. |
| +- **A gap or a different epoch:** stop serving hits for that home and |
| + instance until a lease renewal resolves it. |
| |
| ### 8.3 Leases |
| |
| -A far box may serve a hit for (home box, app) only while it holds a |
| -lease. A lease is the home's answer to a signed renewal: |
| -`GET /.carlos/page-lease` on a hop, door-style. |
| +A far box may serve a hit for (home, instance) only while it holds a |
| +lease. A lease is the home's answer to a signed renewal, |
| +`GET /.carlos/page-lease`, sent on a hop, door-style. |
| |
| **The answer carries:** |
| - the epoch and the sequence; |
| - the clears after the far box's sequence, when the log still covers |
| them, or "reset" when it doesn't; |
| -- the hosts the app serves on that box; |
| -- whether page serving is allowed for the app. |
| - |
| -Allowed is false when the instance's switch is off, the host is lapsed |
| -or throttled (the asset cache's parity rule), or the box no longer |
| -serves the app. |
| +- the hosts of the instance that pass the page predicate right now. An |
| + instance with none is "not allowed". |
| |
| **How the far box applies it:** |
| - a different epoch or "reset" drops every entry it holds for that home |
| - and app; |
| -- otherwise it applies the missing clears. |
| + and instance; |
| +- otherwise it applies the missing clears; |
| +- a host missing from the list drops that host's entries. |
| |
| **The lease lasts L seconds,** measured on the far box's monotonic clock |
| -from when it **sent** the renewal, not when the answer arrived. |
| +from when it **sent** the renewal, not when the answer arrived. It accepts |
| +only an answer that matches its one outstanding renewal for that home |
| +and instance (§8.5). |
| - **Default:** L = 5 s (my call). The builder may tune it between 2 and |
| 10, and the plan states the number. |
| - **Renewing:** a hit that finds the lease expired waits on a |
| @@ -385,12 +492,13 @@ from when it **sent** the renewal, not when the answer arrived. |
| renewal fails, the request goes as a plain backhaul and nothing is |
| served from the cache. A hit that finds less than half the lease left |
| renews in the background. |
| -- **Cost:** about one renewal per far box per app every L/2 seconds |
| +- **Cost:** about one renewal per far box per instance every L/2 seconds |
| while readers are arriving, and nothing when the box is quiet. All of |
| it is box-to-box, with no S3 requests. The app is never woken for a |
| renewal. |
| -- **Push targets:** the home records which far boxes renewed recently. |
| - That record is the push list for §8.2. |
| +- **Push targets:** the home records which far boxes renewed recently, |
| + in a table bounded by the boxes in the mesh. That record is the push |
| + list for §8.2. |
| |
| ### 8.4 The bound |
| |
| @@ -398,55 +506,81 @@ from when it **sent** the renewal, not when the answer arrived. |
| serves a page it covers after t + L. In-flight responses already being |
| written are the only exception. |
| |
| -- **Why it holds:** any lease the far box sent before t either includes |
| - the clear (the home answered after t), or expires by |
| - `sent + L < t + L`. Any lease sent after t includes the clear. |
| -- **What the push adds:** it makes the usual case far faster. The bound |
| - doesn't depend on it. |
| -- **The home's own store:** it applies the clear synchronously, before |
| - the clear is acknowledged to the app (header or socket). |
| - |
| -### 8.5 A new release |
| - |
| -When the app's build or its delivered configuration changes on the home, |
| -the home performs an app-wide clear as part of switching to the new |
| -route. The plan names the exact signal; the config receipts work (#522) |
| -may already provide one. A hibernation wake is not a change, and must |
| -not clear. |
| +**Why it holds:** |
| +- **On the home:** the clear and publication share a lock (§6), so no |
| + entry it covers is servable there after t. |
| +- **On a far box:** any renewal sent before t either was answered after |
| + t, and so carries the clear, or expires by `sent + L < t + L`. Any |
| + renewal sent after t carries the clear. |
| +- **Fills:** a far box stores a fill only when its sequences show the |
| + clear can't apply (§7 step 4). |
| +- **The push** makes the usual case far faster. The bound doesn't depend |
| + on it. |
| + |
| +### 8.5 Message rules (astra R1-6) |
| + |
| +Every new message inherits the asset fill's and burst notice's |
| +protections and adds these: |
| + |
| +- **Fill acknowledgement:** MACs the whole assertion (including its |
| + nonce), as `assetfill.go:120` does, so it authorizes storing exactly |
| + the URL the far box asked for. |
| +- **Lease renewal:** carries the sender box, the home box, the account, |
| + app and instance, a fresh nonce and a timestamp. The answer is MACed |
| + over the request and its nonce. |
| + - The far box keeps at most one outstanding renewal per (home, |
| + instance), and accepts only the answer to it. |
| + - The lease runs from that request's send time. An old answer, or one |
| + for another box, is refused. |
| +- **Clear push:** receiver-bound (it names the destination box), and |
| + ordered by (epoch, sequence), which makes replays no-ops. |
| +- **Receivers:** bound body size, reading time and acceptance rate, as |
| + burst notices do. |
| +- **Home state:** the lease-holder table and the far boxes' clear logs |
| + are bounded by mesh membership, the number of instances and the log |
| + size. |
| +- **Numbers:** left to the builder. |
| + |
| +### 8.6 A new release |
| + |
| +When the instance's build or its delivered configuration changes on the |
| +home, the home performs an instance-wide clear as part of switching to |
| +the new route. The plan names the exact signal; the config receipts work |
| +(#522) may already provide one. A hibernation wake is not a change, and |
| +must not clear. |
| |
| ## 9. More than one box serving the app |
| |
| -- **Region HA.** Only the lease holder renders and serves the app, and |
| - other members forward to it before the cache. The holder is the home |
| - for page purposes. When the holder changes: |
| - - the new holder starts a new epoch and drops any page entries it |
| - kept from an earlier term; |
| - - far boxes see a different home in the home map, or get "no longer |
| - serving" from the old one, so their old entries stop being served |
| - and age out. |
| -- **Moves.** Same as an HA holder change: new box, new epoch. |
| +- **Region HA:** out of v1 (§3). The page predicate refuses HA routes, |
| + so neither home hits nor leases exist for them. |
| +- **Moves:** the old home's route leaves, so its epoch ends and its |
| + entries go (§6). Its lease answers stop listing the hosts, and far |
| + boxes drop them. The new home starts a new epoch. A plain backhaul |
| + that still reaches the old box finds no entry to serve, because the |
| + entries are gone. |
| - **Forward rows** (stateless replicas, fleets) are not cached (§3). |
| |
| ## 10. Switches, tenancy and metering |
| |
| - **Box arming.** `CARLOS_PAGE_CACHE=1` in host.env, armed home first, |
| then far boxes, as for assets. A box that isn't armed treats the |
| - marker as absent and strips it. |
| + marker as absent and strips it (§5.3 still applies: a marked response |
| + never enters the LRU). |
| - **Instance switch.** An off switch on the instance record, the asset |
| - cache's R1 parity (`carlos pages off|on --app`, names to copy review). |
| - Off means: |
| - - the home drops the app's page entries and starts a new epoch; |
| - - every lease answer says not allowed. |
| - It is the operator's tool when an app caches something it shouldn't. |
| -- **Tenancy.** Entries are keyed by the account and app from the home's |
| - route table. A far hit also needs the home map's current account and |
| - app for the host to match the entry's. No field the far box asserts |
| + cache's R1 parity (`carlos pages off|on`, names to copy review). Off |
| + means: |
| + - the home ends the epoch and drops the instance's entries (§6); |
| + - lease answers list no hosts. |
| + It is per instance: other instances of the same app keep theirs. It is |
| + the operator's tool when an app caches something it shouldn't. |
| +- **Tenancy.** Entries are keyed by the account, app and instance from |
| + the home's route table. A far hit also needs the home map's current |
| + account and app for the host to match. No field the far box asserts |
| is trusted for ownership. |
| -- **Plan throttle, lapse and protection.** |
| - - Home hits come after the plan throttle, as LRU hits do today. |
| - - Far hits stop when the lease says not allowed. |
| - - Far hits pass the far edge's request protection the same way asset |
| - hits do. The builder confirms the order. |
| +- **Plan throttle, lapse, password gate.** These are part of the page |
| + predicate (§5.1). Home hits come after the gate and the throttle, as |
| + LRU hits do today. Far hits pass the far edge's request protection |
| + the same way asset hits do; the builder confirms the order. |
| - **Metering.** Page bytes count as usage like any response (asset |
| cache ruling R2). The delivering edge meters hits. Whatever the edge |
| records for a request (usage, analytics, logs), it records for a page |
| @@ -454,9 +588,9 @@ not clear. |
| builder checks that edge analytics count hits. |
| - **Visibility.** `Carlos-Cache: hit|miss|bypass` on every eligible |
| response, using the asset cache's header and words. A |
| - `carlos pages status --app` shows, per home box: |
| + `carlos pages status --app` shows, per instance: |
| - armed or not; |
| - - the instance switch; |
| + - the switch; |
| - the entry count and bytes; |
| - the epoch and sequence. |
| Its contents are the builder's call, and its copy goes to review. |
| @@ -466,15 +600,16 @@ not clear. |
| Each slice changes something Paul can see (stopping rule 6). |
| |
| 1. **Home box.** |
| - - **Built:** the marker, the page store on the home, the clear epoch |
| - and sequence, the app-wide clear, clear on a new release, the |
| - instance switch and `Carlos-Cache` on pages. |
| + - **Built:** the marker, the page predicate, the page store on the |
| + home with the clear lock, the epoch and sequence, the |
| + instance-wide clear, clear on a new release, the instance switch, |
| + the §5.3 rules and `Carlos-Cache` on pages. |
| - **Rollout:** armed on dev. |
| - **Patrix:** sends the header (in its own repo), and repeat views |
| are served without waking it. |
| 2. **Far boxes.** |
| - - **Built:** page fills, leases, push and catch-up, plus the |
| - randomized simulation (§12). |
| + - **Built:** page fills, leases, push and catch-up, the message rules, |
| + and the randomized simulation (§12). |
| - **Rollout:** armed on dev far boxes. |
| - **Check:** a reader through a far box gets hits, and a clear lands |
| there within L. |
| @@ -484,28 +619,37 @@ Each slice changes something Paul can see (stopping rule 6). |
| |
| ## 12. How we know it works |
| |
| -- **A randomized simulation** of homes, far boxes, clears, renewals and |
| - pushes, with lost, delayed and reordered pushes, box restarts, holder |
| - changes and clock skew between boxes. It checks: |
| +- **A randomized simulation** of homes, far boxes, clears, renders, |
| + fills, renewals and pushes. It runs with lost, delayed, duplicated |
| + and reordered pushes, renders that straddle clears, box restarts, |
| + moves, switch and predicate flips, and clock skew between boxes. It |
| + checks: |
| - **I1:** nothing covered by a clear is served after t + L; |
| - - **I2:** nothing stored from a request that carried a cookie that |
| - wasn't ignorable, or an `Authorization` header, is ever served; |
| - - **I3:** a hit is never served under a different account, app or |
| - host than the one the home stored it for. |
| + - **I2:** nothing stored from a request that carried a cookie or an |
| + `Authorization` header is ever served, by either cache, for an |
| + instance with the switch on; |
| + - **I3:** a hit is never served under a different account, app, |
| + instance or host than the home stored it for, nor for a host the |
| + predicate refuses at the last renewal. |
| This follows the rule to check invariants with simulations rather than |
| fix examples one at a time. |
| - **An end-to-end test through the real edge wiring:** |
| - fill, hit, clear and miss on home and far; |
| + - a render that straddles a clear is never indexed; |
| - HEAD from a stored GET; |
| - a 500 never stored; |
| - - a signed-in request never served from or stored into the cache; |
| + - a cookie-bearing request never served from or stored into either |
| + cache; |
| + - enabling a password gate stops far hits by the next renewal; |
| - a clear on the response that carried it; |
| - a new release clearing. |
| - **Fences** (each watched failing under its own mutation): |
| - a page without the marker still goes to the LRU with the 5-minute |
| ceiling; |
| + - a marked response never enters the LRU; |
| - the marker and the internal headers never reach a visitor; |
| - - a far box with an expired lease forwards. |
| + - a far box with an expired lease forwards; |
| + - an HA route is never page-cached. |
| |
| ## 13. Reference: what an existing app learned |
| |
| @@ -531,7 +675,7 @@ takes: |
| - **Pages that change on a schedule** expire at the next scheduled |
| change. Hence §4.2. |
| - **Racing stores** use per-scope clear sequences to refuse stores that |
| - started before a clear. Hence §6 and §7 step 4. |
| + started before a clear. Hence §6. |
| - **HEAD and failed renders:** a HEAD is never stored, and a failed |
| render never hands its waiters an error. Hence §6. |
| |
| @@ -543,28 +687,55 @@ existing purge calls. |
| These are mine, not Paul's. They are listed so they can be checked. |
| |
| - An explicit marker header rather than reading `s-maxage` alone (§4.1). |
| -- Any cookie bypasses unless the app declares it ignorable; the ignore |
| - list rides the marker (§4.1, §5.1). |
| -- 200 only; `Vary` only `Accept-Encoding`; an 8 MiB body cap (§5.2). |
| -- Pages share the asset store and each app's share (§5.4). |
| -- The lease (L = 5 s, measured from send) is what guarantees the bound; |
| +- **Cookies:** any cookie bypasses unless the entry declares it |
| + ignorable. The list belongs to each entry, and only cookieless |
| + requests create entries (§4.1, §5.1). |
| +- **Responses:** 200 only; `Vary` only `Accept-Encoding`; an 8 MiB body |
| + cap (§5.2). |
| +- **LRU:** a marked response never enters it. For opted-in instances, |
| + it also skips cookie and `Authorization` requests (§5.3). |
| +- **Storage:** pages share the asset store and each app's share (§5.5). |
| +- **Leases:** L = 5 s, measured from send, is what guarantees the bound; |
| the push only makes the usual case fast. The far box fails closed |
| when the home is unreachable (§8). |
| -- Clears are a per-home epoch and sequence with a bounded log, not a |
| - generation in the record. The record route takes a 30 s poll, too |
| - slow for G4 (§8.1). |
| -- A new release clears the app's pages; a wake does not (§8.5). |
| -- Forward rows, other variants, non-200 statuses, and a socket for |
| - unit instances are out of v1 (§3). |
| -- An `If-None-Match` hit answers 304 (§4.2). |
| +- **Clear state:** a per-home, per-instance epoch and sequence with a |
| + bounded log, not a generation in the record. The record route takes a |
| + 30 s poll, too slow for G4 (§8.1). |
| +- **Releases:** a new release clears the instance's pages; a wake does |
| + not (§8.6). |
| +- **Region HA routes** are refused in v1 (§3, §9). |
| +- **Also out of v1:** forward rows, other variants, non-200 statuses, |
| + and a socket for unit instances (§3). |
| +- **Conditional requests:** an `If-None-Match` hit answers 304 (§4.2). |
| |
| ## 15. Left to the builder |
| |
| - Exact header, token, socket-field and CLI names, through copy review. |
| -- The clear log's size, the push margin, and L within 2-10 s. |
| +- The clear log's size, the push margin, the message limits, and L |
| + within 2-10 s. |
| - Eviction order between pages and assets inside an app's share. |
| - How the console reaches the home box for a CLI clear: a door call is |
| preferred. Whatever the route, the clear must reach the box within |
| seconds. |
| -- The signal for "new release" (§8.5). |
| +- The signal for "new release" (§8.6). |
| - The contents of `carlos pages status`. |
| + |
| +## 16. Review history |
| + |
| +**Round 1** (Astra, `CODEX-FINDINGS-PAGE-CACHE-R1.md`, rev 1 at 82e62c09). |
| +NOT READY: four P1s and two P2s, each in a different fault family. All |
| +were accepted: |
| + |
| +| Finding | Fault family | Resolution | |
| +|---|---|---| |
| +| **R1-1 (P1)** | I1, a clear must fence pending publications | §6: clears and publications share a per-instance lock, and joining a render after a clear is refused | |
| +| **R1-2 (P1)** | I1, cached responses must not bypass ownership | §3, §9: HA routes refused in v1. §6: a home that loses the route or the switch ends the epoch | |
| +| **R1-3 (P1)** | I2, no second shared-cache path | §5.3: marked responses never enter the LRU, and opted-in instances' LRU skips cookie and `Authorization` requests | |
| +| **R1-4 (P1)** | Access control on far hits | §5.1: one page predicate built on the asset policy's, checked for home hits, acknowledgements and every lease answer | |
| +| **R1-5 (P2)** | Refilling unaffected entries | §7 step 4: the validated sequence, plus the far box's own clear log | |
| +| **R1-6 (P2)** | Mesh trust | §8.5 | |
| + |
| +**Builder questions:** |
| +- **Q1 (HA while sleeping):** settled by refusing HA routes in v1. |
| +- **Q2 (cookie list scope):** settled as per entry, with no learning. |
| +- **Q3 (switch scope):** settled as per instance throughout. |