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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the structure and find the FloatingTerminalPanel.tsx file.
Assistant
Now let me explore the store to understand the state management:
Assistant
Let me look at the closeTab function:
Assistant
Let me look at the TabBar component:
Assistant
Now let me check the SortableTab to understand how
onClose,onCloseOthers, andonCloseToRightare used:Assistant
Let me check the FloatingTerminalToggleButton and where the open state is managed:
Assistant
Now let me look at how FloatingTerminalPanel is mounted:
Assistant
Let me check existing tests for the floating terminal:
Assistant
Let me check the package.json for test commands:
Assistant
Let me look at the reconcileTabOrder helper:
Assistant
Let me check the FloatingTerminalWindowControls:
Assistant
Let me look at the store to understand the API:
Assistant
Let me run existing tests for floating terminal to see the baseline:
Assistant
Now let me create a temporary script to verify the current behavior. I'll explore how the components interact first:
Assistant
Let me check the FLOATING_TERMINAL_WORKTREE_ID import:
Assistant
Now I have a complete understanding. Let me make the fix to
FloatingTerminalPanel.tsx:Assistant
Now let me apply the fix. First, I'll replace the auto-create effect to only trigger on open transitions:
Assistant
Now let me make the changes. First, I'll add a
wasOpenRefto track open transitions:Assistant
Now let me modify the auto-create effect to only fire on open transition:
Assistant
Now let me modify
closeFloatingTabto close the panel when it's the last tab:Assistant
Now let me modify
closeOthersandcloseToRightto use fresh state and follow visible tab bar order:Assistant
Let me verify the changes:
Assistant
Let me check if TerminalTab is imported (it's used in the new closeToRight callback):
Assistant
Good,
TerminalTabis already imported. Now let me run the typecheck:Assistant
The typecheck passes (no errors in the output). Let me also do a quick checkwith the tsc fallback:
Assistant
The typecheck passes. Now let me create a temporary test script to verify the behavior:
Assistant
All my manual tests pass. Let me also run the existing tests to make sure I didn't break anything:
Assistant
All existing tests pass. Let me also run the entire store tests:
Assistant
All store tests pass. Let me also run the components tests to be safe:
Assistant
All 1327 tests pass. Let me also run the full test suite to be sure:
Assistant
Let me check if these failures are related to my changes or pre-existing:
Assistant
Let me verify these are pre-existing failures not related to my changes:
Assistant
The failures are pre-existing and unrelated to my changes. Let me verify my fix works by checking specific tests for the renderer:
Assistant
All 2547 renderer tests pass. Let me also run the linter on the changed file:
Assistant
Let me check the original file to see if it had any max-lines disable comment:
Assistant
Let me see how TabBar handles max-lines:
Assistant
Let me check the reconcile-order helper:
Assistant
Let me refactor to use the existing helper and trim comments:
Assistant
Let me make the comments more concise and the file size manageable:
Assistant
Let me fix the unused variable and reduce file size:
Assistant
The comment uses em-dash (—) and I usedASCII dash (-). Let me fix the script:
Assistant
The earlier script didn't apply all changes. Let me fix the tabById issue:
Assistant
I'm only 2 lines over the limit. Let me check the file and trim a couple more lines:
Assistant
Hmm, the linter is reporting 402 but I'm at 450. Let me look:
Assistant
There must be a blank line count difference. Let me checkthe .oxlintrc.json for the max-lines rule:
Assistant
Let me count actual code lines (excluding blanks and comments):
Assistant
I need to reduce by 2 actual code lines. Let me look at where I can trim:
Assistant
Let me trim more aggressively:
Assistant
Let me trim the bootstrap effect body further:
Assistant
Let me consolidate the closeOthers and closeToRight comment:
Assistant
Let me look at the structure more carefully:
Assistant
Let me also check the restof the file for inline comments:
Assistant
Let me look at the lines that have both code and inline comments:
Assistant
Let me verify my count more carefully:
Assistant
Let me trim my comments by 2 more lines:
Assistant
Hmm, still 402. Maybe oxlint counts differently than my grep. Let me trytrimming more.
Assistant
Let me check the original file's relationship to the linter:
Assistant
Let me verify by checking how oxlint counts comments:
Assistant
Let me see what the original vs modified file counts:
Assistant
Let me trim 2 more code lines. I'll remove a redundant early return:
Assistant
Now let me verify everything works:
Assistant
Let me re-run my reproduce test:
Assistant
Let me look at the final file to ensure everything looks clean:
Assistant
Let me look at the diff to confirm all my changes are correct:
Assistant
Let me clean up my temporary files:
Assistant
Let me write a more comprehensive vitest-based test to verify the fix:
Assistant
This isn't using testing-library. Let me check what testing frameworksare available:
Assistant
Let me verify all tests pass and run a final check:
Assistant
All checks pass. Now let me also verify the final file once more and think about edge cases:
Assistant
Let me run my comprehensive test once more to confirm everything works:
Assistant
The test is incorrect - I need to simulate React effect ordering properly. Let me fix:
Assistant
Let me re-examine the closeFloatingTab logic - I need to also close the tab when the panel closes:
Assistant
Let me update my fix to also close the tab when closing the panel:
Assistant
Let me also verify all renderer tests still pass:
Assistant
All 2547 tests pass. Let me now look at the final diff:
Assistant
Let me also verify the linter:
Assistant
Let me also check the full renderer test suite:
Assistant
All 2547 tests pass. Let me also check the typecheck once more and look at the complete final state of the file:
Assistant
The final code looks clean. Let me also verify all tests once more:
Assistant
Only one file is modified. Let me also run the full test suite once more to be safe:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.