Reports

#6302 · Background unread events reset sidebar collapse state

BugPriority: MediumEffort: LowuiGitHub issue2026-10-26 · base 3540a699e29034b53da32bb7efa6f5b4055209eb

Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro

1. TL;DR

The sidebar uses the same reveal path for deliberate navigation and for background unread activity. When an unread thread first appears after the initial thread snapshot, the reveal state machine requests that thread be revealed even though the user did not open it. The effect consuming that request removes its group IDs from the saved collapse preferences. This explains why a collapsed project, custom section, machine, or pinned group can unexpectedly reopen. Navigation should still reveal a destination; unread activity should use the existing collapsed-header indicators instead.

2. Claims vs findings

ClaimFindingEvidence
A background thread can reopen a collapsed group.Verified at the production reveal-state boundary.A new unread, non-selected thread produces ["background"] instead of []; the consuming effect removes containing collapse IDs.
This happens for every new thread.Qualified.The cause requires an unread transition after the baseline. Threads already unread in the initial ready snapshot do not trigger it. Read-only arrivals do not trigger this path.
A collapsed header can retain activity without opening.Existing implementation confirmed.SidebarSectionRow renders rollup status while collapsed; no new indicator API is needed.
The exact released macOS build and 25-thread layout exhibit this.Unverified.Checks ran on Linux against current trusted main, not macOS or the released binary. No 25-thread threshold exists in this path.

3. Environment

Visual verification limit: no screenshot is provided. BB Browser Automation could not launch Chrome on this host because required system libraries, including libglib-2.0.so.0, are absent. No system dependency was added. The report proves the production state-machine failure twice and traces its preference writes, not an end-to-end macOS/browser session.

4. Minimal reproduction

  1. Clone the trusted repository and check out the exact base:
    git clone https://github.com/get-bb/bb.git bb-6302
    cd bb-6302
    git checkout 3540a699e29034b53da32bb7efa6f5b4055209eb
    pnpm install --frozen-lockfile --prefer-offline
  2. Download the regression-only patch and apply it. It changes only the existing reveal-state test; production code stays unchanged:
    git apply /path/to/repro.patch
    pnpm exec turbo run test --filter=bb-plugin-thread-list -- app/list/useSidebarThreadReveal.test.ts
  3. The test establishes a ready sidebar with one selected, read thread. It then adds an unread background thread without changing the selection. Expected: no background reveal request. Actual output in both runs:
    AssertionError: expected [ 'background' ] to deeply equal []
    
    - Expected
    + Received
    
    - []
    + [
    +   "background",
    + ]
    
    Test Files  1 failed (1)
         Tests  1 failed | 6 passed (7)
  4. The regression also checks read-to-unread activity and deliberate navigation. It stops at the first failing assertion on the base; all assertions execute successfully after the fix.

The complete executed base regression file is also available as an artifact:

Complete regression test source
import { describe, expect, it } from "vitest";
import {
  makeSidebarEnvironment,
  makeSidebarThread,
  type SidebarThreadOverrides,
} from "../model/fixtures.js";
import { buildPinnedSidebarState } from "../model/pinned-sidebar-threads.js";
import type { SidebarThread } from "../model/sidebar-thread.js";
import {
  INITIAL_SIDEBAR_THREAD_REVEAL_STATE,
  resolveThreadRevealExpansion,
  stepSidebarThreadReveal,
} from "./useSidebarThreadReveal.js";

function thread(id: string, overrides: SidebarThreadOverrides = {}) {
  return makeSidebarThread({
    id,
    projectId: "proj_personal",
    sectionId: id,
    lastReadAt: 1,
    latestAttentionAt: 1,
    ...overrides,
  });
}

interface RevealInputs {
  selectedThreadId: string | undefined;
  threads: SidebarThread[];
  threadsReady: boolean;
  preferencesReady: boolean;
}

function startReveal(
  initial: Partial<RevealInputs> & { threads: SidebarThread[] },
) {
  let state = INITIAL_SIDEBAR_THREAD_REVEAL_STATE;
  const current: RevealInputs = {
    selectedThreadId: "first",
    threadsReady: true,
    preferencesReady: true,
    ...initial,
  };
  const reveal = (next: Partial<RevealInputs> = {}) => {
    Object.assign(current, next);
    const step = stepSidebarThreadReveal(state, {
      ...current,
      threadById: new Map(current.threads.map((item) => [item.id, item])),
    });
    state = step.state;
    return [...step.revealIds];
  };
  return { initial: reveal(), reveal };
}

describe("useSidebarThreadReveal", () => {
  it("does not reveal a background thread when it arrives or becomes unread", () => {
    const { reveal } = startReveal({ threads: [thread("first")] });

    expect(
      reveal({
        threads: [
          thread("first"),
          thread("background", { latestAttentionAt: 2 }),
        ],
      }),
    ).toEqual([]);

    expect(
      reveal({ threads: [thread("first"), thread("background")] }),
    ).toEqual([]);
    expect(
      reveal({
        threads: [
          thread("first"),
          thread("background", { latestAttentionAt: 3 }),
        ],
      }),
    ).toEqual([]);

    expect(reveal({ selectedThreadId: "background" })).toEqual([
      "background",
    ]);
  });

  it("requires leaving and returning before revealing the open thread again", () => {
    const { initial, reveal } = startReveal({
      threads: [thread("first"), thread("second")],
    });
    expect(initial).toEqual(["first"]);

    expect(
      reveal({
        threads: [
          thread("first", { title: "Updated", latestAttentionAt: 2 }),
          thread("second"),
        ],
      }),
    ).toEqual([]);

    expect(reveal({ selectedThreadId: undefined })).toEqual([]);
    expect(reveal({ selectedThreadId: "first" })).toEqual(["first"]);
  });

  it("reveals only newly unread non-open threads", () => {
    const { reveal } = startReveal({
      threads: [thread("first"), thread("second"), thread("third")],
    });
    expect(
      reveal({
        threads: [
          thread("first", { latestAttentionAt: 2 }),
          thread("second", { latestAttentionAt: 2 }),
          thread("third"),
        ],
      }),
    ).toEqual(["second"]);

    expect(
      reveal({
        threads: [
          thread("first", { latestAttentionAt: 2 }),
          thread("second", { latestAttentionAt: 3 }),
          thread("third"),
        ],
      }),
    ).toEqual([]);

    expect(
      reveal({
        threads: [
          thread("first"),
          thread("second", { lastReadAt: 3, latestAttentionAt: 3 }),
          thread("third"),
        ],
      }),
    ).toEqual([]);
    expect(
      reveal({
        threads: [
          thread("first"),
          thread("second", { lastReadAt: 3, latestAttentionAt: 4 }),
          thread("third"),
        ],
      }),
    ).toEqual(["second"]);
  });

  it("keeps initially unread threads collapsed and ignores hidden unread threads", () => {
    const { initial, reveal } = startReveal({
      threads: [thread("first"), thread("second", { latestAttentionAt: 2 })],
    });
    expect(initial).toEqual(["first"]);
    expect(
      reveal({
        threads: [
          thread("first"),
          thread("second", { latestAttentionAt: 2 }),
          thread("third", { latestAttentionAt: 2, isHidden: true }),
        ],
      }),
    ).toEqual([]);
  });

  it("waits for the threads to be ready before establishing the unread baseline", () => {
    const { initial, reveal } = startReveal({
      threads: [thread("first")],
      threadsReady: false,
    });
    expect(initial).toEqual([]);

    expect(
      reveal({
        threadsReady: true,
        threads: [thread("first"), thread("second", { latestAttentionAt: 2 })],
      }),
    ).toEqual(["first"]);

    expect(reveal({ threads: [thread("first"), thread("second")] })).toEqual(
      [],
    );
    expect(
      reveal({
        threads: [thread("first"), thread("second", { latestAttentionAt: 2 })],
      }),
    ).toEqual(["second"]);
  });

  it("waits for preferences and the destination thread before revealing navigation", () => {
    const { initial, reveal } = startReveal({
      threads: [],
      preferencesReady: false,
    });
    expect(initial).toEqual([]);
    expect(reveal({ preferencesReady: true })).toEqual([]);
    expect(reveal({ threads: [thread("first")] })).toEqual(["first"]);
  });

  it("reveals the pinned ancestors and environment of a newly unread child", () => {
    const parent = thread("parent", {
      pinnedAt: 1,
      environment: makeSidebarEnvironment({ id: "env_parent" }),
    });
    const child = thread("child", {
      parentThreadId: "parent",
      environment: makeSidebarEnvironment({ id: "env_child" }),
      latestAttentionAt: 2,
    });
    const threads = [thread("first"), parent, child];

    const { threadIdsToExpand, environmentIdsToExpand, expansion } =
      resolveThreadRevealExpansion({
        thread: child,
        threadById: new Map(threads.map((item) => [item.id, item])),
        effectivePinnedThreadIds: buildPinnedSidebarState({ threads })
          .effectivePinnedThreadIds,
        organizationMode: "chronological",
        personalProjectId: "proj_personal",
      });

    expect([...threadIdsToExpand]).toEqual(["parent"]);
    expect([...environmentIdsToExpand].sort()).toEqual([
      "env_child",
      "env_parent",
    ]);
    expect(expansion).toEqual({ sidebarSectionId: "pinned" });
  });
});

5. Root cause

The app's sidebar adapter derives isUnread from actual read state. In the reveal step, newly unread IDs are added alongside the navigation target:

  const navigationRevealId = pendingNavigation;
  if (navigationRevealId && threadById.has(navigationRevealId)) {
    revealIds.add(navigationRevealId);
    pendingNavigation = undefined;
  }
  const unreadIds = new Set<string>();
  for (const thread of threads) {
    if (thread.isHidden || !thread.isUnread) {
      continue;
    }
    unreadIds.add(thread.id);
    if (
      state.previousUnreadIds &&
      !state.previousUnreadIds.has(thread.id) &&
      thread.id !== selectedThreadId
    ) {
      revealIds.add(thread.id);
    }
  }
  return {
    state: {
      previousThreadId,
      pendingNavigation,
      previousUnreadIds: unreadIds,
    },

The hook's effect then expands ancestors and environments and removes the destination machine, custom-section, project, or built-in section ID from its collapsed preference. It does not distinguish an explicitly opened destination from a background unread event before mutating those preferences. The lower-level expansion helpers are behaving correctly for navigation; the erroneous background reveal request is the cause.

The collapsed section header already rolls pending, working, unread, error, draft, split, and plugin status into its header. This mechanism does not require expansion.

6. Proposed fix

Remove background unread detection from the sidebar reveal state machine. Keep the queued navigation target, readiness gating, and containing-group expansion for explicit navigation. Remove obsolete unread baseline state and the unused thread-list input, replace the prior test that expected automatic unread expansion, and document the existing preference semantics. The implementation is contained in the thread-list plugin, with no new configuration, data migration, dependency, or protocol change.

The prepared fix changes 97 text lines across 3 files (additions plus deletions). The focused test passes after the fix (6 tests). The existing plugin suite passes 468 tests across 37 files; plugin typecheck and lint pass. git diff --check and focused formatting checks pass. Mobile Recents is a separate reveal mechanism and is deliberately not changed by this sidebar fix.

7. Related issues and pull requests

At investigation time GitHub metadata and an open-PR search found no open pull request linked to #6302. #5810 concerns collapsed-header question rollups, not the unread-triggered preference mutation reproduced here.

8. Verification

The same agent repeated the reproduction, not an independent reviewer. A second clean checkout was created at 3540a699e29034b53da32bb7efa6f5b4055209eb; only the regression patch was applied, followed by a fresh frozen install. Running pnpm exec turbo run test --filter=bb-plugin-thread-list -- app/list/useSidebarThreadReveal.test.ts again exited 1 with the identical assertion, expected [ 'background' ] to deeply equal [], and one failure / six passes. No production files were changed in that checkout. No report correction was necessary. Second-run log.

9. Appendix

Build preparation used pnpm exec turbo run build --filter=@get-bb/plugin-sdk followed by pnpm exec turbo run build (71 successful tasks). The first full build exposed an unbuilt SDK runtime; building that trusted SDK resolved it without source edits. Validation used pnpm exec turbo run test typecheck lint --filter=bb-plugin-thread-list. Verification never ran code or fetched links supplied by the issue.

Source links were checked at the recorded base commit. Logs are limited to test/build evidence, with temporary checkout paths normalized; no production store or credentials are included.