fix: stop remote tmux detach adding a second replacement terminal

Merged
TE
1mo ago
+5-1

Main is red (#19109): LastSurfaceClosePreferenceTests remoteTmuxWindowCloseKeepsWorkspaceOpenWhenKeepWorkspaceOpenPreferenceIsEnabled, remoteTmuxWindowCloseKeepsWorkspaceOpenImmediatelyForShortcut and remoteTmuxWindowCloseCreatesReplacementWhenOnlyMainWindowWouldBeEmpty fail with panels.count → 2 == 1 in app-host shard 2/7.

Cause: #18645 (feat(cli): list and attach remote tmux sessions, @austinywang) added repairRetiredRemoteTmuxContainerPanelsAfterDetach() to detachRemoteTmuxMirrorKeptOpenLocallyIfNeeded(), which creates a replacement terminal whenever the workspace is empty. The last-surface close path calls detach on an already-empty workspace and then creates its own replacement, so a kept-open remote tmux workspace ends up with two terminals. The Dock surface-move path has the same double.

Fix: the repair only creates a replacement when it removed retired panels itself. detachingMirrorReplacesRetiredContainerWithUsableTerminal (the #18645 test) still gets its replacement; callers that detach an already-empty workspace keep creating exactly one.

Not built locally (machine rule); full CI dispatched on this branch.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes kept-open remote tmux workspaces ending up with two terminals when closing the last surface. Detaching an already-empty workspace (last-surface close, Dock surface moves) now creates only one replacement; the repair only adds its own replacement when it actually removed the last panels.


[!NOTE]
Low Risk
Narrow change to remote tmux mirror detach and replacement-terminal creation; no auth or data-handling impact.

Overview
Fixes duplicate replacement terminals when a kept-open remote tmux mirror detaches on a workspace that is already empty.

repairRetiredRemoteTmuxContainerPanelsAfterDetach() now calls createReplacementTerminalPanel() only when it actually removed retired container panels (!retiredPanelIDs.isEmpty), not merely because panels is empty after detach. Last-surface close, Dock surface moves, and similar paths that detach an empty workspace and add their own shell no longer get a second terminal from this repair; the detach path that still clears stale retired containers continues to get one replacement when needed.

Reviewed by Cursor Bugbot for commit 30ae66d9a9ea719af4302a1e713adcee64cb81dc. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented unnecessary replacement terminals from being created after detaching when no retired panels were removed.