Skip to content

Read the kernel registry's facts from one file in both runtimes - #4197

Merged
max-sixty merged 8 commits into
mainfrom
registry-one-copy
Oct 26, 2026
Merged

max-sixty merged 8 commits into
mainfrom
registry-one-copy

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

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

max-sixty and others added 2 commits October 25, 2026 22:13
Python read the kernel facts ($events, $passages, $marks, $names, $authored) from
browser/registry.json, while the browser read copies that build/registry.mjs
generated into six runtime modules. An edit to the registry reached Python at once
and the browser only after a build: raising $passages.context to 31 left the served
kernel's anchor loop starting at 24.

The kernel facts now live in browser/runtime/kernel-registry.json, part of the
runtime the serving Leaf supplies. Python reads it (state.KERNEL_REGISTRY), and the
browser imports it as a JSON module through runtime/kernel-facts.js, which derives
what the generated modules held. Because the file sits where the runtime is served
from, Node, tsc, vite, dependency-cruiser and rolldown resolve the import on disk
with no mapping, and a page's vendored /registry.json, whose copy of these facts came
from the Leaf that vendored it, is never read for them. Composition merges the
kernel registry first and each layer over it, so a page's composed vocabulary is
unchanged and the protocol stays at its number.

The kernel keeps the JSON import external, so it holds no copy to go stale; the
website's rebundle does the same and leaves it out of modulepreload.
runtime/syntax-languages.js stays generated, now by build/vendor.mjs beside the
grammars it names, since Shiki's aliases come from that build.

A module dependency may now be JSON as well as JavaScript. Capture refused any
non-JavaScript import, which blocked the runtime's JSON module in an export; a JSON
import without `with { type: "json" }` still fails in the browser, and page check
reports it as a console error. The invalid-dependency test now holds the refusal
with a .txt import.

The $names and $passages descriptions said a page's runtime keeps the copy it was
vendored with, untrue since #3448; they now say both runtimes read the serving
Leaf's copy and why a change still bumps the protocol.

Closes #4113

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The kernel imported the whole kernel registry, 68 KB of record schemas, handling
text and descriptions, to read the 3 KB of values kernel-facts.js exports. A rolldown
plugin now evaluates kernel-facts.js in Node at build time, from a data: URL with its
JSON inlined so a long build never reads a cached copy, and emits its exports as
literals; the serializer refuses a value it has no literal for. The kernel records the
registry's hash among its inputs, and the install guard hashes every file the record
names beside the .js modules, so a registry edit serves the source modules, which read
the JSON live, until the kernel is rebuilt. A registry edit now takes a rebuild in the
same change, as a runtime module does.

Recording the inlined file rather than a suffix rule keeps the guard following the
compiler: a base arm without kernel-facts.js gets no new input, so `leaf-dev probe
--base` judges main's kernel current.

The website rebundle compiles the facts in the same way, so the JSON never reaches its
module graph; the modulepreload filter and the JSON branch in native() and the graph
walk go. Capture still admits a JSON module import, which an export taken while the
kernel is stale needs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@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.

JSON module admission also needs support in the website's dependency graph. A widget importing ../page/data.json with { type: "json" } now passes resource_reference, but publishing that layer fails: bundleRuntime follows the native dependency into page/data.json and calls nativeImports(), which parses it as JavaScript. Calling the website's bundleLayer() with that widget and {"value":1} in the JSON file reproduces SyntaxError: Unexpected token (1:8).

The kernel's special evaluator avoids this for its own registry, but leaves the newly admitted page capability incomplete. JSON dependencies need to be treated as data leaves in the website graph, including the preload path that consumes that graph, so a page using the admitted import can also be published.

max-sixty and others added 3 commits October 25, 2026 23:01
…s as values

The kernel record hashed the .js modules and the files kernelFacts inlined, but
rolldown also compiles in any JSON a runtime module imports, which landed in
`replaces` without a hash: an edit to such a file left the guard judging the kernel
current, the failure #4113 removes. The record's `inputs` now hold every file the
compiler read, the modules it compiled and the files it inlined among them. A probe
JSON imported from runtime/words.js is listed in both now, and editing it serves the
source modules; under the previous compiler the kernel stayed in use.

The kernel registry joins `replaces` too, since the kernel holds its values: a
runtime serving the kernel no longer carries the 68 KB file, while the source
modules, which read it, still do.

test_a_leaf_serves_the_kernel_only_while_it_matches_the_tree now holds both sides:
an edit to vendor/initial-dependencies.json, which no kernel reads, keeps the kernel,
and an edit to the kernel registry serves the source modules with the edited file.
Leaving the registry out of `inputs` fails that assertion.

literal() now keeps -0, computes a `__proto__` key so it stays an own key, and names
the value it refuses, such as undefined or an object with no prototype.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…, and rebuild the kernel

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The framework now sits in browser/runtime/framework*.js and its types in
browser/types/. Both sides' notes on dependency-cruiser's exclusions stay, the build
keeps main's licence notices without the registry generator, and the kernel is
rebuilt from the merged tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review October 26, 2026 16:36
max-sixty and others added 3 commits October 26, 2026 10:16
…cides field) into the kernel registry, and rebuild the kernel

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 55864e9 into main Oct 26, 2026
3 checks passed
@max-sixty
max-sixty deleted the registry-one-copy branch October 26, 2026 17:31
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.

Python and the browser read registry facts from one copy

2 participants