← reports

#6438 · Catalog tab closures overwrite earlier changes

BugPriority: LowEffort: Lowplugins · confirmed-repro GitHub issue2026-10-28

Trusted base: f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7, fetched from get-bb/bb main.

Verdict: REPRODUCED · Root-cause confidence: high. Four focused regressions fail for the intended persistence/selection assertions in each of two clean trusted-base checkouts.

1. TL;DR

The Plugins catalog can retain tabs that a bulk-close action should remove. Each individual close uses the tab array captured when the component last rendered, rather than the array produced by the previous close in the same event. The last replacement therefore restores earlier removals. When the original active tab is being removed, per-tab navigation can additionally override the survivor selected by the menu. This is a catalog workspace state bug, not a plugin installation failure.

2. Claims vs findings

ClaimFindingEvidence
Closing other detail tabs can leave an unwanted tab open.VerifiedWith GitHub, Automations and Tasks open, closing others from Tasks retains GitHub and Tasks.
Closing multiple tabs to the right has the same problem.VerifiedFrom GitHub, closing the two tabs to its right retains Automations.
The selected surviving tab can be overridden.VerifiedWith Tasks originally active, either bulk action on GitHub ends on Automations instead of GitHub.
State is persisted, not merely painted incorrectly.VerifiedAssertions read the real local-storage workspace and real router location after the actual context-menu action.
The exact reported plugin trio and screenshot reproduce in Chrome.Not visually recheckedThe regression uses three different ordinary uninstalled catalog entries. Browser tooling could not launch because system Chrome libraries are absent; no issue attachment was fetched.

3. Environment

4. Minimal reproduction

The visible interaction under test is: open three ordinary catalog detail tabs in order, right-click the retained tab, and choose a bulk-close command. The test seeds the same persisted workspace directly to avoid unrelated catalog browsing setup, then invokes the real menu.

  1. Create a clean worktree at the full base commit above.
  2. Install the repository's locked dependencies. Apply the investigator-authored regression patch to the existing owner-boundary test file. It changes no production code.
  3. Run the following from that checkout. Exit status 1 and four assertion failures are the expected bug reproduction.
pnpm install --frozen-lockfile --prefer-offline
git apply /path/to/regression.patch
pnpm exec turbo run test --filter=@bb/app -- src/views/ToolsView.plugin-detail.test.tsx -t 'catalog bulk-close persistence regression'

Expected for each case: tabs: [target], activePluginId: target and route /plugins/target. Actual diagnostic records from the first run:

{"action":"Close other tabs","target":"tasks","active":"tasks","persisted":{"tabs":["github","tasks"],"activePluginId":"tasks"},"location":"/plugins/tasks"}
{"action":"Close tabs to the right","target":"github","active":"github","persisted":{"tabs":["github","automations"],"activePluginId":"github"},"location":"/plugins/github"}
{"action":"Close other tabs","target":"github","active":"tasks","persisted":{"tabs":["github","automations"],"activePluginId":"automations"},"location":"/plugins/automations"}
{"action":"Close tabs to the right","target":"github","active":"tasks","persisted":{"tabs":["github","automations"],"activePluginId":"automations"},"location":"/plugins/automations"}
Test Files  1 failed (1)
     Tests  4 failed | 53 skipped (57)

The second clean run produces the same four records and failures. The skipped cases are unrelated existing tests excluded by the focused name filter, not failed setup. No repair or passing-after-fix claim is made.

Regression test

The inserted block below uses the existing trusted test file's router, catalog fixture and query-client helpers. The complete executable patched test file and minimal patch are saved alongside the first and second test logs.

describe("catalog bulk-close persistence regression", () => {
  it.each([
    { action: "Close other tabs", target: "tasks", active: "tasks" },
    { action: "Close tabs to the right", target: "github", active: "github" },
    { action: "Close other tabs", target: "github", active: "tasks" },
    { action: "Close tabs to the right", target: "github", active: "tasks" },
  ])(
    "$action on $target with $active active",
    async ({ action, target, active }) => {
      const entries = [
        GITHUB_CATALOG_ENTRY,
        {
          ...GITHUB_CATALOG_ENTRY,
          entryId: "automations",
          pluginId: "automations",
          source: "builtin:automations",
          displayName: "Automations",
        },
        {
          ...GITHUB_CATALOG_ENTRY,
          entryId: "tasks",
          pluginId: "tasks",
          source: "builtin:tasks",
          displayName: "Tasks",
        },
      ];
      window.localStorage.setItem(
        "bb.plugins.workspace.tabs",
        JSON.stringify({
          tabs: ["github", "automations", "tasks"],
          activePluginId: active,
        }),
      );
      vi.stubGlobal(
        "fetch",
        vi.fn(async (input: RequestInfo | URL) => {
          const url = String(input);
          if (url === "/api/v1/plugins") {
            return new Response(
              JSON.stringify({ enabled: true, plugins: [] }),
              {
                headers: { "content-type": "application/json" },
              },
            );
          }
          if (url.startsWith("/api/v1/plugin-catalog/search")) {
            return new Response(
              JSON.stringify({ results: entries, collections: [] }),
              {
                headers: { "content-type": "application/json" },
              },
            );
          }
          return new Response(JSON.stringify({ error: "not found" }), {
            status: 404,
            headers: { "content-type": "application/json" },
          });
        }),
      );
      renderWithQueryClient(
        <CompactViewportOverrideProvider isCompactViewport={false}>
          <MemoryRouter initialEntries={[`/plugins/${active}`]}>
            <RoutedPluginsView />
          </MemoryRouter>
        </CompactViewportOverrideProvider>,
      );
      await screen.findByRole("button", { name: "Close Tasks" });
      const targetName = target === "github" ? "GitHub" : "Tasks";
      fireEvent.contextMenu(
        screen.getByRole("button", { name: targetName, exact: true }),
      );
      fireEvent.click(
        await screen.findByRole("menuitem", { name: action, exact: true }),
      );
      console.info(
        JSON.stringify({
          action,
          target,
          active,
          persisted: JSON.parse(
            window.localStorage.getItem("bb.plugins.workspace.tabs") ?? "{}",
          ),
          location: screen.getByTestId("location").textContent,
        }),
      );
      await waitFor(() => {
        expect(
          JSON.parse(
            window.localStorage.getItem("bb.plugins.workspace.tabs") ?? "{}",
          ),
        ).toEqual({ tabs: [target], activePluginId: target });
        expect(screen.getByTestId("location").textContent).toBe(
          `/plugins/${target}`,
        );
      });
    },
  );
});

Visual verification limit

No screenshot is supplied. BB Browser Automation first reported no Chrome installation. A temporary official Chrome for Testing 156.0.8078.73 executable could not run because shared libraries, beginning with libglib-2.0.so.0, were absent. No project or OS dependency was added, and no substitute or fabricated screenshot was produced. Electron, iOS Safari and a real browser reload were not exercised. The persisted-state defect is nevertheless directly reproduced by the real UI components and storage in both clean test runs.

5. Root cause

The shared tab-strip handler, lines 366–379, selects a survivor if necessary and invokes every candidate's onClose() in one event:

if (scope !== "self" && closesActiveTab) {
  tabs.find((tab) => tab.tab.id === tabId)?.onSelect();
}
for (const tab of tabsToClose) {
  tab.onClose();
}

The catalog's close callback, lines 527–539, derives each replacement from render-captured openIds and activePluginId:

const tabs = openIds.filter((id) => id !== closedPluginId);
const closedIndex = openIds.indexOf(closedPluginId);
const next = activePluginId === closedPluginId
  ? (tabs[Math.min(closedIndex, tabs.length - 1)] ?? null)
  : activePluginId;
setWorkspace({ tabs, activePluginId: next });
if (next !== null) selectPlugin(next);
else closePanel();

Starting with [GitHub, Automations, Tasks], closing GitHub writes [Automations, Tasks]; closing Automations then writes [GitHub, Tasks] from the original array. The second write undoes the first. The workspace atom persists this replacement to localStorage.

There is also a selection-order problem: selection initially navigates only, with the selected workspace recorded later by the route effect. The existing close callback navigates even for inactive-tab removal. A bulk command's intended survivor can therefore be replaced by stale active state, and the route effect can reopen a supposedly removed tab. Both mechanisms are observed by the four regression cases.

6. Proposed fix

Make each close consume the latest workspace instead of a render snapshot, so removals compose. Record the selected survivor synchronously before closing other tabs, and navigate only if closing the active tab changes the active selection. Preserve ordinary single-close neighbor fallback, closing the final tab, and harmless duplicate close requests. Keep this correction in the catalog workspace owner rather than changing shared menu semantics. The existing linked PR already targets this approach; this investigation does not create a competing fix.

7. Linked PR review

PR #6439 — static review only

GitHub metadata shows this PR is OPEN and explicitly closes #6438. Its diff reads the latest workspace store for each close, guards already-removed tabs, records selection before navigation, and suppresses navigation when an inactive tab closes. Those changes address the verified stale-list and survivor-selection mechanisms. Its added regression table covers both bulk commands and active-selection cases.

Verdict: the static approach matches the root cause; not execution-verified. No definite defect was identified in this narrow static inspection. The PR branch was never checked out and none of its code or tests were run. All executable evidence here is trusted main plus this investigator's independently authored regression. No new PR was opened because creating a duplicate is unsafe.

8. Related issues

No additional issue is needed to establish this root cause. This report concerns pointer-driven catalog context menus only; it makes no claim about keyboard shortcuts, other panel hosts, or mobile behavior. Related issue and attachment links supplied in the issue were not fetched.

9. Verification

The same investigator repeated the test in checkout B at f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7, created separately from trusted origin/main and installed independently with the frozen lockfile. Only the investigator-authored regression patch was applied; the production implementation remained unchanged. Running the exact focused Turbo command above produced 4 failed, 53 skipped again, with the same persisted arrays and router destinations. Duration was 69.58 seconds versus 72.18 seconds in checkout A. This is a repeat clean run, not an independent-agent review. No report correction was needed; the browser limitation is disclosed explicitly.

10. Appendix and trust boundary

Issue text, comments and linked PR data were treated as untrusted evidence. No issue-provided command, script, patch, branch, external report or attachment was executed or fetched. PR metadata and diff were read only. Reproduction code was designed from the trusted catalog, workspace and tab-strip implementation before reading the PR diff.

Setup used pnpm install --frozen-lockfile --prefer-offline, pnpm exec turbo run build, then pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk and a successful full Turbo build retry. The local dev launcher was pnpm dev; server and host health were checked only against the isolated endpoints above. The missing ss/lsof utilities were worked around with Node socket bind checks. Local data directories and private process logs are intentionally not published.

Artifacts: regression patch · complete owner test file · checkout A output · checkout B output.