Repository navigation
Move the Workflows plugin onto shared live reads - #6418
Merged
ymichael merged 1 commit intoOct 28, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/workflows-plugin-onto-shared-live-reads-thr_p6zy4gjart
branch
October 28, 2026 18:32
ymichael
added a commit
that referenced
this pull request
Oct 28, 2026
## 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 #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 (#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](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
The Workflows UI kept itself fresh by hand.
src/app.tsxsubscribed to aworkflow-runsrealtime channel, ran a 15-second fallback poll while a run was active, backed failed reads off from 2 s up to 60 s, coalesced signal bursts, guarded against stale responses with request sequence numbers, and refetched when the tab or realtime connection came back. All of that duplicates what core's live-read lifecycle already does forplugins/git,plugins/github-pr-statusandplugins/docs.This rebuilds #5660 on main. #5660 was stacked on SDK changes that never landed, and it also bundled new behaviour (inline Retry rows, Retry on errors), which this PR leaves out. No Plugin SDK changes were needed.
What changed
ui-contract.ts:workflowActiveRunsandworkflowRunViewdeclare the origin thread'sruns:<threadId>tag, andworkflowStopRuninvalidates it.service.ts:publishRunsChangednow callsbb.rpc.experimental_invalidate([runs:])instead ofbb.realtime.publish. It runs at the same points as before: start, claim, phase or call change, settle, cancel.realtime-channel.tsis deleted.app.tsx: the two read hooks are nowexperimental_useRpcQuery, and Stop usesexperimental_useRpcMutation. The poll, backoff, coalescing, sequence guards and visibility/reconnect handling are deleted (−318/+78 inapp.tsx). Load, error and refresh-error states map onto the same UI as before, and a loaded "Workflow run not found" is still replaced by a later read error. Stop keeps "Stopping…" until the refreshed view lands, as it did on main.User-visible differences (each one forced by the deleted poll; there are no other UI changes):
workflowActiveRunsrefresh hid the composer banner until the next successful retry. The branch keeps showing the last loaded runs, because core retains data through refresh errors.Neither bug #5660 listed reproduces on main today. I checked with a probe test against main's code: the warning really did retry and cleared after recovery, and a later failure already replaced a cached "Workflow run not found". The second case now has a regression test.
No server/daemon wire changes. No CLI or SDK surface changes.
How you verified
pnpm exec turbo run typecheck lint test --filter=bb-plugin-workflows: 247/247 tests passed, lint reports 4 pre-existing warnings (main has 7 inapp.tsx).pnpm exec turbo run build typecheck lint test --filter='...[origin/main]': 189/191 tasks passed. The two failures were in unrelated files (install-machine-script,builtin-plugins,FilePreview) while the machine's load average was 23–38.FilePreviewpassed on its first rerun;builtin-pluginsfailed on a different test on the first rerun (a 40 s hot-reload timeout) and passed 28/28 on the second.New app tests drive real tag invalidations (
experimental_invalidateRpc):Reverting the missing-run branch or the label tick makes the corresponding test fail.
Service tests now assert
runs:origininvalidations for start, claim, cancel, and phase and call progress.Main vs branch on one real
pnpm devinstance (fresh store, scripted echo provider so agent calls are real worker threads with fixeddelay:lengths). Each comparison swaps onlyplugins/workflowsand reloads the plugin. Requests were counted in-page on/rpc/workflow*, and UI timing was taken from DOM changes against each call's server-sidefinishedAt:One branch Stop sample took 395 ms. Its first read started before the server had finished cancelling, and the next three samples were 42–94 ms.
I also clicked through the branch in the running app: expanded the banner card, used Open in right panel, and clicked Stop (the CLI reports
cancelled). I injected 500s onworkflowRunViewthrough browser request interception: the preview and panel showed "Could not refresh: injected outage." with the run still visible, and the warning cleared on the next invalidation.🤖 Generated with Claude Code