Skip to content

Keep app API requests out of the browser HTTP cache - #5095

Merged
ymichael merged 2 commits into
mainfrom
bb/slow-provider-icon-loading-thr_krauic2pju
Oct 7, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/slow-provider-icon-loading-thr_krauic2pju

Conversation

@ymichael

@ymichael ymichael commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

On reload, the sidebar's provider icons could take ~20 s to appear. A HAR from ymichael.getbb.app showed GET /api/v1/system/providers? spending 20,005 ms in Chrome's Stalled phase before it was sent, then 270 ms waiting on the server. It was the only stalled request out of 270 on the same HTTP/3 connection, and the server log shows no slow /system/providers requests. The wait is Chrome's HTTP cache lock: only one in-flight request per URL may write the cache entry, and a second request for the same URL waits for it, up to a 20 s timeout. App API GETs used the default cache mode and the JSON responses have no Cache-Control, so a stuck /system/providers request elsewhere in the browser profile (most likely another bb tab or the page being reloaded) held the lock. useProviders() returns an empty list until that request completes, so thread rows rendered without icons.

What changed

  • apps/app/src/lib/app-surface.ts: appSurfaceRequestInit defaults to cache: "no-store" unless the caller passes a cache mode. It is shared by the app SDK client, the plugin SDK client, the Hono API client and file previews, so these requests skip the HTTP cache and its lock. React Query, plus the localStorage copy for providers, already caches the JSON, so Chrome's HTTP cache added nothing for these requests.
  • apps/app/src/lib/api.ts: the full-body file preview fetch passes cache: "default". File content routes answer with private, no-cache plus an ETag, and this keeps the browser revalidating unchanged files with a 304. That fetch can still hit the lock, as before. The partial first fetch in file previews was already no-store.
  • Logos, plugin bundles and static assets don't use this helper and keep their long-lived browser caching. No wire, CLI or daemon changes.

How you verified

  • Reproduced the mechanism in headless Chrome against a stub server. Tab A sent GET /api/v1/system/providers? and got no response; the same request from tab B stalled 20,008 ms, and the stub received it only after the timeout. With cache: "no-store" on tab B's fetch, the request took 1 ms.
  • Added a test to app-surface.test.ts: the default is no-store and a caller's own cache mode is kept.
  • pnpm exec turbo run typecheck lint test --filter=@bb/app: passes (lint 0 errors; 587 test files passed, 2 skipped).
  • Not yet re-checked on a real reload through ymichael.getbb.app with the fix deployed.

🤖 Generated with Claude Code

AGENT GENERATED

qa and others added 2 commits October 7, 2026 09:53
Chrome lets one in-flight request per URL own its HTTP cache entry; a
second request for the same URL stalls up to 20 seconds waiting for it.
App API GETs used the default cache mode, so a stuck request in another
tab held up /api/v1/system/providers on reload and the sidebar provider
icons appeared 20 seconds late. API responses are cached by React Query,
so default app API requests to cache: "no-store" unless the caller picks
a mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
File content routes answer with private, no-cache plus an ETag so the
browser can revalidate unchanged files with a 304. The full-body file
preview fetch opts back into the default cache mode so it keeps that
revalidation instead of the app API no-store default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 488ec9f into main Oct 7, 2026
28 checks passed
@ymichael
ymichael deleted the bb/slow-provider-icon-loading-thr_krauic2pju branch October 7, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant