Skip to content

Move tasks onto keyed, tagged live reads - #5670

Closed
ymichael wants to merge 13 commits into
bb/live-data-stack-13-docs-thr_eyhy2ce2t5from
bb/live-data-stack-14-tasks-thr_jkff7k6wj2
Closed

ymichael wants to merge 13 commits into
bb/live-data-stack-13-docs-thr_eyhy2ce2t5from
bb/live-data-stack-14-tasks-thr_jkff7k6wj2

Conversation

@ymichael

@ymichael ymichael commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The tasks plugin kept its views live with its own signal scheduler, cache patchers and snapshot ordering guards. The board loaded through about 1,000 RPCs, and every edit triggered several re-reads. Several refreshes were missing too:

  • title and description edits didn't refresh comments;
  • project choices had no tags;
  • a miss on task key PAR-01 was never refreshed when PAR-1 was created.

Stack 13 of 13, stacked on #5673. #5640 is merged and #5688 is folded into #5658. Review only this PR's commits. Merge order: #5658 → #5661 → #5669 → #5666 → #5659 → #5660 → #5663 → #5667 → #5668 → #5677 → #5673 → #5670.

What changed

  • a3b6cd541e Plugin SDK: seeding cold keyed reads.
    • On a cold keyed read, where the client holds no rows yet for that method, a list response can seed the per-key cache. Later refreshes stay keyed.
    • Tasks seeds the first 25 summaries, which removes the second round trip that keyed loading would otherwise add.
    • Precise key invalidation and failed-batch recovery are covered by tests in the owner package.
    • Plugin SDK 0.6.68.
  • 4b71c6dfd8: tasks contracts declare tags, keyTags and invalidates, and task membership is seeded.
  • 2c99ea120a: task controls write through experimental_useRpcMutation.
  • 992aca8965: the board and list render membership first, then rows through experimental_useRpcKeyedQuery.
  • 8a1487142a: detail, activity and embeds stay live through tagged reads. PR refreshes use a watched server producer.
  • 431925b1e4: removes the signal scheduler, the patchers and the snapshot ordering guards (−1,197 lines).

Behaviour changes:

  • The board and list read membership, seed the first 25 summaries, then load the missing rows by key. Editing one card re-reads only that card.
    • Cards can appear before their labels, thread chips and attachment counts.
  • First-load failures show Retry. Failed refreshes keep loaded data and editors mounted, with an inline error and Retry.
    • A failed keyed batch keeps the partial cards, and the next invalidation recovers them.
  • The list keeps open tasks ahead of closed ones while loading. Unchanged rows keep their render identity.
  • Activity reads comments together with their attachments. Title and description edits refresh activity. Embeds keep their cached card on a refresh error and offer Retry.
  • Detail follows the resolved task ID across a project-prefix rename and keeps the draft. Task-key misses use canonical keys, and project choices use declared tags.
  • PR reads still refresh on window focus.
    • The server producer refreshes only while a watched task's latest PR is open or a draft.
    • The frontend PR timer is removed.

Optimistic updates and refusals (this PR): list status and detail status both update instantly through the shared optimistic option and roll back on refusal; detail status waited for the server on main. The hand-written list edit layer is replaced. A saved title stays visible until the re-read lands. Tasks mutations that returned {ok:false} now throw experimental_PluginRpcRefusal (conflict or invalid, #5688). A description save drops its pending change only on a refusal, and other errors keep it for retry.

  • List rows being saved dim and set aria-busy until the save settles or rolls back, driven by the hook's pendingInputs. This is the same pending feedback main shows.

How you verified

  • pnpm exec turbo run build typecheck lint test --filter='...[origin/main]' --continue: 318/318. The Plugin SDK version check passes against step 3.
  • Perf against origin/main, median of five samples:
Scenario main Branch
Board first cards 629 ms 503 ms
List first cards 512 ms 512 ms
Board and list open together 539 ms 527 ms
Board title / status edit 70 / 70 ms 19 / 13 ms
List title / status edit 57 / 71 ms 17 / 40 ms
Board load RPCs 1,018 26
List load RPCs 20 16
Board and list load RPCs 1,032 29
RPCs per edit (board / list) 7 / 6 4 / 4

Every measured edit re-read exactly one task key. React commit probes confirm that only the edited row re-renders, on both the board and the list.

Behaviour Result
Failed board batches and every board read offer working Retry Passed
Failed keyed rows recover on the next invalidation Passed
Unchanged rows don't re-render Passed
Open rows stay first across batches Passed
Title/description edits refresh comments Passed
Project choices refresh through tags Passed
A PAR-01 miss recovers after PAR-1 is created Passed
A project-prefix rename keeps the detail draft Passed
Embed keeps its cache with Retry Passed
Activity groups comments and attachments Passed
PR focus refresh; no background refresh for absent or closed PRs Passed
Cards appear before their metadata Deliberately different: membership first

Fixes #4944

AGENT GENERATED

🤖 Generated with Claude Code

ymichael added a commit that referenced this pull request Oct 17, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from 9028638 to e1f9107 Compare October 17, 2026 03:36
@ymichael
ymichael changed the base branch from bb/live-data-stack-3-watching-connect-bb-account-thr_79u87xmcbx to bb/live-data-stack-13-docs-thr_eyhy2ce2t5 October 17, 2026 03:37
@ymichael
ymichael force-pushed the bb/live-data-stack-13-docs-thr_eyhy2ce2t5 branch from e733966 to 6b98ae1 Compare October 17, 2026 04:51
ymichael added a commit that referenced this pull request Oct 17, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from e1f9107 to ebc2775 Compare October 17, 2026 04:51
@ymichael
ymichael force-pushed the bb/live-data-stack-13-docs-thr_eyhy2ce2t5 branch from 6b98ae1 to f0fd6d7 Compare October 17, 2026 05:19
ymichael added a commit that referenced this pull request Oct 17, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from ebc2775 to 31e2c28 Compare October 17, 2026 05:19
@ymichael
ymichael force-pushed the bb/live-data-stack-13-docs-thr_eyhy2ce2t5 branch from f0fd6d7 to 7c399df Compare October 19, 2026 22:21
ymichael added a commit that referenced this pull request Oct 19, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from 31e2c28 to c32e1ca Compare October 19, 2026 22:21
@ymichael
ymichael force-pushed the bb/live-data-stack-13-docs-thr_eyhy2ce2t5 branch from 7c399df to d13fb8d Compare October 19, 2026 22:49
ymichael added a commit that referenced this pull request Oct 19, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from c32e1ca to 638a08b Compare October 19, 2026 22:49
ymichael added a commit that referenced this pull request Oct 20, 2026
…mutations (#5640)

## Human comments

## What was wrong

**Stack 1 of 14.** Merge order: #5640 → #5658 → #5688 → #5661 → #5669 →
#5666 → #5659 → #5660 → #5663 → #5667 → #5668 → #5677 → #5673 → #5670.

When a core write changes data that other screens or clients show,
someone has to remember to refresh every query that depends on it. Today
each write does this by hand: a cache-owner module plus a system change
kind (for UI preferences, `ui-preferences-changed`, routed through the
realtime registry). Plugins have no equivalent at all, which is #4944.

This is step 1 of a stack that replaces #5582. Here, a contract declares
what a read depends on and what a write changes, and the client
refreshes from those declarations. The plugin hooks in later steps will
be thin wrappers over this same core path.

## What changed

- **`@bb/domain`:** a new `ContractTagDeclarations` type with
`tags(input, output)` and `invalidates(input, output)`. It contains
types only.
- **`@bb/hono-typed-routes`:**
  - `defineRoute` accepts these declarations.
- After a 2xx JSON response, `typedRoutes` publishes the route's
`invalidates` tags through a new `invalidateTags` option.
- Registering a route that declares `invalidates` throws if that option
is missing.
- **Server:** `hub.notifyTags` batches tags within a microtask and sends
`{type:"changed", entity:"tags", tags}` to every connected client. This
is a new message between the server and the app; the daemon is
untouched, so `HOST_DAEMON_PROTOCOL_VERSION` is unchanged.
- **New `@bb/query-tags` package:**
  - Tags are registered on queries through `meta`.
- `invalidateTags` refreshes the queries whose data carries a matching
tag, within a scope. Core uses `core`.
- A read that is in flight restarts only if an overlapping invalidation
arrives during it.
- `runTaggedMutation` settles only after the affected active reads have
re-read. That includes a first load whose tags aren't known yet, which
the reference branch got wrong.
- **App:**
- The realtime cache effects pass `tags` messages to `invalidateTags`,
and hold them while the tab is hidden.
- A small `route-tags.ts` adapter connects route contracts to these
reads and mutations.
- **UI preferences, which prove the mechanism:**
- The read declares `ui-preferences`, and update and reset invalidate
it.
  - The sync engine saves through `runRouteMutation`.
- `ui-preferences-cache-owner.ts`, the `ui-preferences-changed` change
kind and its registry entry are deleted.
- The sync keeps each acknowledged entry, so a failed re-read neither
reverts the preference nor bases the next write on a stale revision.

Not in this PR: plugin SDK hooks, plugin RPC, plugin WebSocket targets
and the CLI. Those come in later steps of the stack, each with its first
caller.

## How you verified

- `pnpm exec turbo run build typecheck lint test
--filter='...[origin/main]' --continue`: 296/296 tasks passed.
  - Lint has no errors, and the app's warnings match `origin/main`.
- New tests in `@bb/query-tags` cover tag matching, scope isolation,
stale inactive queries, in-flight races, and refresh failure and
recovery.
  - The first-load race test fails against the reference implementation.
- `@bb/hono-typed-routes` tests: invalidations are published only after
2xx JSON responses, and registration fails without the publisher.
- Two isolated browser profiles against a source server: a preference
write in one refreshed the footer preferences in the other, and a
composer draft survived the refresh.
- Two WebSocket clients with no subscriptions both received the `tags`
message after an HTTP write.
- Sidebar perf, five paired samples per checkout with 3,000 threads,
against `origin/main`:

| Metric | Main median (range) | Branch median (range) |
| --- | ---: | ---: |
| Mount, ms | 410 (404–419) | 408 (359–412) |
| Pin, ms | 72 (71–73) | 71 (70–73) |
| Status patch, ms | 69 (69–71) | 70 (69–73) |
| Membership refresh, ms | 103 (103–107) | 107 (103–108) |
| Query observers | 13 | 13 |

The ranges overlap and the number of query observers is unchanged. These
samples were taken before the unused pieces were removed; removing them
deleted code paths without changing the read path.

Part of #4944

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@ymichael
ymichael force-pushed the bb/live-data-stack-13-docs-thr_eyhy2ce2t5 branch from d13fb8d to 356f6c5 Compare October 20, 2026 19:47
ymichael added a commit that referenced this pull request Oct 20, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from 638a08b to 0ebac59 Compare October 20, 2026 19:47
@ymichael
ymichael force-pushed the bb/live-data-stack-13-docs-thr_eyhy2ce2t5 branch from 356f6c5 to 02d916d Compare October 20, 2026 21:19
@ymichael
ymichael force-pushed the bb/live-data-stack-14-tasks-thr_jkff7k6wj2 branch from 0ebac59 to b2b2477 Compare October 20, 2026 21:19
@ymichael

Copy link
Copy Markdown
Collaborator Author

Closing as superseded. Plugin watching was rebuilt on core's watched-target registry in #5929 + #5939. The plugin migrations will be rebuilt one at a time from main on the merged #5658 API. This branch stays available for reference.

@ymichael ymichael closed this Oct 21, 2026
ymichael added a commit that referenced this pull request Oct 28, 2026
## Human comments

## What was wrong

Tasks kept its views live with its own query layer instead of BB's
shared live reads. That layer was a signal scheduler fed by four
`useRealtime` channels
(`tasks`/`projects`/`comments`/`threads:changed`), per-view patchers,
snapshot revision guards, a refresh-generation provider, a hand-written
list edit layer and a 60 s pull request poll. The board loaded card
metadata with one `listAttachments` call per card plus one
`listTaskThreads` call per working task: 427 RPCs for a 400-card
project. Every edit triggered 5–6 re-reads, each after the scheduler's
50 ms batching delay.

I checked #5670's listed bugs on `main` against a seeded dev instance
before porting:

| #5670 bug | On `main` |
| --- | --- |
| Board loads through ~1,000 RPCs | Reproduces: 427 RPCs for 400 cards,
400 of them `listAttachments` |
| Several re-reads per edit | Reproduces: 5–6 reads per edit |
| Title/description edits don't refresh comments | Not a bug on `main`:
activity re-read on every task change, and nothing in it depends on
title or description |
| Untagged project choices | `listBbProjects` reads core data and
refreshes on mount and reconnect, as before |
| A `PAR-01` key miss is never refreshed | Does not reproduce: the
detail view re-read on any task change. The port keeps this (test below)
|

## What changed

No Plugin SDK change. Main's keyed reads don't need #5670's "seed cold
keyed reads from a list response": the views use plain tagged list
reads, so the first paint stays one round trip.

- **Contract** (`shared/contract.ts`, `shared/tags.ts`):
  - Reads declare `tags`.
  - Three internal reads replace client-side fan-out:
    - `listAllTasks`: unpaged; replaces the client page loop.
- `listTaskCardMeta`: attachment counts and working agents for a
project's cards in one read; replaces the per-card calls.
- `labelsByProject`: keyed by project, `keyTags`; serves the All tasks
list's labels.
- **Server** (`api`, `delegate`, `lifecycle`, `attachments`, `cli`):
- Every `bb.realtime.publish` becomes `bb.rpc.experimental_invalidate`
with the matching tags.
- This happens inside the domain handlers that RPC, the CLI and agent
tools share, so every write path invalidates exactly once. The contract
doesn't also declare `invalidates`: the server would then broadcast
twice, and the editing client would re-read twice.
- A `whileWatched` producer on `listTaskPullRequests` replaces the
frontend 60 s poll. It refreshes a watched task's pull requests every 60
s while its last read had an open or draft PR.
- **UI**:
- Every view reads through `experimental_useRpcQuery`. List labels for
all projects use `experimental_useRpcKeyedQuery`.
- List row edits go through `experimental_useRpcMutation` with the
shared optimistic cache. The dimmed pending rows come from
`pendingInputs`.
- The Refresh button uses `experimental_useRpcRefresh`. It spins only
for a manual refresh or a reconnect, as before.
- **Deleted**: `shell/signal-scheduler.ts`, `shell/refresh.tsx`,
`views/list/optimistic.ts`, `views/list/use-task-edits.ts`, the
board/list patchers, snapshot revision guards, visibility handling and
the detail PR interval.
- **Kept**: the localStorage snapshot for folders, projects and the
sidebar summary. The shared cache doesn't persist across reloads, and
this snapshot is what prevents #1676's reload flash. It is now a plain
initial value.
- **Docs**: `docs/api_to_audit.md` lists the Tasks producer under
watched reads.

Behaviour is the same for users. Changes that come from the shared
cache:
- Returning to a list scope you already opened (for example Active →
All) paints its cached rows while it revalidates; `main` showed skeleton
rows again. This is the repeat-visit behaviour #1676 asked for.
- List rows now refresh after a project prefix rename; on `main` they
kept stale keys until the next task change.
- Activity no longer re-reads on edits that don't write a comment.
- A refused list edit (`ok: false`) shows its toast and re-reads the
list to drop the prediction. It no longer rolls back locally first.

`sidebarOpenTaskCount` is now a tagged read. Other plugins can read the
open-task count live with `experimental_useRpcQuery({ pluginId: "tasks",
… })`, which is part of #5720's second ask.

## How you verified

- `pnpm exec turbo run typecheck lint test --filter='...[origin/main]'
--continue`:
  - `bb-plugin-tasks`: 398/398.
  - Lint: 21 warnings, the same count as `main`, none new.
  - Three failures, all outside Tasks (CI re-runs them):
- `@bb/app` `CommandPalette.test.tsx`: a 10 s hook timeout; it passes
alone, 71/71.
- Two `@bb/server` builtin-plugin hot-reload fixture tests: they time
out at load average 24–35.
- New `api/live-reads.test.ts` checks that each write invalidates the
tags of every read it must refresh and leaves the others alone:
- A title edit refreshes that task's detail, both lists and the open
count. It doesn't refresh another task, another project, activity or
card metadata.
  - Status changes and comments refresh activity.
  - A `REV-03` miss resolves when `REV-3` is created.
- Prefix renames, moves between projects, uploads, thread attaches,
label changes, folders, presets and a CLI edit.
- Also tested: `listAllTasks` past one page, and `listTaskCardMeta`
contents.
- `api.test.ts`: the producer refreshes every 60 s only while the PR is
open, and stops when unwatched.
- UI tests that pushed realtime events now drive
`experimental_invalidateRpc` with the tags the server sends. Tests of
the deleted layer were removed: `signal-scheduler`, `optimistic`,
`incremental`, the badge coalescing test and the first-connection test
(that policy now belongs to core).

**Measured on a real dev instance** (`pnpm start:worktree`), same data
on both builds: 480 tasks in one project, 50 with attachments, 5
attached threads. Each build ran in the same headless Chromium at
1600×1000. Medians, main → branch:

| Load (n=7) | Time to first rows (in-page) | Tasks RPCs |
| --- | ---: | ---: |
| Board | 364 → 203 ms | 427 → 10 |
| Project list | 439 → 378 ms | 29 → 12 |
| All tasks | 440 → 406 ms | 32 → 12 |
| Task detail | 228 → 227 ms | 29 → 17 |

| Edit (n=5) | Visible after | Re-reads |
| --- | ---: | ---: |
| Board: title edited elsewhere | 77 → 34 ms | 6 → 4 |
| Board: drag to another column (optimistic) | 23 → 28 ms | 6 → 4 |
| List: title edited elsewhere | 64 → 21 ms | 5 → 5 |
| List: priority from the row menu (optimistic) | 125 → 140 ms | 5 → 5 |

The two optimistic rows (drag and priority menu) are both immediate on
both builds, so their differences are noise. Counting
`toLocaleDateString` calls during load showed the list renders its rows
fewer times than on `main` (6,370 vs 10,226 calls). No edit triggered a
double read.

**Driven in the running app on the branch:**
- Detail page:
- The status change appears in activity, and the badge count follows
open/closed changes.
- Title rename shows on the list. Comment, sub-task, and attachment
upload and removal all update live.
- A `bb tasks update` from the CLI updates an open detail view's title
and activity live.
- Detaching and re-attaching a thread via the CLI removes and restores
the board card's working-agent chip live.
- Board drag persists.
- The Refresh button spins, then clears.
- A detail page for an unknown key (`PERF-0481`) resolves once
`PERF-481` is created.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Michael Yong <review@local>
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