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 what we're working with.
Assistant
Now let me explore related files to understand the broader context:
Assistant
Let me look at the closeTab function in the terminals slice:
Assistant
Let me search for where the floating terminal open state is managed:
Assistant
Let me look for existing tests on the floating terminal:
Assistant
Let me look at the tests file structure for any relevant tests:
Assistant
Now let me look at the package.json to understand how to run tests:
Assistant
Now let me look at the SortableTab file to understand the close button and its relation:
Assistant
Now let me look at the TerminalPane to understand the onPtyExit and onCloseTab handlers:
Assistant
Let me check how
onCloseTabis used in TerminalPane:Assistant
Let me look at the createTab function and other store actions:
Assistant
Now let me understand the test setup and existing tests:
Assistant
Now let me look at the
focusTerminalTabSurfacefunction for understanding the focus behavior:Assistant
Let me also look for any other places where similar logic exists:
Assistant
Let me look at the store types and the test setup:
Assistant
Now I have enough context. Let me also check the tabBar interface:
Assistant
Now I have a good understanding. Let me create a temporary reproduction script to verify the issue and my fix:
Assistant
Let me also confirm the specific line numbers in the file:
Assistant
Let me now look at the current code one more time to ensure I understand the layout:
Assistant
Now I have enough context. Let me create a temporary reproduction script to verify the issue exists:
Assistant
Now let me implement the fix. First, let me make the change to the auto-create effect:
Assistant
Now let me make the edit. I need to add a ref to track previous open state:
Assistant
Let me make the edits to the FloatingTerminalPanel.tsx file. I'll add a ref to track the previous open state.
Assistant
I made a mistake - the edit duplicated some lines. Let me revert and try again:
Assistant
Good, the file is back to its original state. Now let me make the edits one at a time more carefully.
First, let me add the
previousOpenRef:Assistant
I see, the edit created a duplicate. Let me revert and try again with a different approach:
Assistant
Now let me carefully make the edit by replacing the entire dragRef block:
Assistant
The
previousOpenRefis added. Now let me update the auto-create useEffect:Assistant
Now let me update
closeFloatingTabto close the panel when the last tab is being closed:Assistant
Now let me look at and update the
onCloseTabcallback for TerminalPane:Assistant
I need to:
- Keep
onPtyExitas justcloseTab(tab.id)(PTY exit should NOT close the panel) - Change
onCloseTabto usecloseFloatingTab(tab.id)so explicit close action closes the panel if last tab
Let me make this edit.
- Keep
Assistant
Now let me view the whole file to verify the changes look correct:
Assistant
Now let me verify the rest of the file:
Assistant
Let me check the diff to see all my changes:
Assistant
Let me run the existing tests to make sure I didn't break anything:
Assistant
Existing tests pass. Now let me run all renderer tests to ensure nothing is broken:
Assistant
The failures are unrelated to my changes - they're about better-sqlite3 native binding issues. Let me run just the renderer tests to make sure my changes don't break anything in the relevant areas:
Assistant
All renderer tests pass. Now let me write a temporary script to verify the behavior of the fix. The issue is about React component behavior, so a unit test that simulates the React hooks behavior is the best approach:
Assistant
Now let me write a more comprehensive functional test that simulates the actual React component behavior to verify the fix:
Assistant
I see the issue with my test - I need to initialize the panel state correctly. Let me fix the test:
Assistant
I need to fix my test to properly simulate the React behavior - the bootstrap effect should run whenever the open state changes:
Assistant
I see the bug in my test - my expectation was wrong. Let me fix it:
Assistant
All 14 tests pass. Now let me also test the actual source file by running the structural verification test:
Assistant
Now let me also verify by examining the source code structure more thoroughly. Let me write a more rigorous test that uses the actual source code logic:
Assistant
The regex isn't matching properly. Let me check the actual content:
Assistant
Let me simplify the regex:
Assistant
All 8 tests pass. Now let me run the broader renderer tests to make sure my changes don't break anything:
Assistant
All 302 test files pass. Now let me clean up the temporary test files:
Assistant
Now let me check the git status to confirm what's changed:
Assistant
Only one file is modified. Let me look at the final diff one more time to verify everything:
Assistant
Let me also verify there are no syntax issues by examining the file:
Assistant
Let me also run TypeScript checks to ensure no type errors:
Assistant
Only npm warnings - no TypeScript errors. Let me view the full final file to ensure it's all correct:
Assistant
Now let me do final verification by checking my checklist:
Assistant
Let me run all related tests one final time to confirm:
Assistant
All 771 tests across 58 test files pass. Let me also run the renderer-only tests one more time:
Assistant
All 2547 renderer tests pass. Now let me provide a final summary by viewing the final state of the diff:
Assistant
The fix is complete. Let me provide my final checklist:
Summary of Changes
The fix is in
src/renderer/src/components/floating-terminal/FloatingTerminalPanel.tsx:Changes Made:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.