orca/src/main
Jinwoo Hong 66d596fe11
fix: zombie worktree PTY cleanup (issue #218) (#1376)
* fix(runtime): kill all PTYs for a worktree on removal (design §4.3)

Worktree deletion only shut down renderer-tracked terminals, so PTYs owned
by background tabs, split panes, or pre-reload sessions survived the
removal and kept leaking memory. Introduce killAllProcessesForWorktree
with three sweeps (runtime leaves, provider-prefix scan of daemon session
ids, pty-registry by worktreeId) and wire it into both teardown paths:
the CLI-initiated removeManagedWorktree and the renderer-initiated
worktrees:remove IPC handler. OrcaRuntimeService gets a lazy
getLocalProvider thunk so construction order stays robust.

Co-authored-by: Orca <help@stably.ai>

* fix(renderer): purge worktree-scoped state on removal + hydration (design §4.4)

When a worktree is deleted, ~25 worktree-scoped maps (tabsByWorktree,
git caches, browser state, split-tab models, per-file editor drafts,
etc.) kept references to the gone worktree, so SessionsStatusSegment
kept mis-classifying orphaned PTYs as bound and dropdowns rendered stale
ids. Add purgeWorktreeTerminalState as a single atomic action that
wipes every scoped map plus cascades top-level actives. Fire it from
the worktrees:changed listener on the set-diff of removed ids, and once
more at hydration via fetchAllWorktrees to clean up persisted entries
from pre-fix sessions. The hydration-time purge is gated behind a
per-repo success check: a single transient IPC error or an all-empty
fetch defers the purge so a degraded launch cannot wipe legitimate
persisted state.

Co-authored-by: Orca <help@stably.ai>

* test(zombie-worktree): regression coverage for design §4.5

Adds tests for every layer of the zombie-worktree fix:
- worktree-teardown: unit coverage of the three-sweep helper including
  best-effort error swallowing across provider/registry.
- orca-runtime: RPC-initiated removeManagedWorktree kills PTYs before
  any git mutation + verifies the lazy getLocalProvider thunk resolves
  on each call.
- worktrees IPC: renderer-initiated remove kills PTYs before git and
  skips the kill helper for SSH-backed repos.
- renderer slice: fetchAllWorktrees defers the purge when any sibling
  repo fetch fails or every repo returns empty (F1 regression);
  happy-path fires the purge once and does not re-run on subsequent
  calls. Direct purgeWorktreeTerminalState coverage pins the cascade
  across worktree-keyed, tab-id-keyed, and file-id-keyed maps.

Co-authored-by: Orca <help@stably.ai>

* fix(runtime): log worktree-teardown kill counts (design §4.4 observability)

Breadcrumb lets ops distinguish a renderer-state-induced leak (diff-path
purge non-empty) from a backend-induced one (nothing to kill but memory
still pinned). Emit only when the sweep actually shut anything down so
steady-state logs stay quiet. Added at both call sites —
removeManagedWorktree (CLI path) and the worktrees:remove IPC handler.

Co-authored-by: Orca <help@stably.ai>

* test(zombie-worktree): fix ptyIdsByTabId seed shape to match production type

The purge unit test seeded ptyIdsByTabId as Record<string, string> when
the runtime type is Record<string, string[]>. The unit tests passed
because they never hit the UI renderer, but live e2e surfaced a
TypeError: (ptyIdsByTabId[tabId] ?? []).some is not a function.

Corrected to arrays; 21/21 tests still pass.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-05-03 15:54:45 -07:00
..
agent-hooks feat(agent-hooks): on-disk endpoint discovery for surviving PTYs (v2) (#1196) 2026-04-27 21:49:18 -07:00
attribution feat: Add GitHub PR review workflow to tasks (#1172) 2026-04-28 00:11:39 -07:00
browser feat(browser): viewport-size emulation via CDP (#1369) 2026-05-02 20:22:40 -07:00
claude fix(terminal): dirty-file close prompts for split, bulk, and quit flows (#1338) 2026-05-01 21:39:15 -07:00
claude-accounts fix: prevent 401 errors from CLI-refreshed tokens being clobbered (#1286) 2026-04-30 22:24:10 -07:00
claude-usage Add Claude usage tracking analytics (#417) 2026-04-09 12:28:59 -07:00
cli feat: add WSL support for repos on WSL filesystems (#375) 2026-04-07 21:02:36 -04:00
codex feat(agent-hooks): on-disk endpoint discovery for surviving PTYs (v2) (#1196) 2026-04-27 21:49:18 -07:00
codex-accounts feat: add PowerShell 7+ support for Windows terminals 2026-05-02 16:06:11 -07:00
codex-cli fix: add version manager bin paths to startup PATH for GUI-launched apps (#702) 2026-04-15 23:37:16 -07:00
codex-usage Add Codex usage tracking (#444) 2026-04-10 10:04:57 -07:00
cursor feat(agent-hooks): on-disk endpoint discovery for surviving PTYs (v2) (#1196) 2026-04-27 21:49:18 -07:00
daemon fix(pty): release ptmx fd on natural exit + defuse SIGHUP-to-recycled-pid (#1327) 2026-05-02 23:12:14 -07:00
gemini feat(agent-hooks): on-disk endpoint discovery for surviving PTYs (v2) (#1196) 2026-04-27 21:49:18 -07:00
ghostty feat(settings): import Ghostty config with preview, color overrides, opacity and blur (#1001) 2026-04-26 17:00:46 -07:00
git fix(worktree): restore sparse checkout without per-poll git subprocesses (#1316) 2026-05-01 13:25:22 -07:00
github feat(github): per-repo issue-source selector (#1317) 2026-05-01 21:48:51 -07:00
ipc fix: zombie worktree PTY cleanup (issue #218) (#1376) 2026-05-03 15:54:45 -07:00
lib feat(editor): export active markdown to PDF (#882) 2026-04-20 19:41:12 -07:00
linear feat(rate-limits): add Gemini and OpenCode Go usage tracking (#1023) 2026-04-29 16:55:32 -07:00
memory feat(memory): add Memory & CPU status-bar popover (#1146) 2026-04-26 21:42:06 -07:00
menu feat(settings): replace task-icon toggle with Tasks-button toggle, expose in View menu (#1271) 2026-04-29 21:13:13 -07:00
opencode feat(agent-hooks): on-disk endpoint discovery for surviving PTYs (v2) (#1196) 2026-04-27 21:49:18 -07:00
pi fix(pi): stop deleting user Pi data through overlay junctions (#1083) (#1092) 2026-04-25 15:23:24 -07:00
providers fix(pty): release ptmx fd on natural exit + defuse SIGHUP-to-recycled-pid (#1327) 2026-05-02 23:12:14 -07:00
rate-limits Defer protected app data reads until user action (#1370) 2026-05-02 18:15:52 -07:00
runtime fix: zombie worktree PTY cleanup (issue #218) (#1376) 2026-05-03 15:54:45 -07:00
ssh feat(file-explorer): support drag-and-drop file import over SSH (#1279) 2026-04-30 01:28:43 -07:00
star-nag support orca 2026-04-18 00:10:27 -07:00
startup fix(runtime): add single-instance lock + owned-metadata clear (#1312) (#1326) 2026-05-02 23:05:14 -07:00
stats support orca 2026-04-18 00:10:27 -07:00
telemetry feat(telemetry): PR 1 — foundations (types, consent, migration, PRIVACY.md) (#1372) 2026-05-03 13:13:26 -07:00
types
window fix: zombie worktree PTY cleanup (issue #218) (#1376) 2026-05-03 15:54:45 -07:00
e2e-config.ts feat: add idempotent E2E test suite with headless Electron support (#671) 2026-04-19 12:09:32 -07:00
hooks-runner.test.ts Run long GitHub issue commands reliably (#583) 2026-04-13 16:05:48 -07:00
hooks-setup-scripts-match.test.ts fix(hooks): generate worktree setup-runner from target worktree's orca.yaml (#1280) 2026-05-02 18:27:09 -07:00
hooks.test.ts fix(hooks): generate worktree setup-runner from target worktree's orca.yaml (#1280) 2026-05-02 18:27:09 -07:00
hooks.ts fix(hooks): generate worktree setup-runner from target worktree's orca.yaml (#1280) 2026-05-02 18:27:09 -07:00
index.ts fix: zombie worktree PTY cleanup (issue #218) (#1376) 2026-05-03 15:54:45 -07:00
persistence.test.ts feat(telemetry): PR 1 — foundations (types, consent, migration, PRIVACY.md) (#1372) 2026-05-03 13:13:26 -07:00
persistence.ts feat(telemetry): PR 1 — foundations (types, consent, migration, PRIVACY.md) (#1372) 2026-05-03 13:13:26 -07:00
pwsh.test.ts feat: add PowerShell 7+ support for Windows terminals 2026-05-02 16:06:11 -07:00
pwsh.ts feat: add PowerShell 7+ support for Windows terminals 2026-05-02 16:06:11 -07:00
repo-worktrees.test.ts feat: add non-git folder support (#356) 2026-04-06 22:54:02 -07:00
repo-worktrees.ts feat: add non-git folder support (#356) 2026-04-06 22:54:02 -07:00
system-fonts.ts
terminal-history.test.ts feat: scope terminal shell history per worktree (#620) 2026-04-13 22:42:53 -07:00
terminal-history.ts feat: scope terminal shell history per worktree (#620) 2026-04-13 22:42:53 -07:00
updater-changelog.test.ts fix: improve rich card display logic for current and unlisted versions (#634) 2026-04-14 10:25:55 -07:00
updater-changelog.ts fix: use >= in compareVersions fallback to handle equal/unparseable versions (#635) 2026-04-14 10:33:25 -07:00
updater-events.ts fix(updater): throttle wake/focus update checks to daily cadence (#955) 2026-04-22 16:30:17 -07:00
updater-fallback.ts fix(updater): let RC users upgrade to newer RC *and* stable releases (#1104) 2026-04-25 17:49:35 -07:00
updater-mac-install.ts
updater-nudge.test.ts feat: implement on-demand update notification nudge (#570) 2026-04-12 21:30:15 -07:00
updater-nudge.ts feat: implement on-demand update notification nudge (#570) 2026-04-12 21:30:15 -07:00
updater-prerelease-feed.test.ts fix(updater): let RC users upgrade to newer RC *and* stable releases (#1104) 2026-04-25 17:49:35 -07:00
updater-prerelease-feed.ts fix(updater): let RC users upgrade to newer RC *and* stable releases (#1104) 2026-04-25 17:49:35 -07:00
updater.check-failure.test.ts fix(updater): surface user-initiated check failures when GitHub is down (#1181) 2026-04-27 14:50:39 -07:00
updater.fallback.test.ts fix(updater): keep prerelease users on the RC channel (#1053) 2026-04-24 14:36:22 -07:00
updater.mac-install.test.ts feat: implement on-demand update notification nudge (#570) 2026-04-12 21:30:15 -07:00
updater.test.ts fix(updater): surface user-initiated check failures when GitHub is down (#1181) 2026-04-27 14:50:39 -07:00
updater.ts chore: move dev-app-update.yml into config/ (#1276) 2026-04-30 00:11:14 -07:00
win32-utils.test.ts fix(win32): resolve EPERM on userData writes, batch-file spawn failures, and native dep rebuild (#1152) 2026-04-26 22:29:58 -07:00
win32-utils.ts fix(win32): resolve EPERM on userData writes, batch-file spawn failures, and native dep rebuild (#1152) 2026-04-26 22:29:58 -07:00
wsl.test.ts feat: add WSL support for repos on WSL filesystems (#375) 2026-04-07 21:02:36 -04:00
wsl.ts feat: add WSL support for repos on WSL filesystems (#375) 2026-04-07 21:02:36 -04:00