Repository navigation
Per-environment SSH state: desktop clients attached to a Remote Orca Server get working SSH overlays/Connect (STA-1468 desktop topology) - #7831
Conversation
…r Remote Orca Server workspaces (STA-1468 desktop topology) Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis PR adds a new Zustand slice tracking SSH connection state, target labels, and removed-target tombstones per remote runtime environment, along with RPC-backed hydration, connect, and resync helper functions. The terminal SSH reconnect overlay and pane now resolve reconnect status through runtime-aware selectors and an owning environment id, routing connect/resync operations to the remote environment RPC when applicable. IPC event handling and runtime client event subscription are extended to hydrate SSH state on refresh/transport gaps, mark state stale on disconnects, apply SSH state-changed events directly for non-paired windows, and detect subscription replay after reconnect. Corresponding unit tests are added across the new slice, RPC helpers, overlay, and event handling. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/runtime/runtime-environment-ssh-state.ts (1)
49-69: 🚀 Performance & Scalability | 🔵 TrivialConsider fetching per-target connection states in parallel.
fetchEnvironmentSshConnectionStatesawaitsssh.getStatefor each target serially, and each call carries a 15s timeout. On a remote host with several targets this serializes reconnect/hydration latency (worst case N × 15s). Since each fetch is already independently guarded by its owntry/catch, running them concurrently preserves the per-target failure semantics while cutting latency.♻️ Proposed parallelization
- for (const target of targets) { - try { - const { state } = await callRuntimeRpc<{ state: SshConnectionState | null }>( - environmentTarget(environmentId), - 'ssh.getState', - { targetId: target.id }, - { timeoutMs: SSH_RPC_TIMEOUT_MS } - ) - if (state) { - useAppStore.getState().setEnvironmentSshConnectionState(environmentId, target.id, state) - } - } catch { - // A missing state just reads as 'disconnected'; the overlay's Connect - // action and push events converge it. - } - } + await Promise.all( + targets.map(async (target) => { + try { + const { state } = await callRuntimeRpc<{ state: SshConnectionState | null }>( + environmentTarget(environmentId), + 'ssh.getState', + { targetId: target.id }, + { timeoutMs: SSH_RPC_TIMEOUT_MS } + ) + if (state) { + useAppStore.getState().setEnvironmentSshConnectionState(environmentId, target.id, state) + } + } catch { + // A missing state just reads as 'disconnected'; the overlay's Connect + // action and push events converge it. + } + }) + )
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b57e5fab-02d5-4d0f-9625-76a525a44be6
📒 Files selected for processing (16)
src/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.test.tsxsrc/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.tsxsrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/runtime/runtime-client-events.test.tssrc/renderer/src/runtime/runtime-client-events.tssrc/renderer/src/runtime/runtime-environment-ssh-state.test.tssrc/renderer/src/runtime/runtime-environment-ssh-state.tssrc/renderer/src/store/index.tssrc/renderer/src/store/slices/diffComments.test.tssrc/renderer/src/store/slices/runtime-environment-ssh.test.tssrc/renderer/src/store/slices/runtime-environment-ssh.tssrc/renderer/src/store/slices/runtime-status.tssrc/renderer/src/store/slices/store-test-helpers.tssrc/renderer/src/store/types.ts
…r Remote Orca Server workspaces (STA-1468 desktop topology) (stablyai#7831) Co-authored-by: Orca <[email protected]>
Problem — STA-1468, desktop flavor (#7718 family)
PR #7767 fixed the stale "SSH connection required" overlay for paired web clients, but a desktop client attached to a Remote Orca Server — per user feedback the most common topology (Orca on a devbox, attached from another desktop) — still had the original symptom:
sshStateChangedruntime client events for its SSH targets, but the desktop client deliberately dropped them (useIpcEvents.tsgated the event onisPairedWebClientWindow()), because applying a foreign machine's SSH state into the renderer's single global SSH store would collide with the desktop's own local SSH targets.window.api.ssh.connectfor a target id that only exists on the host.Design
Store: SSH state scoped by owning environment. New slice
runtime-environment-ssh.tsaddssshStateByEnvironment: Map<envId, bucket>where each bucket mirrors the local shape (connectionStates,targetLabels,removedTargetLabels,targetsHydratedwith the same positive-evidence rule). The existing local/global maps are untouched — desktop-local and web-client behavior is bit-identical.Selector-only reads. Components never touch the bucket map or the local maps directly:
selectRuntimeAwareSshStatus/TargetLabel/TargetRemoved(state, environmentId | null, targetId)route internally (null= local). For a remote-owned target the status selector returnsnull(= unknown, show nothing) when the environment is unreachable or its bucket is un-hydrated, so a dead/foreign bucket can never produce a wrong overlay, and the environment's own disconnected UI outranks any SSH overlay.Events: apply instead of drop.
handleRuntimeClientEventnow routessshStateChangedinto the emitting environment's bucket on desktop (web keeps the existing global-store path). An event for a target the bucket doesn't know triggers a forced re-fetch of the authoritative target list instead of trusting the event, so a disconnect racing a target removal can't resurrect it.Hydration.
hydrateRuntimeEnvironmentSshState(single-flight per env, force-coalescing) fetchesssh.listTargets+ssh.listRemovedTargetLabels+ per-targetssh.getStateover the environment-routed runtime RPC. Triggered from the runtime project refresh scheduler (initial connect + reconnect) and lazily fromTerminalPanewhen it resolves a remote-owned SSH workspace. Hosts without thessh.*RPC methods (pre-#7767) leave the bucket un-hydrated → reads resolve to unknown, never to destructive "remove workspace" UI.Staleness on transport loss. Client events emitted during a transport gap are lost, so: (a) the replay tag on the first post-reconnect subscription response (#7827 machinery) downgrades the bucket to un-hydrated + clears states, then force-rehydrates; (b) a reachable→unreachable transition in
runtimeStatusByEnvironmentIdalso downgrades; (c) the selectors additionally gate on reachability.Write path.
TerminalSshReconnectOverlaygetssshOwnerEnvironmentId; when set, Connect routes tossh.connecton the owning environment's runtime RPC (mirroring the returned state into the bucket) and the failed-connect resync refreshes that environment's target metadata, keeping the sequential targets-first + swallow pattern.Owner resolution.
TerminalPaneresolves the owning environment with the existinggetExplicitRuntimeEnvironmentIdForWorktree(worktree hostId override → repoexecutionHostId→ never "merely focused runtime"), gated off for paired web windows. Unresolvable repos keep today's behavior (no target id → no overlay).Lifecycle. Buckets are dropped when an environment is removed (
setRuntimeEnvironmentsretain hook, same pattern as detected-agents).Invariant: zero cross-pollution. Remote buckets never feed local SSH settings/pickers (those read the local maps as before), and local state is never written by remote events — enforced by tests.
Test evidence
Unit (all passing,
vitest --config config/vitest.config.ts):runtime-environment-ssh.test.ts(11): bucket routing, no cross-pollution in both directions, reference stability, empty-list hydration flag, retain/detach lifecycle, staleness downgrade, selector resolution (local vs env vs unreachable vs un-hydrated), removal positive-evidence.runtime-environment-ssh-state.test.ts(11): hydration population/skip/force, old-host failure leaves un-hydrated, removed-labels failure keeps targets, event application (known target direct, unknown target re-fetch, removal race not resurrected), connect routing + state mirroring, resync.TerminalSshReconnectOverlay.test.tsx(+2, 9 total): Connect routed to env RPC (local API untouched), failed remote connect resyncs env not local store; all 7 pre-existing local/web tests unchanged and passing.runtime-client-events.test.ts(+1): replay-tagged response signals resync and still delivers events.useIpcEvents.test.ts(+1, 70 passing),ssh.test.ts,ssh-reconnect-pane-retry,runtime-client-events-sync,runtime-status,remote-server-parity,runtime-rpc-client,FloatingTerminalPanelall green.pnpm typecheckclean, oxlint clean on changed files,check:max-lines-ratchetOK.Live smoke (two dev instances of this branch on one machine, separate
ORCA_DEV_USER_DATA_PATH, CDP 9501/9502; throwaway Ubuntu 22.04 sshd Docker container as SSH target;demo-projectcloned in-container from a git bundle because the container has no GitHub auth):smoke-devbox→ connected (relay deployed, node-pty compiled on linux-arm64) → added/work/demo-projectas remote repo.getRuntimePairingUrl→runtimeEnvironments.addFromPairingCode; repos fetched withconnectionId=ssh-…,executionHostId=runtime:<envId>.{labels: {ssh-…: smoke-devbox}, states: {ssh-…: connected}}, local maps 0/0 entries.disconnectedvia the pushed event and the overlay appeared ("This terminal is waiting for smoke-devbox…") — the exact previously-dead flow.ssh.getStateon server:connected; relay node process live in container) → overlay cleared on the client. Local maps still 0/0 throughout.Not verified (honest list)
runWorktreeDeletefor the remote-owned worktree was not exercised live.sshStateChangedas before.Made with Orca 🐋