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
Let me start by exploring the repository structure to understand the codebase and find the relevant files mentioned in the issue description, particularly
FloatingTerminalPanel.tsx.Assistant
Let me find the FloatingTerminalPanel.tsx file specifically.
Assistant
Let me look at the full context and explore related files to understand the codebase better.
Assistant
Now let me understand the issue more clearly. Let me re-read the key parts of the code and understand the problems:
-
Auto-create tab effect (lines 97-103): When
openis true andtabs.lengthis 0, it auto-creates a new tab. This is the root cause of the issue - when user closes the last tab, this effect fires and creates a new one, so the panel never closes. -
closeOthers(lines 176-185): Usestabsfrom the captured closure instead of getting fresh state viauseAppStore.getState(). -
closeToRight(lines 187-198): Same stale closure bug, plus it should follow the reconciled visible tab-bar order rather than raw backing-array order.
Let me also check the store to understand how
closeTabworks and if there's a way to close the panel:-
Assistant
Let me understand the issue more carefully. The key issues are:
-
Main issue: The
closeFloatingTabcallback (line 169-174) just callscloseTab(tabId). When this removes the last tab, the auto-create effect (lines 97-103) fires and creates a new tab, preventing the panel from closing. -
Fix for main issue: The
closeFloatingTabshould also close the panel when it's closing the last tab. We need to callonOpenChange(false)when the last tab is being closed explicitly. -
Stale closure bugs:
closeOthersandcloseToRightusetabsfrom the closure. They should useuseAppStore.getState()to get fresh state. -
closeToRight ordering: Should follow
tabBarOrder(the reconciled visible tab-bar order) rather than rawtabsarray order.
Let me look at more context to understand how to implement this properly:
-
Assistant
Let me check the legacy tabs slice and also understand how the
closeTabandcreateTabare accessed:Assistant
Now let me look at the TabBar component to understand how
onCloseis called:Assistant
Now I have a clear understanding of the issues. Let me now also check for any existing tests related to the floating terminal:
Assistant
Assistant
Let me re-examine the issue and the FloatingTerminalPanel.tsx file to understand the problem better before making any changes.
Let me re-read the code and understand what needs to be fixed.
Assistant
Now I have a clear picture. Let me implement the fixes:
- Auto-create effect: Only bootstrap when panel transitions to open (not on every zero-tabs state)
- closeFloatingTab: Close the panel when closing the last tab
- closeOthers: Use fresh store state instead of stale closure
- closeToRight: Use fresh store state and follow
tabBarOrderfor ordering
Assistant
Now I have a clear picture. Let me implement the fixes:
- Auto-create effect: Add a ref to track whether we've already bootstrapped a tab for the current open session, so it only fires on panel open transition
- closeFloatingTab: Check if closing the last tab and call
onOpenChange(false)to close the panel - closeOthers: Use
useAppStore.getState()for fresh state - closeToRight: Use
useAppStore.getState()and followtabBarOrderfor ordering
Let me apply these changes:
Assistant
I'll apply all four fixes to the FloatingTerminalPanel.tsx file.
Assistant
I need to fix the FloatingTerminalPanel.tsx file. Let me first check what the current state of the file looks like after my partial edit, then apply the remaining changes.
Assistant
Let me restore the file to its original state and apply the changes properly.
Assistant
Now I'll apply all the fixes. Let me start by adding the
hasBootstrappedTabRefref and fixing each section:Assistant
The edit command failed because it's not extracting the command properly. Let me use the correct syntax.
Assistant
Let me use Node.js to apply the fixes instead.
Assistant
Let me verify the changes were applied correctly by checking the modified file.
Assistant
All fixes have been applied. Let me verify the changes with a diff:
Assistant
The diff looks correct. Now let me run the existing tests to make sure nothing is broken:
Assistant
Let me run the existing tests related to floating terminal and check for any TypeScript errors:
Assistant
Good, the floating-terminal tests pass. Let me also check for TypeScript compilation issues and run any related tests:
Assistant
No TypeScript errors related to our changes. Let me also run a broader test suite to make sure nothing is broken:
Assistant
All tab-bar tests pass. Let me also run the store-related tests that might be affected by our changes:
Assistant
All tests pass. Let me also run a few more test suites to be thorough:
Assistant
All tests pass. Let me now verify my changes one more time by reviewing each fix:
Assistant
Let me now verify the complete changes are correct by reviewing the final state of the file once more:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.