Skip to content

fix(terminal): closing a tab is never a silent no-op - #27132

Merged
OrcaWin merged 1 commit into
mainfrom
np/p395-ct-a2-close-never-noop
Oct 10, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
np/p395-ct-a2-close-never-noop

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​121 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​121
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43

ELI5

Sometimes clicking × on a terminal tab did nothing. The app didn't yet know which machine the tab belonged to, so it gave up without a word. Now the close always happens: it asks the tab itself which machine it runs on, and if nothing knows, it still closes the tab here.

What Changed

  • Before:
    • closeTerminalTab resolved the tab's host from the worktree catalog. Before the catalog hydrated, after a failed worktree scan, or with an ambiguous legacy runtime, there was no route, so it called onCancel and returned. The tab-strip × passes no onCancel, so the click looked lost.
    • Separately, closeUnifiedTab returned null when the tab's group record was missing, so no close path could remove that tab.
  • After:
    • The close route comes from the catalog first. Otherwise it comes from the one host the tab's own PTY ids name (a remote:<env>@@<handle> id names its paired server), and otherwise from the host recorded on its unified tab.
    • With no host at all, the tab is still pruned locally, and main still records the close through the normal path.
    • A tab whose group record vanished is removed. wasLastTab is then computed from the worktree's remaining tabs.
  • Mechanism:
    • New resolveTerminalCloseRoute(state, worktreeId, tabId) in src/renderer/src/lib/terminal-close-route.ts. It reuses getPtyExecutionHost and the retirement plan's PTY-id collector (now exported), so no new PTY-id parsing is added.
    • In tabs-close-actions.ts, every group read is optional and the order falls back to the worktree's tabs.

Why

  • The early return protected nothing. Per-PTY teardown already fails closed for a host it cannot prove (buildTerminalTabRetirementPlan uses the strict teardown owner), so a local prune never kills another host's process.
  • Closing on the host the PTY id names is what spawn and teardown already treat as authoritative.
  • No group repair inside close. The tab is leaving, and changing groups during a close widens the change for no gain.
  • Bulk "close others / to the right" still require a routed worktree. Their per-tab routing is a separate change.

Linked Issue

Fixes #11308

Also covers the routing half of #11800 and #17767. Those stay open for their host-side parts.

Visual Proof

N/A: the change is that a click which did nothing now closes the tab. This is covered by unit tests on the exact states from the issue.

Testing

  • New terminal-tab-actions-unrouted-close.test.ts:

    • with an unhydrated catalog and a remote:env-1@@h PTY, the host close is sent to env-1;
    • with no host at all, the tab is still closed locally.
  • New tabs-close-dangling-group.test.ts: terminal and editor tabs with a missing group are removed, and wasLastTab is correct.

  • All five new tests fail on origin/main.

  • Renderer terminal, tabs-slice, retirement and route suites pass (5579 tests). pnpm tc, oxlint, and pnpm run check:code-quality:changed pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

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 wire change. SSH: an ssh: PTY id routes to the local/SSH path exactly as a resolved SSH worktree does. Folder workspaces: the catalog route and the unified-tab host cover folder keys. Windows: no paths involved.

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)

Clicking x did nothing when the worktree catalog had not hydrated yet or
the tab's group record was missing. The close now routes by the host the
tab's own PTY ids (or unified tab) name, and with no host at all still
prunes locally and reaches main's close record; per-PTY teardown already
fails closed for an unproven host. closeUnifiedTab closes a tab whose
group record is gone instead of returning null.

Fixes #11308
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

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: fb3f1b97-a345-48ae-948e-7e779040ceb1

📥 Commits

Reviewing files that changed from the base of the PR and between 8ba3cf4 and ef6f649.


📒 Files selected for processing (6)
  • src/renderer/src/components/terminal/terminal-tab-actions-unrouted-close.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.ts
  • src/renderer/src/lib/terminal-close-route.ts
  • src/renderer/src/store/slices/tabs-close-dangling-group.test.ts
  • src/renderer/src/store/slices/tabs/tabs-close-actions.ts
  • src/renderer/src/store/slices/terminal-tab-retirement.ts

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



📝 Walkthrough

Walkthrough

Terminal tab closing now resolves routes from available host information and continues local closing when no route is available. Unified tab closing now handles tabs whose group record is missing by using the worktree’s tab order. Tests cover both close paths.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to ef6f6

The changed close paths have no established issue requiring a fix before merge.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 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 and concisely describes the primary change: terminal tab closing no longer becomes a silent no-op.
Description check Passed The description follows the required template and explains the user impact, implementation, rationale, linked issue, visual proof, tests, compatibility considerations, and checklist status. It notes t…
Linked Issues check Passed Issue #11308 requires both silent-close paths to remove tabs. resolveTerminalCloseRoute keeps catalog routing, adds PTY-host and unified-tab host fallbacks, and allows local pruning when no host is …
Out of Scope Changes check Passed The changed production code and tests support issue #11308. The route helper, exported PTY collector, close-path changes, and dangling-group tests are directly connected to the reported failures. No u…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • 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.

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.

[Bug]: Closing a tab is sometimes a silent no-op

1 participant