Repository navigation
fix(terminal): keep a pane closed just before quit from coming back on relaunch - #25711
Conversation
…n relaunch The daemon now lists a session whose kill it accepted as state 'exiting' (still live), the inventory carries that through to pty:listSessions, and the worktree activation gate never adopts an exiting PTY into a new tab. Co-Authored-By: Claude <[email protected]>
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughPTY session listings now mark sessions as exiting after accepted termination and preserve that marker through inventory and IPC. The activation gate excludes exiting PTYs from surface adoption while retaining them for recovery and ownership checks. Tests cover pending termination, refused kills, adapter relaunch, and an end-to-end closed-pane relaunch. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The change prevents a pane closed just before quitting from being adopted on relaunch while retaining its live-session information for recovery. No actionable merge-blocking issue was established. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change prevents closed terminals from reopening without visibly expanding permissions or access. Risk is low, with remaining uncertainty around older versions and other recovery paths. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 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.
✅ No new issues found.
Reviewed changes — the exiting signal threaded from the terminal daemon to the renderer so a pane closed during the daemon's kill grace is not re-adopted on relaunch.
- Daemon listing:
listLiveTerminalHostSessionsnow reportsstate: 'exiting'for a session whose kill was accepted (session.isTerminating), while keepingisAlive: true. Verified nothing else emits or branches onSessionState— no daemon reader keys onstate, andshutdownIfIdle/liveness readers use presence, so this is inert apart from the new flag. - Inventory plumbing:
daemon-pty-session-inventory.tsmapsstate === 'exiting'toexiting: true;PtyProcessInfo,PtyProcessListAdmission,pty:listSessions, andPtyListedSessionall carry the optional field through. New optional field only, so wire-safe. - Adoption gate:
worktree-agent-activation-gate.tsfiltersexitingPTYs out ofadoptablePtyIdswhile keeping them inliveWorkspacePtyIdsfor liveness and sleeping-agent claims — matching the "still live, not restorable" contract. - Tests: exact assertions (no tautologies). Ran the four new/changed main-side specs (21 tests) and the gate spec (39 tests) locally — all pass.
Two notes, neither actionable: paired mobile/web clients recover orphans from the runtime's terminal.list, which this PR deliberately does not filter (already documented as a follow-up), and the fix's protection depends on the new daemon, so an app update that adopts a pre-existing daemon still carries the old behavior (also documented).
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

ELI5
When you close a terminal pane, Orca asks its background terminal service to stop that shell. On macOS that stop takes about two seconds. If you quit Orca during those two seconds and open it again, the reopened app asked the service "which terminals are running?", saw the one still shutting down, and gave it a new tab, which then started a fresh shell. The pane you closed came back. Now the service says "this one is shutting down", and the reopened app leaves it alone.
What Changed
Before: on macOS, close a pane (⌘W) and quit within about 2 s. On relaunch you get an extra tab with a new shell where the closed pane used to be. The e2e repro below fails 10 out of 10 times on
main.After: the closed pane stays closed. You get the same tab and panes you had at quit, the panes you kept reattach with their scrollback, and the terminal service no longer has a process under the closed id.
How it works:
terminal-host-session-listing.ts): once the daemon accepts a kill for a session,listSessionsreports that session asstate: 'exiting'. It staysisAlive: truebecause the process really is still running.'exiting'was already a value of the wireSessionStatetype; nothing emitted it before.daemon-pty-session-inventory.ts,pty-process-list-admission.ts,pty-process-info.ts,pty:listSessionsininspect.ts,pty-listed-session.ts): an optionalexiting: trueis carried through to the renderer's session list.worktree-agent-activation-gate.ts): this is the code that gives live, unowned PTYs a tab on startup. It now skips PTYs markedexiting, so it no longer creates the extra tab. Exiting PTYs still count as live work for the gate's "don't start a second agent" checks.Daemon log from a failing run on
main: the first app's kill finishes at 57.883, and 3 ms later the relaunched app's adopted tab creates a new shell under the same id. Its own kill-and-respawn creates it again at 57.924.Why
The daemon is the only party that knows a kill is under way, so it should publish that fact. Two other approaches were considered and rejected:
listSessionsentirely. This is smaller and would also fix older app builds. ButlistSessionsalso feeds liveness checks:verifyUnstoppedPtys(should workspace removal be blocked because a process is still running?),shutdownIfIdle, and the Claude live-PTY gate. A session the daemon cannot kill stays "terminating" forever. Hiding it would reportexitedfor a process that is still running, which is exactly whatdocs/reference/ssh-execution-boundary.mdrules out. Withexiting, the session stayslivefor those readers.I also did not make the daemon refuse to recreate a session id it had just killed. The pane-respawn flow from #18046 depends on creating a session under its own id while the old one is still being torn down, and it has a test for that. Once the extra tab is no longer adopted, nothing sends that create in this race.
Linked Issue
N/A (maintainer; found while investigating restart save races).
Visual Proof
N/A for screenshots. The user-visible effect is one tab instead of two after a restart, and the e2e spec checks exactly that through the tab strip DOM (
[data-testid="sortable-tab"]count), the visible pane count, and the host'sterminal.list.Testing
New e2e
tests/e2e/terminal-closed-pane-quit-relaunch.spec.ts: split into 3 panes, write a marker in each, close one with the real chord (⌘W / Ctrl+Shift+W), quit right away, relaunch. It checks for 1 tab and 2 panes, that each kept pane still shows its marker, and that the host lists exactly the kept PTYs.main(086b06c, and again at 9def4b9): 10/10 failed (2 tabs). Control onmainwith a 4 s wait before quit: 3/3 passed, so the test catches this race and nothing else.Unit and integration tests, each confirmed to fail without the fix:
terminal-host-closing-session-listing.test.ts: immediate and graceful kills list asexitinguntil the process exits; a refused kill signal lists asrunningagain.daemon-pty-adapter-closing-session-inventory.test.ts: a real daemon server, a kill whose client disconnects mid-kill, then a new client lists the session asexiting: trueand later sees it gone.pty:listSessionspassexitingthrough.Terminal layout parity check (
terminal-layout-parity-checkrunner, base 086b06c vs this head): PASS on all 8 journeys.pnpm tc,typecheck:e2e(new spec clean), oxlint, oxfmt,check:code-quality:changed: all pass. vitest oversrc/main/daemon,src/main/providers,src/main/ipc/pty, and the activation libs passes, exceptrepro-13767-shell-ready-marker-lost-to-exec.test.ts, which fails the same way on the base commit on this machine.Tested on macOS only. The daemon change has no platform-specific code: every kill path (immediate plain shell, graceful plain shell, agent sweep, and the Windows taskkill sweep) claims termination the same way.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Compatibility:
exitingis sent, so behavior is unchanged and the race can still happen until that daemon is replaced.'exiting'was already in theSessionStateunion old clients compile against, and no reader branches onstate, so behavior is unchanged.exiting, so they behave exactly as before.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
terminal.list. This PR does not filter that path, and it is a possible follow-up if the same race shows up from a paired client.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)