Skip to content

[Bug]: Mobile keeps showing old agent rows after terminals are closed #6072

Closed

Description

@nikuscs

Operating system

macOS

Orca version

Unknown / current main checked at b1fccad

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 --json still returned old rows in worktrees[].agents
  • liveTerminalCount could stay above 0 because saved workspace tabs still existed
  • orca terminal list --worktree 'id:<worktreeId>' --json did not match what Mobile showed
  • pruning agent-hooks/last-status.json alone 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:

  1. saved tabs in orca-data.json under workspaceSession.tabsByWorktree
  2. 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:

  1. Run a few agent terminals in a worktree.
  2. Let them finish / close the terminals later.
  3. Open Orca Mobile.
  4. Compare Mobile with:
orca worktree ps --json
orca terminal list --worktree 'id:<worktreeId>' --json
  1. Mobile / worktree.ps can still show old Done agents or a non-zero terminal count even when there are no matching live terminals.

Source areas that look related

  • src/main/runtime/orca-runtime.ts

    • getWorktreePs()
    • attachAgentRowsToSummaries()
    • session.tabs.close
  • src/main/agent-hooks/server.ts

    • last-status.json
    • HYDRATE_MAX_AGE_MS
    • runtimeObservedStatusPaneKeys
  • 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 liveTerminalCount to actual live/connected runtime terminals
  • expose saved tab count separately if Mobile still needs it
  • filter worktree.ps[].agents so hydrated done rows without a current tab/pane are not shown as current Mobile activity
  • when session.tabs.close closes 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.

Activity

  1. taifunk commented on Jun 24, 2026

    @taifunk

    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.

  2. added theissue type on Jul 12, 2026
  3. e-jung commented on Jul 17, 2026

    @e-jung

    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

  4. nikuscs commented on Jul 17, 2026

    @nikuscs
    Author

    Should be somehow fixed in #9053

  5. nwparker commented on Jul 18, 2026

    @nwparker
    Contributor

    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 done snapshot → 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.

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

    @brennanb2025
    Contributor

    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.

  8. added a commit that references this issue on Aug 1, 2026
    b04c695
  9. added a commit that references this issue on Oct 15, 2026
    b3f7b23
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 macOSsize/mMedium PR (≤600 added lines, ≤25 files)

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions