Skip to content

applyLynxFirstScreenDirect recurses per host level, so deep first screens now hard-fail with RangeError — and a throw has no staged fallback #90

Open

Description

@Huxpro

Found by the c2-shapes lens of the adversarial audit of #58. Counterexample to #65's claim that the direct applier leaves the container indistinguishable from the staged path and declines (returns false) only for native-<list> trees.

Stack-introduced, specifically by 7600bfbaf — verified in a git worktree at base 6079a6804, where grep -c applyLynxFirstScreenDirect packages/lynx/src/core/host-driver.ts returns 0 and main-thread.ts:1901 renders the first screen through prepareLynxHostBatch only.

Root cause

applyLynxFirstScreenDirect walks the rendered tree with a recursive visit closure (packages/lynx/src/core/host-driver.ts:2936-3013, self-call at :3007), consuming one stack frame per host tree level.

The staged path it replaced consumes none — prepareLynxHostBatch/apply iterate a flat command array, so its depth capacity is effectively unbounded (measured ≥ 60,000 levels on both base and head).

The direct applier is therefore the first stack-bound stage in the first-screen pipeline, and it binds before renderLynxFirstScreen's own recursion does.

Measured, HEAD vs base, identical file and warm-up, 2/2 runs each side

HEAD levels=98  (host depth 3920) -> painted
HEAD levels=100 (host depth 4000) -> RangeError: Maximum call stack size exceeded
HEAD levels=105 (host depth 4200) -> RangeError: Maximum call stack size exceeded

BASE levels=100 (host depth 4000) -> painted
BASE levels=105 (host depth 4200) -> painted
BASE levels=110 (host depth 4400) -> RangeError

Isolated repro naming the throwing frame, 3/3 runs identical:

renderLynxFirstScreen OK: hostCount=5000 (nesting depth 5000)
applyLynxFirstScreenDirect: RangeError: Maximum call stack size exceeded
    at planLynxHostPropPatch (packages/lynx/src/core/host-props.ts:574:31)
    at visit (packages/lynx/src/core/host-driver.ts:2955:7)
    at visit (packages/lynx/src/core/host-driver.ts:3007:4)
  container faulted=true
prepareLynxHostBatch().apply(): painted, capture roots=1, nodes=5000

The renderer produces the tree successfully; only the applier refuses it. Warmed same-process capacity: render reaches 5000, direct reaches 3968 — ~1030 levels the renderer can produce and the direct applier cannot paint.

The more serious half: a throw has no fallback

packages/lynx/src/main-thread.ts:1906 falls back to the staged path only when applyLynxFirstScreenDirect returns false (the native-<list> decline). A throw instead takes the catch at :1934, which calls retireFirstScreen(source, 'failed', 'failed') and rethrows.

So the first screen is retired rather than repainted through the staged path that would have succeeded on the identical tree:

renderLynxFirstScreen(levels=125) OK: hostCount=5000
firstScreenRoot.render THREW RangeError
  first-screen snapshot after render: null
  page children painted: 13 bytes of HTML

false falls back; a throw does not. That asymmetry turns any direct-applier fault into a dead first screen, regardless of cause.

Consumer impact, with an honest bound

firstScreenRoot.render(...) throws to the application, main.firstScreenSnapshot() is null, and the page stays empty. The fixture is a plain recursive component — the shape of a tree view or a nested comment thread — not a synthetic node tree.

Practical severity is bounded by depth: 4000 nested hosts is unrealistic for a mobile UI under V8's ~1 MB default stack. The direction is engine-independent (one frame per level versus zero), but the absolute crossover is not, and this could not be measured on the real Lynx main-thread engine. PrimJS's JS stack budget is typically far smaller than V8's, which would push the crossover proportionally lower — that is the open question, and it needs a device to answer.

Suggested direction

Either fix removes the regression, and they are independent:

  1. Make visit iterative (explicit work stack), restoring the staged path's unbounded depth.
  2. Extend the fallback so a throw from applyLynxFirstScreenDirect also retries through prepareLynxHostBatch, not just a false return.

(2) is worth doing regardless of (1): it converts any future direct-applier fault from a dead first screen into a slower one.

Verification performed

Executed at HEAD 5d000b30e and in a base worktree, 2/2 runs per side on the ladder and 3/3 on the isolated repro, through the public API (firstScreenRoot.render). Attribution established by the applier's absence at base. Not independently re-run by me; no adversarial refuter has adjudicated it.

Related

Activity

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

    @Huxpro
    OwnerAuthor

    Disclosure: this finding has had no adversarial verification

    Every other high-priority finding in this audit went through either a 2-of-3 refuter panel or a dedicated reachability attacker. This one did not — it came from the c2-shapes lens in a close-out workflow I built with no verify phase, and it landed after the reachability audit had already been scoped to #81/#83/#84.

    That matters because of this audit's track record: 18 filed, 4 withdrawn, 1 substantially downgraded. Every failure had the same shape — a real, reproducible mechanism whose severity claim outran what an ordinary program can reach. #72 was withdrawn after I personally reproduced 200,001 iterations, because reproducing a probe confirms the fixture, not the claim.

    What this finding does have

    Stronger primary evidence than most of the withdrawn ones, which is why I still rank it second:

    • Attribution is near-definitional — grep -c applyLynxFirstScreenDirect returns 0 at base 6079a6804, so the recursive walk cannot predate the stack.
    • Public API only — driven through firstScreenRoot.render, not a hand-built node tree or a forged descriptor.
    • Reproducibility stated — 2/2 runs per side on the HEAD-vs-base ladder, 3/3 on the isolated repro, with the throwing frame named (visit at host-driver.ts:3007).
    • The agent bounded its own severity — it volunteered that 4000 nested hosts is unrealistic under V8's ~1 MB stack, and that the PrimJS crossover is unmeasured.

    What has not been tested

    1. Whether the depth is reachable in a real app. The fixture is a plain recursive component, but nobody built a realistic tree view or comment thread and measured its actual nesting. On V8 this likely needs a pathological tree.
    2. The PrimJS crossover — the only number that would make the depth limit matter in production, and it needs a device.
    3. Whether the fallback asymmetry has an independent trigger. This is the half I would defend hardest: main-thread.ts:1906 falls back only on a false return, so any throw from the direct applier retires the first screen instead of retrying the staged path. That is a structural property visible in the source, independent of stack depth — but no probe has driven it from a non-depth fault.

    Point 3 is the cheapest thing to settle and probably the one worth acting on regardless of point 1: inject any fault into the direct walk and check whether the staged path is ever attempted.

    I would rather flag this asymmetry than let the issue inherit confidence from the findings around it that were adversarially tested.


    Generated by Claude Code

  3. added a commit that references this issue on Aug 19, 2026
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