Skip to content

fix(lynx): validate cross-realm messages and accept a null event target id on Lynx for Web - #459

Merged
leonidaz merged 2 commits into
octanejs:mainfrom
Huxpro:fix/lynx-web-cross-realm-messages
Aug 1, 2026
Merged

leonidaz merged 2 commits into
octanejs:mainfrom
Huxpro:fix/lynx-web-cross-realm-messages

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #460, #461, #462.

Summary

  • Make Octane actually run on Lynx for Web (@lynx-js/web-core), where the two Lynx threads are separate JS realms (the background is its own iframe/worker).
  • Fixes the readiness-handshake deadlock and the engine-mode blank first screen — which turned out to be one root cause, not two — plus a native-event validator that dropped every tap.

Why

The two Lynx threads are distinct realms in production. Every message, host-prop bag, worklet capture, and lifecycle record a thread receives is therefore a plain object carrying the sender realm's Object.prototype, never identical to the receiver's. Octane's plain-object validators tested Object.getPrototypeOf(value) === Object.prototype — a realm-local identity check — so main rejected every message the background sent, starting with main-ready-request ("must be a plain object"). The handshake never completed, so the background never committed:

  • firstScreenRender: 'engine' painted a blank screen (nothing released the deferred first screen, because handleReady never ran), and
  • every tap was dropped (no commit could apply).

The single-realm jsdom suite could never observe this, because both "threads" share one realm there — which is also why it survived a green suite.

Note on diagnosis: an earlier triage filed these as three separate issues and hypothesized a canAnnounceReady gating deadlock (Issue 3) and a "release-before-render ordering" bug (Issue 1). Empirical instrumentation in a real browser showed both are downstream of the single cross-realm validation bug: main's validator threw before handleReady/announceReady ever ran. The gating/ordering hypotheses are refuted; the existing first-screen ordering code is correct.

Separately, @lynx-js/web-core reports an element with no author id as target.id === null; the native event payload snapshot required a string id and threw, so once the handshake was fixed a tap still died in the validator.

Changes

  • packages/lynx/src/core/plain-object.ts (new): hasCrossRealmPlainPrototype — accepts a null prototype or any prototype itself one hop from null (the shape of every realm's Object.prototype), rejecting deeper chains. Descriptor walks still enforce enumerable, non-accessor, symbol-free data.
  • Applied it across every realm-crossing validator: protocol.ts (record), host-driver.ts (host props), host-props.ts (style + CSS scope), lifecycle-data.ts, worklets.ts, main-thread.ts (lifecycle record).
  • native-events.ts: LynxNativeEventTargetSnapshot.id widened to string | null; snapshot accepts null and normalizes an omitted undefined id to null.
  • Tests: a node:vm test builds envelopes in a real second realm and proves both validators accept them (protocol.test.ts); a cross-realm style/CSS-scope test (host-props.test.ts); a null/undefined target-id test (native-events.test.ts); runtime-compatibility.test.ts graph updated for the new leaf module.

Validation

  • pnpm typecheck
  • pnpm format:check (changed files via pnpm format:files:check)
  • targeted tests: pnpm test packages/lynx — 267 passed, incl. the new cross-realm/id-null regressions
  • End-to-end: mounted the demo example through @lynx-js/web-core + <lynx-view> in Chromium via Playwright and drove a real mouse click. Before: engine mode elements rendered: 0; immediate mode painted but Count 0 never advanced. After: renders 15 elements and the click moves Count 0 → Count 1 in both engine and immediate modes.
  • full pnpm test (ran the lynx project + full typecheck; did not run every project)

The vm-based regression is the pre-fix oracle (verified it fails on the old === Object.prototype check with the exact production error).

Risk / follow-ups

  • The plain-object check is slightly looser (accepts one-hop-from-null prototypes). This is required for cross-realm data and remains safe: the validators only read own, enumerable, non-accessor data, so a prototype cannot smuggle a getter.
  • Recommend a CI job that mounts an example through @lynx-js/web-core and drives one real click — every one of these bugs survived a green suite because the existing event tests call dispatchNativeEvent directly, bypassing the engine, handshake, and validator. A self-contained Playwright harness exists and can be contributed if wanted.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches core thread-boundary validation and slightly relaxes plain-object checks (one-hop-from-null prototypes); mitigated by existing descriptor walks and focused vm regressions, but incorrect acceptance could affect security-sensitive message handling.

Overview
Fixes Lynx for Web where background and main run in separate JS realms (iframe/worker), so cross-thread plain objects no longer fail realm-local Object.prototype identity checks.

Introduces hasCrossRealmPlainPrototype in plain-object.ts and wires it into every validator that sees background-originated data: transport protocol, host-driver host-prop cloning, host-props style/CSS scope, lifecycle-data, worklets, and main-thread lifecycle records. Descriptor walks for enumerable, non-accessor data stay unchanged; only the “plain shape” test is realm-safe.

native-events widens event target id to string | null, accepts null from @lynx-js/web-core, and normalizes omitted undefined to null.

Adds node:vm regressions for cross-realm protocol envelopes and host props, plus null/undefined target-id snapshots; updates the runtime-compatibility module graph for the new leaf.

Reviewed by Cursor Bugbot for commit 0662825. Bugbot is set up for automated code reviews on this repo. Configure here.

Huxpro added 2 commits August 1, 2026 16:21
… on Lynx for Web

The two Lynx threads are separate JS realms in production (on Lynx for Web the
background is its own iframe/worker), so a message main receives is a plain
object carrying the sender realm's Object.prototype, never identical to main's.
The plain-object validators used a realm-local `=== Object.prototype` identity
test and rejected every background message: the readiness handshake never
completed, so nothing committed — engine-mode first screen was blank and every
tap was dropped. A shared hasCrossRealmPlainPrototype predicate accepts a null
prototype or one that is itself one hop from null, across the protocol, host
driver, host props, lifecycle data, worklet, and main-thread validators. A
vm-based test reproduces the real second realm the single-realm jsdom suite
could not.
@lynx-js/web-core reports an element with no author id as target.id === null.
The native event payload snapshot required a string id and threw, dropping every
tap. Accept null and normalize an omitted undefined id to null, keeping "no id"
distinct from an author-assigned empty-string id and matching the PAPI's
__SetID(node, id: string | null).
@vercel

vercel Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview Aug 1, 2026 8:36am
octane-website-mcp Ready Ready Preview Aug 1, 2026 8:36am

Request Review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 0662825. Configure here.


export interface LynxNativeEventTargetSnapshot extends LynxNativeEventPayloadRecord {
readonly id: string;
readonly id: string | null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public event id type stale

Medium Severity

The snapshot and runtime now preserve a missing target id as null, but the public LynxEventTarget.id in native-types.ts still types it as string. Background bind* handlers therefore type-check as always receiving a string while Lynx for Web can deliver null, so null-unsafe uses of event.target.id slip past typecheck and can throw at runtime.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0662825. Configure here.

Huxpro pushed a commit to Huxpro/vue-lynx that referenced this pull request Aug 1, 2026
…ane#459

Octane's every click-driven metric was previously unmeasurable on Lynx for Web.
Root cause, found from here and fixed upstream: the two Lynx threads are
separate JS realms on web (background runs in an iframe), and Octane's message
validators used a realm-local `getPrototypeOf(v) === Object.prototype` check,
so main rejected every message the background sent. The readiness handshake
never completed and the background never committed.

Measured against octanejs/octane#459 (not yet merged — re-take if review
changes it). Storms n=3 × 1k/10k/30k with the four Vue comparators in one
same-host session; mount-create ladder rebuilt at all six rungs, n=7; startup
n=11.

The penalty turns out to be shape-dependent, not the flat factor the earlier
partial data suggested. Ratios vs `vdom`:

  select@10k     13.1x     update10th@10k  10.0x     (point updates)
  create@10k      2.05x    mount-create   ~1.8x flat
  updateStorm@30k 0.86x                             (batch: faster than vdom)

Per-node object commands through structured clone re-ship whole-node commands
for every update, with no equivalent of the tiny op payload the Vue cells
collapse a point update into; under batch load that cost amortizes and Octane
wins.

Retraction: this branch previously reported Octane at the front of the startup
column. That was an artifact of the bug — the background never committed, so
Octane was timed doing strictly less work. With the handshake completing it is
now the slowest cell (108.7 ms vs vdom+ifr 81.8). The earlier mount-create
figures likewise measured main-thread-only paint and are superseded.

- synthesize.mjs / report-unified.mjs: ingest cross-storms-octane-web.json
- report-unified.mjs: NO_EVENT_ARCHS emptied (mechanism kept for any future
  undriveable framework), octane chart colour
- report-i18n.mjs: conclusion cards rewritten around point-vs-batch; the
  first-screen note now explains the realm bug and flags the superseded numbers
- OCTANE.md rewritten; UNIFIED.md + docs (EN/ZH) updated

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012PRZ3ps5MRQ9m75Wpx2f1h
Huxpro pushed a commit to Huxpro/vue-lynx that referenced this pull request Aug 1, 2026
…the bespoke workload

Octane had a measurement path of its own — a `first-screen` workload with
`--startup-only` / `--mount-create` runners, BENCH_AUTOROWS build variants, its
own report section and two charts. That existed only because Octane could not
be driven on Lynx for Web. octanejs/octane#459 removed that constraint, so the
scaffolding is removed too and Octane is now an ordinary cell measured by the
same two instruments as everything else.

Removed (reverted to the base branch byte-for-byte where possible):
- cross.mjs, build-unified.mjs, shared/data.ts, apps/ui-vdom, apps/ui-vapor —
  `--startup-only`, `--mount-create`, `--mount-reps`, BENCH_AUTOROWS,
  buildDataSeeded, __BENCH_AUTOROWS__
- synthesize.mjs: the `first-screen` workload
- report-unified.mjs: the First screen section, both bespoke charts, the
  `yUnit` axis plumbing, the extra Coverage column, NO_EVENT_ARCHS
- results/{startup-only,mount-create}.json

Added — FCP, through the canonical runner:
- core/workloads/content-octane.mjs — same feed + N keyed cards, same classes,
  same 4 + 8N element accounting as content.mjs and content-react.mjs
- core/matrix.mjs: an `octane` cell
- unified-content.mjs: buildOctaneContentRung, beside the ReactLynx branch
- synthesize/report: octane in UNIFIED_ARCH_BY_CELL and FCP_ARCH_KEYS

(A first attempt built this under packages/ifr-bench/ — the path
unified-content.mjs explicitly supersedes, whose output the authoritative
ingest would have overwritten. Deleted, not shipped.)

Added — harness/verify-coverage.mjs, generic: walks latest.json against the
coordinate lists the report renders and prints per-architecture what is
missing, because an em-dash means both "not applicable" and "never measured".
It reports `octane: COMPLETE` (11/11 storm ops, 6/6 FCP x1, 4/4 x4), and
surfaces one pre-existing gap: vapor-ifr-code-paint is FCP-only, so its entire
storm column is em-dashes today.

FCP (x1, ms, octane / vdom): 179/130 1k · 285/205 3k · 437/281 5k · 679/456 10k
· 1246/846 20k · 1590/1292 30k — 1.37x at 1k narrowing to 1.23x at 30k.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012PRZ3ps5MRQ9m75Wpx2f1h
@leonidaz
leonidaz marked this pull request as ready for review August 1, 2026 14:38

@leonidaz leonidaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 0662825c Deployed Aug 1, 2026 by vercel[bot]
Preview – octane-website-mcp — 0662825c Deployed Aug 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

snapshotEventTarget rejects target.id === null; Lynx for Web sends null for an element with no id

2 participants