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 to understand the codebase and find the relevant files mentioned in the issue.
Assistant
I'll start by exploring the repository structure to understand the codebase and find the relevant files mentioned in the issue.
Assistant
Now let me look at the store to understand
closeTab,createTab, and the tab state structure.Assistant
Let me look at the rest of the closeTab function and understand the tabBarOrder reconciliation.
Assistant
Let me look at the TabBar component to understand how
tabBarOrderis used and how the reconciled visible order is computed.Assistant
Now I understand the tab bar order reconciliation. The
reconcileTabOrderfunction takes the stored order and reconciles with current terminal/editor/browser IDs.For the floating terminal (terminalOnly), the visible tab bar order is:
- For each id in
tabBarOrderthat is a valid terminal id, include it (in stored order) - Then append any terminal IDs not in the stored order
So for
closeToRight, I need to follow the reconciled visible tab-bar order, not the rawtabsbacking array order.Let me look at how the
tabsare passed and whatterminalIdsis in TabBar to understand the order. Let me look at the TabBar to understandterminalIds.- For each id in
Assistant
Now let me understand the FloatingTerminalToggleButton and how the open state is managed.
Assistant
Let me find where the FloatingTerminalPanel is rendered and how the open state is managed.
Assistant
Let me look at the App.tsx to understand the floating terminal open state management.
Assistant
Now let me look at existing tests for the floating terminal to understand the testing patterns.
Assistant
Let me look at the TerminalPane component to understand
onPtyExitvsonCloseTabcallbacks.Assistant
Let me look at how the main Terminal.tsx wires
onPtyExitandonCloseTabto understand the convention.Assistant
I see. The main Terminal.tsx
handleCloseTabreads fresh state viauseAppStore.getState()to determine the owning worktree and current tabs. This is the pattern I should follow.Let me look at the
handlePtyExitin Terminal.tsx to see how PTY exit is handled there.Assistant
Let me look at the
handleCloseToRightin Terminal.tsx to see how it handles the tab bar order.Assistant
Let me look at how
onCloseTabandonPtyExitare invoked in TerminalPane more thoroughly to understand the distinction.Assistant
Let me check the
@alias configuration and verify the reconcile-order import path.Assistant
Let me verify the reconcile-order export signature.
Assistant
Now I have all the information I need. Let me look at the test infrastructure to understand how to write a reproduction test.
Assistant
Let me check the test setup for React components and how tests are run.
Assistant
The test environment is
node, not jsdom. So React component tests with DOM would be harder. Let me check if there are any.test.tsxfiles that test React components to see the pattern.Assistant
The React tests use a lightweight element-tree visiting approach without DOM. The core bug is in the component's
useEffectand callbacks. Let me make the fix and then write a reproduction/verification script using the real store andreconcileTabOrder.First, let me add the import for
reconcileTabOrder:Assistant
Now let me make the edits. First, add the
reconcileTabOrderimport:Assistant
Now let me add the
wasOpenRefref afterpanelRef:Assistant
Now let me modify the auto-create effect to only bootstrap on the open transition:
Assistant
Now let me view and update the
closeFloatingTab,closeOthers, andcloseToRightcallbacks:Assistant
Now let me update all three callbacks:
Assistant
There are leftover lines from the old
closeToRight(lines 240-245). Let me remove them:Assistant
The edit created a duplicate
toggleMaximizedline and a missing closing paren. Let me view and fix this section:Assistant
I see. The closeToRight is missing the closing
)for useCallback, and there's a duplicateconst toggleMaximizedline. Let me fix lines 238-241.Current:
code238: [closeTab] 239: 240: const toggleMaximized = useCallback(() => { 241: const toggleMaximized = useCallback(() => {Should be:
code238: [closeTab] 239: ) 240: 241: const toggleMaximized = useCallback(() => {Let me edit lines 238-241.
Assistant
Now the callbacks look correct. Let me find and update the TerminalPane's
onCloseTabto usecloseFloatingTab(so an explicit close from within the terminal pane also dismisses the panel when it removes the last tab):Assistant
Now I'll update the TerminalPane handlers. Per the contract,
onPtyExit(PTY exit) should just remove the tab without closing the panel or creating a replacement (which is now handled by the open-transition-only auto-create), whileonCloseTab(explicit close like Cmd+W) should behave like the X button and dismiss the panel when it removes the last tab. Let me make this change:Assistant
Let me navigate to that line first, then run the replace:
Assistant
Let me view the full modified sections to confirm correctness:
Assistant
The code looks good. Now let me run the typecheck to verify there are no type errors:
Assistant
The typecheck timed out. Let me run it in the background and check the result:
Assistant
While the typecheck runs, let me look at the store setup to write a verification test:
Assistant
Let me check on the typecheck progress:
Assistant
Let me wait more for the typecheck and meanwhile create a verification test for the logic:
Assistant
Let me create a temporary verification test for the closeToRight reconciled-order logic while the typecheck runs:
Assistant
The verification tests pass. Let me check the typecheck status:
Assistant
Still running. Let me wait more. Let me also check whether the
tsgoprocess is still running.Assistant
The tsgo process finished but the log is ambiguous. Let me re-run capturing the exit code explicitly:
Assistant
While that runs, let me run existing related tests to ensure nothing breaks:
Assistant
All related tests pass. Let me check the typecheck exit code:
Assistant
The typecheck passes (EXIT_CODE=0) and all related tests pass. Let me clean up the temporary verification test file:
Assistant
Now let me run the broader test suite to ensure nothing is broken:
Assistant
The failures appear to be pre-existing environment issues (
better-sqlite3native bindings not compiled). Let me confirm none of the failures are related to my change by checking which test files failed:Assistant
All failures are in
src/main/...(main-process tests using native modules likebetter-sqlite3/node-ptythat aren't compiled in this environment). Let me confirm none are in the renderer code I touched:Assistant
There's 1 renderer failure in
WorktreeCard.pr-display.test.tsx(sidebar, unrelated to my change). Let me verify it's a pre-existing failure by checking the error and confirming it's unrelated:Assistant
The
WorktreeCardtest passes in isolation — it's a flaky test unrelated to my change (it passes when run alone). So my change doesn't break any renderer tests. The only failures are pre-existingsrc/main/native-module environment issues.Let me do a final review of my changes:
Assistant
The diff is clean and complete. Let me run the linter on the modified file to ensure there are no lint issues:
Assistant
Lint and typecheck both pass. Let me do a final sanity check on the complete file structure to ensure there are no syntax issues:
Assistant
The file parses correctly. Let me verify no temporary files are left behind:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.