Repository navigation
fix(terminal): apply the running-process close confirmation to every tab close path (#10142) - #12272
Conversation
…confirmation Unit repro: closeTerminalTab (the X-button/middle-click entry) never consults inspectRuntimeTerminalProcess and drops a tab with a live child. E2E repro: Cmd+W shows 'Stop running command?' for a tab running sleep 300; cancelling then clicking the tab X closes it silently. Co-authored-by: Orca <[email protected]>
…10142) The tab-strip X button, middle-click and the tab context menu closed a terminal with a live child process without asking, while Cmd+W raised "Stop running command?" for the same tab. The probe lived only in TerminalPane's pane-level close handler; every mouse entry point reaches closeTerminalTab(), which guarded pinned tabs and nothing else. Move the decision into closeTerminalTab, above the web-runtime branch so paired/remote host-backed tabs are covered too, and give the last-pane keyboard close back to it instead of probing twice: - running-terminal-close-guard.ts probes every live PTY of the tab and fails open on a rejected probe or a stale remote handle, matching what Cmd+W already did. No live PTY ids => fully synchronous close, so idle, parked and hibernated tabs keep today's behavior. - shouldConfirmRunningTerminalClose keeps lifecycle echoes, bulk closes, CLI/RPC closes and the post-confirmation re-entry off the modal path. - A standalone confirm store drives RunningTerminalCloseDialog, which reuses the existing CloseTerminalDialog (no new user-visible strings). The request carries the tab label because a tab-strip close can target a tab the user is not looking at, and dedupes by tab id. - TerminalPane.handleRequestClosePane now delegates the last pane to closeTerminalTab. Its transport ptyId is nullable by design, so the old path silently skipped the prompt mid-reattach; the pane keeps its own probe only for closing one pane of a split. - Agent panes win the dialog copy when a split has both an agent and a plain command busy, instead of depending on PTY spawn order. - Tab-group closeItem ran leaveWorktreeIfEmpty synchronously after a close that can now defer; it moves to onClosed and still honors skipEmptyCheck. Co-authored-by: Orca <[email protected]>
…ath (#10142) Follow-up hardening on the tab-close confirmation, from review of the first pass: - A pinned tab with `confirmClosePinnedTab` off never got the running-process prompt on any path, including Cmd+W, which is a regression against the old pane-level behavior: the pinned branch short-circuited on pinned-ness alone and re-entered with `force`, which the running guard excludes. The pin prompt now supersedes only when it will actually appear; with the setting off the close falls through to the running guard. - The probe chain had no `.catch`, so a throw in the decision (a copy-kind lookup on a tab id makePaneKey rejects, a store subscriber) left the tab silently unclosed with no user feedback. It now fails open, as the pane path it replaced did. - A wedged remote inspect RPC could leave the X button looking dead for its full 15s timeout. The probe is now bounded; every close path shares the bound, so keyboard and mouse still behave identically. - The agent-vs-command copy had two resolvers on exactly the keyboard/mouse seam this issue is about. terminal-close-copy-kind.ts is now the single policy; TerminalPane and the tab-strip guard both call it. - The running queue is async while the pinned queue is synchronous, so both could be pending at once and stack two modal overlays. The running dialog now waits for a visible pinned confirmation. - Deduping a repeat close request dropped the second caller's callbacks; it now folds them in, so both closes resolve from one prompt. Ticking "don't ask again" also drains queued prompts instead of showing one the user just opted out of, and a queued prompt no longer inherits the previous tab's tick. closeTerminalTab drops its private pinned predicate for the shared isUnifiedTabPinned, whose only consumer the previous commit had removed.
…0142) The running-process close specs polled `hasChildProcesses` to decide the tab was busy, but macOS starts the shell under `login`, so an initialising terminal already reports a child before `sleep 300` runs. Both specs could therefore press close against a shell that never started the command: the probe correctly saw an idle terminal and closed without asking, and the adjudicated repro failed against a correct fix. Wait for `foregroundProcess === 'sleep'` instead. Assertions are unchanged, and the repro still fails at the pre-fix baseline (a92d8e0).
…10142) Round-1 review follow-ups. - The 4s probe bound closed the tab outright, but `inspectRuntimeTerminalProcess` gives remote runtimes a 15s RPC timeout: any probe taking 4-15s silently killed a running remote command that Cmd+W used to prompt about, and the pane path now delegates its last-pane close to this guard. An unanswered probe is unknown, not idle, so the timeout raises the confirmation with every pty treated as a candidate. Failing open still applies to an *answered* probe (rejection, stale remote handle), which is the pre-existing pane behavior. - The split-pane Cmd+W probe had no bound at all; it now shares the same one, so the two paths give the same answer to the same question. - The renamed regression spec dropped its repro scaffolding: the hardcoded /tmp screenshot directory (also a cross-platform path violation) and the title/docblock that still described the bug as open.
📝 WalkthroughWalkthroughAdds a queued dialog for terminal tabs with running processes. Adds PTY inspection with timeout and confirmation handling. Integrates the guard with tab, pane, bulk, lifecycle, IPC, and web-runtime close paths. Adds agent-specific and command-specific dialog copy resolution. Adds unit, component, regression, and end-to-end coverage. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts (1)
473-483: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftReconcile
closeGroupcleanup with deferred terminal closing.
closeGroupcallscloseItem(item.id, { skipEmptyCheck: true }), then immediately runscloseEmptyGroup(worktreeId, groupId)andleaveWorktreeIfEmpty(). Terminal items receive nocloseTerminalTaboptions with this path, so a running process usescloseTerminalTab’s running-process confirmation instead of closing synchronously. If any terminal in the group remains open until after that confirmation, the emptiness cleanup happens too early and is not re-ran, which can leave an empty tab-group shell and keep the worktree active. Thread confirmation-appropriate options through and make the final cleanup wait for deferred closes, or makecloseEmptyGroup/leaveWorktreeIfEmptyself-correct afterward.
🧹 Nitpick comments (4)
src/renderer/src/components/terminal-pane/TerminalPane.tsx (1)
1332-1335: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueAlign the
unavailablecheck with the tab-level guard.
guardRunningTerminalClosetreats a probe result as busy only whenhasChildProcessesis true andunavailable !== true(running-terminal-close-guard.tslines 108-115). This pane path checks onlyprocess.hasChildProcesses.
inspectRuntimeTerminalProcesscurrently returnshasChildProcesses: falsealongsideunavailable: true, so the two paths agree today. If that contract changes, Cmd+W on a split pane will prompt while the tab-strip X closes silently. Mirror the guard's condition to keep the two decisions identical.♻️ Proposed consistency fix
if ( - !process.hasChildProcesses || + !process.hasChildProcesses || + process.unavailable === true || settings?.skipCloseTerminalWithRunningProcessConfirm ) {src/renderer/src/components/terminal/running-terminal-close-guard.test.ts (2)
49-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake
settleProberesilient to microtask-depth changes.
settleProbeawaits a fixed count of three microtask ticks. The count is tied to the current promise depth ofPromise.allSettled(...).then(...)inguardRunningTerminalClose.If the guard adds one more
awaitin that chain, these tests will stop settling the probe. Several assertions are negative (for exampleexpect(onClose).not.toHaveBeenCalled()at line 208), so they would still pass while no longer testing the intended path. Wait on the observable outcome instead of a tick count.♻️ Proposed condition-based settle helper
-async function settleProbe(): Promise<void> { - await Promise.resolve() - await Promise.resolve() - await Promise.resolve() -} +// Why: waiting on a fixed tick count silently breaks if the guard's promise depth changes. +async function settleProbe(): Promise<void> { + await vi.waitFor(() => { + expect( + visibleRequest() !== null || inspectRuntimeTerminalProcessMock.mock.settledResults.length > 0 + ).toBe(true) + }) +}Alternatively, keep the tick loop but bound it by a settled condition supplied per test.
86-91: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRestore real timers in
afterEach.Four tests call
vi.useFakeTimers()in the test body andvi.useRealTimers()before their assertions (lines 300-316, 318-334, 336-352, 354-371). Ifguard()oradvanceTimersByTimethrows,useRealTimers()never runs and fake timers leak into the next test.Add the reset to the existing
afterEachso cleanup does not depend on the happy path.♻️ Proposed cleanup
afterEach(() => { + vi.useRealTimers() const store = useRunningTerminalCloseConfirmStore.getState() while (visibleRequest()) { store.dismissRunningTerminalClose() } })src/renderer/src/components/terminal/terminal-tab-actions.ts (1)
105-118: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider renaming
resolvePinnedTabLabelfor its new generic use.Line 111 calls
resolvePinnedTabLabelto compute the tab label for the running-process dialog. This label resolver does not depend on pin state and is now used for any tab, pinned or not. The name is misleading at this call site.Rename the shared helper to something pin-agnostic, such as
resolveUnifiedCloseTabLabel, and update both call sites (terminal-tab-actions.tsandpinned-tab-close-guard.ts).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bae860b9-dfd8-4841-85fd-6b86495e4696
📒 Files selected for processing (22)
src/renderer/src/App.tsxsrc/renderer/src/components/Terminal.tsxsrc/renderer/src/components/tab-group/useTabGroupWorkspaceModel.tssrc/renderer/src/components/terminal-pane/CloseTerminalDialog.tsxsrc/renderer/src/components/terminal-pane/RunningTerminalCloseDialog.test.tsxsrc/renderer/src/components/terminal-pane/RunningTerminalCloseDialog.tsxsrc/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/components/terminal/running-terminal-close-guard.test.tssrc/renderer/src/components/terminal/running-terminal-close-guard.tssrc/renderer/src/components/terminal/terminal-close-confirm-keyboard-vs-mouse.test.tssrc/renderer/src/components/terminal/terminal-close-copy-kind.test.tssrc/renderer/src/components/terminal/terminal-close-copy-kind.tssrc/renderer/src/components/terminal/terminal-tab-actions.tssrc/renderer/src/components/terminal/terminal-tab-close-running-confirm.test.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/store/pinned-tab-close-guard.tssrc/renderer/src/store/running-terminal-close-confirm.test.tssrc/renderer/src/store/running-terminal-close-confirm.tstests/e2e/terminal-tab-close-running-confirm-mouse.spec.tstests/e2e/terminal-tab-close-running-confirm.spec.ts
…p from #10167 (#10142) Cross-referenced against @innocarpe's #10167, which solved the same issue. Two things it got right that this branch did not: - Queue actions now hold off for 350ms after a queued request replaces the visible one, matching the sibling pinned-tab confirmation. Without it the second click of a double-click aimed at one tab lands on the next tab's prompt and kills a running process the user never saw asked about — the exact bug class this PR exists to close. - The pty lookup unions the layout bindings with ptyIdsByTabId. A mounting pane is bound into the layout before the liveness map catches up, and the store's own teardown collector unions both for that reason, so reading only the map let a close slip through that window with no prompt. Also replaces the render-time ref write that failed React Doctor's "Ref mutated during render" rule: the queued-request checkbox reset now goes through CloseTerminalDialog's existing subject-change reset instead of remounting via key, which keeps the exit animation on one element. Co-authored-by: Orca <[email protected]>
…tab close path (stablyai#10142) (stablyai#12272) * test(repro): demonstrate stablyai#10142 tab X close bypasses running-process confirmation Unit repro: closeTerminalTab (the X-button/middle-click entry) never consults inspectRuntimeTerminalProcess and drops a tab with a live child. E2E repro: Cmd+W shows 'Stop running command?' for a tab running sleep 300; cancelling then clicking the tab X closes it silently. Co-authored-by: Orca <[email protected]> * fix(terminal): confirm running-process close on every tab close path (stablyai#10142) The tab-strip X button, middle-click and the tab context menu closed a terminal with a live child process without asking, while Cmd+W raised "Stop running command?" for the same tab. The probe lived only in TerminalPane's pane-level close handler; every mouse entry point reaches closeTerminalTab(), which guarded pinned tabs and nothing else. Move the decision into closeTerminalTab, above the web-runtime branch so paired/remote host-backed tabs are covered too, and give the last-pane keyboard close back to it instead of probing twice: - running-terminal-close-guard.ts probes every live PTY of the tab and fails open on a rejected probe or a stale remote handle, matching what Cmd+W already did. No live PTY ids => fully synchronous close, so idle, parked and hibernated tabs keep today's behavior. - shouldConfirmRunningTerminalClose keeps lifecycle echoes, bulk closes, CLI/RPC closes and the post-confirmation re-entry off the modal path. - A standalone confirm store drives RunningTerminalCloseDialog, which reuses the existing CloseTerminalDialog (no new user-visible strings). The request carries the tab label because a tab-strip close can target a tab the user is not looking at, and dedupes by tab id. - TerminalPane.handleRequestClosePane now delegates the last pane to closeTerminalTab. Its transport ptyId is nullable by design, so the old path silently skipped the prompt mid-reattach; the pane keeps its own probe only for closing one pane of a split. - Agent panes win the dialog copy when a split has both an agent and a plain command busy, instead of depending on PTY spawn order. - Tab-group closeItem ran leaveWorktreeIfEmpty synchronously after a close that can now defer; it moves to onClosed and still honors skipEmptyCheck. Co-authored-by: Orca <[email protected]> * fix(terminal): close the running-process confirmation gaps on every path (stablyai#10142) Follow-up hardening on the tab-close confirmation, from review of the first pass: - A pinned tab with `confirmClosePinnedTab` off never got the running-process prompt on any path, including Cmd+W, which is a regression against the old pane-level behavior: the pinned branch short-circuited on pinned-ness alone and re-entered with `force`, which the running guard excludes. The pin prompt now supersedes only when it will actually appear; with the setting off the close falls through to the running guard. - The probe chain had no `.catch`, so a throw in the decision (a copy-kind lookup on a tab id makePaneKey rejects, a store subscriber) left the tab silently unclosed with no user feedback. It now fails open, as the pane path it replaced did. - A wedged remote inspect RPC could leave the X button looking dead for its full 15s timeout. The probe is now bounded; every close path shares the bound, so keyboard and mouse still behave identically. - The agent-vs-command copy had two resolvers on exactly the keyboard/mouse seam this issue is about. terminal-close-copy-kind.ts is now the single policy; TerminalPane and the tab-strip guard both call it. - The running queue is async while the pinned queue is synchronous, so both could be pending at once and stack two modal overlays. The running dialog now waits for a visible pinned confirmation. - Deduping a repeat close request dropped the second caller's callbacks; it now folds them in, so both closes resolve from one prompt. Ticking "don't ask again" also drains queued prompts instead of showing one the user just opted out of, and a queued prompt no longer inherits the previous tab's tick. closeTerminalTab drops its private pinned predicate for the shared isUnifiedTabPinned, whose only consumer the previous commit had removed. * test(e2e): wait for `sleep` to own the terminal before closing it (stablyai#10142) The running-process close specs polled `hasChildProcesses` to decide the tab was busy, but macOS starts the shell under `login`, so an initialising terminal already reports a child before `sleep 300` runs. Both specs could therefore press close against a shell that never started the command: the probe correctly saw an idle terminal and closed without asking, and the adjudicated repro failed against a correct fix. Wait for `foregroundProcess === 'sleep'` instead. Assertions are unchanged, and the repro still fails at the pre-fix baseline (a92d8e0). * fix(terminal): ask instead of closing when the close probe times out (stablyai#10142) Round-1 review follow-ups. - The 4s probe bound closed the tab outright, but `inspectRuntimeTerminalProcess` gives remote runtimes a 15s RPC timeout: any probe taking 4-15s silently killed a running remote command that Cmd+W used to prompt about, and the pane path now delegates its last-pane close to this guard. An unanswered probe is unknown, not idle, so the timeout raises the confirmation with every pty treated as a candidate. Failing open still applies to an *answered* probe (rejection, stale remote handle), which is the pre-existing pane behavior. - The split-pane Cmd+W probe had no bound at all; it now shares the same one, so the two paths give the same answer to the same question. - The renamed regression spec dropped its repro scaffolding: the hardcoded /tmp screenshot directory (also a cross-platform path violation) and the title/docblock that still described the bug as open. * fix(terminal): adopt the double-activation guard and layout pty lookup from stablyai#10167 (stablyai#10142) Cross-referenced against @innocarpe's stablyai#10167, which solved the same issue. Two things it got right that this branch did not: - Queue actions now hold off for 350ms after a queued request replaces the visible one, matching the sibling pinned-tab confirmation. Without it the second click of a double-click aimed at one tab lands on the next tab's prompt and kills a running process the user never saw asked about — the exact bug class this PR exists to close. - The pty lookup unions the layout bindings with ptyIdsByTabId. A mounting pane is bound into the layout before the liveness map catches up, and the store's own teardown collector unions both for that reason, so reading only the map let a close slip through that window with no prompt. Also replaces the render-time ref write that failed React Doctor's "Ref mutated during render" rule: the queued-request checkbox reset now goes through CloseTerminalDialog's existing subject-change reset instead of remounting via key, which keeps the exit animation on one element. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Description
closeTerminalTab()guarded only pinned tabs — it never probed for running child processes. The running-process confirmation ("Stop running command?") lived exclusively in the pane-level keyboard path (TerminalPane.handleRequestClosePane→inspectRuntimeTerminalProcess), which only Cmd+W / Ctrl+W reached.Every mouse path bypassed it entirely:
SortableTabonClick→onClose→handleCloseTab→closeTerminalTab(tabId)SortableTabonAuxClick→ same chokepointSo Cmd+W on a tab running
npm run devasked first, but clicking the X on the same tab killed it silently.This PR moves the decision into
closeTerminalTabitself, so every interactive close path — X button, middle-click, tab context menu, tab groups, floating panel — inherits the exact same confirmation, with no per-call-site duplication.running-terminal-close-guard.ts(new) —shouldConfirmRunningTerminalClose()decides whether a close is an interactive user close (excludesforce,rejectPinned,reason: 'cleanup' | 'pty-exit',hostCloseReason: 'pty-exit',lifecyclePtyId), andguardRunningTerminalClose()probes the tab's live PTYs and either closes or raises the dialog.running-terminal-close-confirm.ts(new) — standalone zustand store mirroringpinned-tab-close-confirm's semantics (single visible request, FIFO queue, 350 ms double-activation guard, dedupe by tab id).RunningTerminalCloseDialog.tsx(new, mounted once inApp.tsx) — renders the existingCloseTerminalDialog. Zero new user-visible strings, so no i18n keys and no locale-catalog churn; wording and styling are byte-identical to what Cmd+W already showed, which is the whole point of the issue.TerminalPane's last-pane close now delegates tocloseTerminalTabinstead of running its own probe — that removes a duplicateinspectProcessround trip and makes a double prompt structurally impossible.skipRunningProcessConfirm: CLI/RPC close (useIpcEvents), the CLI pane-close fallback, and the paired-runtime bulk closes.useTabGroupWorkspaceModelmovedleaveWorktreeIfEmpty()intoonClosed— it was already wrong for the deferred pinned path.Fixes #10142
ELI5
Imagine you have a terminal running a long job. If you pressed Cmd+W to close it, Orca asked "hey, something's still running — really close?". But if you clicked the little x on the tab, or middle-clicked it, Orca just closed it and killed your job without a word. Same tab, same job, two different answers depending on how you closed it.
The check was written into the keyboard shortcut instead of into "closing a tab". This PR moves the check down to the one place all closing goes through, so it doesn't matter how you close the tab — you get the same warning either way. Nothing new to learn, no new buttons, and the existing "Don't ask again" checkbox now works for the mouse too.
Fix proof
Test file:
src/renderer/src/components/terminal/terminal-close-confirm-keyboard-vs-mouse.test.ts(the independently adjudicated repro, committed at
a92d8e0b0dasrepro-10142-close-confirm-keyboard-vs-mouse.test.ts; renamed only —git diff -M a92d8e0b0d HEADshows the assertions are byte-identical apart from a header comment and prettier reflow).BEFORE — run at the repro commit
a92d8e0b0d(parent = basef3e087ec06), materialized into a scratch tree:AFTER — this branch:
The two tests that already passed at base (the source assertion on
handleRequestClosePane, and the pinned-tab control) still pass — so the fix adds the mouse path rather than moving the keyboard one.Not tautological: re-verified during review by disabling the guard on this branch — the repro goes red again.
E2E, against real Electron (4/4 passing):
tests/e2e/terminal-tab-close-running-confirm.spec.ts— middle-click prompts + Cancel keeps the tab; Cmd+W raises exactly one dialog (the anti-double-prompt assertion).tests/e2e/terminal-tab-close-running-confirm-mouse.spec.ts— X applies the same confirmation as Cmd+W; confirming "Stop and Close" actually closes it.Plus 69 new unit tests across
running-terminal-close-guard.test.ts,terminal-tab-close-running-confirm.test.ts,running-terminal-close-confirm.test.ts,terminal-close-copy-kind.test.ts,RunningTerminalCloseDialog.test.tsx.Visual proof
Both sides ran the identical Playwright script in the same
electron-headlessproject at the same 1920×1170 viewport. BEFORE is a scratch build ofa92d8e0b0d(pre-fix); AFTER is this branch. The script starts a tab, runssleep 300, pollswindow.api.pty.inspectProcess()untilforegroundProcess === 'sleep', then closes the tab and dumps DOM state.Machine-read DOM state (printed by the run, not hand-written):
confirmDialogVisible: true, renderedTabCount: 1confirmDialogVisible: true, renderedTabCount: 1confirmDialogVisible: false, renderedTabCount: 0confirmDialogVisible: true, renderedTabCount: 1confirmDialogVisible: false, renderedTabCount: 0confirmDialogVisible: true, renderedTabCount: 1The Cmd+W row is identical on both builds, which is what makes the other two rows meaningful: the keyboard path did not change, the mouse paths did.
X button — busy tab → BEFORE (gone, no prompt) → AFTER (prompt, tab kept)
Middle-click — same three panels
Control: Cmd+W unchanged before and after
BEFORE — clicking X kills the busy tab silently:
before-x-button-closes-silently.webm
AFTER — clicking X raises the same prompt Cmd+W does:
after-x-button-shows-confirm.webm
AFTER — confirming really does stop the process and close the tab. This one is assertion-backed: it is the shipped spec
tests/e2e/terminal-tab-close-running-confirm-mouse.spec.ts› "confirming the X-button prompt closes the busy tab", recorded over 3/3 passing runs (the recorder refuses to keep a failing run):after-x-button-confirm-and-close.webm
Raw unpaired frames (same viewport both sides)
Busy tab, X hovered — BEFORE / AFTER:


After X click — BEFORE (tab gone) / AFTER (dialog):


After middle-click — BEFORE / AFTER:


After Cmd+W (control) — BEFORE / AFTER:


Regressions & trade-offs
Test evidence (no regressions found)
vitest run src/renderer/(whole renderer)vitest run src/shared/terminal,terminal-pane,tab-bar,floating-terminal,tab-group,store,useIpcEvents)pnpm run typecheck(node + cli + web)TS2322oxlint,audit:code-quality:native,audit:code-quality:type-aware --deny-warnings,lint:react-doctor:changedcheck:max-lines-ratchetmax-linesdisable or bump added.check:reliability-gates(62 gates)verify:localization-{catalog,extraction,coverage}terminal-panes.spec.tsgolden-core-flows.spec.tsterminal-tab-close-restart-persistence+daemon-generation-legacy-close-safetyTwo e2e specs flaked (
terminal-shortcuts.spec.ts,terminal-pane-close-layout-consistency.spec.ts), plus ahelpers/orca-app.ts:372fixture flake ("seeded e2e worktrees did not load"). All three were reproduced at basef3e087ec06at an equal or higher rate —terminal-shortcutsfailed 2/4 base runs vs 1/3 here, on the same test.helpers/orca-app.tsis untouched by this diff.Disclosed behavior changes
Closing a tab with the mouse is no longer synchronous. When a tab has live PTY ids, the close waits for one
inspectProcessround trip. Measured locally over 60 samples: p50 0.4 ms, p95 4.3 ms, max 20.2 ms; end-to-end X-button close 79–119 ms, dominated by input dispatch, not the probe. No perceptible local regression. On remote/SSH runtimes the probe crosses the relay, so a wedged link makes the X button appear dead for up to 4 s (RUNNING_CLOSE_PROBE_TIMEOUT_MS) before showing the dialog. Cmd+W already had this exposure; a mouse-only shorter timeout was deliberately rejected because it would recreate the very keyboard/mouse asymmetry this PR removes.Timeout asks rather than closes. If the probe does not answer within 4 s, we raise the dialog instead of silently closing. Unanswered ≠ idle — this was changed during review, since performing the destructive close on timeout would have reintroduced the bug on exactly the path this PR reroutes.
Fail-open on probe failure. A rejected probe (or
unavailable: true) is treated as idle and the tab closes without a prompt. This matches the pre-existing Cmd+W behavior verbatim; failing closed would make the X button do nothing at all, which is worse.Spurious prompt on a brand-new tab (macOS, pre-existing). For roughly the first ~0.5 s of a tab's life the daemon reports
foregroundProcess: 'login'→hasChildProcesses: true, so Cmd+T then immediately X shows "Stop running command?" on an idle shell (reproduced 4/4). This is existing probe behavior, but this PR promotes it onto the highest-frequency close path. Alogin/wrapper exclusion inisShellProcesswould remove it — filed as follow-up, not fixed here to keep the diff on-issue.Bulk closes intentionally keep today's silent behavior. Close Others / Close to Right / Close to Left / Kill All / CLI
orca terminal closestill drop running tabs without asking — prompting per tab would be a modal storm, and an aggregate "N terminals are running" dialog is a separate feature.Pinned still supersedes running. A pinned busy tab shows only "Close pinned tab?" — exactly one dialog, preserving today's documented precedence, but the user is not told a command is running.
No probe dedupe. Six rapid X-clicks issue six concurrent probes (measured). The dialog is deduped by tab id, so the user sees one prompt; the extra probes are harmless locally but wasteful on a slow relay. An in-flight
Mapwould collapse them — follow-up.Two dialog hosts remain.
TerminalPane's pane-levelpendingCloseConfirmationstill handles closing one pane of a split; the new store-driven host handles whole-tab closes. Both render the sameCloseTerminalDialog, and theskipRunningProcessConfirmhandoff guarantees only one can open per user action.Known follow-up flagged by the release scan (not fixed here)
useTabGroupWorkspaceModel.closeGroupcallscloseItem(id, { skipEmptyCheck: true }), which is the one bulk caller not givenskipRunningProcessConfirm. With busy terminals in the group, "close split pane" can now show one dialog per busy tab, andcloseEmptyGroup/leaveWorktreeIfEmptyrun before those closes land. This is disclosed rather than hidden; it wants a one-line flag plus a "bulk paths never prompt" regression test. Happy to fold it into this PR if a reviewer prefers that to a follow-up.Perf
Verdict: MINOR. No render fan-out, no polling, no new FS/git/network work, no new synchronous IPC.
check:zustand-selector-fanout(--check, exit 0): 2,500 subscribers × 2,000 unrelated writes = 5,000,000 selector runs, median 32.98 ms, 0 render invalidations. The always-mountedRunningTerminalCloseDialogand the new store add zero invalidations — all four subscriptions are narrow scalar/action reads with no object literals in selectors.TerminalPaneno longer probes separately for the last-pane close.handleRequestClosePane's dep array shrank (droppedworktreeId,tabId), so fewer callback recreations.setTimeouthas a matchingclearTimeouton both the.thenand.catcharms; adecidedlatch prevents double-resolution.closeTerminalTabcall sites enumerated — no surviving guarded one is a loop or background path.Costs are items 1 and 7 above.
Release scan
Verdict: PASS-WITH-NOTES. No P0.
Cleared explicitly:
closeTerminalTabafter confirmation rather than continuing inline, so pin/route/precomputed state is revalidated against fresh state after an arbitrarily long dialog.Promise.allSettlednever rejects; the 4 s probe timeout; a.catchthat force-closes if raising the dialog throws), all arbitrated by onedecidedlatch.RunningTerminalCloseDialogis mounted inApp.tsx, which is the render root for both the Electron renderer and the paired-web root, so no surface can raise a request with no dialog to answer it.skipRunningProcessConfirm/rejectPinned.skipCloseTerminalWithRunningProcessConfirmsetting, no migration, rollback-safe.exec/eval, no new logging, no network sinks.metaKeyhardcoding introduced; the Cmd+W chord still resolves throughterminal-shortcut-policy.tswith an explicitplatformargument, and the e2e spec branches onprocess.platform. No path handling added. Folder workspaces are safe (the guard keys only offptyIdsByTabIdand the unified tab model, never git-worktree state). Nothing provider-specific touched.P1/P2 notes are the tab-group
closeGroupgap and the latency/false-prompt items already listed under Regressions & trade-offs, plus one narrow divergence: the guard treatsunavailable: true(daemon protocol < 11) as idle whileTerminalPanetreats it as busy — the two should read it the same way.Review loop
Reviewed 2 times until clean — verdict: "Merge-ready. The repro's assertions are provably unmodified, and I confirmed the repro still fails when the guard is disabled, so it is not tautological. The fix routes every interactive close path through one shared guard in
closeTerminalTabwhile explicitly opting out every caller that cannot wait on a modal (CLI/RPC, lifecycle echoes, bulk closes), and it removes the duplicate probe fromTerminalPane's last-pane path rather than leaving two competing policies. All 4 e2e specs pass against real Electron, 69 new unit tests pass, ~6,500 tests across the touched areas pass, and typecheck, oxlint, the max-lines ratchet, and all three localization gates are clean. No new user-visible strings were added, so there is no i18n gap. Remaining items are UX/coverage follow-ups, not merge blockers."Round 1 raised 2 blocking issues, both fixed in
f2cf1cbd35/14092a02e5: the probe timeout performed the destructive close (now it asks), and the e2e spec wrote screenshots to a hardcoded scratch dir with a stale "bug is unfixed" docblock.Credits
Cross-referenced against #10167 by @innocarpe, which independently solved the same
issue and reached the same core design: move the decision into
closeTerminalTabso everyclose path shares one policy, raise it through a store-driven dialog reusing
CloseTerminalDialog, and haveTerminalPanedelegate its last-pane close instead ofprobing twice. That convergence is a good sign for the approach.
Two things #10167 got right that this branch did not, now adopted in
47c02a3489:running-terminal-close-confirm.ts) —a queued request replaces the visible one in place, so the second click of a double-click
aimed at one tab would land on the next tab's prompt and kill a running process the user
never saw asked about. fix(terminal): confirm running process on tab X / middle-click close #10167 mirrored the sibling
pinned-tab-close-confirmslice here;this branch had the guard in its description but not in its code.
running-terminal-close-guard.ts) — a mountingpane is bound into
terminalLayoutsByTabIdbeforeptyIdsByTabIdcatches up. fix(terminal): confirm running process on tab X / middle-click close #10167fell back to the layout when the map was empty; this branch now unions both, matching
the store's own
collectPtyIdsForTabteardown collector. Reading only the map let aclose slip through that window with no prompt.
Where this PR goes further, and why it is the one being merged:
reason !== 'pty-exit' && !force,so
reason: 'cleanup'teardowns,rejectPinnedCLI closes,hostCloseReasonechoes,lifecyclePtyIdcloses and bulk "Close Others" would each raise a modal — several fromcallers that are answered synchronously and cannot wait on one.
shouldConfirmRunningTerminalCloseenumerates and tests all seven.
full 15 s RPC timeout; the 4 s bound raises the prompt rather than leaving the X button
looking dead.
unavailableremote handles fail open, and copy resolution is scoped to the PTYs thatactually reported a child, so an idle agent pane in a split cannot mis-word the prompt.
confirmClosePinnedTaboff the pin prompt saysnothing, so a busy pinned tab still gets asked rather than silently closing.
Closing #10167 in favour of this PR — thanks @innocarpe for the analysis and for the two
fixes adopted here.
Made with Orca 🐋