Skip to content

Stale second tab reverts the root composer's project selection to personal via cross-tab localStorage sync #3190

Closed

Description

@apsknight

Summary

With two bb tabs open on the same origin, pressing a project's sidebar plus button ("New thread in ") in one tab flashes the project into the composer for one frame and then reverts to "Work in a project" (personal). The other tab — which loaded before the project was created and still has a stale sidebar-bootstrap project list — receives the selection over the localStorage storage event, fails to find the project in its list, and writes proj_personal back, clobbering the first tab. Expected: a project that exists on the server is selectable regardless of what other tabs have cached.

Versions and environment

  • bb-app 0.42.1 (npm, launched from source via a thin launcher; @get-bb/plugin-sdk 0.4.47), macOS 15, Node 24.15
  • Chrome 152, two tabs on http://127.0.0.1:38899
  • Standard project with a local_path source; no Connect, no worktree env
  • Also reproduced against main source at accd559 by reading the code paths below (same logic as the shipped bundle)

Steps to reproduce

  1. Open bb in tab A. Leave it on the root composer.
  2. Create a new project (Settings → New project, or POST /api/v1/projects). Do not reload tab A. (Equivalent, and what I used for a deterministic repro: intercept GET /api/v1/sidebar-bootstrap in tab A so the response omits the new project — network route "**/api/v1/sidebar-bootstrap*" --body <json without the project>.)
  3. Open bb in tab B (fresh load; its sidebar shows the new project).
  4. In tab B, hover the new project's sidebar row and press its plus button ("New thread in "), or pick the project in the composer's "Work in a project" picker.

Did not reproduce with: a single tab; two tabs that both loaded after the project was created; any project that exists in both tabs' lists.

Expected vs actual

Tab B (clicking tab), instrumented Storage.prototype.setItem + 'storage' listener, key bb.root-compose.project-id:
  [35399 ms] B-set  proj_ekybszguti      <- plus button writes the selection
  [35425 ms] B-evt  proj_personal        <- storage event from tab A, 26 ms later
  localStorage now: proj_personal
  composer footer: "Work in a project"

Tab A (stale tab), same instrumentation:
  [123245 ms] A-evt  proj_ekybszguti     <- receives B's selection via storage event
  [123247 ms] A-set  proj_personal       <- NewThreadComposer normalises unknown id -> personal and writes it back
  sidebar in A: only "New thread in kiro-verify" (no Yojaka row; stale list)

Visually in tab B the composer shows Yojaka · Work locally · Current (mainline) for ~1–2 frames (6 fps screen recording, frames 9→11) then snaps back to Work in a project. Server is consistent throughout: GET /api/v1/sidebar-bootstrap returns both projects, GET /api/v1/projects/proj_ekybszguti/branch-options?hostId=… → 200.

Expected: tab B keeps proj_ekybszguti and shows the environment/branch selectors. Tab A, at most, should ignore or refetch — never overwrite a shared key based on its own stale cache.

Evidence

Mechanism, at accd559:

  • The selection is a cross-tab-synced atomWithStorage (createLocalStorageSyncStorage subscribes to storage):
    const rootComposeProjectIdStorage = createLocalStorageSyncStorage<string>({
    parse: parseStoredProjectId,
    serialize: (value) => value,
    });
    const rootComposeProjectIdAtom = atomWithStorage<string>(
    ROOT_COMPOSE_PROJECT_ID_STORAGE_KEY,
    PERSONAL_PROJECT_ID,
    rootComposeProjectIdStorage,
    { getOnInit: true },
    );
    and
    function subscribeToLocalStorageKey(
    key: string,
    callback: StoredValueListener,
    ): () => void {
    const localStorage = getLocalStorage();
    if (
    !localStorage ||
    typeof window === "undefined" ||
    typeof window.addEventListener !== "function"
    ) {
    return () => {};
    }
    const handleStorage = (event: StorageEvent) => {
    if (event.storageArea === localStorage && event.key === key) {
    callback(event.newValue);
    }
    };
    window.addEventListener("storage", handleStorage);
    return () => {
    window.removeEventListener("storage", handleStorage);
  • NewThreadComposer validates the requested id against useSidebarNavigation().data.projects and substitutes PERSONAL_PROJECT_ID when it is absent and the query is no longer placeholder data:
    const requestedCandidate = requestedProjectId ?? PERSONAL_PROJECT_ID;
    const candidateKnown =
    isProjectlessProjectId(requestedCandidate) ||
    (projects?.some((project) => project.id === requestedCandidate) ?? false);
    const replayKnowsCandidate =
    !sidebarNavigationQuery.isPlaceholderData || candidateKnown;
    const sidebarNavigationSettled =
    sidebarNavigationQuery.isError ||
    (sidebarNavigationQuery.isSuccess && replayKnowsCandidate);
    const projectId = useMemo(() => {
    if (isProjectlessProjectId(requestedCandidate)) return PERSONAL_PROJECT_ID;
    if (!projects || !replayKnowsCandidate) return requestedCandidate;
    return candidateKnown ? requestedCandidate : PERSONAL_PROJECT_ID;
    }, [candidateKnown, projects, replayKnowsCandidate, requestedCandidate]);
  • RootComposeView then writes the normalised value back to the shared atom, which is what propagates to the other tab:
    useEffect(() => {
    if (projectId === rootComposeProjectId) return;
    setRootComposeProjectId(projectId);
    }, [projectId, rootComposeProjectId, setRootComposeProjectId]);

So any tab whose sidebar-bootstrap cache lacks the project acts as a "reverter" for every other tab. Stale caches are easy to get: a background tab that lost its live-update socket, or simply one that loaded before the project was created (the New project flow in the other tab doesn't invalidate this tab's query).

IDs from the repro: proj_ekybszguti (new project), proj_87mvthcq9x (pre-existing), host host_jd965tsynm.

What you ruled out

  • Not A project's new-thread button replaces the focused pane instead of opening beside it #2795 — that is about which pane the composer opens in; here the composer opens but the project selection is reverted.
  • Not a server/project problem: /api/v1/projects/<id>/branch-options and sidebar-bootstrap both return the project; the click sticks with a single tab.
  • Not the picker vs. plus button: both write the same atom and both revert.
  • Reloading tab A (so its list includes the project) makes the problem disappear, which is the workaround.

Suggested priority and effort (optional)

Medium — anyone who keeps a second bb tab open cannot start a thread in a newly created project until they find and reload the other tab, and there is no UI hint about why. Effort probably Low: either don't write the normalised fallback back to storage when the change came from a remote storage event (or when the candidate is not known only because of this tab's cache — e.g. refetch sidebar-bootstrap before deciding), or make the write-back local-only (sessionStorage/no cross-tab sync for the normalised value).

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

AGENT GENERATED — written by a coding agent (pi) from a live repro on the user's machine; instrumented traces above were captured with a headless Chrome driven via agent-browser, screen recording frames reviewed by the agent. Filed on behalf of @apsknight.

Activity

  1. added theissue type on Sep 7, 2026
  2. added
    ui
    confirmed-repro
    on Sep 7, 2026
  3. bb-slop-cop commented on Sep 7, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Low · labels ui, confirmed-repro
    • Report: https://get-bb.github.io/reports/issues/3190.html
    • Verdict: REPRODUCED · high confidence · reproduction label confirmed-repro
    • Root cause: The root composer used cross-tab-synced storage for a tab-local project selection. A tab with a stale settled project list normalized an incoming unknown project to personal and persisted that fallback back to every tab.
    • Regression: The focused test reproduced one unexpected personal-project write before the fix and passed afterward; the full app suite passed 3,926 tests with 3 skipped.
    • Fix: Keep new-thread picker selections tab-local #3191 scopes the selection to the existing tab-local storage adapter (46 changed text lines across 2 files).
  4. added a commit that references this issue on Oct 1, 2026
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

    confirmed-reproui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions