Skip to content

Add per-thread notification levels as the first plugin thread action - #5246

Merged
ymichael merged 10 commits into
mainfrom
bb/thread-action-registry-step-2-notification-level-thr_zcdeqftdp5
Oct 9, 2026
Merged

ymichael merged 10 commits into
mainfrom
bb/thread-action-registry-step-2-notification-level-thr_zcdeqftdp5

Conversation

@ymichael

@ymichael ymichael commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Push notifications had only server-wide channel toggles. Users could not mute one thread, quiet the workers under a coordinator, or keep approvals while skipping finished-turn pushes (#1446, Discord 2026-09-29). This is step 2 of the thread action registry plan, following #5243 (merged): the first plugin registration in experimental_threadAction. A per-thread setting also exposed a gap in step 1's API. A registration had no way to know which threads are on screen, and core had no way to read one plugin's metadata for many threads in one request. Without those, a plugin either loads every thread or fetches per row.

What changed

Ten commits; the first four change core or the thread list and can be reviewed on their own, and the last four are review follow-ups (items 7–10).

  1. Batched metadata read (core). POST /threads/plugin-metadata takes { pluginId, threadIds } (1–200 ids). It runs one WHERE plugin_id = ? AND thread_id IN (…) query on the table's primary key, so no new index or migration. Archived and deleted threads are included, and corrupt namespaces are omitted and logged. The core SDK exposes it as threads.experimental_listPluginMetadata({ pluginId, threadIds }). The plugin-bound SDKs (backend bb.sdk, app useSdk(), fake host) default pluginId to the caller and accept another plugin's id, like getPluginMetadata and updatePluginMetadata. The route trusts pluginId, like the existing single-thread metadata routes, because app requests carry no plugin identity. That is listed as an audit item for all three routes.
  2. useData({ threadIds }) (core). The registry reference-counts the thread ids named by experimental_useThreadActions callers: sidebar rows on screen, the open thread's header, and open menus. It publishes them sorted and deduplicated, once the set has been quiet for 32 ms (at most 100 ms after the first change), so rows that mount a frame apart during a scroll step arrive in one change. A surface counts only while visible: AppSidebar wraps the thread list in ThreadActionSurfaceVisibility, visible when the app body is shown and the sidebar (or compact drawer) is open. A hidden sidebar on a settings route therefore contributes no ids, even if a plugin list mounts rows. The ids live in their own store that only the collectors read, so scrolling re-renders one collector per registration, not the rows. bb's own useData hooks take no arguments and are unaffected. The registration docs make this the recommended pattern for per-thread data until an attributes layer lands.
  3. Hidden thread list mounts no rows (thread-list plugin). SidebarWindowedItems treated a zero-height scroll container as "realize every row", and pinned threads render outside the windowing. So a direct load of a settings route mounted every row behind the hidden sidebar. A zero-height container now realizes nothing, and the IntersectionObserver realizes visible rows once a resize gives it height. Environments without IntersectionObserver keep promote-all. The pinned tree waits for useSidebarListShown, which follows the container's height with a ResizeObserver.
  4. Select option labels (core). PluginSettingDescriptor select settings can declare experimental_optionLabels (value → label). The settings form shows the label in the picker and as the current value, while stored values, defaults, settings.get() and bb plugin config set keep the option values. A label for a value that is not an option is refused at define time. The level selects use it: All activity, Needs input only, Muted, Same as default.
  5. Notification levels (push-notifications plugin). A level is all, input-only or muted. Defaults fill gaps and ancestors cap. A thread uses its own level, else childLevel if it has a parent (default input-only, which matches today's rule that child threads never push a finished turn), else defaultLevel (default all). Every ancestor's own level caps the result: muting a coordinator mutes its whole subtree, a worker set to all beats the child default, and a parent set to all never makes an unset worker louder. Thread plugin metadata stores only a thread's own level, { own }, and only when one is set; the limit from ancestors is worked out on every read from the current tree (item 10). The CLI says "limited by parent" when that ancestor is the direct parent and "limited by an ancestor" otherwise. One pure resolver serves the sender, the CLI and the app, so changing a default rewrites nothing. The registration sits in THREAD_ACTION_GROUPS.settings; its useData keeps an id-keyed cache and fetches only uncached threadIds through threadNotifications.list (200-id batches). It applies the threadNotifications realtime channel per id. After a reconnect it refetches the threads on screen and drops cached levels for the rest, so they load fresh when shown again. item resolves the level (shown as described in item 9), and run calls threadNotifications.set. Nothing is fetched per row. CLI: bb push-notifications thread <thread> [--level inherit|all|input-only|muted] [--json], and status shows both defaults.
  6. SDK 0.6.36, with push-notifications' engines.bbPluginSdk floor raised to match.
  7. Consistent plugin id on metadata reads (core). The bound batched read takes an optional pluginId, like the single-thread reads, instead of always forcing the caller's namespace.
  8. Reconnect staleness fix (push-notifications). A reconnect used to keep cached levels for off-screen threads, and the fetch when they came back skipped ids already cached, so a level changed during the disconnect stayed stale until reload.
  9. Current level on the menu entry (core + push-notifications). The submenu repeated its trigger as a heading, and its hint ("Default (All activity)") was the same size as the choices and sat right above "Default", so it read as an extra option. The entry itself never showed the level. Thread actions gain detail, a muted second line under the label; a quick-action button's tooltip shows "Label: detail". Desktop submenus no longer draw choices.heading, because the trigger names them; the phone drawer step and the quick-action popover still use it as their title. choices.hint is now a footnote below the choices, after a separator. Notifications sets detail to the effective level and switches its icon per level: two SVGs declared in the plugin manifest, push-notifications/ringing and push-notifications/off, plus the built-in BellDot for Needs input only. The Default choice names its fallback ("Default (Needs input only)"), and the footnote appears only when a parent or ancestor limits the level ("Limited by a parent thread" / "Limited by an ancestor thread").
  10. Limits resolved from the current tree (core + push-notifications). Each thread used to store a copy of its quietest ancestor's level, updated only when a level was set or a child was created. Nesting a thread under a new parent, or archiving a parent (which releases its unarchived children), left that copy stale. Core gains threads.experimental_listAncestors (POST /threads/ancestors, 1–200 ids): each thread's ancestor ids from the parent up, in one recursive query on the primary key. Push-notifications reads the ancestors and then everyone's own level in one batched metadata call, for the menu, the CLI and the sender. The cap push-down, the thread.created copy and stored inherit rows are gone. Open menus are not refreshed when an ancestor's level changes; only the written thread is published.

No server/daemon wire changes. Docs: docs/api_to_audit.md (new read entry; slot entry updated with threadIds and the Notifications registration), docs/configuration.md, docs/multiple-devices.md, the bb guide customization template, the plugin-authoring references, the plugin overview, and the Plugin Guide surfaces.

Changes from the source commits (b237c68fb8, 2f9fc5d886, 2b482e6462, 8dffcd7402):

  • The per-row metadata fetch and threadNotifications.get are gone.
  • Inheritance follows Michael's rule ("defaults fill gaps, ancestors cap") instead of "a parent's level applies to its tree".

How you verified

  • One server test table over a grandparent → parent → worker tree covers six cases:
    • an unset worker gets the child default;
    • a worker's own all beats an input-only child default;
    • a parent set to all leaves an unset worker at input-only;
    • a muted parent mutes an unset worker;
    • a muted grandparent caps a parent set to all and its worker;
    • a muted grandparent caps a worker set to all.
  • Further server tests cover:
    • storage of only each thread's own level, with limits resolved from the current tree;
    • a worker moved between a muted and a loud coordinator, then detached, follows each move, and a question notifies after the move to the loud one;
    • list by id with archived threads included, and publication of the written thread;
    • POST /threads/ancestors against a real database: ancestor order, one entry per id, unknown ids dropped, 400 for 0 or 201 ids, and both move paths (PATCH /threads/:id nesting and the child release when a parent is archived);
    • CLI output;
    • send-time filtering, including workers no louder than childLevel under a muted default.
  • App tests:
    • one list call for the shown ids; only uncached ids fetched, once each, and nothing for an empty list;
    • 250 ids split into 200 + 50;
    • an unarchived thread shows its stored level without a reload;
    • own writes, realtime updates, and a refetch after reconnect;
    • threads off screen during a reconnect refetched when shown again, picking up a changed or cleared level.
  • Host tests check that:
    • useData gets the union of subscribed ids and drops released ones;
    • rows mounting 20 ms apart produce one change;
    • a hidden surface with 250 rows contributes no ids until shown.
  • The sidebar harness mounts the real thread-list and push-notifications plugins hidden with 250 threads. It asserts no rows, no subscribed ids, and no threadNotifications.list call. Thread-list windowing tests cover zero height realizing nothing, then realizing on resize plus intersection.
  • Route tests: a requested-ids-only response with archived and deleted threads included, corrupt rows logged, and 400 for a bad plugin id, an empty id list, or 201 ids. A bound-SDK test checks that the batched read defaults to the caller's namespace and reads another plugin's with an explicit pluginId.
  • pnpm exec turbo run typecheck lint test --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=./plugins/thread-list --filter=./plugins/plugin-api-docs --filter=@bb/server --filter=./plugins/push-notifications --filter=@bb/db --filter=@bb/sdk --filter=@bb/server-contract passes: app 5580, server 3399, lint 0 errors.
  • turbo run typecheck --filter='...[ea9cd4061f]' (89 packages) and every plugin's tests (46 tasks) pass. The SDK version guard passes.
  • Item 9: the push-notifications app test checks detail, the icon, the Default label and the footnote for a muted thread, a child limited by its parent, a grandchild limited by an ancestor, a child on the child default, and a top-level thread on the global default. Push-notifications tests (41), thread-list row tests (107), and app ThreadActionsMenu tests (42) pass; app/plugin lint has 0 errors; the SDK version guard passes. On a start:worktree instance I took screenshots of the desktop row menu (on Default, child on Default, set to All activity under a muted parent, muted, Needs input only) and the 390 px phone drawer. A level set from the CLI updated the open menu live. @bb/app typecheck fails only in lazySecondaryPanelComponents.tsx, which comes from main (Convert large text pastes into ordinary attachments #5098) and which this branch doesn't touch.
  • Live verification of the earlier head ran in @thread:thr_kaqaxztx6m and passed every journey. Its findings (hidden-sidebar fetch, scroll-step stragglers, grandparent wording) are fixed here.

Request counts on a start:worktree instance with 240 threads (headless Chrome 1400×900, counting threadNotifications.list requests and their id counts):

scenario before (previous head 4fd4886) after
direct load of /settings 2 requests (200 + 40 ids) 0
load of / (34 rows) 2 (32 + 2) 1 (34)
five 400 px sidebar scroll steps 1 request each, plus a 1-id straggler in 3 of 5 1 request each (13–14 ids)

Sidebar benchmark (BB_SIDEBAR_BENCH=1, 3,000 threads, 81 rendered rows, median of 8 alternating runs in the same tree). The baseline column is this branch with the push-notifications registration unmounted. Core collectors and thread-list's Move are mounted in both. The machine was noisy, so individual runs spread widely.

metric without Notifications with Notifications
mountMs 536.5 543.5
statusPatchMs 164 153
membershipRefetchMs 125.5 110.5
pinMs 164 150.5
React Query observers 821 822
observers per rendered row 10.14 10.15
threadNotifications.list calls / ids requested — 4 / 84 (each id once)

The benchmark ran before the resolver and label changes; neither changes what renders or how often. The single extra observer is the plugin's settings query. The first cut cost about 30 ms per status patch: every fetched batch replaced the cache, even when no requested thread had a level, which re-evaluated every row. The cache now changes only when a batch returns a stored level.

🤖 Generated with Claude Code

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/thread-action-registry-step-2-notification-level-thr_zcdeqftdp5 branch 3 times, most recently from 8742f56 to a2830f4 Compare October 9, 2026 07:49
Base automatically changed from bb/thread-action-registry-v1-thr_dessxnxvus to main October 9, 2026 17:42
@ymichael
ymichael force-pushed the bb/thread-action-registry-step-2-notification-level-thr_zcdeqftdp5 branch 2 times, most recently from 0db6776 to df01415 Compare October 9, 2026 18:31
qa and others added 10 commits October 9, 2026 12:32
A plugin that keeps per-thread state in thread plugin metadata could only
read it one thread at a time, so a menu that shows that state for the rows
on screen needed one request per row. Push notifications' per-thread levels
need exactly that read.

`POST /threads/plugin-metadata` with `{ pluginId, threadIds }` (1–200 ids)
returns `{ threadId, metadata }` for each requested thread holding that
plugin's namespace, archived and deleted threads included, in one
`WHERE plugin_id = ? AND thread_id IN (...)` query on the table's primary
key. Corrupt namespaces are omitted and logged without their content.

The core SDK exposes it as `threads.experimental_listPluginMetadata({
pluginId, threadIds })`. The plugin-bound SDKs (backend `bb.sdk`, the app's
`useSdk()`, and the fake host) take no `pluginId` and always read the
caller's own namespace. Documented in docs/api_to_audit.md and the Plugin
Guide's thread plugin metadata surface.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A registration with per-thread state had no way to know which threads a
surface shows, so it could only load state for every thread or fetch per
row. `experimental_useThreadActions` is already the one subscription every
surface makes per thread (sidebar rows, the open thread's header, open
menus), so the registry now reference-counts the ids those calls name.

`useData` receives `{ threadIds }`: the union of subscribed ids, sorted and
deduplicated, published at most once per animation frame with a 100 ms
timeout fallback for hidden tabs. The ids live in their own store that only
the collectors read, so scrolling re-renders one collector per
registration, not the rows. Registrations without per-thread state ignore
the input; bb's own hooks take no arguments.

The registration docs describe the pattern for per-thread data until an
attributes layer lands: an id-keyed cache, one batched fetch for the ids
not cached yet, realtime updates per id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A direct load of a settings route keeps the app sidebar body mounted but
hidden. `SidebarWindowedItems` treated a zero-height scroll container as
"realize every row", and pinned threads render outside the windowing, so
every thread row mounted behind the settings page (225 rows on the QA
instance) and each one subscribed to the thread action registry.

Rows are now realized only when the scroll container has height: a
zero-height container realizes nothing, and the IntersectionObserver
realizes the visible rows once a resize gives it height. Environments
without IntersectionObserver keep promote-all. The pinned tree waits for
`useSidebarListShown`, which follows the scroll container's height with a
ResizeObserver.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`PluginSettingDescriptor` select settings can declare
`experimental_optionLabels`, a record from option value to label. The
settings form shows the label in the picker and as the current value;
stored values, defaults, `settings.get()` and `bb plugin config set` keep
the option values. A label for a value that is not an option is refused at
define time. First consumer: push notifications' level settings.

Re-derived from 2f9fc5d886.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Users asked to mute specific threads, to quiet child threads under a
coordinator, and to hear about pending interactions without a push for
every finished turn (#1446, Discord 2026-09-29). The plugin had only
server-wide channel toggles.

A thread's level is `all`, `input-only` or `muted`. Defaults fill gaps and
ancestors cap: a thread uses its own level, else the `childLevel` setting if
it has a parent (default `input-only`, which matches today's rule that child
threads never push a finished turn), else `defaultLevel` (default `all`).
The result is capped by every ancestor's own level, so muting a coordinator
mutes its whole subtree, a worker set to `all` beats the child default, and
a parent set to `all` never makes an unset worker louder.

Thread plugin metadata stores only the inputs, `{ own, ancestorCap }`
(the quietest own level among all ancestors), and the key is removed when a
thread holds neither. Setting a level pushes the new cap down the subtree,
and `thread.created` copies the parent's cap. One pure resolver serves the sender, the CLI
and the app, so changing a default never rewrites rows. Every write is
published on the `threadNotifications` realtime channel.

The app registers one `experimental_threadAction` in
`THREAD_ACTION_GROUPS.settings`. Its `useData` keeps an id-keyed cache,
fetches only the `threadIds` it has not loaded through
`threadNotifications.list` (batches of up to 200, archived threads
included, so an unarchived thread shows its level without a reload),
applies channel updates per id, and refetches after a realtime reconnect.
`item` resolves the level and hint and `run` calls
`threadNotifications.set`. The sidebar benchmark mounts the registration
and checks that no id is fetched twice.

`bb push-notifications thread <thread> [--level inherit|all|input-only|muted]`
shows or sets a level from the CLI, and `status` shows both defaults.

Re-derived from b237c68fb8, 2f9fc5d886, 2b482e6462 and 8dffcd7402: the
per-row metadata fetch, and `threadNotifications.get` are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… option labels

push-notifications needs `useData({ threadIds })`,
`threads.experimental_listPluginMetadata`, and `experimental_optionLabels`,
so its `engines.bbPluginSdk` floor moves to 0.6.36.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le-thread reads

The plugin-bound experimental_listPluginMetadata always forced the caller's
own namespace, while getPluginMetadata and updatePluginMetadata default
pluginId and accept another plugin's id. All three now share that rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reconnect refetched only the threads on screen and kept every other
cached level. When an off-screen thread came back into view, the fetch
skipped ids already in the cache, so a level changed or cleared during the
disconnect stayed stale until a reload. A reconnect now drops cached levels
for threads not on screen, so they load fresh when shown again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Notifications submenu repeated its trigger as a heading and put a
same-size hint ("Default (All activity)") directly above a "Default"
choice, so the hint read as a fifth option and the entry itself never
said what the level was.

Thread actions gain `detail`, a muted second line under the label (it
follows the label in a quick-action tooltip). Desktop submenus no
longer draw `choices.heading`, since their trigger names them; the drawer
step and quick-action popover still title themselves with it. `hint`
is now a footnote below the choices.

Notifications shows the effective level as its detail with a per-level
icon (declared `push-notifications/ringing` and `push-notifications/off`
manifest icons, built-in BellDot for needs-input-only), labels the
inherit choice with the level it falls back to ("Default (Needs input
only)"), and keeps a footnote only when a parent or ancestor limits it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each thread stored a copy of its quietest ancestor's level, kept in sync
only when a level was set or a child was created. Nesting a thread under a
new parent, or archiving a parent (which releases its unarchived children),
left that copy stale, so a moved worker kept its old coordinator's mute.

Core gains threads.experimental_listAncestors (POST /threads/ancestors):
each requested thread's ancestor ids from the parent up, in one recursive
query on the primary key. Push-notifications now stores only a thread's own
level and resolves the limit from the current ancestors and their levels on
every read, for the menu, the CLI and the sender. The cap push-down, the
thread.created copy and the stored "inherit" rows are gone.

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