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
Now let's edit the bootstrap effect (lines 97-103) to trigger only on open transition:
Assistant
Now let's view and edit closeFloatingTab, closeOthers, closeToRight.
Assistant
Now let's use edit with exact line range 183:212.
Assistant
Now add the import for
reconcileTabOrderand updateonCloseTabprop for TerminalPane (used by e.g. Cmd+W inside terminal) to usecloseFloatingTabinstead of rawcloseTab, so it also triggers panel close logic.Assistant
Now add the import for
reconcileTabOrder:Assistant
The import is added. Now let's check lint/typecheck to make sure everything compiles.
Assistant
Lint passes. Let's try to run the typecheck with more time in background, or use tsc directly with a longer timeout.
Assistant
Typecheck passes with no errors. Now let's check existing tests related to floating terminal.
Assistant
There's existing store test infrastructure using node environment (createTab works fine in node without electron). Let's write a temp script using vitest run with a custom test file (which we'll delete before submission) to validate the exact logic extracted into a small harness mimicking the component's callbacks.
Assistant
Good, there's a test helper infra I can use for a temporary verification script.
Assistant
All 4 verification scenarios pass, confirming the fix logic works correctly. Now let's remove the temp test file.
Assistant
Now let's run the full existing test suite relevant to this area to make sure nothing broke.
Assistant
Let's also run the broader store test suite and terminal-tab related tests, plus full test suite if feasible time-wise.
Assistant
All 499 store tests pass. Let's run the broader renderer test suite too, and also the tab-bar tests since we use reconcileTabOrder.
Assistant
All tests pass. Now let's do a final review of the diff.
Assistant
This confirms
closeTabdoesn't auto-create replacement tabs; that behavior was solely in the component's effect, which we've fixed. Now let's view final full file once more for sanity check.Assistant
This all looks correct. Let's also verify the full renderer test suite runs fine (a broader sanity pass) within time limits.
Assistant
Passes in isolation with my changes too — confirming it's a flaky test unrelated to my fix, and all the other failures are pre-existing environment issues (missing native bindings for better-sqlite3, node-pty, electron). Not related to our changes. Let's confirm renderer-only test suite (excluding main/native modules) passes cleanly with our changes.
Assistant
All 299 renderer test files (2547 tests) pass. The failures we saw earlier are all in
src/maindue to missing native module bindings (better-sqlite3, node-pty, electron) — an environment limitation unrelated to our change, and one flaky sidebar test that passes in isolation.Assistant
The changes are complete and isolated to the intended file. Let me do a final review of the full diff.
Assistant
This diff addresses all aspects of the issue. Let me go through the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.