Skip to content

fix(ssh): restore saved port forwards on managed hosts and show their Ports tab - #27361

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/blk2-ports
Oct 11, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/blk2-ports

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​237 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​229
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​93

ELI5

If you forward a port from an SSH host that runs a managed Orca server, the forward now comes back after the host reconnects. And the Ports tab now appears for workspaces on those hosts.

What Changed

Saved port forwards after a reconnect

  • Before: on a host served by a managed Orca server, a saved forward never came back after a disconnect and reconnect, or after the link dropped and recovered. The local port stayed open but reached nothing, because the old listener still tunneled through the dead SSH connection. Only the relay session's connect handler ever restored forwards, and managed hosts have no relay session.
  • After: every managed connect, and every time a managed host's SSH link recovers on its own, re-creates the saved forwards. Disconnecting or removing a managed host also closes its local listeners.
  • Mechanism:
    • Each ssh2 forward can now say whether it still tunnels through the connection's current SSH client.
    • Restoring first closes forwards that point at a replaced client, then re-adds only the saved forwards that are not already live, so running it twice changes nothing.
    • On a managed host, restore runs from the managed connect publish and from the "transport connected again" state change. Overlapping runs for one host are queued.
    • The relay path uses the same restore, so a relay reconnect also stops leaving a dead listener on the port.

Ports tab

  • Before: the tab showed only when the workspace's repo had a direct SSH connection, so managed-server workspaces never showed it, even though the panel already scans the workspace's own host (fix(ports): the ports panel scans and stops on the workspace's own host #27258).
  • After: the tab follows the workspace owner. It shows for direct SSH workspaces, SSH targets behind a paired server, and workspaces on a managed server reached over SSH. It stays hidden for local workspaces and for paired servers that are not SSH hosts. This also covers folder workspaces on those hosts.

Why

  • Retiring the relay depends on this: with the relay gone, nothing restores forwards at all.
  • Restore lives on the connect and recovery paths every managed host already goes through, not in relay code. Making it idempotent means repeated "connected" notifications can't double-bind a port, and a forward that is still live keeps its id.
  • The tab reuses the owner resolution the panel already uses, so the tab and the panel agree on the host.

Linked Issue

N/A (maintainer). Found by the managed-host e2e lane (#27323).

Visual Proof

N/A: the Ports tab already exists; it now also appears for managed-server workspaces. The forward behavior is covered by the e2e spec below.

Testing

  • New unit tests: stale forward detection, restore that closes stale forwards and skips live ones, queued managed restores, the managed connect and transport-recovery triggers, and listener cleanup on a managed disconnect. Also tab visibility by owner kind.

  • tests/e2e/ssh-orcad-workspace-tools.spec.ts: the "SSH forward reaches it across a reconnect" case is no longer fixme and runs in the orcad-journeys-docker lane.

  • pnpm tc, pnpm lint, check:code-quality:changed, and focused main ssh/ipc suites pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

P0/P1 self review: none found.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

SSH-only change. Nothing new crosses the wire; this is local listener management on the client.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

Managed-host port forwards now restore during connection publication and eligible reconnects. Restoration closes stale forwards and skips forwards that remain live. Right-sidebar SSH-only item visibility now follows whether the workspace owner reaches an SSH host.


Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: 🟡 Moderate · up to 26412

Disconnecting a managed host can leave a restored local port listener open. Coordinate restoration with teardown before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 18 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes both primary changes: restoring saved SSH port forwards on managed hosts and showing the Ports tab.
Description check Passed The description includes all template sections, explains the user-facing behavior and implementation, links the issue context, documents testing, and completes the checklist. The visual proof is marke…
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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d778876-68f8-4a7f-b025-520a9841801e
📥 Commits

Reviewing files that changed from the base of the PR and between 73575f4 and 2641273.

📒 Files selected for processing (18)
  • src/main/ipc/ssh-connection-state-callbacks.ts
  • src/main/ipc/ssh-host-server-connect.ts
  • src/main/ipc/ssh-managed-host-port-forward-lifecycle.test.ts
  • src/main/ipc/ssh-managed-port-forward-restore.ts
  • src/main/ipc/ssh-port-forward-persistence.ts
  • src/main/ipc/ssh-port-forward-restore.test.ts
  • src/main/ipc/ssh-session-teardown.ts
  • src/main/ssh/ssh-port-forward-provider.ts
  • src/main/ssh/ssh-port-forward.test.ts
  • src/main/ssh/ssh-port-forward.ts
  • src/main/ssh/ssh2-port-forward-provider.ts
  • src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx
  • src/renderer/src/components/right-sidebar/ports-panel-host.test.ts
  • src/renderer/src/components/right-sidebar/ports-panel-host.ts
  • src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.test.ts
  • src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.ts
  • src/renderer/src/components/right-sidebar/use-right-sidebar-activity-items.ts
  • tests/e2e/ssh-orcad-workspace-tools.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +13 to +15
const previous = restoring.get(targetId) ?? Promise.resolve()
const next = previous
.then(() => restorePortForwards(targetId, getCurrentMainWindow))

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect connection retention and the disconnect, restore, and listener-removal paths.
rg -n -C 5 --type ts 'getConnection\s*\(|async disconnect\s*\(|disconnect\s*\(targetId|removeAllForwards\s*\(|restoreManagedHostPortForwards\s*\(' src/main/ssh src/main/ipc

Repository: stablyai/orca

Length of output: 41817


🏁 Script executed:

set -e
nl -ba src/main/ipc/ssh-managed-port-forward-restore.ts
nl -ba src/main/ipc/ssh-port-forward-persistence.ts
nl -ba src/main/ipc/ssh-session-teardown.ts | sed -n '1,125p'
nl -ba src/main/ssh/ssh-connection-manager.ts | sed -n '1,125p'
rg -n -C 8 --type ts 'setSshHostServerStatus|disconnectRegisteredSshTarget|teardownSshTargetTransport|restoreManagedHostPortForwards' src/main/ipc src/main/ssh

Repository: stablyai/orca

Length of output: 42228


Cancel or fence queued restoration during managed-host teardown.

disconnectRegisteredSshTarget clears managed status, but it does not cancel an already queued restoration. teardownSshTargetTransport starts connectionManager.disconnect(targetId) concurrently with removeAllForwards(targetId). The connection remains registered until conn.disconnect() completes, so restorePortForwards can pass its identity check and add a listener after removeAllForwards has taken its snapshot.

Coordinate restoration with teardown, or recheck the lifecycle state immediately before each addForward call.

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