Skip to content

Retire invalidates on plugin RPC contracts - #6462

Merged
ymichael merged 1 commit into
mainfrom
bb/retire-contract-invalidates-thr_nd4q7xvs8p
Oct 28, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/retire-contract-invalidates-thr_nd4q7xvs8p

Conversation

@ymichael

@ymichael ymichael commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

invalidates on 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's invalidated tags). Plugin CLI commands, agent tools and background work usually call the plugin's functions directly, so the server already has to call bb.rpc.experimental_invalidate where the data changes. An app-made write then refreshed twice: once from the broadcast and once from the client's own invalidated handling. 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:

  • Git (plugins/git/rpc-contract.ts) markViewed, clearViewed, setMergeBase: core emits diff-viewed-changed / metadata-changed, and environmentChanged in plugins/git/server.ts invalidates 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.
  • GitHub PR Status (plugins/github-pr-status/contract.ts) refresh, markReady, markDraft, merge: each ends in a store load, and createPullRequestStore's publish broadcasts the row's tag when the row changed. The store covers these cases by itself. The old invalidates refetch ran before that reload and read the old row back, so it was a wasted request.
  • Push notifications (plugins/push-notifications/contract.ts) threadNotifications.set: preferences.set calls publishSubtree, shared with bb push-notifications thread --level.
  • Workflows (plugins/workflows/src/ui-contract.ts) workflowStopRun, added by Move the Workflows plugin onto shared live reads #6418: service.stop publishes runs:<threadId>, shared with bb workflows stop.

Retired the way #6388 retired experimental_threadHeaderAction:

  • PluginRpcMethodContract (packages/plugin-sdk/src/rpc-contract.ts) extends Omit<ContractTagDeclarations, "invalidates">, so declaring it in defineRpcContract is a type error. ContractTagDeclarations in @bb/domain is untouched: core defineRoute descriptors keep invalidates, and the edit stays one line for the parallel move of that type into the SDK.
  • It still works at runtime. readRpcMethodContract, invokeRpcHandler, rpcResponseTags and the fake host are unchanged, so already-built plugins broadcast and refresh as before.
  • bb-plugin-build warns when a server source file inside the plugin's own directory declares invalidates (retiredRpcInvalidatesWarnings in packages/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 use invalidates, don't trigger it. bb plugin build/dev print 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 contract invalidates entry 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:

  • kalindudc/bb-marketplace: loom (src/rpc-tags.ts, spread into its contract), shuttle and vantage (src/contract.ts)
  • smsunarto/bb-plugins: gtd-sidebar (lib/rpc-contract.ts) and kitchen-sink

Docs. The SDK doc comments on defineRpcContract and ExperimentalRpcMutationState are 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 in frontend-hooks-and-ui.md; backend-events.md is 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 lint for @get-bb/plugin-sdk, @bb/plugin-build, the Git, GitHub PR Status, push-notifications, Workflows, plugin-api-docs and bb-guide plugins, @bb/server and @bb/app: pass.

  • turbo run test for the same plugins, @get-bb/plugin-sdk and @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 own tags.ts declares invalidates (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 ignores tags, .invalidates( calls and invalidated.
    • rpc-query-host.test.tsx: the optimistic-mutation test drops invalidates and 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 declares invalidates is 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. A fetch hook recorded every /rpc/ request after each action:

    Write From Refetches seen in the open tab Tab updated without reload
    setMergeBase merge-base picker 1 status (+344 ms) Branch → other
    setMergeBase bb plugin rpc call bb--git setMergeBase 1 status Branch → other
    merge base bb environment update --merge-base-branch main 1 status Branch → main
    markViewed Viewed checkbox 1 viewed (+277 ms) a.txt checked
    markViewed bb git viewed mark 1 viewed b.txt checked
    clearViewed bb git viewed unmark 1 viewed a.txt unchecked
    clearViewed Viewed checkbox 1 viewed b.txt unchecked
    threadNotifications.set thread menu → Notifications → Muted 1 threadNotifications.keyed Muted
    threadNotifications.set bb push-notifications thread --level input-only 1 threadNotifications.keyed Needs input only

    The picker's extra branches read after a merge-base change is the branch list re-reading with its new selectedBranch input, not a duplicate.

  • Legacy fixture: a path plugin whose contract still declares invalidates. bb plugin build printed the warning for contract.ts once, 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 shows bump followed by two count reads, 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:

    Write From Refetches seen in the open tab Tab updated without reload
    markReady composer segment, Mark ready 1 pullRequests (+5.0 s, after gh and the store reload) Draft → Open, Merge shown
    markDraft bb pull-request draft 1 pullRequests Open → Draft, Mark ready shown
    refresh bb plugin rpc call bb--github-pr-status refresh 1 pullRequests yes
    markReady bb pull-request ready 1 pullRequests Draft → Open

    merge was not run: it would merge this PR. It shares runAction → store.refresh with ready and draft. The bb--git status reads that also appear after these actions come from the Git plugin's environment events (gh touches the checkout), which this PR doesn't change.

AGENT GENERATED

🤖 Generated with Claude Code

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
ymichael marked this pull request as ready for review October 28, 2026 18:45
@ymichael
ymichael marked this pull request as draft October 28, 2026 18:45
@ymichael
ymichael marked this pull request as ready for review October 28, 2026 18:45
@ymichael
ymichael merged commit 342ac22 into main Oct 28, 2026
95 of 96 checks passed
@ymichael
ymichael deleted the bb/retire-contract-invalidates-thr_nd4q7xvs8p branch October 28, 2026 18:59
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]>
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