Skip to content

fix(ssh): repair unbuilt relay native deps - #8686

Merged
Jinwoo-H merged 7 commits into
stablyai:mainfrom
geelen:fix/relay-native-deps-auto-repair
Jul 17, 2026
Merged

Jinwoo-H merged 7 commits into
stablyai:mainfrom
geelen:fix/relay-native-deps-auto-repair

Conversation

@geelen

@geelen geelen commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remote terminals could fail with "node-pty is not available on this remote host" after an Orca update on hosts whose npm is configured to skip lifecycle scripts (NPM_CONFIG_IGNORE_SCRIPTS=true, or ignore-scripts=true in ~/.npmrc). This makes the relay's native-dependency install detect and repair that state, and makes the repair path safe so it can never leave a user worse off than before.

Original fix by @geelen; repair-safety hardening added while taking the PR over.

Root cause

The relay installs two native addons on the remote host — node-pty and @parcel/watcher. When the remote npm config ignores lifecycle scripts, npm install lands the JS on disk but never builds node-pty's native binding. The old health/probe checks used require.resolve("node-pty"), which only checks that the JS entrypoint resolves — it passes even when the native .node binding is absent. Orca therefore considered the install healthy, and the relay's runtime require("node-pty") threw at PTY-spawn time.

Reproduced locally (npm 11.16.0):

Command (remote has NPM_CONFIG_IGNORE_SCRIPTS=true) native binding built?
npm install ❌ no — but require.resolve still passes
npm install --ignore-scripts=false ✅ yes — CLI flag overrides the env var and project .npmrc
npm rebuild --ignore-scripts=false <pkg> ✅ yes — repairs an already-present package

What changed

Base fix

  • Health check and post-install probe now use a real require() of both addons (not require.resolve()), so a present-but-unloadable binding is caught.
  • npm install / npm rebuild pass --ignore-scripts=false to force lifecycle scripts even when the host env / npmrc disables them.
  • After install, if the binding still won't load, run a targeted npm rebuild --ignore-scripts=false and re-probe before the relay launches.

Hardening (takeover)

  • Repair is now best-effort / non-fatal. An already-installed relay can always launch in degraded mode (fs/git/preflight still work — only native-backed ops fail), so a repair failure must not block the connection: neither install-lock contention nor an offline/unbuildable repair aborts the deploy. Because the old health check used require.resolve (which passed for a broken binding), newly making repair fatal would have been a straight regression for offline / no-toolchain hosts. The fresh-install path keeps its fatal semantics (no relay to launch yet).
  • Deploy-timeout envelope. The overall deploy timeout now exceeds a first install and its follow-up rebuild, so a legitimate install-then-rebuild isn't falsely timed out mid-repair.
  • Probe quoting hardened — the POSIX node -e probe scripts go through shellEscape so a future edit can't silently break the -e quoting.

Evidence

  • Base mechanism reproduced end-to-end on npm 11.16.0 (table above): the bug, the --ignore-scripts=false override (beats both the env var and project .npmrc), and npm rebuild repairing an already-present package.
  • Tests — ssh-relay-native-deps-install.test.ts + ssh-relay-deploy.test.ts pass. Added coverage: real require() health check, --ignore-scripts=false on install + rebuild, automatic rebuild→re-probe recovery, post-rebuild re-probe SSH-failure propagation, degraded launch on repair-throw, degraded launch when the repair lock can't be acquired, and the widened deploy-timeout bound. Full src/main/ssh suite: 676 passing / 2 skipped; typecheck + oxlint clean.
  • Adversarial review — several independent passes (shell/quoting, Windows/PowerShell, control-flow/regression, holistic). An earlier iteration used an on-disk "unrepairable" marker to skip repeat repairs; review showed it could persist a transient rebuild failure as permanent, so it was dropped for the simpler always-retry + non-fatal design.

ELI5

Orca drops a tiny helper on the remote machine so your terminals work there. The helper needs a special part (node-pty) that has to be built on the remote host. Some locked-down machines are set up to skip "build steps" during installs — so the part got copied but never built. Orca's old check only asked "is the file there?" (yes) instead of "does it actually work?" (no), so it thought all was well and then terminals broke.

Now Orca asks the real question ("does it load?"), tells npm to build it anyway, and if it's still broken, tries a rebuild. And if the remote genuinely can't build it, Orca still connects you (you just won't get remote terminals) instead of refusing to connect at all.

User-facing regression list

No availability regressions — everything that connected before still connects, and the previously-broken ignore-scripts case now works. The minor, non-blocking tradeoffs of the non-fatal design, stated honestly:

  1. Genuinely-unbuildable, already-installed host → slower degraded reconnects. A host that truly can't build node-pty (no compiler / no prebuild for its arch) and already has a completed relay re-attempts a repair each reconnect (a no-op npm install + a node-gyp rebuild that fails — usually in seconds) before launching degraded. Before, it reconnected fast with a silently-broken PTY. This is non-fatal, bounded, and self-heals the instant the host gains a toolchain (the rebuild then succeeds). Deliberately not memoized with a skip-marker here — an on-disk marker risked stranding transient failures; a session/TTL memo is a reasonable follow-up.
  2. Repair-path build-tools hint is logged, not surfaced. For the rare already-installed-needs-compile + no-toolchain case, the actionable "install build tools" message becomes a log line rather than a connection-blocking error (consistent with "always connect degraded"). Fresh installs still surface it.
  3. (pre-existing, unchanged) A @parcel/watcher-only load failure is still tagged [NPTY-MISSING] (cosmetic — the stderr breadcrumb disambiguates), and the Windows probe doesn't capture stderr for that diagnostic.
  4. (theoretical / pre-existing) Under a compound worst case (heavy install-lock contention and a slow install and a slow rebuild) the overall deploy backstop timeout could still fire. The bumped bound reduces this vs. the base commit, it's unreachable in the repair path (its npm install is a no-op), and it self-heals on retry.

Testing

  • pnpm typecheck — clean
  • pnpm lint (oxlint) — clean on touched files
  • pnpm test — src/main/ssh suite 676 pass / 2 skip
  • npm --ignore-scripts=false / npm rebuild mechanism reproduced on npm 11.16.0
  • POSIX + Windows (PowerShell) command generation covered by tests

Security

Dependency names come from a fixed constant and go through the existing POSIX shellEscape / PowerShell literal helpers; no user-controlled package names, new dependencies, auth, secrets, or IPC surfaces. Native-load failures expose only bounded stdout/stderr tails in existing diagnostic logs.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Native dependency deployment now uses direct module loading for health checks, enables npm lifecycle scripts during installation, and makes the node-pty helper executable on POSIX hosts. Failed probes trigger npm rebuild followed by a second probe, with stdout and stderr captured for diagnostics. Repair failures continue in degraded mode, and tests cover recovery, Windows commands, timeout bounds, and direct loading of both native modules.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it omits required template sections like Screenshots and a formal AI Review Report/Security Audit. Add the missing template sections, especially Screenshots, an AI Review Report with cross-platform checks, and a Security Audit summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the main change: repairing native relay dependencies.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d67507fa-521a-4cb2-bee0-6018f40febc3

📥 Commits

Reviewing files that changed from the base of the PR and between f01bfd9 and 7798009807d3b40edfda55c2c65097c4da8239ad.

📒 Files selected for processing (2)
  • src/main/ssh/ssh-relay-deploy.ts
  • src/main/ssh/ssh-relay-native-deps-install.test.ts

Comment thread src/main/ssh/ssh-relay-deploy.ts Resolved
@AmethystLiang

Copy link
Copy Markdown
Contributor

thx for the PR. Reviewing it now

@nwparker

Copy link
Copy Markdown
Contributor

Took this over and pushed a hardening commit (1ee62e3) on top of the original fix — flagging since review was already in progress. Summary of what's new vs the first commit:

  • Repair is now non-fatal. The base commit switched the health check from require.resolve → require, which correctly detects a present-but-unloadable binding — but it also meant an already-installed relay whose repair fails (offline/proxy-locked npm, or a host that can't build the addon) would now abort the whole deploy, where before it connected in degraded mode. repairInstalledNativeDeps is now best-effort: neither install-lock contention nor a failing repair blocks the connection; it releases its lock (if held) and falls through to a degraded launch. The fresh-install path keeps its fatal semantics.
  • Deploy-timeout envelope widened so a first npm install + its follow-up npm rebuild can't falsely trip the overall deploy timeout mid-repair.
  • Probe quoting routed through shellEscape so a future edit can't silently break the node -e probe.

An earlier iteration added an on-disk "unrepairable" marker to skip repeat repairs, but adversarial review showed it could persist a transient rebuild failure as permanent — so it was dropped for the simpler always-retry + non-fatal design. The recurring-repair cost on a genuinely-unbuildable already-installed host is documented in the PR description as a bounded, non-fatal tradeoff (with a session/TTL-memo follow-up noted).

Full src/main/ssh suite green (676 pass / 2 skip), typecheck + lint clean. Description updated with root cause, evidence, ELI5, and a full regression list.

@nwparker

Copy link
Copy Markdown
Contributor

@geelen

Going through PRs, I think this is legit. thanks!

I'm going to bounce this to @Jinwoo-H tomorrow since he's looking into this area. Will get him to respond (and ideally merge!)

@Jinwoo-H
Jinwoo-H force-pushed the fix/relay-native-deps-auto-repair branch from 1ee62e3 to 04371c3 Compare July 16, 2026 21:13
@Jinwoo-H

Jinwoo-H commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Internal review complete — no known code blockers on final pushed head be32a8a496 (diff SHA-256 0efe6b4887e8b507cd1205575fb832601c7fff5afa07e615c1e1a5751f20acab).

The final hardening covers real native-module loading probes, forced npm lifecycle scripts for repair, nonfatal degraded launch, same-process native reload from the deployed bundle, single-flight node-pty loading, and bounded install/rebuild/re-probe behavior.

The locking and GC paths were also hardened against the adversarial cases found during review: PowerShell 5.1-compatible directory locks remain visible to older clients, stale recovery uses tokenized atomic claims and unique tombstones, safety probes fail closed, locked state is rechecked after fencing, launch fencing closes the repair-to-liveness deletion window, contention retries until the deploy deadline, and failed launches retain recoverable fences.

Validation on the exact final candidate:

  • SSH + PTY suite: 879 passed, 9 skipped
  • Focused locking, GC, and native suite: 86/86
  • Relay subprocess suite independently rerun: 24/24
  • Typecheck, touched-file lint, max-lines ratchet, and git diff --check: clean
  • All six relay platform bundles plus the WSL hook built successfully
  • Two independent final reviewers: CLEAN on the identical commit and diff fingerprint

Required PR Checks passed on the final SHA, including full lint, typecheck, the repository-wide test suite, unpacked app build, and packaged CLI smoke. No merge was performed.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


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.

@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #9110 — rebased this branch onto current main, linked #8720 / #8758 (npm 12 allowScripts), and added concurrent loadPty single-flight + regression tests. Safe to close this PR in favor of #9110 once that lands.

geelen and others added 6 commits July 16, 2026 21:11
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.
@Jinwoo-H
Jinwoo-H force-pushed the fix/relay-native-deps-auto-repair branch from 94687d9 to be32a8a Compare July 17, 2026 01:20
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.

4 participants