Repository navigation
feat(ssh): persist and auto-restore SSH sessions across app restarts - #1026
Merged
Merged
Conversation
Jinwoo-H
force-pushed
the
Jinwoo-H/persist-ssh-985
branch
2 times, most recently
from
April 24, 2026 22:54
4bdc694 to
edbd394
Compare
Jinwoo-H
force-pushed
the
Jinwoo-H/persist-ssh-985
branch
2 times, most recently
from
April 24, 2026 22:58
edbd394 to
aa136fc
Compare
Jinwoo-H
force-pushed
the
Jinwoo-H/persist-ssh-985
branch
from
April 25, 2026 02:55
14889bd to
13096a9
Compare
Jinwoo-H
force-pushed
the
Jinwoo-H/persist-ssh-985
branch
from
April 26, 2026 03:06
0724f0f to
c572b6d
Compare
…985) Capture active SSH connections and remote PTY session IDs at shutdown, auto-reconnect on startup, and reattach to relay PTYs within the grace window. Passphrase-protected targets are deferred to tab focus to avoid stacking credential dialogs at startup.
workspace-session.test.ts was missing sshConnectionStates (Map), repos, and worktreesByRepo in the snapshot fixture. pty-connection.test.ts was missing deferredSshReconnectTargets in the mock store state.
The relay now creates a Unix domain socket (relay.sock) alongside its stdin/stdout transport. When the app restarts and SSH reconnects, launchRelay probes for the socket and launches in --connect mode to bridge the new SSH channel to the existing relay process — preserving live PTY sessions and scrollback buffers across restarts. If the socket is stale (crashed relay), the probe fails gracefully and a fresh relay is launched as before.
…h, credential leak P0 fixes: - Deferred SSH reconnect now attempts pty.attach with the persisted session ID instead of always spawning a fresh shell - Socket created with chmod 0600 to prevent other users on shared hosts from hijacking PTY sessions - credentialRequestedForTarget cleared on connect failure so targets aren't permanently misclassified as needing passphrase P1 fixes: - Grace timer only starts when the closing socket is still the active one, preventing spurious shutdown when a socket is replaced - Dispatcher writes to a no-op after stdin dies instead of a dead pipe - Connect-mode bridge has a 5s timeout to avoid hanging on stale sockets - graceTime clamped to integer before shell interpolation
…ects Round 2 review fixes: - Add deferredSshSessionIdsByTabId store field to preserve remote PTY session IDs for passphrase-protected targets across the startup clear of pendingReconnectPtyIdByTabId. Without this, deferred reconnect always fell back to fresh spawn because the IDs were already gone. - Remove target from deferredSshReconnectTargets BEFORE awaiting ssh.connect to prevent split panes from each triggering parallel connect calls that race and fail with "already in progress". - Check sshConnectionStates before calling ssh.connect so panes that mount after another pane already completed the deferred connect skip the redundant call and proceed directly to reattach.
…ssion expired toast - Pass target's relayGracePeriodSeconds to reestablishRelayStack so network-blip reconnects inherit the configured grace period instead of always using the 300s default. - Reset relay dispatcher sequence counters and decoder on socket reconnect so the new client's seq=1 frames are properly acked. Without this, the relay's highestReceivedSeq stays at the old client's value, preventing ack updates for early frames. - Surface sessionExpired flag from SSH pty.spawn to the renderer so users see "Previous session expired — started a new shell" when reattach fails due to elapsed grace window.
… machine Replace scattered relay state (activeMultiplexers Map, initializedConnections Set, explicitRelaySetupTargets Set, reestablishAbortControllers Map) with a single SshRelaySession class per SSH target. The session class encapsulates the full relay lifecycle: - State machine: idle → deploying → ready → reconnecting → disposed - Owns: multiplexer, providers (pty/fs/git), abort controller - Single `registerProviders()` path used by both establish() and reconnect(), eliminating the duplication that caused past bugs where one path forgot a registration step the other handled Delete ssh-relay-helpers.ts — all logic now lives in the session class. Add 13 unit tests covering state transitions, error recovery, overlapping reconnects, PTY reattach, and port forward cleanup.
…rtial cleanup - Dispose existing session before creating new one in ssh:connect, preventing mux/provider/timer leaks on double-connect. - Allow onStateChange to retry reconnect when session is in 'reconnecting' state (not just 'ready'). Without this, a failed relay deploy on a working SSH connection permanently bricked the session with no recovery path. - Clean up mux and partially-registered providers in establish() error path via teardownProviders(), preventing leaks when registerRelayRoots or provider construction throws. - Add 2 tests: partial-registration cleanup and reconnect retry after failure.
Restrict reconnect() to only accept 'ready' and 'reconnecting' states. Calling from 'deploying' would tear down a mux that establish() is concurrently using; 'idle' means no session was established yet. Previously only guarded against 'disposed'.
Jinwoo-H
force-pushed
the
Jinwoo-H/persist-ssh-985
branch
from
April 26, 2026 03:10
c572b6d to
198c557
Compare
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
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.
Summary
Closes #985. When Orca restarts, SSH connections and remote terminal sessions are now automatically restored instead of requiring manual reconnection.
beforeunload— no sync IPC neededsessionIdthroughSshPtyProvider.spawn()→ relaypty.attachwith try/catch fallback to fresh spawn when grace window expirespty:replayIPC channel so relay replay data routes through xterm's replay guard, preventing auto-reply leakageFiles changed (18)
ssh-types.ts,types.ts,workspace-session-schema.ts— new fieldsssh-pty-provider.ts,ssh-relay-helpers.ts,ssh.ts,ssh-relay-deploy.ts,types.ts— sessionId routing, replay wiring, passphrase tracking, configurable grace timeindex.ts,api-types.d.ts—onReplaybindingApp.tsx,workspace-session.ts,terminals.ts,pty-connection.ts,pty-dispatcher.ts,pty-transport.ts,SshPane.tsx,SshTargetForm.tsx— capture/restore/reconnect/UITest plan
orca-data.jsoncontainsactiveConnectionIdsAtShutdownandremoteSessionIdsByTabIdafter quit with SSH tabs active