Skip to content

Fix "posix_spawnp failed" by restoring node-pty spawn-helper execute bit#12

Open
LonestoneBot wants to merge 1 commit into
cloudcli-ai:mainfrom
LonestoneBot:openclaw/fix-spawn-helper-exec-bit
Open

Fix "posix_spawnp failed" by restoring node-pty spawn-helper execute bit#12
LonestoneBot wants to merge 1 commit into
cloudcli-ai:mainfrom
LonestoneBot:openclaw/fix-spawn-helper-exec-bit

Conversation

@LonestoneBot

Copy link
Copy Markdown

Problem

Opening a terminal fails with:

Error: Failed to spawn shell: posix_spawnp failed

Root cause

On macOS and Linux, node-pty launches the shell by exec'ing its bundled native
spawn-helper binary. When the plugin is distributed as an unpacked bundle
(rather than a fresh npm install), the archiving/extraction step can drop the
execute bit on that binary:

-rw-r--r--  spawn-helper   # should be -rwxr-xr-x

Without +x, posix_spawnp returns EACCES, which node-pty surfaces as
posix_spawnp failed. Diagnosis on an affected install (Intel macOS,
node-pty 1.1.0): the binary is a valid Mach-O x86_64 executable with no
Gatekeeper quarantine — only the execute bit is missing. chmod +x on the
helper immediately fixes it.

Fix

Add ensureSpawnHelperExecutable(), run once at startup right after node-pty
is loaded. It locates the helper in both the modern prebuilds/<platform-arch>/
layout and the legacy build/Release/ layout, and restores the execute bit when
it's missing.

  • Best-effort: failures are logged, never thrown.
  • No-op on Windows (which uses ConPTY, no spawn-helper) and no-op when the bit
    is already set — so it can't regress a healthy install.
  • Matches the file's existing defensive style (findModule,
    prioritizeUserNpmGlobalBin).

Testing

On an affected install:

$ chmod -x .../node-pty/prebuilds/darwin-x64/spawn-helper   # reproduce
$ node dist/server.js
[web-terminal] restored missing execute bit on .../prebuilds/darwin-x64/spawn-helper
{"ready":true,"port":64034}

The helper is restored to -rwxr-xr-x and terminals spawn normally.
tsc build passes. Only src/server.ts changes (dist/ is gitignored).

🤖 Generated with Claude Code

When the plugin is distributed as an unpacked bundle (rather than a fresh
`npm install`), node-pty's native `spawn-helper` binary can lose its execute
permission. On macOS and Linux, node-pty exec's this helper to launch the
shell, so without the +x bit every pty.spawn() fails with:

    Error: Failed to spawn shell: posix_spawnp failed

Add ensureSpawnHelperExecutable(), run once at startup after node-pty loads.
It locates the helper in both the prebuilds/<platform-arch>/ and
build/Release/ layouts and restores the execute bit when missing. Best-effort
and no-op on Windows, so it can't regress a working install.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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