Skip to content

Start lazy plugin parts and their runtime slots as early as the screen needs them - #8203

Merged
ymichael merged 6 commits into
mainfrom
bb/lazy-parts-follow-ups
Nov 26, 2026
Merged

ymichael merged 6 commits into
mainfrom
bb/lazy-parts-follow-ups

Conversation

@ymichael

@ymichael ymichael commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

#8152 was squash-merged from its first commit only. The three follow-up commits on the branch were never pushed, so two load-order fixes for lazy plugin parts did not land:

  • A lazy chunk's shim waits for its host-loaded runtime slots, such as the 556 KB diff viewer, before the chunk evaluates. That wait only starts once the chunk has downloaded. So reloading a thread with Git's Diff tab open fetched the chunk and then the diff viewer, one after the other.
  • A lazy part only started loading when its host rendered it or at idle warming. The restored Diff tab requested its chunk about a second after Git's code had run. A plugin's own page also waited for every lazy part of that plugin, including parts the page does not show.

What changed

  • Chunk downloads start their slots too. bb plugin build (packages/plugin-build/src/build-plugin-app.ts) rewrites each dynamic import of a chunk to call loadRuntimeSlot for the host-loaded slots in that chunk's static import closure that the entry does not already load. The chunk and its slots download together, and the shim's own call joins the pending load. HOST_LOADED_RUNTIME_SLOTS in runtime-shims.mjs lists those slots.

  • The restored screen's lazy parts start early. apps/app/src/lib/restored-lazy-parts.ts lists, before plugin frontends load, the parts the restored screen shows:

    • a plugin's settings sections on its settings page
    • its nav panel on its own page
    • on a thread route, the open right-panel tab from the thread's saved panel state: a plugin tab, a plugin panel action, or every plugin's Info rows and sections

    A plugin that a listed part names prefetches its lazy chunks with its entry. Its listed parts start loading as soon as its registrations are collected. Only a plugin's own page or settings page holds its publish, and only for the parts that page shows, with the same 3-second limit. This replaces the old page-owner rule.

  • Boot stays small. Boot works out the settings-page and plugin-page parts synchronously with restoredPageLazyParts, which only matches the route. readStoredPanelTabs moves into fixed-panel-tabs-state.ts, so client-core's panel-state parser stays out of boot. Thread-panel parts start when the plugin loader runs. Boot is 417.1 KB brotli, against 416.5 KB on main.

  • Doc comment fix. PluginSdkApp's doc comment moves back onto PluginSdkApp. It had attached itself to ExperimentalLazyComponent.

  • SDK version bump to 0.6.204. app-contract.ts changes here, and Load plugin surfaces and core contributions from chunks with one lazy helper #8152 and Stop a single background command from the thread banner, CLI and SDK #8158 both shipped 0.6.203.

  • Docs. docs/ui-code-splitting.md and the experimental_lazy entry in docs/api_to_audit.md describe the new behaviour.

No wire, daemon-protocol or CLI changes.

How you verified

Performance, measured on pnpm start:worktree with the same data dir for both builds. Base is 65477919199 (#8152); after is this PR. Each run used headless Chromium at 1440×900 with an empty cache and a localStorage snapshot from a returning user (Git remembered as the panel-tab provider). Slow 4G is CDP at 562.5 ms RTT and 1.44 Mbps. Values are medians of 5 runs, and run-to-run spread was under 0.15 s on Slow 4G.

Scenario Base After
Reload a thread with the Diff tab open, Slow 4G: diff visible 27.41 s 27.14 s
Same: Diff tab chunk starts / diff viewer starts 14.05 s / 19.00 s 10.13 s / 10.81 s
Same, unthrottled: diff visible 539 ms 503 ms
Cold thread load, composer visible: Slow 4G / unthrottled 11.15 s / 283 ms 11.16 s / 253 ms
Reload onto bb connect settings, Slow 4G 13.14 s 13.11 s
Reload onto the automations page, Slow 4G 11.74 s 11.74 s

The Diff tab's code now arrives about 8 s earlier on Slow 4G, but the diff shows only 0.27 s sooner. What holds it back is Git's RPC chain: status runs twice in a row, each 432-byte response takes 4.5–7 s on the shared link, and then files and fileSide follow.

An earlier version of this PR loaded the restored-part check with a dynamic import. That put it inside the 157 KB plugin-frontend chunk, which delayed bb connect's settings by 0.9 s on Slow 4G (14.03 s). The current version measures at 13.11 s.

  • pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/plugin-build --filter=@get-bb/plugin-sdk --filter=@bb/server passes.
  • pnpm exec turbo run test --filter=@bb/plugin-build --filter=@get-bb/plugin-sdk passes. That includes the new build-plugin-app.test.ts cases for the slot preloads that dynamic imports start.
  • pnpm exec turbo run test --filter=@bb/app passes: 711 files, 7,526 tests. That includes the new restored-lazy-parts.test.ts and the updated plugin-frontend-load-order.test.ts.
  • node .github/workflows/check-plugin-sdk-version.mjs passes.
  • node apps/app/scripts/check-bundle-budget.mjs passes after a local turbo run build --filter=@bb/app.

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 6 commits November 25, 2026 15:55
ExperimentalLazyComponent was declared between PluginSdkApp's doc comment
and the interface, so the comment attached to the new type and
PluginSdkApp lost its description. Declare the type above the comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A chunk's runtime shim awaits host-loaded slots such as the diff viewer
before the chunk evaluates, so the slot download only started after the
chunk had downloaded. Reloading a thread with Git's Diff tab open fetched
the Diff tab chunk, then the 556 KB diff viewer, one after the other.

The plugin build now rewrites each dynamic import of a chunk to call
loadRuntimeSlot for the host-loaded slots in that chunk's static import
closure that the entry does not already load. The chunk and its slots
download together, and the shim's own call joins the pending load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n registers

A lazy part only started loading when its host rendered it or at idle
warming. Reloading a thread with Git's Diff tab open requested the Diff
tab chunk about a second after Git's code had run, and a plugin's own
page waited for every lazy part of that plugin, including ones the page
does not show.

restoredLazyParts lists what the restored screen shows before plugin
frontends load: a plugin's settings sections on its settings page, its
nav panel on its own page, and on a thread route the open right-panel
tab from the thread's saved panel state (a plugin tab, a plugin panel
action, or every plugin's Info rows and sections). A plugin a listed
part names prefetches its lazy chunks with its entry, and its listed
parts start loading as soon as its registrations are collected. Only a
plugin's own page or settings page holds its publish, and only for the
parts that page shows. This replaces the page-owner rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The lazy-part follow-ups change app-contract.ts, so the SDK surface
guard needs a version past 0.6.203, which #8152 and #8158 both shipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
usePluginFrontendBoot imported restored-lazy-parts statically, which
pulled client-core's full parseFixedPanelTabsState into boot and put it
0.3 KB brotli over budget (416.5 to 419.4 KB). Load that module with a
dynamic import started next to the plugin list fetch; only the lazy chunk
prefetch waits for it. Boot is back at 416.6 KB brotli.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Loading restored-lazy-parts with a dynamic import put it in the 157 KB
plugin-frontend chunk, so the boot prefetch waited for that chunk. On
Slow 4G bb connect's settings sections started at 7.0 s instead of 4.3 s
and the page showed them 0.9 s later than on main (14.03 s vs 13.14 s).

Boot now computes the settings-page and plugin-page parts synchronously
with restoredPageLazyParts, which only matches the route. Reading a
thread's saved panel state moves to fixed-panel-tabs-state.ts as
readStoredPanelTabs, so the panel-state parser stays out of boot; thread
panel parts still start when the plugin loader runs. Boot is 417.1 KB
brotli (main 416.5 KB).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 8f2b710 into main Nov 26, 2026
53 checks passed
@ymichael
ymichael deleted the bb/lazy-parts-follow-ups branch November 26, 2026 00:57
ymichael added a commit that referenced this pull request Nov 26, 2026
#8152 replaced hand-written import() splits in core contributions with
experimental_lazy, and #8203 starts the restored screen's lazy parts,
including every plugin's Info rows and sections when Info is the restored
panel tab. Register bb's Info rows and sections as experimental_lazy parts
(components in core-contributions/components/ThreadInfoEntries.tsx) so the
host's ordered reveal holds them like plugin entries, and start them from
bootPluginFrontends with the same restoredLazyParts list.

ThreadInfoSlots shows the pending marker while the reveal holds an entry,
since a lazy part no longer suspends into the host. core-contribution-parts
imports plugin-slots first: the core binding's ThreadInfo reaches
plugin-slots, which collects the core contributions at module load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 26, 2026
## Human comments

## What was wrong

bb's Info tab was registered through the public tab slot, but its body
was not public. `ThreadSecondaryPanel` filled a private React context
(`ThreadInfoContentContext`) with `<ThreadMetadataContent>`. That
component took 18 props built in `ThreadDetailView` and merged a
core-only array of seven rows and three sections with plugin
registrations. No plugin could build or replace that body. Core rows
read private host state that plugin rows can't reach (audit V8,
core-contributions rank 8).

Emptiness was also decided from core fields alone.
`hasAnyThreadMetadata` (`ThreadDetailSecondaryContent.tsx`) showed "No
thread details available." whenever core saw no environment, parent,
provisioning failure, archive or forks. That hid every plugin row and
section, and core's own Parent and Project rows (a-thread F12). Repro on
main: a pending thread with no environment and an automation targeting
it shows only "No thread details available."; the Automations section is
hidden.

Main's provisioning-failure row was also wrong. It scanned the cached
timeline for a `systemKind: "error"` row titled "Provisioning thread
failed". `normalize-provisioning-failures` replaces that row with an
`operation` row, so a real failure (a worktree whose repository is gone)
showed "No thread details available." instead of "Environment: Not
created · provisioning failed". Nothing durable recorded the failure:
the thread only moved to `error`, which a lost start, a refused start
command or `provider.failed` before start also do.

## What changed

**The Info tab is the public host**
- `experimental_ThreadInfo` (component, `ExperimentalThreadTabProps`) is
the Info body. Implementation:
`apps/app/src/components/secondary-panel/info/ThreadInfo.tsx`.
- It renders every `threadInfoRow` and `threadInfoSection`, bb's own
included, through the same mount path.
  - It shows a skeleton while the thread loads.
- It shows "No thread details available." only when no `dt` and no
`[data-info-section]` rendered.
- `apps/app/src/core-contributions/thread-info.tsx` (plus
`thread-info/*.tsx`) registers:
  - the `info` fixed tab;
- the seven rows: Parent, Notify parent, Project, Environment and
Machine, provisioning failure, Directory, Archived;
  - the three sections: Child threads, Forks, Thread storage.
- They import only `@get-bb/plugin-sdk` and registry components;
`bb/core-contribution-imports` is green.
- The registration module stays light. The components live in
`core-contributions/components/ThreadInfoEntries.tsx` (inside #8152's
`src/core-contributions/components/*` split boundary), and each row and
section is an `experimental_lazy` part, the helper #8152 added for core
contributions. The host's ordered reveal (`useOrderedReveal`) holds them
like plugin entries. `ThreadInfoSlots` renders a pending marker while
the reveal holds an entry, and the host shows its skeleton rather than
the empty text.
- When Info is the restored panel tab, bb's rows and sections start
through #8203's restored-parts path: `bootPluginFrontends` passes the
same `restoredLazyParts` list to `startRestoredCoreContributionParts`
(`apps/app/src/lib/core-contribution-parts.ts`). Calling
`readStoredPanelTabs` from boot instead would add 12.5 KB raw / 2.3 KB
brotli, which #8203 kept out.
- `vite-core-plugin-sdk-app.ts` resolves the one core binding with
`moduleSideEffects: false` (the same option as #8088), so each importer
pulls in only the members it uses.
- Boot payload: 1661.3 KB raw / 417.3 KB brotli against main's 1657.4 KB
raw / 417.1 KB brotli, inside the 1682.1 KB / 419.1 KB budget, with no
split-boundary violations.
  - `plugin-slots.ts` puts them first in the slot lists plugins join.
- Removed:
  - `ThreadInfoContentContext` and `thread-info-registration.tsx`;
  - `ThreadMetadataContent` and its 18-prop `metadata` plumbing;
  - `metadataContent` on the secondary panel;
  - `hasAnyThreadMetadata`;
  - the private parent-thread subset query;
- `useThreadTimelineProvisioningFailure` and
`thread-provisioning-failure.ts`.
- Section collapse state is stored under `<pluginId>/<id>` for every
section; bb's own are `bb--core/<id>`. The `infoPanel.collapsedSections`
schema maps the legacy bare ids `childThreads`, `forks` and
`threadStorage`, so existing collapsed state carries over.

**New and changed public API (plugin SDK 0.6.205)**
- `experimental_useEnvironment(environmentId):
ExperimentalEnvironmentState`
- States: `loading`, `ready` with `environment`, `notFound`, `error`,
the same as `experimental_useThread`.
- `ExperimentalEnvironment` = `environments.get`'s `Environment` plus
`label` and `host: { id, name, connected, local, named, machineProvider
} | null`.
- It reads the same realtime-kept environment, hosts and provider
queries the thread view uses.
- `label` comes from core's
`formatEnvironmentDisplay`/`getEnvironmentWorkspaceInfoDisplay`.
  - `named` and `machineProvider` carry core's Machine-row rules.
- `GET /api/v1/hosts/:id?includeRemoved=true` / `useSdk().hosts.get({
hostId, includeRemoved })` returns a removed machine, disconnected, so
the Machine row keeps naming it.
- `experimental_useThreadStorageFiles(threadId, { enabled? }):
ExperimentalThreadStorageFilesState`
- States: `loading`, `ready` with `files`, or `error` with
`errorMessage` (core's error text).
- `enabled: false` pauses the read and keeps the last list, the same
option shape as the RPC query hooks. Core's Thread storage section
pauses it while the Info tab is hidden or the machine is offline.
- `experimental_searchPickerOptions({ options, query, getLabel,
getAliases? })` exposes bb's picker ranking.
- It is named after `searchPickerOptions`, which moved from
`@bb/shared-ui/picker-search` into `@bb/fuzzy-match`.
  - Core and the SDK runtime now share that one function.
- `ExperimentalThread.runtime.failure: "provisioning" | null`.
- Stored in the new nullable `threads.failure_kind` (migration
`0172_thread_failure_kind`, generated by drizzle-kit).
- Written only in `writeThreadLifecycleStateInTransaction`: set when
`provisioning.failed` moves the thread to `error`, cleared on every
other status move.
- Filled by the runtime builders for `threads.get`, sidebar entries and
status-change realtime.
  - Server to client only; no daemon protocol change.
- Type-only widening, already supported at runtime:
`ExperimentalThreadTitleTextProps.tooltip`.

**Registry components (no SDK member)**
- Moved from `apps/app` into `@bb/shared-ui` and published by
`plugin-registry`:
  - `option-picker` (13 app callers repointed);
  - `thread-unarchive-button`;
  - `truncate-path-middle`;
  - `thread-storage-tree`;
  - `use-thread-storage-browser`;
  - `right-panel-file-visuals`.
- Newly published: `info-list-row`, `copy-button`,
`list-loading-placeholder`, `picker-layout`, `use-reset-picker-scroll`,
and a new `info-list-more-row`.

**Docs**
- `docs/api_to_audit.md`:
- new entries for `experimental_useEnvironment`,
`experimental_useThreadStorageFiles` and
`experimental_searchPickerOptions`;
- updated entries for Info rows/`experimental_ThreadInfo`,
`experimental_useThread` (`runtime.failure`), panel tabs, unified tabs
and thread-title text.
- Plugin Guide `surfaces.ts` and the anatomy manifest.
- bb-plugin-authoring `frontend-registration.md` and
`frontend-components.md`.
- `docs/configuration.md` row for `infoPanel.collapsedSections`.

**Core callers on the shared path**
- Every core Info row and section and the Info tab itself
(`thread-info.tsx`) run on the public slots and hooks.
- `ThreadInfoRows`/`ThreadInfoSections` mount core and plugin entries
identically.
- The lazy panel placeholder renders the same `ThreadInfo`.
- `BranchPicker`, `ProjectSelector`, `ModelReasoningPicker` and machine
search call the same `searchPickerOptions`.

**Visible changes, all intended**
- A thread with no environment, parent, failure, archive or forks now
shows its Parent and Project rows and any plugin rows or sections,
instead of "No thread details available." (F12).
- A real provisioning failure now shows "Environment: Not created ·
provisioning failed".
- Thread storage no longer marks the file open in a split panel pane, or
opens folders and expands "N more" to reveal it. That highlight only
showed with Info and the file side by side, and reading it publicly
needed a required `target` on every file tab. Removed with `InfoList`'s
`revealIndex`, which existed only for it.
- Everything else matched main on live data (see below).

## How you verified

**Live, one dev server, main's app bundle via a proxy against the
branch's bundle on identical data:**
- Info card element screenshots are pixel-identical for:
- a child thread (Parent link, Notify parent "When stuck", Project,
Environment, Directory, Git rows);
  - an archived thread (Archived row with Unarchive);
  - a fork.
- On the root worktree thread (Child threads, Forks, Thread storage) the
only difference is the relative time "3m" against "4m", from capture
timing.
- Parent picker options are identical ("None", "Fork of QA"; the child
and the archived thread excluded).
- Opening a storage file opens the same tab on both builds.
- F12: the pending thread with an automation shows "No thread details
available." on main. On the branch it shows Parent, Project and the
Automations section.
- Provisioning failure: a worktree thread whose repository was deleted
before dispatch. Main shows "No thread details available."; the branch
shows "Environment: Not created · provisioning failed". The DB row has
`failure_kind = 'provisioning'`.
- Two machines (a second daemon enrolled on the dev server): the Machine
row is pixel-identical on main and branch for a thread on each machine.
- Removed machine (host set to `destroyed` in the dev DB, then
restored): both builds show "Unavailable — machine removed" with Machine
"Studio (second)". The branch gets the name from `hosts.get({
includeRemoved: true })`.
- Removing machine (host `phase = 'removing'`): both builds show
"Machine removal in progress" with the machine named. Pixel-identical.
- Split panes (Root and Child threads side by side): the Info panel
follows the focused pane on both builds. Pixel-identical for the child;
the root differs only in the Forks collapse state.

**Tests (each fails on main for the behaviour it covers):**
- `ThreadInfo.test.tsx`, 7 tests:
  - plugin section plus core rows on a thread without metadata;
- Environment label, Machine row and new-thread action with two
machines;
  - removed machine named through the removed-host read;
  - provisioning failure shown only for `runtime.failure`;
  - archived thread read by id;
  - child threads and forks;
- parent options (children first; self, descendants, side chats and
other projects excluded).
- `lifecycle-failure-kind.test.ts`: `provisioning.failed` sets the
failure. A lost start, a refused start command, `provider.failed` before
start and a deleted environment row leave it null. A retry clears it.
The check covers the column, `threads.get` and the list entry.
- `public-host-get-removed.test.ts`: `includeRemoved` returns a removed
host; a plain GET still 404s.
- `public-ui-preferences.test.ts`: legacy section ids map to
`bb--core/*`.
- `ThreadInfoSlots.test.tsx`: updated so the "core" entries are a plugin
registered first, and it settles bb's lazy Info entries before
asserting.
- `core-contribution-parts.test.ts`: bb's Info rows and sections start
loading when Info is the restored tab and not for another restored tab.

**Commands:**
- `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`:
168/168.
- `pnpm exec turbo run test` for @bb/app, @bb/server, @bb/db,
@bb/domain, @get-bb/plugin-sdk, @bb/shared-ui, @bb/fuzzy-match,
@bb/plugin-registry, @bb/sdk, @bb/server-contract, @bb/test-helpers,
demo-server, bb-guide, the Git plugin and plugin-api-docs: all green.
- `node apps/app/scripts/check-bundle-budget.mjs` after `turbo run build
--filter=@bb/app`: OK (numbers above). `drizzle-kit generate`: no schema
changes after 0172.
- After rebasing onto #8152/#8203, live on `pnpm start:worktree`: the
Info tab on the root thread shows the same rows, Git rows and sections.
A reload with Info restored requests the Info chunk 122 ms in, right
after the plugin loader chunk. The provisioning-failure and
pending-automation threads show what they did before.

## Plugin author impact

One type-only break. Runtime values are unaffected: the host always
sends the field. Plugin code typed against these shapes needs it when it
builds them, which in practice means test fixtures.
- **`runtime.failure` is required** on `ExperimentalThread`
(`ThreadWithRuntime`) and thread list entries. Add `failure: null` to
literal `runtime` objects. In the community corpus (504 folders), 31
folders build `runtime: { displayStatus }` literals, all in tests or
test helpers. Only the ones typed as these thread shapes break.
Examples: tobi/bb-bots-sidebar `tests/workflow-runs.test.ts`,
openwizdev/WizPlugins wizbar tests, VKirill/bb-plugin-project-folders
`auto-archive.test.ts`.

I did not edit these plugins.

**Community callers that can migrate (not edited):**
- environment reads in the app: 14 folders call
`useSdk().environments.*` and about 10 call `hosts.*` as one-shot
fetches, e.g. SergeyGavrilov/bb-diff-tree, wy3z/bb-cursor-suite
agent-pills;
  - storage files: 9 folders call `threads.storageFiles`.
- The KosachMax/bb-plugin-notion-theme CSS on `dl [data-info-section]`
still matches.

🤖 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