Repository navigation
Carry a leaf.page visitor's page across deploys - #6484
Conversation
For the minutes after a deploy that Cloudflare rolls the container image, a new release's session can start a container on the previous image. Leaf carried four mechanisms for that window: containers stamped their release on every answer, the Worker replaced a foreign one with the published state or a 503 with Retry-After (`rollingOut`), the browser probed the document source before reloading on a foreign release, and a sample's allocation retried through the 503 for up to ten minutes, announcing a `waiting` notice that released the page's presentation. Now only the edge names a release. The Worker stamps its own on every answer it passes on from a container, samples included, and containers stamp none. A foreign release can then only mean the edge has moved past the document, so the browser reloads at once. The page store keeps refusing a container on another release, and that refusal now ends the container's start instead of letting it serve without the session's record. So nothing a previous image reads or writes reaches the new release's Durable Object, whatever changed between the two formats. Removed: `rollingOut` and its check, `clearActiveCookie`, the container's `Leaf-Release` stamp, the restore's 409 branch (`FOREIGN_RELEASE`, `page_restore_refused`), `RequestError.retryAfter`, the sample's rollout retry (`ROLLOUT_MS`) and its `waiting` notice in `sample.js` and `lf-sample.js`, the release lines in `sourceMovedOn`, the deploy gate's `STILL_STARTING` reading of the 503, and `rollout_active_grace_period = 0`, which Wrangler defaults to. The Worker's `http_error` records now tell Python's answers by `Leaf-Session`. Startup recovery (`bootstrap.js`) is unchanged: a tab whose release's assets are gone still asks for one new document. What a visitor sees, measured against the website adapter in Chromium with routes standing in for the Worker: - A tab opened before a deploy, once answers name the new release: one reload, 0.6 s after the next state read, with no probe before it; 2 documents in 10 s. - A visitor who comments while their container is on the previous image, with every container request answering the SDK's 500 for 13 s: the message shows "Queued for Agent", the field says "Not through yet — trying again…", the send repeats every 2 s, no reload, and the comment is in the log 2 s after the window. - The adapter process on release A against a store on release B exits with `PageStoreRefused: /records answered 409` before serving; the store answered no restore. - Without the store's refusal, an image on A saves a document naming `data-lf-release` A and loading `/_leaf-release/A/...` into the session. Served back with the edge's B on every answer, that page reloaded 41 times in 15 s. That is why the refusal stays. A reload during the window now shows the Containers SDK's 500 page, where the edge used to serve the published projection. Tests: `pnpm run check` (worker 92, runtime 1065), `tests/process/website_server` (97), `dev/tests/process/test_website_server.py` (29), and the browser tests that touch samples, the event 503 and the layer probe (15). Removed tests covered only the deleted mechanisms: the Worker's rollout answers, `request-wait.test.mjs`, and the four sample-through-a-rollout browser tests.
The Worker set a page's active cookie on any answer passed on from a container, the Containers SDK's own 500 included. A visitor whose container exited while starting, as previous-image containers do during a rollout, was then pinned to it: every later read went to the dead container until the rollout replaced it. That is how the 2026-11-18 17:05 PT report on /how-it-works kept failing. Only Python's answers name a session, so the cookie now waits for one.
…ark a session active A tab now checks an answer's release before its layer. A new release's answer can name a new layer too, and the layer check asks this release's registry, which is gone once the edge has moved on, so the tab used to keep refusing answers after the rollout until the visitor reloaded by hand. The Worker no longer stamps Leaf-Session: active on what it passes on from a container. Python names its session on every answer, so the Containers SDK's own 500 for a container that never answered now names none, and the browser stays passive as the cookie already did. The Worker tests that asserted the stamp on mocks without Python's header drop that assertion; Python's header is asserted in tests/process/website_server/test_routes.py. Both found by a Codex review of the branch. Co-Authored-By: Claude <[email protected]>
…ssive The Containers SDK's 500 no longer marks a session active, so a reload during a rollout loads the published document rather than showing an error. What a visitor can see is the unsent gesture and a live sample that fails until Reset. Co-Authored-By: Claude <[email protected]>
A visitor's private record and container were named after the release, so each deploy pointed every visitor at an empty record that started from the published page: their comments, choices, agent thread and revisions stayed behind in a record nothing read again. In the week to 18 November deploys came a median of 28 minutes apart (194 in 6.9 days), a 30-minute visit spanned one 46% of the time, and both real browsers that added anything to a page lost it within 25 minutes. The maintainer chose to carry the page across deploys, reversing #717's rule that a release never reads another release's records. The session's Durable Object and its active cookie are now keyed by the page protocol, the manifest's new `protocol`, so a record lasts until the protocol moves, as a local page lasts across Leaf updates at one protocol. The record is the page's whole directory, every revision it reads included. Before, it left out the revisions the release published, which the image supplied, and the site build re-initializes every page, so the next release's revision 1 is another file: restoring a record over it read the visitor's log against revisions they never saw. Restore now replaces the image's revisions too. The manifest names the revision files each release publishes (`revisions`), and only those load their resources from the release's assets; a revision an earlier release published is served by the container, like one the session wrote. Three things keep the previous release from reaching a visitor through the carried record: - The store keeps the release beside each committed page and serves its saved responses only to that release, since a saved document names its release's assets. Under a new release the request wakes the container, which serves the page on its own runtime and saves it again at its next commit. - The object records the release whose Worker started its container (`onStart`) and destroys a container an earlier release started before forwarding to it. - The store's 409 for a container on another image stays, so a previous image starting during the rollout still fails before it reads or writes the record. A restore skips the record of a page the new release no longer publishes, which would otherwise end the container's start for every page the session holds. Tests: a store test that a record outlives a release while its responses serve only the release that captured them; a session-object test that a container an earlier release started is destroyed before a request reaches it; a restore test that a page saved under one release keeps its own first revision and comment under the next, whose image publishes a different first revision (it fails on the base, which restores the image's revision); a restore test for a dropped page; and the site journey asserts the manifest's `revisions` and `protocol`.
… active page's versions from its record An independent review found two cases the carry change got wrong. The release marker was written in `onStart`, which the Containers SDK calls only once the port is ready, while `container.running` is already true. A second request while this release's container started read the previous release's marker and destroyed it, as a prewarm followed by a Send would. The object now claims itself for the current release in its first request after a deploy, inside `blockConcurrencyWhile`: it destroys a running container only when the marker names another release, then writes the marker before any container starts, so requests that arrive meanwhile reach the starting container. `onStart` is gone. Only the live document bypassed the release's static assets for an active page. A version is named by its number, so a record an earlier release saved could show the new release's `versions/v1.html` instead of its own, whose state then came from the restored record and failed the browser's layer check. An active page's versions now go to its private record; revisions and media stay static, since their names are their content. Tests: the container test starts this release's container and sends a second request before it answers, which must reach it; the static-miss test now expects an active page's version to skip the static assets.
leaf-agent
left a comment
There was a problem hiding this comment.
Keying the session object by page protocol makes the object's own store a record that crosses releases, but nothing versions its format. Before this change, every deploy picked a fresh object, so PageStore's tables, the /records snapshot, and the publication and drafts shapes only had to agree within one release. Now an object created by one release is read and written by every later release at the same protocol. The protocol doesn't cover these shapes: src/leaf/layer-registry.md, "Page protocol", versions the event log, state.Records and the composer's draft, and build/browser/protocol-baseline.json never sees the Worker's SQLite tables or the z.strictObject schemas in worker/src/storage.ts.
This PR shows the failure it leaves for the next change. It adds a release column to leaf_pages. That works here only because the key changed too. A later PR that adds a column the same way runs CREATE TABLE IF NOT EXISTS against every visitor's existing object, which skips the existing table, and then INSERT INTO leaf_pages VALUES (?, 1, ?, ?, ?) throws. From then on, each save from a visitor who has acted on a page fails. The Worker tests build a fresh database, so neither they nor the site journey would report it. Root AGENTS.md asks for a guard where nothing in the agent's path would catch a break like this.
The cheapest fix I can see keeps the PR's design. Add a store-format constant to the key, ${protocol}.${STORE_FORMAT}:${sessionId}. State in the storage.ts header that it moves whenever the tables, the snapshot, or a stored schema changes shape, and that bumping it starts visitors on the published page, as a protocol bump does. The alternative is to bring the store under the page protocol and its baseline. That would make a website-only storage change bump the protocol for every local page, which seems the wrong trade. Either way, the rule needs a stated home before the next store change lands.
… earlier store Keying the session object by page protocol made its own store cross releases, but the protocol versions page files, not the object's SQLite tables, the encodings in their columns or its own keys. A later change that added a column the way this branch adds `release` would run `CREATE TABLE IF NOT EXISTS` over every visitor's existing table, skip it, and fail every save after, which no test with a fresh database would show (found by the leaf-agent review of #6484). The record scope is now `${protocol}.${STORE_FORMAT}`, for the object's key and the active cookie (`recordScope`). `storage.ts` states that any change to the store's shape moves `STORE_FORMAT`, which starts visitors on the published page as a protocol bump does; nothing migrates a store. A test pins each format to a digest of `STORE_TABLES`, so a table change that doesn't move the format fails in the agent's path. Bringing the store under the page protocol instead would bump the protocol for every local page over a website-only change.
…ploys # Conflicts: # docs/website.html # tests/process/website_server/test_saved_records.py # worker/src/index.ts # worker/src/routing.ts # worker/src/storage.ts
A deploy trial on leaf-website-dev carried a visitor's page across a release: their comment, the agent's reply and the agent's revision all came back under the new release. But the visitor's session object, kept busy by their reads, ran the previous Worker version for 4.5 minutes after the deploy (Workers Observability: object e11e9c2713 on version 171fd7ce until 23:34:26 PT, on the new version from 23:34:31; objects created after the deploy ran the new version from their first request). Cloudflare's default code update strategy lets an active object keep its code for up to 300 s. With the record keyed by page protocol, the new edge reaches that same object, which still holds the previous release's manifest: it made no release claim, and once the rollout replaced its container it answered from the previous release's saved responses while the edge stamped the new release. A tab compares the two and reloads, so an open tab would reload onto the previous release's page at every answer until the object restarted. A record per release never met this, since a new release named a new object. `code_update_strategy = immediate` resets an active object at the deploy, so it runs the deployed release's code, and the release claim stops the old container at the next request as before.
A deploy trial on leaf-website-dev, with an active visitor's triage-board tab open through the deploy, found the tab reloading in a loop once the new release answered: 2,666 reloads in five minutes, about ten a second, each loading the right document for the new release. The page's startup fetched its registry and held the answer's Leaf-Release header to the document's. The registry lives under the revision's assets path, which is named by the bytes served there and cached for a year, and a deploy that leaves the runtime and layer alone keeps that path. So the browser answered the registry from its cache, with the header the previous release had stamped, and every reload met the same stale header. Serving the live registry under the previous release's header reproduced it (12 reloads in 6 s on the dev site); a fresh tab, or a plain reload in one, didn't loop. The visitor's private record now outlives a deploy, so its tab keeps the same assets path across releases; a record per release reset the visitor onto the published page, whose assets path names the release. The registry now goes unadmitted. The initial state read, which the cache never answers, runs beside it and speaks for the server's release, runtime and session, and the registry's own `$layer` still decides its layer. The same trial showed the immediate code update working: the visitor's session object ran the new Worker version from 00:06:52 PT, a second after the deploy.
leaf-agent
left a comment
There was a problem hiding this comment.
The description becomes main's commit message, and it doesn't mention the last commit yet: the registry fetch no longer goes through admitResponse, because a cached revision asset carries the headers of the release it was cached from. The trial paragraph's "which the last commit fixes" also now points at the registry commit, not the code_update_strategy one. Worth a line before merging.
…ys give-up test (#6512) `test_a_document_the_runtime_gives_up_on_lets_its_held_keys_go` has failed deterministically since #6484. That PR stopped holding the registry fetch to its `Leaf-Layer` header, because a revision asset can come from the browser's cache with an earlier release's headers. Whether the runtime gives a document up now depends on the registry's own `$layer.generation` (`prepareDocument` in `browser/runtime/widget-loader.js`). The test still named the other layer only in a header, with a `{}` body. So startup threw `Cannot read properties of undefined (reading 'generation')`, and the floating panel stayed (`.lf-floating-panel` count 1, expected 0). The route now fetches the real registry and serves it with `$layer.generation` set to another layer. That is the reading #6484 left in charge, so the test reaches the give-up path again. What it protects is unchanged: the held keys are dropped, later presses reach the page, and the panel's row and the chrome's sheet go. No runtime code changes. Verification: the test fails on `main` (`2cd1bda49`) and on #6484 (`e81413d38`), and passes on #6484's parent (`152c83570`). With this change it passes on `main`, along with `test_a_page_that_cannot_start_lets_its_held_keys_go`. Refs #6418 — automated triage Co-authored-by: leaf-agent <[email protected]>
A leaf.page visitor's comments, choices, agent thread and revisions now survive a deploy. The Worker named each visitor's private record and container after the release, so every deploy pointed every visitor at an empty record that started from the published page. Deploys came a median of 28 minutes apart last week, and both real browsers that added anything to a page lost it within 25 minutes. The record is now keyed by the page protocol and the session store's own format (
${protocol}.${STORE_FORMAT}), so a deploy keeps it and only a bump of either starts a visitor fresh, as a local page lasts across Leaf updates at one protocol. A test pins each store format to a digest of its tables, so a table change that leaves the format alone fails.Making the record readable by the next release took these changes beyond the key:
revisions), and only those load from the release's static assets.versions/v1.htmlcan be another page than the visitor's.code_update_strategy = immediateinwrangler.toml). By default Cloudflare lets an object that keeps receiving requests run the previous Worker version for up to five minutes. Keyed by protocol, the new edge reaches that same object, which answers from the previous release's records while the edge names the new release, so an open tab would reload onto the old page at every answer.Leaf-Release, and each reload reloaded again. The initial state read, which the cache never answers, speaks for the server.Restoring also skips the record of a page that the new release dropped.
To weigh:
It builds on #6474, which has merged. The maintainer chose it on the Leaf page, reversing #717's rule that a release never reads another release's records. Codex reviewed it independently and found two cases, a container destroyed while it started and versions served from the static assets, which the second commit fixes; its review of the fix found nothing. The leaf-agent review asked for the store format in the key, which the third commit adds.
Trials on
leaf-website-devdeployed this branch five times with an active visitor, whose comment, agent reply and agent revision came back under each new release. They found the cases the last two bullets fix: the visitor's session object ran the previous Worker version for 4.5 minutes after a deploy (Workers Observability), and once the new release answered, their open tab reloaded about ten times a second until closed. With both fixes, the object ran the new version from a second after the deploy, and the tab reloaded once at each of two deploys, one that changed the runtime and one that didn't.Tests: a restore test in which a page saved under one release keeps its own revision 1 and comment under a release that publishes a different revision 1 (it fails on the base), a store test, a container test, manifest assertions in the site journey, and a runtime test in which a registry cached from the previous release leaves the page alone (it reloads on the parent commit).
pnpm run checkandtests/process/website_serverpass.