Skip to content

Remove deferred data fields, so lf-diff's patches arrive with page state - #5896

Merged
max-sixty merged 4 commits into
mainfrom
layer-compose-once
Nov 14, 2026
Merged

max-sixty merged 4 commits into
mainfrom
layer-compose-once

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Leaf's data contracts could mark one field of each record as deferred: the page received rows without it, and a widget fetched each field with loadDeferred through /api/deferred. Only lf-diff's unified-diff contract used it, for each file's patch. Since #2742, lf-diff derives each row from its patch, so it fetched every patch as soon as it showed: one request per file right after the state answer, saving no bytes. On leaf.page those per-file requests also passed the edge's stored state answer, so viewing a diff page started the visitor's container.

This removes the mechanism. A manifest's patches are part of the value page state carries, which the edge already answers for a visitor who hasn't written.

Removed

  • records.deferred in the registry schema, and the contract-records check, which only kept a deferred field from naming the key.
  • The /api/deferred route and the server functions behind it (data_manifest, deferred_fields, deferred_value, browser_data_from), with the two source-protocol methods only it read.
  • The browser's loader: loadDeferred in the portable API and runtime/deferred-value.js, and offlineDeferred in the export reader.
  • The export's per-value spans, which let one deferred field be decoded alone: its data file is now one gzipped JSON object keyed by source.
  • The website's capture of deferred answers into a session's stored responses, and the Worker's routing of them.
  • lf-diff's Retry for a patch that failed to load, and readEntry, which read a manifest patch when its file opened. sourceRecords now parses each manifest patch when the source arrives. A patch it can't draw refuses only its own file and is reported as before.

Behaviour that changes for agents. leaf page state <page> <message> reads a message's widgets with their inputs' values. For an lf-diff in a message bound to a manifest, that reading now carries every patch (220 KB on pr-walkthrough) instead of the rows without them, as a patch-text source always did.

Kept. page_memory.once (#5856) was justified by the 46 concurrent deferred loads on a cold container. It still makes any requests that reach a cold server together compose the layer once; only its docstring changes.

Measured on pr-walkthrough with leaf-dev probe --base: the page first presents the server's state after 315 requests instead of 363, and 8.08 MB instead of 8.09 MB. The state answer itself grows by the 220 KB of patches, which one deferred request per file used to fetch just after it; later state reads still leave out data the tab already holds.

Tests

  • Deleted: the deferred route and its stale-revision refusal, offline deferred reads, loadDeferred's guards, and the in-place and reopen Retry tests.
  • Replaced: the disclosure test that walked a stale deferred read. Its successor, test_a_file_opened_while_a_newer_source_draws_shows_the_newer_lines, holds the wait an opened file keeps on a newer revision's drawing. With that wait removed, it fails with the older lines shown.
  • Rewritten to read whole values:
    • the historical-state and snapshot server tests;
    • the page-owned-contract test, whose old registry now judges data the new one accepts;
    • the anchors and seated-thread diff tests (a refused file now comes from a patch naming another file);
    • the offline export test.
  • Moved: the repeated-key refusal, from a server test to the manifest model test.

tests/browser/projection/test_code_review.py::test_call_diff_source_paths_do_not_alias_durable_rename_coordinates fails locally on macOS (556.8 == 563.8 ± 0.5) identically on the merge base; this change doesn't cause it.

Docs. package-data.md and module-state.md lose the deferred paragraphs, and package-data.md says what records does now. The diff package's author instructions now say the manifest producer isolates a file lf-diff can't draw, since size is no longer a reason to use it.

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

Since #2742, `lf-diff` derives each row from its patch, so it loaded every deferred
patch as soon as it showed: one `api/deferred` request per file right after the state
answer, saving no bytes. It was the only widget with a deferred field. On leaf.page
those per-file requests also passed the edge's stored state answer and started a
passive viewer's container.

This removes `records.deferred` from data contracts with its distinct-fields check
(`contract-records`), the `/api/deferred` route and the server functions behind it
(`data_manifest`, `deferred_fields`, `deferred_value`, `browser_data_from`), the
browser's loader (`loadDeferred` in the portable API, `deferred-value.js`), the
export's separate copy of deferred fields, the website's capture of their answers,
and `lf-diff`'s Retry for a patch that failed to load. A manifest's patches are part
of the value page state carries; a patch `lf-diff` cannot draw is refused as before.

Tests of the deferred route, its stale-revision refusal, its offline reads and the
load Retry are deleted, as is the disclosure test whose failure, a false error from a
stale deferred read, can no longer happen. The rest read whole values.

On pr-walkthrough (`leaf-dev probe`, base then head), the page first presents the
server's state after 363 → 315 requests and 8.09 → 8.08 MB; the state answer now
carries the 220 KB of patches the per-file requests fetched after it.
…e object

With deferred loads gone, every lf-diff entry that isn't refused already holds its
parsed file, so `readEntry` and the fallback that read a record's patch at open time
were unreachable. `sourceRecords` now parses each manifest patch itself, keeping the
per-file refusal, and an entry holds one `source` record with its file or its error.

An export's data file held each value as a gzipped span so one deferred field could be
decoded alone; the offline state read now decodes every value at once, so the file is
one gzipped object keyed by source and the span offsets go.

Tests: a disclosure opened while a newer revision draws now has a test of its own (with
the wait on the source render removed, the older lines land after the newer ones and
the test fails); the page-owned contract test again shows an old document judging data
by its captured registry; the repeated-key refusal moves to the manifest model test,
and its server copy, which also restated the state answer test, goes.
@max-sixty
max-sixty merged commit b0a0fce into main Nov 14, 2026
5 checks passed
@max-sixty
max-sixty deleted the layer-compose-once branch November 14, 2026 18:20
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