Skip to content

fix(ssh): stop a relay-era shell when its bridged tab closes - #29620

Merged
nwparker merged 1 commit into
mainfrom
nwparker/legacy-relay-close-kill
Oct 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/legacy-relay-close-kill

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​337 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​333
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​300 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​294

ELI5

After upgrading from a relay-era Orca (1.4.224–1.4.227), terminals an older Orca started on an SSH host keep working in their old tabs. Closing one of those tabs used to leave its shell running on the host, along with any agent in it. Now closing the tab stops that shell, the same way closing any other terminal tab does.

What Changed

Before: closing a bridged relay-era tab only hung up the bridge. The shell and its agent kept running on the host under the old relay, used host resources, and looked like a ghost session. Those leftover shells also blocked a later move to the managed server: stopping the managed server and reconnecting failed with "Terminals an older version of Orca started in are still running", and it kept failing until someone killed the shells by hand on the host.

After: closing the tab sends the old relay its own stop request, and the shell ends. If the host can't be reached at that moment, the close answers unverifiable: the shell is never reported as exited. The stop is held and sent once the relay can be asked again, after a reconnect.

Mechanism:

  • LegacyRelayClient.shutdown sends the old relay's own pty.shutdown {id, immediate: false, keepHistory: false}, the shape 1.4.224's provider sent. expectedIncarnationId is added only when known, so older relays never see the field.
  • New legacy-relay-pane-stops.ts holds one target's pending stops outside the bridge, so a reconnect's new bridge still sends them. A stop stays pending until the relay reports pty.exit, or until a listing no longer shows the terminal. Until then it re-lists on the bridge's backoff.
  • The stop is fenced to the process the tab ran, so a recycled id never reaches a stranger's shell:
    • when the relay reports an incarnation, the stop carries it and is dropped on a mismatch;
    • a pty2: id carries its relay's start epoch, so the id itself is the fence;
    • a legacy pty-N id with no incarnation is sent only on the same connection that showed the process.
  • New legacyRelayBridge:close IPC → closeLegacyRelayPane in the registry.
  • Renderer:
    • closeTab (the path every user, cleanup and bulk close reaches) asks the bridge to stop the tab's bridged shells. It first waits for main's initial pane list, and skips any shell that another tab now shows (a moved pane) or that the plan marks as shared. A detach-to-tab close (localPtyTeardownOwnedExternally) never stops anything.
    • An explicit split-pane close stops its shell through the bridge transport's destroy, which matches what the other transports' destroy does.
  • Main's generic pty.kill for a bridged ssh: id goes to the bridge. Before, it tombstoned the lease without stopping the shell, which orphaned the shell for good.

Why

Root cause: the bridge had no stop method at all. LegacyRelayClient.close() only hung up, and the renderer's bridged transport destroy() only detached. The tab-close retirement plan classified the ssh: relay-era id under a managed (runtime) worktree as unroutable and skipped it. The managed server's session.tabs.close closes only its own terminals, and it never ran the relay's shells. So no close path ever told the relay.

Alternatives considered:

  • Kill from the managed server. It can't do this: the relay owns those shells.
  • Persist the pending stop on the lease (the old pendingKill field). Leases carrying pendingKill are deliberately unbridgeable, so the relay would never be asked. Pending stops live in memory for the app session instead. If the app quits while the host is unreachable, the stop is lost, and the shell is listed again on the next connect (no worse than today).
  • Route bridged ids through the generic PTY provider. This build has no relay provider, which is exactly why that path tombstoned leases.

Wire compatibility: the relay side uses only the old relay's existing pty.shutdown request, with optional fields omitted when unknown. The desktop-internal IPC adds one channel, and no host-published content changes.

Linked Issue

Found by the 1.4.227 → main upgrade-path test (no issue filed).

Visual Proof

N/A: there is no UI change. The effect is on host processes, verified live below.

Testing

Verified live on omarchy (Linux) under host isolation: a private user-level sshd on its own port with a throwaway remote HOME under /tmp, reached through my own tunnel, and isolated desktop profiles. Each run built a relay-era profile with v1.4.227 (relay mode), then launched this branch's e2e build with a managed-server template:

  • Run 1 (3 bridged tabs, closed with store closeTab):
    • tab 1 with a plain close, tab 2 with the host-owned close shape: both relay shells ended on the host and their tickers stopped;
    • disconnect, then close tab 3: unverifiable, the shell kept running, and the pane was held as unverifiable with no exit reported;
    • reconnect: the queued stop was sent, the shell ended, and the old relay exited.
  • Run 2 (2 bridged tabs, closed with the real tab-strip Close tab button):
    • each click ended exactly that tab's relay shell; the other tab's shell kept running until its own close;
    • after both closes the relay exited;
    • reconnect re-added no tabs; managedOrcad.stop returned unlinked, with no "terminals still running" refusal;
    • reconnect converted the host again (a new managed environment linked the repo), so the move proceeds.
  • Run 3 (final code, 2 bridged tabs, real Close tab button):
    • closing tab 1 while connected ended its shell;
    • after a disconnect, closing tab 2 removed the tab but left its shell running, and the pane stayed unverifiable;
    • reconnect: the queued stop went out, the shell and the relay ended, and no tabs came back.
  • The incarnation and recycled-id fences, the generic pty.kill reroute, the moved-pane exclusion and the split-pane close were verified in tests only.

Automated:

  • legacy-relay-target-bridge.test.ts: stop and exit, stop proven by a listing, unreachable then reconnect, a recycled incarnation, a blind legacy id, and a failed stop never replayed on a new connection.

  • legacy-relay-client.test.ts: the wire shape, with and without the fence.

  • legacy-relay-bridge-transport.test.ts: a pane close stops the shell, a detach does not; closing-tab target selection.

  • legacy-relay-bridged-tab-close.test.ts: waits for the first listing; skips moved and shared shells.

  • kill-legacy-relay-bridged.test.ts: a generic kill leaves the lease to the bridge.

  • All new tests fail before the fix. pnpm tc and the full static-analysis job steps from pr.yml pass locally.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Co-Authored-By: Claude <noreply@anthropic.com>
@nwparker
nwparker merged commit f1677db into main Oct 16, 2026
40 of 44 checks passed
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