Repository navigation
node:worker_threads: expose Worker stdio streams and option state #3330
Description
Summary
new Worker(filename, options) should honor Node-observable Worker option surfaces such as stdout, stderr, stdin, env, resourceLimits, name, SHARE_ENV, and trackUnmanagedFds. Perry currently has no Node-compatible Worker constructor, so these stream and option-state rows are untracked outside the broad worker execution issue.
Node Behavior
A Node v25.9.0 probe shows the stream and option shape:
const { Worker, SHARE_ENV } = require("node:worker_threads");
console.log(typeof SHARE_ENV, String(SHARE_ENV)); // symbol Symbol(nodejs.worker_threads.SHARE_ENV)
const worker = new Worker(`
const { parentPort } = require("node:worker_threads");
process.stdout.write("out-line\\n");
process.stderr.write("err-line\\n");
parentPort.postMessage({ envProbe: process.env.PERRY_WORKER_ENV_PROBE || null });
`, {
eval: true,
stdout: true,
stderr: true,
env: { PERRY_WORKER_ENV_PROBE: "child" },
resourceLimits: { maxOldGenerationSizeMb: 16 },
name: "stdio-probe",
});
console.log(!!worker.stdout, !!worker.stderr, worker.stdin === null);
console.log(worker.threadName, Object.keys(worker.resourceLimits).sort());Node exposes readable stdout/stderr streams when requested, leaves stdin null unless requested, preserves threadName, exposes resource-limit keys, and applies the supplied environment to worker code.
Perry Behavior
docs/runtime-parity-gaps.md lists Worker stdin, stdout, stderr, resourceLimits, threadName, SHARE_ENV, and option rows as missing. #3156 tracks the basic Worker file execution and parentPort lifecycle but does not explicitly cover stdio stream plumbing, SHARE_ENV, or advanced option state. Source search found environment-data and synthetic parentPort shims, plus recently merged main-thread isMainThread / threadId / resourceLimits shape support, but no Worker constructor option implementation. Exact issue/PR searches for worker.stdin, worker.stdout, worker.stderr, trackUnmanagedFds, and worker_threads resource options found no focused tracker beyond #2507/#3156.
Suggested PR Cut
Batch this with related issues in:
node:worker_threads: Worker execution and option surface parity cut
Good batch candidates:
- node:worker_threads: worker and messaging parity cut #2507
- node:worker_threads: execute Worker files with parentPort messaging #3156
- node:worker_threads: expose Worker diagnostics and profiling APIs #3329 if the Worker object shape and lifecycle handles are being introduced together
Do not batch with:
- unrelated modules
- broad subsystem rewrites
- fixes needing different test harnesses
- MessagePort / BroadcastChannel delivery unless needed for Worker message basics
- Web Locks APIs
- Perry-native
perry/threadAPI changes unless required as implementation plumbing
Acceptance
- parity/regression test starts a Worker with
stdout: trueandstderr: trueand observes readable stream output matching Node for a deterministic fixture - Worker option state for
env,name/threadName,resourceLimits,stdin, andSHARE_ENVmatches Node-observable behavior for covered cases - implementation matches Node observable behavior
- related known-failure/docs/manifest entries updated if touched
Activity
andrewtdiz commentedon May 30, 2026
Related module-state leaf: #3395 covers main-thread
worker_threadsvalue exports (isInternalThread,parentPort,threadName,workerData,SHARE_ENV) reading asundefined. This is a natural same-PR candidate if the option-surface work also normalizes Worker/module state values.