Skip to content

fix(terminal): terminals fail on OpenClaw's Bun build when Node is not installed - #159447

Merged
steipete merged 7 commits into
mainfrom
steipete/bun-native-pty
Sep 28, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/bun-native-pty

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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 PATH and no Node process spawned, when the Bun build provides Bun.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 by pause() alone, so openclaw/bun#10 now carries the #11 exit fix as well (cherry-picked as 1f438328c6): any Bun that has pause() 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-pty on every platform, and Windows keeps node-pty under 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, spawnTerminalPty launches a Node worker (terminal-pty-node → terminal-pty-worker, over an IPC protocol), because Bun closes node-pty's nonblocking tty.ReadStream on EAGAIN. This PR adds a small adapter over Bun's own terminal, Bun.spawn(argv, { terminal }), behind the existing TerminalPtyHandle contract. spawnTerminalPty selects it on macOS and Linux when Bun.Terminal.prototype.pause is a function; other Bun builds take the unchanged Node-helper route with the same arguments as on main.

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 wait4 deadlock, 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 the terminalPty runtime entrypoint are unchanged from main, 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:

  • Environment: TERM comes from the resolved terminal name, PWD is the cwd, and an inherited process.env drops host multiplexer variables.
  • Output: output is decoded as a UTF-8 stream and delivered as strings.
  • Exit: exit is reported after PTY EOF, with node-pty's 200 ms fallback so a descendant holding the slave can't block it. A signalled exit reports exit code 0 plus the signal number.
  • Kill: the default kill signals the whole PTY session through a process-tree helper that node-pty's kill now shares.

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 after resume().

In full CI, the runtime partition runs only terminal-pty-bun.test.ts from the process lane on Bun (Linux); its siblings stay on Node. The CI Bun pin lacks pause(), 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 head 1f438328c6), started with env -i and a PATH of only the fork Bun and system directories (no node), with an isolated state dir, config, HOME, and port. A scripted operator client drove the real terminal.* 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 has pause(), so it takes the same path.

Check Result
Runtime Gateway reports Bun 1.4.3 (fork 5c704304a); the Gateway's PATH has no node
Shell spawn terminal.open starts /bin/zsh -l as leader of its own session and process group on a fresh tty, TERM=xterm-256color
Resize stty size changes from 24 80 to 43 132 after terminal.resize
Ctrl-C \x03 interrupts the foreground sleep 300, $? is 130, and the shell keeps answering
Exit codes a child's exit 7 is seen inside the shell; exit 5 arrives as terminal.exit {"exitCode":5,"reason":"process_exit"}
Backpressure with the viewer's socket stalled, a 100 MiB writer stops at 71/1600 64 KiB chunks for 4 s; after resume all 104,857,600 payload bytes arrive and the writer exits 0. On a warm Gateway, RSS stays flat through the stall (1865 → 1866 MB)
Close cleanup after terminal.close, the shell, a background job in its own process group, and a foreground job are all gone
Gateway SIGTERM graceful shutdown: shell, background job, and foreground job all gone
Gateway SIGKILL crash: the PTY session is hung up; shell, background job, and foreground job all gone
No Node no node process appears among the Gateway's descendants at any point

The interactive login shell builds its own PATH from /etc/zprofile, so command -v node inside that shell finds Homebrew node. The Gateway's own environment has none, and no node process 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.
  • A late data subscriber after exit receives nothing; without the exit-time drop it received the queued chunk after exit (negative control).
  • Test cost, pnpm test src/process/terminal-pty-bun.test.ts --maxWorkers=1 on 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 s vi.waitFor bounds. In PR CI (run 36356478860, shard core-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.
  • The replay test now drives the adapter's Bun.spawn terminal 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 receives main's unmodified params and launch-authority check; it fails against the previous revision.
  • Negative controls from earlier rounds: restoring the earlier replay loop fails the pause-honoring replay case, and restoring the earlier single-resume kill fails the "kill while the consumer keeps re-pausing" case (exit never arrives).
  • Node: 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, and git diff --check pass.

Found along the way:

  • Bun deadlock (fixed in fix(spawn): avoid blocking macOS ESRCH exit waits bun#11): stock and fork Bun on macOS could block the event loop in wait4 when kqueue reports ESRCH for a PTY child that prints and exits before its watch is registered. It hung this suite intermittently under load.
  • Concurrent-spawn signal masks (fork fix pending): two threads spawning processes at the same time on macOS could start a terminal child with Ctrl-C blocked. Bun's spawn path used sigprocmask, which is process-wide on Darwin, so one spawn saved the other's temporary all-blocked mask. The fork fix switches to pthread_sigmask, with a regression test; it is committed on a fork branch and not yet published.
  • Windows Ctrl-C through 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 node on PATH. 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 to main as well. So the Windows proof ran one layer down, at spawnTerminalPty, comparing Bun.Terminal routing (from a reverted commit on this branch) with node-pty under Node on one box:

Check Bun (Bun.Terminal) Node (node-pty)
cmd.exe spawn with cwd and env ok ok
Resize (mode con after resize(132, 43)) 132x43 after ~350 ms 132x43 after ~370 ms
Ctrl-C (\x03) stops a foreground ping no (fixed by openclaw/bun#18) yes, under 1 s
Child exit status / onExit exit code 7 / 5 7 / 5
20,000-line output burst 20,000/20,000 20,000/20,000
.cmd shim with quotes, parentheses, ^, !, trailing \ identical output identical output
kill() of a shell with background and foreground pings all gone all gone
node-pty native addon loaded none conpty.node

Windows 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), reporting 1.4.3-canary.1+1f438328c with Terminal.prototype.pause and resume present. The Gateway ran on that binary (/proc/<pid>/exe is the fork build) under env -i with only the fork and system directories on PATH. The box's real node executable was moved aside for each run and command -v node failed, and the same scripted operator client drove terminal.* through the stallable proxy, itself running on the fork Bun.

Check Result
Shell spawn /bin/bash is leader of its own session and process group on /dev/pts/0, TERM=xterm-256color
Resize stty size changes from 24 80 to 43 132
Ctrl-C the foreground job is interrupted, $? is 130, and the shell survives
Exit codes a child's exit 7 is seen inside the shell; exit 5 arrives as terminal.exit exit code 5
Backpressure with the viewer stalled, the 100 MiB writer holds at 117/1600 chunks for 4 s with Gateway RSS between 792 and 825 MB; after resume it exits 0, and a framed rerun received exactly 104,857,600 payload bytes with a matching SHA-256
Close cleanup after terminal.close, the shell, a background job in its own process group, and a foreground job are all gone
Gateway SIGTERM all terminal jobs gone; the Gateway exits 0
No Node zero node descendants 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.ts passed 12 with 1 skipped on the fork build. On the CI-pinned Bun (ddfce5d01, no pause()) it passed 5 with the 8 native cases skipped, and the real terminal went through the Node helper.

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.
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts plugin: file-transfer size: XL labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 7:55 PM ET / 23:55 UTC (Revision 6).

ClawSweeper review

What this changes

The 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
Reviewed head: b55aea839b75ca9f1b3bd1366dcef33542454b62

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Detailed Gateway proof and focused tests support the staged implementation; the standard CI Bun pin does not yet exercise the native cases.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports real macOS and Linux Gateway terminal sessions on the combined fork Bun build with no Node available, exercising the changed native route and observing input, resize, interruption, exit, cleanup, and recovery of a stalled 100 MiB output stream. The macOS run preceded the capability gate but used the same adapter on a build that satisfies it. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports real macOS and Linux Gateway terminal sessions on the combined fork Bun build with no Node available, exercising the changed native route and observing input, resize, interruption, exit, cleanup, and recovery of a stalled 100 MiB output stream. The macOS run preceded the capability gate but used the same adapter on a build that satisfies it. No stored-data contract changes.
Evidence reviewed 8 items Current main still needs Node: The fetched main revision routes every non-Windows Bun terminal through the Node helper.
Latest release retains that route: Release v2026.9.6 also routes non-Windows Bun terminals through the Node helper.
Introduced routing: The pinned PR delta selects the native adapter when Bun exposes Terminal.pause; other non-Windows Bun builds retain the Node helper, and Windows retains node-pty.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +257, Tests +445, Docs +18, Other +25. Total +745 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 2 270 13 +257
Tests 2 445 0 +445
Docs 4 23 5 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 1 29 4 +25
Total 9 767 22 +745

Review metrics

Metric Value Why it matters
Staged adapter growth production +257, tests +445 Retaining the Node helper during rollout explains the temporary production growth.
Native test wall time fork Bun 6.9 s, stock Bun 5.7 s, Node 8.4 s The PR body now records the single-worker cost requested in the prior review.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports real macOS and Linux Gateway terminal sessions on the combined fork Bun build with no Node available, exercising the changed native route and observing input, resize, interruption, exit, cleanup, and recovery of a stalled 100 MiB output stream. The macOS run preceded the capability gate but used the same adapter on a build that satisfies it. No stored-data contract changes.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Bun-only terminal support is a bounded improvement; current released Bun setups retain the existing terminal route.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports real macOS and Linux Gateway terminal sessions on the combined fork Bun build with no Node available, exercising the changed native route and observing input, resize, interruption, exit, cleanup, and recovery of a stalled 100 MiB output stream. The macOS run preceded the capability gate but used the same adapter on a build that satisfies it. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports real macOS and Linux Gateway terminal sessions on the combined fork Bun build with no Node available, exercising the changed native route and observing input, resize, interruption, exit, cleanup, and recovery of a stalled 100 MiB output stream. The macOS run preceded the capability gate but used the same adapter on a build that satisfies it. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-09-27T05:24:55.257Z sha 51c99de :: blocked before merge. :: [P1] Preserve backpressure for stock Bun terminals | [P1] Avoid the unfixed macOS Bun PTY exit path
  • reviewed 2026-09-27T06:22:03.773Z sha 7de9e06 :: blocked before merge. :: [P1] Preserve backpressure before routing stock Bun to native PTYs | [P1] Avoid the unfixed macOS native PTY exit path
  • reviewed 2026-09-27T07:26:48.186Z sha 7de9e06 :: blocked before merge. :: [P1] Keep stock-Bun backpressure when selecting the native PTY | [P1] Gate macOS native PTYs on the exit fix | [P1] Preserve Ctrl-C for Windows Bun terminals
  • reviewed 2026-09-27T07:48:34.144Z sha 057ebf1 :: blocked before merge. :: [P1] Preserve backpressure for stock-Bun terminal users | [P1] Gate macOS native PTYs on the exit fix | [P2] Make the replay test independent of PTY read timing
  • reviewed 2026-09-27T22:54:08.681Z sha b55aea8 :: blocked before merge. :: [P1] Require the macOS exit fix before selecting native PTYs

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.
@steipete steipete changed the title fix(terminal): terminals fail on Bun when Node is not installed fix(terminal): terminals fail on OpenClaw's Bun build when Node is not installed Sep 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Responses to the revision 5 review (head b55aea839b, unchanged):

  • MacOS exit fix vs. the pause() gate (P1, maintainer decision): resolved on the fork side. terminal: add pause() and resume() for output flow control bun#10 now carries the fix: media replies and identity handling #11 exit fix as well (cherry-picked as openclaw/bun@1f438328c6), so any Bun build that has Terminal.pause() also has the non-blocking ESRCH exit handling, whichever fork PR merges first. That tree is byte-identical to the build used for the macOS Gateway proof.
  • Native Linux path unexercised: now proven on Linux x64 with the fork built from 1f438328c6. It ran a real Gateway with no Node on PATH (spawn, input, resize, Ctrl-C, exit codes, stalled-viewer backpressure with exact byte and SHA-256 delivery, close and SIGTERM cleanup, zero node descendants), and on the same box the unit suite passed 12 with 1 skipped on the fork and passed 5 with 8 skipped (Node-helper route) on the CI-pinned Bun. Details are in the PR body's Evidence section.
  • Test cost: single-worker wall times for Node, fork Bun, and stock Bun, plus the PR CI shard timing, are now in the PR body.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 28, 2026
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Sep 28, 2026
@steipete steipete self-assigned this Sep 28, 2026
@steipete
steipete merged commit 8b07c92 into main Sep 28, 2026
238 of 240 checks passed
@steipete
steipete deleted the steipete/bun-native-pty branch September 28, 2026 00:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant