Skip to content

Run every page under the serving Leaf's runtime, and drop served state from the protocol - #3448

Merged
max-sixty merged 15 commits into
mainfrom
runtime-follows-leaf
Oct 22, 2026
Merged

max-sixty merged 15 commits into
mainfrom
runtime-follows-leaf

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A page directory vendored a copy of the browser runtime, and every later Leaf served state to that older code, so the page protocol had to hold the served state across versions. Most past bumps came from reshaping it: 8 of the 11 real ones since protocol 2 renamed or reshaped the user's On me lists. Now the runtime a document executes comes from the Leaf serving, checking or exporting it (runtime_selection.py). page init vendors only the registry, theme, widgets and the modules packages add, and a revision captures those. The served state leaves the protocol, which now covers the log, what a page sends, vendored declarations, the public package API (widget-api.js and what its readers return) and records kept outside a page.

Runtime selection and pinning. runtime_selection reads the runtime whole once per process, pinned at server bind, so a plugin update that replaces the install directory can't change what a running server serves. It uses the committed kernel while that matches the tree (moved here from layer.current_kernel), and the source modules where the kernel is stale or a captured package module replaces one the kernel compiled in. A captured /vendor/ module still replaces the runtime's, including a public provider such as floating-ui.esm.js; a captured /runtime/ module never does.

Runtime identity. HTTP addresses a revision's resources under /revisions/<name>/<runtime>/, so the year-long immutable cache never names other bytes. A served document names its runtime (data-lf-runtime-identity), every answer names the server's (Leaf-Runtime), and a tab sends its own on writes. A tab from before a restart under another runtime refuses the answer and reloads (layer-client.js admitResponse, and admitReading for a version comparison's /api/view), and the server refuses its writes before any of them takes effect, file saves included (http.py _runtime_gate). A write with no Leaf-Runtime header passes, since harnesses and test clients post without one. The identity is a digest of the runtime's files, so a restart of the same build reloads nothing.

Delivery paths. The live shell, export, render gate, samples, previews and saved website responses all deliver a revision with the runtime of the Leaf doing the work. An export's marker carries the generation it was captured at. On the website a release already names its runtime: published revisions load from the release's static tree (the direct adapter now serves those addresses as the Worker does, and only for published revisions), and revisions made in the container load under the runtime identity.

Removed. runtime/layer-generation.js (a tab speaks the generation its document names, and a revision's executable digest includes it), the render gate's probe-linking refusal, and the served-state half of the protocol check with --accept-served. The build still holds the x-state verb, as a declaration this Leaf reads, and the event and record checks. $layer.server now covers the runtime, so a runtime-only change re-vendors and restarts the server, as previews rely on.

Protocol 16 → 17. This is the one-time cutover: a page vendored before this carries the old runtime in its directory and captures, which this Leaf would read as package replacements, and tabs already open run a runtime that sends no identity. The bump re-vendors every page, which gives each open tab a new document. The holding session does it on its first command or hook.

Approval. A signed-off version now renders under the current runtime: approval keeps its content and decisions, not the renderer. layer-registry.md, AGENTS.md "Pages across Leaf updates", page-storage.md, validation.md and packages.md say so.

Tests. pnpm run check (runtime and Worker tests included), the focused model and process modules for layers, revision delivery, module URLs, the live shell, distribution, file bindings, render export and gate, the interact server and the website server, and single browser tests: an export reaching presentation, a comparison refusing another runtime's answer, a tab reloading into its restarted server's runtime, an export running what its served page runs, and smoke. New tests cover a page another Leaf vendored running the serving runtime with a package's vendor replacement, a write naming another runtime, a published revision served at its release address with private revisions refused there, and kernel selection. A startup probe of ship-review shows 45 requests before the page presents against 46 on main (the dropped layer-generation.js), with the same bytes within 2 KB. Not run: the full browser and journey tiers, Firefox, the site build and leaf-dev verify-site. Two failures in dev/tests/process/test_website_server.py also fail on main.

Codex reviewed the design and then each round of the implementation until it found nothing further.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 6 commits October 20, 2026 22:16
…e from the protocol

A page directory vendored a copy of the browser runtime, and every later Leaf
served state to that older code, so the page protocol had to hold the served state
across versions and most bumps came from reshaping it. The runtime a document
executes now comes from the Leaf serving, checking or exporting it
(`runtime_selection.py`): `page init` vendors only the registry, theme, widgets and
the modules packages add, and a revision captures those. The served state leaves
the protocol, which now covers the log, what a page sends, vendored declarations,
the public package API and records kept outside a page.

- `runtime_selection` reads the runtime whole once per process, pinned at server
  bind, choosing the committed kernel while it matches the tree (moved here from
  `layer.current_kernel`) and the source modules where it is stale or a captured
  package module replaces one the kernel compiled in. A captured `/vendor/` module
  still replaces the runtime's; a captured `/runtime/` module never does.
- HTTP addresses a revision's resources under `/revisions/<name>/<runtime>/`, so the
  immutable cache never names other bytes. A served document names the runtime
  (`data-lf-runtime-identity`), every answer names the server's (`Leaf-Runtime`),
  and a tab sends its own on every write: a tab from before a restart under another
  runtime refuses the answer and reloads, and the server refuses its write. A
  website release already names its runtime, so neither side names one there.
- The live shell, export, render gate, samples and saved website responses all
  deliver a revision with the runtime of the Leaf doing it. The website's static
  tree holds that runtime beside each revision, so the Worker and its rebundle are
  unchanged.
- `layer-generation.js` is gone: a tab speaks the generation its document names, and
  a revision's executable digest includes the generation, so a re-vendor still gives
  an open tab a new document. The probe-linking refusal is gone too, since the gate's
  probes and the runtime come from one Leaf.
- `$layer.server` covers the runtime too, so a runtime-only change re-vendors and
  restarts the server, as previews rely on.
- The build no longer compares the served state with the baseline, and
  `--accept-served` is gone; it holds the x-state verb as a declaration this Leaf
  reads, refusing a tightening.

Protocol 16 → 17: a page vendored before this carries the old runtime in its
directory and captures, which this Leaf would now read as package replacements, and
its runtime sends no runtime identity. The holding session re-vendors it on its
first command or hook.

An approved version now renders under the current runtime: approval keeps its
content and decisions, not the renderer (`layer-registry.md`).

Tests changed with the behavior: the init and capture tests assert the page and its
revisions hold no runtime; served-resource tests address the runtime's identity; the
layer-mismatch startup test becomes a reload test for a restarted runtime, and the
probes-cannot-link gate test is deleted. New tests cover a page another Leaf vendored
running the serving runtime with a package's vendor replacement, a write naming
another runtime, an export running the exporter's runtime, and kernel selection.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…d package overrides working

Fixes from review of the runtime-follows-Leaf change:

- An interactive export reloaded forever: the runtime took its generation only from a
  served document's marker, so the export's registry looked foreign. The offline
  marker now names the generation it was captured at (`data-lf-layer`), and
  `context.js` reads it from whichever marker the document has.
- A version comparison decoded `/api/view` without admission, so a tab could read a
  newer runtime's state. It now passes `admitReading`, which holds the answer's
  runtime and release to the document's and leaves its layer, another revision's,
  alone.
- `/api/files/*` saved without the runtime check. The check is its own gate
  (`_runtime_gate`), first on every write route, apart from the vocabulary check.
- leaf.page's container addressed a published revision's resources beneath its own
  runtime, which no static file backs, so a page it saved while asleep woke it for
  them. Published revisions now load from the release's static tree, as their samples
  already did.
- Capture skipped a public vendor module even where the vendored layer held a
  package's replacement, so the page silently ran the runtime's. A public module is
  skipped only as a dependency now.
- The served-state schema and contract types no longer claim protocol checking.

Tests: an export reaching presentation, a comparison refusing another runtime's
reading, a bound-file save refused under another runtime, a saved published page
naming its release, and a package's Floating UI replacement captured and served each
fail without their fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Published documents load their layer and runtime from the release
(`/_leaf-release/<release>/<page>/revisions/<name>/…`), which the Worker answers from
the build's static tree. The website adapter run without a Worker, as
`leaf-dev journey website-adapter` runs it, answered those addresses 404, so a
published page there never started. The adapter now maps a release address to its
page as the Worker's `releaseAssetRoute` does (`released_path`) and delivers the
revision's resource through the same code the static tree was written with
(`PageEndpoint._revision_resource`, the live shell's `delivered_resource` at the
release root), with the Worker's immutable caching and CORS headers. It answers only
a published revision's resources there.

A new process test fails without this: the document names its release entry, and the
runtime, registry and a refused API path behave as at the edge. A browser probe of a
published example through the adapter presented with 45 release-addressed resources
and none failing; without the change its theme and modules 404.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The website adapter mapped every `/_leaf-release/<release>/<page>/revisions/…` path to
the page and let any its resource handler declined fall through to the page's own
routes, so a release address could serve a revision a session saved after the release
(`…/revisions/<private>.html`). The Worker answers release addresses from the static
tree alone and never forwards a miss to the container, so the deployed site never
served one; only the adapter run without a Worker did. A release address is now
answered whole while the page is selected: a published revision's resource, or 404.

The adapter's process test now saves a private revision after the release and fails
without this on its document at the release address.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/kernel/kernel.json
#	skills/leaf/kernel/leaf.js
"Pages across Leaf updates" still said a page keeps its own copy of the
runtime. It now says the page keeps its layer and runs the runtime of the
Leaf that serves, checks or exports it, names what a bump covers (the log,
what a page sends, vendored declarations, the public package API and
records) and why the served state isn't among them, and gives a drift
example that can still happen. The render gate no longer fails on drift,
so the sentence saying its failure names the re-vendor is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 21, 2026
The PR's `test` job failed three tests this branch got wrong; the code was right in
each:

- The site tests asserted every published page directory vendors a non-empty
  `runtime/`. The serving Leaf supplies the runtime, which the release publishes
  beside each revision, so a page whose packages add no runtime module holds none.
- The dependency-graph capture test, as `main` reshaped it into a key set, expected
  the public `/runtime/widget-api.js` among the captured resources. The revision
  captures what its author imports but not the runtime's public module, which the
  delivering Leaf supplies; the test now says so.
- The comparison test waited for "Waiting for the server to finish updating." in the
  panel's field. Only the comparison's answer names another runtime there, so the
  tab's next admitted read takes that wait down, and whichever error is newest when
  the field is read depends on timing; on CI it was the failed comparison. The test
  now reads the outcome that holds either way: "Couldn't load v1" in the Errors list,
  no comparison marks, and a source probe from the refusal. Without the admission in
  `version.js` it fails, since the comparison applies and raises no error.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 21, 2026
# Conflicts:
#	tests/process/test_interact_server.py
leaf-agent
leaf-agent previously approved these changes Oct 21, 2026
# Conflicts:
#	build/browser/protocol-baseline.json
#	skills/leaf/kernel/kernel.json
#	tests/model/test_module_url_delivery.py
# Conflicts:
#	AGENTS.md
#	browser/runtime/layer-generation.js
#	build/browser/build.mjs
#	build/browser/contract-types.mjs
#	dev/leaf_dev/commands/distribution.py
#	dist/kernel/kernel.json
#	src/leaf/layer-registry.md
#	src/leaf/layer.py
#	src/leaf/runtime_selection.py
#	src/leaf/schema.py
#	tests/journeys/test_interact_server.py
#	tests/model/test_distribution.py
#	tests/process/website_server/test_routes.py
#	tests/smoke/test_smoke.py
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026
# Conflicts:
#	build/browser/protocol-baseline.json
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tab left open across a runtime update can still replace the agent's user-view reading. observeUserView.send posts without Leaf-Runtime, and /api/user-view skips the new gate. The server therefore accepts the old tab's checks as a fresh observation in user-views.json, which leaf page state gives to the authoring agent. Send the document's runtime identity with this report and apply _runtime_gate before storing it, so the stale tab cannot describe the new runtime's page.

Comment thread src/leaf/http.py Resolved
`leaf page state` gives the agent each tab's view as the user's, but
`/api/user-view` skipped the runtime gate and `user-view.js` posted no
runtime identity, so a tab left open across a runtime update could still
replace that reading with checks run by its older code. The report now
carries the layer headers, and the route passes `_runtime_gate` first.
Only the interaction log, diagnostics no reader acts on, stays ungated.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 37bfc5c into main Oct 22, 2026
4 checks passed
@max-sixty
max-sixty deleted the runtime-follows-leaf branch October 22, 2026 22:57
leaf-agent added a commit that referenced this pull request Oct 23, 2026
Main CI's five startup module tests failed after
[#3448](#3448) moved executable
browser resources from the page directory to the serving Leaf. The
request recorder still expected revision-only paths, so it missed widget
modules and vendor bundles under the runtime digest; the public API test
also tried to read a page-local `leaf.js` that no longer exists. This
updates those tests to compare logical resource paths and to load the
boot source from the serving runtime, preserving their checks of lazy
module loading and early API import.

The five affected browser cases failed in [main run
39869500958](https://github.com/max-sixty/leaf/actions/runs/39869500958)
and pass together locally after this change (`5 passed`). Other failures
in that run have separate causes and remain under investigation.

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Oct 24, 2026
The [scheduled CI
run](https://github.com/max-sixty/leaf/actions/runs/40087560199) fails
the website shell comparison at `/`: the test rewrites release-addressed
asset URLs to page-relative URLs before comparing them with the adapter,
which now serves the release URLs. It also requests a published runtime
file at the old page-relative URL.
[#3448](#3448) moved published
revision resources to release addresses so the site and adapter use the
same immutable resource graph.

The test now compares the delivered documents directly and requests the
runtime file using the asset root in the site manifest. Its existing
checks still cover the root, example, runtime resource, and historical
document routes. A focused run of `uv run pytest -q -n0
tests/journeys/test_site.py::test_the_edge_shell_is_the_document_and_runtime_the_leaf_server_serves`
failed before this edit and passes after it. Other failures in the
scheduled run have separate causes.

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Oct 26, 2026
Closes #4113

Python and the browser now read the kernel registry's facts (`$events`,
`$passages`, `$marks`, `$names`, `$authored`) from one file,
`browser/runtime/kernel-registry.json`. Neither needs a build between an
edit and reading it. The six modules `build/registry.mjs` generated, and
the generator, are gone. Page startup loads the same requests as main
and 45 more bytes.

## Which copy each side reads

Python already read the serving Leaf's own registry
(`state.kernel_registry`), never a page's vendored `/registry.json`,
whose copy of these facts came from whichever Leaf vendored it. The
browser must read the same copy, or a fact changed without a protocol
bump splits again across Leaf updates. A page's runtime is the serving
Leaf's (`runtime_selection`), so the copy belongs in the runtime.

Serving the existing `browser/registry.json` at a second URL would need
that path mapped in every resolver: Python's runtime, `tsc` paths,
dependency-cruiser, Node's test loaders, `node
worker/bundle-runtime.mjs` and vitest. I tried it first, and
`test:browser` and the worker's tests failed to resolve the import until
each got its own mapping. So the kernel facts moved into the runtime
directory:

- `browser/runtime/kernel-registry.json` holds the five kernel sections,
moved by text with their formatting. `browser/registry.json` keeps the
core layer's vocabulary (`$keys`, `$languages`, idioms, and the rest).
- `runtime/kernel-facts.js` imports it as `./kernel-registry.json` with
`{ type: "json" }` and derives what the generated modules held
(`COLLAPSE`, `TEXT_BLOCK`, `CONTEXT`, `WIDGET_NAME`, `marks`,
`MESSAGE_KINDS`, `VERB_WRITERS`, `drawingSchema`, `DRAFT_FORMAT`). Every
tool resolves the import on disk. The server serves it with the rest of
`runtime/`, where no layer can replace it.
- `state.KERNEL_REGISTRY` is the file's one Python name.
`incoming_registry` merges it first and each layer over it. A page's
composed vocabulary is unchanged: composing with the split and with the
whole file gave identical dicts.

## The kernel carries the values, not the file

The browser reads about 3 KB of the 68 KB file; the rest is record
schemas, handling text and descriptions that only Python and agents
read. So the kernel build (`build/runtime-bundle.mjs`, `kernelFacts`)
evaluates `kernel-facts.js` in Node and emits its exports as literals:

- **Fresh values:** the module is evaluated from a `data:` URL with its
JSON inlined, so a long build never reads a copy Node cached earlier.
The serializer throws on any value it has no literal for.
- **Stale kernel:** `kernel.json`'s `inputs` hash every file the
compiler read: each `.js` module, everything it compiled in, and the
files `kernelFacts` inlined. The install guard (`read_runtime`) hashes
each `.js` module and each other file the record names. After a registry
edit, an install serves the source modules, where `kernel-facts.js`
reads the JSON live, until the kernel is rebuilt. The same holds for any
JSON a runtime module imports, which rolldown compiles in: a probe
`runtime/zz-test.json` imported from `words.js` made the kernel stale
when edited, and under the previous compiler, which hashed only
`kernelFacts`' reads, the kernel stayed in use.
- **No copy served beside the kernel:** the registry is in `replaces`,
so a runtime serving the kernel no longer carries the 68 KB file. The
source modules, which read it, still do.
- **Recording the files, not a suffix rule:** the guard follows the
compiler. A base arm without `kernel-facts.js` gets no new input, so
`leaf-dev probe --base` still judges main's kernel current. Hashing
every `.json` would have caught `vendor/initial-dependencies.json` and
sent main's arm to its source modules.
- **Website:** the rebundle compiles the facts the same way, so the JSON
never enters its module graph.
- **`runtime/syntax-languages.js`** stays generated, now by
`build/vendor.mjs` beside the grammars it names. Its aliases come from
Shiki, and its literal imports point at bundles only that build writes.

**Rebuild before landing:** a change to `runtime/kernel-registry.json`
now takes `pnpm run build:browser` in the same change, as a runtime
`.js` module does (`build/AGENTS.md`). Leaving it out costs no
correctness: installs serve the source modules until the kernel matches
again. `check:browser` reports the stale kernel.

## A restriction this lifts

Capture refused any non-JavaScript module import (`resource_urls`,
`module-type`). It now admits `.json`, which an export taken while the
kernel is stale needs for the source modules' JSON import. The browser
still refuses a JSON import without `with { type: "json" }`, and page
check reports that as a console error. Pages gain JSON modules too.
`test_invalid_dependencies_leave_the_previous_revision_active` now holds
`module-type` with a `.txt` import.

## Repro, before and after

I raised `$passages.context` from 24 to 31 and ran no build:

| | Python | Browser |
|---|---|---|
| main, compiled kernel | 31 | anchor loop starts at 24 (`for (let width
= 24;`) |
| this PR, the checkout's own `leaf server run` | 31 | kernel judged
stale, so source modules load; `CONTEXT` is 31, read from
`kernel-registry.json` |
| this PR, rebuilt kernel (`leaf-dev probe`'s prepared install) | 31 |
`for (let width = 31;`; `kernel-registry.json` never requested |

## Startup

`uv run leaf-dev probe <page> --base`, Chromium, compiled kernel. Main's
arm is built with this PR's compiler, which reproduces main's
`dist/kernel`. Measured at `presented`, when the page first shows the
server's state:

| Page | Arm | Requests | Bytes | JS bytes |
|---|---|---|---|---|
| release-notes | main | 53 | 3,235,283 | 2,509,803 |
| release-notes | this PR | 53 | 3,235,329 | 2,509,674 |
| triage-board | main | 44 | 2,955,241 | 2,375,849 |
| triage-board | this PR | 44 | 2,955,286 | 2,375,720 |

Times are left out: the host's load average was 33–52 during these runs,
and single runs swung by a second. The previous revision of this PR
added one request and about 65 KB.

## Protocol

No bump of its own. Main has since bumped to 27, and the merge carries
that into `kernel-registry.json`; outside the descriptions this PR
rewrote, the split file and `browser/registry.json` together equal
main's registry. A vendored page's composed registry has the same
content, the event records and what a page sends are unchanged, the
public package API is unchanged (`check-api.js` still re-exports
`TEXT_BLOCK`), and `DRAFT_FORMAT` keeps its value. The deleted modules
were private runtime modules, which a page never vendors.
`protocol-baseline.json` is unchanged.

The `$names` and `$passages` descriptions said a page's runtime keeps
the copy it was vendored with, which hasn't been true since #3448. They
now say both runtimes read the serving Leaf's copy, and give the reason
a change still bumps the protocol: `$names.widget` sorts a vendored
registry's keys, and anchors and passages in the log were read by
`collapse` and `blocks`. A change to `context` alone sets only how much
a new anchor captures.

## Tests

- `pnpm run check`: build check, framework/build tests, `test:runtime`
(563), the worker's tsc and vitest (85).
- pytest: `tests/model/interact_contract/` (its regtest snapshot names
the new file), `test_interact_layer.py`, `test_interact_product.py`,
`test_claims.py`, `test_revision_delivery.py`, `test_render_export.py`,
`test_distribution.py` (model and dev;
`test_a_leaf_serves_the_kernel_only_while_it_matches_the_tree` now holds
that an edit to `vendor/initial-dependencies.json` keeps the kernel and
an edit to the kernel registry serves the source modules, and fails at
that assertion when the registry is left out of `inputs`),
`test_live_shell_artifact.py`, `test_product_page.py`,
`process/test_interact_server.py`,
`process/website_server/test_routes.py`,
`dev/tests/model/test_product_page.py`, and the seed test in
`dev/tests/model/test_interact_preview.py`.
- Browser, selected by `-k`: interactive-export tests in
`tests/browser/test_render_export.py`, and the browser/Python
capture-agreement tests in `test_render_anchors.py`.
- `leaf-dev probe --firefox` on release-notes: boots with no console
errors (on the first revision).

Not run locally: the broad suite, the journeys tier
(`tests/journeys/test_interact_layer.py` was edited), and the website's
delivery checks (`leaf-dev verify-site website-worker`), all of which CI
runs. The eval case `first-command-says-what-comes` names the new path,
and the eval format has no per-arm value, so a `--base` run of this
branch points its base arm at a file main lacks. Once this lands, every
later merge base has the file.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Nov 15, 2026
… agent's edit fetches no runtime again (#6066)

A page server answered the resources a document runs (the runtime, the
composed layer and registry, and the revision's captured page files)
under `/revisions/<revision name>/<execution identity>/`. The revision
name changes with every save, and an agent saves one at each edit, so
the year-long immutable cache never carried across revisions: the user's
next load fetched all 309 runtime scripts and the theme again. The name
in the path dates from when each revision captured its own copy of the
runtime; #3448 moved the runtime out of the capture and kept the path.

The address is now `/revisions/<identity>/` (`http.assets_path`). The
identity (`runtime_selection.executing`) covers every byte served
there: the runtime, the layer's files (digested once per composition)
and the revision's registry, the captured files other than media by the
digests their manifest records, and the page widget aliases. Revisions
that change only their document share it. A revision that changes a
page module, its declarations or its layer selection gets a new one,
and so does a server running another Leaf, so an address still names
one set of bytes. Media answers only at the page root, under its own
digest, which is where documents and the runtime already named it: the
address serves none, so adding or swapping an image keeps the address.

A server finds the revision behind an address through an index of each
identity it has computed (`http._Executions`). Serving a document
records its revision there, so the requests the document's load makes,
for the newest revision or any older one or stamped version, find it at
once. An address this process hasn't served a document for, which a
tab from before a restart or under another Leaf names, is searched for
among the revisions, newest first, with each revision's identity
computed once however many requests ask (`page_memory.once`) and kept.

The website's container serves the revisions a visitor's session saves
at the same address, and the responses it saves for a sleeping container
follow it (`storage._responses` calls `assets_path` and lists media only
at the page root); published revisions keep their release paths.

A tab's `session_start` observation now records the revision its
document is and the runtime it runs, which resource paths named before
the address became one identity, so a reload stays attributable to a new
revision or to a restart under another Leaf. The live document is served
at `/`, so its address alone doesn't say which revision it is.

## Evidence

A reload after a new revision, headless Chromium on loopback, median of
5 reloads per run, two runs per arm alternating base and head
(`leaf-dev bench` pages built from each checkout, one line appended to
`index.html` between reloads):

| Page | transferred | main-thread task ms | same-revision reload, ms |
| --- | --- | --- | --- |
| asks 64 | 8.31 MB → 0.41 MB | 483, 484 → 394, 393 | 375–386 |
| events 256 | 8.23 MB → 0.33 MB | 284, 286 → 185, 198 | 184–212 |

Review measured the same reload by phase: 7.60 MB → 0.22 MB loaded
before the page shows the server's state, which it shows at 367 ms
rather than 597 ms. What head still moves after a revision is the
document (189 KB), the stamped version's document the change view
compares against (189 KB on asks 64) and the state read. The main-thread
time saved is, by inference, the work of loading and compiling the same
scripts again under new URLs; script time alone went 127 → 100 ms on
asks 64.

## What to weigh

The search runs only for an address this process hasn't served a
document for. On a page of 300 revisions whose first revision runs other
page code, a fresh server, main vs head: revision 1's `leaf.js` 75 →
408 ms for the first request and 1 ms after; 16 concurrent first
requests 127 → 408 ms wall; an identity no revision has, 357 ms once,
then 1 ms. A cold browser opening revision 1's document presents at
391 ms on main and 368 ms on head. Pages on this Mac have a median of
18 revisions, p90 about 75 and at most 377.

The address no longer serves media: `<assets>/media/<name>` answers
404, and the tests that read a captured copy of a recording there now
read the page root and a captured page file.

## Tests

`test_revisions_that_change_only_their_document_share_their_resources`
fails on main at the shared-address assertion;
`test_a_session_that_swaps_an_image_goes_on_saving` fails before the
media fix with "cannot publish saved page response
revisions/…/media/….png: 404"; the frozen-preview journey, which now
serves the same revision from a live server beside the preview, fails
with a cache keyed by revision name. All three pass here. Run by name:
the process server tests on revisions, samples, media and previews, the
website route and saved-record tests, the model delivery, layer and
distribution modules, the journeys that read an asset path, smoke, the
browser tests whose path parsing changed, and `pnpm run test:runtime`.

`dev/tests/journeys/test_interact_preview.py::test_preview_publishes_companion_edits_at_its_existing_url`
failed on main, since it built the path from the runtime identity; it
now reads the address from the document's `data-lf-entry` and passes.
Review's site build and the Worker's dry-run deploy passed. Its
`leaf-dev site verify` run timed out at the container's activation read
(`GET /api/view`, 120 s), before the step that saves a private revision,
so it never exercised this change. Not run: the full browser and
journey tiers and Firefox.

Left as they are: a published release still writes a full tree per
revision (`live_shell`), so moving between a published page's versions
on leaf.page fetches the runtime again; and a local `lf-sample` loads
the
runtime under its own capability path, so each sample in a gallery
fetches it once. Both are separate changes.

Part of #5194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants