Skip to content

fix(ssh): a managed tunnel follows the server's port after another desktop restarts it - #30888

Merged
nwparker merged 1 commit into
mainfrom
nwparker/managed-tunnel-follow-host-port
Oct 19, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/managed-tunnel-follow-host-port

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​70 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​38

ELI5

A managed Orca server runs on an SSH host, and this desktop reaches it through a tunnel to the server's port. If a different desktop restarted that server (for example, by updating it) and it came back on a new port, this desktop kept its tunnel pointed at the old port. Every health check then failed with "unverifiable". Now, when the server stops answering through the tunnel, the desktop asks the host which port the server is on now, and moves the tunnel if it changed.

What Changed

  • Before: the tunnel's serving check rebuilt the forward only when this desktop's own check had just started the server (state: 'started' with a new boundPort). If another desktop restarted the server, this desktop's check found a live server process that was not answering on the old port. It reported unverifiable and kept the old forward. Resume recovery hit the same check and stayed unverifiable forever.
  • After: whenever the serving check comes back unverifiable, the tunnel reads the port named in the host's current readiness record, the same record a fresh tunnel build already uses. If that port differs from the forwarded one, the check drops the forward and the tunnel is rebuilt there. verifyServing then answers from the rebuilt tunnel.
  • Port reading is now one reader, readActiveSlotBoundPort, used by both tunnel builds (resolveManagedOrcadTunnelPort) and the new check (readManagedOrcadPublishedPort). The new check returns null when the host names no port (older servers) or cannot be read. null never moves a tunnel.

Why

The host owns the truth about which port its server is bound to; this desktop's own events are only a partial view. Following the host's record covers every way the port can move: another desktop's update, a wake, or a crash restart. It needs no new events or wire messages.

Alternatives considered:

  • Broadcasting restarts between desktops would need a new protocol, and old desktops would still miss it.
  • Re-reading the port on every check would add an SSH round trip to the healthy path. The re-read happens only on the failure path.

Wire compatibility: hosts that do not publish a bound endpoint return null, so the old behavior is kept for them.

Linked Issue

Internal review item (managed SSH tunnel lifecycle, item 6). No GitHub issue.

Visual Proof

N/A: there is no UI change. This is the tunnel's recovery behavior behind the existing managed-server status.

Testing

  • New orcad-managed-tunnel-peer-restart.test.ts. It uses the real forward manager with a fake transport and a host whose server another desktop moves from 6768 to 7001.

    • verifyServing now answers serving with the forward at 7001. On main it answers unverifiable and keeps 6768; this case fails on main.
    • Guard: a host that names no port keeps the tunnel.
    • Guard: a host that still names the forwarded port keeps the tunnel.
  • All src/main/managed-server/lifecycle suites pass. The full static-analysis job was run locally and passes.

  • Not exercised live against two real desktops. The Docker managed-orcad e2e lane covers the surrounding tunnel paths in CI.

  • I manually tested these changes locally

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

Review

  • Codex (gpt-6.1-sol, high): clean on round 1.
  • Independent Opus review: no correctness findings. P3 notes, left as is:
    • The re-read costs one extra SSH read, only on the failure path.
    • If resume or the re-check itself finds a second port move, the forward is dropped. The next ensure rebuilds it, which matches the existing "drop now, rebuild on next ensure" design.

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: lost contact is never treated as a reason to move the tunnel; an unreadable host returns null.
  • Wire: nothing new is exchanged.
  • Folder workspaces: not affected.
  • Cross-platform: this reuses the existing remote readiness read, including on Windows hosts.

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)

…r desktop restarts the server

The tunnel was rebuilt only when this desktop's own check saw the server start. When another
desktop restarted it onto a new port, the old forward stayed and every check answered
unverifiable. A check that finds the server not answering now reads the port the host's
readiness record names and, when it moved, rebuilds the tunnel there.
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: e4c8abe1-c100-432a-a5c0-962d564b871e
📥 Commits

Reviewing files that changed from the base of the PR and between b03ac56 and 923aa11.

📒 Files selected for processing: 5
  • src/main/managed-server/lifecycle/orcad-managed-bound-port.ts
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-manager.ts
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-peer-restart.test.ts
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-serving.ts
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-target.ts

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

📝 Walkthrough

The managed tunnel can now read the active slot’s published port. When serving is unverifiable, the check compares that port with the active tunnel and rebinds if they differ. The manager repeats the serving check after a rebind unless the first result is started. Tests cover changed, missing, and unverifiable published ports.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 923aa

No concrete issue currently prevents merging the managed-tunnel rebinding change. The reported tests cover the main port-change and no-change cases; live two-desktop behavior remains untested.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: making a managed SSH tunnel follow the server's port after a restart on another desktop.
Description check Passed The description is comprehensive and covers the user impact, implementation, rationale, alternatives, compatibility, testing, and checklist items. It includes all template sections. The Linked Issue s…
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.
Full details: Description check

Explanation

The description is comprehensive and covers the user impact, implementation, rationale, alternatives, compatibility, testing, and checklist items. It includes all template sections. The Linked Issue section identifies an internal review item but does not provide a GitHub issue link; this is acceptable only if the contributor is an internal maintainer under the template's special case.

  • 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.

@nwparker
nwparker merged commit 98ee268 into main Oct 19, 2026
52 checks passed
brennanb2025 added a commit that referenced this pull request Oct 20, 2026
…0918)

* fix(ssh): move the managed tunnel's is-current check beside its record (fix red main)

orcad-managed-tunnel-manager.ts reached 301 counted lines when #30891 landed on
#30888, failing every PR's static analysis. The six-field check that the recorded
tunnel already matches the connection and deployment moves, unchanged, into
orcad-managed-tunnel-active.ts, which owns that record.

* style: format the 22 files main merged unformatted (fix red main)

CI's format check fails every PR on these files. Formatting pushes
NativeChatStructuredSession.tsx one line past its 400-line limit, so its one-use
question list is inlined where questionBody is already non-null (identical
behavior: agentSessionPromptQuestions is pure and ran on every render).
nwparker added a commit that referenced this pull request Oct 20, 2026
#30888 and #30891 crossed (#30933)

The build's same-pairing check moves next to managedTunnelAccess, which it already wraps.
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