Skip to content

fix(ssh): npm 12 allowScripts for relay node-pty (#8720) - #9110

Closed
nwparker wants to merge 7 commits into
mainfrom
nwparker/fix-8720-wave4
Closed

nwparker wants to merge 7 commits into
mainfrom
nwparker/fix-8720-wave4

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

Remote SSH terminals fail with "node-pty is not available on this remote host" when the remote default npm is v12 (e.g. mise/asdf node latest). npm 12 blocks lifecycle scripts not listed in package.json allowScripts (warn + exit 0), so Linux never builds pty.node. This PR makes the relay native-deps install declare allowScripts, force lifecycle scripts, probe with real require(), rebuild when needed, and safely repair already-installed broken trees.

Also closes #8758 (same root on Debian 13). Rebases and lands the work from open #8686 onto current main, with concurrent loadPty hardening and #8720 regression tests.

Root cause

  1. Relay bootstrap writes package.json with pinned [email protected] + @parcel/[email protected] and runs npm install.
  2. npm 12 blocks scripts not covered by allowScripts. Verified locally with npm 12.0.1: --ignore-scripts=false alone still blocks; allowScripts: { \"[email protected]\": true, ... } unblocks.
  3. node-pty ships prebuilds for darwin/win32 only — Linux must compile. Blocked scripts → no pty.node.
  4. Install still exits 0 → deploy looks healthy → PTY spawn fails at runtime.
  5. Related: host ignore-scripts / weak require.resolve health checks hide present-but-unloadable bindings (addressed in the same install/repair path).

What changed

  • Generated relay package.json includes versioned allowScripts for both native deps.
  • npm install / npm rebuild pass --ignore-scripts=false.
  • Health + post-install probes use real require() of both addons (not require.resolve).
  • Automatic rebuild → re-probe when install leaves bindings unloadable.
  • Already-installed broken trees: best-effort repair under a repair lock; degrade (fs/git still work) rather than refuse connect.
  • Relay loadPty: single-flight load + cwd disk fallback so concurrent spawns cannot race mock/disk modules, and in-place npm repair is visible without restart.
  • Regression test ssh-relay-npm12-allow-scripts.test.ts pins the [Bug]: SSH relay npm install silently skips node-pty build under npm 12 (allowScripts) — "node-pty is not available on this remote host" #8720 contract.

Evidence

package.json (npm 12.0.1) npm install --ignore-scripts=false scripts run?
deps only blocked warn, exit 0 ❌
deps + allowScripts name@version no block ✅
  • src/main/ssh suite: 758 passed / 9 skipped
  • pty-handler + subprocess + native-deps install + npm12 regression: 151 passed
  • pnpm run typecheck:node clean; oxlint clean on touched files
  • Prior fix(ssh): repair unbuilt relay native deps #8686 adversarial/review history (Windows repair locks, non-fatal repair, deploy timeout bound) retained

ELI5

Orca installs a small helper on the SSH machine so remote terminals work. That helper needs a native piece (node-pty) that must be built on Linux. New npm versions refuse to run build scripts unless the project explicitly allows them — and we weren't allowing them — so the piece never got built, but install still said "ok". Terminals then died with a confusing error. We now allow those scripts, double-check the piece actually loads, and try a rebuild if it doesn't.

User-facing regression list

  1. Genuinely unbuildable already-installed host → slower degraded reconnects. Repair re-attempts each reconnect (bounded, non-fatal) instead of silent permanently-broken PTY. Self-heals when toolchain appears.
  2. Repair-path build-tools hint is logged, not always connection-blocking for already-installed trees (fresh install still surfaces toolchain errors).
  3. (pre-existing cosmetic) @parcel/watcher-only failure may still be tagged [NPTY-MISSING]; Windows probe stderr capture is limited.
  4. (theoretical) compound lock + slow install + slow rebuild could still hit deploy timeout; bound was widened to cover install+rebuild.

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/main/ssh — 758 pass / 9 skip
  • pnpm exec vitest run --config config/vitest.config.ts src/main/ssh/ssh-relay-npm12-allow-scripts.test.ts src/main/ssh/ssh-relay-native-deps-install.test.ts src/relay/pty-handler.test.ts src/relay/subprocess.test.ts
  • pnpm run typecheck:node
  • oxlint on touched files
  • Local npm 12.0.1 allowScripts vs flag-only matrix

Security

Fixed dep names/versions only; POSIX shellEscape / PowerShell literals unchanged. No new auth, secrets, or IPC. Probe diagnostics remain bounded stdout/stderr tails.

Related

geelen and others added 7 commits July 16, 2026 16:12
Hardening on top of the ignore-scripts native-deps repair so it can never
leave a user worse off than before the change:

- repairInstalledNativeDeps is now best-effort. An already-installed relay
  can always launch in degraded mode (fs/git/preflight still work), so a
  repair failure must not block the connection. Neither lock contention nor
  an offline/unbuildable repair aborts the deploy now: on lock-acquire failure
  we degrade without releasing a lock we do not hold; on repair-body failure
  we release our lock and fall through to a degraded launch. Pre-repair the
  health check used require.resolve (which passed for a present-but-unloadable
  binding), so a fatal repair here was a straight regression for offline /
  no-toolchain hosts. The fresh-install path keeps its fatal semantics.

- RELAY_DEPLOY_TIMEOUT_MS now exceeds a first install AND its follow-up
  rebuild (2 x NATIVE_DEPS_INSTALL_TIMEOUT_MS + headroom) so a legitimate
  install-then-rebuild is not falsely timed out mid-repair.

- shellEscape the two POSIX probe scripts instead of raw single-quoting so a
  future edit adding a quote can't silently break the node -e probe.

Adds regression coverage for degraded-launch-on-repair-throw, degraded-launch
when the repair lock can't be acquired, and the widened deploy-timeout bound.

Co-authored-by: Orca <[email protected]>
Probe node-pty's actual Windows binding, reset broken package trees before repair, and keep degraded relays retryable after self-heal. Use atomic FileMode.CreateNew locks under Windows PowerShell 5.1 and cover lock races and platform-specific system SSH behavior.
npm 12 blocks node-pty/@parcel/watcher install scripts unless package.json
lists them in allowScripts (exit 0 + warn). Linux has no node-pty prebuild, so
terminals failed with "node-pty is not available on this remote host".

Rebase #8686 onto main and harden:
- emit versioned allowScripts + --ignore-scripts=false install/rebuild
- real require() health probe + best-effort repair
- single-flight loadPty so concurrent spawns cannot race mock vs disk module
- repair test uses relay cwd and lib/index.js entry

Closes #8720
Closes #8758
@nwparker nwparker mentioned this pull request Jul 17, 2026
5 tasks done
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 27e39a8b-4efe-4cfd-ad63-c5102f90d596

📥 Commits

Reviewing files that changed from the base of the PR and between 1cdc8e8 and ed3f1f7.

📒 Files selected for processing (30)
  • src/main/ssh/ssh-connection.test.ts
  • src/main/ssh/ssh-connection.ts
  • src/main/ssh/ssh-file-transfer-abort.test.ts
  • src/main/ssh/ssh-file-transfer-abort.ts
  • src/main/ssh/ssh-relay-build-toolchain.ts
  • src/main/ssh/ssh-relay-cross-version-isolation.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.ts
  • src/main/ssh/ssh-relay-deploy-timing.ts
  • src/main/ssh/ssh-relay-deploy.test.ts
  • src/main/ssh/ssh-relay-deploy.ts
  • src/main/ssh/ssh-relay-exec-command.ts
  • src/main/ssh/ssh-relay-install-lock-commands.ts
  • src/main/ssh/ssh-relay-install-lock.ts
  • src/main/ssh/ssh-relay-native-deps-install.test.ts
  • src/main/ssh/ssh-relay-npm12-allow-scripts.test.ts
  • src/main/ssh/ssh-relay-repair-lock.ts
  • src/main/ssh/ssh-relay-versioned-install.test.ts
  • src/main/ssh/ssh-relay-versioned-install.ts
  • src/main/ssh/ssh-remote-commands.test.ts
  • src/main/ssh/ssh-remote-commands.ts
  • src/main/ssh/ssh-remote-node-resolution.ts
  • src/main/ssh/ssh-remote-platform-detection.ts
  • src/main/ssh/ssh-system-fallback.test.ts
  • src/main/ssh/system-ssh-command.ts
  • src/main/ssh/system-ssh-operation-lifecycle.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/relay/subprocess-test-utils.ts
  • src/relay/subprocess.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Superseded by merged PR #8686 (merge commit fa85536). #8686 contains the same native-dependency and npm repair plus the later Windows cross-version locking, GC and launch fencing, deployed-bundle node-pty reload, and Windows test hardening. Closing this earlier implementation to avoid landing duplicate or stale behavior.

@Jinwoo-H Jinwoo-H closed this Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants