Skip to content

[Feature]: Persist and auto-restore SSH connections + remote terminal sessions across app restarts #985

Description

@artile

Problem or use case

When I'm working in SSH-connected remote worktrees with several remote terminal tabs running long-lived processes (dev server, tail, an in-flight CLI agent), quitting Orca — intentionally or via an update/crash — drops every SSH connection and every remote PTY on the next launch, even though the relay daemon on the remote host stays alive during its grace window (src/relay/relay.ts:70-76, default 5 min).

Specifically:

  • SSH connections are not persisted and not auto-reconnected on startup. src/main/ssh/ssh-connection-manager.ts:21-52 has a working connect(target), but nothing calls it during app initialization — src/renderer/src/App.tsx hydrates the workspace session but has no SSH reconnect pass. Renderer sshConnectionStates (src/renderer/src/store/slices/ssh.ts:13) is in-memory only.
  • Remote PTY session IDs are never persisted. Local daemon-mode PTYs reattach via pendingReconnectPtyIdByTabId and reconnectPersistedTerminals() (src/renderer/src/store/slices/terminals.ts:84, 1158-1257), but that code path explicitly skips SSH repos: const supportsDeferredReattach = !repo?.connectionId around terminals.ts:1196. So even when the relay would still have my PTYs alive, Orca doesn't know their session IDs.
  • Shutdown doesn't record SSH state. Neither the beforeunload capture in src/renderer/src/App.tsx nor the main will-quit handler in src/main/index.ts serializes the set of active SSH connections or remote PTY session IDs into WorkspaceSessionState (src/shared/workspace-session-schema.ts).

Net effect on my workflow: after any restart, I have to manually re-open each remote worktree, wait for the SSH connect + relay redeploy, and re-start every remote process. The workaround — leaving Orca running 24/7 and using tmux inside each remote terminal — works, but it defeats the "open a remote worktree and go" promise of the SSH feature.

This overlaps but is distinct from #954 (general restart/quit UX, focused on local session restore and claude --resume). #954 doesn't cover SSH connection persistence, remote PTY reattach, or the "daemon stays alive while app is off" angle — which is specific to the SSH/relay architecture.

Proposed solution

Two layers — the second is the "ideal" case and can land after the first.

Layer 1 — persist & auto-reconnect (app-bound lifetime):

  1. Persist active SSH state in the workspace session. Extend WorkspaceSessionState (src/shared/workspace-session-schema.ts) with:
    • activeConnectionIdsAtShutdown: string[] — SSH targets that were connected at quit time.
    • remoteSessionIdsByTabId: Record<string, string> — the remote relay PTY session IDs for every SSH-backed terminal tab (mirror of pendingReconnectPtyIdByTabId for remote PTYs).
      Populate both on beforeunload / will-quit alongside the existing terminal-buffer snapshot.
  2. Auto-reconnect on startup. In App.tsx hydration (src/renderer/src/App.tsx:157-228), after repos/worktrees load, call connectionManager.connect(target) for each persisted activeConnectionIdsAtShutdown with soft-fail error handling (offline, auth prompts, network blips) and a per-connection status indicator in the UI.
  3. Reattach remote PTYs. Extend reconnectPersistedTerminals() (src/renderer/src/store/slices/terminals.ts:1158-1257) so SSH-backed tabs are no longer skipped: after the SSH connection is restored, call a new relay RPC pty.reattach(sessionId) in src/relay/relay.ts that returns the existing PTY handle + serialized scrollback if the grace timer hasn't expired, or not-found so the tab can re-spawn fresh and surface a "session lost" notice. src/main/providers/ssh-pty-provider.ts routes the reattach call.
  4. Extend the relay grace window / make it configurable. The current 5-minute grace (src/relay/relay.ts:15) covers quick restarts but not updates or overnight closures. Add a per-target setting (default higher, e.g. 1h) and expose it alongside the existing agent-timeout settings.

Layer 2 — persistent local daemon (app-independent lifetime):

Today the local SSH client and channel multiplexer die with the Electron process. Ideally Orca runs a lightweight background daemon (systemd user unit on Linux, launchd agent on macOS, Windows service on Windows) that:

  • Owns the SSH client connections and the channel-mux to each relay.
  • Keeps the connections warm across Orca quit/update/crash, so the remote relay's grace timer never has to save us.
  • Exposes a local Unix socket / named pipe that the Electron renderer + main attach to on startup and detach from on quit — the daemon is the source of truth, the app is a thin client.
  • Handles credential prompts via a callback to the app when the app is running; otherwise keeps existing connections alive and surfaces prompts lazily on reattach.

This is analogous to the existing local PTY daemon path (src/main/daemon/daemon-entry.ts, src/main/daemon/daemon-spawner.ts) that already survives app quit for local PTYs under experimentalTerminalDaemon, just extended to own SSH connections and remote-PTY session IDs too. With Layer 2 in place, Layer 1's "reconnect on startup" step becomes "reattach to daemon, which already has everything".

Alternatives or additional context

  • Workaround today: leave Orca running 24/7 and wrap every remote terminal in tmux new -A -s orca-<tab>. Works, but manual and bypasses Orca's tab/scrollback model.
  • Related upstream issue: [Feature]: Improve Orca exiting / restarting behavior #954 asks for general restart/restore UX. This request is the SSH/remote counterpart — they could be bundled or cross-referenced.
  • Local precedent already exists: tests/e2e/terminal-restart-persistence.spec.ts covers local scrollback/layout restart; src/renderer/src/store/slices/store-session-cascades.test.ts:660-960 covers local daemon reattach. Extending both suites to cover SSH-backed tabs would be the natural test surface.

Relevant existing code to build on:

  • src/main/ssh/ssh-connection-manager.ts:21-52 — connection pool, ready to be driven on startup
  • src/main/ssh/ssh-connection.ts:24-366 — already has retry/backoff for transient errors
  • src/relay/relay.ts:1-99 (grace timer lines 15, 70-76) — relay already designed for reconnection, just needs a reattach RPC
  • src/main/providers/ssh-pty-provider.ts:13-162 — remote PTY proxy path for reattach
  • src/renderer/src/store/slices/terminals.ts:84, 1158-1257 — reattach orchestration; SSH branch currently disabled at :1196
  • src/shared/workspace-session-schema.ts — session schema to extend
  • src/main/daemon/daemon-entry.ts, src/main/daemon/daemon-spawner.ts — local daemon model to generalize for Layer 2

Activity

  1. self-assigned this
    on Apr 24, 2026
  2. added
    wip
    on Apr 25, 2026
  3. added theissue type on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

wip

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions