Skip to content

feat(lynx): mount a resident program by name, and fold a proved-scalar text hole (#246 E1 + B2) - #269

Merged
Huxpro merged 5 commits into
new-lynxfrom
feat/lynx-mount-program-run
Sep 2, 2026
Merged

Huxpro merged 5 commits into
new-lynxfrom
feat/lynx-mount-program-run

Conversation

@Huxpro

@Huxpro Huxpro commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements #246 E1 in full — mount-program-run, the addressing that makes it
possible, and the build gate that makes it safe — plus B2, the scalar text slot,
as the same ABI change. Per the owner directive
(#246 issuecomment-5485057342); every §6 ruling is taken as given and none is
re-opened here.

§3 says E1 is three parts, and it is:

1 — a key. UniversalPlan gains an optional UniversalProgramAddress,
passed as universalPlan's third argument. The wire carries only the positional
(module id, plan index) of §6.1's A half. The module id is package-relative
with posix separators and no leading ./ (§6.2), computed from the path alone by
OctaneBundlerCompiler#_programModuleId, so a monorepo build and a consumer's
build of the same shipped source name it identically. Deliberately not the
compiler's existing canonical module id: that one is project-relative and falls
back to the absolute path for a file outside the project root, which would put a
build machine's filesystem layout into a shipped chunk.

2 — a registry. packages/lynx/src/core/program-registry.ts, main-thread
only, populated by the main-thread chunk as it evaluates. mount-program-run
resolves against it and re-enters the same applier mount-template-run takes,
with the program resolved instead of carried — so the tree, the ids, the
listeners and adoption are identical by construction rather than by a second
implementation kept in step.

The two realms resolve differently, and the module graph says so. The background
asks the universal core for the program its own producer lowered for that exact
command, keyed by command object: keying the sender by address would be wrong,
because prepareUniversalTemplateProgram memoizes per encoder and two roots hold
two objects for one address. protocol.ts is in both graphs, so it takes the
resolver as a parameter rather than importing either, and program-registry.ts
holds no runtime import from the core — the main-thread graph's packages: []
invariant is intact.

3 — a drift gate. Both compiles emit a structural digest over exactly the
derived wire surface (§6.1's B half), and crossCheckProgramAddresses in the
Rspack loader compares them per (module, index) across the build's two layers.
A disagreement is a build error naming the module. This is the part §3 calls the
worst failure shape in the codebase: a positional address that binds to the wrong
program paints a plausible wrong tree, and nothing at runtime would notice.

An isolated thread: 'main-thread' graph refuses the option outright (§6.3), at
the configuration rather than at a mount that finds nothing, and its diagnostic
names the two-layer build.

What the naming buys

Not the wire bytes. prepareTemplateProgram and assertTemplateProgram both key
on program object identity, so a descriptor that crosses the realm boundary misses
both memos on every mount, while a resident program is walked and validated once
for the chunk's life. That is why the main-thread compile emits the derived wire
into its program object and the registry deep-freezes it at registration: neither
memo will store a program it cannot prove immutable.

B2

§6.4 ruled that a scalar text slot is absent ABI work, not deferred ABI work —
"a binding { valueIndex, name: 'text' } on a text host … no new opcode, no new
field, no arity change, and no receiver dispatch". So B2 lands as an extension of
#250's fold rather than as a new UniversalSlotKind member: {expr as string} as
the lone child of a text-absorbing host folds onto that host as a ['text', slot]
binding, the carrier is never painted, and the slot's kind is the existing
'p:text'.

The proof is read off the authored JSX, not the plan node, because compile.js
strips every TS-only wrapper before printing — by codegen the cast is gone. The
compiled child is checked too, so the two views must agree before anything folds.

A lying cast cannot paint a wrong tree, and the receiver for that was already
built by #250: attributeValue in host-props.ts, the dense route in
host-driver.ts, and the compiled create in emit-main-thread-program.ts each
render a non-string as empty rather than coercing it — which is what the carrier
this replaces did.

Changes

  • octane: UniversalProgramAddress on the plan and as universalPlan's third
    argument; the realm-local wire registry; mount-program-run in the command
    union and in protocol validation; the compiler emits the address and digest
    from both compiles under programAddressing, and reports every address it
    emitted so an integration can cross-check them; the B2 fold; package-relative
    _programModuleId.
  • @octanejs/lynx: core/program-registry.ts; the addressed-run branch in the
    applier; addressedProgramRuns capability negotiation; the design-spec header
    in derive-main-thread-program.ts rewritten, since its stated blocker ("a plan
    the compiler produced cannot say it") is what B2 removes.
  • @octanejs/rspack-plugin: the programAddressing option through normalization,
    cache identity and layer selection — whole-build, deliberately not
    specializable — and the loader's cross-compile digest check.
  • @octanejs/rspeedy-plugin: programAddressing, on by default for an
    application build that configures a main-thread program backend, refused for an
    isolated thread graph. Both layers inherit the backend when it is on, because
    the background decides eligibility by running the same derivation as a pure
    oracle.

#238's two tests, converted per §5

They are on new-lynx already (1bd0af124), which is what makes the conversion
part of this diff rather than a precondition for it.

§5 required the byte-identity gate be replaced, not deleted. The two tests
become naming a resident program from the background (#246 E1):

  • gives both sides the same identifier, and only when the build assigns one —
    both chunks carry the same digest, only the main-thread chunk carries the wire,
    and a build with no module id emits no address at all.
  • changes the background chunk by exactly the addressing, and nothing else —
    strip the address literal from the addressed background chunk and it is the
    plain one.

The wider #163 background byte-identity gate is untouched, because it is
differential over the backend switch rather than absolute; B2 shifts both arms
equally.

One fixture the fold would have quietly gutted

lynx-main-thread-program-first-screen.test.ts exists to catch a program that
numbers its own nodes first and its ranges' members afterwards, and its fixture's
doc says how: an event before the first range and one after it, each range
holding a member that takes an ID of its own. Both of its holes were casts, so B2
folded them and left the file comparing a shape it was not built to test. The
fixtures now ask for the holes they need — a bare hole is still a hole, because
it can evaluate to an array or a component — and every pinned number is restored
exactly rather than repinned. The folded form gets its own cell instead of being
lost.

Spec-silent choices, noted rather than asked about

  1. programAddressing defaults on for an rspeedy application build that
    configures a backend, and only there. There is a program to address and both
    layers of that one build emit the digest that proves they agree. false keeps
    descriptor mounts, which is what an A/B and the byte-identity pins need.
  2. The capability is negotiated once, from residentUniversalProgramCount() > 0, following the first-screen precedent of negotiating at mount rather than
    per command. Consequence recorded under Risk.
  3. A module with no package-relative name declines addressing — no manifest
    owns it, or it sits outside its package root — in both compiles alike, since
    both ask the same question of the same path. It keeps descriptor mounts rather
    than getting an id two builds could disagree about.
  4. The digest is 16 hex characters of FNV-1a over a canonical serialization of
    the derived wire. It is a build-time artifact compared inside one build, never
    shipped as a resolution key, so collision resistance is not load-bearing; §6.1
    explicitly keeps it off the wire.
  5. The text binding is appended after the host's other bindings, so the slot
    table gains p:text at its natural position and no existing slot renumbers.

Validation

  • pnpm test — three failures, all pre-existing (below)
  • pnpm typecheck
  • pnpm format:files on every changed path
  • pnpm sync (no generated changes)
  • targeted: packages/lynx/tests/addressed-program-run.test.ts (new, 6),
    packages/octane/tests/lynx-main-thread-program-first-screen.test.ts (74),
    packages/octane/tests/compiler/lynx-main-thread-program.test.ts (15),
    packages/octane/tests/lynx-target-templates.test.ts (14),
    packages/rspack-plugin-octane/tests/main-thread-program-build.test.ts (5),
    packages/lynx/tests/background-deferred-list.test.ts (5),
    packages/lynx/tests/main-thread-backend-signature.test.ts (2),
    packages/rspeedy-plugin-octane/tests/plugin.test.ts

The three failures, and why they are not this diff's — each was re-run on
origin/new-lynx at c124594c7 in the same container and failed identically
there, and none of the three imports anything the diff touches:

test why it fails here
drei › should match previous one headless-browser screenshot comparison
suspense-hydration › restores focused input and its selected text after a keyed DOM reorder browser focus/selection
native-demo › escalates cleanup for a detached descendant after its leader exits process-tree signal escalation with a 100 ms budget, in scripts/run-lynx-explorer-demo.mjs

Every load-bearing new assertion was falsified before being trusted, per
octane-core-extend. Disabling crossCheckProgramAddresses turns the drift test
red while the build otherwise succeeds and ships the mismatched address.
Making _programModuleId return null turns the addressing test red while the
drift test's build stops failing — the decline path behaving correctly. Disabling
the scalar-text fold turns the new first-screen cell red on both arms.

No performance number is claimed here. Per the directive the web lane is a
development mirror, the absence of a V8 win is expected, and the device round
makes the performance and regression verdict against the finished implementation.

Risk / follow-ups

  • The capability is negotiated once. A lazily code-split main-thread route
    whose module has not yet evaluated would leave the count at zero at negotiation
    time; the background then keeps descriptor mounts for the whole root rather
    than failing per command. Sound but conservative, and moot in practice because
    application builds set splitChunks: false. A per-module negotiation is the
    follow-up if a build ever splits the main-thread chunk.
  • The drift gate lives in the Rspack loader, which is where one build sees
    both compiles. A different integration that drives the compiler directly gets
    the addresses on the compile result and must run its own check; the option
    defaults off there.
  • Branch naming. The harness assigned claude/octane-issue-66-phase-a-7wz97z;
    this repo's create-a-pr requires a feat/-prefixed topic branch so the label
    bot can read the type from it. The topic branch is used, and the deviation is
    flagged here rather than resolved unilaterally.

Does this change the sequence?

No. E2 → E3 → E1 stands and this is E1, built to the directive. It closes
Cause B: B1 is in this diff, and B2 turned out to be absent ABI work rather than
deferred work, exactly as §6.4 ruled. E3's remaining blocker — unfreezing a run's
values — is receiver-local and neither waits on nor is helped by anything here.
Nothing in this PR spends the #163 byte-identity promise beyond the addressing
itself, which §5 authorized and whose replacement gate ships with it.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 4 commits August 31, 2026 22:07
Adds the addressing half of E1: a plan can carry a cross-realm name, a
`mount-program-run` command names one instead of carrying a descriptor, and
both realms resolve it against a registry their own chunk populated.

- `UniversalProgramAddress` on `UniversalPlan`, taken as `universalPlan`'s
  third argument so the background chunk changes by exactly the addressing.
- Realm-local wire registry in the universal core, populated by the producer
  in the background and by the main-thread chunk on the other side.
- `mount-program-run` in the command union, emitted by the producer when the
  plan is addressed and the renderer claims `addressedProgramRuns`.
- Protocol validation for the new op, sharing the descriptor run's checks and
  refusing an address this realm cannot resolve.
- Compiler emits the address plus a build-time digest over the derived wire
  surface, from both compiles, gated on a `programAddressing` build.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
The applier, the validator and the capability negotiation for
`mount-program-run`, plus the resident descriptor it resolves against.

An addressed run re-enters the same applier a descriptor run takes, with
the program resolved instead of carried, so the tree, the ids, the events
and adoption are identical by construction rather than by a second
implementation kept in step.

What the naming buys is not the wire bytes. `prepareTemplateProgram` and
`assertTemplateProgram` both memoize on program object identity, so a
descriptor that crosses the realm boundary misses both memos on every
mount while a resident program is walked and validated once for the
chunk's life. The main-thread compile therefore emits the derived wire
into its program object, and the registry deep-freezes it once at
registration, because neither memo will store a program it cannot prove
immutable.

The two realms resolve differently and the module graph says so. A
background asks the universal core for the program its own producer
lowered for that exact command — keying the sender by address would be
wrong, since `prepareUniversalTemplateProgram` memoizes per encoder and
two roots hold two objects for one address. The main thread asks its own
residency. `protocol.ts` is in both graphs, so it takes the resolver as a
parameter rather than importing either; `program-registry.ts` holds no
runtime import from the core, keeping the main-thread graph's zero
package dependencies intact.

The main thread advertises `addressedProgramRuns` from residency rather
than from the protocol rung it speaks: understanding the op is free,
holding programs to resolve against needs the main-thread chunk of a
two-layer build. An isolated `thread: 'main-thread'` graph registers
nothing, says so, and keeps descriptor mounts.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
…t build (#246 E1, part 3)

Completes E1 with B2 and the build-time drift gate the addressing needs.

B2 rides #250's fold rather than adding wire vocabulary, per the §6.4
ruling that a scalar text slot is a binding `{ valueIndex, name: 'text' }`
on a `text` host and therefore absent ABI work rather than deferred work.
`{expr as string}` as the lone child of a text-absorbing host now folds
onto that host as a `['text', slot]` binding, the carrier is never
painted, and the slot keeps the existing `p:text` kind.

The proof is read off the authored JSX, not the plan node: `compile.js`
strips every TS-only wrapper before printing, so by codegen the cast is
gone. The compiled child is checked too, so a hole that folded to static
text or to a nested plan is not this. A lying cast cannot paint a wrong
tree — `text` on a `text` host takes the carrier's semantics in all three
appliers, each rendering a non-string as empty rather than coercing it.

The drift gate lands in the Rspack loader, which is where one build sees
both compiles of a module. Each compile reports the addresses it emitted
with the digest of the wire surface it derived them from; a disagreement
per `(module, index)` fails the build naming the module, rather than
shipping a positional address that would mount a plausible wrong tree.

The module id is package-relative, computed from the path alone, and
deliberately not the compiler's canonical module id: that one is
project-relative and falls back to the absolute path outside the project
root, which would put a build machine's filesystem layout into a shipped
chunk and disagree between a monorepo build and a consumer's build of the
same source. A module with no package-relative name declines addressing
in both compiles alike and keeps descriptor mounts.

`programAddressing` is on by default for an rspeedy application build
that configures a backend, and refused for an isolated thread graph. Both
layers inherit the backend when it is on, because the background decides
eligibility by running the same derivation as a pure oracle.

The backend signature is bumped and its digest repinned, since the
derivation's design-spec header changed: its stated blocker — that a plan
the compiler produced cannot say a hole is text — is what B2 removes.

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

`lynx-main-thread-program-first-screen.test.ts` exists to catch a program
that numbers its own nodes first and its ranges' members afterwards, and
its fixture's own doc says how: an event before the first range and one
after it, with each range holding a member that takes an ID of its own.
B2 folds `{expr as string}` onto its `<text>`, which removed both ranges
and left the file comparing a shape it was not built to test.

So the fixtures ask for the holes they need. A bare hole is still a hole
for the reason it always was — it can evaluate to an array or a component
— and every pinned number is restored exactly, rather than repinned
against a fixture that lost its point. `HOSTING_CARD` now differs from
`CARD` only by the annotation that lets a caller pass a component, since
the hole it used to open is already open.

The folded form gets its own cell instead of being lost: the same card
with both holes cast, asserting the two encodings agree about the smaller
host count, the shifted listener IDs and the envelope, and that both
paint the value onto the `<text>` with no child under it. Counting hosts
alone cannot tell a fold from a hole the compiler dropped.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
A module evaluated twice mints a fresh plan object each time, so the
identity check refused exactly the ordinary re-evaluation the tolerance
existed for and crashed it with the two-programs TypeError. Same is now
structural over the wire — the surface the address digest already covers
— keeping the first registration so memoization survives; a genuinely
different program is still refused. Also derives a main-thread program
once per root per compile instead of twice (digest + emission).

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