Repository navigation
fix(lynx): two unbounded main-to-background replies - #233
Merged
Merged
Conversation
The background reads one bit out of `main-ready`: a first screen was painted here, so the first background batch must preserve its IDs. `transport.ts` computed exactly that — `message.firstTree !== undefined` — and nothing in the package ever read a node out of the snapshot it tested. Below this change the only way to state the fact was to attach the whole first-tree description, so a correlated reply was O(painted tree): a 30,000-row page shipped a ~37 MB structured clone that `protocol.ts` then validated node by node on receipt, to carry a boolean. The reply now carries `firstTreePainted: 1`, published only to a background whose readiness request was tagged at the new `LYNX_FIRST_TREE_PRESENCE_READY_REQUEST_BASE`. That is the shape every other optional reply key already uses, and for the same reason: a peer below the rung validates against an exact key set and would reject a key it has never heard of. The description route is kept rather than approximated away. A peer below the rung is still sent the snapshot, because presence *is* the key for it — the bit alone would tell it no first screen happened at all, and it would rebuild the page over the command path with fresh IDs. Both skew directions are therefore safe. The two spellings are mutually exclusive on the wire, so a receiver never has to decide which one wins. The main thread's own cost goes with it: the description is built on first read, and the presence path never reads it, so a first screen that hands off this way never allocates a description of itself either. Regressions: a unit budget asserting the reply is byte-identical at 50 and 400 rows and under 512 B, a companion case driving a peer below the rung and asserting it still receives all 401 nodes, and a 4,096 B main-to-background budget in the lynx-table first-screen selector suite, which until now reported only counts and so could not see this. Refs #231 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
…t catch The budget added with the #231 fix claimed its job was "to catch a payload that scales with the tree". It cannot: both arms of this harness render from the background, so the main thread applies commands and never captures a first tree, and there is no description on the wire for the budget to bound. Measured on the fixed build it reads 468 B at 1,000 rows, 470 B at 30,000, and the same 470 B with the background dropped below the presence rung — identical because neither arm has a description to send either way. The check still bounds something real, so it stays: the rest of the handshake must not become a function of the page by any route. The comment now says that is its scope, and names where the description's own budget lives — first-screen-ready-wire.test.ts, which drives a real main-thread paint, pins the reply byte-identical across an 8x tree and under 512 B at the presence rung, and proves that budget can fail by dropping a peer below it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
… the first Issue #230 measured 17.4 MB of MTS->BTS acknowledgement on the benchmark's `create 10000`, deterministic across 7 samples, where upstream spends 732 B. Reading the decision out of a real browser run showed the first create is compact and every later one is not, with one input differing: preparation records no host count from the second run onwards. Taking the compact path installs the driver's dense record store, and the incremental-compact candidate test asks for `state.records instanceof Map`. Against the dense store it is false, so `compactHostCount` comes back undefined -- and the main thread's acknowledgement gate had a recompute fallback only on its provisional branch. The non-provisional branch read the missing count as "not compact" and replied with one handle per host: 70,000 of them for 10,000 rows. Succeeding at compact was what disqualified the next one. The count is a property of the batch, so recompute it on both branches rather than let the container the driver happens to be holding records in decide a wire encoding. The check immediately below still re-validates a count that disagrees with preparation against the prepared handle deltas -- length must match and every delta must be a generation-1 create -- so a recomputed count that does not describe what was prepared still falls back to legacy. Measured on the bench app built from this tree, same machine, one window, seven samples per arm: create@10000 median 17,420,754 B before and 782 B after; `heapMtsAfterClear` 17,850,904 B before and 17,863,780 B after, so this does not touch the retention tracked in #231. The regression drives the real main thread behind a painted first screen, fills a range, clears it, and fills it again, asserting the second run is still acknowledged with `compact-v1`. It fails on the old gate. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Huxpro
marked this pull request as ready for review
August 28, 2026 13:37
Huxpro
marked this pull request as draft
August 28, 2026 13:41
Reconciles the upstream v0.1.47 sync stack with the merged C8-D8 train: union .prettierignore, regenerate-later audit stamps, and a semantic merge of collectFirstScreenEvents keeping the train's merged-order program announcement while threading the sync's component-scope/native-list flags and template-range branch through the node helper. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
The merged pnpm-lock.yaml hashes differently from either parent, so every react-parity manifest and the user-app corpus carry regenerated lockfileSha256/overlayLockfileHash stamps from their own generators. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
Three defects and two cleanups from the gate review of the merged tree: - expandRecordsRunTeardown collected its removes and destroys with one spread call, so a run past the engine's ~125k-argument ceiling died in RangeError at batch-prepare — exactly the run sizes the explicit-records fallback exists for. Appended in loops; red-verified at 17,000 rows of width 7. - expandRunTeardown tested the dense store's removed set with an absolute host id where every other reader uses store-relative offsets, silently kicking intact runs off the certified expansion whenever an aliasing offset was retired. delete() also blanks nodes[offset], so the wrong unit could only decline, never wrongly certify. - Dropped the identical-armed slot ternary and the unreachable __proto__ assignment branch in main-renderer; forbiddenProp declines __proto__ before either loop can reach an assignment. A reviewed hidden-program template-selection divergence was verified unreachable: a first screen holding a compiled program never builds a command batch (the programs guard throws first), and program nodes are the only visibility carriers the template walk does not narrow. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
…test wire Two corrections to the merge resolution, caught by the full run: - The react-parity audit records were resolved to the train side, but the sync regenerated them against upstream v0.1.47 — the tree the merge actually contains — so the parity contract tests read stale execution records (tsconfig lanes pointing at pre-sync paths). Restored the sync side for every conflicted audit and restamped lockfileSha256 against the merged lockfile. - The new first-screen wire and compact-ack tests were written against the pre-codec fork base and put raw objects on the ContextProxy; since the transport owns encoding (#164), such a message never decodes and the reply never fires. They now wire/unwire through the shared fixture, and the reply-cost budgets measure the encoded string that actually crosses instead of a re-print. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
Clean catch-up after #229 landed; the gate tree already carried both sides. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
Huxpro
marked this pull request as ready for review
August 29, 2026 03:06
This was referenced Aug 29, 2026
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two unbounded main-to-background replies, found by the same investigation and
fixed here. Both are the main thread answering a question with the whole page
when a constant would do, and both are invisible to every count the benchmark
harness reports.
main-readyreply carried the entire first-tree description tocommunicate one bit. A 30,000-row page shipped ~37 MB to say "a first screen
was painted here."
one, so every
createafter the first answered with one handle per host:70,000 handles, 17.4 MB, for the benchmark's second
Create 10,000 rows.They are independent defects in the same direction (MTS→BTS), and they are the
only two anomalies in that direction across the whole benchmark coordinate
system.
Why
#231: a boolean shipped as a tree
The background needs one bit out of the
main-readyreply: a first screen waspainted here, so the first background batch must preserve its IDs.
transport.tscomputed exactly that —
message.firstTree !== undefined— and nothing inpackages/lynx/srcever read a node out of the snapshot it tested. Below thischange the only way to state the fact was to attach the whole description, so a
correlated reply was O(painted tree), and
protocol.tsthen validated it node bynode on receipt.
#231 reported this as a 30k scale cliff introduced by the fork. Its own run file
refutes both halves, and the evidence is on the issue:
issue's
upstream = 1,688 Bcolumn is the median of a bimodal sample.race, not a threshold.
wireToMtsBytesmoves with it positionally and withoutexception: every rep that received the correlated
main-ready-requestwhilethe main thread still held the first-tree journal shipped ~37 MB back.
Row count matters only because the ~8 s paint at 30k holds that window open. The
unbounded reply was always there.
#230: compact-v1 worked exactly once per root
main-thread.tspicks the acknowledgement encoding from a host count thatpreparation records. Preparation records that count only while it is itself
driving the compact path — and taking that path installs a
LynxDenseHostRecordStoreasstate.records(host-driver.ts:6955), whichincrementalCompactCandidaterejects because it asks for aMap(
host-driver.ts:6417). So the second identical run on the same root arriveswith no prepared count, and the non-provisional branch read that absence as "not
compact."
Read out of a browser trace, single variable:
That accounts for every shape of the measurement on #230: only
createisanomalous, because only
createis a single largemount-template-runarrivingon the non-provisional path; it is deterministic 7/7, because the store leaves
Mapon sample 1 and never returns; and 70,000 handles for 10,000 rows at 7hosts each is the 17,420,700 B the issue reports.
The count is a property of the batch, so the fix recomputes it rather than
letting the container the driver happens to be holding records in decide a wire
encoding.
Changes
#231
packages/lynx/src/core/protocol.ts: newLYNX_FIRST_TREE_PRESENCE_READY_REQUEST_BASErung (2 ** 45) andfirstTreePainted?: 1onLynxMainReadyReply, rung-gated and mutuallyexclusive with
firstTreeinassertReady.packages/lynx/src/main-thread.ts:dispatchReadypicks the encoding from thepeer's rung; every downstream branch now turns on whether the reply announces a
first tree rather than on which encoding carried it.
packages/lynx/src/core/transport.ts: the background announces at the new rungand reads either encoding.
packages/lynx/tests/first-screen-ready-wire.test.ts(new): the wire-bytebudget.
firstTreePainted: 1is the same shape every other optional reply key alreadyuses, and for the same reason: a peer below the rung validates against an exact
key set and would reject a key it has never heard of.
The description route is kept, not approximated away. A peer below the rung
still receives the snapshot, because presence is the key for it — sending the
bit alone would tell it no first screen happened at all, and it would rebuild the
page over the command path with fresh IDs. Both skew directions are therefore
safe: an old main thread sends
firstTreeto a new background, which still readsit; a new main thread sends
firstTreeto an old background, which never seesthe new key.
The main thread's own cost goes with it.
firstTree.snapshotis built on firstread (#148), and the presence path never reads it, so a first screen that hands
off this way never allocates a description of itself either.
#230
packages/lynx/src/main-thread.ts: the non-provisional branch of theacknowledgement gate gets the same recompute fallback the provisional branch
already had.
packages/lynx/tests/block-first-screen.test.ts: a regression that drives twocompact-eligible runs on one root, separated by a clear, and reads main's own
replies off the wire — the second must still negotiate
compact-v1and carryno
handles.The safety net immediately below the gate is unchanged and does the work that
makes this sound: a recomputed count that disagrees with what preparation
actually produced is re-validated against
prepared.handleDelta— the lengthsmust match and every delta must be a generation-1
create— and falls back tolegacy if it does not.
No check was deleted. In particular this does not remove the
state.records instanceof Maptest inhost-driver.ts, which guards a real castat
:6951where the prefix for the next dense store is copied. Why a recordstore's representation gets to decide a wire encoding at all is a real question,
and it is deliberately left for its own issue rather than smuggled in here.
Benchmarks
benchmarks/lynx-table/{workload.ts,first-screen-selectors.mjs}: thefirst-screen selector suite now measures main-to-background wire bytes against
a 4,096 B budget.
That budget does not guard At 30k rows the "wire-free" first screen ships 42 MB to the background #231's description, and the code now says so in
place. Both of its arms render from the background, so main never captures a
first tree and has no description to send: measured on the fixed build it reads
468 B at 1,000 rows, 470 B at 30,000, and the same 470 B with the background
dropped below the presence rung. What it does bound is the rest of the
handshake — that answering a request and acknowledging a commit stays flat
however large the page gets. The description's own budget lives in
packages/lynx/tests/first-screen-ready-wire.test.ts, where a main-thread paintexists to produce one. An earlier revision of this body described the bench
budget as if it caught At 30k rows the "wire-free" first screen ships 42 MB to the background #231;
73882702acorrects the claim rather than thecheck.
Measured effect
create, one window, one machine, three entries including upstream v0.1.47,--reps 7, quiet box (#39 protocol). Before/after are the same tree builtminutes apart.
Wire, MTS→BTS — the direction both defects live in:
create@1,000create@10,000startup@30,000The command stream (BTS→MTS) is untouched: 350,885 B against upstream's
350,774 B, 1.000×.
Latency and CPU (ms, median ±CI95, n=7):
mtsCpubtsCpuSo the acknowledgement was most of the residual at 1,000 rows (71% of it) and a
real but minority slice at 10,000 (22%). It does not close #230, and the
remaining ~728 ms is reported there rather than claimed here.
Validation
pnpm format:check— viapnpm format:fileson every changed pathpnpm typecheck— cleanpnpm test— 2,443 of 2,448 files, 26,718 of 26,725 tests pass, on aquiet box. Five files fail and none are this change's:
packages/drei/tests/browser/upstream-e2e.browser.test.tspackages/octane/tests/browser/suspense-hydration/suspense-hydration.test.tspackages/rspeedy-plugin-octane/tests/native-demo.test.tspackages/octane/tests/react-hosted/web3-island.test.tsbeforeAllhook timed out at 10,000 mspackages/octane/tests/hydration/deferred-hydration.test.tsvi.waitFornever convergedThe last two are deadline failures under full-suite load, not assertions about
behavior: both pass in isolation on this head, and the diff touches nothing
outside
packages/lynx,benchmarks/lynx-table, and two changesets.A first full-suite run on this same head is deliberately not the one
reported here. It overlapped the benchmark above — four Vitest workers and
three Chromium instances on one box — and produced six extra deadline failures
of the same shape. It is discarded, not averaged in.
targeted tests: whole
packages/lynxproject green (45 files, 686 tests).Both new regressions red-verified by reverting only the product change:
first-screen-ready-wire.test.tsby breakingannouncesByPresence(2 of 3cases fail), the The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230 case by restoring the old gate expression (it then
reports the legacy encoding and a populated
handles).node first-screen-selectors.mjsat rows=1,000 and rows=30,000, bothhandshake arms: 468 B and 470 B against the 4,096 B budget.
The #231 unit budget asserts the reply is byte-identical at 50 and 400 rows and
under 512 B, and proves it can fail by driving a peer below the rung and watching
the same reply grow past 4×; a companion case asserts that peer still receives
all 401 nodes.
first-screen.test.ts's end-to-end adoption scenario now runsthrough the presence encoding and still asserts preserved node identity and
replayed events — that scenario is the evidence the handoff is unchanged, and the
assertion it used to make about the description now says so in place.
Risk / follow-ups
main-readyencodings are a version-skew surface. They are mutuallyexclusive on the wire and both directions of skew are covered above, but the
fallback exists only for peers that predate this rung and can be deleted once
none are deployed.
structured clone as "a plausible common cause" for
heapMtsAfterClearand fora second-position stall, and separately flagged
transport.ts'sadoptingFirstTreeas "a suspect in The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230's create residual". All three are nowrefuted, measured rather than argued:
the third run of the same ordering completed. A fresh browser per entry over
a static server means no application state carries between them.
heapMtsAfterClearis unmoved by removing 17.4 MB of per-createhandlerecords: 17,850,904 B before against 17,863,780 B after, a ratio of 1.0007.
It splits by cause instead — against the pre-sync control, +3.15 MB is the
block core's
array:growth, present since v0.1.36, and +924,152 B is new atthe v0.1.47 sync (
string:row1→10,001, ~1 extraExternalStringDataperrow). That belongs to The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230's remaining residual.
adoptingFirstTreeis not The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230's cause. Rebuilding the same entry with thebackground dropped below the presence rung reproduces the pre-At 30k rows the "wire-free" first screen ships 42 MB to the background #231 encoding
exactly and yields a byte-identical acknowledgement decision, so At 30k rows the "wire-free" first screen ships 42 MB to the background #231 neither
causes nor cures The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230. The actual cause is named above and fixed here.
bench:first-screen-selectors, which is not a CIjob; the unit budgets in
packages/lynx/testsare the ones CI enforces.chore/sync-upstream-v0-1-47(chore: sync new-lynx with upstream octane v0.1.47 (d5175ca8) #229), whose rebase and gate belongto the gatekeeper.
ci.ymltriggers on
pull_requestonly for base branchesmainandnew-lynx, andthis one targets the sync branch, so no CI job is skipped-because-draft here —
none is queued at all, in any state. The local validation above is therefore
the whole gate until the base lands and this is retargeted. Recording it so the
empty check list is not read as "CI passed" or as a draft artifact.
Provenance
agent-authored)