Skip to content

fix(ssh): a tab closed while a managed host is disconnected stays closed; deflake the shared-home spec - #30146

Merged
nwparker merged 3 commits into
mainfrom
nwparker/fix-close-while-disconnected
Oct 18, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/fix-close-while-disconnected

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you disconnect an SSH machine, close a terminal tab, and connect again, the tab should stay closed. Since #30130 it came back. This puts it back to staying closed.

What Changed

Before: Disconnect an SSH host that runs a managed Orca server, close one of its terminal tabs, then Connect. The closed tab reappears.

After: The tab stays closed. Orca remembers the close and sends it to the host as soon as the host is reachable again, which is what it already did when a connection simply dropped.

Mechanism. This is a regression from #30130 ("a Disconnect stays disconnected"). That PR made a user's Disconnect also mark the host's managed server as manually disconnected, so the desktop now answers every call to that server itself with runtime_manually_disconnected, without contacting the host. The tab close path (web-runtime-session-tab-lifecycle.ts) keeps a close it could not deliver and replays it after reconnect, but only for a fixed set of "never reached the host" error codes. runtime_manually_disconnected was not in that set, so the close was treated as an answer from the host: the close was thrown away, and the host's next snapshot after reconnect brought the tab back. The fix adds that code to the "undelivered" set.

The journey spec. ssh-orcad-terminal-journeys.spec.ts closed the tab with the store's bare closeTab. That path only sends terminal.close and holds nothing, so it passed only because the disconnected host used to be redialed in the background, which is exactly what #30130 stopped (the CI log shows runtimeEnvironments:call: ... was disconnected. Connect to use it again.). The spec now clicks the tab's X, the path every user close goes through (closeTerminalTab → closeWebRuntimeSessionTab). That path still fails without the fix above, because it drops the close on runtime_manually_disconnected.

CI path filter. The "ssh on managed orcad (Docker)" lane would have caught this, but it was skipped on #30130 because none of #30130's files were routed to it. The managed-journeys route in config/scripts/pr-e2e-source-routing.mjs now also covers the Connect/Disconnect sources (src/main/ipc/ssh-connect-flow.ts, ssh-connection-handlers.ts, ssh-host-user-disconnect.ts, ssh-session-teardown.ts, runtime-environment-connectivity-handlers.ts, runtime-environment-manual-disconnect.ts, src/main/ssh/ssh-connection-manager.ts, ssh-user-disconnect.ts) and the renderer close-intent/replay modules (web-session-close-*). The route contract test pins all of them. verify / "PR checks passed" is unchanged.

Second, separate cause: a flaky check in ssh-orcad-shared-home-machines.spec.ts:47 (test-only, folded in from #30147). The Docker 2/2 lane runs both specs, so neither fix can show a green lane alone. The two Docker SSH hosts share /root, but each has its own PID namespace. The spec's "B never launched into A's slots" check read the PID that A recorded in the login-home slot and ran kill -0 on B. That PID (229 on both failing runs) can be a live, unrelated process on B. The spec now counts a recorded PID only when that process's command line names its slot directory. Every managed server starts as nohup <runtime> <slot dir>/<launcher> ..., so the check keeps its intent: a server B really launched from A's slot would still fail it. This is not a product regression: none of the PRs after 299dcb86fc8a touch the managed deploy, and the spec passed on both bisect probes.

Why

#30130's intent stays as it is: a Disconnect still stays disconnected, and nothing redials the host. The local refusal really does mean the close never reached the host, so treating it like any other undelivered close is accurate, and it reuses the existing hold-and-replay path (STA-6224) instead of adding a new one. I considered two alternatives. Exempting tab closes from the manual-disconnect refusal would redial the host, which is exactly the loop #30130 removed. Reverting #30130's server-side marking would bring back #30086/#30085.

Linked Issue

Regression from #30130. It fixes the failing tests/e2e/ssh-orcad-terminal-journeys.spec.ts:119 on main. It also fixes the flaky ssh-orcad-shared-home-machines.spec.ts:47, which has a test-only cause and supersedes #30147.

Visual Proof

N/A: no UI change. A closed tab now stays closed, and the e2e spec checks that.

Testing

  • New unit test holds a user close made while the host is disconnected in src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.ts. It fails without the fix and passes with it.

  • Route contract test extended (config/scripts/pr-e2e-route-contracts.test.mjs).

  • Bisect evidence: the Docker 2/2 lane fails ssh-orcad-terminal-journeys.spec.ts:119 at 27cfee6f7ea2 (main up to and including fix(ssh): a Disconnect stays disconnected, and Settings and the status bar agree #30130, probe ci: probe managed-orcad Docker e2e at 27cfee6f7ea2 (bisect) — do not merge #30139) and passes at 7f4243ed1c3d (before the stack).

  • End to end: the managed-orcad Docker lane on this PR runs the real journey (disconnect, close, reconnect, relaunch) against a Docker SSH host. Nothing beyond that and the unit tests was verified live.

  • Shared-home predicate: checked on a real Linux host (omarchy, isolated under /tmp). A slot file holding a live PID whose process runs from another slot is excluded, and a process running from its own slot is still matched. The Docker lane on test(e2e): the shared-home spec tells a host's own server from a PID that only collides #30147 passed this spec, including the checks after line 81.

  • Local: full static-analysis steps, pnpm tc, unit folders src/renderer/src/runtime, hooks, lib, components/{automations,tab-group,terminal}, single worker.

  • I manually tested these changes locally

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

AI Disclosure

Review

Codex review (gpt-6.1-sol, high): no findings.

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: this is SSH-only behaviour. Wire compatibility is unaffected because nothing new goes over the wire. The same applies to a paired server the user disconnected from Settings: a close made while it is disconnected is replayed on Connect.

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)

…sed 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.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The managed-SSH route matcher and contract test now include additional SSH connection, disconnect, session-teardown, terminal, workspace, and web-session close sources. The runtime tab lifecycle logic treats runtime_manually_disconnected as an undelivered close failure. Tests check that the close returns failed, its intent remains pending, and the tab is queued for replay. The E2E test closes the disconnected tab through its visible close button. The shared-home E2E helper verifies that a recorded PID belongs to the directory associated with its PID file.

Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: 🔵 Low · up to bd63d

A future routing regression could silently skip the managed-SSH journeys for session-teardown changes. Adding this source to the route contract is a small follow-up; otherwise, no unresolved behavior risk is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the user impact, mechanism, rationale, testing, visual proof, and checklist. However, the Linked Issue section does not provide an actual issue link or a `Fixes … Add the actual issue reference in the Linked Issue section, preferably using Fixes #<issue-number>, and retain the relevant pull request references as supporting context.
Passed Passed checks: 4 passed
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 6 files.
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.
Title check Passed The title clearly identifies both main changes: the SSH tab-close fix and the shared-home test deflake.
Full details: Description check

Explanation

The description is detailed and covers the user impact, mechanism, rationale, testing, visual proof, and checklist. However, the Linked Issue section does not provide an actual issue link or a Fixes #... reference as required by the template; it only references pull requests and test failures.

Resolution

Add the actual issue reference in the Linked Issue section, preferably using Fixes #&lt;issue-number&gt;, and retain the relevant pull request references as supporting context.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 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.

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.
…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.
@nwparker nwparker changed the title fix(ssh): a tab closed while a managed host is disconnected stays closed after Connect fix(ssh): a tab closed while a managed host is disconnected stays closed; deflake the shared-home spec Oct 18, 2026

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

🧹 Nitpick comments: 1
config/scripts/pr-e2e-route-contracts.test.mjs: 1

478-497: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add src/main/ipc/ssh-session-teardown.ts to the route contract.

The managed-SSH matcher routes this source to all three journey specs, but the contract test does not include it in expectRouted. Removing the matcher branch would therefore leave this test passing while changes to session teardown could stop selecting the journeys.

Suggested fix
           // #30130's Disconnect sources merged with this lane skipped.
           'src/main/ipc/ssh-host-user-disconnect.ts',
+          'src/main/ipc/ssh-session-teardown.ts',
           'src/main/ipc/ssh-connect-flow.ts',

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4112bd77-45fd-4b9a-a44a-c05b56b6f9fb
📥 Commits

Reviewing files that changed from the base of the PR and between dcc6f2e and bd63ddc.

📒 Files selected for processing: 1
  • tests/e2e/ssh-orcad-shared-home-machines.spec.ts

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

@nwparker
nwparker merged commit 1b3113d into main Oct 18, 2026
80 of 81 checks passed
nwparker added a commit that referenced this pull request Oct 18, 2026
…callers' policy (#30246)

Each list that decides delivered / undelivered / recoverable / definitive by code now has a
test naming its codes, the message fragments it relies on, and nearby codes it must not
treat the same. Includes the #30146 shape: a client-minted runtime_manually_disconnected
keeps a user's close for replay. Tests only; no production change.
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