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 store to understand
closeTab,createTab, and related actions.Assistant
Let me look at the closeTab and createTab actions in the browser slice.
Assistant
Let me look at the existing tests for the floating terminal panel and understand the structure better.
Assistant
Let me look at the TerminalPane component to understand
onPtyExitvsonCloseTab.Assistant
Let me look at where
onCloseTabis invoked andonPtyExitto understand them better. TheonCloseTabis called fromexecuteClosePanewhen there's only one pane (Cmd+W). AndonPtyExitis called when the PTY exits.Let me check the onPtyExit usage.
Assistant
Let me look at the Cmd+W handler that calls
onCloseTab.Assistant
Now let me check existing tests that might exercise the floating terminal auto-create behavior.
Assistant
Let me check how the floating terminal is tested and the test infrastructure.
Assistant
Let me check whether there are component-level tests that render the FloatingTerminalPanel and how tests are run.
Assistant
I now have a clear understanding. Let me view the exact lines I need to edit for the refs and the auto-create effect.
Assistant
Now let me make the edits. First, add the
prevOpenRefand rewrite the auto-create effect to only bootstrap on the open transition.Assistant
The replace command says the file wasn't modified because the text wasn't in "displayed lines." I need to navigate to the line first using
goto. Let me usegoto 64.Assistant
Now let me add the
prevOpenRefdeclaration:Assistant
Now let me rewrite the auto-create effect to only bootstrap on the open transition:
Assistant
Now let me view and rewrite the
closeFloatingTab,closeOthers, andcloseToRightcallbacks:Assistant
Now let me rewrite the three callbacks with the fixes:
Assistant
Now let me update the
TerminalPane'sonCloseTabto usecloseFloatingTab(explicit close) while keepingonPtyExitas rawcloseTab:Assistant
Now let me wire
onCloseTab(the Cmd+W explicit close) tocloseFloatingTabwhile keepingonPtyExitas rawcloseTab:Assistant
Let me check the package.json for the available scripts (lint, typecheck, test).
Assistant
Let me run the linter and the web typecheck on the changed file to verify correctness.
Assistant
The lint timed out. Let me try running oxlint directly on just the changed file.
Assistant
Lint passes for the file. Now let me run the web typecheck (it uses
tsgo):Assistant
Typecheck passed. Now let me run the relevant existing tests to make sure nothing broke. Let me run the floating terminal and tab-bar context menu tests.
Assistant
All relevant tests pass. Now let me create a temporary test to reproduce the original bug and verify my fix. Let me first check the test environment setup.
Assistant
The test environment is 'node', not jsdom. So rendering React components with @testing-library would need jsdom. Let me check if there are any .test.tsx files that render React components.
Assistant
Let me check if
react-test-rendereris available and how the store'screateTestStoreworks, so I can write a focused temporary test.Assistant
Let me write a temporary test that exercises the real store behavior my component logic depends on (createTab/closeTab/setTabBarOrder on the floating terminal worktree), to validate the contract my fix relies on.
Assistant
Let me verify the
closeToRightreconciled-order algorithm specifically with a temporary test:Assistant
The reconciled-order algorithm works correctly. Now let me clean up the temporary test files.
Assistant
Let me review the final diff to ensure everything is correct and clean:
Assistant
The diff looks clean and correct. Let me run a broader set of related tests (tab-bar, tab-group context menus, workspace-session) to be thorough since they exercise the close behaviors.
Assistant
All tests pass. Let me do a final sanity check to confirm all referenced variables are still used and there are no dangling references:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.