Skip to content

fix(terminal): prune explicitly-killed SSH tabs on create - #10365

Closed
innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/prune-killed-ssh-terminal-tabs
Closed

innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/prune-killed-ssh-terminal-tabs

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Mark PTY/session ids as retired when spawn fails with TerminalKilledError or when the user closes a tab (cleanup/user).
  • Treat retired ids as non-reconnectable in orphan detection so createTab permanently sweeps dead serve-* tabs that still have a stale ptyId.
  • Keeps sleep/reattach wake hints working for non-retired sessions.

Fixes #10342.

Why

Phantom SSH tabs showed Session "serve-…" was explicitly killed and reappeared after close when a new terminal was opened. Orphan cleanup treated any non-null tab.ptyId as reconnectable, so killed sessions never got swept.

Test plan

  • terminal-orphan-helpers + terminal-retired-session-ids + pty-transport (91 tests)
  • Manual: kill remote serve session → open new terminal → dead tabs pruned; close dead tab → create terminal → stay gone

Screenshots

No visual chrome change.

ELI5

Closed or killed SSH terminal tabs sometimes came back as phantoms when you opened a new terminal. Explicitly killed sessions are marked retired so create permanently cleans them up.

Dead serve-* sessions leave tab.ptyId set, so orphan cleanup treated them
as still reconnectable. Closing them could also fail to stick when a later
createTab rebuilt from that stale wake hint.

Mark sessions retired on TerminalKilledError and on user/cleanup closeTab,
and treat retired ids as non-reconnectable so the next createTab sweeps
phantom tabs permanently.

Closes stablyai#10342
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an in-memory registry for retired terminal session IDs. Explicitly killed PTY sessions and session IDs associated with closed tabs are recorded as retired. Reconnectable PTY detection now excludes retired IDs, and tests cover single, bulk, empty, retired, and non-retired session cases.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, rationale, testing, and screenshots, but omits required AI Review Report, Security Audit, and Notes sections. Add the missing AI Review Report, Security Audit, and Notes sections, and confirm cross-platform compatibility checks in the review.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements #10342 by retiring killed/closed session IDs and making orphan cleanup remove stale serve-* tabs while preserving wake hints.
Out of Scope Changes check ✅ Passed The changes stay focused on terminal retirement/orphan cleanup and tests, with no clear unrelated code paths added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly reflects the main change: handling explicitly-killed SSH terminal tabs during creation/orphan cleanup.

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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 14fefdb7-5c8c-405a-9042-1927ce9549ca

📥 Commits

Reviewing files that changed from the base of the PR and between 1bd36ce and 7eff2d2.

📒 Files selected for processing (6)
  • src/renderer/src/components/terminal-pane/pty-transport.ts
  • src/renderer/src/store/slices/terminal-orphan-helpers.test.ts
  • src/renderer/src/store/slices/terminal-orphan-helpers.ts
  • src/renderer/src/store/slices/terminal-retired-session-ids.test.ts
  • src/renderer/src/store/slices/terminal-retired-session-ids.ts
  • src/renderer/src/store/slices/terminals.ts

@AmethystLiang
AmethystLiang requested a review from OrcaWin July 24, 2026 16:49
CodeRabbit: cold reattach can leave retired serve-* ids in ptyIdsByTabId.
@innocarpe

Copy link
Copy Markdown
Contributor Author

Closing this stale PR because issue #10342 is now completed by the merged upstream fixes #16752 and #16969, which cover the SSH close-tombstone and reconnect persistence paths more completely than this earlier prune-on-create approach. Thank you to the maintainers and contributors for landing the fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phantom terminal tabs survive close and are restored from persisted layout state (SSH host)

2 participants