You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Remote host restoring/spawning terminal tabs that were manually closed #9352
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.
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 sametabs 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.
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.
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.
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..
Activity
shady2k commentedon Jul 18, 2026
This looks like the user-visible symptom of the pair #8878 (duplicate
--resumespawns) and #8871 (mirrorpty-exitkilling 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.logshows the same pane's session recreated with a fresh@@<suffix>~2 min apart, and across the whole day there are almost nosession-attachedevents — i.e. the reattach path rarely fires; nearly every reconnect / re-materialization mints a new session: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 liveremote:<host>@@term_<handle>ptyId — the other 3 hadptyId: 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 localruntime:<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
tabsByWorktreemirror against the host's live-terminal snapshot and dropptyId: nulltabs that aren't in it; (3) suppress the "was explicitly killed" message on the remote transport like the local one does.fix(terminal): prune handle-less phantom mirror tabs on viewers (stab…
shady2k commentedon Jul 18, 2026
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 bumpssnapshotVersionand re-publishes the sametabslist; the dead surface stays, now effectivelypending-handle. SomobileSessionTabsByWorktreeaccumulates 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 everytype === 'terminal'surface regardless of liveness (only'ready'ones get a ptyId), so each dead surface becomes aptyId: nullphantom. Because the host keeps re-publishing them, clearing the viewer's persisted mirror (or the on-diskworkspaceSessionsByHostId[...].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
applyWebSessionTabsSnapshotthat 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.AmethystLiang commentedon Jul 19, 2026
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:
nwparker commentedon Jul 21, 2026
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 perparentTabIdgroup for every terminal surface regardless of liveness; a group whose active surface ispending-handleyieldstab.ptyId === null(:591) withptyIds === [].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 bumpssnapshotVersionand re-publishes the sametabslist, so the dead surface keeps coming back — matching the "auto restore closed tabs" symptom and survival across restart.Re-run:
Key assertion + observed values: two host panes (one
ready→term_live, onepending-handle→terminal:null) are applied, then the same snapshot is re-applied atNOW + 60_000(well past any ~25s window):The phantom is present with
ptyId === nullfrom 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.renatop7 commentedon Jul 21, 2026
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..