Skip to content

Take core off query tags: UI preferences refresh through a system change - #6466

Merged
ymichael merged 1 commit into
mainfrom
bb/take-core-off-tags-thr_cmtzgs6ymh
Oct 28, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/take-core-off-tags-thr_cmtzgs6ymh

Conversation

@ymichael

@ymichael ymichael commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Core's query-tag use was left over from the live-data stack (#5640). route-tags.ts (routeTaggedRead / routeTaggedPages) still wrapped threads.list, threads.get and sidebarBootstrap, but those routes have declared no tags since #6002. UI preferences were the only real core tag user: the read declared ui-preferences, the two writes declared invalidates, and the server sent a tags websocket message to every client for them. So core kept a second invalidation mechanism, the tags message, CORE_TAG_SCOPE, and tags/invalidates on defineRoute for one preference read. Everything else in core refreshes through changed messages.

What changed

Core now uses only changed messages. Tags are plugin-only.

  • UI preferences use a normal system change. ui-preferences-changed is back in SYSTEM_CHANGE_KINDS. The update and reset routes send it with notifySystem after a successful write, the same point where the route layer used to publish the tags. realtime-cache-registry.ts maps it to the ui-preferences query. A failed write invalidates the query through a new invalidateUiPreferences in system-cache-effects.ts. The sync engine calls sdk.system.uiPreferences.set directly.
  • Reconnect behaves as on main. Main refreshed core-tagged queries on reconnect with applyTags(CORE_TAG_SCOPE, null). That is now ui-preferences-changed, sent through the same defer-while-hidden path as system messages. It applies on reconnect only, not on the first connect. Thread and sidebar queries use the existing reconnect refresh list, as every other core query does.
  • Deleted:
    • route-tags.ts, and the queryClient parameters Store each thread once in a keyed store shared with plugin keyed rows #6002 added only for it. Thread, palette, sidebar and ui-preferences reads are plain queries again; sidebar-navigation-query.ts and palette-thread-queries.ts are back to their pre-Store each thread once in a keyed store shared with plugin keyed rows #6002 text.
    • The tags message: hub.notifyTags, its domain schema, the app handler and its tests.
    • CORE_TAG_SCOPE; the query-tags tests use a local scope instead.
    • tags/invalidates on core defineRoute, with RouteTagDeclarations, RouteTagInput, RouteSuccessOutput, the invalidateTags option, the package README, and hono-typed-routes' @bb/domain dependency.
    • UI_PREFERENCES_TAG and client-route-descriptors.ts. That file existed only so the app could import the three ui-preferences routes cheaply; they are back inline in public-api.ts.
  • ContractTagDeclarations moved from @bb/domain into the plugin SDK (internal/rpc-tags.ts). Its callers are the SDK, its fake host, and the server's plugin API, which already imports @get-bb/plugin-sdk/internal/rpc-tags. Retire invalidates on plugin RPC contracts #6462's retirement is unchanged: the public PluginRpcMethodContract still extends Omit<ContractTagDeclarations, "invalidates">, and the runtime still reads invalidates for already-built plugins. A new @ts-expect-error case in rpc-contract.test.ts keeps invalidates out of the public type.
  • runTaggedMutation deleted from @bb/query-tags, along with TaggedMutationOptions and its README mention. It had no callers outside the package's own tests. useTaggedMutation is now the only mutation entry point, used by core thread writes and plugin RPC mutations. The tests that used the wrapper now drive the hook through a mutateOnce test helper (renderHook + mutate); the helper creates each pending outcome up front, because TanStack starts mutationFn a few microtasks after mutate. The core/plugin case pair in mutation.test.ts only differed by the wrapper, so it is now one test.
  • Plugin tags are unchanged: the plugin message, experimental_invalidate, and contract tags.
  • docs/api_to_audit.md no longer says core uses tags for UI preferences or runRouteMutation, and Retire invalidates on plugin RPC contracts #6462's retired-invalidates entry no longer says core routes keep invalidates.

Plugin SDK: one added change kind, patch bump to 0.6.96

The SDK's published types copy domain's changed-message schema. Plugins see it through sdk.subscribe: the event passed to system:changed callbacks is typed from SYSTEM_CHANGE_KINDS. This PR therefore:

  • Adds "ui-preferences-changed" to system:changed events. At runtime, plugins subscribed to system:changed get one extra event per preference write. system:config-changed is unaffected, since it only fires for config-changed.
  • Removes the tags entry from the copied schema. No exported type can reach it, but the published bundled-types bytes change.

scripts/bump-plugin-sdk.mjs --patch bumps the SDK from 0.6.95 (#6462) to 0.6.96. Apart from these two changes, moving ContractTagDeclarations leaves every public entry the same: only declaration order changed. The internal rpc-tags entry now exports the type.

Marketplace plugins that subscribe to system:changed. I scanned the 469 entries in https://getbb.app/marketplace/v2/marketplace.json: all 364 git sources (shallow clones of the default branches) and all 14 npm tarballs. Two entries subscribe, and both filter on other kinds, so the new kind is a no-op for them:

Entry Source Reacts to
matt-pocock-skills-for-bb erikmackinnon/bb-plugin-matt-pocock-skills-for-bb server/backend.ts plugins-changed
plugin-workshop mosmanlaw/plugin-workshop server/wiring.ts plugins-changed, plugin-install-jobs-changed, plugin-update-jobs-changed

Two non-marketplace plugins in the same repos (brsbl/bb-plugins open-in-moss, rebryk/bb-plugins auto-update) also filter on plugins-changed/plugin-update-jobs-changed. The other matches were copies of bb-plugin-sdk.d.ts and system:config-changed listeners.

No server/daemon wire change, so HOST_DAEMON_PROTOCOL_VERSION is unchanged. Clients parse change kinds leniently, so an older app on a newer server drops the unknown kind. Neither version breaks, but preferences only sync across clients when both sides have this change.

How you verified

  • pnpm exec turbo run typecheck lint test --filter='...[origin/main]' --continue, rebased on 852d1e8 (before Retire invalidates on plugin RPC contracts #6462): 254/259 tasks pass, and typecheck and lint pass everywhere. The five failing test tasks are all timing or file-watch tests. The machine's load average was about 40–50 during the run (other worktrees):

    • Pass alone on this branch: @bb/app FilePreview.test.tsx (Pierre worker pool) and bb-plugin-bb--mcp cli-runner.test.ts.
    • Fail the same way on a clean origin/main checkout: @bb/host-watcher workspace-root-ignores.test.ts (no watch events delivered) and @bb/desktop preload-build.test.ts (Electron smoke page timeout).
    • @bb/server builtin-plugins.test.ts: see the last bullet.
    • CI is the gate for these.
  • After rebasing on f67c1e6 (with Retire invalidates on plugin RPC contracts #6462): @bb/query-tags typecheck, lint and test pass (4/4 tasks), and @get-bb/plugin-sdk typecheck passes. Not rerun after this rebase: the app, server and full suites, and the browser QA below (it ran on 9c1346d). CI gates this rebase.

  • New and updated tests:

    • realtime-cache-effects.test.ts: a ui-preferences-changed system message refreshes the ui-preferences query, visible or hidden. A reconnect refreshes it; the first connect does not.
    • public-ui-preferences.test.ts: update and reset each send ui-preferences-changed; a 409 sends nothing.
  • Two clients, in the running app. Using start:worktree builds of this branch and of origin/main (9c1346d) on fresh data dirs, with two separate headless browser profiles per build, I removed "Report a bug" from the footer in client A. Client B's footer dropped it about 150 ms later without a reload, on both builds, and it stayed gone after reloading B.

  • Requests per action, branch vs main. Same script on both builds, /api requests in a 5 s window after each action, five rounds each:

    Action main (rounds 1–5) branch (rounds 1–5)
    Pin 9, 6, 6, 4, 6 6, 6, 6, 6, 6
    Unpin 4, 4, 4, 4, 4 4, 4, 4, 4, 4
    Rename 5, 4, 4, 4, 4 5, 4, 4, 4, 4
    Send + stop 16, 18, 18, 13, 18 15, 18, 19, 18, 18

    Every non-timeline endpoint had the same count on both builds in the settled rounds, for example pin = POST + 2 sidebar GETs + 1 thread GET + hosts + config. The differences are first-visit noise (main round 1 includes the mark-read POST and the extra sidebar fetch it triggers) and timeline GETs during streaming, which vary on both builds (main 4–5, branch 3–6).

  • UI preference write. The writing client sends PUT + 1 GET on this branch, versus PUT + 2 GETs on main. Main re-read once after its local tag invalidation and again for the broadcast tags message; the writer now re-reads only on the broadcast. The other client sends 1 GET on both builds.

  • test/services/plugins/builtin-plugins.test.ts ("hot-reloads a source-layout builtin server…") is flaky locally on main too: it failed in 2 of 6 runs on origin/main. In the failing runs the file is written 1 ms after the watcher starts, and macOS FSEvents never reports the change.

AGENT GENERATED

🤖 Generated with Claude Code

Core now refreshes only through changed messages; tags are plugin-only.
UI preferences use the ui-preferences-changed system change, published by
the update and reset routes and handled in the realtime cache registry. The
route-tags wrapper, the tags websocket message, CORE_TAG_SCOPE, and
tags/invalidates on defineRoute are deleted. ContractTagDeclarations moves
into the plugin SDK; invalidates stays out of the public RPC contract type.
runTaggedMutation is deleted and its tests drive useTaggedMutation. The
added change kind appears in the SDK's system:changed event type, so the
plugin SDK is bumped to 0.6.96.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/take-core-off-tags-thr_cmtzgs6ymh branch from 14b9d16 to fe14e70 Compare October 28, 2026 19:20
@ymichael
ymichael merged commit a2829ad into main Oct 28, 2026
52 checks passed
@ymichael
ymichael deleted the bb/take-core-off-tags-thr_cmtzgs6ymh branch October 28, 2026 19:35
mistakeknot added a commit to mistakeknot/aleph that referenced this pull request Nov 3, 2026
Sync upstream bb through get-bb#6466 (remove query tags)
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