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 structure and finding the relevant file mentioned in the issue.
Assistant
I'll start by exploring the repository structure and finding the relevant file mentioned in the issue.
Assistant
Let me look at the store to understand the structure.
Assistant
Let me look at the terminals slice for
closeTabandcreateTab.Assistant
Let me look at the
createTabandcloseTabimplementations.Assistant
Let me check for existing tests related to the floating terminal.
Assistant
Let me look at the TabBar component and how it uses the close handlers, plus the TabGroupPanel for comparison.
Assistant
Let me look at the TabBar's
reconcileTabOrderand how the close handlers are wired (especially how terminal tabs vs editor tabs pass IDs toonClose,onCloseOthers,onCloseToRight).Assistant
Let me look at how SortableTab wires the close handlers, to understand the IDs being passed.
Assistant
Let me look at the TerminalPane component to understand
onPtyExitandonCloseTab.Assistant
Let me look at how
onPtyExitis invoked in TerminalPane and the pty-connection.Assistant
Let me look at how onPtyExit is actually called in pty-connection.ts to understand the exit behavior.
Assistant
Let me look at the
reconcileTabOrderfunction and thetabBarOrderstate to understand the visible order.Assistant
Let me look at how TabGroupPanel implements
closeOthersandcloseToRightfor comparison.Assistant
Let me verify the import path for
reconcileTabOrderand check the existing imports in the panel.Assistant
Now I have a clear understanding. Let me look at the exact lines I need to modify, then make the changes. First, let me open the file.
Assistant
Now let me make the changes. First, add a ref to track the open transition for bootstrapping.
Assistant
Now let me update the auto-create effect to only bootstrap on the open transition.
Assistant
Now let me look at the close callbacks section to update them.
Assistant
Now let me add the import for
reconcileTabOrder. Let me check the existing imports.Assistant
Let me use the
editcommand with line numbers for the import.Assistant
Now let me update the close callbacks. Let me view the current state of those lines.
Assistant
Now let me update the three close callbacks.
Assistant
I see that my edit accidentally removed the
const toggleMaximized = useCallback(() => {line. Let me fix that.Assistant
Now let me update the
onPtyExitandonCloseTabhandlers in the TerminalPane render. Let me view those lines.Assistant
Now let me update the
onPtyExitandonCloseTabhandlers.onCloseTab(Cmd+W explicit close) should usecloseFloatingTabso it closes the panel on the last tab, whileonPtyExitstays as a plaincloseTab(PTY exit removes the tab but keeps the panel open).Assistant
Let me add a clarifying comment for
onPtyExitto make the intent clear (PTY exit must not close the panel).Assistant
Now let me verify the changes compile. Let me check the build/typecheck setup.
Assistant
Typecheck passed with no errors. Let me run the linter on the file.
Assistant
There's a
max-lineslint error. Let me check the lint config and how other files handle this.Assistant
The
max-linesrule (400 for.tsx, skipping blank/comment lines) is exceeded by 3. Let me check the line-length conventions to compact the code.Assistant
No max-len rule, so I can compact lines. Let me simplify
closeToRightto remove the now-redundanttabByIdmap (sincereconcileTabOrderonly returns valid current tab ids) and putcurrentTabson one line, which will bring the file under the 400-line limit.Assistant
Now let me re-run the linter to confirm the max-lines error is resolved.
Assistant
Lint passes. Let me re-run the typecheck to confirm.
Assistant
Let me look at the existing test setup to write a verification test.
Assistant
Let me check how the store is tested to understand the testing approach.
Assistant
There's a
createTestStorehelper. Let me run the existing tests related to the store and tab bar to ensure nothing is broken.Assistant
Existing tests pass. Now let me create a temporary verification script using the real store to confirm my logic. Let me find the
createTestStorehelper.Assistant
Let me create a temporary verification script that exercises the real store with the exact callback logic from the component.
Assistant
Let me place the test in the
srcdirectory (where vitest looks) and fix the import path.Assistant
The code works correctly — my test assertion was buggy.
closeToRightcorrectly closedb(the tab to the right ofain visible order[c, a, b]), leaving[a, c]. ThetoContain(b.id)assertion threw becausebwas correctly removed. Let me fix the assertion.Assistant
All 6 tests pass. Now let me verify how
FloatingTerminalPanelis used to ensureonOpenChange(false)actually closes the panel, and confirm the open-transition logic is sound.Assistant
onOpenChange(false)correctly setsfloatingTerminalOpento false, closing the panel. The panel stays mounted across open/close cycles, so the ref persists and resets on close. The logic is sound. Let me clean up the temp test and run the broader store test suite.Assistant
All 538 tests pass. Let me do a final review of the complete diff.
Assistant
The diff looks clean and correct. Let me verify there are no other tests that depend on the old auto-create-on-empty behavior, and check for any other auto-create paths I might have missed.
Assistant
Let me check the
FloatingTerminalWindowControls.tsxcreateTab call to ensure it's user-initiated.Assistant
launchDefaultAgentis user-initiated, not an auto-create path. The only auto-create path is the effect I modified. Let me run the remaining tests that reference the floating terminal worktree to be safe.Assistant
All tests pass. Let me do a final review of the complete modified sections to ensure coherence.
Assistant
Let me run the final lint and typecheck to confirm everything is clean.
Assistant
Both lint and typecheck pass cleanly. Let me verify the temp test file is fully removed and do a final git status.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.