Skip to content

WORKFLOW_VM=quickjs silently corrupts data at workflow and step boundaries: distinct floats collapse ([0.1, 0.2] → [0.1, 0.1]) and bigints beyond int64 wrap #5774

Done

Description

@ali-aamir-fs

Versions: workflow 5.8.0 / @workflow/core 5.8.0 (latest), quickjs-wasi 3.7.0, Local World, WORKFLOW_VM=quickjs.

Repro

// value.workflow.ts
export async function valueReturn(value: unknown) {
  'use workflow'
  return value
}

// test, run with WORKFLOW_VM=quickjs through @workflow/vitest
const run = await start(getWorkflowRef('valueReturn'), [[0.1, 0.2]])
await run.returnValue // [0.1, 0.1]   (WORKFLOW_VM=node: [0.1, 0.2])
// [31260, 8104.4, 16056, 30925.6, 4400] comes back [31260, 8104.4, 16056, 8104.4, 4400]
// [2n ** 70n] comes back [0n]

It happens with no step (workflow input to return value) and through a step (input → step → result). No error is raised, and a double can also come back as a reference to an unrelated object in the same payload. WORKFLOW_VM=node is exact.

Root cause

  1. dist/runtime/quickjs-serde.js, identify (around lines 748–754), sends a handle down the primitive branch only when value.identity === 0 or value.isString. quickjs-wasi 3.7.0 returns a non-zero identity for positive doubles (their low 32 bits, a NaN-boxing tag bug, reported at JSValueHandle.identity is non-zero for doubles, and newBigInt wraps values outside int64 vercel-labs/quickjs-wasi#68). devalue's dedup then turns distinct doubles with equal low words into back-references, e.g. 0.1 and 0.2 (both 0x9999999a) or 8104.4 and 30925.6 (both 0x66666666).
  2. The BigInt reviver (around line 1780) and fromPrimitive build guest bigints with vm.newBigInt, which wraps outside int64. The reducer already reads bigints exactly through BigInt.prototype.toString; the write side was not hardened the same way.

Suggested fix

  1. In identify, treat every primitive as a primitive whatever its identity: if (pointer === 0 || value.isString || value.isNumber) return primitiveOf(value).
  2. Build bigints outside int64 from their decimal string in the guest (e.g. a captured BigInt intrinsic called with the string, with a fallback when a snapshot predates the capture), or take the fixed quickjs-wasi once released.
  3. Add node-vs-quickjs codec parity tests for distinct doubles sharing low words, integers held as doubles (2**32 + 1), and bigints beyond ±2^63.

We currently carry a downstream patch of quickjs-wasi (identity and newBigInt); with it, quickjs output matches the node codec exactly and existing event logs still parse.

Activity

  1. added a commit that references this issue on Dec 1, 2026
    a80ddd1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions