Skip to content

feat(lynx): port the Block model to the wire host - #105

Merged
Huxpro merged 3 commits into
new-lynxfrom
feat/lynx-block-core
Aug 20, 2026
Merged

Huxpro merged 3 commits into
new-lynxfrom
feat/lynx-block-core

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

Issue #103 U2: the first vertical slice of the Lynx-specialized background core —
runtime.ts's Block model with a host id where the DOM node was.

Stacked on #104 (U0) → #102 → #101 → #100 → #97.

packages/lynx/src/core/block-core.ts is Block + ForSlot over instance
handles: a block is {template, firstId, values, key, prev, next}, a range site
is {parent, items: Map<key, Block>, head, tail, size}, and the keyed reconcile
is an LIS over the survivor sequence. Nothing else in the package changes; the
module is not reachable from src/root.ts or src/main-thread.ts, so the source
graph runtime-compatibility.test.ts pins is untouched.

It emits host commands, not delta frames, and that is deliberate.
UniversalHostBatch already carries the whole vocabulary the Block model needs —
mount-template-run is RUN, update is SET, move is MOVE,
remove/destroy is REMOVE, visibility is VIS. The v2 delta protocol
(#101) is a compact encoding of that vocabulary, not new applier capability.
Emitting commands keeps the applier, the wire, the PAPI layer, and the event
journal shared with the universal path, which is the only thing that makes a
physical-tree comparison between the two cores mean anything: fork the applier
and byte-equality of the tree proves nothing about the core.

Why

#103's U0 measured the update path's architectural ceiling with a hand-written
op emitter that kept its row state in an array. It answered "what would a
specialized core's output cost" and returned GO. It could not answer "does a
real keyed core actually emit that", because there was no keyed core. This is
that core, and its counts are asserted rather than described.

Changes

  • packages/lynx/src/core/block-core.ts — new. Template compilation with the
    slot→node inverse map a scoped write needs, dense-run instance allocation,
    Map<key, Block> range sites, LIS keyed reconcile, and deterministic
    blockLookups/commands counters.
  • packages/lynx/tests/block-core.test.ts — new. Equivalence against a fresh
    mount, survivor host identity across a reorder, and the change-proportionality
    counts at 10 / 1,000 / 10,000 rows.
  • packages/lynx/tests/_fixtures/fake-element-papi.ts — insertBefore now
    reparents. Separate commit; see below.

Validation

  • pnpm format:check — via pnpm format:files:check over every changed path
  • pnpm typecheck — full repo, exit 0
  • pnpm test — running against this diff; result in a follow-up comment
  • targeted tests: vitest run --project lynx — 30 files / 405 tests, all
    passing
    , which is the meaningful set: the diff touches packages/lynx
    only, and grep puts the changed fixture in exactly two test files, both
    in that project.

The keyed-reorder test is the regression for the fixture commit: it fails
without it (4,1,6,2,3,4,5,6 for a six-row list, the moved rows left in both
places) and passes with it.

A fixture bug this slice found

__InsertElementBefore delegates to DOM appendChild/insertBefore on a real
host (confirmed in @lynx-js/testing-environment's ElementPAPI), so an
already-attached child is moved. host-driver.ts relies on that: a move
command emits one papi.insertBefore with no preceding papi.remove.

The fake Element PAPI spliced without detaching, so a moved node stayed in both
places. Nothing caught it because no existing fake-PAPI test moves a node —
first-screen-direct.test.ts only mounts. Fixed in the fixture, which is where
the defect is, with the keyed-reorder test as its regression.

Risk / follow-ups

  • No changeset. packages/lynx does not export ./core/*, so this adds an
    internal module and changes no published behavior.
  • Not wired to a root yet. The per-root opt-in (CreateLynxRootOptions) and
    the differential test against the universal path's own round trip are the next
    slice. Wiring it into src/root.ts puts block-core.ts into the pinned
    background source graph, which is a deliberate, separately-reviewable step.
  • No hooks. The scoped entry points here are what a useState setter would
    call; the hook cells that call them are not in this slice. That is why the
    tests compare the core against itself rather than against a universal-core
    render of the same component — the two are not yet the same program, and a
    test that pretended otherwise would be comparing fixtures, not cores.
  • Teardown is the one place the command vocabulary is genuinely weaker than
    the delta protocol.
    destroy refuses a target that is still attached or
    still owns children, so removing a row costs one remove plus one destroy
    per host in its run. REMOVE {firstInstance, count} says the same thing in one
    frame. The test asserts the cost the vocabulary actually charges rather than
    the cost the protocol would.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 2 commits August 20, 2026 04:58
`__InsertElementBefore` delegates to DOM `appendChild`/`insertBefore` on a real
host, so an already-attached child is moved, not duplicated. `host-driver.ts`
relies on that: a `move` command emits one `insertBefore` with no preceding
`remove`.

The fake spliced without detaching, so a moved node stayed in both places. No
existing fake-PAPI test moves a node — `first-screen-direct.test.ts` only mounts
— which is why this survived. The regression that fails without this fix is the
keyed reorder in the block-core suite added next.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Issue #103 U2: the first vertical slice of the Lynx-specialized background core.

`Block` is `{template, firstId, values, key, prev, next}` and a range site is
`{parent, items: Map<key, Block>, head, tail, size}` — `runtime.ts`'s pair of
structures with a dense host-id run where the DOM node and its marker pair were.
The keyed reconcile is an LIS over the survivor sequence, so final order and
survivor identity are guaranteed while the set of moved instances is not, which
is the guarantee `docs/differences-from-react.md` already documents.

It emits host commands rather than delta frames deliberately.
`UniversalHostBatch` already carries the vocabulary the Block model needs, so
the applier, the wire, the PAPI layer, and the event journal stay shared with
the universal path — the only thing that makes a physical-tree comparison
between two cores mean anything.

The tests assert two separate claims: an incremental update leaves the tree
identical to a fresh mount of the same state, and the counts a scoped update
pays do not move between 10 and 10,000 rows.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy

Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner Author

pnpm test — full run, complete. This is the result promised by the unticked
pnpm test box in the body.

Result: Test Files 12 failed | 2184 passed (2196), Tests 6 failed | 20954 passed | 75 skipped (21035), 1 unhandled error. Start 06:09:53, duration 3888 s. Ran on a clean tree at 781e4fca3, the tip of this stack, so it covers this PR's head (89e9f72b8) plus the branches above it.

No lynx project failure — the project this stack changes.

Every one of the 12 was then re-run individually on an idle host and A/B'd against the stack's merge-base 5d6172478 (unmodified new-lynx) in the same working tree. The stack touches only packages/lynx/** plus the lynx compiler target in compile-universal.js; none of the failing packages import either.

failure at 5d6172478 at stack head verdict
octane react-hosted/web3-island pass pass full-run load: 10 s beforeAll
redux-toolkit conformance/query — jsdom _location unhandled error clean clean full-run load
docusaurus hydration pass pass full-run load: 15 s deadline
aria hydration fail pass environmental
aria package-boundary fail fail environmental
alien-signals hydration fail fail environmental
dropzone probes/hydration fail fail environmental
syntax-highlighter negative-controls fail fail environmental
octane-events-browser suspense-hydration, selection restore fail fail pre-existing
rspeedy-plugin native-demo, detached-descendant cleanup fail fail pre-existing (#66 §2.3)
website-integration ×3 (dev-SSR e2e, Nitro preview e2e, ssr-smoke) not run fail environmental
drei-adapted-browser upstream-e2e not run not run outbound network

Notes on the three groups:

  • The five-project batch (aria, alien-signals, dropzone, syntax-highlighter, docusaurus) runs as one invocation. At the merge-base it fails 5 files; at this head it fails 4. Every failure in it is a subprocess or bundler timeout inside a 5–10 s beforeAll or test deadline — buildConsumer, renderHydrationFixture, execFileSync scripts/generate-surface.mjs. This container transforms slowly enough (transform 205 s, import 274 s for 82 files) to blow those deadlines regardless of the diff.
  • website-integration still fails on an idle host, all three from website vite build did not finish within 300000ms. The build was still emitting chunks when the deadline hit, so it is container speed, not a hang. The website references @octanejs/lynx only in docs prose and a package-name list; it never imports it.
  • drei-adapted-browser is Could not load potsdamer_platz_1k.hdr: Failed to fetch against raw.githack.com. Not re-run: it needs outbound network this container does not have. Recorded as explained-but-unverified rather than claiming an A/B I did not run.

Generated by Claude Code

Review follow-ups on the U2 slice: a duplicate key silently corrupted the
keyed range (double-matched survivor, self-anchored move, size drift) and
leaked a mounted run on the fill path; reconcile and clear destroyed
departing blocks without a window for the owner to release their
listeners, leaving retired listener ids routable. Both refusals and the
departed callback are pinned red-green in block-core.test.ts.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
@Huxpro
Huxpro changed the base branch from test/lynx-update-ceiling to new-lynx August 20, 2026 17:56
@Huxpro
Huxpro marked this pull request as ready for review August 20, 2026 17:56
@Huxpro
Huxpro merged commit 615920d into new-lynx Aug 20, 2026
1 of 2 checks passed
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.

1 participant