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
Now let me look at the related files to understand the store and the TerminalPane component.
Assistant
Assistant
Let me look at how the X button in the tab bar calls onClose. Let me look at the TabBar component to understand the onClose flow.
Assistant
Let me look at the SortableTab component to understand how the X button works and what onClose does.
Assistant
So the X button (and the "Close" context menu item) calls
onClose(tab.id), which in FloatingTerminalPanel iscloseFloatingTab, which just callscloseTab(tab.id). Let me look at the reconcile-order logic to understand the visible tab-bar order forcloseToRight.Assistant
Let me look at how TabBar computes
orderedItemsto understand the visible tab-bar order.Assistant
Let me look at the TerminalPane more to see when
onPtyExitvsonCloseTabare called.Assistant
Let me look at how onPtyExit is actually invoked, and the OverlayLayer to understand the flow.
Assistant
I see. So in the floating terminal,
onPtyExitandonCloseTabboth callcloseTab(tab.id). Let me check for existing tests for the floating terminal.Assistant
Let me look at the FloatingTerminalToggleButton to understand how the panel is opened/toggled.
Assistant
Let me find where FloatingTerminalPanel is used (the parent that controls
openandonOpenChange).Assistant
Let me look at
setFloatingTerminalOpenWithFocusandfloatingTerminalOpento understand the open state.Assistant
onOpenChangeissetFloatingTerminalOpenWithFocus, which accepts a boolean directly. Now let me view the exact lines I need to edit in the FloatingTerminalPanel.Assistant
I now have a clear picture. Let me make the edits. First, I'll add the import for
reconcileTabOrder.Assistant
No python3. Let me use the editor commands instead. Let me open the file.
Assistant
Now let me make the edits using the replace command.
Assistant
Now add the
wasOpenRef:Assistant
Now replace the auto-create effect:
Assistant
Now replace
closeFloatingTab:Assistant
Now I'll replace the three close callbacks (lines 182-211) with the fixed versions:
Assistant
Now let me verify there are no unused variables introduced. The
tabsvariable is still used elsewhere (rendering, activeTab), so it's fine. Let me check the build/typecheck setup.Assistant
Let me run the web typecheck to confirm my changes compile:
Assistant
Typecheck timed out. Let me try the faster linter:
Assistant
Lint passes. Let me verify the
reconcileTabOrdersignature and the store types align:Assistant
Let me run the existing relevant tests to ensure nothing is broken:
Assistant
The logic looks sound. Let me write a temporary test to verify the behavior using the actual store. First, let me look at how store tests are set up.
Assistant
Let me check whether there are existing React component rendering tests I can model a temporary verification test on.
Assistant
The test environment is
node(no jsdom), and full rendering would be heavy. Let me look at how the store tests set upcloseTabso I can write a focused temporary test verifying the store-level behaviors my callbacks rely on.Assistant
I can replicate the store setup. Let me create a temporary test that replicates the exact close-callback logic I wrote and verifies it against the real store:
Assistant
The vitest config only includes
src/**/*.test.ts. Let me place the test inside src temporarily.Assistant
The relative path is wrong. Let me use the
@/alias instead.Assistant
The
reconcileTabOrdercall needs the editorIds arg. Let me re-check its exact signature:Assistant
The
editorIdsparameter is required (no default). My call passes only 2 args, leavingeditorIdsundefined. Let me fix the component to pass[]:Assistant
Now let me update my temporary test to match (pass
[]) and re-run:Assistant
All 4 tests pass. Let me verify the in-pane
onPtyExit/onCloseTabhandlers in the JSX still just callcloseTab(so PTY exits don't close the panel or create replacements):Assistant
The X button (
onClose={closeFloatingTab}) now closes the panel on the last tab, while PTY exits (onPtyExit) and in-pane closes (onCloseTab) just remove the tab (no panel close, no replacement). Let me clean up the temporary test and run the broader related test suites.Assistant
All passing. Let me check if there's a terminals test file and run it too, plus verify the final diff:
Assistant
The diff is clean. Let me run the terminals-hydration test and confirm the file still lints:
Assistant
Everything passes. Let me do a final review of the complete modified sections to ensure correctness:
Assistant
Let me verify the blank line separator after the effect is intact (lines 116-118):
Assistant
The blank line is intact and lint passes. Let me confirm no temporary files remain and do a final status check:
Assistant
Only the intended file is modified, and the temporary test is removed. Let me do a final lint pass on the whole floating-terminal directory to be safe, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.