Repository navigation
fix(terminal): terminals fail on OpenClaw's Bun build when Node is not installed - #159447
Conversation
Under Bun on macOS and Linux, spawnTerminalPty launched a Node worker
because Bun closes node-pty's nonblocking tty.ReadStream on EAGAIN, so
terminals failed on Bun-only installs without Node. Replace the bridge
with an adapter over Bun.spawn({ terminal }) behind TerminalPtyHandle and
delete the worker, its IPC protocol, their tests, and the terminalPty
runtime entrypoint. Node and Windows keep node-pty.
The adapter keeps node-pty's contract: TERM/PWD handling, UTF-8 string
output, exit after PTY EOF with a 200 ms fallback, signalled exits as
exit code 0 plus the signal number, and session-tree kills. One ordered
queue replays pre-subscription output and honors pause; the OpenClaw Bun
fork's Terminal.pause()/resume() (openclaw/bun#10) supplies real output
backpressure and is feature-detected. A terminating kill keeps reading to
EOF and drains output before exit so a paused consumer cannot hold up
teardown.
The CI process lane runs the new Bun suite on Bun and keeps its siblings
on Node.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 7:55 PM ET / 23:55 UTC (Revision 6). ClawSweeper reviewWhat this changesThe branch uses Bun's native pseudo-terminal on macOS and Linux when output flow control is available, retains the existing paths elsewhere, and updates tests, CI routing, and documentation. Merge readiness✅ Ready for maintainer review Keep open. Current main and the latest release still require Node for macOS and Linux Bun terminals. The branch addresses that limitation, and the previously identified macOS exit concern is resolved in the verified Bun fork head. Priority: P2 Review scores
Verification
How this fits togetherGateway and node-host terminal requests reach a shared launcher that creates a pseudo-terminal. Terminal output, flow control, and exit events then reach viewers or command clients. flowchart LR
A[Terminal request] --> B[Shared terminal launcher]
B --> C{Runtime and flow control}
C -->|Supported Bun| D[Bun terminal]
C -->|Other runtime| E[Existing terminal path]
D --> F[Output and exit events]
E --> F
F --> G[Viewer or command client]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +257, Tests +445, Docs +18, Other +25. Total +745 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the capability-gated adapter and existing fallbacks, then pin a Bun build containing both flow control and the macOS exit fix when distributing Bun-only apps. Do we have a high-confidence way to reproduce the issue? Yes. Current main always starts a Node helper for non-Windows Bun terminals, and that helper explicitly errors when Node is unavailable; this read-only review did not execute the setup. Is this the best way to solve the issue? Yes. The shared launcher is the appropriate boundary, and the capability gate preserves the existing route for stock Bun and Windows. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b3f4c0aa540b. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
Route Bun terminal creation through the native adapter on every platform while preserving Windows batch command lines, environment inheritance, and direct kill behavior. Keep node-pty for Node and preserve existing output lifecycle handling. Add Windows ConPTY coverage and portable spawn-contract regressions; document Windows flow-control availability. Validation: 546 Node tests passed, fork Bun passed 9 tests, stock Bun passed 6, typechecks/lint/format/assertion safety passed, and independent review found no actionable issues. Real Windows ConPTY tests remain unexecuted on this macOS host.
Bun.Terminal on Windows does not deliver Ctrl-C to the foreground program; node-pty does on the same host. Restore node-pty for Bun on Windows while retaining Bun native PTYs on macOS and Linux and node-pty for Node on every platform.
# Conflicts: # docs/install/bun-compatibility.md
Resolve ClawSweeper's P1s for supported stock Bun: preserve output backpressure and avoid the macOS wait4 event-loop deadlock after fast PTY child exit. Gate the native adapter on Terminal.prototype.pause, supplied by the OpenClaw Bun fork carrying openclaw/bun#10 and #11. Other POSIX Bun builds keep main's Node helper with raw parameters and launch-authority checks; Node and Windows retain node-pty. Restore the helper, worker, protocol, tests, and runtime entrypoint byte-identically from origin/main. Require pause/resume in the gated native adapter while preserving output replay, teardown drain, EOF grace, and exit ordering. Update runtime and terminal docs without a changelog edit. Resolve the P2 replay-test issue with controlled Bun.spawn callbacks, without sleeps or a production test hook. Cover capability routing and a real stock-Bun Node-helper terminal; retain CI routing with native PTY cases skipped until its Bun pin gains the capability. Validation: Node product suites 550 passed; fork Bun 16 passed; stock Bun 9 passed with all 8 native cases skipped. Typechecks, scoped lint, formatting, assertion-safety ratchet, and docs syntax pass. The requested combined Node command reports only the known lint-suppression mismatch already fixed on main by b8fa8dc (#159553); leave that file untouched.
Output queued with no data subscriber stayed in the adapter's queue when exit was published, so a later onData subscription received it after exit. Drop it at exit, as node-pty drops output nobody listens to, and cover a late subscriber with a deterministic controlled-callback test.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Responses to the revision 5 review (head
|
|
Merged via squash.
|
…t installed (openclaw#159447) * fix(terminal): run PTYs on Bun's native terminal Under Bun on macOS and Linux, spawnTerminalPty launched a Node worker because Bun closes node-pty's nonblocking tty.ReadStream on EAGAIN, so terminals failed on Bun-only installs without Node. Replace the bridge with an adapter over Bun.spawn({ terminal }) behind TerminalPtyHandle and delete the worker, its IPC protocol, their tests, and the terminalPty runtime entrypoint. Node and Windows keep node-pty. The adapter keeps node-pty's contract: TERM/PWD handling, UTF-8 string output, exit after PTY EOF with a 200 ms fallback, signalled exits as exit code 0 plus the signal number, and session-tree kills. One ordered queue replays pre-subscription output and honors pause; the OpenClaw Bun fork's Terminal.pause()/resume() (openclaw/bun#10) supplies real output backpressure and is feature-detected. A terminating kill keeps reading to EOF and drains output before exit so a paused consumer cannot hold up teardown. The CI process lane runs the new Bun suite on Bun and keeps its siblings on Node. * fix(terminal): use Bun’s native PTY on Windows Route Bun terminal creation through the native adapter on every platform while preserving Windows batch command lines, environment inheritance, and direct kill behavior. Keep node-pty for Node and preserve existing output lifecycle handling. Add Windows ConPTY coverage and portable spawn-contract regressions; document Windows flow-control availability. Validation: 546 Node tests passed, fork Bun passed 9 tests, stock Bun passed 6, typechecks/lint/format/assertion safety passed, and independent review found no actionable issues. Real Windows ConPTY tests remain unexecuted on this macOS host. * revert(terminal): keep node-pty for Bun on Windows Bun.Terminal on Windows does not deliver Ctrl-C to the foreground program; node-pty does on the same host. Restore node-pty for Bun on Windows while retaining Bun native PTYs on macOS and Linux and node-pty for Node on every platform. * fix(terminal): keep the Node helper on Bun builds without Terminal.pause Resolve ClawSweeper's P1s for supported stock Bun: preserve output backpressure and avoid the macOS wait4 event-loop deadlock after fast PTY child exit. Gate the native adapter on Terminal.prototype.pause, supplied by the OpenClaw Bun fork carrying openclaw/bun#10 and openclaw#11. Other POSIX Bun builds keep main's Node helper with raw parameters and launch-authority checks; Node and Windows retain node-pty. Restore the helper, worker, protocol, tests, and runtime entrypoint byte-identically from origin/main. Require pause/resume in the gated native adapter while preserving output replay, teardown drain, EOF grace, and exit ordering. Update runtime and terminal docs without a changelog edit. Resolve the P2 replay-test issue with controlled Bun.spawn callbacks, without sleeps or a production test hook. Cover capability routing and a real stock-Bun Node-helper terminal; retain CI routing with native PTY cases skipped until its Bun pin gains the capability. Validation: Node product suites 550 passed; fork Bun 16 passed; stock Bun 9 passed with all 8 native cases skipped. Typechecks, scoped lint, formatting, assertion-safety ratchet, and docs syntax pass. The requested combined Node command reports only the known lint-suppression mismatch already fixed on main by 4a34b87 (openclaw#159553); leave that file untouched. * fix(terminal): never deliver unsubscribed Bun PTY output after exit Output queued with no data subscriber stayed in the adapter's queue when exit was published, so a later onData subscription received it after exit. Drop it at exit, as node-pty drops output nobody listens to, and cover a late subscriber with a deterministic controlled-callback test.
What Problem This Solves
Fixes: terminals fail with "A Node executable is required for terminals on Bun" when OpenClaw runs on its own Bun build without Node installed, which is the setup the macOS app and the desktop app are moving to.
User Impact
On macOS and Linux, operator terminals, agent terminals, node-host PTY commands, and PTY exec work on Bun-only installs with no Node on
PATHand no Node process spawned, when the Bun build providesBun.Terminal.pause()/resume(). That capability comes from the OpenClaw Bun fork: openclaw/bun#10 adds it and openclaw/bun#11 fixes a macOS event-loop deadlock after a fast PTY child exits. Neither is merged or released yet, so this change takes effect once the apps pin a fork build that includes them. OpenClaw detects the build bypause()alone, so openclaw/bun#10 now carries the #11 exit fix as well (cherry-picked as1f438328c6): any Bun that haspause()also has the exit fix, whichever fork PR merges first.Nothing changes elsewhere. Stock Bun releases (for example 1.4.2) keep today's Node helper, with its output backpressure, and still need Node installed for terminals. Node installs keep
node-ptyon every platform, and Windows keepsnode-ptyunder Bun too, because a real-Windows comparison (below) showed Bun's ConPTY terminal does not deliver Ctrl-C.Why This Change Was Made
Under Bun,
spawnTerminalPtylaunches a Node worker (terminal-pty-node→terminal-pty-worker, over an IPC protocol), because Bun closes node-pty's nonblockingtty.ReadStreamonEAGAIN. This PR adds a small adapter over Bun's own terminal,Bun.spawn(argv, { terminal }), behind the existingTerminalPtyHandlecontract.spawnTerminalPtyselects it on macOS and Linux whenBun.Terminal.prototype.pauseis a function; other Bun builds take the unchanged Node-helper route with the same arguments as onmain.An earlier revision replaced the Node helper outright. ClawSweeper pointed out that stock Bun would then lose output backpressure (a fast program's output would buffer in Gateway memory) and could hit the macOS
wait4deadlock, and the maintainer chose a staged rollout: the native path only on builds with the fix, the Node helper everywhere else. The helper, worker, protocol, their tests, and theterminalPtyruntime entrypoint are unchanged frommain, and can be deleted once pause-capable Bun builds are the norm. That is why this PR adds about 280 production lines without removing any.The adapter keeps node-pty's observable behavior:
TERMcomes from the resolved terminal name,PWDis the cwd, and an inheritedprocess.envdrops host multiplexer variables.All output goes through one ordered queue, which replays output emitted before the first subscriber and honors
pause().pause()also stops reading the PTY, so the child blocks once the kernel queue fills. After a terminating kill (SIGKILL or SIGTERM), a paused consumer can no longer hold up teardown, as with node-pty's socket teardown: the adapter keeps reading to EOF, drains the dying tree's remaining output to subscribers, then reports exit. Nothing is delivered after exit: output that no data subscriber has taken by then is dropped, as node-pty drops output nobody listens to. macOS keeps an exiting session leader in exit until its PTY output drains, so a paused terminal reports its exit only afterresume().In full CI, the runtime partition runs only
terminal-pty-bun.test.tsfrom the process lane on Bun (Linux); its siblings stay on Node. The CI Bun pin lackspause(), so there the native real-PTY cases skip, while the replay, routing, and real Node-helper cases run. PR CI runs the file under Node, where the Bun-only cases skip.Evidence
Live Gateway proof on macOS arm64: a built checkout on the fork Bun (
1.4.3-canary.1+5c704304a, openclaw/bun#10 plus #11; its source tree is byte-identical to #10's current head1f438328c6), started withenv -iand aPATHof only the fork Bun and system directories (nonode), with an isolated state dir, config,HOME, and port. A scripted operator client drove the realterminal.*Gateway methods through a TCP proxy that can stall the viewer's socket. This ran on the adapter before the capability gate was added; the gate only chooses the route, and that build haspause(), so it takes the same path.5c704304a); the Gateway'sPATHhas nonodeterminal.openstarts/bin/zsh -las leader of its own session and process group on a fresh tty,TERM=xterm-256colorstty sizechanges from24 80to43 132afterterminal.resize\x03interrupts the foregroundsleep 300,$?is 130, and the shell keeps answeringexit 7is seen inside the shell;exit 5arrives asterminal.exit {"exitCode":5,"reason":"process_exit"}terminal.close, the shell, a background job in its own process group, and a foreground job are all gonenodeprocess appears among the Gateway's descendants at any pointThe interactive login shell builds its own
PATHfrom/etc/zprofile, socommand -v nodeinside that shell finds Homebrewnode. The Gateway's own environment has none, and nonodeprocess is ever spawned.Why stock Bun keeps the helper: the same harness on stock Bun 1.4.2 with the native adapter (no
pause()) let the writer finish all 1600 chunks within 2 s while the viewer was stalled, and Gateway RSS grew from 1323 to 1805 MB as output buffered in memory. With this PR, stock Bun never takes that path.Node host: the node-host PTY entry point,
runNodePtyCommand, ran directly under the same fork Bun with a slow emitter (2 ms per chunk), so it paused the PTY on every chunk. A child writing a 2 MiB burst plus an end marker, then exiting 3 while output was still queued, delivered every byte (1968 chunks, end marker last), then{"exitCode":3}. A child that sent itself SIGTERM reported{"exitCode":0,"signal":15}. No paired node host was run live, because today's node-host PTY commands are the Codex and Claude session catalogs.Tests, on the head merged with current
main:OPENCLAW_VITEST_RUNTIME=bun pnpm test src/process/terminal-pty-bun.test.ts src/process/terminal-pty-node.test.ts: fork build 17 passed, 1 skipped (the stock-only helper case); stock Bun 1.4.2 10 passed, 8 native cases skipped, with a real terminal routed through the Node helper.exit(negative control).pnpm test src/process/terminal-pty-bun.test.ts --maxWorkers=1on an M-series Mac: Node 8.4 s wall (4 passed), fork Bun 6.9 s (12 passed), stock Bun 5.7 s (5 passed); over 80% of each run is transform. No real timers or sleeps in the deterministic cases; the real-PTY cases wait on output with 2 svi.waitForbounds. In PR CI (run 36356478860, shardcore-runtime-infra-process-hosted-2, Node) the four deterministic cases took 3 ms of test time inside a 15-file shard that ran 13.9 s.Bun.spawnterminal callbacks directly with controlled chunks, so it no longer depends on how the kernel splits PTY reads. It checks replay order, a listener pausing on the first chunk, delivery on resume, and exit after all output. The routing test covers both capability states and checks that the helper receivesmain's unmodified params and launch-authority check; it fails against the previous revision.pnpm test src/process/terminal-pty.test.ts src/process/terminal-pty-bun.test.ts src/process/terminal-pty-node.test.ts src/process/terminal-pty-node.failure.test.ts src/process/supervisor/ src/node-host/pty-command.test.ts src/gateway/terminal/ test/scripts/ci-run-node-test-shard.test.ts test/scripts/lint-suppressions.test.ts: 691 passed, 20 skipped.pnpm tsgo:core, core test typecheck, scoped oxlint, oxfmt, the assertion-safety ratchet, andgit diff --checkpass.Found along the way:
wait4when kqueue reportsESRCHfor a PTY child that prints and exits before its watch is registered. It hung this suite intermittently under load.sigprocmask, which is process-wide on Darwin, so one spawn saved the other's temporary all-blocked mask. The fork fix switches topthread_sigmask, with a regression test; it is committed on a fork branch and not yet published.Bun.Terminal(fork fix in openclaw/bun#18): a Bun process that ignores Ctrl-C (SSH, services,detached: true) passed that flag to ConPTY children. node-pty restores the default handler after creating the pseudoconsole; RPC agent configuration not working #18 does the same, proven on a Windows build of the fork.Windows, which is why Windows keeps node-pty: AWS Windows Server 2022 through Crabbox, running stock Bun 1.4.2, with no
nodeonPATH. A Gateway-level run is not possible there today: on stock Bun the Gateway exits during startup, right after "SQLite read-only worker snapshot cleanup failed", while the same build starts and listens under Node. That failure is unrelated to terminals and applies tomainas well. So the Windows proof ran one layer down, atspawnTerminalPty, comparing Bun.Terminal routing (from a reverted commit on this branch) with node-pty under Node on one box:mode conafterresize(132, 43))\x03) stops a foregroundpingonExitexit code.cmdshim with quotes, parentheses,^,!, trailing\kill()of a shell with background and foreground pingsconpty.nodeWindows code paths are unchanged from
main.Linux x64 (Blacksmith Testbox through Crabbox, lease stopped afterwards): the fork built from openclaw/bun#10's current head
1f438328c6(pause/resume plus the #11 exit fix), reporting1.4.3-canary.1+1f438328cwithTerminal.prototype.pauseandresumepresent. The Gateway ran on that binary (/proc/<pid>/exeis the fork build) underenv -iwith only the fork and system directories onPATH. The box's realnodeexecutable was moved aside for each run andcommand -v nodefailed, and the same scripted operator client droveterminal.*through the stallable proxy, itself running on the fork Bun./bin/bashis leader of its own session and process group on/dev/pts/0,TERM=xterm-256colorstty sizechanges from24 80to43 132$?is 130, and the shell survivesexit 7is seen inside the shell;exit 5arrives asterminal.exitexit code 5terminal.close, the shell, a background job in its own process group, and a foreground job are all gonenodedescendants of the Gateway across 2,251 samples (largest gap about 57 ms)On the same box,
OPENCLAW_VITEST_RUNTIME=bun pnpm test src/process/terminal-pty-bun.test.tspassed 12 with 1 skipped on the fork build. On the CI-pinned Bun (ddfce5d01, nopause()) it passed 5 with the 8 native cases skipped, and the real terminal went through the Node helper.