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.
Assistant
I need to find the FloatingTerminalPanel.tsx file mentioned in the issue description.
Assistant
Found it. Let me read the file to understand the current code:
Assistant
Now let me understand the store structure better to see how tabs are managed:
Assistant
I need to look at the tabs store to understand how closeTab and createTab work.
Assistant
Let me look at the relevant parts of the tabs store more carefully, particularly the close functions:
Assistant
Now I have a thorough understanding of the issues. Let me summarize:
- Auto-create effect (lines ~102-108): Triggers whenever
tabs.lengthdrops to 0 whileopenis true, causing auto-recreation after user closes the last tab. closeOthers(lines ~177-184): Uses capturedtabsarray from render scope instead of fresh store state.closeToRight(lines ~186-195): Same stale closure issue + uses rawtabsarray instead of reconciled tab-bar order.
Let me implement the fixes:
- Auto-create effect (lines ~102-108): Triggers whenever
Assistant
Now I understand the issue. Let me look at the rest of the file, specifically the closeOthers and closeToRight functions:
Assistant
Now I have a complete understanding of the three issues. Let me implement all the fixes:
- Auto-create effect: Should only trigger when the panel transitions open, not when tabs become empty. Use a ref to track this.
closeOthers: Read current tabs fromuseAppStore.getState()instead of stale capturedtabs.closeToRight: Read current tabs fromuseAppStore.getState()and use the reconciledtabBarOrderfor visible ordering.
Assistant
Now I have a clear picture. Let me apply all three fixes:
Fix 1: The auto-create effect (lines 97-103) should only trigger on panel open transition, not when tabs become empty. I'll add a
wasOpenRefto track this.Fix 2:
closeOthers(lines 176-185) should read current tabs fromuseAppStore.getState()instead of stale capturedtabs.Fix 3:
closeToRight(lines 187-198) should read current tabs fromuseAppStore.getState()and usetabBarOrderfor the visible ordering instead of the rawtabsarray.Assistant
Let me verify the store types to make sure I understand the tabBarOrder type correctly.
Assistant
Now I'll apply all three fixes. Let me create the updated file:
Assistant
I need to use the edit command to replace the specific sections. Let me apply each fix one at a time.
Assistant
Let me use the
editcommand to make the changes. I'll apply all three fixes:Assistant
Now let me apply all three fixes step by step using the
editcommand.Fix 1: Add a
wasOpenRefand change the auto-create effect to only trigger on panel open transition.Assistant
Now I need to:
- Change the auto-create effect (lines ~97-103) to only trigger on panel open transition
- Fix closeOthers to use useAppStore.getState()
- Fix closeToRight to use useAppStore.getState() and tabBarOrder
Let me first check the current state of the file, then apply each fix.
Assistant
Good, the wasOpenRef is added. Now let me fix the auto-create effect. I need to replace lines 97-103 to only trigger on panel open transition:
Assistant
Now I need to fix this effect to only trigger when the panel transitions to open (not when tabs become empty). I need to track the previous value of
openwith a ref, and only auto-create when going from closed to open.Assistant
That approach is getting messy. Let me take a cleaner approach and rewrite the whole file properly.
Assistant
Let me start fresh and apply the fixes more carefully using a single write approach:
Assistant
Let me read the file and create a script to make the precise changes needed:
- Fix 1 (lines 64-66): Add
wasOpenRefafterpanelRef - Fix 2 (lines 97-103): Change the auto-create effect to only trigger on panel open transition
- Fix 3 (lines 176-185): Fix
closeOthersto useuseAppStore.getState() - Fix 4 (lines 187-198): Fix
closeToRightto useuseAppStore.getState()andtabBarOrder
Let me use sed to make these changes precisely.
- Fix 1 (lines 64-66): Add
Assistant
Now I need to apply the fixes. Let me use a Python script to make precise edits to the file.
Assistant
Python3 is not available. Let me try using
sedorperlinstead.Assistant
Let me use perl to make the changes:
Assistant
Let me verify the changes were applied correctly:
Assistant
Fix 1 is applied correctly. Let me check the closeOthers and closeToRight fixes:
Assistant
All three fixes are applied correctly. Let me verify the overall file integrity:
Assistant
Good. The file went from 397 to 412 lines which is expected with our additions. Let me verify the complete file is syntactically valid:
Assistant
All three fixes are correctly applied. Let me verify the diff to confirm the changes:
Assistant
The diff shows all three fixes are correctly applied:
-
Fix 1 (Auto-create effect): Added
wasOpenRefand changed the effect to only trigger when the panel transitions from closed to open, not when tabs become empty. -
Fix 2 (closeOthers): Changed from stale captured
tabsto reading fresh state viauseAppStore.getState(), withtabsremoved from dependency array. -
Fix 3 (closeToRight): Changed from stale captured
tabsarray to reading fresh state viauseAppStore.getState()and using the reconciledtabBarOrderfor visible tab ordering, withtabsremoved from dependency array.
Now let me check for any existing tests related to the floating terminal:
-
Assistant
Let me check if there are any tests that exercise the floating terminal panel component or its store interactions:
Assistant
Let me check the floating terminal panel bounds test:
Assistant
Let me check if there's a build/lint system and run tests to verify nothing breaks:
Assistant
Let me try running the type checking and tests to make sure my changes are correct:
Assistant
The pnpm test command timed out, likely because it's trying to install dependencies. Let me check if node_modules already exists and what the state of the project is.
Assistant
Since the node_modules don't exist, running the full test suite would require installing dependencies which could take a long time. Let me instead verify the code changes are syntactically valid by checking for any obvious TypeScript errors through simpler means:
Assistant
All changes look correct. Let me verify the final diff one more time:
Assistant
All changes are correctly applied. Let me summarize the fixes:
Summary of Changes
The issue was fixed by making three targeted changes to
FloatingTerminalPanel.tsx:Fix 1: Auto-create effect now only triggers on panel open transition (lines 96-112)
- Added
wasOpenRef(line 67) to track whether the panel has been open before - Changed the auto-create effect to only trigger when the panel transitions from closed to open (first time), not when tabs become empty during runtime
- When
openis false, we update and return early
- Added
Assistant
Let me try the submit command properly.
Assistant
The submit command is not being recognized properly. Let me check what's happening.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.