Skip to content

feat: decline a page that would cross Android's painted-element ceiling - #236

Merged
Huxpro merged 5 commits into
new-lynxfrom
feat/lynx-painted-element-ceiling
Aug 31, 2026
Merged

Huxpro merged 5 commits into
new-lynxfrom
feat/lynx-painted-element-ceiling

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Summary

Issue #234 Part C: a page that would cross Android's painted-element ceiling is
declined in JavaScript, with a diagnostic, instead of painted into a process
abort that carries no JavaScript cause at all.

Lynx on Android charges one JNI global reference per painted element and its
table holds max=51200; the ART dump at the crash attributes the entries to
Lynx's PaintingContext. Crossing it is a SIGABRT with nothing above it in the
JavaScript stack, which is why every framework in the cross-framework native
matrix DNFs at eager 10k for the same reason and none of them says why.

createLynxHostContainer now takes a paintedElementCeiling, and both paths
that paint project what a mount would cost before painting any of it:

  • the first-screen direct applier accumulates the projection in the pre-walk
    that already runs before anything is created, and refuses over the line with a
    LynxFirstScreenRefusalError — the same class as the three refusals beside
    it, so the page falls back to the command path instead of being half painted;
  • prepareLynxHostBatch walks the batch before its first command runs and
    rejects the commit, which leaves the tree the previous commit left and puts
    the reason on the wire as a reject rather than a fault.

The projection is net rather than gross: a commit that retires a run and mounts
its replacement holds the survivors, not the sum, so a page that fits is not
refused. A declared native-list row costs nothing — the platform materializes a
cell through componentAtIndex when it is about to show it — because counting a
deferred run would refuse the very <list> the diagnostic recommends.

installLynxMainThread derives the default from SystemInfo.platform, which is
the only place that knows which engine is running: native Android reports
Android and Lynx-for-Web reports web through the same field, so one bundle
serving both cannot carry the ceiling as a constant. Android gets
LYNX_PAINTED_ELEMENT_CEILING (45,000, leaving the platform's own bookkeeping
the remaining ~6,200); iOS, Lynx-for-Web, and an engine that reports no platform
get none. An explicit number sets it on any platform, and null turns it off
for an engine that lifted the limit.

Validation

  • pnpm typecheck — passes through packages/lynx/tsconfig.json and
    packages/lynx/tsconfig.testing.json, the two projects this diff is in;
    the full ~80-project chain was still running when this was opened and its
    result is reported in a comment below.
  • targeted tests: pnpm vitest run --project lynx — 49 files, 747 tests
    passing, up from 744 on the base.
  • pnpm format:files on every changed file; pnpm sync clean.
  • pnpm format:check (repo-wide) — not run; the scoped formatter covers the
    four changed files.
  • pnpm test (full Vitest run) — not run locally; CI is the gate.

Every guard was red-verified by breaking it and watching the matching test fail,
then restoring:

broken test that went red
direct applier projected > ceiling declines a first screen that would cross the ceiling
command path projected > ceiling faults a commit… / template run… / holds the ceiling against what the container already painted
destroy no longer decrements projects a teardown and its replacement net, not gross
deferred-run skip removed does not count a native list row nobody has asked for yet
mount-template branch removed counts a mounted template by the nodes it materializes
program range count removed counts the keyed ranges a first-screen program was handed to paint
platform === 'android' misspelled derives the ceiling for an Android engine
derivation forced on for every platform derives no ceiling for Lynx-for-Web / for an engine that reports no platform
null opt-out ignored turns the ceiling off for an Android engine given null

Risk / follow-ups

  • Cost. A container with no ceiling reads Infinity and skips both
    projections entirely, so nothing changes off Android. On Android the commit
    path pays one extra O(commands) pass per commit, before the pass that applies
    them. It has to be a separate pass: the whole point is to refuse before the
    first command runs.
  • What the net projection leaves unguarded. A single commit whose creates
    all precede its destroys peaks above its own net total. No core composes one
    today, and projecting the gross sum instead would refuse pages that fit.
  • 45,000 is a judgement, not a measurement. It is max=51200 less headroom
    for the platform's own references. Part D's device gate is where a real number
    can replace it.
  • Verified against the emulated Element PAPI and the Lynx testing environment,
    not on a device. Part D is the device-side correctness gate.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Lynx on Android charges one JNI global reference per painted element and its
table holds max=51200; the ART dump at the crash attributes the entries to
Lynx's PaintingContext. Crossing it aborts the process with a SIGABRT that
carries no JavaScript cause, so a page that paints too much dies without ever
saying why, and every framework in the cross-framework native matrix DNFs at
eager 10k for the same reason.

The host driver now takes a paintedElementCeiling and projects what a mount
would paint before painting any of it:

- the first-screen direct applier accumulates the projection in the pre-walk
  that already runs before anything is created, and refuses over the line with
  a LynxFirstScreenRefusalError, so the page falls back to the command path
  rather than being half painted;
- prepareLynxHostBatch walks the batch before its first command runs and
  rejects the commit, which leaves the tree the previous commit left and puts
  the reason on the wire.

The projection is net rather than gross, so a commit that retires a run and
mounts its replacement holds the survivors instead of the sum. A declared
native-list row costs nothing: the platform materializes a cell through
componentAtIndex when it is about to show it, so counting a deferred run would
refuse the very <list> the diagnostic recommends.

installLynxMainThread derives the default from SystemInfo.platform, which is
the only place that knows which engine is running. Android gets the ceiling;
iOS, Lynx-for-Web, and an engine that reports no platform get none, because
only Android's reference table charges per painted element. An explicit number
sets it on any platform and null turns it off.

Refs #234 Part C, #193.

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

Huxpro commented Aug 29, 2026

Copy link
Copy Markdown
Owner Author

Repo-wide pnpm typecheck finished on this head: exit code 0, the full chain through benchmarks/spa-navigation. That closes the one box the body left open pending — both packages/lynx/tsconfig.json and packages/lynx/tsconfig.testing.json are in it, along with every downstream project.

Two notes on what the scoped tooling reports, so a reviewer running it does not read them as this diff's:

  • pnpm typecheck:files packages/lynx/tests/painted-element-ceiling.test.ts reports Cannot find name 'Window', Cannot find name 'Element', and a missing jsdom declaration. Those come from the scoped runner resolving a test file against the package's own tsconfig.json, which carries no DOM lib; packages/lynx/tests/list-recycling.test.ts on the base reports the same class of error. pnpm typecheck uses tsconfig.testing.json and is clean.
  • node --test benchmarks/lynx-table/stages/*.test.mjs fails 1/112 on stages/results/issue57-clear-teardown.json — a record checked in before writeEvidenceJson grew its heap/wire blocks, so it is no longer byte-identical to what the writer emits. Confirmed pre-existing on 8938c1260 by stashing this diff; untouched here, and reported on The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230.

Generated by Claude Code

Huxpro commented Aug 30, 2026

Copy link
Copy Markdown
Owner Author

Gate finding — bounced from this train: the projection refuses the very page its diagnostic recommends

High review on the merged train found the ceiling projection counts every plain create command, but the apply phase skips materialization for a create whose record is a direct native-list item with an unattached cell (host-driver.ts, the directListItem/attachedByItem check in the create op) — native-list rows compose as ordinary create list-item + subtree creates + inserts (see list-recycling.test.ts's ancestry fixture), and paint nothing until componentAtIndex. Only mount-template-run with deferred: true is carved out.

Consequences, both directions:

  1. False refusal of the remedy: a 46,000-row native <list> page over the command path projects 46k+ painted elements and is refused with a diagnostic telling the author to use… a native <list>. This is the guard refusing the only page shape that survives the ceiling.
  2. Under-guard on the other side: a destroy of a never-materialized row still decrements projected (which starts from ownedNodes.size, the painted reality), so a batch retiring unmaterialized rows while creating real views projects no growth and can cross the real JNI table unrefused.

The fix is a membership-aware projection: count a create only if it will materialize — which requires resolving list membership transitively (an unattached item's whole subtree is unpainted, and the list/item/subtree may all be created within the same batch, so the projection needs the batch's own create-type and insert-parentage maps joined with state.records), and decrement on destroy/destroy-run only for records whose nodes are actually owned. Mirror the exact predicate the apply uses rather than approximating it, and red-verify all three: a large <list> page is not refused; an eager page over the ceiling still is; retiring unmaterialized rows does not mask real growth. The direct applier's pre-walk twin needs the same audit — check whether its walk counts deferred/list subtrees.

Your adversarial review caught three defects of exactly this class before the PR went up; this is the fourth, one layer deeper (batch-composed lists rather than command-shape carve-outs). Same standard: the guard re-enters the next train once the projection matches the painter. Everything else in the train merged.


Generated by Claude Code

Huxpro and others added 2 commits August 31, 2026 00:47
The gate on the merged train found this guard refuses the one page shape its
own diagnostic recommends. The projection counted every plain `create`, but
the applier skips materialization for a create whose record is a direct
native-list item with an unattached cell: the row exists logically and the
platform builds it later, through `componentAtIndex`.

Only `mount-template-run` with `deferred: true` announces that shape in the
command itself. A native list composed the ordinary way is `create list`,
`create list-item`, subtree `create`s and `insert`s, and no single one of
those commands says the row will not paint. So a 46,000-row native-`<list>`
page over the command path projected 46k+ painted elements and was refused
with a diagnostic telling the author to use a native `<list>`.

The other direction was an under-guard: `projected` starts from
`ownedNodes.size`, the painted reality, so decrementing for a row that was
never painted handed the batch headroom it never occupied. A commit retiring
declared rows while creating real views could cross the real JNI table
unrefused.

The projection now mirrors the applier's own predicate rather than
approximating it. Membership resolves transitively over the batch's create
types and insert parentage joined with accepted records, because the list,
the item and the subtree may all be created in the same commit; a pre-pass
makes that readable before the first create is counted. A `destroy`
decrements only for a host that has an element, and a `destroy-run` over a
deferred run releases the attached cells rather than the declared count.

The direct applier's pre-walk twin was audited and needed no change: its
`insideList` flag is already sticky across the whole subtree under a
`<list>`, so it never counted a deferred row.

Red-verified: forcing every create to count breaks the native-list page
test, and making `destroy` decrement unconditionally breaks the masked-growth
test and only that one.

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

Huxpro commented Aug 31, 2026

Copy link
Copy Markdown
Owner Author

Gate answered — the projection now mirrors the applier's predicate, and the twin needed no change

Pushed f628fad47 (on 057c34efa, which merges the current new-lynx in — this branch was based on 8938c1260, before the E2 train landed).

The false refusal

The projection counted every plain create. The applier skips materialization for a create whose record is a direct native-list item with an unattached cell, and only mount-template-run with deferred: true announces that shape in the command itself. A native list composed the ordinary way is create list, create list-item, subtree creates and inserts — and no single one of those commands says the row will not paint.

The fix mirrors directListItem rather than approximating it, resolved over the batch's own create-type and insert-parentage maps joined with accepted records. That join is what the finding called for and it is load-bearing: the list, the item and the subtree may all be created in the same commit, so parentage has to be readable before the first create is counted. Hence a pre-pass rather than one loop.

One detail worth recording, because it decided the pre-pass's shape: the applier resolves membership against state.records after the batch's records are committed (state.records = stagedRecords runs before the operations loop), so it uses end-of-batch parentage, not parentage at command position. A create that is inserted under a list-item later in the same batch is skipped by the applier, and the pre-pass matches that by taking the last insert/move for each id.

The under-guard

destroy now decrements only for a host that has an element — the applier's own destroy is if (activeNodes.get(id) !== undefined), and a row nobody materialized answers undefined. destroy-run over a deferred run releases the attached cells rather than the declared count, counted over the cells' physical trees; attached cells are viewport-bounded, so that walk costs far less than the run it belongs to.

The twin: audited, no change needed

The direct applier's pre-walk was already membership-aware. Its insideList flag is sticky — insideList || (node.kind === 'host' && node.type === 'list') — so the whole subtree under a <list> is excluded, not just its immediate children, and it never counted a deferred row.

There is one asymmetry, and it is benign: the pre-walk excludes everything under a <list>, while directListItem only excludes hosts under an unattached list-item — so a non-list-item child of a <list> would be under-counted by the pre-walk. It cannot occur, because such a child is refused earlier with must be a <list-item>.

Red-verified

broken test that went red
paints() forced to always true does not count a native list page composed out of ordinary commands and does not let a destroy of rows nobody materialized mask real growth
destroy decrements unconditionally does not let a destroy of rows nobody materialized mask real growth, and only that one

The second probe is the one that matters: it breaks exactly one test, so the two new cases are independent rather than one assertion written twice. The existing eager-over-ceiling refusals stayed green under both probes, which is the third case the gate asked for — the guard still refuses what it should.

The first new test puts the row subtree two levels deep under the list-item, so a projection that only checked a create's immediate parent would count it and fail.

Validation

  • npx vitest run --project lynx — 755 passed, 49 files (was 753 on the merged base; +2 new).
  • npx vitest run --project octane — 8378 passed | 1 skipped, 472 files.
  • pnpm typecheck:files packages/lynx/src/core/host-driver.ts — 0 errors.
  • pnpm format:files on all changed files (no changes); pnpm sync clean.

pnpm typecheck:files on the test file still reports the DOM-lib errors this PR's earlier comment already documented — the same set with and without this diff, and none in the added range.

The changeset's last paragraph was rewritten: it claimed "a declared native-list row is not painted and is not counted", which was only true of the deferred: true shape. It now says what the code does.


Generated by Claude Code

@Huxpro
Huxpro marked this pull request as ready for review August 31, 2026 07:39
LYNX_PAINTED_ELEMENT_CEILING is documented as the default an embedder
derives their own paintedElementCeiling from, but lived only in a module
the exports map never exposes; it is now re-exported from ./main-thread,
the entry the option lives on. Also removes an unreachable null-return in
projectedParent: batchParents stores number | null, so a stored null
already returns through the staged check and has() can never add to it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
@Huxpro
Huxpro merged commit 57ceb95 into new-lynx Aug 31, 2026
1 check failed
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