Repository navigation
fix(ssh): compare lease and runtime pty ids in one form so pane recovery runs - #17969
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Id-form normalization at the comparison site —
getRecentExpiredSshLeasenow compareslease.ptyIdagainsttoComparableRelaySshPtyId(lease.targetId, ptyId), so the relay-form stored lease (pty-3) finally matches the runtime's app-form id (ssh:target@@pty-3). Non-SSH ids pass through unchanged, and a mismatched target returnsfalserather than throwing. - Tolerant normalizer extraction —
toComparableRelaySshPtyIdinsrc/shared/ssh-pty-id.tsabsorbs the previous inline try/catch fromgetRelayPtyIdForSshLeaseComparisoninto one shared implementation, re-exported through the provider barrel. - Reattach-eligibility gate —
recoverTerminalPanenow refuses superseded and relay-id-recycled expired leases viasshRemotePtyLeaseAllowsReattach, placed at the recovery site (not the shared getter) so the two coordinate-retention callers keep their existing behavior. - Fixture and test hardening —
createRuntimeWithSshLeasenow stores the lease in relay form exactly asupsertSshRemotePtyLeasedoes, which exposed that #17957's "host confirmed the exit" test was also inert in production; new tests pin the cross-form match plus the superseded/recycled refusals, and twoadoptStablePanetests pin reattach-before-respawn.
I traced the reattach claim end to end: recoverTerminalPane → createTerminal({focus: false}) → shouldCreateInBackground → adoptStablePane → resolveStablePaneOwner → provider.spawn({sessionId, attachOnly: true}), with a fresh spawn only after the relay's own "PTY not found" answer retires the binding. The comparison semantics check out for matching targets, mismatched targets, host-form vs bare target ids, and non-SSH passthrough. Test suites pass (orca-runtime.test.ts, ssh-expired-lease-pane-readoption.test.ts: 1229 passed, 1 skipped).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Base lint-fix propagation — the new commit merges the base branch's import-consolidation change into
deferred-session-reattach-connect.ts(two./pty-connect-limitsimports collapsed into one). Purely mechanical; no behavioral surface.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Resolved: this does not arm any dead positive gateReview raised the sharpest risk on this PR — that fixing the id-form comparison flips Checked, and it does not happen. There are exactly three non-test callers on this branch, and only one passes a
The predicate short-circuits on the id entirely when none is supplied: (ptyId === undefined || lease.ptyId === toComparableRelaySshPtyId(lease.targetId, ptyId)) &&So both positive gates were already matching before this PR and are byte-for-byte unaffected by it — they never reached the broken comparison. The only caller whose behaviour changes is the negative one, and arming it restores pane recovery rather than authorising anything new. Two related points from the same review, recorded1. The fails-closed direction means #17965 is not blocked on this. Because the resolve-terminal-pane gate always threw pre-fix, landing #17965 without this PR cannot match the wrong pty or strand an orphan at that site — SSH pane recovery simply stays inert and the pane reports 2. This PR does depend on #17966, which the stated chain order already guarantees: the Acknowledged limitationReview also makes a fair architectural point: the underlying defect is that an SSH pty id exists in two forms that are both The root fix is a branded type — |
57c88a9 to
db53b3e
Compare
e777f2f to
d3623d8
Compare
db53b3e to
a913860
Compare
`getRecentExpiredSshLease` compared the stored lease ptyId (relay form, written through `toStoredPtyId` -> `toRelaySshPtyId`) raw against the runtime's app-form `pty.ptyId`, so `'pty-3' === 'ssh:target@@pty-3'` never held and `recoverTerminalPane` refused every real SSH pane. Normalize with the same tolerant helper the binding reader already uses, now shared as `toComparableRelaySshPtyId`. Switching the path on is only safe on top of #17957 (respawn gated on the runtime liveness verdict), #17965 (`expired` no longer withdraws bindings) and #17966 (supersession and id recycling carry their own marks). `recoverTerminalPane` additionally refuses a lease those marks disqualify, so it acts only on an `expired` lease that means "reattach gave up". The path's outcome is a reattach, not a respawn: `createTerminal` calls `adoptStablePane` first, which attaches attach-only to the retained binding and only falls through to a fresh shell once the host itself answers that the PTY is absent.
d3623d8 to
c571773
Compare
…tablyai#17969) `getRecentExpiredSshLease` compared the stored lease ptyId (relay form, written through `toStoredPtyId` -> `toRelaySshPtyId`) raw against the runtime's app-form `pty.ptyId`, so `'pty-3' === 'ssh:target@@pty-3'` never held and `recoverTerminalPane` refused every real SSH pane. Normalize with the same tolerant helper the binding reader already uses, now shared as `toComparableRelaySshPtyId`. Switching the path on is only safe on top of stablyai#17957 (respawn gated on the runtime liveness verdict), stablyai#17965 (`expired` no longer withdraws bindings) and stablyai#17966 (supersession and id recycling carry their own marks). `recoverTerminalPane` additionally refuses a lease those marks disqualify, so it acts only on an `expired` lease that means "reattach gave up". The path's outcome is a reattach, not a respawn: `createTerminal` calls `adoptStablePane` first, which attaches attach-only to the retained binding and only falls through to a fresh shell once the host itself answers that the PTY is absent.

Closes #17958. Stacked on #17966 — review that first.
ELI5
SSH pane recovery has never run. Leases are stored in relay form (
pty-3); the reader compared them raw against the runtime's app form (ssh:target@@pty-3), so the equality never held andrecoverTerminalPanealways threwterminal_not_recoverable.toComparablePtyIdexisted right beside it, unused.#17958 said this could not be fixed alone: switching the path on would have introduced duplicate spawns, since every
expiredwriter was audited as non-attesting. That ordering constraint is satisfied by the stack below this PR — verified by reading the code on the branch, not just the log:recoverTerminalPanerefuses when liveness isliveorunverifiable.expiredno longer withdraws the pane binding, so an orphan can reattach.supersededBy/relayIdRecycledexist, soexpiredmeans exactly one thing.It reattaches; it does not respawn
Traced end to end and pinned with tests rather than read:
recoverTerminalPane→createTerminal(..., {focus: false})→ norendererBacked, soshouldCreateInBackgroundis true → the first act isadoptStablePane, before any spawn →resolveStablePaneOwnerfinds the persisted binding (retained because #17965 stoppedexpiredwithdrawing it) →attachStablePaneOwnercallsprovider.spawn({ sessionId: owner.ptyId, attachOnly: true }).That is a reattach. A fresh shell happens only when the provider raises
isPtyAlreadyGoneError— the relay's own "PTY not found" — which retires the binding and letscreateTerminalspawn. The attach attempt is itself the arbiter, so #17958's warned-about duplicate-spawn cannot occur.The common orphan case never reaches
createTerminalat all: a failed relay reattach writesexpiredand a syntheticpty:exit -1, which gradesunverifiable, and #17957's gate refuses. This path fires for anexpiredlease whose PTY has nolive/unverifiableverdict — a host-confirmed exit, or a pane with no verdict recorded.A second inert test found along the way
#17957's
still recreates a shell for an SSH pane whose host confirmed the exitwas also inert in production. It only passed because the fixturecreateRuntimeWithSshLeasestored the lease in app form, whichupsertSshRemotePtyLeasenever writes. Making the fixture apply the same relay-form conversion production does is what exposed it — and it then failed, correctly.Changes
src/shared/ssh-pty-id.ts— extracted the tolerant normalizer astoComparableRelaySshPtyId(the try/catch wrapper previously inline ingetRelayPtyIdForSshLeaseComparison, which now delegates to it). One implementation, not two.orca-runtime-reconcile-headless-mobile-session-browser-tabs.ts:95—lease.ptyId === toComparableRelaySshPtyId(lease.targetId, ptyId).orca-runtime-resolve-terminal-pane.ts—recoverTerminalPanealso refuses a lease thatsshRemotePtyLeaseAllowsReattachdisqualifies (superseded / recycled).Why the primitive and not a
RuntimeStoremember:getRelayPtyIdForSshLeaseComparisonis a method on a persistence class reachable only through instance wiring; neitherRuntimeStorenorStoreexposes it. Plumbing it as an optional member would have re-created this exact bug — every test mock store lacks it, so it would silently fall back to the raw compare.The other two callers of
getRecentExpiredSshLease(:90,:122) pass noptyId, so the normalized branch short-circuits and their behavior is unchanged. The supersession check went inrecoverTerminalPanerather than the shared getter deliberately, to keep their pane-coordinate retention exactly as-is.User-facing regressions
None expected. Negative controls, all passing:
terminatedstill refuses — and that test was upgraded to a real SSH pane, so it now exercises the live path instead of a non-SSH id that never reached the comparison;Testing
Before (production change reverted, tests in place):
After:
Suites:
orca-runtime.test.ts1225 passed | 1 skipped; +5 lease/binding suites 1283 passed; +7 further suites 68 passed.tc:node,tc:webclean.check:code-quality:changed0 new findings across 35 files.