Repository navigation
Description
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-52has a workingconnect(target), but nothing calls it during app initialization —src/renderer/src/App.tsxhydrates the workspace session but has no SSH reconnect pass. RenderersshConnectionStates(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
pendingReconnectPtyIdByTabIdandreconnectPersistedTerminals()(src/renderer/src/store/slices/terminals.ts:84, 1158-1257), but that code path explicitly skips SSH repos:const supportsDeferredReattach = !repo?.connectionIdaroundterminals.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
beforeunloadcapture insrc/renderer/src/App.tsxnor the mainwill-quithandler insrc/main/index.tsserializes the set of active SSH connections or remote PTY session IDs intoWorkspaceSessionState(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):
- 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 ofpendingReconnectPtyIdByTabIdfor remote PTYs).
Populate both onbeforeunload/will-quitalongside the existing terminal-buffer snapshot.
- Auto-reconnect on startup. In
App.tsxhydration (src/renderer/src/App.tsx:157-228), after repos/worktrees load, callconnectionManager.connect(target)for each persistedactiveConnectionIdsAtShutdownwith soft-fail error handling (offline, auth prompts, network blips) and a per-connection status indicator in the UI. - 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 RPCpty.reattach(sessionId)insrc/relay/relay.tsthat returns the existing PTY handle + serialized scrollback if the grace timer hasn't expired, ornot-foundso the tab can re-spawn fresh and surface a "session lost" notice.src/main/providers/ssh-pty-provider.tsroutes the reattach call. - 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.tscovers local scrollback/layout restart;src/renderer/src/store/slices/store-session-cascades.test.ts:660-960covers 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 startupsrc/main/ssh/ssh-connection.ts:24-366— already has retry/backoff for transient errorssrc/relay/relay.ts:1-99(grace timer lines 15, 70-76) — relay already designed for reconnection, just needs areattachRPCsrc/main/providers/ssh-pty-provider.ts:13-162— remote PTY proxy path for reattachsrc/renderer/src/store/slices/terminals.ts:84, 1158-1257— reattach orchestration; SSH branch currently disabled at:1196src/shared/workspace-session-schema.ts— session schema to extendsrc/main/daemon/daemon-entry.ts,src/main/daemon/daemon-spawner.ts— local daemon model to generalize for Layer 2
Activity