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 understanding the repository structure and finding the relevant file mentioned in the issue:
FloatingTerminalPanel.tsx. I need to explore the codebase first.Assistant
Let me find the FloatingTerminalPanel.tsx file.
Assistant
Let me examine the file with line numbers to understand the exact code locations.
Assistant
Now let me see the
closeOthersandcloseToRightcallbacks and the rest of the file:Assistant
Now let me also look at the TerminalPane component to understand how
onPtyExitandonCloseTabare handled:Assistant
Now let me understand the issue better. Let me look at the evaluation contract:
- Bootstrap a terminal tab only when the panel transitions open - The auto-create effect (lines 97-103) should only create a tab when the panel opens, not when a tab is closed.
- An explicit close action that removes the last tab closes the panel - Clicking X on the last tab should close the panel.
- A PTY exit removes its tab but must neither close the panel nor create a replacement tab - PTY exit behavior needs to be different from explicit close.
- Bulk close operations must read the current store state -
closeOthersandcloseToRightshould useuseAppStore.getState()instead of stale closure captures. closeToRightmust follow the reconciled visible tab-bar order - It should usetabBarOrderinstead of rawtabsarray order.
Let me look at how the
openprop is managed:Assistant
Now I understand the full picture. Let me plan the fix:
Problem 1: The auto-create effect (lines 97-103) fires whenever
openis true andtabs.length === 0. This means when the user closes the last tab, the effect fires again and creates a new tab before the panel can close.Problem 2:
closeOthersandcloseToRightusetabsfrom closure (stale state) instead of getting fresh state fromuseAppStore.getState().Problem 3:
closeToRightshould use thetabBarOrderfor determining which tabs are to the right, not the raw backing array order.Solution:
-
Auto-create effect: Only create a tab when the panel transitions to open (i.e., when
openchanges from to ). We should NOT auto-create when a tab is closed while the panel is already open. We can do this by tracking whether the panel was just opened vs. already open.
-
Assistant
Now let me understand the exact flow better. The auto-create effect at lines 97-103:
- Fires when
openis true ANDtabs.length === 0 - This means it creates a tab when the panel opens (good) but ALSO when a tab is closed (bad)
The fix needs to:
- Only auto-create a tab when the panel transitions from closed to open
- When the user explicitly closes the last tab (via X button), close the panel
- When a PTY exits, remove the tab but DON'T close the panel and DON'T create a replacement
- Fix
closeOthersandcloseToRightto use fresh store state - Fix
closeToRightto use tab-bar order
Let me also check if there are tests for this file:
- Fires when
Assistant
These tests are about bounds, not about the panel logic itself. Let me now implement the fix.
Here's my plan:
-
Auto-create effect: Track whether the panel was previously open. Only auto-create when the panel transitions from closed to open (i.e.,
openis true and was previously false). -
Close last tab (explicit): In
closeFloatingTab, after callingcloseTab, check if this was the last tab. If so, callonOpenChange(false)to close the panel. -
PTY exit: The
onPtyExithandler passes() => closeTab(tab.id)toTerminalPane. When a PTY exits, the tab should be removed but the panel should stay open. No replacement tab should be auto-created. The auto-create effect fix already handles this (it won't fire sinceopendoesn't transition). -
Fix
closeOthers: UseuseAppStore.getState()to get fresh tabs state. -
Fix
closeToRight: UseuseAppStore.getState()and usetabBarOrderfor ordering.
Let me implement these changes:
-
Assistant
Now I understand the full picture. Let me implement the fix:
- Auto-create effect: Only bootstrap a tab when the panel transitions from closed to open (not when a tab is closed while panel is open)
closeFloatingTab: Close the panel when the last tab is explicitly closedcloseOthers: UseuseAppStore.getState()for fresh statecloseToRight: UseuseAppStore.getState()andtabBarOrderfor correct ordering
Assistant
Now let me make the edits. First, I'll add a
useRefto track the previousopenstate, so the auto-create effect only fires on transition:Assistant
Let me edit the file to add a ref for tracking the previous open state and fix the auto-create effect:
Assistant
I need to use a different approach since python3 is not available. Let me use sed or manual edits.
Assistant
Good, I can use Node.js to do the replacement:
Assistant
Let me verify the changes were applied correctly by viewing the modified file.
Assistant
Good, let me check the close callbacks:
Assistant
All the changes look correct. Let me also verify the full file compiles by checking its TypeScript validity:
Assistant
Now let me check if there are any TypeScript or build tools I can use to validate the changes:
Assistant
Let me run the typecheck for the web (renderer) part to verify the TypeScript is correct:
Assistant
The typecheck passed without errors. Let me now run the existing tests to make sure I haven't broken anything:
Assistant
The test failures are all related to
better-sqlite3native binding issues (not related to my changes). These are pre-existing environment issues with the SQLite native module, not caused by my code changes.Let me specifically check if the floating terminal panel bounds test passes:
Assistant
Assistant
The
normalizedInitialBoundsRefis only set totrueand never reset tofalse. This is existing behavior and unrelated to my fix. If the panel is closed and reopened, the bounds normalization won't happen again. But this is not the issue we're fixing.Now let me also consider: what if
closeOthersis called on the last tab? Let me check:If there are 2 tabs and user does "Close Others" on one tab:
closeOthers(tabId)closes the other tab- Only 1 tab remains
- The auto-create effect won't fire because
prevOpenRef.currentistrue - The panel stays open with 1 tab. ✅
But wait,
closeOthersdirectly callscloseTabfor each other tab. It doesn't go throughcloseFloatingTab. So if all tabs except one are closed, and then the user closes the remaining tab via the X button:closeFloatingTabis called for the last tabcurrentTabs.lengthis 1, soonOpenChange(false)is calledcloseTab(tabId)removes the tab- Panel closes. ✅
Now let me verify the diff to make sure all changes are correct:
Assistant
The diff looks correct and addresses all the issues mentioned in the evaluation contract. Let me now verify there are no issues with the linting:
Assistant
now let me remove the backup file I created and then submit the changes.
Assistant
Now let me do a final review of all the changes by viewing the complete modified file:
Assistant
The changes look good. Let me now go through the checklist from the issue:
Checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.