Repository navigation
Description
Operating system
macOS
Details
Short summary:
Closing a tab sometimes does nothing at all — the X (and Cmd+W, and the context-menu close) is a silent no-op with no error, no toast, and no log. Retrying does not help while the triggering condition holds. There are two independent code paths that dead-end a close, both traced below.
What happened?
1. closeTerminalTab aborts the whole close when the tab's worktree owner cannot be routed
src/renderer/src/components/terminal/terminal-tab-actions.ts
const worktreeRoute = resolveTerminalWorktreeRoute(state, owningWorktreeId)
if (!worktreeRoute) {
options?.onCancel?.()
return // no local prune, no error, no toast
}The tab-strip close button calls closeTerminalTab(tabId) with no onCancel (Terminal.tsx), so hitting this branch is indistinguishable from the click never registering.
resolveTerminalWorktreeRoute returns null whenever resolveWorktreeOperationRouteResult is not resolved. For a tab whose worktree row is absent from worktreesByRepo/detectedWorktreesByRepo, and whose repo is a plain local repo (local repos carry no executionHostId — see the addRemoteRepoFromPath comment in persistence.ts, and resolveIndexedRepoOperationRoute skips repos with neither executionHostId nor connectionId), resolution falls through to the legacy gates in worktree-operation-route.ts and returns missing when any of these hold:
runtimeEnvironmentCatalogHydrated === false. It startsfalse(runtime-status.ts) and only flips insetRuntimeEnvironments, reached via the fire-and-forgethydrateRuntimeEnvironmentStatuses()infetchSettings. So this covers the startup window — and, ifruntimeEnvironments.list()throws (that catch returns without setting anything), the entire session.removedRuntimeEnvironmentIds.size > 0— i.e. any runtime environment removed during this session.- Two or more saved runtime environments with one active (
legacyRuntimeIsUnambiguous === false).
The worktree row is missing during startup hydration for repos whose scan has not landed yet, when a fetchWorktrees call failed, and for runtime-owned worktrees before the deferred remote-worktree-refresh completes.
activateTerminalTab has the same guard, so such a tab also cannot be selected.
Note that the fail-closed here buys nothing for safety: provider teardown already fails closed per PTY inside buildTerminalTabRetirementPlan, which routes each PTY through resolveTerminalHostOwnership(..., 'teardown') and pushes anything it cannot attribute onto unroutablePtyIds (skipped and warned). The outer gate only adds the ability to ignore the user's click.
2. closeUnifiedTab dead-ends when the tab's group record is missing
src/renderer/src/store/slices/tabs.ts
const group = findGroupForTab(state.groupsByWorktree, worktreeId, tab.groupId)
if (!group) {
return null // tab stays in unifiedTabsByWorktree forever
}Every close path funnels through this action, including terminals.closeTab's unified sweep, so a tab whose group record disappeared while activeGroupIdByWorktree still points at that id renders in the strip (TabBar filters on tab.groupId === resolvedGroupId) and can never be removed — not by the X, not by Close Others / Close to the Right, not after a restart. Group records are dropped by tabOrder-based checks (closeUnifiedTab's collapse branch, and the empty-group filter in the workspace-tab reconciliation), so any desync between a group's tabOrder and the tabs pointing at it orphans those tabs.
How can we reproduce it?
Path 1, from a store state (verified with a unit test against the real resolver):
- Have at least one runtime environment saved, or start Orca and act before the runtime-environment catalog hydrates.
- Open a terminal tab on a local-repo worktree whose row is not in
worktreesByRepo/detectedWorktreesByRepo(startup before that repo's worktree scan lands, or after its scan failed). - Click the tab's X — nothing happens.
resolveTerminalWorktreeRoutereturnsnulland the close returns before any state change.
Path 2:
- Get a tab into a group id that no longer exists in
groupsByWorktreewhileactiveGroupIdByWorktreestill points at it (host session-tab snapshot desync, or a group collapse racing a tab add). - The tab renders and is unclosable through every close path.
Anything else that might help:
Two related-but-separate issues found while tracing this, not covered here:
- Remote/host-owned worktrees prune locally and fire the host close as
void closeWebRuntimeSessionTab(...). On RPC failure the catch inweb-runtime-session.tsclears the close intents, so the next host snapshot re-adds the tab — the "closed, then it came back" symptom, distinct from "won't close". The host can also answerrefused: trueand republish. pinned-tab-close-confirm.tsswallows a confirm click that lands withinINTER_REQUEST_ACTION_GUARD_MS(350ms) of the previous one when a request is queued behind it. The dialog stays up, so a second click works.
Activity
fix(terminal): closing a tab is never a silent no-op (#27132)