Skip to content

Fix SSH state for paired remote clients + complete target re-adoption sweep (STA-1468) - #7767

Merged
Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/ssh-issues-2
Jul 8, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/ssh-issues-2

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes STA-1468: a user on a paired remote client saw Error invoking remote method 'ssh:connect': SSH target "ssh-…" not found on 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. reassignSshTargetId left 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-N in tabs/layouts/remoteSessionIdsByTabId), the startup reconnect list activeConnectionIdsAtShutdown (replayed into ssh.connect at boot — the exact "not found" thrower), sleeping-agent records, provisioned project host setups, sidebar host-scope arrays, and relay pty leases. New ssh-target-id-migration.ts sweeps every carrier in one pass. (SSH worktrees partition into the local session blob — verified via workspace-session-host-split.ts field 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-changed went 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 a sshStateChanged runtime client event emitted from broadcastSshState, new ssh.listTargets / ssh.listRemovedTargetLabels RPC methods (beside the previously unused ssh.getState/ssh.connect), and backed the web preload's listTargets/listRemovedTargetLabels/getState/connect with real runtime RPC. useIpcEvents applies the event through the same guarded path as desktop ssh.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, isolated ORCA_DEV_USER_DATA_PATH, CDP-attached, identity verified as Jinwoo-H/ssh-issues-2. pnpm build:relay before connecting; relay compiled node-pty on the linux-arm64 host.

  • Setup proof: target connected (status: connected, remotePlatform: linux), remote repo /work/demo-project registered, worktree /work/e2e-sta1468 created and confirmed via git worktree list over ssh. Typing in Orca's terminal created /tmp/pty-proof.txt on the container.
  • Gate 1 — re-adoption (PASS): persisted state confirmed holding the old id in all 4 carriers → removed host (tombstone recorded) → re-added same host (new id minted) → app restart: new target auto-reconnected with zero "not found" errors, workspace terminal spawned fresh under the new id, and echo readopt-proof-$(pwd) executed in /work/e2e-sta1468 on the container. Boot log shows the one residual stale pty id hitting the existing belongs to SSH connection recovery marker and spawning fresh (see follow-ups).
  • Gate 3 — overlay convergence (PASS): with the host removed, clicking Connect produced exactly one SSH target not found toast, then the overlay flipped to "SSH host removed" + "Remove workspace" — no loop. (Pre-fix: infinite identical toasts, which is the reporter's screenshot.)
  • Gate 2 — paired web client (PASS): generated a real pairing URL, opened web-index.html#pairing=… in a separate Chromium. Web store hydrated sshTargetLabels (both targets) and sshConnectionStates: connected over the new RPC — previously empty stubs. Host-side ssh.disconnect → web overlay appeared with the friendly label via the sshStateChanged event. 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 executed echo web-client-proof-4 on the remote host.
  • Cleanup: container, temp keys, isolated user-data, and dev processes removed; only this PR's changes remain in the worktree.

Known follow-up gaps (documented, not regressions — both previously unreachable behind the never-clearing overlay)

  • The live renderer's in-memory pty-id maps aren't remapped on re-adoption, so one stale embedded id can persist until next spawn; the reattach path already treats the mismatch as a stale session and spawns fresh (verified in boot logs). A renderer-side remap event would remove the transient throw entirely.
  • A web pane whose bound host session died during an SSH disconnect cycle reattaches to the defunct session instead of respawning (web reload recovers). Same reconnect-desync family as [Bug]: Remote Orca Server issues #7718; noted there.

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 🐋

Jinwoo-H and others added 3 commits July 7, 2026 22:54
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>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5c62cbe9-9ca8-4ec4-891c-fc8a3d8d9b51

📥 Commits

Reviewing files that changed from the base of the PR and between f8eef7d and 1fc5702.

📒 Files selected for processing (7)
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.test.tsx
  • src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.tsx
  • src/renderer/src/store/slices/ssh.test.ts
  • src/renderer/src/store/slices/ssh.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.tsx
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.test.tsx
  • src/main/persistence.ts

📝 Walkthrough

Walkthrough

This 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 sshStateChanged runtime client event, forwards SSH broadcasts from main to runtime clients, and adds SSH target-listing RPC and IPC methods. Renderer updates include SSH metadata hydration tracking, paired-client SSH event routing, refreshed reconnect overlay behavior, and updated web preload SSH calls.

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template sections and omits Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections with a Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main SSH state bridging and target re-adoption work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 523dfb6a-fed8-4371-a076-dbe35c87595d

📥 Commits

Reviewing files that changed from the base of the PR and between 8368e94 and f8eef7d.

📒 Files selected for processing (17)
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/ssh.test.ts
  • src/main/runtime/rpc/methods/ssh.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/ssh/ssh-target-id-migration.test.ts
  • src/main/ssh/ssh-target-id-migration.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.test.tsx
  • src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.tsx
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/runtime/runtime-client-events.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/runtime-client-events.ts

Comment thread src/main/persistence.ts Resolved
- 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>
@Jinwoo-H
Jinwoo-H merged commit 864594f into main Jul 8, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant