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's add the import for
reconcileTabOrderand update the effect and callbacks.Assistant
No python available; I'll use
edit/replacecommands instead.Assistant
Now let's make the edits. First, add the import for
reconcileTabOrder.Assistant
No trailing whitespace issue apparent. Let me use
editwith explicit line range instead.Assistant
Good. Now let's find and update the closeFloatingTab, closeOthers, closeToRight functions.
Assistant
Now let's update the
onCloseTabusage in TerminalPane rendering to usecloseFloatingTab(explicit close) while keepingonPtyExitusing rawcloseTab.Assistant
Now let's view the full diff and check for lint/type errors.
Assistant
The diff looks good. Now let's check
closeTabin the store to see whether it does anything withactiveTabIdor worktree management that might affect closing panel logic, and check ifcloseTabfor last tab has any special behavior already (e.g., auto-creating a tab itself).Assistant
Good — this is the terminals.ts
closeTab(the one actually used sinces.closeTabselector reads from terminals slice, this one used for tabsByWorktree, not the tabs.ts one used for unified tab model). Let's confirm which slice'scloseTabis bound tos.closeTabin the combined store.Assistant
Good,
closeTabmaintainstabBarOrderByWorktree. Now let's run TypeScript checks and existing tests for this component.Assistant
No existing tests for this component. Let's check package.json for test/lint/typecheck commands.
Assistant
Good, now pnpm works. Let's set the env var persistently and re-run typecheck for web with a longer timeout, perhaps limiting to just this file isn't possible with tsgo project-based typecheck, but let's try running it in background.
Assistant
Still running. Let's wait more.
Assistant
Process finished with no errors in the log — typecheck passed cleanly.
Assistant
Typecheck passed with no errors. Now let's run lint on the file.
Assistant
Lint passes too. Now let's check the import order didn't break with
oxfmt/format rules; let's run format check.Assistant
Format and lint both pass. Now let's write a quick reproduction test using vitest to simulate the scenario, mocking the store, to confirm the fix behavior logically. Let's check if there's a testing setup with React Testing Library for similar components.
Assistant
Confirmed: these 46 failing test files (74 tests) are pre-existing environment issues (missing native
better-sqlite3bindings), unrelated to my change. My 4 new sanity tests pass. Now let's remove the temp test file and run relevant existing tests for tab-bar and store slices to be safe.Assistant
All tab-bar related tests pass (the "-- path" filter does work, but the full suite still runs since it's the vitest CLI, but shown results all pass). Now let's check terminals/tabs store tests pass too.
Assistant
All relevant tests pass. Now let's double check git status/diff to confirm only the intended file changed.
Assistant
Only the intended file is modified, and the temp test file was removed. Let's do a final review of the full diff.
Assistant
The diff looks complete and correct. Let's also verify no unused variable warnings (
tabsvariable is still used elsewhere in JSX for rendering), and double checktabsis still needed.Assistant
Good,
tabsis still used for rendering. Let's re-run lint and typecheck one final time to be safe after all edits.Assistant
Lint passes for the whole repo with 0 warnings/errors. Let's do a final full diff review and check the checklist items.
Assistant
I found an edge case: if the panel mounts with
open=trueon the very first render (e.g., restored session state), initializingwasOpenRefwithopenwould incorrectly skip bootstrapping. Let me fix that by initializing the ref tofalsealways.Assistant
Let's use the
editcommand with line range instead.Assistant
Now there are two duplicate "Why:" comment blocks; let's merge them into one cleaner comment.
Assistant
Now let's re-run lint and typecheck, and re-verify with the temp test approach for the mount-already-open edge case.
Assistant
All edge cases behave correctly with the
useRef(false)initialization. Let's clean up the temp file and do a final check of the full diff.Assistant
This diff looks solid and addresses all the points in the issue's evaluation contract. Let's run the full relevant test suite one more time and confirm clean state before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.