Skip to content

fix(terminal): a background tab whose process exits closes as a process exit, not a user close - #34083

Merged
nwparker merged 1 commit into
mainfrom
nwparker/terminal-parked-exit-reason
Oct 26, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/terminal-parked-exit-reason

Conversation

@nwparker

@nwparker nwparker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

ELI5

When a terminal tab you weren't looking at had its program exit, for example because its WSL distro was shut down, Orca closed it as if you had clicked Close. That threw away the terminal's saved session, so it couldn't come back. Now that exit is recorded as what it is: a process exit.

What Changed

  • Before: the background ("parked") tab watcher closes a tab whose only process exited with closeTerminalTab(tab, { hostCloseReason: 'pty-exit' }). For a local tab, closeTerminalTab passed no reason to closeTab, which defaults to 'user'. So a process exit wrote a user-close tombstone, committed close_tab in main and retired the tab's session. The same exit in a visible tab uses reason: 'pty-exit' and does none of that.
  • After: the local branch of closeTerminalTab uses 'pty-exit' when the caller passed only hostCloseReason: 'pty-exit'. The background tab closes the same way a visible one does.
  • Why the fix is in closeTerminalTab and not the watcher: the watcher sends only hostCloseReason on purpose. Passing reason: 'pty-exit' from the watcher would skip the pinned-tab confirmation that closeTerminalTab applies to every other reason. A test (keeps the pinned confirmation guard for a hostCloseReason pty-exit close) holds that guard. Paired-host closes still carry no local reason, as before.

Why

Found in verify-15a (5e): wsl --terminate killed a background bridge tab's shell. The tab was closed as a user close, its session was retired, and the next launch opened a new session even though the old checkpoint was still on disk. The follow-up PR keeps such tabs entirely when the distro itself is gone. This one makes any background process exit stop posing as a user close.

Linked Issue

Internal: WSL via orcad, verify-15a 5e.

Visual Proof

N/A. This changes the close reason recorded for a background tab whose process exits, with no visible difference. Covered by unit tests.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated: terminal-tab-actions-unrouted-close.test.ts checks that a local tab closed with hostCloseReason: 'pty-exit' reaches closeTab with reason: 'pty-exit'. It fails without the fix, and I ran it that way. The existing pinned-guard test still passes.
  • pnpm tc:web, the touched terminal-tab suites (87 tests) and check:code-quality:changed pass.

User risk: low. It affects any user whose background terminal's process exits. The tab still closes as before; only the recorded reason changes, from "user" to "process exit". A tab closed this way is no longer recorded as one the user chose to close.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only. No SSH, wire or platform-specific change.

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)

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

When closing a local terminal tab, the close path uses pty-exit when reason is absent and hostCloseReason is pty-exit. An explicit reason takes precedence. A test checks this behavior when the lifecycle PTY ID matches the tab’s PTY ID.

Priority: Normal

Merge Risk: Low · up to d02dd

A narrow last-tab process-exit path can produce incorrect worktree successor selection; fix before or shortly after merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the actual fix: a background terminal tab whose process exits is now closed with a process-exit reason instead of a user close. The raw summary confirms the change to closeLocalTermina…
Description check Passed The description follows the template and covers ELI5, What Changed, Why, Testing, Visual Proof (N/A with reason), Notes, and Checklist. It explains the before and after behavior and the mechanism, and…
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.
Full details: Title check

Explanation

The title names the actual fix: a background terminal tab whose process exits is now closed with a process-exit reason instead of a user close. The raw summary confirms the change to closeLocalTerminalTabState and the local close branch, so the title matches the main change. It is specific, but it does not mention the close-reason mechanism in detail, and the 94-character length is long for a title.

Full details: Description check

Explanation

The description follows the template and covers ELI5, What Changed, Why, Testing, Visual Proof (N/A with reason), Notes, and Checklist. It explains the before and after behavior and the mechanism, and it justifies the approach over moving the fix into the watcher. The Linked Issue section does not link a GitHub issue. It cites an internal reference (verify-15a 5e) instead, and the template asks outside contributors to link an actual issue. The AI Disclosure and Review sections are empty. The manual testing box is unchecked, and the lint/typecheck/test/build checklist item is unchecked. The description also says the test fails without the fix, which is a useful testing detail.

Resolution

Consider these additions: a real linked issue (or confirm the contributor is a stablyai maintainer and no issue is needed), a clear statement on whether manual testing was done, and confirmation that pnpm lint, typecheck, test, and build pass, since that checklist item is unchecked. Also fill in or remove the empty AI Disclosure and Review sections.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · 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.

@blacksmith-sh

This comment has been minimized.

@nwparker
nwparker force-pushed the nwparker/terminal-parked-exit-reason branch from e23e5fe to d02ddb5 Compare October 26, 2026 22:11

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Use the resolved PTY-exit reason for last-tab deselection. · terminal-tab-actions.ts:228

src/renderer/src/components/terminal/terminal-tab-actions.ts:228
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the resolved PTY-exit reason for last-tab deselection.

The parked PTY watcher passes only hostCloseReason: 'pty-exit'. The close function resolves that reason for local closure, but this branch checks only options.reason. For the last renderable tab, this can treat a process exit as a user clear and select the wrong worktree successor.

🐛 Suggested fix
+  const resolvedCloseReason =
+    options?.reason ?? (options?.hostCloseReason === 'pty-exit' ? 'pty-exit' : undefined)
   closeLocalTerminalTabState(terminalTabId, {
-    reason: options?.reason ?? (options?.hostCloseReason === 'pty-exit' ? 'pty-exit' : undefined),
+    reason: resolvedCloseReason,
...
-          } else if (options?.reason === 'pty-exit') {
+          } else if (resolvedCloseReason === 'pty-exit') {

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d7648c99-120b-4292-a007-cc19ca71c2d1
Commits

Reviewing files that changed from the base of the PR and between b2270cd and d02ddb5.

Files selected for processing: 2
  • src/renderer/src/components/terminal/terminal-tab-actions-unrouted-close.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.ts

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

…-exit, not a user close

The parked watcher passes only hostCloseReason 'pty-exit' (so the pinned
guard still applies), and the local branch then let closeTab default the
reason to 'user': a process exit wrote a user tombstone and retired the
session. The local close now carries the pty-exit reason.

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/terminal-parked-exit-reason branch from d02ddb5 to be887d7 Compare October 26, 2026 22:39
@nwparker
nwparker merged commit 1d1c6da into main Oct 26, 2026
39 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