[Bug]: Mobile keeps showing old agent rows after terminals are closed
Operating system
macOS
Orca version
Unknown / current main checked at b1fccada
Details
Summary
Orca Mobile can keep showing old agent/session rows for a workspace after the real terminals are already gone.
I hit this on macOS with Mobile showing a long list of Done agents under a project, but the live terminal list for that worktree was empty / much smaller. It looked like Mobile was showing current activity, but it was actually stale saved state.
What I observed
orca worktree ps --jsonstill returned old rows inworktrees[].agentsliveTerminalCountcould stay above 0 because saved workspace tabs still existedorca terminal list --worktree 'id:<worktreeId>' --jsondid not match what Mobile showed- pruning
agent-hooks/last-status.jsonalone did not update Mobile while Orca was running - the in-memory hook cache also had to be cleared, or Orca needed a restart
So it seems like there are two separate stale sources here:
- saved tabs in
orca-data.jsonunderworkspaceSession.tabsByWorktree - agent hook cache in
agent-hooks/last-status.json+ the runtime in-memory cache
Repro shape
I dont have a perfect minimal repro yet, but this is the shape that caused it:
- Run a few agent terminals in a worktree.
- Let them finish / close the terminals later.
- Open Orca Mobile.
- Compare Mobile with:
orca worktree ps --json
orca terminal list --worktree 'id:<worktreeId>' --json
- Mobile /
worktree.pscan still show oldDoneagents or a non-zero terminal count even when there are no matching live terminals.
Source areas that look related
-
src/main/runtime/orca-runtime.tsgetWorktreePs()attachAgentRowsToSummaries()session.tabs.close
-
src/main/agent-hooks/server.tslast-status.jsonHYDRATE_MAX_AGE_MSruntimeObservedStatusPaneKeys
-
mobile/src/components/WorktreeListRow.tsx -
mobile/src/components/WorktreeAgentList.tsx -
mobile/src/worktree/workspace-list-sections.ts
Why I think this happens
getWorktreePs() seems to mix live runtime state with persisted workspace session state. In particular, liveTerminalCount can be raised from saved tabs.
attachAgentRowsToSummaries() also appears to attach cached agent hook rows by worktreeId without checking if the pane/tab still exists in the current session. Since last-status.json can hydrate entries for up to 7 days, old completed agents can show back up in Mobile as if they still belong to the active workspace.
Possible fix
Maybe Mobile needs a stricter projection than desktop:
- keep
liveTerminalCountto actual live/connected runtime terminals - expose saved tab count separately if Mobile still needs it
- filter
worktree.ps[].agentsso hydrateddonerows without a current tab/pane are not shown as current Mobile activity - when
session.tabs.closecloses a terminal tab, clear hook status for pane keys from that tab too
This was pretty confusing to cleanup manually, because the stale state was split between persisted tabs, persisted hook status, and the in-memory hook cache.
Possibly related, though one difference may point to a separate cause. On Android (mobile 0.0.15, desktop 1.4.95): the desktop state was correct — orca worktree ps and the persisted tabsByWorktree / openFilesByWorktree matched the live worktree. The mobile view was stale: it showed old markdown-doc tabs no longer open on the desktop and was missing terminals that were live. In #6072 the desktop CLI itself returns stale rows; here orca worktree ps was correct and only mobile was stale — so this looks like a separate mobile-side projection issue rather than the same root cause. (I couldn't find where the stale mobile copy is stored; workspaceSessionsByHostId was empty.)
The stale view survived an app force-stop + relaunch and an Android "Clear cache"; it eventually reconciled after several more restarts. Once synced, mobile lags the desktop by a visible delay — a tab closed on the desktop took tens of seconds to drop on mobile.
Second symptom — per-tab Close no-ops on stale tabs. Long-press → Close on a tab that's in the mobile view but not in the desktop's live worktree does nothing (count unchanged, across retries and a restart). A freshly created terminal closes fine — desktop's live terminal count rises on create, drops on close. This matches the "failed host-side close" case that applyClosedTabTombstones (mobile/src/session/session-tab-snapshot-gate.ts) already anticipates: mobile sends session.tabs.close for a tabId the host has no live record of, the host no-ops, the publisher snapshot never confirms the drop, and the tab persists.
I reproduced the stale-count half of this on Orca v1.4.144 with a headless Linux server, so it is not limited to the mobile renderer. After closing worker terminal tabs, orca terminal list --json no longer contained those worktree terminals, while orca worktree ps --json still retained completed rows and positive liveTerminalCount values.
The likely shared source is the persisted session.tabsByWorktree contribution in src/main/runtime/orca-runtime.ts: the summary uses Math.max(summary.liveTerminalCount, tabs.length), even when the corresponding PTYs are no longer live. The desktop/mobile parity intent makes sense, but stale saved tabs can therefore keep runtime-level counts nonzero indefinitely.
A useful regression test would close the final PTY for a worktree and assert that both terminal list and worktree ps converge to zero after the allowed reattach window. If persisted tabs must remain visible temporarily, the API could distinguish savedTabCount from liveTerminalCount rather than treating them as equivalent.
— @ericjung
Should be somehow fixed in https://github.com/stablyai/orca/pull/9053
Status: REPRODUCED on current main (PR #9053 is not in the tree).
OrcaRuntimeService.getWorktreePs() — the projection behind Orca Mobile and orca worktree ps --json — folds persisted session state into the live view. liveTerminalCount is raised from saved tabs via summary.liveTerminalCount = Math.max(summary.liveTerminalCount, tabs.length) (src/main/runtime/orca-runtime.ts:12325) even when no PTY/leaf/process is live, and attachAgentRowsToSummaries() (orca-runtime.ts:12403, assigns at :12518) attaches hydrated hook rows — including done — resolved by src.worktreeId with no check that the pane/tab still exists. Because last-status.json hydrates for days, a finished agent whose tab was closed keeps showing up. The isFreshNonDoneAgentStatus gate at :12525 only guards hasHostSidebarActivity/status, not row inclusion.
Repro test (imports the real runtime, pins both buggy outputs — passes today):
pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/repro-6072-stale-worktree-ps.test.ts
- persisted tab with
ptyId:null, no live PTY →liveTerminalCount === 1(should be 0) - closed tab + hydrated
donesnapshot →summary.agents.length === 1(should be 0)
Fix direction: separate savedTabCount from liveTerminalCount, and filter agent rows whose pane/tab no longer exists (and clear hook status on session.tabs.close).
Key files: src/main/runtime/orca-runtime.ts, src/main/agent-hooks/server.ts, src/main/runtime/repro-6072-stale-worktree-ps.test.ts.
Automated bug-reproduction pass. Repro artifact committed on branch nwparker/bug-repro-pass2; check it out to run the command above. Writeup: docs/bug-reproductions/6072.md.
Fix is up in #11464 (CI green, awaiting merge).
Worth noting this issue was really two bugs. The liveTerminalCount-from-saved-tabs half is already fixed on main by #9874 — the repro test committed in this thread no longer reproduces. The surviving half was stale done-agent rows, and that's what #11464 fixes: local rows are dropped when their tab is gone from every session/runtime-graph record and no connected PTY backs them. Remote rows stay exempt, because the SSH no-PTY contract forbids requiring local evidence.
This supersedes #6222 — that approach's live-PTY-only gate would break the SSH contract as it stands today.