Repository navigation
fix(ssh): stop a relay-era shell when its bridged tab closes - #29620
Merged
Merged
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
8 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.shutdownsends the old relay's ownpty.shutdown {id, immediate: false, keepHistory: false}, the shape 1.4.224's provider sent.expectedIncarnationIdis added only when known, so older relays never see the field.legacy-relay-pane-stops.tsholds one target's pending stops outside the bridge, so a reconnect's new bridge still sends them. A stop stays pending until the relay reportspty.exit, or until a listing no longer shows the terminal. Until then it re-lists on the bridge's backoff.pty2:id carries its relay's start epoch, so the id itself is the fence;pty-Nid with no incarnation is sent only on the same connection that showed the process.legacyRelayBridge:closeIPC →closeLegacyRelayPanein the registry.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.destroy, which matches what the other transports'destroydoes.pty.killfor a bridgedssh: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 transportdestroy()only detached. The tab-close retirement plan classified thessh:relay-era id under a managed (runtime) worktree as unroutable and skipped it. The managed server'ssession.tabs.closecloses only its own terminals, and it never ran the relay's shells. So no close path ever told the relay.Alternatives considered:
pendingKillfield). Leases carryingpendingKillare 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).Wire compatibility: the relay side uses only the old relay's existing
pty.shutdownrequest, 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:
closeTab):unverifiable, the shell kept running, and the pane was held as unverifiable with no exit reported;managedOrcad.stopreturnedunlinked, with no "terminals still running" refusal;unverifiable;pty.killreroute, 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 tcand 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
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)