Floating terminal auto-creates tab after user closes the last one Floating terminal…
- User
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 check how
TabBarreconciles the visible order, and howcloseTabbehaves in the store. - Assistant
Now let me check for existing tests for this component:
- Assistant
Now I'll implement the fixes:
- Assistant
Let me verify how
TerminalPaneusesonPtyExitandonCloseTabto confirm the semantics: - Assistant
There are failures — let me check whether they're pre-existing (they look like native module issues, e.g. better-sqlite3):
- Assistant
All failures are in
src/main/src/relay(native modules, sockets, sqlite) — unrelated to my renderer-only change. Let me confirm they're pre-existing by stashing and re-running just those, plus run the renderer tests with my change: - Assistant
The fix is complete in
src/renderer/src/components/floating-terminal/FloatingTerminalPanel.tsx. Four changes:-
Bootstrap only on the open transition (
FloatingTerminalPanel.tsx:98): the auto-create effect now tracks the previousopenvalue in a ref and only creates a tab on the closed→open transition, reading current tabs viauseAppStore.getState(). Previously it keyed offtabs.length, so any path to zero tabs while open immediately respawned a replacement — which is exactly why the X button couldn't dismiss the panel. -
Explicit close of the last tab dismisses the panel (
closeFloatingTab,FloatingTerminalPanel.tsx:184): aftercloseTab, it checks fresh store state and calls when no tabs remain. This is wired to the tab-bar X button () and to 's (the explicit Cmd+W/Ctrl+D close path).
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.