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 locate the relevant files.
Assistant
Let me search for the FloatingTerminalPanel file mentioned in the issue.
Assistant
Now let me look at the full file and understand the issue better. Let me also check for any existing tests related to this component.
Assistant
Let me understand the issue more thoroughly by analyzing the code. The key issues are:
-
Auto-create tab effect (lines 102-108): When
closeFloatingTabis called on the last tab, it triggerscloseTab(tabId), which removes the tab. Then theuseEffectat lines 102-108 detectsopen && tabs.length === 0and auto-creates a new tab. -
Stale closure bugs:
closeOthersandcloseToRightusetabsfrom theiruseCallbackdependencies, which captures the stale array. -
Expected behavior: Clicking X on the last tab should close the panel. The panel should auto-create a tab only when the panel transitions to open state.
Let me look at the store to understand how
closeTabworks:-
Assistant
The key issue is clear. Let me analyze the solution approach:
-
For the auto-create tab effect: The effect should only create a tab when the panel opens (i.e., when
opentransitions fromfalsetotrue), not whenevertabs.length === 0. I need to track the previousopenstate. -
For
closeOthersandcloseToRight: They should useuseAppStore.getState()to get fresh tab state instead of relying on the capturedtabsarray. -
For
closeToRightspecifically: It should use the tab bar order (visible order) rather than the raw backing array order.
Let me first check how
tabBarOrderworks:-
Assistant
Now I have a clear understanding. Let me create a test script to understand the behavior, then implement the fix.
Let me now write the fix for the
FloatingTerminalPanel.tsxfile:Assistant
Now let me see the closeOthers and closeToRight functions:
Assistant
Now I have a clear understanding of the issues. Let me implement the fixes:
- Auto-create tab effect: Only create a tab when
opentransitions fromfalsetotrue, not whentabs.length === 0at any time closeFloatingTab: Close the panel when closing the last tabcloseOthersandcloseToRight: UseuseAppStore.getState()to get fresh state, andcloseToRightshould usetabBarOrder
- Auto-create tab effect: Only create a tab when
Assistant
I need to use a different approach since python3 is not available. Let me use sed or manually edit the file.
Assistant
Let me use
editcommand instead. First, let me count the lines properly:Assistant
Now let me apply the fixes step by step using the
editcommand:Fix 1: Add
prevOpenRefto track previous open state (after line 65):Assistant
Continue with the fix. I need to add the prevOpenRef after the restoreBoundsRef line. Let me use sed to make the changes.
Assistant
Now let me find the bounds normalization effect and add the prevOpenRef update after it:
Assistant
I'll add the prevOpenRef update after the bounds normalization effect (after line 87):
Assistant
Now let me check where the auto-create effect is:
Assistant
Good. Now I need to update the auto-create effect to check
prevOpenRef.current. The effect is at lines 103-109. Let me update it:Assistant
I'll use the edit command with file option for multiline replacements:
Assistant
Let me try a different approach with sed:
Assistant
Now let me find and update the
closeFloatingTabfunction:Assistant
Now let me find and update the
closeOthersfunction:Assistant
Now let me verify the changes by viewing the modified sections:
Assistant
I see there's an issue with the sed replacement - the braces didn't close properly. Let me fix this:
Assistant
Let me try a more careful approach using a heredoc-based script:
Assistant
Let me try a different approach. I'll create a complete replacement file using awk:
Assistant
Let me check if the fix was applied:
Assistant
Good, but I also need to add the
prevOpenRef.current = openupdate effect. Let me redo this more carefully. I'll use a node.js script since this is a JS/TS project and node should be available:Assistant
Let me check the original file again and plan my edits carefully:
Assistant
Now let me create a node script to apply all the changes:
Assistant
Now let me verify the changes:
Assistant
Let me check the closeFloatingTab, closeOthers, and closeToRight functions:
Assistant
All the changes look good. Now let me verify the file compiles correctly and check if there are any tests:
Assistant
Let me verify the TypeScript compiles correctly by running TypeScript type check:
Assistant
The errors are from dependencies, not from my changes. Let me check if there are specific errors related to my file:
Assistant
These are all TypeScript configuration errors (module resolution, JSX flag), not actual code errors. The file syntax is correct. Let me look for existing tests in the project to see how they run them:
Assistant
Let me check if there are existing tests for the floating terminal:
Assistant
Let me run the tests related to floating terminal:
Assistant
The floating-terminal tests pass. Now let me also check if there are any other tests that might be related to tab operations. Let me also review the full diff of my changes:
Assistant
Wait, I see a potential issue with my approach. The
prevOpenRefupdate effect runs before the auto-create effect due to effect ordering in React. This means when the panel first opens,prevOpenRef.currentwould already betrueby the time the auto-create effect runs, preventing the initial tab creation.Let me fix this by tracking the previous value inside the auto-create effect itself:
Assistant
Let me verify the final changes:
Assistant
<|im_sep|>Now let me run the tests again to make sure everything still works:
<tool_call> <function=bash_terminal> <parameter=command> cd /orca && npm test -- floating-terminal 2>&1 </tool_call>
Assistant
I need to run the tests again using the proper bash terminal command.
Assistant
Good, the tests pass. Let me now verify that the logic is correct by reviewing the key behaviors once more. Let me check how PTY exit flows through the code:
Assistant
I notice that
onPtyExitandonCloseTabboth callcloseTabdirectly (notcloseFloatingTab). Let me verify this is the expected behavior according to the issue:Assistant
I notice there's an
onCloseTabprop that also callscloseTabdirectly. Let me check what this is used for - it might also need to close the panel for explicit close actions:Assistant
I need to check what triggers
onCloseTabin the TerminalPane component to understand if it's an explicit user action or an automatic action. Let me look at the TerminalPane component to see whenonCloseTabis called.Assistant
Looking at this more carefully, I see that
onCloseTabis triggered when the user explicitly closes the last pane in a tab (e.g., Cmd+W). According to the evaluation contract, this explicit close action should also close the panel when it's the last tab. Let me updateonCloseTabto usecloseFloatingTab:Assistant
I need to verify the changes and run tests to make sure everything is working correctly.
Assistant
Let me run the tests to make sure everything still works correctly:
Assistant
All tests pass. Let me now review the final solution to ensure it's correct:
Assistant
Let me now run some related tests to ensure nothing is broken.
Assistant
The test failures are related to
better-sqlite3native module issues, not my changes. Let me verify the floating-terminal specific tests pass and check if there are any tab-related tests I should run:Assistant
The tab-related tests pass. The only failure is an Electron installation issue in the test environment, not related to my code changes.
Let me do a final review of my changes:
Assistant
All changes look good. Let me now submit the solution.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.