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 to understand its structure and locate the relevant file (FloatingTerminalPanel.tsx). Let's first get an overview.
- Assistant
Let me open the main file mentioned in the issue - FloatingTerminalPanel.tsx.
- Assistant
Let me see the rest of the file to understand the full logic.
- Assistant
Let me see the rest of the file.
- Assistant
Now let me look at the full file and understand the auto-create effect and the callback implementations. Let me also look at how the
closeTabinTerminalPaneworks to understand the onPtyExit behavior. - Assistant
Let me look at how the TabBar component handles the onClose callback and what order data is passed.
- Assistant
Let me check the store to understand
closeTabbehavior and the state structure: - Assistant
Let me look at the
closeTabimplementation in the store to understand what it does, and then look at how the floating terminal panel is managed from its parent component. - Assistant
Let me find the
closeTabfunction definition in the store: - Assistant
Let me search for
closeTabmore broadly. - Assistant
The
closeTabmight be in the terminal slice. Let me check there. - Assistant
Let me look at the closeTab implementation in the terminals slice:
- Assistant
Let me see more of the closeTab implementation and also understand the
tabsstate: - Assistant
Now let me see the rest of the file, particularly the closeFloatingTab, closeOthers, closeToRight, and the auto-create effect:
- Assistant
Now let me read the full file to understand the complete picture:
- Assistant
Now let me also look at the
onPtyExitusage in the JSX: - Assistant
Let me see the rest of the TerminalPane usage:
- Assistant
Now let me check for any existing tests related to the floating terminal panel:
- Assistant
Now let me look at the
reconcileTabOrderto understand how tab order works: - Assistant
Now let me check how
tabBarOrderByWorktreeis used in the TabBar: - Assistant
Now let me check if there are any tests that cover the floating terminal panel behavior:
- Assistant
Let me look at the
tabs.test.tsto understand the test patterns: - Assistant
Let me check how
onOpenChangeis typically implemented by looking at whereFloatingTerminalPanelis rendered: - Assistant
Let me look at how the FloatingTerminalPanel is used in App.tsx:
- Assistant
Let me check what
setFloatingTerminalOpenWithFocusdoes. - Assistant
Let me look at how
onCloseTabis used in TerminalPane: - Assistant
Let me check how onPtyExit and onCloseTab are used in the non-floating context to understand the expected behavior:
- Assistant
Let me look at how TerminalPane handles pty exit to understand if there's a display period before the callback fires:
- Assistant
Now I have a clear picture. Let me now plan the fix:
-
Auto-create effect (lines 97-104): The effect creates a tab when
openis true andtabs.length === 0. This fires every timetabs.lengthchanges to 0 while the panel is open, which is the bug. We need to change this to only create a tab when the panel transitions from closed to open with no tabs. -
closeFloatingTab(lines 169-173): When closing the last tab, should close the panel instead. -
closeOthers(lines 176-183): Uses staletabsfrom closure. -
closeToRight(lines 185-195): Uses staletabsand raw array order instead of tab bar order.
Let me implement the fix. First, let me look at what's needed from the
reconcileTabOrder: -
- Assistant
Now I understand the full picture. Let me implement the fix. I need to:
- Add a
prevOpenRefto track open state transitions, so auto-create only happens on open (not when tabs become 0) - In
closeFloatingTab, check if this is the last tab and close the panel instead - Fix
closeOthersto use fresh store state - Fix
closeToRightto use fresh store state and follow tab-bar order - Ensure
onPtyExitdoesn't close the panel (just removes the tab)
Let me make the changes:
- Add a
- Assistant
Let me use the terminal for edits:
- Assistant
Now let me add a
prevOpenRefto track open transitions, and replace the auto-create effect. First, let me see the exact lines around the effect: - Assistant
Now let me replace the auto-create effect to only create a tab when the panel transitions from closed to open:
- Assistant
Good, the auto-create effect is fixed. Now let me fix the
closeFloatingTabcallback to close the panel when closing the last tab: - Assistant
Now let me see the closeToRight callback too:
- Assistant
Now let me replace all three callbacks with the fixed versions:
- Assistant
I see there's a duplicate
)on line 221. Let me fix that: - Assistant
Good, the duplicate
)is fixed. Now let me verify the file looks correct by checking the full modified section: - Assistant
Good. Now let me also verify the
onPtyExitandonCloseTabhandlers in the JSX - I need to make sure they don't try to close the panel: - Assistant
Let me check the context of how
onCloseTabis triggered in TerminalPane: - Assistant
Now I understand the distinction.
onCloseTabis an explicit user action (Cmd+W), whileonPtyExitis when the PTY process exits. The evaluation contract says "An explicit close action that removes the last tab closes the panel" - soonCloseTabshould also close the panel when it's the last tab. Let me update the JSX: - Assistant
Now I need to update the
onCloseTabhandler to usecloseFloatingTab(which closes the panel if it's the last tab), while keepingonPtyExitas-is (just removes the tab, panel stays open): - Assistant
Good. Now let me verify the complete file by checking for any TypeScript compilation issues:
- Assistant
It seems tsc is running - let me wait for it to finish.
- Assistant
No TypeScript errors. Let me now check if there are any existing tests related to floating terminal:
- Assistant
Let me wait for the test run to complete:
- Assistant
There are many pre-existing test failures (import resolution issues, etc.). Let me check if there are specific tests that relate to the floating terminal panel:
- Assistant
Let me run just the tests related to tabs and the floating terminal:
- Assistant
This is a pre-existing issue with the test environment, not related to my changes. Let me run the floating-terminal-panel-bounds tests to confirm they still pass:
- Assistant
Good. Let me also run the persistence tests and other tests related to floating terminal:
- Assistant
Let me also run the store-cascades test since it's related to tab closing:
- Assistant
Let me verify the full modified file is correct by viewing the complete diff:
- Assistant
The diff looks clean and correct. Let me review the changes:
-
Import
reconcileTabOrder: Added to supportcloseToRightusing reconciled order. -
Auto-create effect: Changed from depending on
tabs.lengthto usingprevOpenRefto track open state transitions. Now only creates a tab when the panel transitions from closed to open. -
closeFloatingTab: Now checks if closing the last tab and closes the panel viaonOpenChange(false). -
closeOthers: UsesuseAppStore.getState()instead of staletabsclosure. -
closeToRight: UsesuseAppStore.getState()andreconcileTabOrderto follow the reconciled visible tab-bar order. -
onCloseTab: Changed to usecloseFloatingTabso explicit close actions also close the panel on last tab. -
onPtyExit: RemainscloseTab(tab.id)- PTY exit just removes the tab, panel stays open.
Let me verify the file compiles correctly:
-
- Assistant
No TypeScript errors. Let me also check if there's a lint command available:
- Assistant
Let me run lint to make sure the code passes:
- Assistant
No linting issues. Let me verify the complete file structure one more time to make sure it's all correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.