Skip to content

Overlap render invariant groups within the existing CI job - #7669

Merged
ymichael merged 2 commits into
mainfrom
bb/ci-render-invariant-shards
Nov 17, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/ci-render-invariant-shards

Conversation

@ymichael

@ymichael ymichael commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Render invariants are a recurring CI critical path: across 17 recent successful jobs the median was 154 seconds, including a 111-second build/test step. In main run 44022670766, six serial scenarios consumed 78.68 seconds plus Vitest startup/import overhead. Their browser settling and observation windows can overlap when each group has an independent fixture.

What changed

Partition the same six scenarios into idle, typing, and push files. Run those files concurrently with three Vitest workers inside the existing four-vCPU job. Job count, runner size, workflow, and Turbo configuration are unchanged from the base. Each file owns its server/database/provider/browser fixture; scenarios within a file retain fresh browser contexts and sequential execution. Keep all assertions, fixture sizes, observation windows, and timeouts. Setup repeats per fixture, but dependency installation and profiling builds happen once.

How you verified

pnpm exec turbo run test:render-invariants lint typecheck --filter=@bb/render-invariants passed all six real-browser scenarios, lint, and typecheck with the final configuration. Local suite time was 48.17 seconds; a prior CLI experiment took 49.69 seconds. The split files run serially took 120.66 seconds. These local results do not establish performance on a four-vCPU CI runner.

An AST comparison confirmed all six test names and callback bodies match the original after normalizing formatting and fixture access. Whitespace check passed. Final single-job CI run 44030986921 passed all six scenarios on the existing four-vCPU runner. Vitest took 56.26 seconds versus 83.27 seconds in sampled original main run 44022670766 (about 32% lower). The complete render job took 102 seconds; prerequisites hit cache in this run, so its full difference from the historical 154-second job median cannot all be attributed to this change. These are observational comparisons, not repeated controlled measurements. The full run is now green after rerunning an unchanged Windows PromptBox paste test that failed on the first attempt. The render job passed on its first attempt.

AGENT GENERATED

@ymichael
ymichael marked this pull request as ready for review November 17, 2026 06:19
@ymichael
ymichael marked this pull request as draft November 17, 2026 06:23
@ymichael ymichael changed the title Overlap render invariant groups on three isolated CI runners Overlap render invariant groups within the existing CI job Nov 17, 2026
@ymichael
ymichael marked this pull request as ready for review November 17, 2026 06:27
@ymichael
ymichael merged commit 2a5bab4 into main Nov 17, 2026
99 of 100 checks passed
@ymichael
ymichael deleted the bb/ci-render-invariant-shards branch November 17, 2026 06:42
ymichael added a commit that referenced this pull request Nov 17, 2026
…nload (#7615)

## Human comments

## What was wrong

**Cold load (hotspot 7).** I measured before changing anything. Adding
HTML preload hints for the priority plugin bundles (via a proxy) moved
their download from ~730 ms to ~320 ms at RTT 150 over H2, but ready
didn't change (1118 vs 1127 ms). Hinting every enabled plugin made ready
worse (+60 ms). Request initiator stacks showed the actual chain. The
WebSocket's `handleConnected` invalidates `/api/v1/plugins`, and plugin
boot's `fetchQuery` landed right after it, so boot waited ~150 ms for a
second fetch of the list. Only then did it discover the lazily loaded
zod runtime that thread-list needs (one more round trip). Only then did
thread-list mount and issue `listPreferences`. Once boot stopped
waiting, two hidden couplings appeared. (a) Non-priority plugins had
only stayed off the HTTP/1.1 connections because of that accidental
delay. (b) The toaster and thread-row metadata splits now revealed
through Suspense before the thread view. React stamps every Suspense
visibility toggle and holds the next retry reveal for 300 ms, so the
thread view committed ~300 ms late.

**Reload / tab close (hotspot 8).** A non-persisted `pagehide` ran
`disposePluginFrontends`. It removed every plugin's slot registrations
and CSS, so React synchronously unmounted each plugin tree. A
thread-detail effect then forced layout, and ProseMirror tore down its
view, all in a document the browser was about to discard.

**First-run onboarding (found in review of this PR).** Making plugins
the page doesn't need wait for the route paint broke onboarding. Only
the main app layout sent that signal, and `OnboardingGate` doesn't
render the main app during first run. So onboarding loaded only the
priority plugins (3 of 26), and the Devices step showed an empty Connect
sign-in panel. Nothing caught it: every browser harness marks onboarding
done before it starts, and the load-order tests stub the signal.

## What changed

- **Server** (`apps/server/src/server.ts`): the SPA shell now carries
the enabled plugin list as inert JSON (`<script type="application/json"
id="bb-plugin-list">`, the same body `GET /api/v1/plugins` returns, with
`<` escaped). The shell ETag hashes the rendered document, so a
validator from before a plugin change never 304s a stale list. The shell
is no longer served from the `.br` sidecar; the compress middleware
gzips it (9.5 KB, and it replaces the separate `/plugins` request on the
critical path). The element ID lives in `@bb/server-contract`.
- **App boot**:
- `main.tsx` seeds the plugin-list query from the shell, dated
`performance.timeOrigin` so the initial-connect invalidation still
replaces it.
- Initial boot reads the cached list (`ensureQueryData`) instead of
waiting on a refresh. A reconcile requested before boot (e.g. the
connect-time `plugins-changed`) now runs after boot instead of being
dropped.
- The zod/pierre runtime loaders moved to `plugin-runtime-groups.ts` so
the priority prefetch warms them at entry evaluation.
- Non-priority plugins wait for `whenScreenPainted` before downloading.
- **Screen paint signal** (`apps/app/src/lib/screen-paint.ts`,
`components/ScreenPaintSignal.tsx`): the route-content paint signal is
renamed to a screen paint signal and moved into its own component. The
main app routes and the first-run onboarding screen both render it.
`whenScreenPainted()` also resolves 3 s after page start if no screen
sends it, so a screen without the signal (the auth callback today, any
future full-screen gate) delays plugin loading instead of stranding it.
The signal stays inside the main layout rather than at the app root,
because from the root it would fire before the lazy
Settings/Plugins/Skills pages draw. `docs/ui-code-splitting.md`
documents both.
- **Bundle budget** (`apps/app/bundle-budget.json`): the boot brotli
limit rises 512 bytes (428,127 → 428,639). The onboarding paint signal
and its fallback add 0.3 KB brotli to the boot payload. That put it at
418.2 KB against a 418.1 KB limit, which the rest of this PR plus main
had left 0.2 KB under. The raw limit is unchanged.
- **`defineSplit({ suspends: false })`**: renders `loading` until the
module arrives, then mounts without a Suspense boundary. It's used for
the two boot-time background splits, `app-toaster` and
`thread-row-metadata-collectors`. Documented in
`docs/ui-code-splitting.md`.
- **Unload**: `pagehide` with `persisted: false` calls
`discardPluginFrontends`. It aborts pending loads and content-script
signals and runs content-script cleanups in reverse order, which the SDK
promises. It no longer unmounts slot trees, removes CSS, clears statuses
or publishes diagnostics. Discard is terminal: a live reconcile after it
does nothing. The bfcache path (`persisted: true` → keep, `pageshow` →
reconcile) is unchanged. The SDK README now says slot components are not
unmounted at unload.
- I didn't add preload `<link>` hints. Measured on top of this change,
they moved bundle downloads earlier but left ready unchanged or slightly
worse in every configuration (table below). The duplicated plugin CSS is
left to the per-plugin CSS scoping work in a separate thread (hotspot
3), which owns that pipeline.

No wire changes to the daemon protocol.

## How you verified

Production builds of origin/main `da3e60b81d` and this branch, each
served by `pnpm start:worktree` with the same deterministic 500-thread
fixture (long timelines 1.2k/2.9k/9.7k items). Headless Chrome 145;
HTTP/2 through a local TLS proxy (like bb Connect) or HTTP/1.1 direct;
CDP latency/throughput and CPU emulation. Variants alternated run by
run, 5 runs each, median. "Ready" = sidebar row + visible timeline row +
composer on a 2.9k-item thread. Cold = empty cache; warm = second load
in the same profile (returning user).

| Config | main cold | branch cold | main warm | branch warm |
|---|---|---|---|---|
| H2, RTT 150 | 1108 | **958** | 812 | **665** |
| H2, RTT 150, 20 Mbit/s | 1444 | **1330** | 833 | **688** |
| H2, RTT 50, 4× CPU | 1783 | **1704** | 1999 | **1863** |
| H1, RTT 50 | 750 | **685** | 562 | **535** |
| H2, RTT 0 | 430 | 400 | 419 | 435 |

Ablation (branch + priority preload hints in HTML): 965 / 1351 / 1701 ms
cold for the first three rows, i.e. no gain over the branch alone.

Reload and close, median of 6 (pagehide = the trace's `pagehide`
EventDispatch; reload = reload command to ready):

| | main | branch |
|---|---|---|
| pagehide, 1× CPU | 162 ms (48 ms layout, 31 ms style) | **1 ms** |
| pagehide, 4× CPU | 762 ms (226 ms layout) | **3 ms** |
| reload → ready, 1× | 524 ms | **358 ms** |
| reload → ready, 4× | 2196 ms | **1436 ms** |
| tab close/navigate away, 1× / 4× | 190 / 738 ms | **38 / 57 ms** |

Behavior checks on both builds: a draft typed right before reload
survives; back/forward restores a working composer, sidebar and plugin
styles (Chrome reports `BrowsingInstanceNotSwapped`, so neither build
enters bfcache in this harness). No duplicate plugin bundle requests.

Tests (each fails on the old behavior):
- `app-shell-plugin-list.test.ts`: boot candidates resolve from the
shell's list while the connect refresh is still in flight (hangs with
the old `fetchQuery` path).
- `plugin-frontend-boot-catch-up.test.ts`: a reconcile requested before
boot re-reads the list after boot (fails if the pre-boot request is
dropped).
- `plugin-frontend-reload.test.ts`: discarding an unloading page aborts
signals and runs cleanups in reverse order, keeps the plugin UI and
stylesheet mounted, and stays terminal.
- `plugin-frontend-load-order.test.ts`: other plugins' downloads wait
for the screen paint.
- `screen-paint.test.ts`: with no signal, waiters are released at the 3
s deadline, counted from page start (fails without the deadline).
- `OnboardingGate.test.tsx`: the first-run setup guide sends the paint
signal even though the app behind it never renders (fails without it).
- `tests/render-invariants/src/idle.test.ts` (real browser): with
onboarding not done, opening the app requests every enabled plugin
bundle. Without the fix, 3 of 6 load and it fails.
- `define-split.test.tsx`: a `suspends: false` background split doesn't
delay a sibling route reveal (≈5 ms vs 298 ms with `suspends: true`).
- `static-shell.test.ts` / `static-cache.test.ts`: the shell embeds the
same list as `GET /api/v1/plugins`, the ETag rotates with the embedded
head, the JSON can't break out of its script element, and the shell is
still gzipped.

Onboarding, checked live on `pnpm start:worktree` with onboarding reset:
before the fix the Devices step loaded 3 of 26 plugin bundles and the
Connect panel was empty. After it, all 26 load and "Sign in to your bb
account" shows. Other plugins start downloading at ~440 ms, so the
signal drives it, not the 3 s fallback. Thread-page ready (~1350 ms at
RTT 150, HTTP/1.1) and pagehide (<1 ms) are unchanged by the fix.

Rebased onto origin/main `cb627c8574a`. Main had split the
render-invariants suite into `idle`/`typing`/`push` files that run in
parallel (#7669), so the onboarding case now lives in `idle.test.ts`,
and `useRenderFixture` exposes its browser for the case's fresh context.
Main already carries plugin SDK 0.6.150, so this PR no longer bumps it;
the README note isn't SDK surface, and `check-plugin-sdk-version.mjs`
reports the surface unchanged. After the rebase, `pnpm exec turbo run
typecheck lint test --filter=@bb/app --filter=@bb/server
--filter=@bb/server-contract --filter=@bb/render-invariants
--filter=@get-bb/plugin-sdk --filter=@bb/provider-parity` and
`test:render-invariants` pass (7/7; the idle group still finishes before
the push group). The bundle budget check passes at 418.2 KB brotli
against the 418.6 KB limit. iOS Simulator Safari wasn't run: the only
simulator was booted by another session, and the persisted (bfcache)
path that WebKit uses most is unchanged.

The pagehide and reveal invariants live in the unit suites. A
"non-persisted pagehide does no layout" case would also fit the
real-browser render-invariants suite.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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