Repository navigation
Description
After you close the last terminal in a thread, the next click on the terminal button does nothing. A second click opens the drawer.
terminal-reopen-before.mp4
Steps
- Open any thread and click the terminal button in the top right. The drawer opens.
- Close the terminal with the trash icon and confirm. Typing
exitin the shell does the same. - Click the terminal button again.
Expected: the drawer opens with a new terminal.
Actual: nothing visible happens. The second click opens it.
Seen in the web app on main at a1e7ac2b24, in draft threads and in existing threads.
Cause
The first click does open the drawer. It closes again 22 ms later:
before the 1st click drawer: closed seen on server: term-1
1st click drawer: open (term-1) seen on server: term-1
22 ms later drawer: closed seen on server: (none)
2nd click drawer: open (term-1) stays open
reconcileTerminalIds in apps/web/src/terminalUiStateStore.ts remembers which terminal ids it last saw on the server (serverObservationsByThreadKey). It closes a local terminal that was on that list and is no longer on the server. The list is only refreshed by an effect in PersistentThreadTerminals.tsx, and that component unmounts when the last terminal closes. So the list still says "term-1 was on the server" when the drawer reopens, and the first reconcile closes the new term-1. That same reconcile empties the list, which is why the second click works.
The list was added in commit 17c401ddc0 ("drawer drops a background terminal closed by another client"), so this looks like a regression from that change.
Failing test
Added to apps/web/src/terminalUiStateStore.test.ts, it fails on main with expected false to be true:
it("keeps a reopened terminal after the last one was closed", () => {
const store = useTerminalUiStateStore.getState();
store.setTerminalOpen(THREAD_REF, true);
store.reconcileTerminalIds(THREAD_REF, [DEFAULT_THREAD_TERMINAL_ID], "snapshot-1");
store.closeTerminal(THREAD_REF, DEFAULT_THREAD_TERMINAL_ID);
// The drawer unmounts here, so nothing reconciles the server dropping the terminal.
store.setTerminalOpen(THREAD_REF, true);
store.reconcileTerminalIds(THREAD_REF, [], "snapshot-1");
expect(layout().terminalOpen).toBe(true);
expect(layout().terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]);
});Suggested fix
When closeTerminal runs, also remove that id from serverObservationsByThreadKey. Tried locally: the test above passes, the other 14 store tests still pass, and the drawer opens on the first click.
Activity
viktorce commentedon Nov 19, 2026
Reported upstream as pingdotgg#39259, with the fix in pingdotgg#39260.