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 to understand the codebase and locate the relevant files. Let's first get an overview.
- Assistant
Let me find the specific file mentioned in the issue: FloatingTerminalPanel.tsx
- Assistant
Let me examine the file mentioned in the issue description: FloatingTerminalPanel.tsx.
- Assistant
Let me explore the repository structure more and understand the store to see how
closeTabworks. - Assistant
Let me look at the store slice to understand how
closeTabworks. - Assistant
Let me understand the existing store methods and find the relevant
closeTabimplementation: - Assistant
Let me search for the relevant code one thing at a time.
- Assistant
Let me look at the
closeTabfunction in the store. - Assistant
Let me look at the closeTab implementation in terminals.ts
- Assistant
Let me see the rest of closeTab and also see how it interacts with tabsByWorktree.
- Assistant
Now let me understand the full picture. Let me look at what
createTabandsetActiveTabForWorktreedo, and also understand how the store selects tabs. - Assistant
Let me look at existing tests for this component:
- Assistant
Let me now check if there are any tests specifically for FloatingTerminalPanel:
- Assistant
Now let me look at the existing tests and understand what the test setup looks like:
- Assistant
Let me look at the store test to understand the
closeTabbehavior in the unified model: - Assistant
Let me look at the exact lines I need to modify:
- Assistant
Let me look at the closeFloatingTab, closeOthers, and closeToRight callbacks:
- Assistant
Now I have a clear picture. Let me look at how the PTY exit is handled:
- Assistant
Let me see the TerminalPane part to understand onPtyExit:
- Assistant
Let me look at the TerminalPane component to understand onCloseTab:
- Assistant
Let me look at TerminalPane onCloseTab usage to understand what it does:
- Assistant
Now I understand the full picture. Let me also look at how
onPtyExitis handled in TerminalPane: - Assistant
Let me look at how
onPtyExitis called in TerminalPane to understand if it's called when the PTY process exits: - Assistant
Let me understand how
onPtyExitis invoked: - Assistant
Let me now look at the terminal-pane-lifecycle to understand when onPtyExit is triggered vs onCloseTab
- Assistant
Let me look at where onPtyExitRef is actually called:
- Assistant
Let me search for how onPtyExit is invoked in the terminal pane code:
- Assistant
Now I understand the full picture. Let me now make the changes. The issues are:
-
Auto-create effect: Currently fires whenever
open=trueandtabs.length=0. After user closes last tab,tabs.lengthbecomes 0 and effect auto-creates a new tab. Fix: only auto-create when panel transitions from closed to open (not when it's already open and tabs become 0). -
closeFloatingTab: Needs to close the panel (onOpenChange(false)) when closing the last tab explicitly. -
closeOthers: Uses staletabsfrom closure instead of fresh store state. -
closeToRight: Uses staletabsfrom closure instead of fresh store state, and uses raw array order instead of reconciled tab-bar order.
-
- Assistant
Now I have a clear understanding of the issue. Let me make the fixes:
- Auto-create effect (lines 97-103): Only bootstrap a tab when panel transitions from closed→open, not whenever
open=true && tabs.length=0 closeFloatingTab: Close the panel when closing the last tab explicitlycloseOthers: Use fresh store state viagetState()closeToRight: Use fresh store state viagetState()and reconciled tab-bar order
Let me start with the auto-create effect:
- Auto-create effect (lines 97-103): Only bootstrap a tab when panel transitions from closed→open, not whenever
- Assistant
Let me use the proper syntax for the edit command. The parameter name should be
line_rangenotLINE_RANGE. - Assistant
Good, the
prevOpenRefis added. Now let me fix the auto-create effect to only fire on transition from closed to open: - Assistant
Good, now let me fix
closeFloatingTabto close the panel when closing the last tab: - Assistant
Good. Now let me fix
closeOthersto use fresh store state: - Assistant
Good. Now let me fix
closeToRightto use fresh store state and reconciled tab-bar order: - Assistant
Good. Now let me review the full file to make sure everything looks correct:
- Assistant
The code looks good. Now let me run the existing tests to make sure nothing is broken.
- Assistant
Let me check what test runner is available and run the relevant tests:
- Assistant
Let me run the floating-terminal bounds test and the terminals test:
- Assistant
Let me run the store tests:
- Assistant
Let me also run the store cascade tests and the terminals test:
- Assistant
Let me run the full test suite:
- Assistant
The test failures seem to be related to native module issues (better-sqlite3) and environment setup, not my changes. Let me verify by checking if any floating-terminal related tests failed:
- Assistant
The floating-terminal-panel-bounds test passes, and the other floating-related tests seem to be from persistence and hydration which are not directly affected by my changes.
Let me also verify that the store tests pass:
- Assistant
All terminal and tab related tests pass. Let me also verify TypeScript compilation:
- Assistant
Let me verify the changes once more by looking at the diff:
- Assistant
The diff looks clean and correct. Let me verify there's no whitespace issue and restore the blank line that was inadvertently removed:
- Assistant
I see a duplicate got introduced. Let me fix that:
- Assistant
There's a duplicate from the bad edit. Let me revert the file and redo the changes properly.
- Assistant
Good, the file is reverted. Now let me redo all changes carefully:
- Assistant
Good, the file is back to original. Now let me apply all changes carefully using the
replacecommand:- First, add the
prevOpenRef:
- First, add the
- Assistant
Good,
prevOpenRefadded. Now fix the auto-create effect (lines 98-104): - Assistant
Good, auto-create effect fixed. Now fix
closeFloatingTab: - Assistant
Let me go to line 178 first then try the replace.
- Assistant
Now let me edit the closeFloatingTab:
- Assistant
Good. Now fix
closeOthers: - Assistant
Good. Now fix
closeToRight: - Assistant
All four changes are applied. Let me verify the complete diff:
- Assistant
The diff looks correct. Let me run the tests again to make sure everything passes:
- Assistant
All tests pass. Let me do a final review of the complete file:
- Assistant
Let me run the linter to check for any issues:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.