Skip to content

fix(desktop): restore exec bit on node-pty spawn-helper for dev terminals - #66734

Merged
OutThisLife merged 1 commit into
mainfrom
bb/desktop-spawn-helper-exec-bit
Jul 18, 2026
Merged

OutThisLife merged 1 commit into
mainfrom
bb/desktop-spawn-helper-exec-bit

Conversation

@OutThisLife

Copy link
Copy Markdown
Contributor

Summary

The embedded terminal in Hermes Desktop crashes on first use in the dev flow with:

Error occurred in handler for 'hermes:terminal:start': Error: posix_spawnp failed.
    at new UnixTerminal (.../node-pty/lib/unixTerminal.js:92:24)

Root cause: node-pty's published npm tarball ships the POSIX spawn-helper with mode 0644 (no exec bit) — verified against the upstream tarball:

$ npm pack node-pty@1.1.0 && tar tzvf node-pty-1.1.0.tgz | grep spawn-helper
-rw-r--r--  package/prebuilds/darwin-arm64/spawn-helper
-rw-r--r--  package/prebuilds/darwin-x64/spawn-helper

node-pty posix_spawnps that helper on macOS/Linux, so a non-executable copy fails every terminal spawn. This reproduces from plain Node too, not just Electron.

Why it only bites in dev:

  • Packaged builds are finestage-native-deps.mjs copies the helper into dist/ and makeExecutable()s it (chmod 755).
  • Dev is notbundle-electron-main.mjs --dev marks node-pty external, so electron . resolves require('node-pty') from the raw node_modules/node-pty, which nothing ever chmods. Every macOS/Linux dev running npm run dev hits this on the first terminal.

Fix

  • New DI-testable helper apps/desktop/electron/spawn-helper-perms.ts that scans a node-pty package root (prebuilds/* + build/Release) and restores exec bits on any spawn-helper that's missing them. Best-effort: missing files are skipped; stat/chmod failures are collected and logged, never thrown.
  • Wired into main.ts as a memoized guard invoked right before the first hermes:terminal:start spawn. Packaged builds already stage a 0755 copy, so it's a no-op there; Windows (no spawn-helper) short-circuits.

Single-resolver, single home for the policy — no build-step coupling, and it also self-heals any environment where the bit got stripped.

Test plan

  • npx vitest run electron/spawn-helper-perms.test.ts — 6 tests, covers exec-bit detection, candidate discovery, selective chmod, missing files, chmod-failure collection, and the Windows no-op.
  • npm run typecheck clean.
  • npx eslint clean on changed files.
  • node scripts/bundle-electron-main.mjs --dev builds.
  • E2E: reset spawn-helper to 0644, confirmed require.resolve('node-pty/package.json') resolves the same copy the app uses, the guard restores 0755, and node-pty spawns successfully.

…nals

node-pty's published npm tarball ships the POSIX `spawn-helper` with mode
0644 (no exec bit). node-pty `posix_spawnp`s that helper on macOS/Linux, so a
non-executable copy fails every embedded-terminal spawn with
`Error: posix_spawnp failed.`. Packaged builds are unaffected because
stage-native-deps.mjs chmods the staged copy, but the dev flow
(`npm run dev` -> `electron .`) resolves node-pty straight from node_modules,
which nothing chmods -- so the first terminal in dev always dies.

Restore the exec bit once, lazily, right before the first spawn, via a small
DI-testable helper. Idempotent: already-executable copies (packaged builds)
are left untouched, and stat/chmod failures are collected and logged rather
than thrown so terminal startup never breaks.
@OutThisLife
OutThisLife enabled auto-merge July 18, 2026 05:03
@OutThisLife
OutThisLife merged commit 126559d into main Jul 18, 2026
23 checks passed
@OutThisLife
OutThisLife deleted the bb/desktop-spawn-helper-exec-bit branch July 18, 2026 05:05
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/desktop Electron desktop app (apps/desktop/*) labels Jul 18, 2026
@alt-glitch

Copy link
Copy Markdown

This was generated by AI during triage.

Related: #61389, #62329, and #61395 repair the packaged-build staging path. This PR instead restores permissions in the raw node-pty dev-flow path before terminal spawn, so it has distinct coverage.

Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…awn-helper-exec-bit

fix(desktop): restore exec bit on node-pty spawn-helper for dev terminals
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
…awn-helper-exec-bit

fix(desktop): restore exec bit on node-pty spawn-helper for dev terminals
prmartinow pushed a commit to prmartinow/hermes-agent that referenced this pull request Aug 26, 2026
…awn-helper-exec-bit

fix(desktop): restore exec bit on node-pty spawn-helper for dev terminals
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 2026
…awn-helper-exec-bit

fix(desktop): restore exec bit on node-pty spawn-helper for dev terminals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants