Repository navigation
fix(core): convert worker results like the other adapters - #100
Merged
frontegg-david merged 1 commit intoOct 4, 2026
Merged
Conversation
The worker_threads adapter copied the script result with its own
sanitizeObject and sent it as JSON: a Date came back as {}, a BigInt
failed the run ("Do not know how to serialize a BigInt"), NaN and
Infinity became null, and maxSanitizeDepth and maxSanitizeProperties
did not apply.
The worker now runs core's sanitizeValue on the result, with the
configured limits, so it converts exactly as the double and single VM
do ('[Circular]', BigInt to string, Map to object, Set to array, limits
and functions fail the run). The transport stays JSON: the values JSON
cannot carry (Date, NaN, +/-Infinity, undefined) are sent next to the
result as [path, kind] entries and restored by the pool. The decoder
refuses an entry that does not point at a null placeholder inside the
result's arrays and null-prototype objects, so a malformed message
fails the run instead of writing elsewhere.
The worker pool docs example now disables the double VM, without
which adapter: 'worker_threads' has no effect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYour organization has reached its usage spending cap. Adjust your spending cap in the billing tab. Next included review available in 8 minutes. View limit detailsLimit details: You’ve used all 3 included reviews currently available. Your 43 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (7)
Comment |
This was referenced Oct 4, 2026
frontegg-david
added this pull request to stack #97
October 4, 2026 00:33
alexmercerpo
approved these changes
Oct 4, 2026
This was referenced Oct 4, 2026
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.
Stack 8/10:
main← #92 ← #93 ← #94 ← #95 ← #96 ← #98 ← #99 ← this ← #101 ← #102Follow-up to #94 and #98. The double VM and single VM now return a script's
Dateas aDate; theworker_threadsadapter had its own result path and didn't.Root cause
worker-script.tscopied the result withsanitizeObject(safe-deserialize.ts) and sent it as a JSON string. The protocol is JSON-only on purpose (no structured clone). Onworker_threads, before this change:{ date: new Date(0) }Date{}Date{ big: 10n }'10'Do not know how to serialize a BigInt'10'{ nan: NaN, inf: Infinity, undef: undefined }{ nan: null, inf: null }a.self = a'[Circular]'undefined'[Circular]'maxSanitizeProperties/ deeper thanmaxSanitizeDepthFix
Worker: runs core's
sanitizeValueon the result with the configuredmaxSanitizeDepth/maxSanitizeProperties, so the conversion is the same as on the in-process adapters.Transport stays JSON. New
result-encoding.ts:encodeResultreplaces each value JSON can't carry (Date,NaN,±Infinity,undefined) withnulland lists it inspecialValuesas{ path, kind, time? }.decodeResulton the main thread puts them back.The decoder treats the message as untrusted:
specialValuesmust be an array of known kinds with string or non-negative integer path segments;safeDeserializeproduces), never__proto__/constructor/prototype;nullplaceholder.Anything else throws
MessageValidationError, which fails the run.Keys the transport strips (
prototype, ...) are left out of the encoding, so their paths never dangle.ExecutionResultMessageand its zod schema gain the optionalspecialValuesfield.Behavior change
Worker results are now bounded by
maxSanitizeDepth/maxSanitizeProperties(STANDARD: 20 / 500), like the other adapters. A larger result now fails the run. Before, only the transport's 50-level depth cap applied.Docs:
worker-pool.mdxexplains how results are converted. Its basic example now setsdoubleVm: { enabled: false }: without it,adapter: 'worker_threads'has no effect (see #96).Red → green
enclave.result-sanitization.spec.ts,worker_threadscases (new){}for the Date;Do not know how to serialize a BigInt)worker-result-encoding.spec.ts(new, 14 tests: round trip through the real transport, root values, invalid Date, stripped keys, 8 malformed lists refused)Verification
jest -c libs/core/jest.config.ts --testPathIgnorePatterns /perf/: 67 suites, 2376 passed, 1 skipped (core:build-worker-scriptrebuilt first; the worker tests load it fromdist)nx lint core,nx build core, prettier: pass🤖 Generated with Claude Code