Skip to content

applyLynxFirstScreenDirect paints first-screen trees the staged applier refuses #76

Open

Description

@Huxpro

Found by an adversarial audit of the #58 L0–L3 equivalence claims, against the #65 stack head 2fe14465f. Counterexample to the #65 claim that applyLynxFirstScreenDirect "leaves container state indistinguishable from prepareLynxHostBatch + apply".

Root cause

The staged applier validates host placement before mutating; the direct applier runs no equivalent check. Given the same rendered first-screen tree:

DIRECT: {"outcome":"accepted(true)","instances":2}
STAGED: {"outcome":"threw: Octane Lynx host: #text host 2 may only be placed
                   directly under a text host.","instances":0}

One paints the tree, the other refuses it. The refusal is what keeps an invalid tree away from the engine, so an applier that skips it is not substitutable for one that performs it — the direct path is the less safe of the two.

This sits entirely on the plan encoding (a children binding makes the template ineligible), so it is an applier-level divergence independent of #63.

Reachability, and a second gap it exposes

The renderer already guards the idiomatic form, but an explicit children prop bypasses that guard. Both executed:

source compile result
<view class="page">{props.t as string}</view> rejected: renderer "lynx" does not allow authored primitive text under <view>
<view class="page" children={props.t} /> compiles clean, no diagnostic

validationAttributeName skips children in the attribute check at packages/octane/src/compiler/compile-universal.js:1817, so the explicit-prop spelling escapes the very rule the direct spelling trips. The renderer then materializes the string into a #text host under the view, and renderPlanNode picks it up through const dynamicChildren = props.children at packages/lynx/src/main-renderer.ts:801.

So there are two things to fix here, and they are independent:

  1. applyLynxFirstScreenDirect performs no host-placement validation (packages/lynx/src/core/host-driver.ts:2900).
  2. The compiler's text-under-<view> rule is bypassable via children={...}.

Reproduction

Committed as a red test on claude/octane-issue-58-adversarial-audit (5d000b30e):
packages/lynx/tests/first-screen-applier-acceptance.test.ts

AssertionError: expected 'painted' to be 'refused: Octane Lynx host: #text host 2 may only be placed directly under a text host.'

Consumer impact

Since #65 made the direct path the default for every non-native-list first screen (packages/lynx/src/main-thread.ts, installLynxMainThread), a tree that the staged path would have refused now reaches the Element PAPI on every launch. Whether the native engine tolerates a raw-text child under a view is exactly the question the staged validation existed to avoid asking.

Notes for the fix

The committed test asserts only that the two appliers agree, so either direction passes: give the direct path the same placement validation, or establish that the check is unnecessary and drop it from the staged path. It does not pin which.

What else was checked on this surface, and held

To be clear about scope, these were attacked and did not break:

  • Teardown fault handling — faults injected at setEvent, remove, setAttribute, flush, insertBefore during disposal produce byte-identical LynxHostCleanupResult (complete, errors, remainingRoots) and identical container.disposed on both appliers. The retry contract (disposed:false plus populated errors) works as documented.
  • Flush obligation — exactly one flush on a mid-walk fault on both paths.
  • Ordered PAPI call journals differ (direct 46 calls, staged 48; direct interleaves insertBefore during the walk and skips setEvent SET/REMOVE pairs on hidden subtrees) but terminal container state is identical. Assessed as not a defect — .rulesync/rules/testing.md lists exact internal call order as a non-contract, and feat(lynx): direct-emission first screen with unchanged adoption capture (issue-58 L3) #65's claim is about container state, which holds.

Verification performed

Reproduced independently of the finding agents; the compile-reachability contrast above was executed directly. Three separate finder agents independently reported the direct path skipping staged-path validation, which is what prompted this check. Adversarial refuter panel had not adjudicated at time of filing.

Activity

  1. added
    bug
    on Aug 18, 2026
  2. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Second mechanism for the same defect: shared main-thread:ref across a visible and a hidden host

    A dedicated adoption lens found an independent way the direct applier paints a tree the staged applier refuses. Same root-cause class as the #text placement case above — the direct path lacks state/validation the staged path has — but a different mechanism, and this one is confirmed not pre-existing.

    The two appliers derive visible from different sources

    • Direct computes it structurally during the walk: const visible = parentVisible && node.visibility !== 'hidden' (packages/lynx/src/core/host-driver.ts:2951), then passes visible && state.hasMainThreadProps as applyProps' interactive argument (:2996). A host inside a hidden <Activity> therefore never installs its main-thread:ref.
    • Staged reads operation.visible, snapshotted from record.visible at create time (:4418, visible: true).

    So for a main-thread:ref shared by a visible host and a hidden <Activity> host, the two paths disagree on whether the second registration happens.

    Observed

    direct : paints. tree has <view id=live> and <view id=ghost hidden=true>,
             ref -> node#3, capture succeeds, adoption verdict = 'adopt'
    staged : throws 'Octane Lynx host: main-thread ref "scene:shared" is already mounted.'
             paints nothing (tree is just <page#1>)
    

    Throw originates at packages/lynx/src/core/host-driver.ts:1795.

    Authored-reachable

    useMainThreadRef() returns one descriptor with a stable _wvid (packages/lynx/src/renderer.ts:52-96), so this is ordinary code:

    const r = useMainThreadRef(null);
    <view main-thread:ref={r} />
    <Activity mode="hidden">
    	<view main-thread:ref={r} />
    </Activity>

    In production packages/lynx/src/main-thread.ts:1906 always tries the direct applier first, so such a page paints. It then adopts only while the background commit matches byte-for-byte; the same throw fires for a plain background-only mount of the identical tree, and on the repair path after a direct paint.

    Attribution

    Checked in a git worktree at base 6079a6804: git show 6079a6804:packages/lynx/src/core/host-driver.ts | grep applyLynxFirstScreenDirect returns nothing — the direct applier does not exist on base, so only one applier existed and it refused this tree. The staged-side refusal itself is pre-existing (byte-identical on base), but the divergence is introduced by this stack, which is what makes it a CLAIM 2 counterexample rather than a latent bug.

    Bearing on the fix

    This strengthens the case that the fix belongs on the direct side. Two independent mechanisms now show the direct applier accepting trees the staged applier rejects — #text placement above, and main-thread ref lifetime here — which suggests the gap is systematic rather than a single missing check.


    Generated by Claude Code

  3. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Panel result: not refuted by either refuter, and both attacks broadened it

    Two independent refuters attacked this on the fixture-validity axis. Neither could kill it, and both made it stronger.

    It is a crash on a real page, not only an acceptance asymmetry

    The issue above frames this as "direct paints, staged refuses" — a divergence. A refuter showed the production consequence: add a native <list> to the same page and applyLynxFirstScreenDirect declines via firstScreenTreeHasList, so packages/lynx/src/main-thread.ts:1906 falls through to prepareLynxHostBatch(...).apply() — which throws.

    NO LIST   -> direct paints raw-text "kid" under <view class="page">
    WITH LIST -> direct declines, staged fallback throws
                 "#text host 3 may only be placed directly under a text host."
    

    So on any page combining a native <list> with a children={string} prop on a non-text host, the first screen throws rather than merely differing. The <list> is not exotic — declining lists is the one documented fallback the direct applier has.

    The compiler really does guard the idiomatic forms

    A refuter set out to show the fixture was an exotic backdoor and it backfired — the guard is real, which is what makes children={...} an escape hatch rather than an equivalent spelling:

    <view class="page">hello</view>                  -> "renderer lynx does not allow authored JSX text under <view>"
    <view class="page">{props.a as string}</view>    -> "renderer lynx does not allow authored primitive text under <view>"
    

    Both rejected under both targets. Only the explicit children prop slips past, because validationAttributeName skips children.

    Not a typing artifact

    An independent sweep compiled five authored sources through the real compiler and fed identical result.nodes/result.batch to both appliers head to head. With fully typed props — no any — <view class="page" children={props.label} /> still gives DIRECT paints / STAGED throws. The divergence does not depend on loose typing.

    Panel tally

    Two verdicts on this candidate: both not refuted, both reproduced byte-identically from a clean tree, both attacking fixture validity and failing.

    Combined with the main-thread:ref mechanism in the previous comment, that is now three distinct routes by which the direct applier accepts or paints what the staged applier refuses — which is the argument for treating the missing validation on the direct path as systematic rather than as three separate patches.


    Generated by Claude Code

  4. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Two more mechanisms from a registry-backed worklet lens — and the staged path is implicated in one of them

    A lens that finally built a registry-backed container (createLynxHostContainer(papi, { root, worklets }) with createLynxMainThreadWorkletRegistry()) reached the main-thread: surface that defeated two earlier attempts. Both findings below are verified not pre-existing — the direct applier does not exist at base 6079a6804, and the staged path there is byte-identical (271 insertions(+), 0 deletions).

    Mechanism 3 — the staged path over-refuses because its visible flag is stale

    This one inverts the usual direction, so it is worth stating carefully.

    A first-screen batch emits every visibility/hidden command last (packages/lynx/src/main-renderer.ts:1117-1125). The staged create operation captures visible: record.visible at staging time (host-driver.ts:4418), so a host that the same batch will hide is still staged as visible: true. The apply loop then gates main-thread installation on that stale flag (:5330-5332).

    The direct applier computes final visibility structurally during the walk (:2951, :2996), so it gets the right answer.

    direct : painted (4 hosts, ref owned by the visible host only)
    staged : refused — 'main-thread ref "probe.tsrx:ref" is already mounted.'
             container left unpainted (removedRoots 0, flushed false);
             captureLynxFirstTree then refuses with
             'first tree can only be captured from a stable accepted root.'
    

    So for a page binding one useMainThreadRef to a visible element and to an element inside a hidden <Activity>, the direct path is arguably correct and the staged path is wrong. It renders fine today and hard-fails the moment a native <list> forces the staged fallback.

    That matters for the fix: the answer here is not simply "add the staged path's checks to the direct path". Mechanism 3 needs the staged path's stale-visibility bug fixed too, or adding its check to the direct path would propagate a false refusal.

    Mechanism 4 — both refuse, but with different messages, phases, and PAPI footprints

    Two visible hosts sharing one main-thread:ref:

    • Staged validates duplicate ref ownership up front over the final host set (:4794-4807): "main-thread ref X is assigned to hosts A and B", zero PAPI calls.
    • Direct has no prepare stage; the duplicate is only caught incidentally when installMainThreadRef reaches the second host mid-walk (:1789-1796): "main-thread ref X is already mounted". Before failing it allocates three engine elements, attaches one, publishes the ref into the worklet registry, and calls flush.

    Both reject the tree, so the end state agrees — but against a real Element PAPI the engine observes a partial page and a flush for a tree that was never valid, which the staged path never produces.

    Where this leaves the issue

    Four distinct mechanisms now, plus a fifth filed separately (#84 — the direct applier skips assertNoMainThreadEventCollision entirely, silently dropping the main-thread handler):

    # mechanism direction
    1 #text under a non-text host direct paints, staged refuses
    2 main-thread:ref shared visible + hidden direct paints, staged refuses
    3 stale visible on the staged create op direct paints (correctly), staged wrongly refuses
    4 duplicate main-thread:ref, two visible hosts both refuse, different message/phase/PAPI footprint
    5 (#84) no assertNoMainThreadEventCollision on the direct path direct paints and silently drops the handler

    The pattern is that the direct applier has no prepare stage at all, so every batch-level invariant the staged path checks up front is either missed or discovered mid-mutation. That is one structural fix, not five patches — and mechanism 3 shows the prepare-stage checks themselves need auditing before they are copied over.


    Generated by Claude Code

  5. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Correction: mechanism 1 is refuted as a consumer-visible defect

    A refuter ran the full production stack — installLynxMainThread({firstScreen:true}) + firstScreenRoot.render(...) + createLynxRoot().render(...) + markFirstScreenSyncReady() over @lynx-js/testing-environment — across five configurations. I only ever tested at the applier boundary, hand-feeding result.nodes/result.batch to the two appliers. The end-to-end result contradicts this issue's central consumer claim.

    config result
    A. plain app, no first screen at all background render throws the identical error, paints nothing
    B. first screen on, no <list> — my "paints fine today" case direct paints, then background adoption throws the identical error. App is dead.
    C. with <list> first screen throws, background throws the same
    D. same divergence without the children prop (explicit raw-text under view) direct paints, adoption throws
    E. background tree that does not re-issue the #text mismatch repair removes the illegal node and publishes OCTANE_LYNX_FIRST_SCREEN_MISMATCH

    There is no configuration in which the direct applier's extra leniency changes a consumer outcome. Every path ends in the same hostError, or the node is repaired away with a published diagnostic.

    Three specific things I got wrong:

    1. "Paints fine today, hard-fails once a <list> is present" — false. It dies either way; config B kills the app with no list at all.
    2. "A tree the staged path would have refused now reaches the Element PAPI on every launch" — the sharpest sentence in the issue, and the one thing I never executed. The background adopter rejects it (B, D) or repairs it (E).
    3. The children-prop escape hatch isn't load-bearing — config D reaches the same divergence with an explicit raw-text host, so the validationAttributeName gap is a side detail, not the root cause.

    <view children={string}/> is an already-fatal authoring violation on this branch and every branch before it; docs/lynx-native-renderer-plan.md:408 states the compiler must reject text under view, and compile-universal.js:1789 does so for authored text.

    The committed red test's oracle is disputed

    packages/lynx/tests/first-screen-applier-acceptance.test.ts (5d000b30e) asserts the two appliers accept the same trees. The refuter argues, reasonably, that both places declaring the contract scope it to container state and named downstream observers — not to acceptance sets — so pinning acceptance parity may itself violate .rulesync/rules/testing.md's rule against pinning non-contracts. I am leaving the test in place because it documents a real mechanical divergence, but the owner should decide whether acceptance parity is a contract worth pinning. If it isn't, that test should be dropped.

    What survives

    This refutation is specific to mechanism 1. It does not generalise, and two mechanisms are untouched by it:

    Mechanism 3 (stale visible on the staged create op) also stands and is a staged-path bug regardless.

    So CLAIM 2 remains falsified — but on mechanisms 2, 3, and 5, not on the #text placement case this issue is titled around. The title now overstates the finding; treat #84 and mechanism 2 as the load-bearing evidence.

    Panel tally

    Three verdicts on this candidate: two not-refuted (both attacking fixture validity at the applier boundary), one refuted by going end-to-end past that boundary. The refutation is better-evidenced than the confirmations, because it tested the thing that actually matters.


    Generated by Claude Code

  6. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Correction: mechanism 2 is also refuted — the direct applier is correct there, and the staged path was already broken

    A refuter attacked mechanism 2 (main-thread:ref shared across a visible and a hidden <Activity> host) and killed it as a stack-caused defect. I have read the argument and it holds.

    The only thing that actually goes wrong in that composition — main-thread ref "scene:shared" is already mounted thrown out of prepareLynxHostBatch — is entirely pre-existing. Executed against base 6079a6804 in a worktree: byte-identical throw, byte-identical empty <page#1>, byte-identical unowned ref, same order-dependence (hidden-first passes on base too). Base's main-renderer.ts already appends every visibility command last, and base's installMainThreadRef already carries the record.visible-gated tolerance. Root cause, trigger and symptom all predate the stack.

    What the stack added is a second applier that handles the composition correctly: applyLynxFirstScreenDirect derives visibility structurally during the walk (:2951) and passes visible && state.hasMainThreadProps as interactive (:2996), so the hidden host never installs the ref and it lands on the visible owner — the semantics the finding itself argued for.

    My headline consequence did not survive execution either. I claimed the direct-painted page "adopts cleanly, but the first background divergence tears down the first screen and throws mid-repaint, leaving the page empty and the root faulted." Measured against what base does on every mount of this composition, the terminal states are byte-identical JSON. There is no state HEAD reaches here that base does not already reach unconditionally and immediately — while HEAD's steady state (direct paint → exact-match adopt → ordinary update commit) runs with error: null and the correct tree, where base is dead on arrival.

    HEAD ≥ base at every observable point, and strictly better in the common path.

    Where that leaves this issue

    Both mechanisms this issue was filed on are now refuted as stack defects:

    # mechanism status
    1 #text under a non-text host refuted — adoption throws the same error or repairs the node away; no consumer outcome changes
    2 main-thread:ref visible + hidden refuted — direct is correct; staged was already broken on base
    3 stale visible on the staged create op pre-existing staged bug; direct is correct
    4 duplicate ref on two visible hosts both refuse; differs only in message, phase, and PAPI footprint
    5 #84 — no assertNoMainThreadEventCollision on the direct path stands — direct is strictly worse

    So the honest position is:

    Treat #84 as the actionable item and this issue as documentation of the surface. I would not fix mechanisms 1–4 by making the direct path match the staged path — that would propagate staged bugs into a correct applier. The structural read still stands (the direct applier has no prepare stage, so batch-level invariants are missed or found mid-mutation), but the fix is to audit those invariants first, not to copy them.

    If the maintainers prefer, this issue could reasonably be closed in favour of #84, with mechanisms 3 and 4 split out as their own staged-path cleanups.

    Panel tally

    Mechanism 1: 2 not-refuted, 1 refuted (the refutation went end-to-end past the applier boundary and was better-evidenced). Mechanism 2: 2 not-refuted, 1 refuted (the refutation established base-parity, which the confirmations did not test).

    In both cases the refuting verdict tested something the confirming verdicts did not. That is the panel working as intended, and it is why the two mechanisms this issue is titled around should not be the ones anyone acts on.


    Generated by Claude Code

  7. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Correction to the structural read: some staged-path checks are transport checks the direct path structurally cannot need

    My earlier comment said the direct applier "has no prepare stage, so every batch-level invariant the staged path checks up front is either missed or discovered mid-mutation," and framed that as one structural fix. A refuter working an adjacent candidate disproved the general form of that claim by execution, and the distinction matters for anyone acting on this issue.

    The two appliers agree across the whole invalid-main-thread: value space

    A sweep over empty _wkltId, missing _wkltId, main-local _owlt activation, string, number, array, and unregistered worklet id produced an identical error class and identical message on both appliers in every case. They share the prop validator.

    A genuinely tagged callable (bindThreadFunction('main-thread','scene.tsrx:tap',...)) is accepted by both, unwrapped by both to {"_wkltId":"scene.tsrx:tap","_c":{"values":[]}}, with byte-identical PAPI journals and physical trees. The direct path does perform the unwrap — planLynxHostPropPatch → decodeMainThreadWorklet (packages/lynx/src/core/host-props.ts:304-316) → unwrapThreadFunctionDescriptor, a thin wrapper over the same getThreadFunctionDescriptor that cloneProps uses (core/worklets.ts:1394-1413).

    The one divergence is structural, not a missing check

    It exists for exactly one input class — a raw, untagged JavaScript function — and the reason is architectural:

    cloneHostValue's transport-clonability check exists because the staged path must encode props into a command batch, and a live closure cannot cross that envelope. The direct applier never encodes a batch, so it has nothing to say about clonability.

    That is not the direct path skipping validation. It is the staged path running an extra, earlier check that only the staged path needs.

    What this changes for the fix

    Do not port cloneProps-family checks onto the direct path. They are transport invariants, not tree invariants, and adding them would impose an encoding constraint on a path that performs no encoding — cost with no correctness gain.

    The distinction to apply when auditing the prepare stage:

    check class belongs on the direct path?
    tree invariants (host placement, ref uniqueness, event-channel collision) yes — #84 is exactly this, and is the one real gap
    transport invariants (clonability, prop-bag encodability) no — meaningless without a batch to encode

    So the structural read narrows: the direct applier is missing tree-invariant checks, of which #84 is the confirmed instance. It is not missing the transport checks, and it should not acquire them.

    Net effect on this issue

    Combined with the earlier refutations of mechanisms 1 and 2, CLAIM 2's acceptance surface comes out substantially healthier than this issue's title suggests: the two appliers agree on the entire invalid-value space, produce byte-identical journals for valid tagged worklets, and diverge only where the staged path carries transport concerns the direct path does not have — plus the single genuine tree-invariant gap in #84.

    This reinforces the earlier recommendation: act on #84; treat this issue as documentation of the surface.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-authoredbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions