Skip to content

Send a state answer's data sources only when the tab lacks that version - #3009

Merged
max-sixty merged 4 commits into
mainfrom
corpus-data-version
Oct 15, 2026
Merged

max-sixty merged 4 commits into
mainfrom
corpus-data-version

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Every /api/state read and every /api/event answer carried each data source's whole value, though data moves only when an agent sets it. Since #2929 added two Playwright trace manifests (~650 KB each, mostly saved accessibility trees) to the corpus example, a comment there carried 1.4 MB back in its event answer, and again in the state read that often follows: 1.5–3 MB per comment.

A state request or event POST now names the data version the tab holds in Leaf-Data-Version. When the answer's data is still that version, page_state (http.py) sends data: {version} without sources, and the reader restores them from the reading its request named (completeData in layer-client.js, used by state-feed.js and delivery.js), so the reading stays exact if another answer moved the tab's data meanwhile. A request naming no version (the first read, website publications, exports, older vendored pages) still gets every source, so no protocol bump.

Why this is for your review: it adds a wire mechanism, and it didn't move local timings: bytes per corpus comment fell from ~2.2 MB to ~140 KB, but painted and Sent stayed within noise, since the main-thread cost is applying the state, not transferring it. Its gain is on leaf.page, where the bytes cross a network. The alternative is to defer the trace manifests' phases through the existing records.deferred mechanism (as the diff package defers patch), which would also take ~1.2 MB off the corpus's first state read, but changes lf-trace to fetch accessibility trees on demand. Codex's review found no correctness defects (every answer reader restores or gets full data; state answers are no-store), and noted the server still reads and hashes the sources each answer.

Also: bench-latency's results.json now records each request a benched transition caused (URL, initiator, bytes), which is how the bytes were found.

Checks: pnpm run test:runtime, pnpm run check:framework, a new runtime test ("a read keeps the data it named…") and a server assertion, each failing with its half of the fix removed.

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

max-sixty and others added 3 commits October 15, 2026 00:50
Every /api/state read and every /api/event answer carried each data source's
whole value, though data moves only when an agent sets it. Since #2929 added
two Playwright trace manifests (~650 KB each, mostly saved accessibility
trees) to the corpus, a comment there carried 1.4 MB back in its event answer,
and again in the state read that often follows: 1.5 to 3 MB per comment.

A state request now names the data version the tab holds in
`Leaf-Data-Version`. When the answer's data is still that version, the server
sends `data: {version}` without sources, and the reader restores the sources
from the reading its request named (`completeData` in `layer-client.js`), so
the reading stays exact even if another answer moved the tab's data in
between. A request naming nothing, such as the first read, a saved website
response or an export, still gets every source.

On the corpus comment bench (3 runs, load 12-15), bytes per comment fell from
~2.2 MB to ~140 KB; timings did not move, since the main-thread cost is the
state application, not the transfer or parse.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The table's request count and byte total said a corpus comment had grown from
4 requests and ~200 KB to 6-13 requests and 1.5-3 MB, but not which requests;
finding them took a patch to the probe. results.json now records each
request's URL, initiator and transferred bytes beside the totals.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 15, 2026
# Conflicts:
#	skills/leaf/kernel/kernel.json
@max-sixty
max-sixty merged commit 4cb0f17 into main Oct 15, 2026
3 checks passed
@max-sixty
max-sixty deleted the corpus-data-version branch October 15, 2026 20:34
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