Skip to content

fix(ssh): a Disconnect stays disconnected, and Settings and the status bar agree - #30130

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ssh-user-disconnect-block
Oct 17, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ssh-user-disconnect-block

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​314 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​313
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​226 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​213

ELI5

When you press Disconnect on an SSH host, it now stays disconnected until you press Connect. And pressing Disconnect in Settings or in the status bar now does the same thing, so both places always say the same.

What Changed

Before

After

  • Either Disconnect takes down both the SSH connection and the server reached through it. Both surfaces show Disconnected and stay that way through status checks, census, sleep/wake recovery, and automatic pane or automation restores.
  • Either Connect (Settings, the status bar, a terminal's reconnect button) brings both back. The status bar's Connect goes through the host's own connect, so the host's managed-server status and its saved port forwards come back too.
  • Test in Settings still works on a disconnected host and leaves it disconnected.

Mechanism

  • New src/main/ssh/ssh-user-disconnect.ts: a per-session record of hosts the user disconnected, next to the existing "sign-in cancelled" record from fix(ssh): a password SSH host waits for you at launch instead of prompting #30025. SshConnectionManager.connect refuses a dial to a recorded host before it reuses or opens a transport. A connection test passes { probe: true } to bypass it. Automatic ssh:connect calls fail fast without publishing an error state.
  • New src/main/ipc/ssh-host-user-disconnect.ts ties the SSH host to the servers reached through it (a managed server, or a paired server with SSH access). ssh:disconnect records the host and marks those servers manually disconnected, which already stops their status checks. The status bar's runtimeEnvironments:disconnect of a managed server also disconnects its SSH host. An explicit SSH connect clears both and restarts the servers' status checks after the connect finishes. The teardown claims the host's lifecycle before its first await, so a Connect clicked right after Disconnect is not undone.
  • Only explicit user actions clear the record: a non-automatic ssh:connect, runtimeEnvironments:connect, or Test (Test only bypasses it). Internal teardowns that use disconnectRegisteredSshTarget (conversion, ephemeral VMs) do not set it.

Why

  • fix(ssh): a Disconnect or Remove during a background connect sticks #29918 fixed only a Disconnect that landed while a connect was still running. The rest of the loop came from this: managed SSH hosts had no "the user disconnected this" record, though paired servers did. So runtime-environment-status-owner → resolveManagedRuntimeEnvironment → ensureOrcadManagedTunnel → connectionManager.connect dialed the host again after a finished Disconnect.
  • I put the check inside SshConnectionManager.connect, where fix(ssh): a password SSH host waits for you at launch instead of prompting #30025 put the sign-in block. Every background dial goes through that call, so one check covers all of them. Guarding each caller separately would miss the next one someone adds.
  • The record lasts for the session only, not across restarts. A paired server's manual disconnect is already session-only. The two halves of one machine must be forgotten at the same time, or they would disagree again after a restart. Saving it to disk would also add a store field and a case of "why won't my host connect after I restarted?"
  • Settings and the status bar still read their usual stores (SSH connection state and runtime status). Both are now set by the same Disconnect and cleared by the same Connect in main, so they cannot drift. I did not rewrite either surface to read the other's store. That would be a larger renderer change and would not stop background dials.
  • Nothing changes on the wire. All of this is desktop main-process state. Nothing new is published to paired clients.

Linked Issue

Fixes #30086
Fixes #30085

Visual Proof

Managed host on a real Linux machine (omarchy), isolated as described under Testing.

Settings Disconnect, then a server status read (#30086). Before: the host connects again by itself.
main-settings-poke.png
After: still Disconnected, and the status bar shows 0 hosts.
fix-settings-poke.png

Status bar Disconnect, then open Settings (#30085). Before: the status bar shows 0 hosts but Settings shows Connected.
main-sb-settings.png
After: both show disconnected.
fix-sb-settings.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Verified live (macOS dev build with its own HOME and userData, launched in the background and driven over CDP; the SSH host was omarchy Linux through a user-level sshd on a free port with a throwaway remote HOME and a fresh test key, reached through a private ssh -L tunnel; a real managed orcad was deployed into that throwaway HOME):

  • On main: Disconnect in Settings, then a server status read → the SSH host connected again ([Bug]: Manually disconnecting an SSH host triggers immediate automatic reconnection loop #30086 reproduced). Disconnect in the status bar → Settings still said Connected ([Bug]: Connection state desync between Settings > SSH Hosts and Status Bar popover #30085 reproduced).
  • With this branch: Disconnect in Settings → both surfaces disconnected for 90 s of polling, plus a forced status read, plus 60 s more; the remote sshd had 0 connections. Settings Connect → both connected and verified within 3 s.
  • Status bar Disconnect → Settings shows Disconnected; status bar Connect → both connected; a saved port forward (local 24599) was released on Disconnect and listening again after Connect, and the host's managed status was republished.
  • Disconnect followed at once by Connect → both ended connected.
  • Test on a disconnected host → it stayed disconnected.

Only in tests: the sign-in-block interplay, automation restore, the terminal pane's automatic connect, and paired (non-managed) servers with SSH access.

Tests (each new test fails on main): ssh-host-user-disconnect.test.ts (automatic connect refused, server status checks stopped, explicit Connect lifts both, Test leaves it disconnected, Disconnect immediately followed by Connect), runtime-environment-managed-host-disconnect.test.ts (status bar Disconnect also disconnects the managed host; Connect goes through the host's connect), and ssh-connection-manager.test.ts (background dial refused before reuse; probe allowed). Local: the full static-analysis job steps, pnpm tc, and src/main/ipc, src/main/ssh and src/main/runtime/rpc/methods run single-worker. The one failure, pty-launch-race-parity.test.ts, also fails on main.

Review

Codex (gpt-6.1-sol, high) found three real issues over three rounds, and all are fixed. (1) Disconnect cleanup could re-mark a server after a fast Connect, so the lifecycle is now claimed before any await. (2) A test's transport could be reused by a background dial, so the check now runs before reuse. (3) The status bar's Connect did not restore the managed verdict and port forwards, so it now goes through the host's connect. The final round found nothing.

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

Cross-platform: main-process state only, with no paths or processes. SSH: the change is all about SSH hosts. A Disconnect is a user verdict, not a liveness claim, and nothing here reports a remote process as live or exited. Mobile and paired clients: nothing new on the wire.

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)

…s bar agree

A user's Disconnect of an SSH host is now recorded for the session, and background
dials (a managed server's tunnel and status checks, census, host-resume recovery,
pane and automation restores) refuse it until an explicit Connect. Disconnecting a
managed host from Settings also stops its server's status checks, and the status
bar's Disconnect of a managed server also disconnects the SSH host it runs on, so
both surfaces read the same verdict.

Fixes #30086
Fixes #30085
@coderabbitai

coderabbitai Bot commented Oct 17, 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: 44ee4e31-36d9-41f5-a647-4b3be4d9d81b
📥 Commits

Reviewing files that changed from the base of the PR and between 965f881 and 2d32c26.

📒 Files selected for processing: 11
  • src/main/ipc/runtime-environment-connectivity-handlers.ts
  • src/main/ipc/runtime-environment-managed-host-disconnect.test.ts
  • src/main/ipc/ssh-app-shutdown.test.ts
  • src/main/ipc/ssh-connect-flow.ts
  • src/main/ipc/ssh-connection-handlers.ts
  • src/main/ipc/ssh-host-user-disconnect.test.ts
  • src/main/ipc/ssh-host-user-disconnect.ts
  • src/main/ipc/ssh.ts
  • src/main/ssh/ssh-connection-manager.test.ts
  • src/main/ssh/ssh-connection-manager.ts
  • src/main/ssh/ssh-user-disconnect.ts

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

📝 Walkthrough

The change adds in-memory tracking for user-disconnected SSH targets and blocks automatic SSH connects while that state is set. SSH and runtime-environment disconnect handlers now coordinate target teardown, transport invalidation, and manual-disconnect state. Explicit connects lift disconnect state and resume eligible status checks. Connection-test probes use a separate option that permits probing while a target remains marked disconnected.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2d32c

No actionable disconnect or reconnect issue remains; the change is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 11 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 SSH disconnect behavior change and the synchronization between Settings and the status bar.
Description check Passed The description follows the required template and provides a clear user-facing summary, implementation details, linked issues, visual proof, testing evidence, known test failure, and checklist coverag…
Linked Issues check Passed The changes meet the coding requirements in #30086 and #30085. SshConnectionManager.connect rejects automatic dials for recorded user disconnects before transport reuse. Probe connections bypass thi…
Out of Scope Changes check Passed The changes stay within the linked issue scope. The new session-only disconnect record, lifecycle coordination, manager guard, handler updates, teardown behavior, and focused tests directly support re…
Full details: Description check

Explanation

The description follows the required template and provides a clear user-facing summary, implementation details, linked issues, visual proof, testing evidence, known test failure, and checklist coverage.

Full details: Linked Issues check

Explanation

The changes meet the coding requirements in #30086 and #30085. SshConnectionManager.connect rejects automatic dials for recorded user disconnects before transport reuse. Probe connections bypass this guard. disconnectSshHostForUser records the host and marks reached runtime environments manually disconnected. Explicit host or environment connects clear the records and resume status checks after connection. The handlers route Settings and status-bar disconnects through this coordination. Added tests cover automatic reconnect rejection, status-check invalidation, explicit reconnect, probe behavior, race handling, and status-bar coordination.

Full details: Out of Scope Changes check

Explanation

The changes stay within the linked issue scope. The new session-only disconnect record, lifecycle coordination, manager guard, handler updates, teardown behavior, and focused tests directly support reconnect suppression and synchronization for SSH hosts and associated runtime environments. The test reset changes and probe option support the same behavior. No unrelated product behavior or wire protocol changes are shown.

  • 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 27cfee6 into main Oct 17, 2026
31 checks passed
nwparker added a commit that referenced this pull request Oct 18, 2026
The journey called the store's bare closeTab, which sends only terminal.close
and holds nothing; it passed only because the disconnected host used to be
redialed in the background, which #30130 stopped. Click the tab's X instead,
the path that holds and replays an undelivered close.
nwparker added a commit that referenced this pull request Oct 18, 2026
…sed; deflake the shared-home spec (#30146)

* fix(ssh): a tab closed while a managed host is disconnected stays closed after Connect

#30130 made a user's Disconnect mark the host's managed server manually
disconnected, so the desktop now answers its calls itself with
runtime_manually_disconnected. The tab close path read that as the host's
answer and dropped the close instead of holding it for replay, so the tab
came back on reconnect. Treat it as an undelivered close, and route the
Disconnect sources to the managed-orcad Docker lane.

* test(e2e): close the disconnected host's tab the way a user does

The journey called the store's bare closeTab, which sends only terminal.close
and holds nothing; it passed only because the disconnected host used to be
redialed in the background, which #30130 stopped. Click the tab's X instead,
the path that holds and replays an undelivered close.

* test(e2e): the shared-home spec tells a host's own server from a PID that only collides

Each Docker host has its own PID namespace, so the PID host A records in the
login-home slot can belong to an unrelated live process on host B; kill -0
alone then read it as B running from A's slot. Count a recorded PID only when
its process runs from that slot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant