Repository navigation
feat(lynx): adopt a painted native list into the background root - #112
Conversation
Adoption refused every tree holding a native `<list>`, so a feed — the app shape a synchronous first screen exists for — was the one shape that never got one. It is adoptable now. What made it look impossible was a measurement nobody had taken: at first screen a native list has no cells at all. The platform materializes a row through `componentAtIndex` when it needs one, so a 1,000-row feed paints exactly one node, the `<list>` itself, and every row is a live record with no element behind it. That collapses the problem twice. What is painted is one node, so transfer moves one node. And the state that cannot be serialized — cells by native sign, recycle pools, retained items, the three recycling callbacks — is main-local and never crosses the wire, so adoption moves it by reference rather than describing it. Only the callbacks cannot come along, because they close over the container adoption is about to empty; they are rebound against the target and installed through `updateCallbacks`. No wire format changes. The snapshot keeps `format: 1` and its contract of one painted physical node each; the unpainted rows live in the main-local journal beside it, because widening the format would change a shape every peer validates on receipt in order to describe nodes no peer reads. Adoption of a list proves the painted nodes agree, the list's items agree, and the platform has not materialized a cell since capture — the last through a recycling epoch read at capture and re-read at adoption. Capture declines only a list that had already materialized a cell, which is why the Phase C opener's pre-check is removed here: it cannot predict that, and would decline exactly the pages that gained a first screen. Issue #66 Phase C, C2.
|
Adding a validation run that finished after the body was written, rather than editing the body around Bugbot's region.
I would rather report this than quietly re-run until it is green: the honest statement is that this container cannot run these three files reliably alongside other work, not that they are unaffected by the change — though the import graph says they are. Generated by Claude Code |
…pt-native-list Carries the review fix "replay prepare-walk diagnostics before declining a first screen" up the stack. Conflict resolution: this branch retires `firstScreenTreeIsUnadoptable` and its call site outright, because adopting a painted native list is what makes the early decline unnecessary. The fix hardened the skip path the removal deletes, so its hunks are dropped here rather than reapplied — but the property it protects is kept, and is now proved by its own two regressions running against the no-skip path: a colliding main-thread event prop and a duplicated main-thread ref still throw from `render`, with a null snapshot.
… paints Before this branch a page holding a native <list> was declined by the direct first-screen applier and rebuilt through the staged path, so prepare's final validation raised `main-thread ref X is assigned to hosts N and M` with zero PAPI calls spent. C3 makes such a page directly buildable, and the direct path carried a pre-walk for only one of prepare's two non-list diagnostics: the main-thread/background event collision. A duplicated ref therefore survived to `installMainThreadRef`, which reports it as `is already mounted` — a weaker message, raised mid-mount, after elements exist. That is the half-painted page the pre-walk exists to prevent. Extend the pre-walk to carry both diagnostics, with prepare's exact ref message and its visibility rule. The walk is now unconditional: a background listener is announced by the envelope, but a ref is announced by nothing but the host's own props, and this applier is exported, so no envelope field may make the check skippable. It is a second read-only pass over a tree the function already scans for a <list>. This is where the pre-check fix on new-lynx (e6b2898) lands once #112 retires `firstScreenTreeIsUnadoptable`: the same two diagnostics, replayed from the one place that still decides whether to paint. Regressions: the two gate scenarios now also assert nothing was painted, and a new one puts the duplicate on two rows of one list — rows own no element during the first screen, so no mid-mount check can ever see it. Both ref scenarios were verified red without the check (2 failed | 25 passed). Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Summary
Stacked on #111. Issue #66 Phase C, C2.
Adoption refused every tree holding a native
<list>, so a feed — the app shapea synchronous first screen exists for — was the one shape that never got one. It
is adoptable now: a
<list>page paints on the main thread and the backgroundroot adopts that paint, including the list.
What made it look impossible was a measurement nobody had taken. At first
screen a native list has no cells at all. The platform materializes a row
through
componentAtIndexwhen it needs one, so a 1,000-row feed paints exactlyone node — the
<list>itself — and every row is a live record withnode === null. I confirmed this with a probe before designing anything:physicalCells: 0, only the<list>host attached.That collapses the problem twice.
physical identity to hand over, because they have no physical identity yet.
LynxNativeListState— cells by native sign, recycle pools, retained items,counters, and the three recycling callbacks — is main-local. The background
only ever tests
message.firstTree !== undefined. So adoption moves thestate by reference instead of describing it.
Only the callbacks cannot come along: they close over the container adoption is
about to empty, and would materialize cells into a retired source. They are
rebound against the target through
bindNativeListCallbacks(extracted in #111for exactly this) and handed over with
listPAPI.updateCallbacks— the same seamapplyListUpdateanddisposeNativeListStatealready use.No wire format changes
My first design said
format: 2, carrying the rows in the snapshot. That waswrong twice, and I corrected it publicly on the issue before implementing:
main-readyreply and never boot.validateLynxBackgroundInboundMessageruns unconditionally on receive, and
assertFirstTreeSnapshotfails aformat !== 1.So the snapshot keeps
format: 1and its contract of one painted physical nodeeach — which is what
nativeIdmeans and what the validator enforces — and theunpainted rows live in the main-local journal beside it, along with one entry per
list.
What adoption has to prove for a list
update-list-infoontothe node being adopted;
listUpdatesis what the background would havewritten onto a node it created itself.
epoch —
enterCount + leaveCount + createdCells + reusedCells— read atcapture and re-read at adoption. A list that woke up in between holds physical
state the captured tree does not describe, so the page repairs.
A list with no rows at all is an ordinary page, not a disagreement: its
commit carries no list update, because there is nothing to insert.
Capture now declines only a list that had already materialized a cell.
The Phase C opener's pre-check is deleted here
firstScreenTreeIsUnadoptable(#110) answered "would capture refuse this tree?"before painting. Capture refuses far less now, and the pre-check cannot predict
what it still refuses — cell materialization is a runtime event, not a property
of the record tree. Left in place it would decline exactly the pages that gained
a first screen. Its changeset is amended to say so; its measurement stands as the
record of what build-and-discard cost.
Measurement
Real
installLynxMainThreadfirst-screen path, against the lowering compiled.tsrxproduces: atemplate-created<view>shell wrapping<list>whose rowsarrive through a keyed
@for, each row a<list-item>with three children. Thebackground thread is stood in for by a second render whose batch is dispatched
over the real ContextProxy as a
commit. Arms by checking out the three changedsource files; 21 samples per pass after 3 warmups, each in a fresh environment;
Element PAPI traffic counted by wrapping every function-valued
__*global andasserted identical across a pass.
Every head sample was asserted to have actually adopted (
ack.adoption === 'adopted', no diagnostics), so these are adoption timings, not repairs.Medians of three passes each at 1,000 rows (base 70.4 / 70.2 / 71.4, head 42.8 /
41.5 / 43.7), two at 50.
I expected the compare walk to dominate the extra total work, and it does
not. Timed directly at 1,000 rows:
prepareLynxHostBatchwalkcompareFirstTreetransferFirstTreeThe commit costs about the same in both arms (60.2 base, 70.9 head) because the
record walk runs either way — adoption skips the mutation, not the preparation.
Transfer is 0.8 ms because two nodes are physical. So the trade is: the page
appears after the paint instead of after the background's commit, and the main
thread pays the paint plus a 12 ms agreement check to make that happen.
Adoption's host traffic is constant, not per-row: 21 calls against 12 at both
50 and 1,000 rows, because an unscrolled list materializes no cells at any size.
Both figures understate the case. The harness dispatches the background commit
immediately, charging the base arm 3.6 ms (1,000 rows) or 0.2 ms (50) for "the
background produced its first commit", where a real page pays a bundle load and a
cold render on another thread — which the painting arm does not wait for at all.
The harness was temporary and is not in this diff; the numbers are in
docs/lynx-specialized-target-l0.md§8.Red/green, including two breaks that came back green
Each break run against the full 24-test file:
sameListItemscheckBoth green rows are declared rather than quietly kept, and neither is fixable by
adding a test:
The list-items check cannot fail alone. Every field of a
LynxListItemDescriptorcomes from a row'sid, its position among the list'schildren, and four props — and the node walk already compares ids, child order,
and props, more strictly: an absent
reuse-identifierand an empty one are onedescriptor but two prop sets. A row set that differs at all differs there first.
The check states the
update-list-infoagreement where adoption relies on it, andbecomes load-bearing the moment list metadata stops being a plain prop or row
props stop being compared one-for-one. A comment in the source says this. Note the
contract is still guarded —
repairs when the background list holds different rowspasses through the props comparison.The ownership equality is unreachable from any test, and that is not new. I
checked instead of assuming: disabling the assertion entirely on the parent
commit, in its original un-relaxed form, leaves all 434 lynx tests passing. It
is an internal invariant that only a driver bug can violate, and fabricating one
would mean writing to
LynxHostStateinternals, which.rulesync/rules/testing.mdrules out. The design requirement it had to meet — that relaxing it must not
weaken it for non-list trees — is met by construction: it stays an exact count of
the logical rows the capture walk itself emitted
(
ownedNodes.size !== records.size - logicalNodes.size), not an inequality.A bug found by reasoning, then by a test
listUpdates.length !== journal.lists.sizelooked like the obvious agreementcheck and is wrong: a list with no rows produces no prepared update at all. I
predicted it while writing the empty-feed case, wrote
adopts a native list that has no rows at all, watched it fail, and removed thecount equality. Absence is agreement here, not disagreement.
Tests
21 → 24 in
packages/lynx/tests/first-screen.test.ts. Six decline tests arereplaced by tests of the new behavior:
The two duplicate-
item-keytests are kept verbatim: a malformed list must stillthrow its diagnostic from the staged path rather than settling as a quiet skip.
One rewritten assertion is a stronger contract than the one it replaced. A
painted list now gates background startup until
markFirstScreenSyncReady(),where the declining version announced readiness immediately, so the test proves
the gating rather than the old immediate
main-ready.Validation
pnpm format:check— clean repo-widepnpm typecheck— clean (exit 0)pnpm test— not run to completion in this container: the full runexceeded a 60-minute cap on the branch below. The reachable projects were
run explicitly instead.
--project lynx— 32 files, 437 passed (parent: 434)packages/lynx/tests/first-screen.test.ts— 24 passednode benchmarks/bench.mjs --quick --ratios lynx-list— PASS, 0.012xeager (12 physical cells for 1,000 logical items, 988 reuses, 0 after
teardown). This is the exit gate Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §5 names for Phase C. It exercises the
list runtime, including the callback binding this change rebinds, but not
the adoption path itself.
Per #66 §2.3 the
rspeedy-pluginnative-demoandpacked-consumerfailuresremain pre-existing in this container and were not chased.
Risk / follow-ups
transferFirstTreemust stay free of Element PAPI calls before the rebindlands. Nothing above or below it calls the PAPI, so no native callback can
interleave with the move; a
flush, aninsertBefore, or asetAttributeadded there would open that window. A comment in the source says so.
cell before capture is declined, and one that materializes between capture and
adoption repairs. Neither is adopted, deliberately: the physical subtree is
keyed by a native sign, and nothing here can establish that it survives the
window without a device to observe.
proving agreement over records that own nothing physical. The load-bearing
contract for a list page is narrower — the painted nodes agree, and the list's
items agree — because an unpainted row's descendants materialize later from the
background's own records. Narrowing the walk there is the change that would also
make the items check load-bearing. Not taken here; it belongs with C3.
was never independent of C2, since capture refused every list tree whatever
painted it.
rather than compiled in-process, because the
lynxvitest project compiles.tsrxwith the background renderers. If the main-thread lowering changesshape, it goes stale silently. Unchanged from perf(lynx): decline an unadoptable first screen before painting it #110.
Provenance
agent-authored)Generated by Claude Code