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.
Assistant
Let me explore the store and understand
closeTab:Assistant
Now let me look at the relevant effect in the panel file (lines 102-108):
Assistant
Let me look at the TerminalPane:
Assistant
Now let me look at where
onPtyExitis used:Assistant
Now let me look at the TabBar to understand how theX button and context menu actions work:
Assistant
Now let me look at how
closeFloatingTabis called from the X button vs howcloseOthersandcloseToRightare used:Assistant
Let me look at how
tabBarOrderis structured and find the visible tab order logic:Assistant
Let me look at SortableTab to understand the X button:
Assistant
Let me check the existing tests for FloatingTerminalPanel and related files:
Assistant
Now let me check the existing tests in the panel:
Assistant
Now let me check the package.json to understand the testing setup:
Assistant
Let me see if there's a way to test this with vitest. Let me check for similar component tests:
Assistant
Now let me look at the structure of the panel's logic to write the fix:
Assistant
Let me look at the existing test file for tabs to understand the patterns used:
Assistant
Let me now first reproduce the bug to confirm the behavior. Let me look at how tabs relate:
Assistant
Let me look at how the toggle button works:
Assistant
Let me look at
terminalOnlyprop in TabBar:Assistant
So
terminalOnlyonly hides some menu items. The TabBar still usesreconcileTabOrder(tabBarOrder, terminalIds, editorFileIds, browserTabIds).For the floating terminal panel, the props passed are:
tabs={tabs}- only terminal tabsterminalOnly- trueonNewBrowserTab={() => {}}- noop
Let me check if there are any editorFiles or browserTabs passed. Looking at the panel:
Assistant
Let me verify reconcile-order doesn't import any heavy deps:
Assistant
Good - no imports. Now let me think about reproducing the bug. Let me write a quick reproduction test first:
Assistant
Let me look at how othercomponents with similar structure are tested:
Assistant
OK so they use
renderToStaticMarkupandvi.mockto test components. But that doesn't test React hooks like useEffect.Let me think differently. The simpler approach is to test the logic by extracting it into testable functions or by directly testing the store behavior.
Actually, since this is about React effects, let me use
@testing-library/react. Let me check what'savailable:Assistant
Let me check what testing libraries are available:
Assistant
Let me look at closeUnifiedTab:
Assistant
Let me first set up a small reproduction test to confirm my understanding of the bug. Let me check what's in the test file for tabs:
Assistant
Let me create a reproduction script that simulates the bug at the store level:
Assistant
My reproduction confirms the bug at the store level. Now let me write the fix:
Assistant
Now let me apply the fix:
Assistant
Let me add the reconcile-order import after the floating-terminal-panel-bounds import:
Assistant
Let me try edit with a different syntax.
Assistant
The edit tool is failing. Let me try with a different syntax - maybe heredoc:
Assistant
Now let me update the auto-create effect and callbacks. Let me look at the current state of the file:
Assistant
Let me add the new ref for tracking open state and update the auto-create effect:
Assistant
The unicode character got messed up. Let me fix that:
Assistant
Good. Now let me update the auto-create effect:
Assistant
Let me use Node:
Assistant
Now let me update
closeFloatingTab,closeOthers, andcloseToRight:Assistant
Let me check the rest of the file:
Assistant
Good.
tabsis used foractiveTabmemo and for rendering. Thetabsvariable is still defined and used.Now let me run typecheck to verify my changes:
Assistant
Typecheck passes. Let me also verify the file:
Assistant
Let me also look at the full updated panel:
Assistant
Now let me run the existing tests to make sure I didn't break anything:
Assistant
All 1327 component tests pass. Let me also check the lib tests:
Assistant
Let me check if any failures are related to my changes:
Assistant
All failures are in
src/mainandsrc/relaywhich are not related to my changes (they seem to be environmental issues with native modules likebetter-sqlite3). Let me verify by checking if the failure existed before my changes:Assistant
Good. The failures are pre-existing environmental issues. My changes are not responsible.
Now let me write a reproduction test that simulates the React lifecycle for the fix:
Assistant
Let me write the reproduction as a vitest test instead:
Assistant
Now let me also test the closeOthers and closeToRight logic:
Assistant
All 3 tests pass. Let me also run the original test (without my fix) to confirm it would fail:
Assistant
The bug is confirmed in the original code. Let me restore my fix and run the test again:
Assistant
Now let me restore my actual fix test:
Assistant
Let me remove the test file from the repo since the instructions say not to add new tests:
Assistant
Let me re-verify my fix by running the tests from /tmp:
Assistant
Let me verify the final state of the file:
Assistant
Now let me run all the renderer tests once more to make sure I haven't introduced regressions:
Assistant
All 2547 renderer tests pass. Now let me run typecheck once more:
Assistant
Let me check git status to see my changes:
Assistant
Let me do a final verification by running all the tests one more time:
Assistant
The file now exceeds the 400-line limit by 1 line. Let me check if this was already an issue:
Assistant
I need to shorten my comments. Let me trim them to follow the "one or two lines" guideline:
Assistant
Let me reduce more aggressively:
Assistant
Let me look at the current state of the file:
Assistant
Let me look at all the lines I added vs the original:
Assistant
Let me check if the lint max-lines is part of CI checks:
Assistant
Let me check the effective line count after excluding blank lines and comments:
Assistant
Just barely over. Let me reduce one more line. The auto-create effect can be slightly compacted.
Assistant
Lint passes. Let me verify the file again:
Assistant
Let me now run the tests once more to make sure everything still works:
Assistant
All tests pass. Let me also run the typecheck:
Assistant
Let me also do a final reproduction test to verify the fix:
Assistant
Let me debug the issue:
Assistant
closeTab works fine. Let me check what differs in my failing test:
Assistant
I see the issue - my test used a hardcoded 'tab1' id. The real test scenario uses the actual generated id. Let me fix the test:
Assistant
All 4 tests pass. Let me clean up the test files (they were temporary and shouldn't be in the repo):
Assistant
Let me view the final state of my changes:
Assistant
The diff looks clean. Let me run the full test suite one more time to confirm everything is good:
Assistant
All checks pass:
- All 2547 renderer tests pass
- Lint passes (0 warnings, 0 errors)
- Typecheck passes
Let me also clean up the temp files:
Assistant
Let me do a final check by viewing the complete file:
Assistant
Let me also verify I haven't left any test files in the repo:
Assistant
Only the one file is modified. Let me run one more comprehensive verification:
Assistant
All checks pass:
- Lint: 0 warnings, 0 errors
- Typecheck: passes
- Tests: 4 tests pass (the existing floating-terminal tests)
Let me also look at the final diff one more time to ensure the fix is correct and complete:
Assistant
Let me check formatting:
Assistant
Let me run the full tests one more time to ensure formatting didn't break anything:
Assistant
All checks pass:
- Format: All matched files use correct format
- Lint: 0 warnings, 0 errors
- Typecheck: passes
- Tests: All 2547 renderer tests pass
Let me also do a final check of the diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.