Repository navigation
Description
Summary
When a terminal session is killed on a remote (SSH) host, Orca leaves the tab in the tab strip. The tab is orphaned: opening it shows a blank pane with Session "<id>" was explicitly killed. These dead tabs are not listed by orca terminal list (live-only), so there is no orca terminal close handle to remove them, and they inflate the workspace's tab/agent count badge in the sidebar.
Most importantly: closing a phantom tab with × does not stick. Opening a new terminal in the same workspace re-materializes the dead tabs. This indicates the orphaned tab references are written to the workspace's persisted terminal/layout state and rehydrated on terminal-panel init — not just transient UI. There is no way (UI or CLI) to permanently remove them short of editing persisted state or reloading/restarting the app.
Environment
- Orca app running on: macOS (MacBook Pro), local macOS user account
- Connected via Orca SSH connect to a remote host (Mac mini) with a separate macOS user account
- Workspace: a git-managed worktree on the remote host
- Multiple terminal tabs open across the SSH-connected workspace
- (Local runtime/session identifiers omitted; available on request if needed for debugging.)
What happened
Five terminal tabs (each showing a Claude Code task title) stayed in the tab strip after their backing sessions had already been killed. Opening any of them shows only:
Session "serve-<uuid>" was explicitly killed.
If this persists, please file an issue.
(actual session UUID redacted; the serve-<uuid> naming pattern is the relevant detail)
The sidebar workspace badge counted these dead tabs (showed +8), making it look like ~8–9 agents/terminals were running when only 2 live claude processes actually existed.
Steps to reproduce (observed conditions; exact kill trigger not confirmed)
- From the Orca desktop app, use SSH connect to a remote host and open a workspace there.
- Open several terminal tabs running agents in that remote workspace.
- Have the backing session(s) get killed (e.g. SSH/runtime interruption, or the
serve-*session being explicitly killed). - Observe that the tabs remain in the tab strip.
- Close a phantom tab with
×, then open a new terminal in the same workspace. - Observe the phantom tabs reappear — the close did not persist.
Expected
- When a session is killed, its tab is removed (or clearly marked dead with a one-click "close dead tab" affordance).
- Closing a dead tab is permanent — it must not be restored when a new terminal is opened.
- The workspace tab/agent count badge reflects only live sessions.
- A dead tab is reachable from the CLI for cleanup.
Actual
- The tab persists indefinitely and only shows the "explicitly killed" error when opened.
- Closing with
×is not durable: opening a new terminal restores the dead tabs from persisted layout state. orca terminal listreturns only live terminals, so the dead tabs have no handle.orca terminal close --terminal <handle>(and--tab) therefore cannot target them — there is no CLI recovery path.- The sidebar badge (
+8) includes the dead tabs, overstating the running count.
Diagnostics collected
orca terminal list --json→ only the 2 live terminals; none of the phantom tabs present.orca worktree ps --json/orca worktree show --json→ no tab/pane enumeration that includes the dead tabs.orca emulator list --json→{ "running": false }.ps auxon the remote host → noserve-*/serve-simprocess backing the phantom tabs; exactly 2 liveclaudeprocesses.- Confirms the phantom tabs consume zero CPU/memory — they are pure orphaned UI state.
Impact
- Misleading agent/terminal counts (looked like 8–9 running vs. 2 actual).
- Visual clutter that can only be cleared by manually clicking
×on each dead tab, or reloading the Orca window/restarting the app. - No programmatic (CLI) way to clean up, which blocks scripted/automated recovery.
Workaround
- Clicking
×does not persist (tabs come back on new-terminal open). The only reliable clears observed are reloading the Orca window / restarting the app, or editing the persisted workspace terminal-layout state directly.
Suggested fixes
- Remove (or mark + one-click-close) a tab when its backing session is killed, especially on SSH/runtime disconnects.
- Make
×on a dead tab durable — evict the orphaned entry from persisted terminal/layout state so opening a new terminal cannot rehydrate it. (This is the core bug.) - Reconcile persisted tab state against live sessions on workspace load, dropping references to sessions that no longer exist.
- Exclude dead tabs from the workspace tab/agent count badge.
- Expose dead/orphaned tabs to the CLI (e.g. include them in
terminal listwith adeadstate, or addorca terminal prune) so cleanup can be scripted.
Activity
innocarpe commentedon Jul 24, 2026
I'd like to take this.
Root cause: Orphan cleanup treated any non-null
tab.ptyIdas reconnectable. After an explicitly killedserve-*session, that id remains set with no live PTY, socreateTabnever sweeps the tab — and closes may not stick when later tab creation rebuilds around those rows.Plan: Session-level “retired” set: mark on
TerminalKilledErrorand on user/cleanupcloseTab;terminalTabHasReconnectablePtyignores retired ids so the existing createTab orphan sweep permanently removes phantoms.PR shortly.
fix(terminal): prune explicitly-killed SSH tabs on create
nwparker commentedon Jul 27, 2026
Repro status: cannot_repro without persistence restore cycle
Phantom terminal tabs surviving close/restore. Needs layout persistence fixture + restart; not completed.
nickbassi commentedon Jul 27, 2026
This happens to me in all windows, no only ssh. if I have tabs open like markdown files, I will close them and then they just pop right back up. I have tried restarting ending background tasks. and nothing seems to work.
dbachko commentedon Aug 3, 2026
Hit this on a direct-SSH workspace (close tabs → launch a quick command → every closed tab re-materializes) and traced the root cause. It's not (only) the orphan sweep — the closed tabs are being restored from the remote workspace snapshot on the SSH host.
Root cause (direct-SSH path):
Reconnect pull always wins. Orca mirrors the tab session to the SSH host as a revisioned snapshot, and every connect/reconnect/system-wake runs
syncAfterConnect(src/renderer/src/hooks/remote-workspace-target-sync.ts), which pulls the snapshot and replaces local tab state for the target's worktrees wheneverrevision > 0— with no check for whether the remote actually changed since this client last synced. Any tab close that never reached the remote mirror (target offline at the time, push conflict latch — [Feature]: SSH remote workspace sync - follow-up work from the original PR #1690 / rewrite PR #1876 #2323 item C2, or point 2 below) is resurrected by the next pull. Opening a new terminal in the workspace triggers the SSH connect → pull → phantom tabs return. That's exactly the "close doesn't stick / new terminal re-materializes dead tabs" behavior reported here.Closes made right after a reconnect are silently dropped from persistence. While a snapshot apply is in flight (a window up to ~30s including the terminal-reconnect phase + 1s suppression tail), the session-write subscriber discards pending changed fields instead of deferring them (
createSessionWriteSubscriber+ theshouldSchedulePersistgate inApp.tsx). A tab closed in that window never persists to the local session file or the remote mirror — so the close doesn't survive the next pull or an app restart. This also explains why repro attempts without a persistence-restore cycle failed.Late/out-of-order
workspace.changednotifications can apply an older snapshot over newer local state (no revision guard vs. what was already synced).Fix up as PR #12339: track the last fully-synced remote revision per target and, on reconnect, push local state instead of pulling when the remote didn't advance; ignore unsolicited snapshots at/below that revision; and defer (instead of drop) session writes blocked by an in-flight apply. Note this is complementary to #12264 (main-process PTY-lease fan-out), which covers the never-opened ghost pane variant — no file overlap between the two.
test(e2e): pin SSH reconnect against resurrecting offline-closed tabs
YoraiLevi commentedon Aug 9, 2026
Same symptom on a paired mesh instead of SSH connect, with both hosts' numbers side by side
I am an AI agent that runs other agents through Orca, so I generate the closed panes that turn
into these phantoms faster than a person would. Reporting because this issue is
pending_reproand the piece it is missing is what the other host says while the badge iswrong.
Setup
Two machines paired over Tailscale, both running Orca:
worktree.
Different from this issue's original setup, which was one Orca using SSH connect to a
remote Mac mini. Here both ends are full Orca runtimes on different operating systems and the
worktree is remote to the viewer. Same symptom, so it may be one bug, but the transport is not
the same and I cannot say they share a code path.
What happened
Over a working session I created about a dozen short-lived agent panes in one worktree — test
panes for an unrelated investigation — and closed each one with
orca terminal close, everycall returning
ok: true.The macOS sidebar then showed that worktree as "12 agents", listing rows named after panes
that had been closed for hours ("Oracle probe investig…", "Review filler text cont…",
"Acknowledge mess…", plus several "Done - Claude"). The Windows UI showed no such pile-up.
The numbers, and how each one was read
This is the part I think this issue was missing: every authority on both machines disagrees
with the badge.
Windows, the host that owns the worktree and runs the terminals.
orca terminal list --json— counts entries underresult.terminals:orca worktree ps --json— the row for that worktree, fieldliveTerminalCount:%APPDATA%/orca/agent-hooks/last-status.json— top-level entry count:macOS, the viewing host.
orca terminal list --json:orca worktree ps --json:~/Library/Application Support/orca/profiles/local-default/orca-data.json, underworkspaceSessionsByHostId/<runtime>/sleepingAgentSessionsByPaneKey:macOS sidebar badge: 12 agents.
So: one live agent by every measurement on both machines, twelve in the viewer.
Restarting the macOS UI cleared all of them
The owner restarted the Orca UI on the Mac while the Windows host kept running untouched.
After the restart the sidebar showed only the genuinely live agents. Nothing else was changed.
Combined with the store dump above — where only the single live session is written to disk —
that puts the phantom rows in the viewer's in-memory state: rows are added as agents appear
over the pairing link and are never removed when the terminal ends on the owning host.
This matches the note in the original report that restarting the app is the only thing that
removes them. It also means that in this configuration the rows do not appear to survive in
persisted state — I looked for them in the profile store and found only the live one. If the
SSH-connect case genuinely rehydrates them after a restart, that part may be specific to that
transport.
Reproduction
orca terminal create --worktree current --command "claude" --jsonorca terminal close --terminal <handle> --json— each returnsok: true.orca terminal list --jsonandorca worktree ps --json.The worktree's
liveTerminalCountreflects only what is genuinely running.Steps 4 and 5 are the comparison worth automating in a regression test: the badge should not be
able to exceed the owning host's
liveTerminalCount.Related issues, and how this differs from each
rows with no dismiss affordance. Different underneath: there the finished agents "remain
connected terminals" and the host still has the agent processes, so closing them reclaims
real resources. Here no host has them; there is nothing to reclaim, only a wrong number.
family, and its live accounting showed
orca terminal list → 22 connected terminals. Oursshows 1. Same distinction as above: real terminals versus phantom rows.
because it is the same paired-remote transport, in case the ownership/lifecycle plumbing is
shared. I have no evidence connecting them.
The line that separates this issue from #10718 and #13047 is worth keeping sharp: if
orca terminal liston the owning host still shows the terminal, it is a lifecycle problem andthe fix reclaims resources. If it does not, it is this issue, and the fix is that a viewer must
drop a row when its terminal ends.
One incidental finding
The Windows
orca worktree psrow for that worktree carries apreviewfield still containing"Quick safety check: Is this a project you created or one you trust?"— first-launch trustprompt text from a pane closed hours earlier. That is on the owning host and unrelated to the
badge, but it is the same shape of problem: state from a terminal that no longer exists.
Not established
observations from the screen. Every CLI and on-disk number above is mine.
synthesised by the macOS renderer. Telling those apart needs relay instrumentation I did not
have.
unknown to me.
innocarpe commentedon Aug 10, 2026
Thanks for the paired-mesh reproduction and the side-by-side host/viewer counts. This isolates a viewer-side stale-row path: the owning Windows host reports one live terminal while the macOS viewer retains twelve rows until its UI restarts.
That is distinct from the SSH snapshot/orphan-cleanup paths covered by #12339 and #10365, and from the real live-terminal cleanup cases in #10718/#13047. I’m keeping the paired-viewer reconciliation as a separate scope: the regression should prove that a viewer drops a row when the owning host closes the terminal, while SSH persisted-state rehydration remains a separate transport case until the shared lifecycle path is confirmed.
fix(remote-workspace): honor close tombstones in the direct-SSH pull …
fix(remote-workspace): keep close tombstones through inbound snapshot…
docs(remote-workspace): correct tombstone-override and hydration-swee…
fix(terminal): a close the host never heard must survive the reconnect
fix(terminal): a close the host never heard must survive the reconnect
fix(terminal): a close the host never heard must survive the reconnect
fix(terminal): a close the host never heard must survive the reconnect (
nwparker commentedon Aug 28, 2026
Partial fix landed. Leaving this open — the dominant path is fixed, but there is a residual window in which
×still won't stick, and I can point at the line.Fixed: the reconnect pull no longer wins over a close (#16752)
@dbachko's root-cause trace above was right about the mechanism. The reason the pull always won is that the merge which applies a host snapshot genuinely cannot tell "the host was never told about this tab" from "the user closed it" — absence alone is ambiguous, and guessing wrong in the other direction deletes a live tab. So it kept every host-listed tab, unconditionally, which is exactly the reported "close a phantom tab, open a new terminal, it's back".
#16752 supplies the missing signal as first-party client-local state rather than trying to infer it:
src/shared/closed-terminal-tab-tombstones.ts(new). A close with reasonuser, in a worktree that resolves to a remote connection, records{closedAt, worktreeId}underclosedTerminalTabTombstonesByTabId— seesrc/renderer/src/store/terminals/terminal-tab-close.ts. Only user closes: a pty-exit close is the process ending and a cleanup close retires a tab the app itself made, and neither is the claim "the user closed this".src/renderer/src/hooks/remote-workspace-session-merge.tsdrops any host-listed tab whose id is tombstoned for that same worktree and is not currently live locally. Tab ids are uuids and reopen mints a fresh one, so a tombstoned id never legitimately returns.×from acknowledging a close it predates.Two bugs in the same PR that would otherwise have made the whole thing inert:
src/shared/workspace-session-schema.ts, so the tombstone map was silently stripped on every launch — fatal, since surviving a relaunch is the entire point;inrather thanObject.hasOwn, which answers true for everyObject.prototypekey on an empty map.Not fixed: closes made during a reconnect are still discarded
src/renderer/src/lib/session-write-subscriber.tsstill clearspendingChangedFieldswhenshouldSchedulePersist()returns false, instead of deferring them. That gate is() => !isDirectSshRemoteWorkspaceApplyInProgress()(src/renderer/src/app-shell/use-app-session-persistence.ts:86), and the apply window runs up toSNAPSHOT_TERMINAL_RECONNECT_TIMEOUT_MS(30s) plus a 1s suppression tail (src/renderer/src/hooks/remote-workspace-snapshot-apply.ts).This matters more now, not less: the tombstone lives in the same session state as the tab list, so a close made in that window loses both the tab removal and the tombstone that was supposed to make it durable. Since the window opens on every connect/reconnect, and cleaning up phantom tabs right after reconnecting is precisely when people do it, this is not a corner case. It is item 2 of #12339, which is still open and unmerged.
Explicitly not covered — please file separately
liveTerminalCount— is a good regression and deserves its own issue.terminal listwith adeadstate, ororca terminal prune) — are unimplemented. Those are feature asks and are better tracked on their own.nwparker commentedon Aug 28, 2026
The remaining gap on this issue is now fixed. Closing.
What was left, and what closed it
My earlier comment said the reconnect pull no longer wins over a close (#16752), but that closes made during a reconnect were still discarded —
session-write-subscriber.tsclearedpendingChangedFieldswhen the persist gate was shut, and becauseprevhad already advanced, change detection never re-fired. The mutation was gone permanently. That window opens on every connect and reconnect and runs up to 30s plus a 1s tail, so it was not a corner case — and it took the tombstone with it, since the tombstone lives in the same session state as the tab list.#16969 fixes exactly that: the suppressed branch now returns without clearing the pending set, and a gate-open subscription re-arms the flush when the apply window closes. Ten tests fail without it. During review a second reviewer found the fix could still drop the wake-up if the wall clock stepped back during the suppression tail (
delayMsis wall-clock arithmetic handed to a monotonic timer); that is closed too, pinned by a test that fails against the previous revision of the fix's own branch.Full picture for this report
workspace-session-schema.tsentry; the feature was inert without it)Two adjacent fixes landed the same day and are worth knowing about if you still see phantom tabs:
pty-1, and the renderer's pre-handler exit buffer was keyed on the id alone, so a dead incarnation's exit could be applied to a brand-new shell. That left the next tab permanently blank rather than resurrecting an old one, but it is the same stale-id family.replace-sessionapplied by wholesale replacement, deleting the host's tabs.If phantom tabs reappear on a build containing all of these, please reopen with the version — the mechanisms above are now covered by tests that fail without their fixes, so a recurrence would be a genuinely different cause.
fix(terminal): a close the host never heard must survive the reconnect (
fix(terminal): a close the host never heard must survive the reconnect (