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 the structure and locate the relevant file. Let's first get a sense of the project.
- Assistant
Let me search for FloatingTerminalPanel.tsx file.
- Assistant
Now I'll open the file to examine it.
- Assistant
Let me view more of the file to understand the full context.
- Assistant
Let me continue viewing the file to see the rest of the callbacks.
- Assistant
Let me continue viewing the file to see the rest of the code.
- Assistant
Let me continue reading the rest of the file.
- Assistant
Now I understand the issue. Let me look at the
closeTabfunction in the store to understand its behavior, and also check theTerminalPanecomponent to understand the PTY exit behavior. - Assistant
Let me check the tabs slice to understand closeTab behavior:
- Assistant
Let me look at the
closeTabandcloseTabsToRightmethods to understand the issue better. - Assistant
Let me look at the TerminalPane component to understand the onPtyExit and onCloseTab callbacks:
- Assistant
Now let me look at the
closeTabin the terminals slice: - Assistant
Let me look at the closeTab implementation in the terminals slice:
- Assistant
Let me look at the TerminalPane component to understand the onPtyExit and onCloseTab callbacks:
- Assistant
Now let me look at the auto-create effect more carefully and understand the full flow:
- Assistant
Let me now understand how
tabsandtabBarOrderrelate in the store: - Assistant
Let me look at how
tabBarOrderworks with the floating terminal to understand what the reconciled visible tab-bar order means: - Assistant
No output means those terms might not be in that file. Let me search more broadly.
- Assistant
Let me look at the closeTab method in terminals.ts to understand how it handles closing:
- Assistant
Now I have a thorough understanding of the codebase. Let me create a reproduction script to confirm the issue, then implement the fix.
Analysis of the root cause:
-
Auto-create effect (lines 97-103): The
useEffectdepends ontabs.length, so when the last tab is closed,tabs.lengthbecomes 0, re-triggering the effect and creating a new tab. The fix: only bootstrap when the panel transitions from closed to open. -
closeFloatingTab(line 169-174): Doesn't check if it's the last tab - should close the panel instead of just closing the tab. -
closeOthers/closeToRight: Use staletabsfrom closure instead of fresh store state.closeToRightalso uses raw array order instead of reconciled tab-bar order. -
onPtyExit: Should remove its tab but NOT close the panel or create a replacement.
Let me implement the fixes:
-
- Assistant
Let me check what the TabBar component expects:
- Assistant
Let me look at how
onCloseTabis used in TerminalPane: - Assistant
Now let me look at the
closeTabsToRightfunction in the tabs slice: - Assistant
Now I have a thorough understanding of the issues. Let me plan and implement the fixes:
Issues to fix:
- Auto-create effect (lines 97-103): Creates a new tab whenever
tabs.length === 0while panel is open. Should only create when panel transitions from closed→open. closeFloatingTab: Should close the panel when closing the last tab.closeOthers: Uses staletabsfrom closure, should useuseAppStore.getState().closeToRight: Uses staletabsfrom closure + raw array order, should useuseAppStore.getState()and reconciled tab-bar order.onPtyExit: Should just close the tab but NOT create a replacement (handled by fixing auto-create).
Let me implement:
- Auto-create effect (lines 97-103): Creates a new tab whenever
- Assistant
Let me use the replace command instead:
- Assistant
I need to navigate to line 97 first before editing. Let me do that.
- Assistant
I need to first open the file, then goto the line.
- Assistant
Now I can see the file with the correct line numbers. Let me now use the replace command:
- Assistant
Good, the first change is applied. Now let me fix
closeFloatingTabto close the panel when it's the last tab: - Assistant
I need to navigate to that line first.
- Assistant
Now I can see the exact lines. Let me apply the edits for
closeFloatingTab: - Assistant
Good. Now let me fix
closeOthersto use fresh state: - Assistant
Good. Now let me fix
closeToRightto use fresh state and the reconciled tab-bar order: - Assistant
All four main changes have been made. Let me now review the entire file to make sure everything looks correct:
- Assistant
Let me see the rest of the file:
- Assistant
Let me check the
onPtyExitandonCloseTabin the render section: - Assistant
Let me look at how
onPtyExitis actually used in the terminal pane: - Assistant
- Assistant
Let me also update the
onCloseTabhandler in the render section - it should close the panel when it's the last tab (same as the X button behavior), whileonPtyExitshould remain just closing the tab without closing the panel: - Assistant
Now I need to fix the
onCloseTabcallback in the render section. Per the contract:onPtyExitshould just close the tab (no panel close, no replacement — already handled by our bootstrap fix)onCloseTabis an explicit close action from within the terminal, so it should close the panel when removing the last tab (symmetric with the X button)
- Assistant
Now let me verify the complete file looks correct by viewing the key sections:
- Assistant
Good, the file looks correct. Now let me check if there are any tests related to this component:
- Assistant
Let me run the existing tests to make sure I haven't broken anything:
- Assistant
Let me wait for the test to complete:
- Assistant
The test failures are all pre-existing environment issues (missing native bindings for better-sqlite3). Let me run just the renderer tests that are relevant:
- Assistant
Let me run the floating terminal bounds test as well:
- Assistant
Let me also run the terminals slice test:
- Assistant
All 27 test files and 499 tests pass. Let me also check for TypeScript compilation errors:
- Assistant
Let me find the correct tsconfig file:
- Assistant
Let me try the web config:
- Assistant
The TypeScript errors are pre-existing (unrelated to my changes). Let me check for any TypeScript errors specifically in our file by running the full project type check:
- Assistant
Good, no TypeScript errors in FloatingTerminalPanel.tsx specifically. Let me check the diff of the changes I made:
- Assistant
The diff looks correct. Let me now verify I haven't missed any edge cases by examining the final state of the file:
- Assistant
Let me run all the renderer tests one more time to confirm everything passes:
- Assistant
All 299 renderer test files pass with 2547 tests. Let me now go through the checklist to make sure I've addressed everything:
- Assistant
Now let me do a final review of the changes and confirm everything is correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.