Skip to content

fix(ssh): stop a markerless native-deps probe from deleting both native modules - #18011

Merged
nwparker merged 1 commit into
mainfrom
fix/native-deps-markerless-probe
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/native-deps-markerless-probe

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​160 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​146
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41

Closes the destructive half of #18007. Follow-up to #17979 (merged), which fixed the unanswered probe and left the answered-but-unparseable one asserting the maximally destructive conclusion. I fenced that fix away from this on reasoning that was wrong.

ELI5

missingNativeDepsFromProbe returned "both deps missing" whenever the probe output had no marker line. But the POSIX probe was (node -e '<js>' 2>/dev/null || echo MISSING), and that subshell always exits 0 — so #17979's catch → unverifiable branch never fired. If node itself failed to start, stdout was the bare string MISSING, no marker, and the result was rm -rf node_modules/node-pty and rm -rf node_modules/@parcel/watcher plus a node-gyp compile.

2>/dev/null had already discarded the one diagnostic that would have distinguished the cases.

This was deterministic and permanent per host. An invalid NODE_OPTIONS in ~/.profile, an OOM-killed node -e, or exit 127: every connect deletes both deps, npm install fails the same way, finalizeInstall is skipped — but .install-complete from the original install is still present, so isRelayAlreadyInstalled keeps returning true. The relay launches with no node-pty and no file watcher, and because repair runs on every connect for an installed dir, each reconnect re-deletes and burns another four minutes. It never self-heals. Strictly worse than the transient bug #17979 fixed.

The fix

  • missingNativeDepsFromProbe returns RelayNativeDepName[] | undefined — undefined for a markerless answer and for a marker naming zero recognized deps. It no longer manufactures a dep list from no evidence.
  • probeRequiredNativeDeps maps that to unverifiable (fix(ssh): stop an unanswered native-deps probe from wiping a healthy relay #17979's existing verdict — no fourth added) and warns [ssh-relay][NATIVE-DEPS-PROBE-UNPARSEABLE] with the tail of stdout and stderr. Only a marker naming ≥1 dep yields blocked.
  • Dropped 2>/dev/null. New optional onStderr on execCommand, invoked on the zero-exit resolve path where stderr was previously discarded, with redactRelayInstallMarkerTokens applied.

Deliberately not 2>&1: the probe JS source contains the literal strings ORCA-NATIVE-DEPS-OK and ORCA-NATIVE-DEPS-MISSING:, and node echoes -e source into stderr on an uncaught throw — folding the streams could manufacture a false ok and permanently suppress a real repair.

Windows had the same hole and is fixed by the same change: a native non-zero exit does not throw in PowerShell, so try { & node -e … } catch { 'MISSING' } yields empty, markerless stdout. It shares missingNativeDepsFromProbe. There is now an end-to-end control for it.

User-facing regressions

One, deliberate and stated. A native module whose load aborts the process (uncatchable dlopen crash, cf. #9902) leaves no marker, so it is now unverifiable and launches degraded instead of triggering a blind reset.

That trade is correct: the blind reset was indistinguishable from the NODE_OPTIONS/OOM/exit-127 case and did far more damage there, and a crash on dlopen is not reliably fixed by reinstalling the same version on the same host. If it needs covering later, the honest fix is a synchronous fs.writeSync(2, …) breadcrumb in the probe naming the dep it is about to require — turning the crash into an answer with a marker, rather than widening what counts as evidence.

Otherwise none. A genuinely broken dep still repairs: the probe JS catches require failures per-dep and prints ORCA-NATIVE-DEPS-MISSING:<names>, so one named dep resets one, both named resets both.

Testing

Failing before the source fix, passing after (test file unchanged between runs):

 × leaves node_modules intact when the probe answers without naming a dep
AssertionError: expected true to be false
 × carries the probe stderr into the unparseable-answer warning
AssertionError: promise rejected "Error: Relay failed to start within 10s. …" instead of resolving
 × leaves a Windows relay intact when its probe answers without naming a dep
      Tests  3 failed | 5 passed (8)

After: Tests 8 passed (8).

Negative controls pass before and after, so they pin the repair path rather than moving with it: a marker naming @parcel/watcher resets exactly that dep and not node-pty; a marker naming both resets both and calls finalizeInstall once; an ORCA-NATIVE-DEPS-OK answer runs no npm install; #17979's unanswered probe still launches intact. Plus an execCommand unit test that a zero-exit command's stderr reaches onStderr and does not leak into conn.exec options.

pnpm test src/main/ssh: 1803 passed, 16 skipped. tc:node clean. check:code-quality:changed 0 new findings across 7 files.

Fixture note

Bare 'MISSING' in repair-path fixtures now means unverifiable, so suites using it to mean "both deps broken" were feeding the wrong evidence. The string changed, never the slot count — no positional array shifted. 7 slots in ssh-relay-sftp-namespace-install.test.ts and 3 in ssh-relay-native-deps-install.test.ts now share BOTH_NATIVE_DEPS_MISSING_PROBE, which also replaces two inline copies.

The repair path read "the probe answered, but nothing in the answer names a
dep" as "both deps are missing". The POSIX probe is fenced with
`|| echo MISSING`, so the subshell always exits 0 and the unanswered-probe
catch added by #17979 never ran. A node that cannot start (invalid
NODE_OPTIONS, OOM kill, exit 127) therefore produced a bare `MISSING`, and
every reconnect rm -rf'd node_modules/node-pty and node_modules/@parcel/watcher
and burned a 240s npm install that failed the same way. `.install-complete`
from the original install survives, so the relay kept launching with no PTY
and no file watcher, permanently, per host.

Only a marker line that actually names deps is evidence about them; anything
else is `unverifiable` and launches as-is. Also drop `2>/dev/null` from the
POSIX probe and carry stderr into the warning via a new execCommand `onStderr`
hook, so the reason node failed survives. stderr stays its own stream — folded
into stdout it would match the probe's own token strings.

The Windows branch shared the same parser and is fixed with it.
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 43ab8a55-1280-4a40-8cba-5304f49e6e88

📥 Commits

Reviewing files that changed from the base of the PR and between 2be5352 and e7a23be.

📒 Files selected for processing (7)
  • src/main/ssh/ssh-relay-deploy-helpers.test.ts
  • src/main/ssh/ssh-relay-deploy.ts
  • src/main/ssh/ssh-relay-exec-command.ts
  • src/main/ssh/ssh-relay-native-deps-install-fixture.ts
  • src/main/ssh/ssh-relay-native-deps-install.test.ts
  • src/main/ssh/ssh-relay-native-deps-probe-verdict.test.ts
  • src/main/ssh/ssh-relay-sftp-namespace-install.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

SSH command execution now reports successful stderr through an optional callback while resolving stdout. Native-dependency probes now capture stderr and classify responses without named dependencies as unverifiable. Dependency repair uses only explicitly named missing dependencies. Tests and shared fixtures now cover Linux and Windows probe responses, selective repair, and both-dependency markers.

Merge Risk: ⚪ Minimal · up to e7a23

The change prevents ambiguous native-dependency probes from deleting both modules while preserving targeted repairs when a dependency is explicitly identified. No actionable merge-blocking risk remains; the PR is merge-ready after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the SSH native-dependency probe bug and the destructive behavior it prevents.
Description check ✅ Passed The description clearly explains the failure mode, fix, rationale, linked issues, regression trade-off, and test results. It provides sufficient information for review, although several optional templ…
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.
Full details: Description check

Explanation

The description clearly explains the failure mode, fix, rationale, linked issues, regression trade-off, and test results. It provides sufficient information for review, although several optional template headings and checklist items are omitted.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • missingNativeDepsFromProbe returns undefined for a markerless answer — a node that can never start (bad NODE_OPTIONS, OOM kill, exit 127) no longer manufactures "both deps missing" and triggers rm -rf of node-pty and @parcel/watcher plus a node-gyp source build on every reconnect of an affected host.
  • probeRequiredNativeDeps maps that to unverifiable and emits an [NATIVE-DEPS-PROBE-UNPARSEABLE] warning carrying the stdout/stderr tails; 2>/dev/null was dropped so the one line that identifies the host-side failure survives.
  • execCommand gains an optional onStderr invoked only on the zero-exit resolve path, marker-token-redacted, and destructured out of execOptions so it never leaks into conn.exec.
  • probeInstalledNativeDeps reports ?? [] for a markerless answer — available already carries the failure, and the first-install rebuild path keys off available rather than missing.
  • Tests — new verdict tests pin the no-repair path (POSIX and Windows markerless) and the stderr-through-onStderr wiring; fixtures gained a shared BOTH_NATIVE_DEPS_MISSING_PROBE so bare 'MISSING' no longer doubles as "both broken". I ran pnpm test src/main/ssh/ssh-relay-native-deps-probe-verdict.test.ts src/main/ssh/ssh-relay-deploy-helpers.test.ts → 36 passed.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 4f4872c into main Sep 2, 2026
32 of 33 checks passed
@nwparker
nwparker deleted the fix/native-deps-markerless-probe branch September 2, 2026 05:45
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 3, 2026
…stablyai#18011)

The repair path read "the probe answered, but nothing in the answer names a
dep" as "both deps are missing". The POSIX probe is fenced with
`|| echo MISSING`, so the subshell always exits 0 and the unanswered-probe
catch added by stablyai#17979 never ran. A node that cannot start (invalid
NODE_OPTIONS, OOM kill, exit 127) therefore produced a bare `MISSING`, and
every reconnect rm -rf'd node_modules/node-pty and node_modules/@parcel/watcher
and burned a 240s npm install that failed the same way. `.install-complete`
from the original install survives, so the relay kept launching with no PTY
and no file watcher, permanently, per host.

Only a marker line that actually names deps is evidence about them; anything
else is `unverifiable` and launches as-is. Also drop `2>/dev/null` from the
POSIX probe and carry stderr into the warning via a new execCommand `onStderr`
hook, so the reason node failed survives. stderr stays its own stream — folded
into stdout it would match the probe's own token strings.

The Windows branch shared the same parser and is fixed with it.

Mirror-Of: 4f4872c
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#18011)

The repair path read "the probe answered, but nothing in the answer names a
dep" as "both deps are missing". The POSIX probe is fenced with
`|| echo MISSING`, so the subshell always exits 0 and the unanswered-probe
catch added by stablyai#17979 never ran. A node that cannot start (invalid
NODE_OPTIONS, OOM kill, exit 127) therefore produced a bare `MISSING`, and
every reconnect rm -rf'd node_modules/node-pty and node_modules/@parcel/watcher
and burned a 240s npm install that failed the same way. `.install-complete`
from the original install survives, so the relay kept launching with no PTY
and no file watcher, permanently, per host.

Only a marker line that actually names deps is evidence about them; anything
else is `unverifiable` and launches as-is. Also drop `2>/dev/null` from the
POSIX probe and carry stderr into the warning via a new execCommand `onStderr`
hook, so the reason node failed survives. stderr stays its own stream — folded
into stdout it would match the probe's own token strings.

The Windows branch shared the same parser and is fixed with it.
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