Skip to content

[Bug][Windows] Ghost terminal registry entries: no UI tab, no OS process, but terminal list reports connected: true and terminal close succeeds without removing them #15549

Open

Description

@somegee

Operating system

Windows

Orca version

1.4.184

Details

Symptom
After closing agent terminal tabs over time, orca terminal list --json keeps returning 5 terminals while the UI (and --include-visual-layouts) shows only 2 tabs. The 3 extra entries report connected: true, writable: true, orphaned: false, but:

  • Resource Manager showed them as 3 orphans; clicking "Close orphan terminals" succeeded, and tasklist confirms the PIDs no longer exist.
  • orca terminal close --terminal on each ghost returns ok: true with ptyKilled: true.
  • Re-running terminal list seconds later still returns all 5 entries, unchanged (topologyRevisions stays at the same value, i.e. no topology change was recorded).

Repro (as observed)

  1. Run several agent sessions (Claude Code / Codex) in one worktree on native Windows.
  2. Close some tabs; later use Resource Manager → "Close orphan terminals".
  3. orca terminal list --json → dead sessions still listed as connected: true, orphaned: false.
  4. orca terminal close --terminal --json → {"close": {..., "ptyKilled": true}} but the entry survives.

Expected: entries whose PTY/OS process is gone should be flagged orphaned and be removable; a successful terminal close should remove the registry entry.

Impact: agents driving Orca via CLI (terminal list → send) cannot tell live sessions from ghosts (orphaned flag is false), so they may send input to dead handles.

Possibly related: #10897 (orphan handles persist, but with orphaned: true), #15210 (Linux pool shell leak). This case differs: flags claim healthy, close claims success, entry survives.

Activity

  1. added theissue type on Aug 20, 2026
  2. Pr1p commented on Aug 20, 2026

    @Pr1p
    Contributor

    Taking a look at this one.

    I'll first verify whether the stale rows are being kept in the terminal/session registry after the backing PTY or OS process has already disappeared, then pin the behavior with a focused regression around terminal list, terminal close, and the orphan-cleanup path.

    I'll keep the fix scoped to removing or marking terminal records whose backing process is no longer observable, and avoid changing broader terminal teardown semantics unless the repro points there.

  3. yzxcj797 commented on Aug 20, 2026

    @yzxcj797
    Contributor

    Traced the three flags through the current code — each symptom in the report has a distinct propagation point, and together they narrow the root cause considerably.

    Why orphaned: false is misleading here. buildPtyTerminalSummary derives orphaned purely from the UI graph (!pty.tabId || !pane || pane.tabId !== pty.tabId) — it says "no visible tab claims this PTY", nothing about process liveness. Your ghosts kept pane/tab bindings alive, so they read non-orphaned even with the process gone. The Resource Manager disagrees because it attributes via the pty-registry, a different surface.

    Why connected: true survives. The provider-session reconciliation sweep marks a row connected: false when the provider's session list omits it and hasPty() doesn't rescue it. Your rows stayed connected: true, which is only possible if the provider inventory (the daemon session list, for a orca-terminal-daemon.exe host) still reports these sessions as live. So the stale surface is the daemon's own session inventory — most plausibly sessions revived from the persisted registry at daemon restart, with their OS processes actually dead. tasklist proving the PIDs gone + registry rows surviving is consistent with exactly that.

    Why close reports ptyKilled: true but doesn't evict. The explicit-close funnel (stopExplicitlyClosedTabPtys → stopAndWait) resolves "stopped" for an id the provider no longer backs — there's nothing to stop, so the shutdown RPC succeeds — but runtime-side eviction of ptysById rows only happens through the pty:exit event (or the disconnected-record prune, which never applies because the row still reads connected). A ghost therefore can't be evicted by the very close that claims to have killed it.

    Two follow-ups that would pin the daemon side:

    1. Do the ghosts appear across a daemon restart (i.e. did orca-terminal-daemon.exe restart between the tabs being closed and the ghosts appearing)? The registry-revival path is the main candidate for listing dead sessions as live.
    2. Does orca terminal list --json still show connected: true for them right after orca daemon restart (if that subcommand exists on your build) — i.e. does a fresh daemon also revive them as live?

    If revival is confirmed, the fix shape is: revived daemon sessions must corroborate liveness (or surface as disconnected) before the session list reports them, and an explicit close whose stop resolved without a backing session should evict the runtime row directly instead of waiting for an exit event that can never arrive.

  4. AmethystLiang commented on Aug 20, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  5. nwparker commented on Aug 22, 2026

    @nwparker
    Contributor

    Not fixed by #15755 — correcting an earlier claim.

    I originally listed this as addressed via job-membership liveness. Testing on Windows 11 showed otherwise: node-pty drops its handle record when the shell exits, so a dead tree reports null rather than an empty list. null means unverifiable — no job support, not a ConPTY, or no longer tracked — and is never evidence that processes died.

    What the API does add is descendant liveness for a tree that is still tracked. Making the registry's connected flag authoritative needs job lifetime decoupled from node-pty's handle record, which is a separate change.

  6. somegee commented on Aug 24, 2026

    @somegee
    Author

    @yzxcj797 @nwparker nwparker Follow-up data for the two questions above, from the reporting machine (Orca 1.4.188, Windows 11):

    1. Daemon restarts: yes — and stale daemon instances survive and coexist.
    Get-Process currently shows two orca-terminal-daemon processes running at the same time:

    Id     Name                  StartTime
    29216  orca-terminal-daemon  2026-08-19 20:04
    39148  orca-terminal-daemon  2026-08-24 08:07
    

    The current app instance started 2026-08-24 08:51, i.e. after the newer daemon. The 08-19 daemon predates my original ghost observation (08-20, on 1.4.184) and is still alive across an app upgrade to 1.4.188 and multiple app restarts. So "did the daemon restart between the tabs being closed and the ghosts appearing" — yes. Extra wrinkle: old daemons apparently never exit, so the provider inventory may be reviving/aggregating sessions across daemon generations.

    2. A fresh daemon still reports the ghosts as connected: true.
    This build has no daemon restart subcommand, but the newest daemon started today at 08:07 (app at 08:51). ~2.5h later, orca terminal list --include-visual-layouts --json reports 11 terminals while the visual layout topology contains only 3 tabs (the window also has a 4th tab, but it is a document/editor tab, not a terminal). All 8 tab-less rows read connected: true, writable: true; 5 of them also read orphaned: false (the misleading combination from my report — the other 3 do read orphaned: true and carry pty:<worktreeId>@@<hash>-style tabIds). 7 of the 8 have lastOutputAt: null and an empty preview — no output ever observed in this app's lifetime — consistent with rows revived from the persisted registry rather than sessions that ever produced anything.

    (One of the 8 is a different sub-case worth noting: recent lastOutputAt and a live preview, tab gone but the underlying process genuinely still running.)

    Happy to run more probes on this machine if useful.

  7. nwparker commented on Aug 25, 2026

    @nwparker
    Contributor

    Design notes from investigating this, including a measurement that changes the obvious approach. Posting so the next person does not repeat it.

    The tempting fix does not work

    src/main/windows/windows-pty-job.ts:117 exports listPtyJobProcessIds with zero production callers, so "wire the job object into terminal list" looks like the answer. It is not, on its own.

    Reading the native (config/patches/node-pty@1.1.0.patch, PtyListJobProcessIds):

    • Wedged ConPTY, baton still held → QueryInformationJobObject runs, empty job → [], positive proof of death.
    • Baton already dropped (normal exit, or after terminatePtyJob — node-pty closes hJob and removes the baton before JS onExit) → null, unverifiable.

    The win32 test "stops answering once the tree is gone" (windows-pty-job.win32.test.ts:167) measures the second case, not the first.

    The ghosts actually reported here — two orca-terminal-daemon processes, a fresh daemon, lastOutputAt: null — are JS sessions whose native baton is gone or never existed in this daemon generation. The job returns null for those. So a patch that only wires listPtyJobProcessIds and acts on [] is a no-op on the reported bug, and treating null as death is forbidden by the job's own contract and by docs/reference/ssh-execution-boundary.md.

    What actually resolves it

    Use the job when it answers, and fall back to shell-pid absence:

    • job [] → exited
    • job non-empty → live
    • job null + kill(pid, 0) → ESRCH → exited
    • EPERM, pid ≤ 0, anything else → unverifiable

    Pid absence proves that pid is gone. Pid presence is not identity (recycling), so it must read live, never exited. Listing must never kill.

    Shape constraints worth knowing before coding

    • Add an optional liveness field to the terminal summary. Do not flip connected on unverifiable, and do not touch orphaned (it is pane-binding bookkeeping, unrelated to the process).
    • Absent liveness means "not evaluated" — fall back to connected. Never liveness ?? 'live'.
    • New optional JSON field only: no protocol bump, no capability negotiation.
    • listOwnedTree? on SubprocessHandle should be optional; making it required taxes ~30 test stubs.
    • Do not change the isAlive getter (session.ts:104); synthesize the existing onExit path when a probe proves death.
    • For terminal close returning ptyKilled: true with the row surviving: synthesize onPtyExit when the row is still connected after a successful kill.
    • Nothing becomes dead code — windows-pty-root-identity.ts and windows-process-tree-kill.ts stay as kill fallbacks and for non-PTY trees.
    • macOS/Linux/SSH/remote ids get no local probe. WSL is fine: the Windows-side wsl.exe job/pid is valid.

    Prerequisite

    Job-object exports only exist in a source build of the patched node-pty, and no shipped desktop release contains that patch yet (see #16059). Verify isPtyJobOwnershipAvailable() on the target build before relying on the job half; the pid half works regardless.

  8. minglo-eco commented on Oct 6, 2026

    @minglo-eco

    Additional data point: the same ghost-entry behaviour on a macOS host, not only Windows.

    Setup (all on 1.4.221 at the time of the repro)

    • Host: Mac mini, macOS 27.0, Orca 1.4.221, used as the active server
    • Clients: Orca 1.4.221 on Windows 10 (19045) and the Android app
    • Agents: Claude Code in each workspace

    What happened (2026-10-06, times UTC)

    1. After the app updated to 1.4.221, two daemons were running side by side: the new one (protocol v40) for new terminals, and the old one (1.4.216, protocol v36) still holding six earlier sessions. This matches the "stale daemon instances survive and coexist" note above.
    2. All six old sessions were idle. At 13:29:26 I sent SIGTERM to the old v36 daemon only. daemon.log shows shutdown reason SIGTERM, and the six agent processes exited.
    3. orca terminal list --json still returned all six terminals with connected: true, writable: true, orphaned: true. Their tabId/leafId were synthetic pty:<worktreeId>@@<id> values, not real layout tabs.
    4. At 13:33:42 the user typed a message into one of those dead terminals from the Android client. Orca created a new PTY on the v40 daemon (session-created), ran claude --resume <same session id>, and delivered the input once. The agent answered normally.
    5. The dead entry was not removed. terminal list then showed two terminals for the same worktree and the same conversation: the new one with a real tab, and the ghost with the pty: tab id and no process. This is the "same conversation shows up twice" symptom we keep seeing.
    6. The Windows client stayed on the ghost and showed "Reconnecting to remote runtime" indefinitely, until the Windows app was restarted (looks like [Bug]: remote-runtime-pty-transport attach() latches in connecting state forever on terminal_not_found #21344).
    7. orca terminal close --terminal <ghost handle> --json returned ok: false, error.code: terminal_stop_unverifiable, but the entry did disappear from terminal list a few seconds later. I repeated this on five more ghosts and got the same result each time. So on macOS, close does remove the row, even though it reports an error. On Windows (this issue), close reports ok: true and the row survives.

    Also seen
    A live session (agent process running, attached to the v40 daemon) is listed as orphaned: true and keeps that flag. It still shows normally on the Android client.

    An earlier incident (2026-10-05 11:15 UTC, single v36 daemon) looked like #11904. An agent started without a tab (tab_missing,layout_missing). Three seconds later the Windows client sent a close for that workspace tab. The process stayed alive as an orphan. Later, a restore launched a second claude --resume of the same conversation.

    I can share redacted daemon.log excerpts if useful.

  9. ucinemallc-eng commented on Oct 24, 2026

    @ucinemallc-eng

    Additional reproduction on Windows, Orca 1.4.237, after decommissioning a managed SSH host (2026-10-24).

    1. The remote machine was permanently deleted. Its saved SSH target remained connecting, and Remote Orca Servers displayed Connection to <retired-host> is already in progress.
    2. The SSH removal dialog correctly directed us to forget the managed server first. orca environment forget --environment <retired-environment-id> --yes --json returned ok: true, outcome: forgotten.
    3. Removed only that SSH target through Settings > SSH Hosts > select target > Remove. The dialog completed. Both orca host list --json and orca environment list --json now exclude the retired host. The remaining SSH host stays connected.
    4. However, local orca terminal list --json still returns two terminals whose executionHostId is the deleted SSH target. Both have orphaned: true, connected: true, writable: true, incarnationId: null, lastOutputAt: null, and an empty preview. Their tab/leaf IDs use the pty:ssh:<deleted-target>... fallback. The deleted host also remains in hostScope.omittedHostIds, with no usable selector.

    Unlike the original report, these entries are marked orphaned; the remaining problem is the contradictory connected/writable flags and stale references after the host-removal workflow succeeds. We have not sent input to these handles or deleted conversation files. No claim that the old PTYs actually survive: their machine no longer exists.

    Expected: forgetting/removing a permanently unavailable host should reconcile terminal inventory, or at least report these handles as disconnected and non-writable while retaining recoverable session metadata. There should be a supported way to retire the stale bindings without deleting historical conversations.

    This follow-up intentionally omits host addresses, account identifiers, credentials, paths, and conversation contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions