Skip to content

fix(ssh): Move to managed server keeps the host's terminal tabs - #26077

Merged
OrcaWin merged 2 commits into
OrcaWin/node-rt-phase3from
OrcaWin/move-restores-tabs
Oct 7, 2026
Merged

OrcaWin merged 2 commits into
OrcaWin/node-rt-phase3from
OrcaWin/move-restores-tabs

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​331 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​328
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​186 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169

ELI5

When you move an SSH host to its managed Orca server, Orca warns that the host's open terminals will restart. They were supposed to come back. Instead most of them vanished: the host ended up with one terminal, or a new default one, and a leftover pane showed "SSH connection is not active…" until you clicked the workspace again. Now every terminal tab comes back on the managed server.

What Changed

Before (from the Phase 5 real-host test): the host had two relay terminals, Terminal 1 and Terminal 2. After Move to managed server, only Terminal 1 came back on the server. Terminal 2 was gone. The open workspace still showed the old Terminal 1 pane, now dead, with "SSH connection is not active…". The local terminal list still reported the stopped relay shell as connected.

After: all the host's terminal tabs stay open through the move. The conversion copies them to the server, which starts each one as a fresh shell with the same layout. The open workspace switches to the server copy as soon as the server's lists load, so no dead SSH pane is left behind. terminal list stops calling a stopped relay shell connected.

Mechanism:

  • Tabs closing (root cause). The move stops the relay shells first. Each exit was treated as the shell simply ending. Main took the terminal out of the saved SSH session, and the renderer closed the tab like a user exit. Both happened before the conversion copied the host's workspace session to the server, so only tabs whose exit happened to be lost made it across. (When a relay's last shell stops, the relay hangs up before it sends that exit. That is why one tab survived, and why another rerun saw 1 of 2.)
    • Now, right before each shutdown, the move registers exactly that shell (with its incarnation) as a replaced stop in main's existing intentional-stop register. That is the same register restarts use. Main then keeps the terminal in the saved session, and the exit reaches every viewer labeled as a restart, so mounted, parked and unmounted tabs all stay open. A death the relay confirms is still recorded as exited.
    • Exits that land before a shell's stop is registered are not covered, so a user's own exit still closes its tab.
    • If the host moves, the server owns the tabs. If it stays on the relay (refused, or stayed), Move returns the shells it actually stopped. That list includes shells stopped before a later stop failed. The renderer restarts only those tabs and first discards any buffered exit, so a parked tab doesn't close when it's revealed.
  • Stale pane. After a conversion, the open workspace still pointed at the host's SSH rows, which the conversion drops. Its panes kept dialing the stopped relay until you selected the workspace again. Once the server's lists load, the open workspace now moves to the same workspace on the server, using the same setActiveWorktree a click uses. It does not change the current view, because Move is usually clicked from Settings.
  • terminal list connected. terminateSshTargetSessions now tells the runtime about each shell it stopped, unless the runtime already has a real exit for it. Because the lost exit never arrived, the runtime kept that record connected. The report uses the stop sentinel (-1), so the verdict reads unverifiable, never a certified death (docs/reference/ssh-execution-boundary.md). The relay accepting a kill is not an observed exit.

Why

The move already promised a restart, and the conversion already carries the host's tabs to the server. The tabs were simply gone by the time it read them. Keeping them open at the source fixes the cause, using a suppression mechanism every exit path already honors.

Alternatives I rejected:

  • Suppressing the exits only in the window that started the move. That was the first version of this PR. It left main retiring the saved tab, left other windows unprotected, and swallowed real exits for the whole request.
  • Rebuilding the tabs on the server from a list kept before the move. That would mean a second copy of the session-migration logic.

There is no wire change, so mixed client and server versions are unaffected.

Not in this PR: a migrated tab's title. The server publishes a live shell's title as "Terminal", so a restored "Terminal 1" shows as "Terminal". That is general server behavior for any restored tab, not specific to the move. Changing what the server publishes reaches old clients, so it belongs in its own change.

Linked Issue

Phase 5 real-host test findings P5-3 and P5-4 (rollout plan for the node runtime, Phase 3).

Visual Proof

N/A. I could not rerun the packaged two-version upgrade flow for this PR. The behavior is covered by the unit tests below, and the root cause comes from the test's saved profile. That profile's server session held only Terminal 1's id (as web-terminal-<id>), and Terminal 2 was already missing from the SSH session.

Testing

  • pnpm test src/main/ipc/ssh-managed-server-move-stop-retention.test.ts src/renderer/src/components/terminal-pane/terminal-parked-watcher-sleep-preserved-exit.test.ts src/renderer/src/ssh/ssh-managed-server-move-terminal-tabs.test.ts src/renderer/src/hooks/ipc-events/ssh-managed-server-converted-catalogs.test.ts src/renderer/src/hooks/ipc-events/ssh-managed-server-state-effects.test.ts src/main/ipc/ssh-terminate-sessions.test.ts src/main/ipc/ssh-terminate-sessions-previous-relay.test.ts src/main/ipc/ssh-managed-server-move.test.ts src/main/ipc/ssh-managed-server-move-conversion.test.ts passes.

    • New, with a real runtime: a shell the move stops keeps its tab in the saved SSH session through its real exit, and its verdict is still exited. A user exit before the stop closes its tab as always. I checked that this test fails without the register entry.
    • Also new: a host that stays restarts only the tabs whose shells the move stopped, and clears a parked tab's buffered exit. A tab whose shell exited before the stop is never reopened. Shells stopped before a later stop failed are still reported. The open workspace re-homes onto the server, and a workspace on another host is left alone. Terminate reports a lost exit to the runtime as the stop sentinel and keeps an exit that was already reported.
    • I checked that the re-home test fails without the change.
  • pnpm tc, oxlint, and pnpm run check:code-quality:changed pass.

  • I manually tested these changes locally

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

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: a refused move never certifies a shell dead. Unreached shells keep their normal exit handling.
  • Folder workspaces: the re-home looks up the workspace by key on the server host, so folder workspaces are covered too.
  • Platforms: no platform-specific code.

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)

Move stops the relay shells; their exits read as a user exit and closed
the tabs before the conversion copied them to the server. Suppress those
exits for the move, restart stopped shells on the relay when the host
stays, re-home the open workspace onto the server, and report stopped
shells to the runtime so terminal list stops calling them connected.
@OrcaWin
OrcaWin marked this pull request as draft October 7, 2026 05:18
The renderer-only exit suppression left main retiring the stopped tab from
the saved SSH session before the conversion copied it, left other viewers
unprotected, and swallowed real exits for the whole request. Register
exactly the shells the move stops, from just before each shutdown, as a
'replaced' stop with their incarnation; main keeps the surface and labels
the exit for every viewer, while a confirmed death stays 'exited'. Move
now returns the shells it stopped, and a host that stays on the relay
restarts only those tabs, discarding any buffered exit first.
@OrcaWin
OrcaWin marked this pull request as ready for review October 7, 2026 06:21
@OrcaWin
OrcaWin merged commit a2851ff into OrcaWin/node-rt-phase3 Oct 7, 2026
55 of 57 checks passed
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