Skip to content

fix(child_process): expose parent-end pipe fd through stream._handle (port oven-sh/bun#39760) - #28

Merged
steipete merged 2 commits into
mainfrom
codex/child-stdio-handle-fd
Sep 30, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/child-stdio-handle-fd

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown

TypeScript's synchronous native API borrows child.stdout._handle.fd and child.stdin._handle.fd, switches them to blocking mode, pauses/unrefs the streams, and uses fs.readSync/fs.writeSync. Bun's stdio wrappers lacked _handle, and stdin lacked stream-level ref()/unref(), preventing this transport from initializing.

Ports oven-sh#39760 at 3e1d66db472a794a03228c60a6ba454117701950, originally implemented by @robobun. The port exposes live parent-end descriptors without transferring ownership, adds blocking-mode control, rejects closed or buffer-only descriptors, and makes stdin ref/unref edge-triggered so eager spawn initialization does not swallow the first unref. The fork's newer native-readable interfaces declare these optional properties.

Rebase onto upstream sync #26

Rebased onto 7862bb3750dc05cdcaa55711a125c461930fbd63, the fork sync through upstream ba3f27d1d1ce359d4eed842c135f0f6fba1acb00. Qualified head: 8bda719daf3546289914b9737dee3b11fc8fd5ae.

subprocess.rs and FileSink.rs merged cleanly. The sync's testing_apis::close_stdin_writer, FileSink::on_close lifetime guard, TTY state/poll flags, and force-sync classification remain intact. The port's set_stdio_blocking helper and closed-descriptor gates retain their upstream semantics. The sync's lower-level async pipe-write changes also remain intact; they do not replace the raw descriptor blocking-mode control used by the synchronous transport.

The only textual conflict was the changelog: all main entries were preserved and the stdio entry was placed below the existing child-signal entry. The old changelog-relocation commit became redundant and was dropped. No part of oven-sh#39760 was already supplied by the sync; no runtime change was dropped. All additions/deletions in the eight source/test files match the previously qualified port. Upstream oven-sh#36316 remains independent and is not included.

Rebased Bun proof

One new macOS arm64 release build, reporting 1.4.3-canary.1+8bda719da, completed successfully (210 seconds including monitoring). The SDK27 signpost patch is build-only, uncommitted, and excluded from this PR. The binary is ad-hoc signed and loads the consumer's native addons.

Check Rebased result
child-process-stdio.test.js 13 pass, 0 fail (0.563 s runner)
Full test/js/node/child_process/ 147 pass, 13 skip, 5 existing TODO, 0 fail (6.53 s runner)
Full test/js/node/net/ 266 pass, 37 skip, 0 fail (15.37 s runner)
W9 raw synchronous pipe repro PASS
W9 TypeScript synchronous API + JS filesystem callback PASS
Prettier/organize-imports, Rust formatting, JS lint PASS
All five TypeScript configs used by CI PASS
rust:check-all 12 targets pass; 0 failed, 0 skipped
Fresh independent review, P0–P2 No actionable findings

The suites used bun run build:release -- --expose-internals test <path>. The net skips include its 25 debug-only fault-injection cases plus 12 existing platform/build gates. No test exclusions or assertions were changed, and no test retries were needed.

Negative controls retained from the original qualification: all four added upstream cases fail on the supplied unpatched fork ee83b78b1; Node 24.21.0 passes both W9 probes, while that unpatched fork fails at stdout._handle.fd. Those controls were not rerun or represented as builds of the new base. The two patched W9 probes were rerun on this rebased binary.

Fresh OpenClaw consumer

Detached current origin/main at 8dc03c36077131c99e88d90c3fa68eab37a50d55, fresh pnpm install, TypeScript 7.1.0-dev.20260920.1, Vitest 5.0.1. Each file ran separately via node scripts/run-vitest.mjs <file> --maxWorkers=1, with OPENCLAW_VITEST_RUNTIME=bun, the rebuilt Bun first on PATH, and TMPDIR=/private/tmp/w10tmp mode 0700. Node handled orchestration; the rebuilt Bun executed Vitest and workers.

17/17 files and 108/108 tests pass, without retries or residual failures. Total wrapper time was 133.563 seconds. Times include setup/worker preparation.

File Result Wall time
src/agents/agent-bundle-mcp-requester-connect.import-boundary.test.ts PASS (3 tests) 9.37 s
src/agents/agent-model-discovery.imports.test.ts PASS (2 tests) 8.89 s
src/agents/code-mode.auto-results.test.ts PASS (11 tests) 52.02 s
src/agents/harness/native-hook-relay.imports.test.ts PASS (1 test) 8.56 s
src/cli/program/register.database.import-boundary.test.ts PASS (1 test) 2.66 s
src/library.test.ts PASS (3 tests) 19.59 s
src/plugin-sdk/provider-tools.test.ts PASS (31 tests) 3.22 s
test/scripts/audit-control-ui-dead-css.test.ts PASS (4 tests) 2.42 s
test/scripts/canvas-cli-import-closure.test.ts PASS (1 test) 2.92 s
test/scripts/check-session-accessor-boundary.test.ts PASS (26 tests) 4.14 s
test/scripts/check-session-transcript-reader-boundary.test.ts PASS (6 tests) 2.59 s
test/scripts/check-sqlite-transaction-boundary.test.ts PASS (5 tests) 2.88 s
test/scripts/native-typescript.test.ts PASS (3 tests) 2.22 s
test/scripts/nodes-cli-import-closure.test.ts PASS (1 test) 3.88 s
test/scripts/ts-topology.test.ts PASS (8 tests) 2.97 s
test/scripts/typecheck-inert.test.ts PASS (1 test) 3.12 s
test/test-helper-extension-import-boundary.test.ts PASS (1 test) 2.14 s

Runtime execution proof is macOS arm64. Cross-target checking is not Linux/Windows runtime execution. Tested binary SHA-256: eba9b53ba922531101e079e45dd6515ca85732751fd879e1cdbba80a1fc150f6.

Leave this PR open for coordinator review. No merge or release is part of this work order. No workflow or WebKit-pin edits are included.

Ports oven-sh#39760 at 3e1d66d,
originally implemented by robobun.

TypeScript's synchronous native API borrows child stdout/stdin _handle.fd,
sets blocking mode, and unrefs the streams before synchronous pipe I/O.
Expose live native descriptors without transferring their ownership, guard
closed and buffer-only sources, and make stdin ref/unref edge-triggered.

Retain the fork's testing_apis visibility and existing stdio tests while
adding all four upstream cases. The native lifetime and blocking semantics
are unchanged from the upstream proposal.
Declare the optional handle and File-source descriptor getter in the newer native-readable interfaces. These declarations emit identical JavaScript and preserve the tested runtime behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant