Repository navigation
refactor(lynx): make validation a checked|trusted policy and delete the walk the boundary replaced - #165
Merged
Conversation
The receive-boundary validator refused hostile prototypes, symbol fields, accessors, non-enumerable properties, sparse arrays and cycles. Every one of those existed to survive a *hostile composite*: a value built on the other thread that could answer the validator one way and the host driver another. Since the transport owns encoding (#156 slice 1), every message reaching a validator is `JSON.parse` output, which can express none of them. A check whose failing branch cannot be reached is not a weaker check — it is a claim about where safety comes from that is no longer true. Safety comes from the boundary; what is left for these functions is schema. Gone: `record`'s `Reflect.ownKeys` walk and descriptor triple, `assertWireValue`'s symbol check and per-descent cycle `Set`, `assertTemplateArray`'s density count, `assertTemplateScalarValues`'s canonical decimal-key table and per-slot descriptor read-back, and the integrity half of `commandRecord`'s fused walk. Slots are read as slots and keys as keys. One bound is replaced rather than dropped. The sender's development self-check runs on the live object graph *before* the transport encodes it, so a cycle is still reachable there, and recursing into one gives a `RangeError` naming nothing — worse than the report it replaced. `assertWireValue` now carries the codec's own depth limit, which is exported for the purpose so the two cannot disagree about which payload is carryable. The tests that pinned each deleted check are rewritten to pin what actually answers the question now: the boundary normalizes a hole into an explicit `undefined`, resolves an accessor, drops a symbol field and a non-index property, defeats an `ownKeys` proxy by walking arrays by index, and refuses a foreign-prototype object at the sender. The codec's copy-on-write means an accessor is read twice and its second answer travels, which is documented where it happens and pinned where it is observable. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
`createLynxRoot` and `installLynxMainThread` now take `validation: 'checked' | 'trusted'`, defaulting to `checked`. A spelling neither implements is refused rather than quietly falling back: a typo resolving to `checked` would look like it worked, and one resolving to `trusted` would drop validation nobody asked to drop. `checked` walks a message against the schema. `trusted` says the two threads ship together and the sender is this same package, so a production build checks the envelope -- protocol, renderer, root, version, discriminant, arity -- and declines the O(commands x props) walk beneath it. The envelope stays in both modes because it is what decides which root a commit belongs to and which version it answers; skipping it would not be a trust decision but a routing bug. A development build runs the full `checked` walk under either mode, so drift fails loudly where it is introduced rather than silently where it is deployed. Neither mode changes what happens after validation. The compact completion acknowledgement, backpressure, lifetime and fault semantics are identical, and that is asserted by running the same mount, update and teardown through both modes and comparing the whole protocol trace on each thread plus the rendered HTML. The page-scoped data lifecycle receiver stays `checked` whatever a root chooses: `__RenderPage` and friends outlive any one root and carry data the app did not author. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Huxpro
changed the base branch from
feat/lynx-transport-json-boundary
to
new-lynx
August 25, 2026 23:44
- The dev send-side self-check refuses symbol-keyed record fields again: invisible to Object.keys, so the codec's value refusals never see one and JSON drops it without a trace — the one silent-loss shape left after the boundary took over. Red-verified; the checked receive walk skips the probe since JSON.parse output cannot carry one. - exactKeys' comment now derives its exactness from the transport boundary instead of a guarantee this train deleted from record(). - resolveLynxValidationMode is the single spelling guard for both ends of the wire. - The shared-depth comment stops claiming the two walks cut off at the same level; they share a budget, counted from different roots. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #156, slice 2. Validation stops being a fixed cost and becomes a policy,
and the integrity walk that slice 1 made unreachable is deleted rather than left
as decoration.
Stacked on #164 (slice 1), so this diff is slice 2 alone. It retargets to
new-lynxwhen #164 merges.The deletion. Every message reaching a validator is now
JSON.parseoutput.JSON.parseoutput cannot have symbol keys, non-enumerable properties,accessors, a foreign prototype, sparse holes, or cycles — so the branches that
refused those could not be taken. That is not a weaker check being removed; it
is a claim about where safety comes from that stopped being true. Safety comes
from the boundary now. What remains is schema.
record()goes from ~35 lines to 8: no cross-realm prototype probe, no symbolscan, no
Reflect.ownKeysreconciliation.assertWireValueloses the per-descentSet, thetry/finallythat unwoundit, the symbol check, the dense-array own-name count, and the per-index
descriptor triple.
assertTemplateArrayisArray.isArray.assertTemplateScalarValuesreadsslots by index, retiring
templateScalarIndexKey, its cache, andMAX_CACHED_TEMPLATE_SCALAR_INDEX.commandRecordusesObject.keysand breaks out of the ordered-run scaninstead of re-deriving key order.
One bound is kept rather than dropped. The sender's own development self-check
runs before the transport encodes, where the value is still a live object graph
and a cycle is exactly what a mistaken worklet capture produces. So the walk
carries the transport codec's own
LYNX_MAX_WIRE_DEPTH: one integer compareinstead of a
Setoperation per composite, the same number the encoder enforcesa moment later, and a message naming where it gave up rather than a bare
RangeError.The policy.
createLynxRootandinstallLynxMainThreadtakevalidation: 'checked' | 'trusted', defaultchecked.checked(default)trustedtrustedsays the two threads ship together and the sender is this samepackage. Production then checks the envelope — protocol, renderer, root,
version, discriminant, arity — and declines the O(commands × props) walk beneath
it. The envelope stays in both modes because it decides which root a commit
belongs to and which version it answers; skipping it would not be a trust
decision but a routing bug. Development runs the full
checkedwalk under eithermode, so drift fails loudly where it is introduced rather than silently where it
is deployed.
A spelling neither mode implements is refused on both sides of the wire, not
quietly coerced: a typo resolving to
checkedwould look like it worked, and oneresolving to
trustedwould drop validation nobody asked to drop.The page-scoped data lifecycle receiver stays
checkedwhatever a root chooses.__RenderPageand friends outlive any one root and carry data the app did notauthor.
Nothing after validation moves. The compact completion acknowledgement,
backpressure, lifetime and fault semantics are identical under both modes, and
that is asserted rather than asserted-about: the same mount → update → teardown
runs through both modes and the whole protocol trace on each thread is compared,
alongside the rendered HTML.
Measurements
protocol.ts, base488f704e8→ head:The policy adds 13 code lines and 42 total; the rest of the total-line figure is
the prose explaining why each deleted check was deletable.
Bundle size,
benchmarks/lynx-bundle-size/run.mjs, base and head built in thesame window on the same host. Both artifacts carry identical visible and
background semantic checksums at base and head, so this is a size delta on
functionally equal artifacts:
Both threads shrink because
protocol.tsis shared, and the reduction ispresent under
checkedtoo — it is smaller code on the same path, not code thattrustedtree-shakes away.The harness's own frozen gate (
NO_WORKLET_BUDGET, calibrated on upstream mainffadd397) fails at both base and head — base85424 > 77286, head85028 > 77286. That staleness is pre-existing onnew-lynx, which the #66/#103line has moved well past; this PR narrows the overshoot rather than causing it,
and recalibrating that ledger is not this PR's business.
Wire bytes are unchanged: no message shape, field, or ordering is touched.
Validation
Six red verifications, each seen failing and then restored:
assertWireValueloses the depth capprotocol.test.tstests red (stack exhaustion, no path named)lynxValidationTraversesreturnstrueunconditionallydeclines only the command walkredif (!traverse) return;moved above the envelope checkskeeps the envelope checkedredtransport.ts+main-thread.tscompleteonvalidation !== 'trusted'undefinedencoded asnullinstead of the sentinelprotocol.test.tstests redRun on this head:
pnpm format:check— ranpnpm format:files:check packages/lynx .changeset/lynx-validation-policy.md, cleanpnpm typecheck— ran the three lynx projects (packages/lynx/tsconfig.json,tsconfig.testing.json,typetests/tsconfig.json), all cleanpnpm test— ranvitest run --project lynx--project lynx, 41 files / 579 tests green;pnpm syncexit 0 with no generated changesNot run repo-wide:
pnpm format:check,pnpm typecheck,pnpm testacross all276 workspace projects. The diff is confined to
@octanejs/lynx, and the threescoped equivalents above cover every file it touches. Per #66 §2.3 the
rspeedy-pluginnative-demotest fails pre-existing in this container.Risk / follow-ups
Deliberately out of scope, to be filed as their own PR on this train:
The lifecycle walk.
lifecycle-data.ts(snapshotLynxLifecycleData,lifecycleRecordEntries,ownEnumerableDataNames) andmain-thread.ts'slifecycleRecord/lifecycleTuple/lifecycleBooleanOptionstill carry thesame now-unreachable checks — symbol scans, cross-realm prototype probes,
descriptor reads. All five callers sit downstream of
localizeLynxHostValueor
decodeLynxTransportValue, so the branches are dead for the same reason.Left here because the path is cold (per page-data update, not per node),
because Lynx transport: receiver-local JSON values, checked|trusted validation, conformance transport #156 slice 2's stated deliverable is
protocol.ts, and becausekeeping it out preserves a clean
protocol.tsline delta for Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66's L2 gate.The codec reads accessors twice.
prepare's copy-on-write returns theoriginal composite when nothing needed escaping, so
JSON.stringifywalks itagain and an accessor's second answer is what crosses. Documented on the
codec rather than paid for: the receiver is handed
JSON.parseoutput eitherway so it cannot be shown two values, and the same check would fire on every
engine-provided composite reaching
localizeLynxHostValue, where a fresh readis expected.
Per-batch memoization on the decoded receive path.
lastTemplateProgram,validatedTemplatePrograms,validatedStaticPropsandvalidatedTemplateShapeskey on object identity, which
JSON.parseno longer preserves across messages.They still work within a batch; across batches they now always miss.
Where this meets delta-protocol v2: v2 already shrinks what a commit carries, so
trusted's saving is proportionally smaller on a v2 update batch than on afirst-screen batch. The two compose — v2 reduces the number of props walked,
trusteddecides whether to walk them — and neither subsumes the other.Provenance
agent-authored)Generated by Claude Code