Repository navigation
Keep website documents at the edge - #717
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Two readings in the new startup record are wrong in reachable cases, which
undercuts the profile the record exists to produce. Both fixes are inline.
presentedMs drifts past presentation. The observer watches
childList/subtree over the whole document, so it keeps firing after
data-lf-presented lands, and each callback re-stamps presentedMs. report
runs a macrotask later — or waits for load, which images and fonts can hold
well past presentation — so every DOM batch in that window overwrites the
reading. Measured on a page that presents at 38 ms and then appends one element
per 10 ms tick, the record reports presentedMs: 443. scripts/verify_site.py
reads window.__leafVerifier.startupReading rather than the beacon, so the gate
cannot see the divergence.
rounded discards a legitimate zero. navigationType includes prerender,
where navigation timings from before activation are clamped to 0, so a
prerendered page records firstByteMs and serverMs as null —
indistinguishable from "not measured". Server-Timing: leaf;dur=0 is reachable
for an edge hit too, which drops exactly the fastest samples and biases any
serverMs reading upward. The schema's own nonnegative() already says 0
belongs in the record.
…hot flip's margin command, and a ring specimen behind a closed tab (#734) The nightly suite went red on main with 4 failures and 22 errors ([run 34960165078](https://github.com/max-sixty/leaf/actions/runs/34960165078)). Three durable causes account for 25 of those 26 nodes; the fourth was already repaired by #732, which merged 24 minutes after the run started. Each cause is one commit here. **The website adapter 404s the startup beacon.** #717 added the public startup report, handled it in `worker/src/index.ts`, and required it in `scripts/verify_site.py` — but `worker/server.py` never learned the route. Every released document posts to `<page>/api/performance`; the deployed site answers at the edge, and a site served straight from the adapter has no edge in front of it, so the POST fell through to the base handler's 404. That is a console error on every page the adapter serves, which is why one missing route reddened 23 nodes of the suite's clean-console reading. The adapter now answers 204 at its own boundary, the way `end_headers` already adds the `Leaf-Session` reading the Worker would have. **`lf-shot`'s margin entry lost the flip's name.** #716 replaced adopted source controls with immutable margin projections and deleted contributor-owned margin command rows, adding a `marginEntry` `scope` option to carry the declaration across to a control the margin generates. `lf-draft` was cut over in that commit; `lf-shot` was not, so standing on Show before / Show after left the shortcut bar with nothing to say about the flip. It is now one `commandScope`, attached to the widget's own checkbox and projected onto its margin entry. **A ring specimen moved behind a closed tab.** #721 added an example that sorts ahead of `triage-board` in the corpus, so the first `.lf-grip` landed in a tab panel that arrives hidden. Nothing inside it is focusable, so the sweep read a ring the grip paints perfectly well as undrawn. The sweep now asks the runtime's `reveal()` before focusing, deriving the surface from where the specimen sits instead of from a tab order that follows the examples directory. The fourth failure, `test_conversation_readiness_waits_for_the_keyed_thread_list`, raised `Page.evaluate: Resulting promise was garbage collected` from the `armed` re-entrancy hack around `scheduleUpdate`. #732 replaced that arrangement with an explicit `performUpdate` hold, and the test passes on main as it stands. Nothing here touches it. <details><summary>Verification</summary> Each regression was reproduced on main and bisected to its origin with `git bisect run`, one node id per run under `-n0`: the shot regression to e790513 (#716), the ring regression to eb055b1 (#721). The adapter 404 is not a bisect — the route has never existed in `server.py`; it reproduced directly and the fix clears it. On this branch: - `tests/test_render_controls.py` — all passed, ring sweep included. - `tests/test_site.py` — 1 failed of 136. `test_the_interaction_gallery_drives_real_widgets` expected `Playing`; it passes alone under `-n0` and passed in the failing run above, so it is timing under parallel load rather than this diff. - `tests/test_render_commands.py`, `tests/test_render_margin.py`, `tests/test_website_server.py` — 193 passed, 4 failed. All four are `bin/leaf` subprocesses reporting `no browser launched`; each reproduces on unmodified main in this sandbox and each was green in the failing run above. - `uv run pytest tests` — 1119 passed, 4 failed: the umask, read-only `/tmp`, and `bundleLayer` cases this sandbox cannot run. - Changed-file pre-commit hooks pass. No TypeScript changed, so the website-worker gate is unaffected. </details> --------- 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:
- **The record holds every revision it reads.** It used to leave out the
revisions the release published, but each build re-initializes every
page, so the next release's revision 1 is a different file. The manifest
now names each release's revision files (`revisions`), and only those
load from the release's static assets.
- **Saved responses are served only to the release that captured them**,
since a saved document names that release's assets. The first read under
a new release starts the container, which saves them again.
- **The first request after a deploy stops a container from before it**,
under the object's concurrency gate, so no request stops a container
this release is starting.
- **An active page's versions come from its own record.** Versions are
named by number, so the release's published `versions/v1.html` can be
another page than the visitor's.
- **An active session object resets at the deploy**
(`code_update_strategy = immediate` in `wrangler.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.
- **A page's startup no longer holds its registry's headers to its
release.** The registry sits under the revision's assets path, named by
the bytes served there and cached by the browser for a year. A visitor's
record now keeps that path across a deploy that leaves the runtime
alone, so the browser answered the registry from its cache with the
previous release's `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:
- During each rollout's few minutes, a visitor who has acted on a page
has their reads and sends retried until the new image answers, and a
reload then shows Cloudflare's "Failed to start container". Before, they
were already back on the published page.
- A page's first save in a session now uploads its published revisions
too, a few hundred KB.
- An agent turn cut off by a deploy still leaves its message unanswered
(#4080).
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-dev` deployed 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 check` and
`tests/process/website_server` pass.
> _This was written by Claude Code on behalf of max-sixty_
---------
Co-authored-by: Claude <[email protected]>
Keep every ordinary leaf.page document on the edge, including after the reader has activated private state. Replace the site-wide active and container-pin cookies with page-specific active markers, scope ephemeral containers to the deployed release, and route only an explicitly marked executable-revision reload through the container.
Add one content-free startup record with Worker time, first byte, first contentful paint, Leaf presentation, browser family, and platform. Extend the local site verifier to require that record and prove that activating one page leaves a neighboring page on the edge.
Validated with pre-commit, 61 Worker tests and typechecking, 36 browser-framework tests, the executable-revision browser test, and the complete local Worker/container site journey.