Skip to content

Desktop cold start can leave the shell on a terminal "Failed to load projects." until an unrelated realtime event refetches #2533

Open

Description

@mariomile

Summary

On a desktop cold start the app can replace its whole shell with Failed to load projects. and stay there. The sidebar bootstrap is the shell's only read, it retries for about half a second, and once it has failed nothing refetches it except an unrelated realtime invalidation. The window recovers on its own seconds or minutes later, whenever some thread or project event happens to fire, which reads as "bb says I have no projects, then it fixes itself".

Expected: a bootstrap that fails while the server is still warming up retries until the server answers, and the shell never presents a transient startup failure as a terminal state.

Versions and environment

  • bb 0.40.0, desktop app, macOS 15.5 (Darwin 25.5.0)
  • Source repro built from main at ad79bbb5ec909524f8f281e62d860c588a86f332, Node 22.22.3
  • Local server on the default port, default data dir (~/.bb), no Connect, no remote host
  • Not provider specific: this is the app shell, before any agent is involved

Steps to reproduce

Deterministic repro against a running bb (Playwright, no bb code changes). It injects the failure the cold start produces naturally, an unreachable server for a few seconds while the renderer is already up:

const t0 = Date.now();
const log = [];
await page.route('**/api/v1/sidebar-bootstrap*', async (route) => {
  const dt = Date.now() - t0;
  if (dt < 8000) { log.push(['fail', dt]); await route.abort('connectionrefused'); }
  else { log.push(['ok', dt]); await route.continue(); }
});
await page.goto('http://127.0.0.1:38886/', { waitUntil: 'domcontentloaded' });
for (let i = 0; i < 6; i++) {
  await page.waitForTimeout(5000);
  console.log(Date.now() - t0, (await page.locator('body').innerText()).includes('Failed to load projects'));
}
  1. Run the snippet against a healthy bb server. The server is reachable again after 8s.
  2. The app shows Failed to load projects. and never recovers on its own.
  3. Focus, visibilitychange, pageshow and online do not recover it either (verified: zero further requests).

Did not reproduce with a single failed request: one 503 followed by a healthy server recovers, because a second consumer of the same query key fetches again shortly after mount. The failure needs to outlast the retry budget, which any cold start on a large data dir does.

Expected vs actual

Actual, request log (ms since load) and screen state:

  fail 385
  fail 655
  fail 925          <- last attempt, 540ms of retry budget spent
  (no further requests at all)

  t= 5452ms  "Failed to load projects."
  t=10460ms  "Failed to load projects."
  t=15464ms  "Failed to load projects."   <- server healthy since 8000ms
  t=20469ms  "Failed to load projects."
  t=25474ms  "Failed to load projects."
  t=30494ms  "Failed to load projects."

Rendered body at that point is the nav chrome plus the error line, no projects,
no threads:

  New thread / Extensions / Automations / GitHub / Kanban / Docs / Tasks /
  Settings / Remote access / Report a bug
  Failed to load projects.

Expected: retries continue while the server is unreachable, and the shell
renders as soon as the server answers.

Evidence

Cause, three parts, all on main at ad79bbb:

  1. The bootstrap runs on the default read-retry budget: two retries at a fixed 250ms delay, and only for transport errors. Any HttpError / BbHttpError, so any HTTP status the warming server returns, gets zero retries.
    • const TRANSIENT_READ_RETRY_COUNT = 2;
      export const TRANSIENT_READ_RETRY_DELAY_MS = 250;
    • export function isTransientReadError(error: unknown): boolean {
      if (toRecord(error)?.name === "AbortError") {
      return true;
      }
      if (error instanceof HttpError || error instanceof BbHttpError) {
      return false;
      }
      const record = toRecord(error);
      if (!record || typeof record.message !== "string") {
      return false;
      }
      const message = normalizeErrorMessage(record.message);
      return (
      message.includes("failed to fetch") ||
      message.includes("load failed") ||
      message.includes("networkerror")
      );
      }
      export function shouldRetryTransientReadQuery(
      failureCount: number,
      error: unknown,
      ): boolean {
      if (failureCount >= TRANSIENT_READ_RETRY_COUNT) {
      return false;
      }
      return isTransientReadError(error);
      }
    • retry: shouldRetryTransientReadQuery,
      retryDelay: TRANSIENT_READ_RETRY_DELAY_MS,
  2. The query is on the static-cache tier, staleTime: Infinity, with no retry override.
    • export function useSidebarNavigation(options?: QueryOptions) {
      const enabled = options?.enabled ?? true;
      useEnvironmentListRealtimeSubscription({ enabled });
      useHostListRealtimeSubscription({ enabled });
      useProjectListRealtimeSubscription({ enabled });
      useThreadListRealtimeSubscription({ enabled });
      return useQuery<SidebarBootstrapResponse>({
      queryKey: sidebarNavigationQueryKey(),
      queryFn: async ({ signal }) => {
      const response = await fetchSidebarNavigation(signal);
      // Bounded and written off the critical path; see the cache module.
      writeCachedSidebarBootstrap(response);
      return response;
      },
      enabled,
      ...REALTIME_OWNED_STATIC_CACHE_QUERY_POLICY,
      // A full load starts from an empty query cache, so the rail showed its
      // two-row loading skeleton on every visit until the bootstrap resolved.
      // Replay the last bootstrap this profile received instead (a bounded
      // copy: projects whole, thread lists capped); the live response replaces
      // it in place. Consumers treat the replay like any sidebar data
      // (navigation only), and a cold profile still shows the skeleton, so
      // first-run behavior is unchanged.
      placeholderData: () => readCachedSidebarBootstrap() ?? undefined,
      });
      }
    • export const REALTIME_OWNED_STATIC_CACHE_QUERY_POLICY = {
      staleTime: Infinity,
      } as const;
  3. The failure is terminal in the UI, and the usual escape hatches are closed: focus and reconnect refetches are gated off while the socket is connected, and the error screen has no retry affordance. Only a realtime invalidation of the sidebar key brings the app back.
    • // The composer renders immediately with loading pickers; only a failed
      // bootstrap with no projects at all replaces it (see B28). While the
      // bootstrap is in flight the project picker shows a loading label and the
      // projectId-dependent queries inside NewThreadComposer stay disabled.
      if (!projects && sidebarNavigationError) {
      return (
      <PageShell contentClassName="min-h-full items-center justify-center">
      <p className="py-12 text-center text-sm text-destructive">
      Failed to load projects.
      </p>
      </PageShell>
      );
      }
    • bb/apps/app/src/main.tsx

      Lines 31 to 38 in ad79bbb

      const queryClient = createAppQueryClient({
      // While the realtime socket is connected, change events and the reconnect
      // watermark own cache freshness; a focus or browser-online refetch on top
      // would re-request every active query on each phone unlock, app switch,
      // and mobile-Safari `online` blip.
      shouldRefetchOnWindowFocus: () =>
      wsManager.getConnectionState() !== "connected",

Why a cold start lands in that window, from ~/.bb/logs/server.1.log on the machine where this was first noticed (data dir at 15 MB bb.db plus a 7.5 MB WAL):

11:58:40.999  Server listening
11:58:42.706  last plugin loaded          (+1.7s)
11:58:47.025  [plugin:github] synced 240 item(s) across 3 repo(s)   (+6.0s)

The desktop probe only waits for /api/v1/system/config, so the renderer can issue its bootstrap during that warm-up. Numbers above are wall clock from the log lines; the request timings are Date.now() deltas inside the interceptor.

What you ruled out

Suggested fix

Give the app shell's bootstrap its own retry policy instead of the generic read budget: treat a warming server (5xx, 408, 429) as retryable alongside transport failures, and back off exponentially to a 4s cap over six retries, about twelve seconds of coverage.

Patch, tests, and end-to-end verification: mariomile/bb@main...mariomile:bb:fix/sidebar-bootstrap-startup-retry

Verified with the repro above against the patched app: attempts at 821, 824, 1082, 1585, 2591, 4600ms, success at 8603ms, and the shell renders projects without ever showing the error. Unit and hook tests added; the hook test fails on main and passes with the change. tsc --noEmit and oxlint clean on the touched files.

Two things deliberately left out, since they are UI changes and CONTRIBUTING asks for an issue first:

  • A retry affordance on the error screen. Today a user whose bootstrap fails past the retry window has no way to ask for another attempt, short of reloading the window.
  • Refetching a bootstrap that has no data when the realtime socket connects, which would make any future variant of this self-healing regardless of the retry budget.

Happy to open a PR for the retry policy alone, or to include either of the above if you want them in the same change.

Suggested priority and effort

Medium. Hits every user whose server is slow to warm up (large data dir, cold page cache, slow disk), no in-app workaround other than reloading the window, no data lost. Effort Low for the retry policy.

AGENT GENERATED

Investigation thread (local bb): thr_xa2mu3c56k, project proj_personal.

Activity

  1. added theissue type on Aug 27, 2026
  2. added
    desktop
    ui
    on Aug 27, 2026
  3. SawyerHood commented on Aug 27, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/2533.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): The sidebar bootstrap exhausts a narrow retry policy after the socket's one-time repair check, so no later lifecycle trigger refetches it.
    • Proposed fix: Add a sidebar-specific policy for transport, 408, 429, and 5xx errors. Use capped backoff, low-rate recovery, and a Retry button.
    • Caveats: The deterministic Linux browser test reproduced the defect. I did not test the natural macOS cold-start timing or the reporter's large database.

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at the base commit, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by GPT-5.6-Sol

  4. added
    confirmed-repro
    on Aug 27, 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-reprodesktopui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions