You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to #58, per the L0 spec (docs/lynx-specialized-target-l0.md §3.2–§3.6; PR #59). L0 proved the floor with a standalone cell; L3 lands it in the real @octanejs/lynx stack.
Replace the renderPlanNode → FirstScreenNode[] → UniversalHostBatch → prepare → apply first-screen pipeline with compiler-emitted create functions, for both immediate and engine render modes. L0 measured this pipeline (not the plan walk alone) at ~676 ms of FCP@10k on the reference host — same-window 0.575×.
Adoption on compile-time identity: (templateId, instance ordinal) instead of runtime-minted logical IDs + snapshot field comparison; should collapse most of core/first-screen.ts and per-node ack/handle machinery. Mismatch repair/remount and source-attributed diagnostics stay at parity.
Slot-table applier replacing generic host apply on the update path (mt_validate + mt_apply_other measured at ~300 ms of create@10k).
Event token routing with embedded priority and buffered replay before background-listener acceptance, unchanged in contract.
Deferred capability details tracked here (from the L0 pass): native .lynx.bundle element-template sections as an alternative static-structure carrier (Roadmap: replace the universal-renderer target for Lynx with a Lynx-specialized compiler and renderer #58 open question 2 — needs the native encoder surface; web JSON bundles have none), first-screen host-spread and callback-erasure rule parity, and keeping the octane-direct benchmark cell green as the floor reference while L1–L3 land (re-measure per phase).
Exit gate (from #58): plan_interpretation eliminated from FCP attribution; adoption mismatch diagnostics at parity; first-screen host-spread and callback-erasure rules preserved.
L3 adoption identity under slot-addressed templates: semantics
Design note for the L0 §3.6 line item. No code changes. Everything below is read against claude/octane-issue-58-l3-direct-first-screen @ 2fe1446, where L3's first slice
(applyLynxFirstScreenDirect) has landed and capture/compare are still the Milestone-6 ones.
Notation:L0 §x.y cites docs/lynx-specialized-target-l0.md; a bare §x cites a section of
this note. R1–R7 are the normative rules.
0. Correcting the premise the spec is written on
L0 §3.6 says adoption keys off "(templateId, instance path) … instead of runtime-minted logical IDs
plus snapshot field comparison". The first half of that contrast does not hold, and getting it right
changes the whole design.
Today's logical IDs are already positional pre-order ordinals, not minted identities. assignIds walks the rendered record tree pre-order from attempt.nextId = 1
(packages/lynx/src/main-renderer.ts:986-991, :1065), and the background program does the same
walk over the same logical tree from the same seed. The L3 applier's own comment says so:
"Ids are the pre-order ids the background renderer will independently assign, so adoption identity
is positional, not minted." (packages/lynx/src/core/host-driver.ts:2870-2873).
So the change L3 actually makes is not positional-vs-minted. It is granularity: from
per-node field comparison to per-template-instance comparison. That is where the win is, and it
is a real one — but it is a different win from the one L0 §3.6 describes, and it has a different set of
preconditions.
Two consequences fall straight out, and both are load-bearing below:
The ordinal must become hierarchical. Today's pre-order counter numbers every logical node
including ranges (assignIds recurses unconditionally; logicalCount is the full logical count, main-renderer.ts:1130, while only hosts reach the batch via visitHosts, :1097-1099). A flat
counter renumbers everything after any insertion. Under a flat "creation ordinal", partial
adoption degenerates to "adopt the pre-order prefix up to the first divergence, remount the rest"
— which for a divergence near the root is barely better than today's all-or-nothing. Range-local
ordinals are the precondition for scoped repair, and L0 §3.6's wording ("creation ordinal") reads as
the flat kind. This needs to be settled explicitly, not inherited.
Logical IDs do not go away. They stop being the matching key and remain the addressing
key: getPublicInstance(container, id) backs event re-resolution (main-thread.ts:1549),
host-attachment deltas (:1654), nodes-ref selectors (host-driver.tscreateHandle), and the
ack handle protocol. (templateId, path) is the identity; a dense integer stays the handle.
1. Normative model
Coordinates. All compile-time except memberSelector and epoch:
Anchor ::= (parentInstance, anchorSlotIndex) -- a slot whose kind is a range/branch anchor
Member ::= (Anchor, memberSelector) -- memberSelector = authored key, else ordinal
Instance ::= (Member, templateId, epoch) -- what was instantiated at that member
Path ::= [Member] -- root-relative, hierarchical, range-local
Slot ::= (Instance, slotIndex) -- kind from the template's slot table
epoch starts at 1 and increments when an instance is destroyed and recreated at the same Path.
It is the successor of today's per-node generation (host-driver.tscreateHandle, seeded to 1
by the direct applier at :2959) and it stays mandatory — see §3.3.
The capture record. Per instance, replacing LynxFirstTreeNodeSnapshot
(packages/lynx/src/core/first-screen.ts:14-24, which today carries id/nativeId/type/generation/
parent/children/props/visible/events per physical node):
Interior node types, topology, static props, and event sites are not captured at all: they are a
function of templateId (compile-universal.js:3967-4022 emits them as straight-line env.h/p/e/t/a calls; main-renderer.ts:701-739 is the first-screen binding).
Comparison is two-phase and the phases are not symmetric.
R1 — Shape phase. Walk both sides' anchor trees in lockstep. At each Anchor compare the member sequence: (memberSelector, templateId) pairs. Anything that differs here is a shape
divergence, scoped to that Anchor.
R2 — Value phase. For every Instance the shape phase paired, compare the two values arrays
element-wise, dispatching on the compile-time slot kind. Differences are value divergences,
scoped to the Slot.
R3 — The value phase is total and mandatory. Matching templateIds never license skipping it.
(Proof obligation, not style: useId is a global render-order counter, main-renderer.ts:1230-1236, :1070. A shape divergence anywhere shifts every later useId, and
those values surface as ordinary p:/c: slot values in id/for/aria-* props. Under today's
all-or-nothing repair that is invisible; under scoped repair it is exactly how an "adopted" region
silently ends up with stale identifiers. Only a total value walk catches it.)
R4 — Value divergence never escalates to shape divergence, and shape divergence never
de-escalates. A c:-kind slot is the one case where a value difference IS a shape difference
(the hole materialized different structure); it is classified as shape at the child anchor, not as
a patchable value.
R5 — Repair scope is always a whole Anchor's member range or a whole Instance subtree, never an
individual interior node. Interior nodes have no independent identity to repair to.
Slot-kind dispatch (kinds as emitted today by lynxTemplateSlotKinds, compile-universal.js:3943-3957):
kind
divergence is
repairable by
p:<name>
value
one PAPI setter — SET(instance, slot, value)
e:<name>
binding presence only (priority is compile-time from the prop name, main-renderer.ts:729)
Add/RemoveEvent; invalidates tokens on that slot
c → text on both sides
value
SET
c → anything else
shape at that child anchor
destroy + RUN
Handler identity on an e: slot is not comparable across threads and must not be compared: the
main graph's handlers are DCE'd stubs. Today's compare only ever checks listener id/priority
(host-driver.ts:3314-3352), and that stays right. What is newly comparable is presence: the
first-screen env drops a non-function handler silently (main-renderer.ts:728), so function ↔ null across the two renders is a real divergence today that compare catches only as an
event-count difference (:3321-3332).
2. Repair-vs-remount decision table
"Repair(scope)" = destroy the instances under scope and apply the background's RUN/SET for
them. "Remount" = Repair(root), i.e. exactly today's behavior. "Adopt+patch" is the new third
outcome that does not exist today — firstTreeAction is currently a two-valued 'adopt' | 'repair' (host-driver.ts:4938) and adoption drops the entire first commit
(:5090, applicationOperations = firstTreeAction === 'adopt' ? [] : operations).
#
Observed
Phase
Outcome
Scope
Buffered tokens in scope
Diagnostic
1
p: slot value differs
R2
Adopt+patch
Slot
kept
debug
2
c: slot, text on both, differs
R2
Adopt+patch
Slot
kept
debug
3
e: slot, both handlers present
—
Adopt
—
kept
none
4
e: slot, present ↔ absent
R2
Adopt+patch
Slot
dropped (that slot)
warn
5
@if/@switch anchor: arms differ
R1
Repair
Anchor
dropped (subtree)
warn — init-data race
6
@try anchor: MT @pending, BG primary/@catch
R1
Repair
Anchor
dropped (subtree)
info — expected transition, not a mismatch
7
Keyed range, same key set, different order
R1
Adopt + MOVE
Anchor
kept
debug
8
Keyed range, BG superset (3 → 4)
R1
Adopt matched + RUN new
Anchor
kept for matched
warn
9
Keyed range, BG subset
R1
Adopt matched + REMOVE
Anchor
dropped for removed
warn
10
Unkeyed / index i range, length or content differs
R1
Adopt longest matching prefix, Repair remainder
Anchor suffix
dropped past prefix
warn
11
Root-level member sequence differs
R1
Repair
root range
dropped
warn
12
templateId absent from the peer template table
fault
Remount
root
dropped
error — build skew
13
Slot stride ≠ template's declared slot count
fault
Remount
root
dropped
error — build skew
14
Container invariants: root id / page ref / worklet registry / version / owner stability
Rows 12–15 are deliberately un-scopable. 12–13 mean the two builds disagree about the template
table, so no coordinate in the capture can be trusted. 14–15 mean the main thread's own journal is
untrustworthy — 15 in particular is an anti-tamper check on the MT tree between capture and adopt
(native recycled a node), and once one node is suspect the ownership journal that transferFirstTree reads (:3345-3400) is suspect wholesale.
3. Per-case walkthroughs
3.1 Init-data race: BTS takes a different @if arm
Today. The MT painted arm A. The plan node is if, which materializes to [range(renderPlanNode(selected, values))] (main-renderer.ts:784-787) — no arm tag is recorded
anywhere. Arm B renders a different node count, so finalIds.size differs from snapshot.nodes.length and compare bails at the host count check (host-driver.ts:3257-3259)
before it ever reaches the diverging node. If the counts happen to coincide, it bails at the first
per-id type mismatch (:3271-3272). Either way: firstTreeAction = 'repair' (:4938), disposeLynxFirstTree tears down the entire first screen (:4980-4990, delegating to disposeLynxHostContainer, :5796-5797), and the whole background batch replays as fresh creates.
One flipped boolean near the root repaints 10k nodes.
Slot-addressed. R1 compares, at the @if's Anchor, (memberSelector=0, templateId). Arm A is
templateId 7, arm B is templateId 9 → shape divergence scoped to that Anchor. Everything outside
it — every sibling range, every ancestor template's own slots — proceeds to R2 independently.
Outcome: Repair(Anchor). The background's first commit for that Anchor is BRANCH(anchorSlot, 9, values…) (L0 §3.4), which is already exactly the opcode the steady-state path would emit for the same
transition. Adoption and steady-state converge on one mechanism.
What is compared: both. Template identity settles the shape; slot values settle the rest, and R3
makes the value walk unconditional. Neither alone is sufficient — template identity alone would
adopt a tree whose every useId shifted, slot values alone cannot detect an arm swap whose arms
happen to have the same slot arity.
Is partial adoption definable?Yes, at Anchor granularity, under four preconditions, and it is
not definable without all four:
Range-local ordinals (§0). With the flat pre-order counter, a divergence renumbers every
later instance and "partial" collapses to "prefix".
A recorded arm/member tag. The capture must start recording which arm/how many members —
data no representation on this branch carries. @if today has no arm tag (above), and plans
containing @if/@for/@switch/components are not template-eligible at all: lynxTemplateEligible accepts only host/text/slot and is gated at the plan root
(compile-universal.js:3928-3941, :4055-4056), so any component with control flow emits zero
create functions today. L0 §3.4's BRANCH and range framing are the presumed representation, not
the landed one. This is the single largest piece of unbuilt work behind L0 §3.6.
Subtree-scoped ownership transfer.transferFirstTree is whole-container: it moves every
record, then clears the source and marks it disposed (host-driver.ts:3345-3400). disposeLynxFirstTree likewise disposes the whole source container (:5786-5798). Both need
subtree variants that preserve the existing retry-safety contract (:5800-5804) — a partial
dispose that faults mid-walk must leave a container that a repeated dispose can still finish.
Prepare/apply atomicity must survive. The background's first commit will now mix SETs
against adopted instances with RUNs against repaired ones. The staged-prepare/mutating-apply
split (:4954-5090) is what makes that atomic, and the slot-table applier's table dispatch does
not replace it. Ordering within an Anchor is destroy-before-create, or physical child order is
wrong.
Preconditions 1 and 2 are compiler/representation work; 3 and 4 are host-driver work. Until 1 and 2
land, partial adoption is not definable and all-or-nothing is the correct conservative posture —
which is what the L3 slice on this branch (correctly) preserved.
3.2 Instance ordinals under divergence: MT 3, BTS 4
Do shared-prefix ordinals stay matchable? Only if memberSelector is the authored key. With
ordinals, a prepended item mismatches all three survivors and repaints a list that changed by one
row — the exact init-data race that motivates adoption. So:
R6 — For a range with an authored key, memberSelector is that key. For an unkeyed or index i range, it is the ordinal, and matching is longest-common-prefix only.
@for's key clause is optional in Octane today (@for (const item of props.items) and @for (…; index i) both appear in-tree, e.g. packages/octane/tests/_fixtures/ssr-control.tsrx:17, packages/devtools/src/panel/ProfilerTab.tsrx:40), so R6 cannot assume keys. For index i ranges
the ordinal-suffix rule is not merely conservative but required: member content is index-derived,
so a shift changes every later member's slot values anyway.
R6 has a cost worth naming: the key is a per-instance runtime string that must be captured. It is
precisely the "snapshot field comparison" L0 §3.6 wanted deleted, reintroduced: one string per range
member instead of a full node record per node. Orders of magnitude smaller, but not zero, and it
brings a new determinism obligation (§4.2, item 7).
The first commit against an adopted range. Today adoption discards the entire first commit
(host-driver.ts:5090). That is only sound because adoption is total. Under partial adoption the
first commit becomes a residual, computed during prepare:
RUN(templateId, anchorSlot, 1, values₃…) -- the one unmatched member
MOVE(instance, before) -- only if keyed matching reordered survivors
SET(instance₀…₂, slot, value) -- per R3, for every value-divergent slot
Note what is absent: no creates for members 0–2, no re-application of their static structure. That
residual is the delta protocol's ordinary vocabulary (L0 §3.4) — adoption stops being a special commit
mode and becomes "the first commit, computed against a non-empty starting state". That is a genuine
simplification, and it also removes today's structural precondition that the background root be
completely empty (host-driver.ts:3563-3582).
Against a repaired range, the first commit for that Anchor is the full RUN, preceded by the
repair's destroys, and identical to what a cold start would emit. Both forms coexist in one commit
message; precondition 4 above is what keeps that safe.
3.3 Event token continuity
The current mechanism, precisely. Capture builds eventsByToken: native registration token → {host, generation, type, listener, priority} (host-driver.ts:3064, :3083-3101). A delivery
arriving during the adoption window is resolved at arrival through the MT journal
(main-thread.ts:1517-1518, core/first-screen.ts:109-115) into a logical target {host, generation, type, priority} — and the listener id is deliberately discarded
(main-thread.ts:1525-1531). At drain, that logical target is re-resolved against the adopted
container: instance must exist with the same generation, still be attached, and expose a listener of
the same priority for that type; the background's listener id is then used
(:1545-1566). Anything else throws "stale, hidden, removed, or foreign native event".
That arrival-resolve / drain-re-resolve indirection is the right design and must survive verbatim.
It is what makes tokens adoption-safe at all.
Under slot addressing. The token becomes s:<path>:<eventSlotIndex> (L0 §3.5's s:<rowId> form).
Arrival resolves it to (Path, eventSlot, epoch); drain re-resolves (Path, eventSlot) to the
background's listener. Two things get structurally better:
The priority equality check (main-thread.ts:1562) becomes a compile-time invariant: priority is
derived from the event prop's name (main-renderer.ts:729), which is baked into the create
function, so both sides cannot disagree.
The deterministic listener-counter coupling disappears entirely — see §4.1.
When the adopted tree came from repair. Today repair drops the entire buffer
(main-thread.ts:2211, and again on fault at :2296, :2309). That is correct-but-over-broad once
repair is scoped: a tap on an untouched sibling range was perfectly resolvable and got discarded.
The rule:
R7 — A buffered delivery is delivered iff the instance at its captured Path exists after the
commit AND its epoch is unchanged AND its event slot still carries a handler. Otherwise it is
dropped with a diagnostic. It is never redirected to a replacement instance at the same Path.
The epoch is what makes R7 decidable, and it is why generation does not become unnecessary:
under positional identity, Path alone cannot distinguish "adopted" from "destroyed and recreated
in the same position". Redirecting to the replacement would violate the plan's hard invariant — "It
must never silently attach the wrong logical identity"
(docs/lynx-native-renderer-plan.md:283-284) — because the replacement's handler closed over
different data than the one the user physically tapped, and may not even be the same templateId.
R7 is strictly better than today's contract (drop only the repaired scope's buffer) while preserving
that invariant. The MAX_FIRST_SCREEN_EVENT_DELIVERIES = 128 backpressure cap
(main-thread.ts:211, enforced at :1597-1607 and :1613-1622) is unaffected.
When slot-addressed instances replace logical-ID handles. They don't, fully — see §0 point 2. getPublicInstance (main-thread.ts:1549) and the handle/selector surface stay integer-addressed.
The concrete requirement is that Path → id be resolvable on the main thread at drain time, which
means the adopted container must carry a path index, not just the record map. That is new state the
current LynxHostState does not hold, and it is the piece of "per-node handle machinery" that L0 §3.6
expects to delete but which R7 in fact requires.
3.4 Suspense on the first screen
This is the one divergence that is guaranteed rather than racy, and it is the strongest argument
for scoped repair.
The MT first-screen pass is one-shot: it throws if it suspends without an authored @pending
(main-renderer.ts:1084-1089). So @try reliably paints the pending arm while the background
resolves the primary body. Today that is a whole-tree repaint every time.
How compile-time identity expresses "this range was the fallback and is now replaced": it does not need a dedicated expression. L0 §3.4 already frames @try/@pending/@catch as a
range with BRANCH at the boundary anchor. So the boundary is an Anchor with three compile-time-known
arms, the capture records arm = pending, the background's first commit records arm = primary, and
R1 sees an arm difference at that Anchor. Identical mechanism to §3.1's @if. Suspense is not a
special case — it is the flagship case.
The structural preconditions hold already: renderTry returns [range([range(…)])] for all
three arms (main-renderer.ts:812-848), so the boundary's frame depth is arm-independent, and both
arms occupy the same slot in the same parent template by construction. What is missing is only the
arm tag itself, per precondition 2 above.
Two things must be got right that @if does not raise:
Diagnostic class.@pending → primary is the intended transition, not an app defect.
Reporting it through LynxFirstTreeMismatchError / "Octane Lynx repaired a first-screen mismatch"
(core/first-screen.ts:52-67, main-thread.ts:2163) is a false alarm on every suspending first
screen, and false alarms are how a real mismatch diagnostic gets ignored. Same mechanism, different
severity: row 6 is info, row 5 is warn. The adoption: 'adopted' | 'repaired' ack field
(main-thread.ts:2255) needs a third value for partially-adopted, and arguably a fourth for
"adopted with expected boundary swaps".
useId checkpointing.renderTry already restores attempt.nextUniversalId when the body is
abandoned (main-renderer.ts:814, :826) so the fallback and the primary get the same starting useId. That checkpoint discipline must be preserved verbatim by whatever emits the boundary
arms; without it R3 turns every suspending first screen into a cascade of value divergences past
the boundary.
Worth noting for scheduling: if the background's first commit is taken while the primary body is still suspended, both sides show arm = pending, adoption is total, and the swap is an ordinary
later BRANCH with no adoption machinery involved at all. Taking the background's first commit at
the same suspense stratum the MT painted is therefore the highest-value non-representational lever
on adoption rate. Listed as unresolved.
4. Determinism obligations after the change
4.1 What the scheme actually makes unnecessary (proven against compareFirstTree)
Today's check
Fate
Why
per-node type (host-driver.ts:3271-3272)
deleted
interior types are literals in the create function (compile-universal.js:3987-3996)
per-node parent / children order (:3281-3291)
deleted within a template; survives as R1 member-sequence comparison across ranges
interior topology is the create function's env.a call order (compile-universal.js:4020-4025)
per-node event count / type / priority (:3314-3352)
deleted
sites are env.e calls; priority derives from the prop name (main-renderer.ts:729)
per-node visible (:3291-3294)
deleted for template interiors
visibility is owner-inherited (main-renderer.ts:710), constant within an instance
L0 §3.5 tokens are compile-stable strings with instance identity embedded; no counter to agree on
snapshot.nodes[] node records (core/first-screen.ts:14-24)
deleted, replaced by per-instance descriptors
~40 lines of type + the ~100-line builder at host-driver.ts:3064-3160
The listener-seeding deletion is the most valuable single item on this list. Today both programs must
independently reach 1_000_000 and count event sites in identical order
(main-renderer.ts:1063-1070) — a coupling that is invisible in source, has no diagnostic when it
breaks, and fails on any render-order difference. The L3 slice on this branch is still bound to it: applyLynxFirstScreenDirect consults the staged batch only for its event commands specifically
so the assignment stays single-sourced (host-driver.ts:2893-2898, :2921-2932). Killing that
coupling is also what would let the direct path stop building the batch at all.
4.2 What remains an app/compiler obligation
Same init data → same shape stream. Untouched. The scheme changes the cost of divergence,
never its likelihood. This is the entire content of §3.1 and §3.2.
Thread-DCE correctness. Untouched (docs/lynx-native-renderer-plan.md:902-903). DCE that
removes something shape-bearing still diverges the two graphs.
No render side effects, no nondeterministic render. Untouched and more important than
today. Under all-or-nothing repair, nondeterminism is loud: the whole screen repaints. Under
scoped repair it is quiet and data-dependent. Partial adoption is a net regression in
observability unless it ships with per-Anchor diagnostics and a test-mode "any repair is a
failure" switch. That switch should be considered part of the feature, not a follow-up.
templateId stability across the two builds — NEW, and stronger than anything today. The two
graphs are separate Rspack layers over the same entry
(docs/lynx-native-renderer-plan.md:883-886). Today the shared identity is the plan object
reached through the same import (compile-universal.js:4051-4057) plus a renderer-id check
(main-renderer.ts:1078-1081) — resilient to build skew because it is reference identity, not a
number. A numeric templateId is not. If ids are assigned by emission counter, the two layers
diverge whenever they tree-shake differently. templateIds must be content- or source-position-
derived, never emission-ordinal-derived, and rows 12–13 of the decision table exist to catch it
when they are not.
Slot-index stability across the two builds — NEW. Same argument one level down. L0 §3.3 says
"same discipline as hook slots", which is the right precedent, but it is a second and much larger
index space, and unlike hook slots a skewed slot index is silently type-correct.
Main-thread worklet / ref _execId tolerance. Survives verbatim. sameAdoptableSnapshotValue
exists precisely because "first-screen and background graphs assign different local execution
tokens" (host-driver.ts:2689-2745), and the slot-value comparator inherits that exception
wholesale. Nothing about slot addressing makes it unnecessary.
Key determinism — NEW, if R6 lands. Making the authored key the match selector turns "key
derived from a nondeterministic source" from a benign inefficiency into an adoption failure with
no existing diagnostic.
useId ordering. Untouched, and newly load-bearing via R3 (§1) and the renderTry checkpoint
(§3.4).
Net: six obligations survive unchanged, three are new (4, 5, 7), one is genuinely retired
(listener seeding). That is a real simplification, but it is not the direction L0 §3.6 implies — the
scheme trades a runtime determinism obligation for two build-time ones.
4.3 Where "matching becomes an array-index walk" overpromises
True, and understated, inside a template instance. Given a matched templateId there are zero
comparisons of interior structure, not an index walk. Better than claimed.
True for the whole tree only when the tree has no ranges — one templateId check plus a flat
value walk. This is the shape of the L0 prototype's fixture, which is where the claim comes from.
False as soon as ranges exist, which is every real app. A range's member sequence is a runtime
sequence; comparing two possibly-different-length runtime sequences while preserving survivor
identity is a reconciliation problem, not an index walk — it is the same LIS-shaped problem the
background reconciler already solves (L0 §3.4). The index walk is the degenerate case where nothing
diverged.
False for all four cases in this note, which is the point: every one is a case where the walk
terminates in "unequal", and the entire design content is what happens next.
Names the wrong file for the collapse. L0 §3.6 expects this to "collapse most of core/first-screen.ts". That file is 115 lines and is mostly the event-token journal
(:69-115) and the error class (:52-67) — neither of which the scheme deletes, and R7 makes the
journal more load-bearing, not less. What actually collapses is in host-driver.ts: the
~100-line snapshot builder (:3064-3160) and the ~90-line per-node field walk (:3263-3352). The
node-snapshot types in first-screen.ts:5-38 do collapse; the journal machinery gains
responsibility.
Understates the wire win, which is the real prize. The deleted comparison is per-node; the
deleted transfer is per-node too. L0 §3.6 frames this as a comparison-cost story, but §3.2's
residual-first-commit is the larger structural change: it removes the "background root must be
completely empty" precondition (host-driver.ts:3563-3582) and merges adoption into the ordinary
delta vocabulary.
5. Unresolved
Flat vs hierarchical ordinal. L0 §3.6 says "creation ordinal", which reads flat. Partial
adoption requires range-local. This is the one decision that must be made before any code, because
it is a wire-format decision.
Anchor/branch representation is unbuilt.lynxTemplateEligible rejects any plan containing
control flow, at the plan root (compile-universal.js:3928-3941, :4055-4056), so no component
with an @if or @for emits a create function today. L0 §3.4's BRANCH and range framing must land
before any of §3.1/§3.2/§3.4's semantics are testable. Sizing this is the next concrete step.
R6's key capture. Whether reintroducing a per-member runtime key is acceptable, or whether
ordinal-prefix matching everywhere is preferred as the simpler contract with a known worst case
(head insertion repaints the list). Recommendation: keyed, but this is a judgment call about
whether adoption rate or spec purity wins.
Partial-adoption blast-radius observability. §4.2 item 3. Needs a decision on whether the
test-mode strict switch ships with the feature.
Ack protocol shape.adoption: 'adopted' | 'repaired' (main-thread.ts:2255) is two-valued
and the compact-ack path is gated on firstTreeAction === 'none' (:2220-2225). Partial adoption
needs a richer ack, and it is not obvious whether the compact encoding can survive it.
Background first-commit stratum. §3.4's closing note: taking the background's first commit at
the MT's suspense stratum converts the guaranteed suspense divergence into a no-op. Worth
measuring before building scoped repair for it.
Whether scoped repair pays for itself at all. Everything above assumes a partial repaint beats
a full one. L0 measured FCP, not repair cost, and today's repair is a cold create of the whole
tree — the create path L0 measured at 1082 ms @10k on the current stack (862 ms on the
prototype). A scoped repair of 1% of the tree should be ~1% of that — but the prepare-side
residual computation is new cost paid on every adoption, including the ones that match
completely. That trade needs a measurement before it is designed in, not after.
Activity
Huxpro commentedon Aug 18, 2026
L3 adoption identity under slot-addressed templates: semantics
Design note for the L0 §3.6 line item. No code changes. Everything below is read against
claude/octane-issue-58-l3-direct-first-screen@2fe1446, where L3's first slice(
applyLynxFirstScreenDirect) has landed and capture/compare are still the Milestone-6 ones.Notation:
L0 §x.ycitesdocs/lynx-specialized-target-l0.md; a bare§xcites a section ofthis note.
R1–R7are the normative rules.0. Correcting the premise the spec is written on
L0 §3.6 says adoption keys off "(templateId, instance path) … instead of runtime-minted logical IDs
plus snapshot field comparison". The first half of that contrast does not hold, and getting it right
changes the whole design.
Today's logical IDs are already positional pre-order ordinals, not minted identities.
assignIdswalks the rendered record tree pre-order fromattempt.nextId = 1(
packages/lynx/src/main-renderer.ts:986-991,:1065), and the background program does the samewalk over the same logical tree from the same seed. The L3 applier's own comment says so:
"Ids are the pre-order ids the background renderer will independently assign, so adoption identity
is positional, not minted." (
packages/lynx/src/core/host-driver.ts:2870-2873).So the change L3 actually makes is not positional-vs-minted. It is granularity: from
per-node field comparison to per-template-instance comparison. That is where the win is, and it
is a real one — but it is a different win from the one L0 §3.6 describes, and it has a different set of
preconditions.
Two consequences fall straight out, and both are load-bearing below:
including ranges (
assignIdsrecurses unconditionally;logicalCountis the full logical count,main-renderer.ts:1130, while only hosts reach the batch viavisitHosts,:1097-1099). A flatcounter renumbers everything after any insertion. Under a flat "creation ordinal", partial
adoption degenerates to "adopt the pre-order prefix up to the first divergence, remount the rest"
— which for a divergence near the root is barely better than today's all-or-nothing. Range-local
ordinals are the precondition for scoped repair, and L0 §3.6's wording ("creation ordinal") reads as
the flat kind. This needs to be settled explicitly, not inherited.
key:
getPublicInstance(container, id)backs event re-resolution (main-thread.ts:1549),host-attachment deltas (
:1654),nodes-refselectors (host-driver.tscreateHandle), and theack handle protocol. (templateId, path) is the identity; a dense integer stays the handle.
1. Normative model
Coordinates. All compile-time except
memberSelectorandepoch:epochstarts at 1 and increments when an instance is destroyed and recreated at the same Path.It is the successor of today's per-node
generation(host-driver.tscreateHandle, seeded to1by the direct applier at
:2959) and it stays mandatory — see §3.3.The capture record. Per instance, replacing
LynxFirstTreeNodeSnapshot(
packages/lynx/src/core/first-screen.ts:14-24, which today carries id/nativeId/type/generation/parent/children/props/visible/events per physical node):
Interior node types, topology, static props, and event sites are not captured at all: they are a
function of
templateId(compile-universal.js:3967-4022emits them as straight-lineenv.h/p/e/t/acalls;main-renderer.ts:701-739is the first-screen binding).Comparison is two-phase and the phases are not symmetric.
Slot-kind dispatch (kinds as emitted today by
lynxTemplateSlotKinds,compile-universal.js:3943-3957):p:<name>SET(instance, slot, value)e:<name>main-renderer.ts:729)c→ text on both sidesSETc→ anything elseRUNHandler identity on an
e:slot is not comparable across threads and must not be compared: themain graph's handlers are DCE'd stubs. Today's compare only ever checks listener id/priority
(
host-driver.ts:3314-3352), and that stays right. What is newly comparable is presence: thefirst-screen env drops a non-function handler silently (
main-renderer.ts:728), sofunction ↔ nullacross the two renders is a real divergence today that compare catches only as anevent-count difference (
:3321-3332).2. Repair-vs-remount decision table
"Repair(scope)" = destroy the instances under
scopeand apply the background'sRUN/SETforthem. "Remount" = Repair(root), i.e. exactly today's behavior. "Adopt+patch" is the new third
outcome that does not exist today —
firstTreeActionis currently a two-valued'adopt' | 'repair'(host-driver.ts:4938) and adoption drops the entire first commit(
:5090,applicationOperations = firstTreeAction === 'adopt' ? [] : operations).p:slot value differsc:slot, text on both, differse:slot, both handlers presente:slot, present ↔ absent@if/@switchanchor: arms differ@tryanchor: MT@pending, BG primary/@catchMOVERUNnewREMOVEindex irange, length or content differstemplateIdabsent from the peer template tablehost-driver.ts:3196-3236):3301-3308)<list>anywhere in the treeskipped:3060,:3077,main-thread.ts:1913-1930)Rows 12–15 are deliberately un-scopable. 12–13 mean the two builds disagree about the template
table, so no coordinate in the capture can be trusted. 14–15 mean the main thread's own journal is
untrustworthy — 15 in particular is an anti-tamper check on the MT tree between capture and adopt
(native recycled a node), and once one node is suspect the ownership journal that
transferFirstTreereads (:3345-3400) is suspect wholesale.3. Per-case walkthroughs
3.1 Init-data race: BTS takes a different
@ifarmToday. The MT painted arm A. The plan node is
if, which materializes to[range(renderPlanNode(selected, values))](main-renderer.ts:784-787) — no arm tag is recordedanywhere. Arm B renders a different node count, so
finalIds.sizediffers fromsnapshot.nodes.lengthand compare bails at the host count check (host-driver.ts:3257-3259)before it ever reaches the diverging node. If the counts happen to coincide, it bails at the first
per-id
typemismatch (:3271-3272). Either way:firstTreeAction = 'repair'(:4938),disposeLynxFirstTreetears down the entire first screen (:4980-4990, delegating todisposeLynxHostContainer,:5796-5797), and the whole background batch replays as fresh creates.One flipped boolean near the root repaints 10k nodes.
Slot-addressed. R1 compares, at the
@if's Anchor,(memberSelector=0, templateId). Arm A istemplateId 7, arm B is templateId 9 → shape divergence scoped to that Anchor. Everything outside
it — every sibling range, every ancestor template's own slots — proceeds to R2 independently.
Outcome: Repair(Anchor). The background's first commit for that Anchor is
BRANCH(anchorSlot, 9, values…)(L0 §3.4), which is already exactly the opcode the steady-state path would emit for the sametransition. Adoption and steady-state converge on one mechanism.
What is compared: both. Template identity settles the shape; slot values settle the rest, and R3
makes the value walk unconditional. Neither alone is sufficient — template identity alone would
adopt a tree whose every
useIdshifted, slot values alone cannot detect an arm swap whose armshappen to have the same slot arity.
Is partial adoption definable? Yes, at Anchor granularity, under four preconditions, and it is
not definable without all four:
later instance and "partial" collapses to "prefix".
data no representation on this branch carries.
@iftoday has no arm tag (above), and planscontaining
@if/@for/@switch/components are not template-eligible at all:lynxTemplateEligibleaccepts onlyhost/text/slotand is gated at the plan root(
compile-universal.js:3928-3941,:4055-4056), so any component with control flow emits zerocreate functions today. L0 §3.4's
BRANCHand range framing are the presumed representation, notthe landed one. This is the single largest piece of unbuilt work behind L0 §3.6.
transferFirstTreeis whole-container: it moves everyrecord, then clears the source and marks it
disposed(host-driver.ts:3345-3400).disposeLynxFirstTreelikewise disposes the whole source container (:5786-5798). Both needsubtree variants that preserve the existing retry-safety contract (
:5800-5804) — a partialdispose that faults mid-walk must leave a container that a repeated dispose can still finish.
SETsagainst adopted instances with
RUNs against repaired ones. The staged-prepare/mutating-applysplit (
:4954-5090) is what makes that atomic, and the slot-table applier's table dispatch doesnot replace it. Ordering within an Anchor is destroy-before-create, or physical child order is
wrong.
Preconditions 1 and 2 are compiler/representation work; 3 and 4 are host-driver work. Until 1 and 2
land, partial adoption is not definable and all-or-nothing is the correct conservative posture —
which is what the L3 slice on this branch (correctly) preserved.
3.2 Instance ordinals under divergence: MT 3, BTS 4
Do shared-prefix ordinals stay matchable? Only if
memberSelectoris the authored key. Withordinals, a prepended item mismatches all three survivors and repaints a list that changed by one
row — the exact init-data race that motivates adoption. So:
@for's key clause is optional in Octane today (@for (const item of props.items)and@for (…; index i)both appear in-tree, e.g.packages/octane/tests/_fixtures/ssr-control.tsrx:17,packages/devtools/src/panel/ProfilerTab.tsrx:40), so R6 cannot assume keys. Forindex irangesthe ordinal-suffix rule is not merely conservative but required: member content is index-derived,
so a shift changes every later member's slot values anyway.
R6 has a cost worth naming: the key is a per-instance runtime string that must be captured. It is
precisely the "snapshot field comparison" L0 §3.6 wanted deleted, reintroduced: one string per range
member instead of a full node record per node. Orders of magnitude smaller, but not zero, and it
brings a new determinism obligation (§4.2, item 7).
The first commit against an adopted range. Today adoption discards the entire first commit
(
host-driver.ts:5090). That is only sound because adoption is total. Under partial adoption thefirst commit becomes a residual, computed during prepare:
Note what is absent: no creates for members 0–2, no re-application of their static structure. That
residual is the delta protocol's ordinary vocabulary (L0 §3.4) — adoption stops being a special commit
mode and becomes "the first commit, computed against a non-empty starting state". That is a genuine
simplification, and it also removes today's structural precondition that the background root be
completely empty (
host-driver.ts:3563-3582).Against a repaired range, the first commit for that Anchor is the full
RUN, preceded by therepair's destroys, and identical to what a cold start would emit. Both forms coexist in one commit
message; precondition 4 above is what keeps that safe.
3.3 Event token continuity
The current mechanism, precisely. Capture builds
eventsByToken: native registration token →{host, generation, type, listener, priority}(host-driver.ts:3064,:3083-3101). A deliveryarriving during the adoption window is resolved at arrival through the MT journal
(
main-thread.ts:1517-1518,core/first-screen.ts:109-115) into a logical target{host, generation, type, priority}— and the listener id is deliberately discarded(
main-thread.ts:1525-1531). At drain, that logical target is re-resolved against the adoptedcontainer: instance must exist with the same generation, still be attached, and expose a listener of
the same priority for that type; the background's listener id is then used
(
:1545-1566). Anything else throws "stale, hidden, removed, or foreign native event".That arrival-resolve / drain-re-resolve indirection is the right design and must survive verbatim.
It is what makes tokens adoption-safe at all.
Under slot addressing. The token becomes
s:<path>:<eventSlotIndex>(L0 §3.5'ss:<rowId>form).Arrival resolves it to
(Path, eventSlot, epoch); drain re-resolves(Path, eventSlot)to thebackground's listener. Two things get structurally better:
main-thread.ts:1562) becomes a compile-time invariant: priority isderived from the event prop's name (
main-renderer.ts:729), which is baked into the createfunction, so both sides cannot disagree.
When the adopted tree came from repair. Today repair drops the entire buffer
(
main-thread.ts:2211, and again on fault at:2296,:2309). That is correct-but-over-broad oncerepair is scoped: a tap on an untouched sibling range was perfectly resolvable and got discarded.
The rule:
The epoch is what makes R7 decidable, and it is why
generationdoes not become unnecessary:under positional identity,
Pathalone cannot distinguish "adopted" from "destroyed and recreatedin the same position". Redirecting to the replacement would violate the plan's hard invariant — "It
must never silently attach the wrong logical identity"
(
docs/lynx-native-renderer-plan.md:283-284) — because the replacement's handler closed overdifferent data than the one the user physically tapped, and may not even be the same templateId.
R7 is strictly better than today's contract (drop only the repaired scope's buffer) while preserving
that invariant. The
MAX_FIRST_SCREEN_EVENT_DELIVERIES = 128backpressure cap(
main-thread.ts:211, enforced at:1597-1607and:1613-1622) is unaffected.When slot-addressed instances replace logical-ID handles. They don't, fully — see §0 point 2.
getPublicInstance(main-thread.ts:1549) and the handle/selector surface stay integer-addressed.The concrete requirement is that
Path → idbe resolvable on the main thread at drain time, whichmeans the adopted container must carry a path index, not just the record map. That is new state the
current
LynxHostStatedoes not hold, and it is the piece of "per-node handle machinery" that L0 §3.6expects to delete but which R7 in fact requires.
3.4 Suspense on the first screen
This is the one divergence that is guaranteed rather than racy, and it is the strongest argument
for scoped repair.
The MT first-screen pass is one-shot: it throws if it suspends without an authored
@pending(
main-renderer.ts:1084-1089). So@tryreliably paints the pending arm while the backgroundresolves the primary body. Today that is a whole-tree repaint every time.
How compile-time identity expresses "this range was the fallback and is now replaced":
it does not need a dedicated expression. L0 §3.4 already frames
@try/@pending/@catchas arange with
BRANCHat the boundary anchor. So the boundary is an Anchor with three compile-time-knownarms, the capture records
arm = pending, the background's first commit recordsarm = primary, andR1 sees an arm difference at that Anchor. Identical mechanism to §3.1's
@if. Suspense is not aspecial case — it is the flagship case.
The structural preconditions hold already:
renderTryreturns[range([range(…)])]for allthree arms (
main-renderer.ts:812-848), so the boundary's frame depth is arm-independent, and botharms occupy the same slot in the same parent template by construction. What is missing is only the
arm tag itself, per precondition 2 above.
Two things must be got right that
@ifdoes not raise:@pending → primaryis the intended transition, not an app defect.Reporting it through
LynxFirstTreeMismatchError/ "Octane Lynx repaired a first-screen mismatch"(
core/first-screen.ts:52-67,main-thread.ts:2163) is a false alarm on every suspending firstscreen, and false alarms are how a real mismatch diagnostic gets ignored. Same mechanism, different
severity: row 6 is
info, row 5 iswarn. Theadoption: 'adopted' | 'repaired'ack field(
main-thread.ts:2255) needs a third value for partially-adopted, and arguably a fourth for"adopted with expected boundary swaps".
useIdcheckpointing.renderTryalready restoresattempt.nextUniversalIdwhen the body isabandoned (
main-renderer.ts:814,:826) so the fallback and the primary get the same startinguseId. That checkpoint discipline must be preserved verbatim by whatever emits the boundaryarms; without it R3 turns every suspending first screen into a cascade of value divergences past
the boundary.
Worth noting for scheduling: if the background's first commit is taken while the primary body is
still suspended, both sides show
arm = pending, adoption is total, and the swap is an ordinarylater
BRANCHwith no adoption machinery involved at all. Taking the background's first commit atthe same suspense stratum the MT painted is therefore the highest-value non-representational lever
on adoption rate. Listed as unresolved.
4. Determinism obligations after the change
4.1 What the scheme actually makes unnecessary (proven against
compareFirstTree)type(host-driver.ts:3271-3272)compile-universal.js:3987-3996)parent/childrenorder (:3281-3291)env.acall order (compile-universal.js:4020-4025):3314-3352)env.ecalls; priority derives from the prop name (main-renderer.ts:729)visible(:3291-3294)main-renderer.ts:710), constant within an instancemain-renderer.ts:1063-1070,:1100-1113)snapshot.nodes[]node records (core/first-screen.ts:14-24)host-driver.ts:3064-3160The listener-seeding deletion is the most valuable single item on this list. Today both programs must
independently reach
1_000_000and count event sites in identical order(
main-renderer.ts:1063-1070) — a coupling that is invisible in source, has no diagnostic when itbreaks, and fails on any render-order difference. The L3 slice on this branch is still bound to it:
applyLynxFirstScreenDirectconsults the staged batch only for itseventcommands specificallyso the assignment stays single-sourced (
host-driver.ts:2893-2898,:2921-2932). Killing thatcoupling is also what would let the direct path stop building the batch at all.
4.2 What remains an app/compiler obligation
never its likelihood. This is the entire content of §3.1 and §3.2.
docs/lynx-native-renderer-plan.md:902-903). DCE thatremoves something shape-bearing still diverges the two graphs.
today. Under all-or-nothing repair, nondeterminism is loud: the whole screen repaints. Under
scoped repair it is quiet and data-dependent. Partial adoption is a net regression in
observability unless it ships with per-Anchor diagnostics and a test-mode "any repair is a
failure" switch. That switch should be considered part of the feature, not a follow-up.
graphs are separate Rspack layers over the same entry
(
docs/lynx-native-renderer-plan.md:883-886). Today the shared identity is the plan objectreached through the same import (
compile-universal.js:4051-4057) plus a renderer-id check(
main-renderer.ts:1078-1081) — resilient to build skew because it is reference identity, not anumber. A numeric templateId is not. If ids are assigned by emission counter, the two layers
diverge whenever they tree-shake differently. templateIds must be content- or source-position-
derived, never emission-ordinal-derived, and rows 12–13 of the decision table exist to catch it
when they are not.
"same discipline as hook slots", which is the right precedent, but it is a second and much larger
index space, and unlike hook slots a skewed slot index is silently type-correct.
_execIdtolerance. Survives verbatim.sameAdoptableSnapshotValueexists precisely because "first-screen and background graphs assign different local execution
tokens" (
host-driver.ts:2689-2745), and the slot-value comparator inherits that exceptionwholesale. Nothing about slot addressing makes it unnecessary.
derived from a nondeterministic source" from a benign inefficiency into an adoption failure with
no existing diagnostic.
useIdordering. Untouched, and newly load-bearing via R3 (§1) and therenderTrycheckpoint(§3.4).
<list>exclusion. Untouched (host-driver.ts:3060,:3077; L0 §3.7 defers to L4).Net: six obligations survive unchanged, three are new (4, 5, 7), one is genuinely retired
(listener seeding). That is a real simplification, but it is not the direction L0 §3.6 implies — the
scheme trades a runtime determinism obligation for two build-time ones.
4.3 Where "matching becomes an array-index walk" overpromises
comparisons of interior structure, not an index walk. Better than claimed.
value walk. This is the shape of the L0 prototype's fixture, which is where the claim comes from.
sequence; comparing two possibly-different-length runtime sequences while preserving survivor
identity is a reconciliation problem, not an index walk — it is the same LIS-shaped problem the
background reconciler already solves (L0 §3.4). The index walk is the degenerate case where nothing
diverged.
terminates in "unequal", and the entire design content is what happens next.
core/first-screen.ts". That file is 115 lines and is mostly the event-token journal(
:69-115) and the error class (:52-67) — neither of which the scheme deletes, and R7 makes thejournal more load-bearing, not less. What actually collapses is in
host-driver.ts: the~100-line snapshot builder (
:3064-3160) and the ~90-line per-node field walk (:3263-3352). Thenode-snapshot types in
first-screen.ts:5-38do collapse; the journal machinery gainsresponsibility.
deleted transfer is per-node too. L0 §3.6 frames this as a comparison-cost story, but §3.2's
residual-first-commit is the larger structural change: it removes the "background root must be
completely empty" precondition (
host-driver.ts:3563-3582) and merges adoption into the ordinarydelta vocabulary.
5. Unresolved
adoption requires range-local. This is the one decision that must be made before any code, because
it is a wire-format decision.
lynxTemplateEligiblerejects any plan containingcontrol flow, at the plan root (
compile-universal.js:3928-3941,:4055-4056), so no componentwith an
@ifor@foremits a create function today. L0 §3.4'sBRANCHand range framing must landbefore any of §3.1/§3.2/§3.4's semantics are testable. Sizing this is the next concrete step.
ordinal-prefix matching everywhere is preferred as the simpler contract with a known worst case
(head insertion repaints the list). Recommendation: keyed, but this is a judgment call about
whether adoption rate or spec purity wins.
test-mode strict switch ships with the feature.
adoption: 'adopted' | 'repaired'(main-thread.ts:2255) is two-valuedand the compact-ack path is gated on
firstTreeAction === 'none'(:2220-2225). Partial adoptionneeds a richer ack, and it is not obvious whether the compact encoding can survive it.
the MT's suspense stratum converts the guaranteed suspense divergence into a no-op. Worth
measuring before building scoped repair for it.
a full one. L0 measured FCP, not repair cost, and today's repair is a cold create of the whole
tree — the create path L0 measured at 1082 ms @10k on the current stack (862 ms on the
prototype). A scoped repair of 1% of the tree should be ~1% of that — but the prepare-side
residual computation is new cost paid on every adoption, including the ones that match
completely. That trade needs a measurement before it is designed in, not after.
Generated by Claude Code