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
The find command worked. Let me look for the FloatingTerminalPanel.tsx file mentioned in the issue.
Assistant
The file exists. Now let me read its contents.
Assistant
Assistant
Let me search for the relevant files differently.
Assistant
Let me look at the terminals store to understand the createTab and closeTab functions.
Assistant
Now let me look at the TerminalPane to understand how
onPtyExitworks:Assistant
Now I have a clear understanding of the issues. Let me analyze them:
-
Auto-create on panel open vs. on tab close: The
useEffectat lines 102-108 auto-creates a tab wheneveropen && tabs.length === 0, which fires both on panel open AND when a tab is closed. It should only fire on open transition. -
closeOthersandcloseToRightstale closures: They capturetabsfrom the render scope in theiruseCallbackdependencies, which can be stale. They should useuseAppStore.getState(). -
closeToRightuses wrong order: It usestabs(backing array order) instead oftabBarOrder(visible tab-bar order). -
Closing last tab doesn't close panel: When user clicks X on the last tab, the panel should close, not auto-create a new one.
-
PTY exit: Should remove the tab but not close the panel or auto-create.
Let me open the file and make the necessary changes:
-
Assistant
Let me examine the specific lines I need to modify in detail.
Assistant
Now I understand all the issues. Let me implement the fix:
- Auto-create effect: Only triggers on panel open transition, not on tab count changes
closeFloatingTab: Closes panel when last tab is explicitly closedcloseOthers: Uses fresh store state viauseAppStore.getState()closeToRight: Uses fresh store state ANDtabBarOrderfor correct order
Assistant
Let me use the proper edit syntax with the triple quotes for multi-line text.
Assistant
The issue is that the tool call format isn't being parsed correctly. Let me use bash_terminal to check the exact content and then use a proper edit command.
Actually, looking at the error more carefully, it says "Cannot extract command from tool call" which means my tool call format is wrong. Let me look at the instructions again - it says I should use
editwith proper format.Looking at the example:
edit 1:1 << 'EOF' Line1 Line2 EOFLet me try with this format.
Assistant
Let me try a different approach using bash to make the edit:
Assistant
Let me try the
replacecommand with the correct syntax for multi-line text replacement:Assistant
Let me use sed to make the targeted edits:
Assistant
The environment doesn't have python3. Let me try python or use a different approach.
Assistant
Node is available. Let me use node to make the edits.
Assistant
The fixes were applied. Let me verify them:
Assistant
Good, the auto-create fix looks correct. Now let me verify the closeFloatingTab, closeOthers, and closeToRight fixes:
Assistant
All four fixes have been applied correctly. Let me verify the file is syntactically valid by running a TypeScript check:
Assistant
The file looks good. Let me check if there are any tests related to this component and run them:
Assistant
Let me check if there are any existing tests for the FloatingTerminalPanel component itself.
Assistant
The user wants me to check if there are any existing tests for the FloatingTerminalPanel component itself, and if not, I should look at whether the existing tests still pass. Let me run the existing tests and also check if there's a test runner available.
Assistant
Let me check if there are any tests specifically for the FloatingTerminalPanel component, and run the existing tests:
Assistant
No test files directly reference
FloatingTerminalPanel. Let me check how to run tests in this project and run the existing test suite to make sure nothing is broken.Assistant
Let me run the tests to verify the changes don't break anything:
Assistant
The tests are running. Let me wait for them to complete:
Assistant
The test failures are all related to
better-sqlite3native bindings not being found (Could not locate the bindings file), which is an environmental issue unrelated to my changes. This is a pre-existing issue in the test environment.Let me verify that the floating-terminal-specific tests pass:
Assistant
Let me use the correct vitest filter option:
Assistant
The floating terminal panel bounds tests pass. Let me review the complete modified file to ensure the logic is correct:
Assistant
The code looks correct. Let me verify my changes with git diff:
Assistant
All changes look correct. Let me summarize the fixes made:
Summary of Changes
1. Auto-create tab only on panel open transition (lines 97-109)
Added a
prevOpenRefto track the previousopenstate. The auto-create effect now only fires when:- Panel was previously closed (
!prevOpenRef.current) - Panel is now open (
open) - No tabs exist (
tabs.length === 0)
This prevents the effect from auto-creating tabs when the user closes the last tab (since the panel was already open,
prevOpenRef.currentistrue).2.
closeFloatingTabcloses panel when last tab is closed (lines 175-186)Now reads fresh state via
useAppStore.getState()to check if this is the only tab. If so, it callsonOpenChange(false)to close the panel after closing the tab.- Panel was previously closed (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.