Skip to content

feat(lynx): cut the delta protocol over to instance-addressed v2 - #101

Merged
Huxpro merged 4 commits into
new-lynxfrom
feat/lynx-delta-protocol-v2
Aug 20, 2026
Merged

Huxpro merged 4 commits into
new-lynxfrom
feat/lynx-delta-protocol-v2

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 1 of the revised plan on #66. Cuts delta-protocol.ts over to the opcode
set that #61's closure analysis settled, ports the #78 profiling shadow onto it,
and lands the implementable half of amendment A6 in the compiler.

Stacked on #100 (Phase 0), which is stacked on #97. Review the last two
commits only; the base merges first.

Three refutations of the draft protocol, each load-bearing rather than cosmetic:

  • A bare slot index is not an address. Slot indices are per-template, so one
    index names one anchor per instance — in a 10,000-row list, 10,000 of them.
    Every address is now an (instance, slot) pair, with handle 0 reserved as
    the END anchor sentinel and handles dense, monotonic, and never reused.
  • BRANCH is deleted. Retained Suspense keeps the committed arm and the
    pending arm live simultaneously, which a single-arm opcode cannot express, and
    every arm swap is already REMOVE + RUN into the same range site.
    (RECREATE was never added: a template's CSS scope is baked into its create
    function, so a scope change is a different template.)
  • VIS is added. Activity and retained Suspense are visibility transitions
    over instances whose identity does not change, and the draft had no way to say
    so. CLEAR is added for the exclusive-range case.

Slot values are restricted to scalars. That is the premise header-only
validation rests on: a structured value would have to be walked to be checked,
which is exactly the recursive cost this format exists to delete. Validation is
now a single forward scan — version, opcode bounds, frame arity, one typeof
per value — with no recursion and no allocation. A rejected value is decided by
that one typeof, so a hostile getter is never reached; there is a test that
throws from a getter to prove the decoder never touches it.

A6 could not be completed, and the reason is a finding rather than a
shortfall.
The amendment asks for the range-site kind r to be split from the
scalar kind c in lynxTemplateSlotKinds. That split is not available there:
the universal plan IR has no scalar hole to split off. kind: 'text' is
produced only for static text and never carries a slot, and every dynamic hole
— a bare {expr}, a cast {expr as string}, @if, @for, @switch, @try,
Activity, a component call — reaches addDynamicAst and becomes one
indistinguishable {kind:'slot'}. The as string cast is a type assertion the
compiler strips, so it leaves no trace in the plan. Compiling all four forms and
diffing their emitted slot tables shows them identical.

What landed is the truthful half: every renderable hole is r, because every
one of them is a range site — a bare expression can evaluate to an array or a
component exactly as a directive can. That satisfies the validator rule
requiring a RUN/CLEAR parent slot to be a range site, and is pinned by a test
over all four hole forms. A scalar kind has no producer today, so introducing
one is an IR change that belongs with the applier work that would consume it.
Recorded in the spec so the next slice does not re-derive it.

No performance claim is made. The protocol stays deliberately unwired, and Phase
0 (#100) established that the update path's cost is not in the wire.

Validation

  • pnpm format:check — via pnpm format:files:check over every changed path
  • pnpm typecheck — exit 0
  • pnpm test — running against this diff; result reported in a follow-up comment
  • targeted tests: packages/lynx/tests/delta-protocol.test.ts (31),
    packages/lynx/tests/delta-shadow.test.ts (5),
    packages/octane/tests/lynx-target-templates.test.ts (6),
    full @octanejs/lynx suite (29 files / 390 tests)

Red-green was verified in both directions rather than assumed:

  • The v2 test file fails 15/31 against the v1 encoder before the rewrite.
  • Reverting the compiler's 'r' back to 'c' fails the two new slot-kind tests.

Risk / follow-ups

  • The protocol has no production consumer, so this cannot regress rendering. The
    shadow encoder is compiled out when profiling is off.
  • siteOf() in the shadow uses the parent node's index within its template as
    the slot, standing in for the compiler's range-site slot, which the command
    ABI does not carry. Its doc comment says so explicitly: only the instance
    qualification is claimed. A real range-site slot arrives with the applier.
  • A6's remaining half (a scalar slot kind), plus the n and a kinds from the
    same amendment, are deferred to the applier slice and recorded in §8 of
    docs/lynx-specialized-target-l0.md.
  • Dense-handle allocation would need revisiting if commit-granular batching is
    ever split finer (Roadmap: replace the universal-renderer target for Lynx with a Lynx-specialized compiler and renderer #58 open question 4). Noted in §3.4.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 2 commits August 19, 2026 23:30
`lynxTemplateSlotKinds` labelled every dynamic hole `c`, the same kind a
scalar prop write would carry. The delta applier has to dispatch `RUN` and
`CLEAR` from that table, and both require their parent slot to be a range
site, so a kind shared with a scalar write cannot answer the question.

Every renderable hole is a range site: a bare `{expr}` can evaluate to an
array or a component exactly as `@for` or `@if` can, and the plan IR gives
the compiler no way to tell them apart in the first place. So they are all
`r`, pinned by a test over the four authoring forms — cast text child, bare
hole, conditional, and keyed loop — whose emitted slot tables are identical.

Only emitted metadata changes; nothing reads the kind at runtime yet.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
The closure analysis on #61 refuted the draft opcode set on three counts,
and each one is load-bearing rather than cosmetic:

- A bare slot index is not an address. Slot indices are per-template, so one
  index names one anchor per instance — in a 10,000-row list, 10,000 of
  them. Every address is now an `(instance, slot)` pair, with handle 0
  reserved as the `END` anchor sentinel.
- `BRANCH` is deleted. Retained Suspense keeps the committed arm and the
  pending arm live at the same time, which a single-arm opcode cannot
  express, and every arm swap is already `REMOVE` + `RUN` into the same
  range site.
- `VIS` is added. Activity and retained Suspense are visibility transitions
  over instances whose identity does not change, and the draft had no way
  to say so. `CLEAR` is added for the exclusive-range case.

Slot values are restricted to scalars. That is the premise header-only
validation rests on: a structured value would have to be walked to be
checked, which is the recursive cost this format exists to delete. A
rejected value is decided by one `typeof`, so a hostile getter is never
reached — asserted directly.

The #78 profiling shadow follows: it allocates dense handles of its own
instead of reusing command-batch node ids, and its differential oracle
addresses instances by wire handle, which is the property instance
qualification exists to provide. It declines a non-scalar value rather than
encoding one.

#61's worked Cases 1-3 are the test contract, and were verified to fail
against v1 first. The protocol stays unwired: Phase 0 established that the
update path's cost is not in the wire.

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

Review follow-ups on the v2 protocol slice: the shadow re-implemented
delta-protocol's scalar rule (a drift risk with no diagnostic on the
decline path) and allocated a throwaway array per changed binding on the
profiling hot path; the slot-kind test called startsWith on entries a
slot table documents as possibly null. isLynxDeltaValue is now the one
exported guard, consumed by requireValue and the shadow directly.

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

Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner Author

Finding: v2 makes the profiling shadow miss 100% of lynx-table's commits

While measuring Phase D on the stack head I read the shadow counters this PR ports, and they are zero on the flagship workload. Bisecting the stack puts the change exactly at this PR's 2dc0768e4:

commit create@1k update10th@1k updateStorm@1k
85dda3237 (v1, immediately before) 1 commit / 0 misses / 1 op / 33,083 B 1 / 0 / 100 ops / 3,598 B 50 / 0 / 5,000 ops / 108,500 B
2dc0768e4 (this PR) 0 commits / 1 miss / 0 ops / 0 B 0 / 1 / 0 / 0 0 / 50 / 0 / 0

Same result in every cell measured — create, select, selectStorm, swap, update10th, updateStorm, at both 1k and 10k — and on every later commit in the stack through 566700e30. Each arm is one node benchmarks/lynx-table/run.mjs 1 under LYNX_PROFILE; the counters are deterministic, so one pass settles it.

Mechanism

v1 used command.parent as the anchor directly (anchorSlot: parent ?? 0), so a mount under a host the shadow had never seen was still representable. v2 resolves it first:

const parentSite = siteOf(next, command.parent);
if (parentSite === null) return null;

and siteOf requires state.hosts.get(host) to hit. state.hosts has exactly one population site — delta-shadow.ts:227, inside the mount-template-run arm. So a mount-template-run is representable only when its parent host was itself produced by an earlier mount-template-run in a batch the shadow accepted.

That never holds at an app root. lynx-table's rows mount under the table-body host, which the shadow never registers: it arrives either through the direct first-screen path (not in a command batch at all) or in a batch containing create, which both v1 and v2 decline through the unhandled-op fallthrough. So the first row batch misses — and every later update/move/remove addresses those same unregistered hosts through the same map, so they miss too. 100% from the first command, for the life of the page.

Why the tests don't see it

All four mount-template-run commands in delta-shadow.test.ts pass parent: null, which siteOf short-circuits to the synthetic ROOT_INSTANCE before the lookup ever runs. (The parent: -1 / parent: 0 in that file are template-program node parents, not command parents.) The non-null branch is never exercised by any fixture, so the suite passes 5/5 while the facility measures nothing.

Severity

Profiling-only. The shadow is constructed only under LYNX_PROFILE and never feeds the transport, so nothing user-visible regressed, and this PR's body makes no performance claim from it. I checked the stack's docs and PR bodies for citations of these counters and found none, so nothing published needs correcting.

The real cost is that a total miss reads as a clean zero rather than as "the shadow could not address the root" — so the facility quietly stops being evidence for the applier slice it exists to inform.

Not fixing it here

The addressing rule is the design #61's closure analysis settled and this PR implemented deliberately. Choosing the repair — register hosts from create, synthesize a root instance for an unregistered parent, or keep the restriction and make the miss attributable — is a design call, and rewriting this branch would rebase ten stacked descendants. Leaving it to you.

If it helps: the smallest repair that leaves the design intact is to make a miss say why. A per-reason miss counter (unregistered-parent, non-scalar-value, unhandled-op) turns today's undifferentiated zero into the signal the next slice actually needs, and costs nothing at the wire. The missing regression is one fixture — a mount-template-run whose parent is a host id the shadow has not registered — asserting whichever behavior you decide is correct.


Generated by Claude Code

@Huxpro
Huxpro changed the base branch from test/lynx-stage-decompose-mutations to new-lynx August 20, 2026 17:55
@Huxpro
Huxpro marked this pull request as ready for review August 20, 2026 17:55
@Huxpro
Huxpro merged commit c949e30 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.

2 participants