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 to understand the codebase structure and locate the relevant file(s).
- Assistant
Let me look at the FloatingTerminalPanel.tsx file first to understand the current implementation.
- Assistant
Let me see the rest of the file.
- Assistant
Let me see the rest of the file.
- Assistant
Let me see the rest of the file.
- Assistant
Let me see the last few lines.
- Assistant
Now let me look at the store to understand how
closeTabworks and also look at any existing tests for this component. - Assistant
Let me make one call at a time.
- Assistant
Let me look at the store to understand how
closeTabworks and the store structure. - Assistant
Let me find the app store definition.
- Assistant
Let me look at the tabs slice to understand closeTab behavior.
- Assistant
Let me look at the full store file to understand how
closeTabworks. - Assistant
Let me look at the terminal slice, which has the
closeTabandcreateTabmethods that the FloatingTerminalPanel uses. - Assistant
Let me look at the terminals slice which likely defines
closeTabandcreateTabfunctions used in the FloatingTerminalPanel. - Assistant
Let me understand the closeTab function and how it relates to the issue. Let me read the relevant sections.
- Assistant
Let me now understand the full picture. Let me also check the TerminalPane component to understand how
onPtyExitandonCloseTabare used. - Assistant
Now let me also check the
onPtyExitcall site to understand the difference: - Assistant
Now let me check the existing tests that could be affected by changes:
- Assistant
Let me also check the
floating-terminal.tslib file to see if there are any relevant functions: - Assistant
Let me look at any relevant test files for terminal/tabs:
- Assistant
Now I have a clear understanding of the issue and the codebase. Let me plan the fix:
Root cause analysis:
- Auto-create effect (lines 97-103): Fires whenever
open && tabs.length === 0, including when the user closes the last tab via X button. This creates a replacement tab before the panel can close. closeFloatingTab(lines 169-174): Simply callscloseTabwithout checking if it's the last tab — it should close the panel when the last tab is explicitly closed.- PTY exit (line 345): Calls
closeTab(tab.id)which removes the tab, but after fix #1, the auto-create effect won't fire since it should only trigger on panel open transition. closeOthers/closeToRight(lines 176-198): Capturetabsin theuseCallbackdependency closure, operating on stale state. Should useuseAppStore.getState().closeToRight: Uses raw backing-array order. Should followtabBarOrder.
Let me implement the fixes:
- Auto-create effect (lines 97-103): Fires whenever
- Assistant
Now let me implement the fix. First, fix the auto-create effect (lines 97-103) to only fire on open transition:
- Assistant
Good, the auto-create effect is fixed. Now let me fix the
closeFloatingTabcallback to close the panel when the last tab is explicitly closed: - Assistant
Good. Now fix
closeOthersto use fresh state from the store: - Assistant
Now fix
closeToRightto use fresh state and follow tabBarOrder: - Assistant
Now let me check that the
onPtyExitcallback in the render is using the rawcloseTab(notcloseFloatingTab), which is the correct behavior for PTY exits: - Assistant
I need to think about the
onCloseTabcallback vsonPtyExit. Looking at lines 365-366:tsxonPtyExit={() => closeTab(tab.id)} onCloseTab={() => closeTab(tab.id)}According to the evaluation contract:
- "An explicit close action that removes the last tab closes the panel" —
onCloseTabis an explicit close action (e.g., typingexitin the terminal). - "a PTY exit removes its tab but must neither close the panel nor create a replacement tab" —
onPtyExitis a PTY exit.
So
onCloseTabshould usecloseFloatingTab(which closes the panel on last tab), whileonPtyExitshould keep using rawcloseTab.I see that
onCloseTab(line 366) callscloseTab(tab.id)directly too. According to the spec, an explicit close action (like typingexitin the terminal) should close the panel when it's the last tab. Only PTY exit should leave the panel open. Let me fixonCloseTabto usecloseFloatingTab: - "An explicit close action that removes the last tab closes the panel" —
- Assistant
All changes are done. Let me now review the complete file to make sure everything looks correct:
- Assistant
The file looks clean and correct. Now let me run the existing tests to make sure nothing is broken:
- Assistant
Good, the existing floating terminal tests pass. Let me also run the store-related tests to make sure nothing is broken:
- Assistant
This test failure is a pre-existing issue unrelated to my changes (it's a module resolution problem with
@/lib/ensure-hooks-confirmed). Let me verify my changes are only in the correct file: - Assistant
Good, only one file changed. Let me view the full diff:
- Assistant
The diff looks clean and correct. Let me run the TypeScript compiler to check for type errors:
- Assistant
Let me find the tsconfig.
- Assistant
Let me try the web tsconfig.
- Assistant
No type errors. Let me also run the linter to check for any issues:
- Assistant
ESLint timed out needing to install. Let me focus on running the available tests to verify the changes don't break anything:
- Assistant
The pre-existing test failures are module resolution issues unrelated to my changes. The floating-terminal-panel-bounds tests passed. Let me do a final review of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.