Skip to content

target 'lynx' and target 'universal' render different first screens when a prop value throws #70

Open

Description

@Huxpro

Found by an adversarial audit of the #58 L0–L3 equivalence claims, against the #65 stack head 2fe14465f. Counterexample to the #63 claim that "a module compiled under target: 'lynx' renders a first-screen batch deep-equal to the target: 'universal' encoding".

Root cause

The two encodings observe prop values at different points in the render walk.

  • The template lowering emits every env.p/env.e call for a host before that host's child statements — lynxTemplateCreateStatementsAst in packages/octane/src/compiler/compile-universal.js runs the props loop, then the bindings loop, then recurses into children. TEMPLATE_ENV.p validates the value on assignment at packages/lynx/src/main-renderer.ts:715.
  • renderPlanNode does the opposite: it materializes all children first (packages/lynx/src/main-renderer.ts:803-809) and only then calls hostNode, whose prop scan at packages/lynx/src/main-renderer.ts:650 is therefore the last thing to run for that subtree.

So when more than one prop value in a subtree can throw, the two encodings surface a different exception. Under a @try/@catch boundary the throw is recovered, so both renders succeed and simply paint different screens. This is not an error path.

Reproduction

Committed as a red test on claude/octane-issue-58-adversarial-audit (f70f46aa3):
packages/octane/tests/lynx-target-template-equivalence.test.ts → paints the same caught error when a prop value throws

export function Scene(props: { outer: unknown; inner: unknown }) @{
	<view class="page">
		@try {
			<view class="risky" data-outer={props.outer}>
				<text class="inner" data-inner={props.inner}>{'inner'}</text>
			</view>
		} @catch (error) {
			<text class="fallback">{error.message as string}</text>
		}
	</view>
}

with two ordinary consumer objects whose property read throws:

AssertionError: expected [ 'outer prop exploded' ] to deeply equal [ 'inner prop exploded' ]

A second observation from the same mechanism: with a component subtree inside the boundary, the child renders zero times under the template encoding and twice under the plan encoding ({count:0,text:["rendered=0"]} vs {count:2,text:["rendered=2"]}), both at hostCount: 3.

Why this is reachable

data-* is an allowlisted wildcard on the renderer's own intrinsics, so this needs no custom element and no augmentation — plain <view>/<text> and ordinary consumer objects.

Consumer impact

An app with an error boundary that renders error.message paints different text depending only on which compiler target built the module — in one case the framework's own internal diagnostic string. Side-effect counts inside the boundary differ too. Because adoption identity is positional, the background thread then adopts against a tree it did not produce.

Notes for the fix

The committed test asserts only that the two encodings agree; it does not pin either one's behavior, so either direction of fix (validate props after children on the template path, or before children on the plan path) turns it green. Picking which order is canonical is the design decision here.

Verification performed

Reproduced independently of the finding agent, with a fixture reduced to pure consumer code (no createLynxNativeResource). Adversarial refuter panel had not yet adjudicated this candidate at time of filing.

Activity

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

    @Huxpro
    OwnerAuthor

    Sharper manifestations of the same root cause — including a different @try arm

    Further audit lenses found three consequences of the evaluation-order inversion reported above. Same mechanism, no new root cause, but the consumer impact is considerably worse than the error-text case originally filed. All executed.

    1. The two encodings commit different @try arms

    <view class="page">
    	@try {
    		<view class="risky" data-outer={props.bad}>
    			<text class="inner">{use(props.thenable) as string}</text>
    		</view>
    	} @pending {
    		<text class="pending">{'PENDING'}</text>
    	} @catch (error) {
    		<text class="caught">{error.message as string}</text>
    	}
    </view>
    - create 4 <text>  {"class":"pending"}      <- target 'universal' (plan encoding)
    - create 5 <#text> {"value":"PENDING"}
    + create 4 <text>  {"class":"caught"}       <- target 'lynx' (template encoding)
    + create 5 <#text> {"value":"Lynx first-screen rendering does not support native
                                 resource prop \"data-outer\" on <view>; native
                                 resources are background-only."}
    

    The template path validates the parent's prop before rendering children, so the throw beats the suspension and @catch wins. The plan path renders children first, so use() suspends and @pending wins. Same source, same props — a different branch of the user's own error boundary, with the framework's internal diagnostic string painted as visible text.

    This reproduces identically across all five compile modes — prod, hmr-vite, hmr-webpack, dev, profile — so it is not a dev-only or HMR-only artifact.

    2. The application's own error is masked, and its subtree never renders

    Where the app itself throws during render, target: 'lynx' replaces the app's error with the framework's native-resource TypeError, because the child component is never invoked. An instrumented counter gives childRenders=0 under the template encoding vs childRenders=1 under the plan encoding, while both produce a 3-host first screen — so the app keeps running and the loss is silent.

    Two consequences worth separating:

    • The error reaching a @catch boundary or a crash reporter is the framework's diagnostic, not the thrown application error, so the real bug is invisible.
    • Every render-time side effect in the skipped subtree never happens — notably use()/useBatch prefetch registration, which docs/differences-from-react.md documents as deliberately eager in Octane. Under target: 'lynx' those fetches simply never start.

    3. The native-resource diagnostic blames a different element

    With a native resource on both a parent and a descendant, the template encoding reports data-outer on <view> (parent, validated first); the plan encoding reports data-inner on <text> (deepest child, rendered first). A developer fixing the reported element under one target finds the error moves rather than clears.

    The landed suite only ever places a native resource on a single node, so it cannot observe this.

    Why this raises the severity

    The original report framed the impact as different error.message text. The arm flip is categorically worse: it is a different rendered branch of the user's own error boundary, and it means the first screen the background thread adopts against is a tree the user should never have seen. Combined with the skipped prefetch registration, the ordering inversion changes what work happens, not just what error surfaces.

    The fix direction is unchanged — decide which order is canonical and make both encodings observe prop values at the same point. The committed red test (packages/octane/tests/lynx-target-template-equivalence.test.ts) still asserts only that the two agree, so it does not constrain that choice.


    Generated by Claude Code

  3. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Correction: my fixture is weaker than I described, and the batch does not diverge for pure programs

    Multiple refuters attacked this from different angles. The mechanism stands, but two things I said about it are wrong, and one of them is in the committed red test.

    1. My "pure consumer code" fixture is not pure

    The committed test paints the same caught error when a prop value throws uses:

    outer: { get $$kind(): never { throw new Error('outer prop exploded'); } }

    $$kind is the property isLynxNativeResource reads (packages/lynx/src/resource.ts:22). So the throw fires inside the framework's own validation predicate — the object is impersonating the internal resource brand. I described this in the commit message and in this issue as "two ordinary consumer objects whose property read throws" and as "pure consumer code, no createLynxNativeResource." That was inaccurate: an app does not define $$kind.

    2. No app-authored throw can diverge

    A refuter ran the decisive control (R4): two ordinary app errors thrown from the prop expressions — data-bad={props.f()}, data-worse={props.g()} — MATCH on both encodings ("outer expr" on both). Slot values are evaluated up-front in identical source order on both paths.

    So only the framework's own post-hoc validation checkpoint can diverge, and only after the app has already committed two independent violations of a rule the framework loudly refuses, at different depths. Everything narrower is exact parity, executed: single outer fault MATCH, single inner fault MATCH, single deep fault + @catch MATCH, two faults on the same host MATCH, two faults in sibling subtrees MATCH, zero faults MATCH.

    3. The batch itself never diverges for a pure program

    Probe D3 is my exact fixture with one change — the @catch body paints a constant instead of error.message:

    ### D3 batch equal: true      (both batches byte-identical, ids 1/4/5)
    

    With pure children the entire surface matches: painted text, hostCount 5, logicalCount 7, and the whole host batch. So the "silently different painted screen" is the app choosing to render the framework's internal diagnostic string into a text node, not a structural divergence.

    The childRenders=0 vs 1 sub-case is likewise measured through an impure render (a counter mutated during render and read back during render), which .rulesync/rules/testing.md explicitly excludes as an oracle.

    4. Both orderings already coexist inside target: 'lynx'

    Compiling the same fixture twice, both under target: 'lynx', differing only by an unrelated ref on the risky view (which trips lynxTemplateEligible so that plan keeps the interpreted encoding): the ref-bearing lynx build matches universal exactly. Both orderings therefore already ship side by side in every target: 'lynx' app and have since L1 — which is documented behaviour (§8: "eligible host-only templates emit create functions … and ineligible plans keep the interpreted encoding").

    That also means pinning this ordering would freeze lynxTemplateEligible: admitting ref-bearing hosts into templates — an obvious future slice — would break the test while changing nothing a consumer sees.

    What still stands

    The @try arm flip is the stronger evidence and is not addressed by the above. Using a real createLynxNativeResource (not a forged brand) plus a real suspending use(), the two encodings commit different arms — @catch versus @pending — and both renders succeed:

    - create 4 <text> {"class":"pending"}   - create 5 <#text> {"value":"PENDING"}
    + create 4 <text> {"class":"caught"}    + create 5 <#text> {"value":"Lynx first-screen rendering
                                                                  does not support native resource prop..."}
    

    Identical across all five compile modes. That is a structural divergence in which branch commits, not a difference in which of two violations gets named — but it still requires a native resource on a prop, which the framework refuses on both paths, so it sits behind the same "app already violated a loud rule" precondition.

    Revised severity

    Downgrade from "different rendered branch of the user's error boundary" to: a real ordering difference in framework-internal validation, observable only when an app commits two simultaneous violations of a background-only-resource rule at different depths, or one such violation racing a suspension. Both paths reject the same programs with the same error class; what differs is which violation is named and how much abandoned work ran.

    The committed red test should be re-cut against the arm-flip fixture with a real native resource, or dropped — its current $$kind fixture does not represent a consumer program, and I should not have described it as one.

    I had this ranked first in my triage. On this evidence it belongs below #84, #90, and #81.


    Generated by Claude Code

  4. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Red test re-cut — 72482a268

    Acting on the correction above rather than leaving it as a recommendation.

    packages/octane/tests/lynx-target-template-equivalence.test.ts no longer uses the { get $$kind() { throw } } fixture. It now pins the arm-selection case, which is the part of this finding that survived scrutiny:

    expected [ 'root', 'caught' ] to deeply equal [ 'root', 'pending' ]
    

    A @try body whose parent carries a real createLynxNativeResource and whose child suspends on use(). The two outcomes are mutually exclusive, both renders succeed, and the encodings commit different arms. That is a difference in what gets painted on a renderable program — not a difference in which of two simultaneous rule violations gets named, which is all the previous fixture measured.

    The custom-element __proto__ case in the same file is unchanged.

    Validation: pnpm format:files clean, pnpm typecheck:files shows only the pre-existing TS7016 on compile.js that the committed sibling suite also reports, pnpm sync no drift, both tests confirmed red.

    The severity revision stands — this belongs below #84, #90, and #81 in the triage, and it remains gated behind the app having already placed a background-only resource on a prop.


    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