Skip to content

fix(ssh): stop a relay not-found from certifying death, and keep dead panes recoverable - #18029

Closed
nwparker wants to merge 0 commit into
fix/ssh-lease-liveness-gatefrom
fix/s1-gate-audit
Closed

nwparker wants to merge 0 commit into
fix/ssh-lease-liveness-gatefrom
fix/s1-gate-audit

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​171 $\color{#cf222e}{\Huge{\mathbf{−}}}$​74 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3

Stacked on #18013. Reverts that PR's S1 commit, which I asked for and which was wrong. The other three commits (S11 tab resolution, S2 expired → attached, S5 predicate) are untouched.

The question, and the answer is "no"

#18013's S1 change made recoverTerminalPane require a positive exited verdict, and supplied that verdict by writing hostExitConfirmed: true on the pty.attach not-found branch. Review flagged that as fabricating a death certificate, so this branch removes it — and then asks whether the gate still works without it.

It does not. exited and a reattachable expired lease are mutually exclusive by construction. recoverTerminalPane requires an expired lease that sshRemotePtyLeaseAllowsReattach permits, but every legitimate exited source writes terminated:

Source Lease write Reaches the gate?
retireExitedPty (ssh-relay-session.ts:2230) terminated no — refused at if (!expiredLease)
host-reports-absent (ssh-pending-pty-kill-replay.ts:49) terminated no
fulfilled provider.shutdown (ssh-connection-handlers.ts:156) terminated no

Demonstrated by reverting the inventory hunk while keeping the gate:

AssertionError: promise rejected "Error: terminal_not_recoverable" instead of resolving
 ❯ OrcaRuntimeService.recoverTerminalPane orca-runtime-resolve-terminal-pane.ts:111:13

So the S1 gate as specified would have made genuinely-dead panes permanently unrecoverable.

S1 did not raise the bar — it relocated the fabrication

The one writer that did co-occur with a reattachable expired lease was S1's other hunk: refreshPtyWorktreeRecordsWithControllerInventory promoting observed === false to exited.

That rests on exactly the evidence the review rejected. pty.listProcesses returns the relay's current session map, and ids are pty2:${ptyIdMintEpoch}:${n} with a fresh epoch per relay start — so a restarted relay omits every previously-minted id whether or not those shells died. Same union as pty.attach not-found, one hop further from where it is documented.

What this branch does

  1. Removes the hostExitConfirmed: true write; handlePtyReattachFailure publishes only pty:exit code -1 again.
  2. Reverts the gate to refusing on unverifiable / live. null there is not "nobody asked": reaching the gate needs a registered pty record with connected === false, and for an SSH pane only onPtyExit or the inventory sweep clears that — both record their doubt when they have any. A fresh app start has no pty record and fails earlier on terminal_not_found.
  3. Reverts the inventory site to forgetPtyLivenessVerdict.
  4. Keeps the exited retention and onPtyExit's host-attested write — a host-delivered exit frame is now its only writer. Removed markPtyLivenessExited, which had no production caller once the fabricated site was gone.

A second effect of change (3), easy to miss

hostExitConfirmed: true also flips preservesAbnormalSshSurface to false in onPtyExit — so a mere relay not-found was additionally running retireMobileSessionSurfacesForPty (the pane disappears from paired-client snapshots instead of surviving the reconnect grace), retirePtyAgentLaunchAuthority, failActiveDispatchOnExit, and reconcileAgentStatusForEndedProcessFn.

Old-client impact: none. No wire change, and published content returns to its pre-S1 (= main) shape. This is strictly a rollback per docs/reference/remote-wire-compatibility.md.

Also resolves the conflict with #17963

#17963's ratchet pins the opposite claim — that pty.attach not-found must not certify a death — and its wording is the careful one. That ratchet is now on this branch with its original wording, so the two no longer contradict.

Testing

Failing before:

FAIL ssh-relay-orphan-abandon-paths.test.ts › stops claiming the id without asserting an exit when the relay answers not-found
  Array [ "ssh:target-1@@pty-live", -1, undefined, Object { "hostExitConfirmed": true } ]
FAIL terminal-pane-recovery-liveness-gate.test.ts › recreates a shell for an SSH pane the relay disowned
  AssertionError: expected { status: 'exited' } to be null
FAIL pty-inventory-liveness-verdict.test.ts › records no death certificate when a listing of the owning host omits the PTY
  AssertionError: expected { status: 'exited' } to be null

After: Test Files 3 passed (3) / Tests 19 passed (19).

Negative controls, all green: a host-attested exit still recovers; live refuses; unverifiable refuses; #17963's ratchet (isProvenProcessExit(publishedCode) === false) passes.

Broader: src/main/runtime + src/main/ssh → 7858 passed; src/main/ipc/pty + src/shared → 670 passed. tc:node, tc:web, check:code-quality:changed (0 new findings), oxfmt --check all clean.

One claim in the working notes I could not reproduce

The implementation reported that the 98 .spec.ts files under src/main/runtime/orca-runtime-tests/ never run in CI, because config/vitest.config.ts includes only src/**/*.test.ts. That is not the case — all 98 are imported by orca-runtime.test.ts, which does run; the harness executes 1220 tests. The test relocation it made on that basis is unnecessary, though harmless.

Follow-ups deliberately not taken

  • The inventory sweep could earn a genuine exited by requiring the listing to name siblings on that host — the boundary doc's own test. As written it treats an empty listing from a restarted relay identically to a populated one that omits the id.
  • SshPtyProvider.hasPty is a client-side livePtyIds set, so the observed === false branch mixes host evidence with client bookkeeping.

@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 blocking issues — the revert is sound and well-argued; two citation/comment nits below.

Reviewed changes

  • Stop certifying a death from the relay's not-found answer — handlePtyReattachFailure no longer calls runtime.onPtyExit(…, { hostExitConfirmed: true }); it publishes pty:exit code -1 only.
  • Loosen the recovery gate back to refuse-on-positive-verdicts — recoverTerminalPane now refuses on unverifiable/live instead of requiring a positive exited, keeping genuinely-dead panes recoverable (an host-attested exit tombstones the lease terminated, so no exited writer co-occurs with a reattachable expired lease).
  • Revert the fabricated inventory certificate — the observed === false branch returns to forgetPtyLivenessVerdict, and the orphaned markPtyLivenessExited is deleted.
  • Tests — a new end-to-end gate test, two pty-inventory-liveness-verdict additions, and a ratchet pinning isProvenProcessExit(code) === false on the published -1.

The central claim is correctly demonstrated in the tests and matches the boundary doc: every exited writer tombstones terminated, and the only expired-co-occurring signal the gate ever sees is an answered-and-omitted id, so recovering on null is the right reading. No wire change; old clients unaffected.

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

Comment on lines +10 to +12
// a remote pane. Lives in a `.test.ts` rather than beside the other recoverPane cases in
// orca-runtime-tests/*.spec.ts because config/vitest.config.ts — the config CI runs — includes only
// `*.test.ts`, so a ratchet placed there would never execute.

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 justification is incorrect: the .spec.ts fragments under orca-runtime-tests/ are not skipped by CI — orca-runtime.test.ts imports all 98 explicitly, and orca-runtime-test-fragment-coverage.test.ts enforces that. The relocation is therefore unnecessary and splits these gate cases away from the sibling recoverPane cases still in terminal-handles.spec.ts (near-identical "unverifiable" and "host confirmed" tests already live there). Either correct the comment or fold these back beside them.

// and is covered in ssh-relay-orphan-abandon-paths.test.ts.
// running on the host and duplicates its agent. This is the `unverifiable` arm only; the
// relay's own absence branch (`handlePtyReattachFailure`) reaches the runtime with no verdict
// at all, and is covered by the relay-disowned case in terminal-handles-part-02.spec.ts.

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 points at the wrong file — the "relay-disowned" case was removed from terminal-handles-part-02.spec.ts in this same PR and now lives in terminal-pane-recovery-liveness-gate.test.ts.

@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #18013. The S1 commit (ef4de0d8da3) and this PR's revert of it were collapsed into a single commit on fix/ssh-lease-liveness-gate, so the defect is never introduced and then undone inside the stack. #18013's tip tree is now identical to this PR's verified end state, except that the stale pty-handler.ts:1936/:1943 line references are dropped (main has moved them to 1962/1968). fix/s1-gate-audit now points at that same commit and has no commits of its own — closing as folded in.

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