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 first inspect the repository structure and the floating terminal implementation, then identify available tests and state-management conventions before making a focused fix.
- Assistant
The target component is isolated under
src/renderer. I’ll read repository guidance, the full component, related store actions, and scripts to understand ordering semantics and the most appropriate validation commands. - Assistant
rgis unavailable, so I’ll usegrep. The current auto-create effect is level-triggered (open && tabs.length === 0), confirming the race described. Next I’ll inspect the JSX wiring,TabBarreconciliation logic, store implementation, and PTY-exit callback so the fix distinguishes explicit close from process exit and respects visible order. - Assistant
The wiring confirms
onPtyExitalready calls the raw store close and can remain separate, while tab X / terminal explicit-close should use a wrapper that closes the panel only when the target is the sole current tab. I’ll now inspectreconcileTabOrder, terminal close behavior, and existing component test patterns before editing. - Assistant
reconcileTabOrderexactly matches the tab bar’s rendered ordering and handles stale/missing/duplicate stored IDs. I’ll verify the PTY lifecycle semantics briefly, then update only the panel: edge-trigger bootstrap, fresh-state explicit close, fresh-state bulk actions, and reconciled right-side ordering. - Assistant
I’ll make the focused edit now. The bootstrap effect will treat the initial
open=truemount as an opening transition but will not react to later tab-count changes. Explicit close will inspect current store state before closing, while PTY exit remains wired directly tocloseTab. Bulk actions will also snapshot current state at invocation time, andcloseToRightwill use the same reconciliation function asTabBar. - Assistant
Python is not installed in this environment, so no file changed. I’ll apply the same exact transformations using the available Node runtime and immediately inspect the diff.
- Assistant
The diff now implements all required paths without changing interfaces. I’ll run the formatter in check mode, lint the edited file, and perform the renderer/web typecheck. If those pass, I’ll run the relevant unit tests (tab-order reconciliation and floating panel bounds, plus the broader suite if practical).
- Assistant
pnpminvoked Corepack and blocked on an interactive download prompt, so no validation command ran. The dependencies are already installed; I’ll bypass Corepack using localnode_modules/.binexecutables and inspect the package manager metadata only if needed. - Assistant
Lint, renderer typecheck, and 11 targeted tests passed; only formatting check failed. I’ll format the edited source file, review the resulting diff, and rerun all three static checks.
- Assistant
The formatted implementation passes formatting, lint, and renderer typechecking. The key edge cases are covered by construction: a PTY close changes only tabs (not
open) so bootstrap cannot rerun; an explicit sole-tab close invokes panel close; reopening flips the transition ref and bootstraps once; stale stored order is reconciled before bulk close. I’ll now run the complete Vitest suite to catch unrelated integration regressions, then inspect final status/diff. - Assistant
The complete suite ran 6,795 tests: 6,711 passed, while 75 tests and 41 suites failed for pre-existing environment reasons (Electron not installed, missing
node-pty/better-sqlite3native bindings, root-permission assumptions, plus one timeout). None of the failures reference the edited component or tab ordering; the focused tests already pass. I’ll rerun the focused tests after the full-suite attempt and verify that no test artifacts or unrelated modifications were created. - Assistant
One final edge-case review found another explicit user-close path:
TerminalPane.onCloseTabstill bypasses the wrapper. To satisfy the evaluation contract for any explicit close action (while keeping onlyonPtyExitraw), I’ll route that callback throughcloseFloatingTab, then rerun the focused validation before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.