Skip to content

[Bug]: Remote host restoring/spawning terminal tabs that were manually closed #9352

Closed

Description

@renatop7

Operating system

macOS

Orca version

v1.4.143

Details

Hi,

Orca keeps auto restoring closed terminal tabs from a Remote host.
Not only spawns the same terminal tab, but try to spawn 3 times the same session

here is a short video:
https://github.com/user-attachments/assets/33c16db5-2fab-4bf5-88c5-6241587264f1

if i visit those tabs i see an empty terminal and an error bottom of the screen:

Session "****" was explicitly killed
If this persists, please [file an issue](https://github.com/stablyai/orca/issues).
Image

Remote Host is a macOS M1 and client is macOS M2

Activity

  1. added theissue type on Jul 18, 2026
  2. shady2k commented on Jul 18, 2026

    @shady2k
    Contributor

    This looks like the user-visible symptom of the pair #8878 (duplicate --resume spawns) and #8871 (mirror pty-exit killing live host sessions). Reproduced on v1.4.146-rc.0 with a host + a second Orca desktop as a viewer over "orca servers" (both macOS) — so it isn't fixed yet.

    Corroborating forensics from a live occurrence:

    Duplicate spawn (→ #8878). The host daemon.log shows the same pane's session recreated with a fresh @@<suffix> ~2 min apart, and across the whole day there are almost no session-attached events — i.e. the reattach path rarely fires; nearly every reconnect / re-materialization mints a new session:

    20:03:57Z session-created  <worktree>@@f3ecb62f   → duplicate TUI
    20:05:55Z session-created  <worktree>@@a3b11f4b   → the live one
    

    Both were claude --resume <same client session id>.

    Phantom tabs persist on the viewer and survive restart (→ this issue). On the viewer, the mirrored tabs live in the client's runtime:<host-env> partition and are never pruned against the host's authoritative live-terminal list. On disk (orca-data.json), workspaceSessionsByHostId/runtime:<host>/tabsByWorktree/<worktree> held 4 terminal tabs, but only 1 had a live remote:<host>@@term_<handle> ptyId — the other 3 had ptyId: null (no backing terminal), including a tab id belonging to a duplicate pane that had already been killed. Meanwhile the host runtime had exactly 1 live terminal for that worktree. A full restart of the viewer re-hydrates all 4 from disk → the phantoms come back, which matches the "auto restore closed tabs" symptom reported here. (This lines up with #8878's root-cause step 3: resume/tab records persist in the local runtime:<env> partition and rehydrate on next boot.)

    The "was explicitly killed" toast leaks specifically on the remote transport: remote-runtime-pty-transport.ts (isRemoteTerminalGoneMessage) doesn't treat that message as a benign "terminal gone", whereas the local transport swallows it (pty-transport.ts). So an intentionally-killed session surfaces the red file-an-issue toast on the viewer instead of retiring quietly.

    Suggested direction (consistent with #8878/#8871): (1) gate client-side resume on host runtime ownership (#9098); (2) reconcile/prune the viewer's tabsByWorktree mirror against the host's live-terminal snapshot and drop ptyId: null tabs that aren't in it; (3) suppress the "was explicitly killed" message on the remote transport like the local one does.

  3. shady2k commented on Jul 18, 2026

    @shady2k
    Contributor

    Following up with the actual root-cause mechanism (this issue still has no linked PR, so posting in case it helps whoever picks it up).

    Why the phantom tabs are un-closable and survive restart: the published session-tabs snapshot never drops a terminal whose PTY exited. A terminal surface has only two client statuses (RuntimeMobileSessionTerminalClientTab, src/shared/runtime-types.ts): 'ready' (live handle) and 'pending-handle' (terminal: null). There is no 'exited' status — when a PTY exits, onPtyExit → touchMobileSessionSnapshotsForPty (src/main/runtime/orca-runtime.ts) only bumps snapshotVersion and re-publishes the same tabs list; the dead surface stays, now effectively pending-handle. So mobileSessionTabsByWorktree accumulates dead terminals and re-publishes them on every change.

    Paired viewers mirror this faithfully: buildMirroredTerminalTabs (src/renderer/src/runtime/web-session-tabs-sync.ts) builds a tab for every type === 'terminal' surface regardless of liveness (only 'ready' ones get a ptyId), so each dead surface becomes a ptyId: null phantom. Because the host keeps re-publishing them, clearing the viewer's persisted mirror (or the on-disk workspaceSessionsByHostId[...].tabsByWorktree) doesn't help — they return on reconnect, and a viewer restart re-hydrates them.

    Observed on a host + paired-viewer setup: the host runtime had 1 live terminal for the worktree while the viewer's mirror had grown to 6 tabs (5 × ptyId: null).

    Proper fix is host-side: on permanent PTY exit, remove the terminal surface from the published snapshot (in/around touchMobileSessionSnapshotsForPty), gated so genuinely resumable/sleeping sessions are kept — the same attribution being worked out in #8871 / #8888. The subtlety is that a plain dead shell and a resumable sleeping agent both end up handle-less, so the gate must distinguish them.

    Interim (viewer-side, field-confirmed): a grace-based prune in applyWebSessionTabsSnapshot that drops a mirror group which stays handle-less past a short window (~25s) removes the phantoms without touching host state — a live terminal readies well within the window, and a reconnect blip can't flash real tabs. Non-destructive; a usable stopgap while the host-side fix lands.

  4. AmethystLiang commented on Jul 19, 2026

    @AmethystLiang
    Contributor

    Duplicate consolidation

    Closing #9423 as a duplicate of this issue.

    Both describe remote / secondary-client behavior where empty or manually closed terminal tabs are restored/respawned incorrectly (often with dead sessions / "Session was explicitly killed"), while the runtime-host machine behaves correctly.

    #9423 also mentions split-group caps and window resize thrash on the secondary client; treat those as additional symptoms of the same remote tab/session restore path if they still reproduce after the restore bug is fixed.

    Related:

  5. nwparker commented on Jul 21, 2026

    @nwparker
    Contributor

    Reproduced on current tree (main-based).

    Added a headless vitest pinning test that drives the REAL viewer-side reconciler applyWebSessionTabsSnapshot (src/renderer/src/runtime/web-session-tabs-sync.ts) and confirms the phantom-tab facet still exists.

    Root cause (confirmed on this tree): buildMirroredTerminalTabs (web-session-tabs-sync.ts:515) emits one mirrored tab per parentTabId group for every terminal surface regardless of liveness; a group whose active surface is pending-handle yields tab.ptyId === null (:591) with ptyIds === []. applyWebSessionTabsSnapshot (:1668) has no grace-based prune, so a group that stays handle-less across re-published snapshots is kept forever. On the host, onPtyExit → touchMobileSessionSnapshotsForPty (src/main/runtime/orca-runtime.ts) only bumps snapshotVersion and re-publishes the same tabs list, so the dead surface keeps coming back — matching the "auto restore closed tabs" symptom and survival across restart.

    Re-run:

    pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/runtime/repro-9352-phantom-mirror-tabs.test.ts
    

    Key assertion + observed values: two host panes (one ready → term_live, one pending-handle → terminal:null) are applied, then the same snapshot is re-applied at NOW + 60_000 (well past any ~25s window):

    expect(liveTab.ptyId).toBe('remote:web-env-1@@term_live')   // live sibling OK
    expect(phantomSecond.ptyId).toBeNull()                      // still a phantom after 60s
    expect(secondTabs.map(t => t.id).sort())
      .toEqual([<host-tab-1 surface>, <host-tab-2 surface>].sort())  // both retained
    

    The phantom is present with ptyId === null from the first reconcile and is never dropped.

    A fix would change this: the interim viewer-side prune (drop a mirror group that stays handle-less past ~25s in applyWebSessionTabsSnapshot) or the host-side removal of the surface from the published snapshot on permanent PTY exit would drop the phantom — flipping the final assertion. Scope note: this test pins only the phantom-tab facet; the "Session was explicitly killed" toast leak on the remote transport is not exercised.

  6. added
    has_reproConclusive reproduction exists (test/script/CLI evidence). See docs/bug-reproductions/
    on Jul 21, 2026
  7. renatop7 commented on Jul 21, 2026

    @renatop7
    Author

    Just to add to this, I don't know if it's related, but I recently had bad connection with my internet and this got even worse.. it was spawning even more terminals..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghas_reproConclusive reproduction exists (test/script/CLI evidence). See docs/bug-reproductions/os:macosIssues affecting macOS

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions