ISSUE DESCRIPTION Floating terminal auto-creates tab after user closes the last one…
- User
ISSUE DESCRIPTION
Floating terminal auto-creates tab after user closes the last one
Floating terminal auto-creates tab after user closes the last one
Symptom
When the floating terminal has a single tab open and the user clicks the X button to close it, the panel auto-creates a new terminal tab instead of closing the panel. The user has to close the panel manually via the minimize button or by closing the newly created tab again.
Steps to reproduce
- Open the floating terminal (Cmd+Alt+T on Mac / Ctrl+Alt+T on Windows/Linux)
- The panel opens with one auto-created terminal tab
- Click the X button on that tab to close it
- Expected: Panel closes cleanly
- Actual: Panel stays open with a fresh auto-created tab
Root cause
The
closeTabcallback used for the X button triggers the auto-create effect (lines 102-108 inFloatingTerminalPanel.tsx) that spawns a tab whenever the panel is open with zero tabs. The panel never closes because a replacement tab is created before the close check can run.Additionally,
closeOthersandcloseToRightcontext menu actions had stale closure bugs—they readtabs.lengthfrom the captured array inuseCallbackdependencies instead of pulling fresh state viauseAppStore.getState(), causing these callbacks to operate on outdated tab lists.Expected behavior
- Clicking X on the last terminal tab should close the floating panel (symmetric with the auto-create on open)
- The panel should remain open if a PTY exits so the user can see exit status
- Multi-tab operations (
closeOthers,closeToRight) should operate on current state, not stale captures
Why it matters
The asymmetry breaks user expectations: the panel auto-creates a tab on open (hotkey press), but closing that tab doesn't reverse the action. Users expect the X button on the last tab to dismiss the panel, not spawn an orphaned replacement.
Environment
- All platforms (macOS, Linux, Windows)
- Floating terminal feature introduced in recent releases
Evaluation contract
Bootstrap a terminal tab only when the panel transitions open. An explicit close action that removes the last tab closes the panel; a PTY exit removes its tab but must neither close the panel nor create a replacement tab. Bulk close operations must read the current store state rather than a stale render-time tab list, and
closeToRightmust follow the reconciled visible tab-bar order rather than raw backing-array order. Assistant
I'll start by exploring the repository structure and understanding the codebase.
Assistant
Let me explore the store and related components to understand the full picture.
Assistant
Let me look at the terminals slice which is what the floating terminal uses (
tabsByWorktree,createTab,closeTab,tabBarOrderByWorktree).Assistant
Let me look at the
closeTab,createTab,setTabBarOrderfunctions in the terminals slice.Assistant
Let me check for existing tests and look at the TerminalPane and TabBar components.
Assistant
Let me look at how TabBar uses these callbacks and computes the visible order.
Assistant
Let me look at how SortableTab wires the close callbacks (the X button and context menu).
Assistant
Now I have a good understanding. Let me look at how SortableTab computes
hasTabsToRightandtabCountto understand the order it uses.Assistant
Let me look at the TerminalPane component to understand
onPtyExitvsonCloseTab.Assistant
So
onCloseTabis called whenexecuteClosePaneis called with a single pane (the last pane). This is triggered by Cmd+W or similar close actions within the terminal pane. This is an explicit close action by the user.Let me look at where
executeClosePaneis called and whereonPtyExitis called.Assistant
Let me look at the exact section of FloatingTerminalPanel.tsx I need to modify (the auto-create effect and the close callbacks).
Assistant
Now I have a clear picture. Let me first check the imports section to add
reconcileTabOrder.Assistant
Now I'll make the changes. First, add the
reconcileTabOrderimport.Assistant
Now let me add a ref to track the open transition and fix the auto-create effect. Let me view the current state of those lines.
Assistant
Now let me fix the auto-create effect to only bootstrap on the open transition.
Assistant
Let me use the
openandeditcommands instead to avoid shell escaping issues.Assistant
Now let me replace the auto-create effect (lines 99-105) with the open-transition-only version.
Assistant
Now let me fix the
closeFloatingTab,closeOthers, andcloseToRightcallbacks. Let me view the current lines.Assistant
Now let me replace the three close callbacks (lines 181-210) with fresh-state versions.
Assistant
Now let me update the
onPtyExitandonCloseTabhandlers in the TerminalPane rendering.onPtyExitstays as a directcloseTab(PTY exit), whileonCloseTab(explicit Cmd+W close) routes throughcloseFloatingTab.Assistant
Now update the
onPtyExit(keep directcloseTabfor PTY exit) andonCloseTab(route explicit close throughcloseFloatingTab).Assistant
Now let me verify the changes compile and lint correctly. Let me check available scripts.
Assistant
Let me run the linter on the changed file and the web typecheck.
Assistant
Lint passes. Now let me run the web typecheck to ensure types are correct.
Assistant
Typecheck passes. Now let me run the existing relevant tests to make sure nothing is broken.
Assistant
Let me search for any existing tests referencing the floating terminal worktree or store tab operations.
Assistant
Let me look at how existing tests set up the store so I can write a temporary verification script for the closeToRight ordering logic.
Assistant
Let me look at the store-test-helpers to write a temporary verification test.
Assistant
Now let me write a temporary verification test that exercises the closeToRight/closeOthers/closeFloatingTab logic against the real store with a reordered tabBarOrder.
Assistant
The verification confirms the new
closeToRightfollows the reconciled visible order (the old backing-array logic would have closed the wrong tabs). Let me remove the temporary test.Assistant
Let me review the full diff of my changes.
Assistant
The diff looks complete and correct. Let me run the broader context-menu and tab-related tests to ensure nothing is broken.
Assistant
All tests pass. Let me run the full terminals slice test suite to be thorough.
Assistant
All 499 slice tests pass. Let me run the full lint to be safe.
Assistant
Let me do a final review of the complete modified sections to confirm coherence.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.