Repository navigation
Fix SSH state for paired remote clients + complete target re-adoption sweep (STA-1468) - #7767
Conversation
reassignSshTargetId re-pointed repos and worktree metas but left the old target id embedded in persisted session pty ids (ssh:<id>@@pty-N in tabs, layouts, remoteSessionIdsByTabId), the startup reconnect list (activeConnectionIdsAtShutdown, replayed via ssh.connect at boot — the exact 'SSH target not found' in STA-1468), sleeping-agent resume records, provisioned project host setups, sidebar host-scope arrays, and relay pty leases. Any survivor resurfaces later as a failing connect or reattach. New ssh-target-id-migration module re-points every carrier in one pass, wired into reassignSshTargetId with per-carrier unit and store-level round-trip tests. Co-authored-by: Orca <help@stably.ai>
The SSH surface was desktop-only: ssh:state-changed went to the host's own BrowserWindow and the web client's ssh API was a no-op stub, so a paired client's reconnect overlay never learned the host connected and its target labels stayed empty (STA-1468 — overlay stuck on 'please connect' over a live terminal). - New sshStateChanged runtime client event, emitted from broadcastSshState through OrcaRuntimeService onto the existing clientEvents stream. - New ssh.listTargets / ssh.listRemovedTargetLabels RPC methods next to the previously unused ssh.getState / ssh.connect. - Web preload now routes listTargets / listRemovedTargetLabels / getState / connect to the paired host's runtime RPC instead of stubbing them. - useIpcEvents applies sshStateChanged on paired web clients through the same guarded path as desktop ssh.onStateChanged; desktop clients ignore the event since a foreign runtime's targets would pollute their local SSH store. Co-authored-by: Orca <help@stably.ai>
- Only present the destructive 'SSH host removed' state on positive evidence (a removal tombstone label, or a hydrated non-empty target list lacking the id). A client whose SSH state never hydrated has an empty labels map for every id and must not offer workspace removal. - After a failed Connect, resync target metadata so a stale overlay converges to the ghost/re-adopted state instead of offering the same failing Connect forever (the repeated 'SSH target not found' toast loop in STA-1468). Co-authored-by: Orca <help@stably.ai>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis PR adds SSH target-id migration across persisted session, UI, lease, and project-host data during reassignment, and wires the persistence path to use those migrations. It introduces a new Sequence Diagram(s)See the review stack artifact above for the SSH state propagation sequence. Estimated code review effort: 4/5 Related issues: None specified Related PRs: None specified Suggested labels: ssh, persistence, runtime, renderer Suggested reviewers: None specified 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 523dfb6a-fed8-4371-a076-dbe35c87595d
📒 Files selected for processing (17)
src/main/ipc/ssh.test.tssrc/main/ipc/ssh.tssrc/main/persistence.test.tssrc/main/persistence.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/ssh.test.tssrc/main/runtime/rpc/methods/ssh.tssrc/main/runtime/runtime-rpc.tssrc/main/ssh/ssh-target-id-migration.test.tssrc/main/ssh/ssh-target-id-migration.tssrc/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.tssrc/renderer/src/runtime/runtime-client-events.tssrc/renderer/src/web/web-preload-api.tssrc/shared/runtime-client-events.ts
- Re-key workspaceSessionsByHostId partitions stored under a removed SSH host id during re-adoption (no writer keys partitions by ssh host today, but the schema tolerates it — re-key instead of stranding; live partition wins when both keys exist). - Track SSH target-list hydration explicitly (sshTargetsHydrated) instead of inferring it from a non-empty label map, so a legitimately empty target list still counts as removal evidence and a never-hydrated client still never offers destructive removal. - Apply the refreshed target list before the best-effort removed-labels fetch in the overlay resync, so a labels failure can't discard it. Co-authored-by: Orca <help@stably.ai>
… sweep (STA-1468) (stablyai#7767) * Sweep all persisted carriers of a removed SSH target id on re-adoption reassignSshTargetId re-pointed repos and worktree metas but left the old target id embedded in persisted session pty ids (ssh:<id>@@pty-N in tabs, layouts, remoteSessionIdsByTabId), the startup reconnect list (activeConnectionIdsAtShutdown, replayed via ssh.connect at boot — the exact 'SSH target not found' in STA-1468), sleeping-agent resume records, provisioned project host setups, sidebar host-scope arrays, and relay pty leases. Any survivor resurfaces later as a failing connect or reattach. New ssh-target-id-migration module re-points every carrier in one pass, wired into reassignSshTargetId with per-carrier unit and store-level round-trip tests. Co-authored-by: Orca <help@stably.ai> * Bridge SSH connection state to paired remote clients The SSH surface was desktop-only: ssh:state-changed went to the host's own BrowserWindow and the web client's ssh API was a no-op stub, so a paired client's reconnect overlay never learned the host connected and its target labels stayed empty (STA-1468 — overlay stuck on 'please connect' over a live terminal). - New sshStateChanged runtime client event, emitted from broadcastSshState through OrcaRuntimeService onto the existing clientEvents stream. - New ssh.listTargets / ssh.listRemovedTargetLabels RPC methods next to the previously unused ssh.getState / ssh.connect. - Web preload now routes listTargets / listRemovedTargetLabels / getState / connect to the paired host's runtime RPC instead of stubbing them. - useIpcEvents applies sshStateChanged on paired web clients through the same guarded path as desktop ssh.onStateChanged; desktop clients ignore the event since a foreign runtime's targets would pollute their local SSH store. Co-authored-by: Orca <help@stably.ai> * Harden the SSH reconnect overlay against stale or unknown target state - Only present the destructive 'SSH host removed' state on positive evidence (a removal tombstone label, or a hydrated non-empty target list lacking the id). A client whose SSH state never hydrated has an empty labels map for every id and must not offer workspace removal. - After a failed Connect, resync target metadata so a stale overlay converges to the ghost/re-adopted state instead of offering the same failing Connect forever (the repeated 'SSH target not found' toast loop in STA-1468). Co-authored-by: Orca <help@stably.ai> * Address CodeRabbit review on stablyai#7767 - Re-key workspaceSessionsByHostId partitions stored under a removed SSH host id during re-adoption (no writer keys partitions by ssh host today, but the schema tolerates it — re-key instead of stranding; live partition wins when both keys exist). - Track SSH target-list hydration explicitly (sshTargetsHydrated) instead of inferring it from a non-empty label map, so a legitimately empty target list still counts as removal evidence and a never-hydrated client still never offers destructive removal. - Apply the refreshed target list before the best-effort removed-labels fetch in the overlay resync, so a labels failure can't discard it. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
Fixes STA-1468: a user on a paired remote client saw
Error invoking remote method 'ssh:connect': SSH target "ssh-…" not foundon every Connect click, and the "SSH connection required" overlay never cleared even while the terminal was demonstrably live.Root causes and fixes (3 commits)
1.
reassignSshTargetIdleft stale carriers of the removed target id (follow-up to #7753). Re-adoption re-pointed repos/worktree metas but not: persisted SSH pty ids (ssh:<targetId>@@pty-Nin tabs/layouts/remoteSessionIdsByTabId), the startup reconnect listactiveConnectionIdsAtShutdown(replayed intossh.connectat boot — the exact "not found" thrower), sleeping-agent records, provisioned project host setups, sidebar host-scope arrays, and relay pty leases. Newssh-target-id-migration.tssweeps every carrier in one pass. (SSH worktrees partition into the local session blob — verified viaworkspace-session-host-split.tsfield ownership — so the sweep targets that blob plus all host partitions.)2. The SSH surface was desktop-only — never bridged to paired remote clients.
ssh:state-changedwent only to the host's own BrowserWindow, and the web client's entire ssh API was a no-op stub, so a paired client could never learn the host connected. Added asshStateChangedruntime client event emitted frombroadcastSshState, newssh.listTargets/ssh.listRemovedTargetLabelsRPC methods (beside the previously unusedssh.getState/ssh.connect), and backed the web preload'slistTargets/listRemovedTargetLabels/getState/connectwith real runtime RPC.useIpcEventsapplies the event through the same guarded path as desktopssh.onStateChanged, gated to paired web clients (a desktop client's local SSH store must not absorb a foreign runtime's targets).3. Overlay hardening. The destructive "SSH host removed → Remove workspace" state now requires positive evidence (tombstone label, or a hydrated non-empty target list lacking the id) — a client with unhydrated SSH state is never offered removal from ignorance. A failed Connect resyncs target metadata so a stale overlay converges to the ghost/re-adopted state instead of looping the same failing toast.
Live SSH e2e evidence (brennan-test-ssh)
Target: throwaway Ubuntu 22.04 arm64 Docker container (
sshd, Node 20, build-essential), demo-project cloned via git bundle (container has no GitHub auth). Host: this exact PR worktree, isolatedORCA_DEV_USER_DATA_PATH, CDP-attached, identity verified asJinwoo-H/ssh-issues-2.pnpm build:relaybefore connecting; relay compiled node-pty on the linux-arm64 host.status: connected, remotePlatform: linux), remote repo/work/demo-projectregistered, worktree/work/e2e-sta1468created and confirmed viagit worktree listover ssh. Typing in Orca's terminal created/tmp/pty-proof.txton the container.echo readopt-proof-$(pwd)executed in/work/e2e-sta1468on the container. Boot log shows the one residual stale pty id hitting the existingbelongs to SSH connectionrecovery marker and spawning fresh (see follow-ups).SSH target not foundtoast, then the overlay flipped to "SSH host removed" + "Remove workspace" — no loop. (Pre-fix: infinite identical toasts, which is the reporter's screenshot.)web-index.html#pairing=…in a separate Chromium. Web store hydratedsshTargetLabels(both targets) andsshConnectionStates: connectedover the new RPC — previously empty stubs. Host-sidessh.disconnect→ web overlay appeared with the friendly label via thesshStateChangedevent. Clicked Connect on the web client → routed over runtime RPC → host reconnected → overlay cleared on the web client (the exact reported symptom). After a web reload, typing in the web terminal executedecho web-client-proof-4on the remote host.Known follow-up gaps (documented, not regressions — both previously unreachable behind the never-clearing overlay)
Tests
Per-carrier migration unit tests + store round-trip tests, RPC method tests,
broadcastSshState→runtime-stream emission test, overlay convergence/positive-evidence tests. 3,350 tests green across affected suites; typecheck (all three configs), oxlint, max-lines ratchet, localization all pass.Made with Orca 🐋