Skip to content

Terminal button needs two clicks after the terminal was closed #22

Open

Description

@viktorce

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

  1. Open any thread and click the terminal button in the top right. The drawer opens.
  2. Close the terminal with the trash icon and confirm. Typing exit in the shell does the same.
  3. 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

  1. added
    bugSomething is broken or behaving incorrectly.
    value: highActing on it pays off a lot
    readyReproduced in the app, with a recording
    on Nov 19, 2026
  2. viktorce commented on Nov 19, 2026

    @viktorce
    OwnerAuthor

    Reported upstream as pingdotgg#39259, with the fix in pingdotgg#39260.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.readyReproduced in the app, with a recordingseverity: mediumProblem is real but containedvalue: highActing on it pays off a lot

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions