You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(ssh): a restore racing a disconnect never leaves a forward behind - #27368
Orca reopens your saved SSH port forwards when a managed host reconnects. If you disconnected or removed that host while Orca was still reopening them, one forward could survive and keep a local port and an SSH login open until Orca quit. Now that forward is closed.
What Changed
Before: Orca restores saved forwards one at a time. Disconnecting or removing a host closes only the forwards that exist at that moment. A forward whose setup finished just after that got registered anyway. With the system SSH transport, setup takes about 750 ms per forward, so the window was real. The leftover was an ssh -L process holding the local port, and a later reconnect treated it as live.
After:
restorePortForwards checks the connection again after each forward is added. If the host disconnected or reconnected meanwhile, it closes the forward it just added and stops.
A queued managed-host restore checks that the host is still managed when it actually runs, not only when it was queued.
Why
Both checks sit where the race happens, so teardown does not need to wait for or cancel an in-flight restore. The alternative was having teardown wait for in-flight restores. That would make every disconnect wait up to a few seconds on forwards being set up. Found by the post-merge review of #27361.
N/A. This is a background race with no visible UI.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Two new unit tests failed before the fix:
a forward whose add completes after the disconnect is closed
a queued managed restore is skipped once the host is no longer managed
pnpm tc, pnpm lint and check:code-quality:changed pass.
Review
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
The relay restore path shares restorePortForwards, so it gets the same guard. There are no wire changes.
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)
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 77369889-2031-401c-a033-0e742daf0d70
📥 Commits
Reviewing files that changed from the base of the PR and between 5f350a3 and c78e0a7.
📒 Files selected for processing (3)
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
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
📝 Walkthrough
Walkthrough
The restore flow now removes a forward if the target connection changes while the forward is added. Queued restores now skip hosts that are no longer managed. Tests cover both asynchronous race conditions and update the port-forward manager mock.
Priority: ⬇️ Low
Merge Risk:⚪ Minimal · up to c78e0
The changed restore paths address the identified disconnect and host-removal races. No concrete merge-blocking issue remains after normal checks.
Pre-merge checks | 4 | 1
❌ Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name
Status
Explanation
Title check
The title clearly and concisely describes the primary fix: preventing SSH port forwards from remaining after a restore races with disconnect.
Description check
The description is complete and focused. It explains the user impact, technical changes, rationale, tests, visual-proof exception, and checklist items. It does not report manual testing and does not e…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Orca reopens your saved SSH port forwards when a managed host reconnects. If you disconnected or removed that host while Orca was still reopening them, one forward could survive and keep a local port and an SSH login open until Orca quit. Now that forward is closed.
What Changed
Before: Orca restores saved forwards one at a time. Disconnecting or removing a host closes only the forwards that exist at that moment. A forward whose setup finished just after that got registered anyway. With the system SSH transport, setup takes about 750 ms per forward, so the window was real. The leftover was an
ssh -Lprocess holding the local port, and a later reconnect treated it as live.After:
restorePortForwardschecks the connection again after each forward is added. If the host disconnected or reconnected meanwhile, it closes the forward it just added and stops.Why
Both checks sit where the race happens, so teardown does not need to wait for or cancel an in-flight restore. The alternative was having teardown wait for in-flight restores. That would make every disconnect wait up to a few seconds on forwards being set up. Found by the post-merge review of #27361.
Linked Issue
N/A (maintainer). Follow-up to #27361.
Visual Proof
N/A. This is a background race with no visible UI.
Testing
Two new unit tests failed before the fix:
pnpm tc,pnpm lintandcheck:code-quality:changedpass.Review
Agent skill upstream boundary
Notes
The relay restore path shares
restorePortForwards, so it gets the same guard. There are no wire changes.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)