Repository navigation
Retire invalidates on plugin RPC contracts - #6462
Merged
Merged
Conversation
A contract's invalidates fired only for writes through that RPC method, so plugins also had to call bb.rpc.experimental_invalidate where CLI, agent-tool and background writes change the data, and app-made writes refreshed twice. The server now marks tags stale where the data changes, and nothing else. The Git, GitHub PR Status, push-notification and Workflows plugins already invalidated at the data change (core environment events, the PR store's publish, publishSubtree and service.stop), so their declarations are deleted. invalidates leaves the public PluginRpcMethodContract type and docs, keeps working at runtime for built plugins, and bb-plugin-build warns on it in the plugin's own server sources. Plugin SDK 0.6.95. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
marked this pull request as ready for review
October 28, 2026 18:45
ymichael
marked this pull request as draft
October 28, 2026 18:45
ymichael
marked this pull request as ready for review
October 28, 2026 18:45
ymichael
added a commit
that referenced
this pull request
Oct 28, 2026
…nge (#6466) ## 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 #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-#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`. #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 #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 #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 #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](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
invalidateson a plugin RPC contract method only fired when a write went through that RPC method (invokeRpcHandler→hub.notifyPluginChanged, plus the calling client invalidating the response'sinvalidatedtags). Plugin CLI commands, agent tools and background work usually call the plugin's functions directly, so the server already has to callbb.rpc.experimental_invalidatewhere the data changes. An app-made write then refreshed twice: once from the broadcast and once from the client's owninvalidatedhandling. The rule is now that the server marks tags stale where the data changes, and nothing else does.What changed
First-party users. All four already invalidated where the data changes, so their declarations are just deleted. No new invalidate call was needed:
plugins/git/rpc-contract.ts)markViewed,clearViewed,setMergeBase: core emitsdiff-viewed-changed/metadata-changed, andenvironmentChangedinplugins/git/server.tsinvalidates the viewed and status tags for watched environments. The CLI (bb git viewed mark|unmark,bb environment update --merge-base-branch) goes through the same events.plugins/github-pr-status/contract.ts)refresh,markReady,markDraft,merge: each ends in a store load, andcreatePullRequestStore'spublishbroadcasts the row's tag when the row changed. The store covers these cases by itself. The oldinvalidatesrefetch ran before that reload and read the old row back, so it was a wasted request.plugins/push-notifications/contract.ts)threadNotifications.set:preferences.setcallspublishSubtree, shared withbb push-notifications thread --level.plugins/workflows/src/ui-contract.ts)workflowStopRun, added by Move the Workflows plugin onto shared live reads #6418:service.stoppublishesruns:<threadId>, shared withbb workflows stop.Retired the way #6388 retired
experimental_threadHeaderAction:PluginRpcMethodContract(packages/plugin-sdk/src/rpc-contract.ts) extendsOmit<ContractTagDeclarations, "invalidates">, so declaring it indefineRpcContractis a type error.ContractTagDeclarationsin@bb/domainis untouched: coredefineRoutedescriptors keepinvalidates, and the edit stays one line for the parallel move of that type into the SDK.readRpcMethodContract,invokeRpcHandler,rpcResponseTagsand the fake host are unchanged, so already-built plugins broadcast and refresh as before.bb-plugin-buildwarns when a server source file inside the plugin's own directory declaresinvalidates(retiredRpcInvalidatesWarningsinpackages/plugin-build/src/retired-sdk-members.ts). The warning names the replacement. The check is limited to the server build and the plugin's own directory: contracts are always registered on the server, so the warning prints once, and bundled workspace packages such as@bb/server-contract, whose core route descriptors useinvalidates, don't trigger it.bb plugin build/devprint it, and the server writes it to the plugin log.docs/api_to_audit.md: the live-reads bullet states the one rule, and there's a new Retired RPC contractinvalidatesentry with its callers.Marketplace callers. I scanned all 364 git repositories and 14 npm packages behind the community marketplace's 469 entries (2026-10-28). Five plugins in two repos declare it:
src/rpc-tags.ts, spread into its contract), shuttle and vantage (src/contract.ts)lib/rpc-contract.ts) and kitchen-sinkDocs. The SDK doc comments on
defineRpcContractandExperimentalRpcMutationStateare updated. The Plugin Guide's wire card (plugins/plugin-api-docs/src/surfaces.ts) states the rule. The bb-plugin-authoring skill gets a "Tags and invalidation" section infrontend-hooks-and-ui.md;backend-events.mdis at its 500-line cap, so its refusal line only drops "publishes no invalidations". Plugin SDK bumped to 0.6.95.No server/daemon wire change.
How you verified
pnpm exec turbo run typecheck lintfor@get-bb/plugin-sdk,@bb/plugin-build, the Git, GitHub PR Status, push-notifications, Workflows, plugin-api-docs and bb-guide plugins,@bb/serverand@bb/app: pass.turbo run testfor the same plugins,@get-bb/plugin-sdkand@bb/plugin-build: pass.@bb/server: 3692/3698 on the first run. The skills-quality cap failure was mine (fixed by moving the section). The other failures were three builtin-plugins hot-reload timing tests that ran while a dev instance was building; both files pass alone (65/65).New tests:
build-plugin-app.test.ts: a server whose owntags.tsdeclaresinvalidates(property and method forms) builds, keeps the field, and gets exactly one warning. A file outside the plugin root that declares it doesn't warn.retired-sdk-members.test.ts: the pattern flags property, quoted-key and method declarations, and ignorestags,.invalidates(calls andinvalidated.rpc-query-host.test.tsx: the optimistic-mutation test dropsinvalidatesand invalidates after acknowledgement, as the server does. Predictions still hold through acknowledgement, roll back on failure, and keep the read error on refresh failure.plugin-wire.test.ts: the untyped built fixture that still declaresinvalidatesis renamed as the compatibility test. It still broadcasts.Live run on an isolated
pnpm dev(fresh data dir), a scratch repo project, with a thread open in a headless browser. Afetchhook recorded every/rpc/request after each action:setMergeBasestatus(+344 ms)setMergeBasebb plugin rpc call bb--git setMergeBasestatusbb environment update --merge-base-branch mainstatusmarkViewedviewed(+277 ms)markViewedbb git viewed markviewedclearViewedbb git viewed unmarkviewedclearViewedviewedthreadNotifications.setthreadNotifications.keyedthreadNotifications.setbb push-notifications thread --level input-onlythreadNotifications.keyedThe picker's extra
branchesread after a merge-base change is the branch list re-reading with its newselectedBranchinput, not a duplicate.Legacy fixture: a path plugin whose contract still declares
invalidates.bb plugin buildprinted the warning forcontract.tsonce, and the server wrote it to the plugin's log on install. Clicking Bump on its page updated the count from 0 to 1. Its request log showsbumpfollowed by twocountreads, the double refresh this removes for first-party plugins.GitHub PR Status, against this PR (Retire invalidates on plugin RPC contracts #6462) from a clone of its branch:
markReadypullRequests(+5.0 s, afterghand the store reload)markDraftbb pull-request draftpullRequestsrefreshbb plugin rpc call bb--github-pr-status refreshpullRequestsmarkReadybb pull-request readypullRequestsmergewas not run: it would merge this PR. It sharesrunAction→store.refreshwith ready and draft. Thebb--git statusreads that also appear after these actions come from the Git plugin's environment events (ghtouches the checkout), which this PR doesn't change.🤖 Generated with Claude Code