Skip to content

[Bug]: Terminal closed from mobile app reappears as a brand-new terminal #7345

Closed

Description

@nvergez

Operating system

Other

Orca version

Mobile app: v0.0.18 (3). Desktop: recent build (code references below are against current main, a074ed6)

Details

Short summary:
Closing a terminal from the Orca mobile app never sticks — the terminal disappears for a moment, then reappears as a brand-new terminal (fresh shell). Closing the same terminal from the desktop app works fine. Markdown/file/browser tabs close fine from mobile; only terminal tabs resurrect.

How can we reproduce it?

  1. Pair the mobile app with a running desktop session.
  2. Create a terminal from mobile (or use one only ever driven from mobile).
  3. Long-press the terminal tab on mobile → Close.
  4. The terminal briefly disappears, then comes back as a brand-new terminal.

Root cause (traced in code):
Terminal tabs are the only tab type on mobile whose Close goes through the handle-only terminal.close RPC instead of the session-tab close path, and the two halves of that path re-create the terminal:

  1. Mobile Close calls handleCloseTerminal → terminal.close (mobile/app/h/[hostId]/session/[worktreeId].tsx:4110). Host-side closeTerminal (src/main/runtime/orca-runtime.ts:16363) only kills the PTY — it does not remove the session tab or drop its persisted binding.
  2. On PTY exit the runtime keeps the tab in the mobile session snapshot and republishes it as status: 'pending-handle', terminal: null (orca-runtime.ts:18548-18550, republished via touchMobileSessionSnapshotsForPty at :6959). The closed tab is still present — and still marked active.
  3. handleCloseTerminal removes the terminal only from the legacy terminals list; it never removes the tab from sessionTabs, never clears activeSessionTabId, and sets no tombstone. When the pending snapshot arrives, the auto-activation effect ([worktreeId].tsx:4187) sees an active pending terminal tab and calls session.tabs.activate with notifyClients: false → host hits shouldMaterializePendingTerminal (orca-runtime.ts:3841-3862) → createHeadlessMobileSessionTerminal spawns a new PTY into the same tab. That is the resurrection.

This exact resurrection class was already fixed for the other tab types: handleCloseSessionTab tombstones closed tabs ([worktreeId].tsx:4154), and host closeMobileSessionTab documents the authoritative-teardown requirement (orca-runtime.ts:4082-4087). The terminal Close button just doesn't use either fix.

Suggested fix:

  • Mobile: route the terminal action sheet's Close through the session-tab close path (session.tabs.close + tombstone + clear activeSessionTabId) instead of handle-only terminal.close.
  • Host (defense in depth): in runtime.closeTerminal, when the handle maps to a runtime-owned mobile session tab, perform the same authoritative teardown as closeMobileSessionTab (kill PTY + drop persisted binding + prune and emit snapshot) so stale clients cannot resurrect the tab.

Likely shares a root cause with #6927 (headless-server pairing: tab never closes from mobile) — same close path, different manifestation.

Activity

  1. added theissue type on Jul 12, 2026
  2. nwparker commented on Jul 27, 2026

    @nwparker
    Contributor

    Repro status: cannot_repro on current host close path (please re-test mobile)

    Original report: mobile Close → terminal.close only killed PTY → pending tab rematerialized.

    On c3a9a5e8a6, host Runtime.closeTerminal also tears down the mobile session tab when a surface is present:

    // src/main/runtime/orca-runtime.ts ~23036-23065
    const ptyKilled = this.ptyController?.kill(...)
    if (!ptyKilled || siblingCount <= 1) {
      if (surface) {
        await this.closeMobileSessionTab(`id:${pty.pty.worktreeId}`, tabId)
      }
    }

    Mobile UI still routes the action-sheet Close through handleCloseTerminal → terminal.close (not session.tabs.close + local tombstone), which is inconsistent with markdown/file/browser tabs — but the host durable close should prevent resurrection.

    If still reproducible on latest mobile + host pair, reopen with versions and a network capture of terminal.close vs session.tabs.* RPCs.

  3. added
    pending_reproRepro attempted; still pending conclusive reproduction
    on Jul 27, 2026
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 workingmobileos:mobilepending_reproRepro attempted; still pending conclusive reproduction

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions