Repository navigation
Conversation
quickjs-wasi 3.7.0 gives doubles a non-zero identity (their low 32 bits), so identify() sent them down the object path and devalue deduplicated distinct doubles with equal low words into back-references: [0.1, 0.2] came back as [0.1, 0.1]. Treat every number handle as a primitive. vm.newBigInt wraps values outside int64, so a revived 2n ** 70n became 0n. Build those values with the guest's BigInt, captured at boot with the other intrinsics, from their decimal string. A capture root from a snapshot taken before this capture falls back to a bigint literal. Upstream: vercel-labs/quickjs-wasi#68 Fixes vercel#5774 Signed-off-by: Ultranmus <[email protected]>
🦋 Changeset detectedLatest commit: 67443c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 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 |
|
@Ultranmus is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
@vercel/workflow ready for review. |
|
Thanks @Ultranmus, this was a great find, and the root-cause write-up made the upstream fix straightforward: vercel-labs/quickjs-wasi#68 is fixed in quickjs-wasi 3.7.1 ( I opened #5784, which bumps to 3.7.1 instead of working around it in the serde. It keeps your tests (minus the legacy capture-root case, since that fallback is no longer needed) and credits you as co-author. I'd suggest closing this PR in favor of that one; let us know if you see anything we missed. |
### What Bumps `quickjs-wasi` from 3.7.0 to 3.7.1. With `WORKFLOW_VM=quickjs`, distinct doubles no longer collapse into one another and bigints outside int64 stay exact at workflow and step boundaries. Fixes #5774 and supersedes #5775. ### Why #5775 by @Ultranmus traced #5774 to two quickjs-wasi bugs ([vercel-labs/quickjs-wasi#68](vercel-labs/quickjs-wasi#68)) and worked around them in the serde. Both are now fixed upstream in [3.7.1](vercel-labs/quickjs-wasi#69), so this PR takes the dependency bump instead of the workarounds and keeps their tests. - **Doubles.** A double's handle reported a non-zero `identity` (the low 32 bits of the double), so devalue deduplicated doubles that shared those bits into back-references. `[0.1, 0.2]` came back as `[0.1, 0.1]`. In 3.7.1, `identity` is 0 for every number. - **Bigints.** `vm.newBigInt()` wrapped values outside int64, so `2n ** 70n` was revived as `0n`. In 3.7.1, `newBigInt()` and `handle.toBigInt()` are exact at any size. #### Changes - `quickjs-wasi` 3.7.1 in `@workflow/core` and `@workflow/world-cloudflare`, plus the lockfile. - The serde reads bigints with `handle.toBigInt()`. It previously called the captured `BigInt.prototype.toString` only because `toBigInt()` truncated, so that capture is gone. - No changes are needed in `identify` or at the `newBigInt()` call sites. Snapshots taken under 3.7.0 are refused on restore (their `engineVersion` doesn't match) and replay from the event log, as with every engine bump. That means no restored VM can carry a capture root from before this change. ### How did you test your changes? The tests are adapted from #5775 into `quickjs-serde.test.ts`: - **Wire parity with the node reference codec:** `[0.1, 0.2]`, `[31260, 8104.4, 16056, 30925.6, 4400]` (the example from #5774), integers held as doubles, and doubles next to objects. - **Bigints revived inside the VM:** `±2n ** 70n`, `2n ** 63n`, `-(2n ** 63n) - 1n` and a 30-digit value. They're checked from reference-codec bytes and from the host serde's own round trip, plus a boxed `Object(2n ** 70n)`. - I dropped #5775's legacy capture-root test, because the fallback it covered isn't needed. Results: | Check | Result | |---|---| | `quickjs-serde.test.ts` on 3.7.1 | 75 passed | | Same file with `quickjs-wasi` swapped back to 3.7.0 | 4 failed: the 3 new double/bigint cases, plus the existing `bigint` parity case, which now relies on exact `toBigInt()` | | `pnpm test` in `packages/core` | 262 files passed, 2 skipped; 5068 tests passed, 6 expected fail, 55 skipped | | `quickjs-snapshot-fuzz.test.ts` with `FUZZ_TRIALS=20` | passed | | `tsc --noEmit` (core) | clean | | Biome on the changed files | same 18 warnings as `main` | | `node scripts/check-changesets.mjs` | passed | ### PR Checklist - Required to merge - [x] 📦 `pnpm changeset` was run to create a changelog for this PR - [x] 🔒 DCO sign-off passes (run `git commit --signoff` on your commits) - [ ] 📝 Ping `@vercel/workflow` in a comment once the PR is ready, and the above checklist is complete _Written by fx_ Signed-off-by: Nathan Rajlich <[email protected]> Co-authored-by: Ultranmus <[email protected]>
|
Thanks, glad the write-up helped! Closing in favor of #5784. |
What
With
WORKFLOW_VM=quickjs, distinct doubles now stay distinct and bigints outside int64 stay exact when they cross a workflow or step boundary. Fixes #5774.Why
Both bugs come from quickjs-wasi 3.7.0 (vercel-labs/quickjs-wasi#68, still open) and silently corrupt data:
identity(its low 32 bits).identifyinquickjs-serde.tstreated any handle with a non-zero identity, other than a string, as an object, so devalue deduplicated doubles with equal low words into back-references.[0.1, 0.2]came back as[0.1, 0.1].vm.newBigIntwraps values outside int64, so theBigIntreviver andfromPrimitiveturned2n ** 70ninto0n. Reading bigints was already exact, through the capturedBigInt.prototype.toString.The fix
identifytreats every number handle as a primitive, as the issue suggests.vm.newBigInt. Larger ones are built by calling the guest'sBigIntwith their decimal string.BigIntis captured at boot with the other intrinsics, so user code can't patch it.BigIntis captured asoptional, because a VM restored from a snapshot taken before this change has a capture root without it. In that case the serde evaluates a bigint literal, which user code can't intercept either.Once quickjs-wasi ships a fix for #68, the int64 split and the fallback can go.
How did you test your changes?
New cases in
quickjs-serde.test.ts:[0.1, 0.2],[31260, 8104.4, 16056, 30925.6, 4400](the issue's example), integers held as doubles (2 ** 32 + 1,2 ** 53), and doubles next to objects.±2n ** 70n,2n ** 63n,-(2n ** 63n) - 1n, and a 30-digit value, from reference-codec bytes and from the host serde's own round trip, plus a boxedObject(2n ** 70n)through theBigIntreviver.BigIntremoved, standing in for an older snapshot.The double and bigint cases (4 tests) fail on
mainand pass with the fix. All 76 serde tests pass.I also ran the issue's repro end to end on world-local with a throwaway test (not committed). The workflow takes
[[0.1, 0.2], [31260, 8104.4, 16056, 30925.6, 4400], [2n ** 70n, -(2n ** 70n)]], passes it through a step, and returns both:mainquickjs[0.1, 0.1],8104.4twice,[0n, 0n]nodeThe full core suite passed: 4976 tests. The one failure,
world-local-coalescing("expected 13 to be less than 13"), is a timing check that passes on its own, with and without this change.tsc --noEmitpasses. Biome reports the same 18 warnings asmainfor these files.PR Checklist - Required to merge
pnpm changesetwas run to create a changelog for this PRgit commit --signoffon your commits)@vercel/workflowin a comment once the PR is ready, and the above checklist is complete