Skip to content

feat(lynx): mount a worklet keyed list through one template run - #122

Merged
Huxpro merged 1 commit into
new-lynxfrom
feat/lynx-universal-worklet-runs
Aug 21, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
feat/lynx-universal-worklet-runs

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

#103 U4b, stacked on #121. U4a taught a Lynx template run to carry a
main-thread: prop; this makes the shipping path actually take that road, so
the 6,002 in §1 becomes 3.

The measurement that opened U4 (real compiler, real transport, template runs
negotiated, keyed list of view.row > text.col > #text):

fixture rows commands before commands now
plain row 10 3 3
plain row 1,000 3 3
main-thread:bindtap 1,000 6,002 3

The "before" column is §1's; the "now" column is measured in this PR, through
the same real compiler and real transport, at 10 rows and at 1,000.

Three refusals stood between the two rows, and each was answered where it lives:

  • The compiler disqualified a keyed row from a template program if any
    attribute was main-thread:-namespaced, so the list lost its program before
    the core ever saw it. A worklet and a main-thread ref are produced by the
    setup body and bound per instance — which is exactly what a program slot is —
    so a bound one is now eligible. A literal one is still refused, the same
    answer the core's program derivation gives a static main-thread prop.
  • The core refused a main-thread: binding when compiling a collapsed
    template program, and refused a non-scalar value in any slot. A slot whose
    binding names a renderer-namespaced prop may now carry a value the core
    forwards without interpreting; every other slot is scalar-only exactly as
    before, so the same object in a plain slot still declines the program.
  • The renderer bound background closures only on the create/update path,
    so a worklet mounted through a run shipped with no _execId and could not
    call back. That was not in U4a's design record, which scoped U4b as "lift the
    refusals"; the correction is recorded on Lynx specialized background core: the Block model over the wire (#58 L2 body, post-attribution direction) #103.

Changes

  • octane compiler isTemplateProgramForHost: resolves attribute names through
    hostAttributeName, which is namespace-aware, and admits a main-thread:
    attribute whose value is a per-instance expression the same predicate already
    accepts for every other binding. The only change in emitted output is the
    run-eligible flag on universalFor.
  • octane universal-core.ts: compiledCollapsedTemplateProgram keeps a
    namespaced binding eligible; prepareCollapsedTemplateValues checks a
    namespaced source for what it must not be rather than for being a scalar and
    validates the encoded result through a slot-scoped predicate. A function is
    still refused outright: it is what the encoder exists to replace, so one
    surviving means the renderer declined to encode.
  • octane UniversalHostTemplateProgramOpaqueValue is now object rather than
    a record of unknown fields. A renderer's descriptor is a declared interface,
    and TypeScript gives an interface no implicit index signature, so the record
    form made this escape hatch unusable by the renderers it exists for — the
    first consumer could only reach it through a double cast. The core reads no
    field here; what the value must not be is enforced at runtime, where the core
    can enforce it.
  • @octanejs/lynx client-driver.ts: prepareLynxClientWorkletBatch retains
    the worklets a run carries, the same step create already took, and derives
    which slots those are once per program (cached with the program, like the
    three other places that derive the same fact inside a walk they already do).
    Ownership is recorded per host — firstId + instance * hostCount + node —
    rather than per command, because one run installs callbacks on many hosts and
    each is replaced or destroyed on its own.
  • @octanejs/lynx root.ts: the accepted-worklet ledger takes that per-host
    shape. create/update/recreate assign one host, a run assigns the hosts
    it named, and destroy releases one — all through a single assign helper,
    so the three cannot drift.

Validation

  • pnpm format:check (repo-wide, clean)
  • pnpm typecheck (repo-wide, clean)
  • pnpm test — 5 failed / 21,056 passed / 8 skipped; none of them this diff's
  • targeted tests: --project lynx 453 passed, --project octane 6,797 passed

Every failing file in the full run was attributed individually:

  • pre-existing on the base in this container, the same four feat(lynx): carry main-thread props on a template run #121's run hit:
    dropzone probes/hydration, octane browser suspense-hydration
    (focus/selection after a keyed reorder), drei browser upstream-e2e (WebGL),
    and rspeedy-plugin native-demo per Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §2.3;
  • contention only, re-run in isolation on this branch and green: octane
    react-hosted/web3-island (2 passed), aria package-boundary (6 passed), and
    markdown conformance/public-types (1 passed, 2.16s against a 5s deadline).
    All three are fixed-deadline hooks or imports that compile or bundle, and the
    run they failed in took 3,519s wall.

Red-first, per changed source file, against the new
packages/lynx/tests/worklet-template-runs.test.ts:

reverted what fails
universal-core.ts a create per host instead of one run
client-driver.ts the shipped worklet carries no _execId
root.ts a destroyed row's callback stays callable — a leak

compile-universal.js is attributed by the new case in
universal-renderer.test.ts: reverted, the bound row is no longer
program-eligible.

New tests:

  • packages/lynx/tests/worklet-template-runs.test.ts (2) — the shipping path
    end to end: createLynxRoot over the real transport onto the official Element
    PAPI. One run mounts the whole list with exactly one create (the page) at 10
    and at 1,000 rows, and each row's captured background function is callable
    while its hosts live and refused once they are destroyed.
  • packages/octane/tests/universal-renderer.test.ts (1) — a keyed row that
    binds a main-thread: prop stays program-eligible; a literal one does not.
  • packages/octane/tests/universal-host-sdk.test.ts (1) — sibling to the
    existing "falls back for refs, native-list hosts, and main-thread-owned
    props": a renderer-namespaced binding carries an opaque value through a run,
    and the identical value in a plain slot still declines the program.

The compiler and core changes are shared, so they reach the main-thread
first screen as well as the background root: createLynxHostDriver negotiates
templateProgramRuns too. first-screen-direct.test.ts already renders a keyed
list whose rows bind main-thread:bindtap through that applier, and it is green
on this branch; the applier's own handling of a main-thread prop on a program is
U4a's work, tested directly in host-driver.test.ts.

The component in the Lynx test is written the way the compiler writes one — a
module-level plan with per-instance bindings and a run-eligible universalFor —
because the lynx suite compiles .tsrx without selecting a thread layer, so a
'main thread' directive cannot be authored in a fixture there. The compiler
half is proven on the octane side instead, which is where a compiler test can
choose its own options.

Risk / follow-ups

  • The update path still re-sends. bindThreadFunction returns a fresh
    tagged function every render, and the core's prop diff falls back to identity
    for a function, so every surviving worklet-bearing row takes an update on
    every render — measured here: removing one row from a three-row list emits two
    updates carrying the full prop bag. A plain row emits none. U4a already fixed
    this inside the Block core with a structural compare; the universal path needs
    a renderer-owned equality hook to do the same, which is a designed core-API
    addition rather than something to bolt onto this diff. Recorded on Lynx specialized background core: the Block model over the wire (#58 L2 body, post-attribution direction) #103 as the
    next unit; the new test asserts the survivors stay callable through whichever
    execution the current frame carries
    , so it does not pin the re-send itself.
  • main-thread:ref is deliberately not retained by the run path, matching
    create: a ref cell holds no background closure and so has no execution
    lifetime. One ref bound on every row of a keyed list is still one cell claiming
    N hosts, which is question 2 on Lynx specialized background core: the Block model over the wire (#58 L2 body, post-attribution direction) #103.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

U4a taught a template run to carry a `main-thread:` prop. The shipping path
still could not take that road: a 1,000-row list with one `main-thread:bindtap`
mounted in 6,002 commands where the same list without it mounted in 3. It now
mounts in 3 at either scale.

Three refusals stood in the way, each answered where it lives.

The compiler disqualified a keyed row from a template program if any attribute
was `main-thread:`-namespaced, so the list lost its program before the core saw
it. A worklet and a main-thread ref are produced by the setup body and bound per
instance, which is exactly what a program slot is, so a bound one is now
eligible. A literal one is still refused — the same answer the core's program
derivation gives a static main-thread prop.

The core refused a namespaced binding when compiling a collapsed program, and
refused a non-scalar in any slot. A slot whose binding names a
renderer-namespaced prop may now carry a value the core forwards without
interpreting, and the renderer's driver validates it. Every other slot stays
scalar-only, so the same object in a plain slot still declines the program. A
function is refused outright: it is what the encoder exists to replace, so one
surviving means the renderer declined to encode.

`UniversalHostTemplateProgramOpaqueValue` becomes `object` rather than a record
of unknown fields. A renderer's descriptor is a declared interface, which
TypeScript gives no implicit index signature, so the record form made this
escape hatch unusable by the renderers it exists for — its first consumer could
only reach it through a double cast. The core reads no field there; what the
value must not be is enforced at runtime, where the core can enforce it.

Lifting the refusals alone would ship a worklet with no bound execution: the
Lynx driver retained background closures on the create path only, so a worklet
mounted through a run would paint and be uncallable. It now retains the ones a
run carries, the same step `create` already took, and records ownership per host
rather than per command — one run installs callbacks on many hosts, and each
host's later `update` replaces its own while its `destroy` releases them, so
removing one row cannot take another row's handler down with it.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants