Skip to content

fix(terminal): keep a pane closed just before quit from coming back on relaunch - #25711

Merged
Jinwoo-H merged 4 commits into
mainfrom
fix/closed-pane-resurrection
Oct 6, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
fix/closed-pane-resurrection

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​336 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​334
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15

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 daemon (terminal-host-session-listing.ts): once the daemon accepts a kill for a session, listSessions reports that session as state: 'exiting'. It stays isAlive: true because the process really is still running. 'exiting' was already a value of the wire SessionState type; nothing emitted it before.
  • App inventory (daemon-pty-session-inventory.ts, pty-process-list-admission.ts, pty-process-info.ts, pty:listSessions in inspect.ts, pty-listed-session.ts): an optional exiting: true is carried through to the renderer's session list.
  • Worktree activation gate (worktree-agent-activation-gate.ts): this is the code that gives live, unowned PTYs a tab on startup. It now skips PTYs marked exiting, 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:

  • Hide closing sessions from listSessions entirely. This is smaller and would also fix older app builds. But listSessions also 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 report exited for a process that is still running, which is exactly what docs/reference/ssh-execution-boundary.md rules out. With exiting, the session stays live for those readers.
  • Have the app skip sessions it remembers closing. The app's record of the close can be lost in the same quit race, and it would add a second, app-side source of truth for something the host owns.

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's terminal.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 on main with a 4 s wait before quit: 3/3 passed, so the test catches this race and nothing else.
    • This branch: 0 failures in 30 runs (3 + 15 + 12) with no wait before quit. The daemon log shows the closed session killed once and never created again.
  • Unit and integration tests, each confirmed to fail without the fix:

    • terminal-host-closing-session-listing.test.ts: immediate and graceful kills list as exiting until the process exits; a refused kill signal lists as running again.
    • 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 as exiting: true and later sees it gone.
    • Activation gate: never adopts an exiting PTY but still adopts its live sibling.
    • Admission and pty:listSessions pass exiting through.
  • Terminal layout parity check (terminal-layout-parity-check runner, 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 over src/main/daemon, src/main/providers, src/main/ipc/pty, and the activation libs passes, except repro-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:

  • New app with an old daemon (including an adopted daemon from before the update on the same protocol v39): no exiting is sent, so behavior is unchanged and the race can still happen until that daemon is replaced.
  • Old app with a new daemon: 'exiting' was already in the SessionState union old clients compile against, and no reader branches on state, so behavior is unchanged.
  • No daemon protocol bump is needed. The change adds a value to an existing field and an optional field; nothing about shell launch changes.
  • SSH relay inventories never set exiting, so they behave exactly as before.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Mobile/web clients use a different adoption path: orphan recovery from the runtime's 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.
  • Performance: no added work. The flag is read from data the daemon already sends.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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]>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 84613c21-4147-4977-8d24-393db75673db
📥 Commits

Reviewing files that changed from the base of the PR and between 7ef0283 and 5511887.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63ae318a-6b95-4423-ae91-6e7dff99b259
📥 Commits

Reviewing files that changed from the base of the PR and between 6398173 and 7ef0283.

📒 Files selected for processing (1)
  • tests/e2e/terminal-closed-pane-quit-relaunch.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

PTY 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 7ef02

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 Review

Security architecture risk: 🔵 Low · up to 0245a

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected behavioral change concerns listed PTYs selected by provider scope and workspace identity. It reduces which sessions are offered for adoption rather than adding a new execution or privilege-granting operation.

Trust Boundaries and Controls

  • observed — The marker originates in host-owned termination state rather than terminal output or renderer input. Inventory continues validating live agent-owner bindings, and admission retains identity validation, owner-to-PTY matching, and capacity limits.

Resilience and Maintainability Implications

  • observed — The separate runtime recovery contract has no exiting field. Its inspected consumer constructs adoption claims using terminal handle, PTY ID, and incarnation ID. This establishes distinct recovery semantics, but does not establish whether final host-side adoption rejects a terminating session.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preventing a pane closed just before quitting from reappearing after relaunch.
Description check ✅ Passed The description covers the required sections with a clear explanation of the change, rationale, testing, compatibility, and visual-proof status. It also explains that the linked issue is not applicabl…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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: listLiveTerminalHostSessions now reports state: 'exiting' for a session whose kill was accepted (session.isTerminating), while keeping isAlive: true. Verified nothing else emits or branches on SessionState — no daemon reader keys on state, and shutdownIfIdle/liveness readers use presence, so this is inert apart from the new flag.
  • Inventory plumbing: daemon-pty-session-inventory.ts maps state === 'exiting' to exiting: true; PtyProcessInfo, PtyProcessListAdmission, pty:listSessions, and PtyListedSession all carry the optional field through. New optional field only, so wire-safe.
  • Adoption gate: worktree-agent-activation-gate.ts filters exiting PTYs out of adoptablePtyIds while keeping them in liveWorkspacePtyIds for 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).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit ce4c99a into main Oct 6, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant