orca icon indicating copy to clipboard operation
orca copied to clipboard

[Bug]: Resource Manager misclassifies live daemon sessions as orphan and force-kills them without confirmation

Open bbingz opened this issue 4 months ago • 8 comments

Summary

On macOS with Orca 1.4.137, Resource Manager classified actively running daemon-backed agent terminals as "orphans". Clicking Kill orphan terminals then force-killed all of them without a confirmation dialog.

This incident followed the headless-serve / GUI relaunch lifecycle mismatch documented in #8457, but the destructive false-positive cleanup is an independent safety bug: any incomplete, stale, or recovering renderer store can make valid daemon sessions look unbound.

Observed incident (2026-07-13, Asia/Shanghai)

  1. A packaged orca serve process still owned the single-instance runtime and live AI terminals after the GUI had quit.
  2. A GUI was forced back into view while the runtime/renderer lifecycle was inconsistent (see #8457).
  3. Resource Manager displayed 25 orphans, including workspaces with agents that were visibly still running.
  4. The user clicked Kill 25 orphan terminals.
  5. daemon.log then recorded 28 distinct session-killed events with immediate:true in ~50 ms (02:48:41.072Z–02:48:41.122Z). The count increased from the screenshot's 25 because additional sessions were created between the screenshot and the kill.
  6. Live agent sessions were interrupted and some UI/session state churned afterward.

The Electron main process did not restart at the moment of the bulk kill: its PID and start time remained unchanged, and main.trace.ndjson contains no new renderer_bootstrap_started after cleanup. The visual "window restart" therefore appears to be UI/session reconstruction after the forced kills, not a second confirmed main-process restart.

I am not attaching the screenshot because it contains private workspace names, but the daemon event counts and timestamps above are deterministic and redacted.

Root cause in current main

"Orphan" currently means only "not referenced by the current renderer's binding index":

  • resource-session-bindings.ts builds boundPtyIds exclusively from renderer-owned tab/PTY/layout state, then counts every daemon session absent from that set as unbound.
  • This is not authoritative proof that the daemon session has no owner, no foreground process, or no persisted/restorable binding. A recovering renderer can legitimately have an incomplete index.

The destructive path trusts that derived label without revalidation:

  • ResourceUsageStatusSegment.tsx explicitly skips confirmation for one unbound session, and bulk-kills every session absent from the current binding set with Promise.allSettled.
  • pty.ts turns each request into provider shutdown with immediate: true.

The code comment asserting that an unbound session has no tab or unsaved work in "this Orca instance" is unsafe across renderer recovery, runtime-generation mismatch, headless/mobile ownership, and stale persisted state.

Why this is distinct from existing reports

  • #8457 documents the headless serve process hijacking GUI relaunch and the unsupported serve-to-desktop transition that exposed this incident.
  • #7742 concerns renderer/app crashes breaking PTYs.
  • #4760 concerns headless/mobile-created terminals being invisible to desktop clients.

This issue is specifically about false-positive orphan classification plus destructive, confirmation-free bulk termination. It remains dangerous even after #8457 is fixed because other recovery or synchronization gaps can produce an incomplete renderer binding index.

Expected behavior / acceptance criteria

  • [ ] Absence from the current renderer binding map is not, by itself, sufficient to classify a daemon session as safe to kill.
  • [ ] Orphan classification reconciles daemon ownership/liveness, persisted or restorable pane identity, headless/mobile ownership, and renderer/runtime generation.
  • [ ] While workspace hydration or reconciliation is incomplete/mismatched, destructive orphan actions fail closed and show a recovery warning.
  • [ ] Bulk cleanup requires explicit confirmation that includes the count and clearly distinguishes inactive/unowned sessions from sessions with live foreground processes.
  • [ ] Every target is revalidated immediately before shutdown; a stale snapshot cannot authorize a kill.
  • [ ] Active or ambiguous sessions require an explicit force action and are never sent through the ordinary orphan cleanup path.
  • [ ] Regression coverage reproduces an incomplete/recovered renderer index with live daemon sessions and proves they are neither labeled kill-safe nor terminated.
  • [ ] The behavior is covered for native, SSH, and headless/mobile-owned sessions.

Environment

  • Orca 1.4.137 (packaged /Applications/Orca.app)
  • macOS
  • Daemon-backed PTYs
  • Related lifecycle incident: #8457

bbingz avatar Jul 13 '26 02:07 bbingz

Also having the similar issue: Below is the report from Fable 5, diagnosing my case:

Independent occurrence on macOS with Orca 1.4.141 (auto-updated the same morning), adding two data points to this report: the bulk kill also hits actively attached, foreground-busy sessions, and it recurred throughout one day.

Environment

  • macOS 15.x (Darwin 25.2.0), Orca 1.4.141 (installed 2026-07-15 03:35 KST; daemon restarted 07:35 KST)
  • Daemon-backed workspace panes running long-lived agent CLIs (Claude Code, with a codex exec child process)

Observed

daemon.log recorded 30 session-killed events during a single day (2026-07-14T22:35Z–2026-07-15T06:11Z), several of them as multi-workspace bursts. The clearest incident:

06:00:17.544Z session-killed  <workspace-A>  immediate:true
06:00:17.562Z session-killed  <workspace-B>  immediate:true
06:00:17.581Z session-killed  <workspace-C>  immediate:true
06:00:17.582Z session-killed  <workspace-C>  immediate:true

4 sessions across 3 different workspaces force-killed within 40 ms .

The killed workspace-A session was not idle and not unbound from the user's perspective: it hosted a live Claude Code CLI that had an active background codex exec child mid-write (its output file's last write was seconds before the kill). Both processes died with the pty; the interactive agent session and its delegated task were lost mid-task.

Corroborating the "main process did not restart" finding

main.trace.ndjson renderer memory breadcrumbs (60 s interval) continue uninterrupted across the kill window (offsets −74 s, −14 s, +46 s relative to the burst), and the daemon PID was unchanged. So the app/renderer stayed up; only the pty sessions were torn down — consistent with a client-issued bulk kill over the daemon protocol (the daemon's case "kill" handler just executes requests).

Trigger: no Resource Manager interaction

Unlike the original report, no "Kill orphan terminals" click preceded these bursts — the user confirms they did not interact with Resource Manager at any of the kill times, and at the 06:00:17Z burst the machine was unattended (the pane's agent had finished its turn ~2 minutes earlier and was running a background child). Bursts recurred across the day (22:35Z–06:11Z window) with the same signature.

So on 1.4.141 there appears to be a path that issues these bulk kill requests for renderer-unbound sessions without user confirmation or interaction — plausibly after the same-day auto-update/relaunch left the renderer binding index stale. The failure mode still matches this issue's root cause: "orphan" derived solely from the renderer binding index, then destructive bulk kill without verifying attachment, foreground children, or recency of I/O — but the unprompted variant makes the missing verification strictly worse than a mislabeled button.

The verification approach in #8467 (only close sessions freshly verified as idle shells with no child processes) would have prevented both the original incident and ours — our killed session had an attached stream client, recent PTY I/O, and a live child process tree.


Update (~40 min after posting): the kills are recurring on a rolling basis, not as a one-off burst. In the 15 minutes while this comment was being written, three more workspaces were hit:

06:26:59.716Z session-killed <workspace-B>              immediate:false
06:26:59.717Z session-killed <workspace-B>              immediate:true
06:37:50.301Z session-killed <workspace-C>              immediate:false
06:37:50.303Z session-killed <workspace-C>              immediate:true
06:41:52.445Z session-killed <workspace-D>              immediate:false
06:41:52.525Z session-killed <workspace-D>              immediate:true

Signature per incident: a killed(immediate:false) + killed(immediate:true) pair ~2 ms apart, one workspace at a time, every ~5–15 minutes, with the app idle and no user interaction. One of these again took down a live agent session the user was actively using. Total session-killed events on this machine since the 1.4.141 update: 36 in under 8 hours.

snutp avatar Jul 15 '26 06:07 snutp

Recurrence confirmed on official v1.4.142 (auto-updated overnight from 1.4.139): today at 00:44:48Z another burst killed sessions across 3 workspaces within 1 ms, all immediate:true, again with no Resource Manager interaction and no user at the machine's UI at that moment.

Consequence worth highlighting: one of the killed sessions was being viewed from a second Orca host at the time (desktop-to-desktop remote view). The viewer had shown a blank pane since 00:42Z (separate buffer-snapshot issue); two minutes later the burst destroyed the underlying session, its terminal-history directory was purged, and the next subscription attempt silently spawned a fresh empty shell in its place — so from the user's perspective the work session was replaced by an empty prompt with no warning.

The mitigation we run locally (daemon-side guard: refuse kill for sessions with PTY I/O in the last 30 min, env-tunable) has been effective. Happy to share the patch if useful.

snutp avatar Jul 16 '26 01:07 snutp

@snutp thanks for the additional info, if you have a draft PR for your patch, can you link it here? we can work on a fix based on it

AmethystLiang avatar Jul 16 '26 01:07 AmethystLiang

@AmethystLiang

Sure, I've already applied a daemon-side mitigation locally and have been testing it. Let me finish validating it and I'll open a draft PR shortly.

snutp avatar Jul 16 '26 02:07 snutp

Draft PR: #9032 — field results and known limitations are in the description.

snutp avatar Jul 16 '26 15:07 snutp

🤖 Agent handoff — reproduction kit

Status: REPRODUCED · GitHub label has_repro
Writeup (branch): docs/bug-reproductions/8459.md
Branch with tests + docs: nwparker/bug-repro-handoffs

Summary

Resource Manager treats every daemon session absent from the current renderer binding map as an “orphan.” Bulk Kill N orphan terminals and per-row kill on unbound rows skip confirmation and call window.api.pty.kill immediately. A recovering/incomplete renderer can therefore force-kill live agents.

Automated re-run

git fetch origin nwparker/bug-repro-handoffs
git checkout nwparker/bug-repro-handoffs
# or: git worktree add /tmp/orca-repro-8459 origin/nwparker/bug-repro-handoffs

pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/status-bar/repro-8459-orphan-live-daemon.test.ts

Code / evidence files

How another agent should use this

  1. Check out nwparker/bug-repro-handoffs (or cherry-pick the repro-* test for this issue).
  2. Run the command(s) above — green documents the bug (or cannot_repro proves current tree does not show it).
  3. Implement the fix on a new branch from main; keep/adapt the repro test as a regression test that should flip behavior or stay as a guard.
  4. Open a PR with: Description, Evidence, ELI5, User-regression-tradeoffs.

Posted by bug-repro orchestration so work is not trapped in a local worktree only.

nwparker avatar Jul 16 '26 18:07 nwparker

@Jinwoo-H is working on this right now

AmethystLiang avatar Jul 18 '26 01:07 AmethystLiang

will be in next release, usually within 24 hours

OrcaWin avatar Jul 27 '26 18:07 OrcaWin