agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

Web dashboard `posix_spawnp failed` on macOS when `ignore-scripts=true` (PR #638/#1086 postinstall bypassed by Socket Firewall, pnpm 10, etc.)

Open tomfuertes opened this issue 6 months ago • 5 comments

Summary

The web dashboard's terminal pane is permanently blank on macOS arm64 because [email protected]'s prebuild ships spawn-helper with mode 0644. AO already addresses this via two postinstall fixes (PR #638, PR #1086), but both run only when npm/pnpm permits lifecycle scripts. In ignore-scripts=true environments — increasingly the default — those fixes are silently neutralized and users hit the same posix_spawnp failed symptom that #624 and #987 fixed.

This is not a duplicate of #624/#987; it's the gap their fixes don't cover.

Symptom

Dashboard tab at localhost:<port>/projects/<proj>/sessions/<session> shows the session as CONNECTED but the terminal pane never paints. Browser console:

[MuxProvider] Terminal error for <session>: posix_spawnp failed.

tmux capture-pane -p -t <session> confirms the underlying tmux session is healthy and rendered. CLI works fine — only MuxServer's per-tab pty spawn breaks.

Why the existing fixes don't fire

PR #638 added packages/ao/bin/postinstall.js (chmod spawn-helper to 0755) and PR #1086 extended it to rebuild node-pty via node-gyp if the prebuild's ABI is wrong. Both are gated by the user's package manager actually running lifecycle scripts.

The reality on a security-conscious 2026 macOS dev machine:

Tool Default behavior
pnpm 10+ --ignore-scripts is default (security hardening since pnpm 10)
Socket Firewall (sfw npm shim) Forces ignore-scripts=true to neutralize malicious postinstall vectors
npm config set ignore-scripts true Common in shared dev orgs and CI
npm install --ignore-scripts Recommended in security guides
Renovate / Dependabot bots Run with scripts disabled by default

In any of these, npm install -g @aoagents/ao lands a working binary tree but skips AO's own remediation, leaving node-pty/prebuilds/darwin-arm64/spawn-helper at 0644. The dashboard then breaks at first WS connect. There is no in-product surface for the failure — only the browser DevTools console mentions it.

Verified repro on AO 0.6.0

# Confirm the broken bit on a fresh install:
HELPER=$(find ~ -path '*node-pty/prebuilds/darwin-arm64/spawn-helper' -print -quit 2>/dev/null)
ls -la "$HELPER"
# -rw-r--r-- (mode 0644)

# Confirm it fails to spawn:
node -e 'require("node-pty").spawn("tmux",["-V"],{name:"xterm-256color",cols:80,rows:24,env:process.env});'
# Error: posix_spawnp failed.
#     at new UnixTerminal (node-pty/lib/unixTerminal.js:92:24)

# Confirm the postinstall didn't run (ignore-scripts):
npm config get ignore-scripts
# true   <-- (or via Socket Firewall, pnpm 10 defaults, etc.)

# Manual fix:
chmod +x "$HELPER"
# Refresh dashboard tab — MuxServer reads the helper on each spawn, no ao restart needed.

The npm tarball mode is verifiable straight from the registry (no install needed):

curl -sL "$(npm view [email protected] dist.tarball)" | tar tvz | grep spawn-helper
# -rw-r--r-- ...spawn-helper       <-- 0644 in the published artifact

Upstream context

  • microsoft/node-pty#850 — original report (closed)
  • microsoft/node-pty#858 / #866 — fix merged (sets 0755 on prebuild spawn-helper at publish time)
  • microsoft/node-pty#919 — open: requests a 1.1.1 patch release that backports the fix to the latest dist-tag. The fix is currently only on beta (1.2.0-beta.12).

So upstream has a fix; it's stuck on the beta channel pending a release-management decision. AO's existing postinstall fixes are a correct workaround for that gap — they just need to survive ignore-scripts=true environments.

Proposed fix

Options A and D are complementary — A is the invisible safety net (fixes silently on first spawn), D is the discoverable check users can run on demand and that surfaces the diagnosis when something is already broken. Pairing them gives you both "it just works" and "I can audit why."

Option A — Runtime self-heal in MuxServer.open() (most robust)

packages/web/dist-server/mux-websocket.js already pty-spawns tmux attach-session. On posix_spawnp failure, do a one-time best-effort chmod 0o755 on the helper and retry once before giving up:

// pseudocode at the spawn site
try {
  return ptySpawn(this.TMUX, args, options);
} catch (err) {
  if (err.message?.includes("posix_spawnp") && !this.spawnHelperRepaired) {
    this.spawnHelperRepaired = true;
    const helper = path.join(
      path.dirname(require.resolve("node-pty/package.json")),
      "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper"
    );
    try { fs.chmodSync(helper, 0o755); } catch {}
    return ptySpawn(this.TMUX, args, options);   // retry once
  }
  throw err;
}

This survives any install-time policy because it runs in the daemon process at first use. It's also safe — the chmod targets a file inside AO's own node_modules tree, not anywhere user-owned.

Option D — ao doctor check with --fix auto-remediation

ao doctor is already the user's first stop when something is off, and its output already supports a FIXED result class (Results: N PASS, N WARN, N FAIL, N FIXED). Adding a check is purely additive and reuses the existing remediation pattern.

The check would walk the same path AO's postinstall already knows (node-pty resolved via the walk-up resolver from PR #638, then prebuilds/<platform>-<arch>/spawn-helper) and verify the executable bit:

// pseudocode for the doctor check
const helperPath = resolveSpawnHelperPath();   // reuse PR #638's walker
if (!helperPath) return { status: "skip", reason: "no spawn-helper for this platform" };

const mode = fs.statSync(helperPath).mode;
if (mode & 0o111) {
  return { status: "PASS", message: `node-pty spawn-helper is executable (${helperPath})` };
}

if (opts.fix) {
  fs.chmodSync(helperPath, 0o755);
  return { status: "FIXED", message: `chmod +x on ${helperPath} (was 0o${(mode & 0o777).toString(8)})` };
}

return {
  status: "WARN",
  message: `node-pty spawn-helper is not executable (mode 0o${(mode & 0o777).toString(8)})`,
  remedy: "Web dashboard terminals will fail with `posix_spawnp failed`. Run `ao doctor --fix` or `chmod +x " + helperPath + "` to repair. See ao#1770.",
};

Option B — Pin node-pty to ^1.2.0-beta.12

The published beta has the fix baked into the tarball, so no postinstall or runtime chmod is needed regardless of script policy:

{
  "dependencies": {
    "node-pty": "1.2.0-beta.12"
  }
}

Trade-off: opting into a beta channel for a stable release. Mitigated by the fact that the diff between 1.1.0 and 1.2.0-beta.12 is small and predominantly the spawn-helper packaging fix (per the changelog).

Option C — Document the failure mode prominently

If neither A nor B is desirable, at minimum surface the failure in-product. Right now a new user with a security-hardened npm hits a blank dashboard with no actionable error anywhere except DevTools. A check at MuxServer boot — if (!fs.statSync(helper).mode & 0o111) console.error("...") — could log a clear remediation line to the daemon's stdout that ao users would actually see.

Why this matters

The web dashboard is the primary UX in onboarding screenshots and docs. macOS users with pnpm 10, Socket Firewall, or any common security-hardened npm setup hit a silent blank pane on first run. The CLI works, so users don't realize the dashboard is broken until they try to use it — by which point they've already followed setup docs that show working terminal panes. Adding a runtime self-heal closes the only remaining failure mode for this regression.

Happy to send a PR for Option A or Option D (or both — they're complementary, not alternatives).

Environment

  • AO: 0.6.0 (ao --version)
  • Node: v24.15.0 (via fnm)
  • macOS arm64
  • npm wrapped by Socket Firewall (npm is a shell function sfw npm "$@"); npm config get ignore-scripts returns true
  • Runtime: tmux (the only macOS-reliable runtime per AO docs)
  • Manual chmod +x ...spawn-helper resolves the symptom; verified by smoke-test (node -e 'pty.spawn("tmux", ...)' succeeds)

tomfuertes avatar May 09 '26 22:05 tomfuertes

Hi, thanks for filing this, it is really detailed and useful. I'm a contributor on AO and trying to get a sense of how it's working for folks using it in real workflows. Would love to hear a bit more about your experience and happy to hop on a quick 15-min call if that's easier. Here’s my calendly link https://calendly.com/atulpandey-iift1618/30min

Also, the contributors meet on Discord every day at 10pm IST: https://discord.gg/6KgeUjbe — drop in if you're around, good place to see what's being worked on and shape direction directly.

prod-blip avatar May 10 '26 14:05 prod-blip

@prod-blip new issue from a non-collaborator.

OrcInc avatar May 12 '26 17:05 OrcInc

Hi @tomfuertes , thanks for filing this, it is really detailed and useful. I'm a contributor on AO and trying to get a sense of how it's working for folks using it in real workflows. Would love to hear a bit more about your experience and happy to hop on a quick 15-min call if that's easier. Here’s my calendly link https://calendly.com/atulpandey-iift1618/30min

Also, the contributors meet on Discord every day at 10pm IST: https://discord.gg/6KgeUjbe — drop in if you're around, good place to see what's being worked on and shape direction directly.

prod-blip avatar May 14 '26 06:05 prod-blip

New Reproduction — live, confirmed root cause + fix

Reported by: @i-trytoohard (dogfooding session, live observation) | Date: 2026-05-21 | AO: 0.9.0-nightly-37d3a86d

This issue reproduced cleanly during a dogfooding session. Posting a full RCA because the symptom initially masqueraded as an unrelated terminal-rendering bug, and the diagnostic path is worth recording.

Environment

OS macOS (Darwin 24.2.0), arm64
Node v25.9.0
AO 0.9.0-nightly-37d3a86d6de2bbeacfa7ad9050773dc7a8702180 (installed via ao update)
Install location ~/Library/pnpm/global/5/ (global pnpm store)
pnpm 9.15.4
node-pty 1.1.0

Symptom

Every web terminal — orchestrator and all agent sessions — showed only a blinking cursor, no output. The mux server logged a tight reconnect loop:

[MuxServer] Opened terminal ao-orchestrator (tmux: ao-orchestrator)
[MuxServer] PTY exited for ao-orchestrator with code 1
[MuxServer] Mux connection closed
[MuxServer] New mux connection
... (repeats)

i.e. the PTY was dying immediately on spawn (exit code 1) and the client kept reconnecting.

Misdiagnosis (worth flagging)

The blank terminal was first attributed to a buffer-replay/rendering bug (the #1689 / PR #1690 area). A buffer-replay fix was dist-swapped into the running install — terminals stayed blank, which ruled out the rendering layer entirely. Lesson: a blank xterm with PTY exited … code 1 in the mux log is a spawn failure, not a render failure.

Root cause (confirmed)

A synthetic mux-WebSocket probe surfaced the real error: posix_spawnp failed. node-pty could not exec its prebuilt helper because the binary was not executable:

prebuilds/darwin-arm64/spawn-helper   mode 0644   ← non-executable
prebuilds/darwin-x64/spawn-helper     mode 0644   ← non-executable

The postinstall from PR #638 / #1086 that chmods spawn-helper to 0755 never ran for this install — the dependency lifecycle script was skipped (pnpm-state cleanup / script-skipping install path; the conditions this issue already enumerates: Socket Firewall, pnpm 10 allowlist default, explicit ignore-scripts). Notably, no ignore-scripts was persisted in project .npmrc, ~/.npmrc, or pnpm global config — the script-skip was transient to the install, which makes this hard to notice after the fact.

Fix applied locally

chmod +x \
  ~/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper \
  ~/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper

Both binaries are now -rwxr-xr-x (0755). Terminals spawned cleanly on the next open — no reinstall or rebuild needed. Confirms the only fault was the executable bit; the rest of the PTY/mux path is healthy.

Why this keeps recurring

The fix is in-place and non-durable: any reinstall / ao update under a script-skipping install path re-lands spawn-helper at 0644 and breaks terminals again. AO's terminal correctness currently depends on a dependency postinstall executing — which is increasingly not the default (pnpm 10 requires explicit approve-builds; Socket Firewall and ignore-scripts both suppress it).

Suggested permanent fixes (in order of robustness)

  1. Self-heal at runtime — before the first PTY spawn, the mux/runtime layer fs.stats spawn-helper and chmod 0755 if the executable bit is missing. Removes all dependence on install-time scripts. (Cross-platform note: no-op on Windows, which uses ConPTY, not spawn-helper.)
  2. Detect + surface — if posix_spawnp failed is caught on spawn, emit an actionable error ("node-pty helper is not executable; run chmod +x …") instead of a silent code 1 loop, so it's diagnosable in seconds rather than mistaken for a render bug.
  3. Doc/guard — document the chmod in the install/troubleshooting path and have ao doctor (if/when it exists) check the helper's mode.

Recommend option 1 as the real fix — it makes AO correct regardless of how dependencies were installed.

OrcInc avatar May 21 '26 01:05 OrcInc

Implementation scope — runtime self-heal (cross-platform)

Final fix: stop depending on the postinstall; repair the exec bit at app runtime before the first PTY spawn, with an actionable error as the fallback for the unrepairable case. The postinstall (packages/ao/bin/postinstall.js → fixNodePty()) is kept as a best-effort fast path but is no longer the source of truth — any script-skipping install (pnpm 10 allowlist, Socket Firewall, ignore-scripts) bypasses it, which is the entire bug.

Cross-platform requirements (must hold on all three)

node-pty's prebuilds layout (confirmed in 1.1.0):

Platform Helper Needs exec bit? Behaviour of fix
macOS (darwin-arm64, darwin-x64) prebuilds/{plat}-{arch}/spawn-helper Yes stat → chmod 0o755 if missing
Linux (linux-x64, linux-arm64) prebuilds/{plat}-{arch}/spawn-helper Yes — affected identically to macOS stat → chmod 0o755 if missing
Windows (win32-x64, win32-arm64) ConPTY: conpty.node, winpty-agent.exe, *.dll — no spawn-helper No (NTFS, no POSIX exec bit) no-op

So the fix is correct on all platforms by: (a) resolving the helper via ${process.platform}-${process.arch} (never hardcoding darwin-arm64), so Linux is covered for free; and (b) early-returning on Windows where there is nothing to chmod.

Work items

  1. Add ensureNodePtyExecutable() to core (packages/core/src/platform.ts or a small dedicated module):
    • if (isWindows()) return; — use isWindows() from core, not process.platform inline (Golden Rule). (Note: postinstall.js has its own local isWindows() only because it's a standalone install-time script outside the bundle — the runtime helper must use core's.)
    • Resolve node-pty's package root robustly (createRequire(import.meta.url).resolve("node-pty") → walk to package dir), then prebuilds/${process.platform}-${process.arch}/spawn-helper. Fall back to the legacy build/Release/spawn-helper location if the prebuilds path is absent.
    • fs.statSync; if the owner-exec bit (mode & 0o100) is missing, chmodSync(path, 0o755).
    • Memoize (run once per process) and wrap in try/catch — never throw. Return a boolean/flag indicating whether the helper is now executable.
  2. Call it before the first PTY spawn in every node-pty consumer. Primary site: packages/web/server/mux-websocket.ts (TerminalManager, just before pty.spawn). Grep for all node-pty import / .spawn( sites and gate each behind the memoized call so no spawn path is missed.
  3. Actionable error fallback (handles read-only / root-owned installs where chmod fails): when a PTY spawn throws posix_spawnp failed, surface a clear error ("node-pty helper is not executable; run chmod +x <resolved-path>") instead of the current silent PTY exited … code 1 reconnect loop. This converts a multi-hour misdiagnosis into a 10-second fix.
  4. Tests (mock process.platform per docs/CROSS_PLATFORM.md):
    • Windows → no-op, no chmod attempted, no throw.
    • POSIX, helper at 0o644 → chmodded to 0o755.
    • POSIX, helper already 0o755 → idempotent (no error).
    • chmod throws (read-only) → caught, returns false, no throw.
    • Path resolves correctly for linux-x64 and darwin-arm64 (don't hardcode darwin).
  5. Docs — add a one-line entry to docs/CROSS_PLATFORM.md's helper inventory for ensureNodePtyExecutable().

Constraints

  • No version bumps / changesets (release-train handles versioning).
  • Surgical: the core helper + spawn-site gating + error fallback + tests + one doc line. Don't refactor the mux server or postinstall beyond wiring the call.
  • Keep fixNodePty() in postinstall.js as-is (best-effort); do not delete it.

Mirror the chmod logic already proven in packages/ao/bin/postinstall.js:165 (fixNodePty).

OrcInc avatar May 21 '26 01:05 OrcInc