Skip to content

fix(ssh): repair a rebuildable node-pty failure once, instead of asking the user to reconnect - #17907

Merged
nwparker merged 3 commits into
mainfrom
fix/node-pty-spawn-repair
Sep 2, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/node-pty-spawn-repair

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​647 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​647
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​244 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​244

Stacked on #17891 (fix/node-pty-load-failure-diagnosis), which lands the structured cause this consumes. Review that one first; retarget to main once it merges.

Completes #17830. #17891 made the relay say why node-pty would not load; this acts on it.

The gap this closes

The fault is proved on the relay, at spawn time. The only thing that can fix it — repairInstalledNativeDeps in ssh-relay-deploy.ts — runs on the client, during deploy, under tryAcquireRelayRepairLock. Nothing connected the two, so a user whose remote Node changed under an existing install got a paragraph of guesses. Reconnecting genuinely worked; they just had no way to know that was the step.

Deliberately indirect

This does not touch the remote node_modules. It drives one relay reconnect and lets the locked deploy path do the rebuild, so all mutation stays behind tryAcquireRelayRepairLock. #17891 rejected a relay-side rebuild for exactly this reason — an unlocked rebuild could collide with a concurrent reconnect's repair — and this keeps that property rather than working around it.

The invariant that matters more than the recovery

At most one repair per host per reason, and the attempt is recorded before the reconnect starts, not after it succeeds. A repair that ran and failed has still spent the attempt, and that host renders the relay's message from then on.

That ordering is the whole safety argument: a rebuild loop against someone's remote host is worse than the bug it is chasing. forgetRelayNodePtyRepairs clears the ledger on disconnect, since that is user action and may earn a fresh attempt.

Outcomes are explicit rather than boolean, so each refusal is greppable and testable: not-repairable, already-attempted, ptys-live, reconnect-failed, no-provider, repaired.

Guards

  • ptys-live — no rebuild while this client still holds live PTYs on the relay about to be rebuilt. Yanking node-pty from under a running session destroys someone's work.
  • mayRepairFromCause is re-derived client-side; the peer's repairable flag is never trusted on its own. That is the [Bug]: Direct SSH Connect hangs on Deploying relay (native probe never finishes) #14830 lesson — an unverifiable probe must never authorize a destructive repair.
  • Only abi_mismatch, arch_mismatch, libc_floor, load_crashed and dependency_missing qualify, and only when the toolchain is not known-missing. toolchain_missing and shared_library_missing never repair — the rebuild would need the very thing that is absent.
  • The provider retried against is the one registered after the reconnect, never the one that failed.

Verification

$ pnpm test <the three new test files>
 Test Files  3 passed (3)
      Tests  25 passed (25)

$ pnpm test src/main/ssh src/main/providers
 Test Files  207 passed | 3 skipped (210)
      Tests  2624 passed | 21 skipped (2645)

$ pnpm test src/relay
 Test Files  153 passed (153)
      Tests  1572 passed | 2 skipped (1574)

$ pnpm tc:node                            # clean
$ pnpm run check:code-quality:changed     # 0 new findings across 21 files

Coverage includes the refusals, not just the happy path: a repairable cause repairs exactly once; a second identical failure does not repair again; an unverifiable cause never repairs; toolchain_missing never repairs; live PTYs block it; and an unavailable repair lock degrades to today's message rather than proceeding.

Answering the question #17891 left open

A user hitting #17830 with an ABI or arch mismatch now recovers with no action — the failed spawn triggers one reconnect, the locked deploy path rebuilds node-pty against the remote's actual Node, and the retry runs on the new provider.

toolchain_missing and shared_library_missing still require the user, correctly — we cannot install a compiler or a system library for them — but they now get one named cause and an exact command instead of four hedged possibilities.

Fixes #17830


ELI5

Follow-up to the above: when the remote's terminal library is broken in a way a rebuild can fix, Orca now just fixes it instead of telling you to reconnect.

User-facing regression risk

  • Orca may now reconnect the relay by itself after a failed terminal spawn. Unexpected if you are not expecting it, though it replaces a failure.
  • Strictly bounded: at most one repair per host per cause, and the attempt is recorded before the reconnect so a failed repair still spends it. No retry loop is possible. Cleared only on disconnect.
  • Never runs while you hold live PTYs on that relay, never on unverifiable evidence, and never for toolchain_missing / shared_library_missing — a rebuild needs the thing that is missing.

The relay could only say "terminals are unavailable" and then list three
remedies for four different faults, none of which the user could verify
(#17830). Two things were destroying the evidence:

- `loadPtyUncached` caught the load error into bare `catch {}` blocks
  (pty-handler.ts:539, :551) and returned null. The only cause anyone had
  was discarded on the spot.
- node-pty's own loader walks three directories and rethrows only the LAST
  failure, so even an uncaught error arrives as `Cannot find module
  '../prebuilds/...'` — the GLIBC/ABI/arch sentence is already gone.

The relay now keeps the load error, recovers the real dlopen message with an
out-of-process load of the file node-pty would have opened, reads what
node-gyp configured the binding for (`build/config.gypi`), captures the
host's Node ABI, arch and glibc, and probes the toolchain only when nothing
was compiled. Each fault gets its own message naming values the user can
check: toolchain_missing, dependency_missing, abi_mismatch, arch_mismatch,
libc_floor, shared_library_missing, load_crashed, and load_failed which
quotes the loader verbatim. A probe that did not answer stays `unverifiable`
and prescribes nothing.

The classification is now also structured data on the error, so a client can
repair the host instead of printing a paragraph: an additive, schema-validated
`data` field on an existing JSON-RPC error, with `repairable` true only for a
proved fault that recompiling on the host actually fixes.

Reuses orcad's loader-message parsers and out-of-process probe rather than
adding a second copy; `classifyLoaderMessage` moves to a shared module and
gains architecture and missing-shared-library cases, which the orcad boot
precondition picks up too.
@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown

Too many files changed for review (274 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

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

Caution

This PR does not contain the change its title and description claim. The diff is a max-lines module-splitting refactor with no node-pty repair code at all.

Reviewed changes

Reviewed all 274 changed files across the 8 commits in this run. The actual content is a mechanical decomposition of oversized modules, not the SSH node-pty repair the title announces.

  • Preload bridge split — src/preload/index.ts is decomposed into ~100 per-domain src/preload/api/*-bridge.ts modules plus a new preload-runtime-support.ts.
  • Renderer runtime/store split — sync-runtime-graph.ts, web-session-tabs-sync.ts, and the agent-status/browser/linear/tabs/ui slices are split into per-domain modules behind barrel re-exports.
  • Keybindings split — src/shared/keybindings.ts becomes a facade re-exporting from src/shared/keybindings/*.
  • Baseline pruning — config/max-lines-baseline.txt and config/tsconfig.tc.web.json are updated to match the split.

🚨 The described node-pty repair is absent from the diff

The PR body claims this "acts on" the structured cause from #17891 by adding a repair ledger (mayRepairFromCause, forgetRelayNodePtyRepairs, outcomes like repaired/ptys-live/already-attempted) and driving one relay reconnect through tryAcquireRelayRepairLock. None of that exists in the changed files: searches for mayRepairFromCause, forgetRelayNodePtyRepairs, tryAcquireRelayRepairLock, and the outcome strings return no matches in the diff, and no src/main/ssh, src/relay, src/main/providers, or src/shared/terminal-unavailable-cause.ts file is touched. The three changed test files (github-ipc-channel-parity.test.ts, browser-workspace-tab-close-census.test.ts, host-session-mirror-settle-census.test.ts) are census tests for the module split, not the 25 repair tests the body's verification section describes.

⚠️ The branch is not stacked on the diagnosis commit it cites

The base tip 3641310e3d ("fix(relay): diagnose why node-pty will not load instead of hedging") is not an ancestor of the head; the merge-base of the two is the older 41ef1ddd80. So the structured-cause work this PR claims to consume is also absent from the branch, and the diff cannot show a repair built on it.

Technical details
# Reconcile PR title/description with branch content

## Affected sites
- All 274 changed files — preload/renderer/store/keybindings module splits only.
- `config/max-lines-baseline.txt`, `config/tsconfig.tc.web.json` — baseline pruning.

## Required outcome
- Either push the actual node-pty repair commits (rebased onto `3641310e3d` so the diagnosis is present), or retitle/rewrite the PR to describe the module-splitting refactor it actually contains.

## Open questions for the human
- Was the wrong branch pushed, or was this PR force-pushed over the repair commits?

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

@nwparker
nwparker force-pushed the fix/node-pty-spawn-repair branch from c475d23 to 62f8fb8 Compare September 1, 2026 11:07

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

Important

The repair logic now matches the PR description, but the ledger is cleared on the wrong teardown path: forgetRelayNodePtyRepairs runs on dispose, not on the ssh:disconnect path (detach), so the "fresh attempt on disconnect" the body promises never happens for an ordinary disconnect.

Reviewed changes

  • Added the client spawn-repair seam (spawnWithTerminalRuntimeRepair) and wired it into SshPtyProvider.spawn.
  • Added the once-per-host-per-reason repair ledger (recoverRelayNodePtyForSpawn, claimRepairAttempt, forgetRelayNodePtyRepairs).
  • Added terminalUnavailableCauseFromError to recover the relay's structured cause from the rejected call's data.
  • Wired SshRelaySession to drive one locked reconnect on a proved-repairable spawn failure and hand back the post-reconnect provider.
  • Added 25 tests covering the seam, the ledger, and the locked deploy rebuild.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

this._state = 'disposed'
// Why here and not on reconnect: an explicit disconnect is user action, so the host earns a
// fresh node-pty repair attempt. A reconnect must not, or the repair becomes a loop.
forgetRelayNodePtyRepairs(this.targetId)

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.

This clears the repair ledger only on dispose, but the user-facing disconnect (ssh:disconnect → disconnectRegisteredSshTarget → detachAndPersist) runs runDetach, not runDisposal. So a user who disconnects and reconnects after a spent repair attempt still hits already-attempted on the next spawn failure — the fresh attempt the PR body promises on disconnect is never earned except by removing the target or restarting the app. runDisposal is only reached by ssh:terminateSessions, target removal, and app shutdown.

Technical details
# Clear the ledger on the disconnect path

## Affected sites
- src/main/ssh/ssh-relay-session.ts:860 — `forgetRelayNodePtyRepairs(this.targetId)` placed in `runDisposal`, commented as "an explicit disconnect is user action".
- src/main/ipc/ssh-session-teardown.ts:14 — `disconnectRegisteredSshTarget` calls `session.detachAndPersist()`, which routes to `runDetach`, not `runDisposal`.

## Required outcome
- A user disconnect earns a fresh repair attempt, matching the PR body's "Cleared only on disconnect."

## Suggested approach (optional)
- Also call `forgetRelayNodePtyRepairs(this.targetId)` in `runDetach` (and decide whether `beginShutdownDetach` needs it — it does not, since the app is quitting and the module-level ledger dies with the process).

@nwparker
nwparker changed the base branch from fix/node-pty-load-failure-diagnosis to main September 2, 2026 05:37
@nwparker
nwparker merged commit f9587f7 into main Sep 2, 2026
4 checks passed
@nwparker
nwparker deleted the fix/node-pty-spawn-repair branch September 2, 2026 05:48
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: c23c823d-abac-4e1f-9302-1f8f1ba27fef

📥 Commits

Reviewing files that changed from the base of the PR and between 4f4872c and 9cd6211.

📒 Files selected for processing (8)
  • src/main/providers/ssh-pty-provider-terminal-repair.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-spawn-repair.ts
  • src/main/ssh/ssh-relay-node-pty-repair.test.ts
  • src/main/ssh/ssh-relay-node-pty-repair.ts
  • src/main/ssh/ssh-relay-node-pty-spawn-repair.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/shared/terminal-unavailable-cause.ts

📝 Walkthrough

Walkthrough

Adds terminal-unavailable cause extraction and a one-shot SSH PTY spawn retry. Adds relay repair tracking by target and cause, live-PTY checks, reconnect outcomes, and provider resolution. Integrates recovery with SSH relay sessions while preserving grace time across reconnects and clearing repair state on explicit disposal. Adds Vitest coverage for client retries, repair outcomes, lock behavior, non-repairable causes, and session repair state.

✨ Finishing Touches
📝 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.

paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 3, 2026
…ng the user to reconnect (stablyai#17907)

* fix(relay): diagnose why node-pty will not load instead of hedging

The relay could only say "terminals are unavailable" and then list three
remedies for four different faults, none of which the user could verify
(stablyai#17830). Two things were destroying the evidence:

- `loadPtyUncached` caught the load error into bare `catch {}` blocks
  (pty-handler.ts:539, :551) and returned null. The only cause anyone had
  was discarded on the spot.
- node-pty's own loader walks three directories and rethrows only the LAST
  failure, so even an uncaught error arrives as `Cannot find module
  '../prebuilds/...'` — the GLIBC/ABI/arch sentence is already gone.

The relay now keeps the load error, recovers the real dlopen message with an
out-of-process load of the file node-pty would have opened, reads what
node-gyp configured the binding for (`build/config.gypi`), captures the
host's Node ABI, arch and glibc, and probes the toolchain only when nothing
was compiled. Each fault gets its own message naming values the user can
check: toolchain_missing, dependency_missing, abi_mismatch, arch_mismatch,
libc_floor, shared_library_missing, load_crashed, and load_failed which
quotes the loader verbatim. A probe that did not answer stays `unverifiable`
and prescribes nothing.

The classification is now also structured data on the error, so a client can
repair the host instead of printing a paragraph: an additive, schema-validated
`data` field on an existing JSON-RPC error, with `repairable` true only for a
proved fault that recompiling on the host actually fixes.

Reuses orcad's loader-message parsers and out-of-process probe rather than
adding a second copy; `classifyLoaderMessage` moves to a shared module and
gains architecture and missing-shared-library cases, which the orcad boot
precondition picks up too.

* fix(ssh): repair a rebuildable node-pty failure once, instead of asking the user to reconnect

Mirror-Of: f9587f7
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ng the user to reconnect (stablyai#17907)

* fix(relay): diagnose why node-pty will not load instead of hedging

The relay could only say "terminals are unavailable" and then list three
remedies for four different faults, none of which the user could verify
(stablyai#17830). Two things were destroying the evidence:

- `loadPtyUncached` caught the load error into bare `catch {}` blocks
  (pty-handler.ts:539, :551) and returned null. The only cause anyone had
  was discarded on the spot.
- node-pty's own loader walks three directories and rethrows only the LAST
  failure, so even an uncaught error arrives as `Cannot find module
  '../prebuilds/...'` — the GLIBC/ABI/arch sentence is already gone.

The relay now keeps the load error, recovers the real dlopen message with an
out-of-process load of the file node-pty would have opened, reads what
node-gyp configured the binding for (`build/config.gypi`), captures the
host's Node ABI, arch and glibc, and probes the toolchain only when nothing
was compiled. Each fault gets its own message naming values the user can
check: toolchain_missing, dependency_missing, abi_mismatch, arch_mismatch,
libc_floor, shared_library_missing, load_crashed, and load_failed which
quotes the loader verbatim. A probe that did not answer stays `unverifiable`
and prescribes nothing.

The classification is now also structured data on the error, so a client can
repair the host instead of printing a paragraph: an additive, schema-validated
`data` field on an existing JSON-RPC error, with `repairable` true only for a
proved fault that recompiling on the host actually fixes.

Reuses orcad's loader-message parsers and out-of-process probe rather than
adding a second copy; `classifyLoaderMessage` moves to a shared module and
gains architecture and missing-shared-library cases, which the orcad boot
precondition picks up too.

* fix(ssh): repair a rebuildable node-pty failure once, instead of asking the user to reconnect
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.

[Bug]: Remote terminals are unavailable

1 participant