Backport #4443: fix(core): serialize a DataView as its viewed bytes - #4477
Merged
Merged
Conversation
* fix(core): serialize a DataView as its viewed bytes `DataView` had no reducer, so it fell through to devalue's built-in encoding: the whole backing `ArrayBuffer` plus the view's offset and length. Node hands out small `Buffer`s as windows onto a shared 8 KiB pool, so a four-byte `DataView` over a `Buffer.allocUnsafe(4)` serialized 8 KiB of unrelated allocations — and step returns are written to the run's event log, where that residue outlives the process that leaked it. Add a `DataView` reducer alongside the typed-array ones, base64 of the viewed range only, in all three reducer sets that share the wire format (host, VM twin, QuickJS handle-space) so a value round-trips identically whichever side serializes it. Revivers accept a non-string payload as well: devalue hands a custom reviver the hydrated referent, so a pre-reducer payload arrives as the backing `ArrayBuffer` rather than base64. Without that branch, old event logs would decode an `ArrayBuffer` as if it were base64 (or throw, in the `atob` implementations). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Nathan Rajlich <71256+TooTallNate@users.noreply.github.com> * fix(core): emit the new DataView encoding under its own tag Registering a custom reviver for `DataView` took devalue's built-in parse branch out of reach, and with it the bounds that branch restores from `["DataView", buf, offset, length]`. Those tuples are already in event logs, and the o11y UI and CLI read them with current code — so the previous commit made them render the whole pooled slab where `main` renders the few viewed bytes, surfacing exactly the residue it exists to keep out of new logs. Emit the base64 form under `DataViewBytes` instead and register no `DataView` reviver anywhere. Old payloads keep taking the built-in branch with their bounds in every reader (QuickJS's `fromViewInfo` already handles the tag), new payloads still carry only the viewed range, and the four "accept an ArrayBuffer too" reviver branches and their helpers go away. A payload written under the new tag remains unreadable by an older SDK, as it was before, but now fails with `Unknown type DataViewBytes` rather than a TypeError. Tests pin both directions: a legacy tuple revives as its recorded [2, 3] with byteOffset 1 / byteLength 2, and no reducer or reviver set claims the `DataView` tag. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Nathan Rajlich <71256+TooTallNate@users.noreply.github.com> --------- Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Co-authored-by: Nathan Rajlich <71256+TooTallNate@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 4f05621 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
TooTallNate
approved these changes
Sep 29, 2026
TooTallNate
enabled auto-merge (squash)
September 29, 2026 17:24
Contributor
Author
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests🌍 Community Worlds (106 failed)redis (21 failed):
turso (85 failed):
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
✅ 📋 Other
|
This branch was successfully deployed
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.
Automated backport of #4443 to
stable(backport job run).AI recommendation: This fixes a real data-leak defect: without a
DataViewreducer, devalue's built-in encoding persists the entire backingArrayBuffer, which for Node's pooledBufferallocator means unrelated process memory (including uninitializedallocUnsaferesidue) is written into the run's event log. I verified the bug exists onstable:packages/core/src/serialization.tsthere has typed-array reducers but noDataViewentry, so aDataViewfalls through the same way. The change is a fix rather than feature work —DataViewwas already serializable, just leaking — and it is deliberately backward compatible via a distinctDataViewBytestag, though the cherry-pick will need rework sincestablehas a singleserialization.tsinstead of theserialization/reducers/split and has noquickjs-serde.ts.Merge conflicts were resolved by AI (opencode with
anthropic/claude-opus-5). Please review the conflict resolution carefully before merging.