Skip to content

Move automations onto tagged live reads - #5667

Closed
ymichael wants to merge 6 commits into
bb/live-data-stack-5-theme-preview-thr_x3tzyie8jqfrom
bb/live-data-stack-8-automations-thr_n2p6uq8hfm
Closed

ymichael wants to merge 6 commits into
bb/live-data-stack-5-theme-preview-thr_x3tzyie8jqfrom
bb/live-data-stack-8-automations-thr_n2p6uq8hfm

Conversation

@ymichael

@ymichael ymichael commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Automations owned signal listeners, refresh timers, request guards, and pagination snapshots. Background failures could discard loaded views or hide errors, run starts did not refresh script detail, and returning to detail could reuse stale script content.

Stack 9 of 13, stacked on #5663. #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

Declare tags/keyTags/invalidates on the RPC contract, use the shared query/keyed-query/mutation hooks, and replace producer signals with scoped RPC invalidations. Overview, detail, drafts, and run rows survive refresh errors with inline Retry. Run starts refresh script detail, and returning to detail rereads its file.

Run history retains loaded positional windows through refresh and failed Load more, without a skeleton or gaps when a new run shifts page boundaries. This deliberately retains older pages after refresh; pagination failures use inline Retry instead of only a toast, following the plan's error rule. The new automations_run_pages RPC is available through SDK/CLI and documented; existing cursor pagination remains available. UI mutations now wait for matched active reads rather than issuing extra manual refreshes.

A separate mechanism commit adds opt-in refetchOnMount to the SDK query hook, with an SDK-owned regression test and SDK version 0.6.66. The Plugin Guide and API audit document it. No daemon protocol or persisted schema changes.

How you verified

pnpm exec turbo run build typecheck lint test --filter='...[origin/main]' --continue: 318 successful tasks, 292 cached, 2m23.694s. Automations: 139 passing tests; Plugin SDK: 378 passing tests. Both SDK version checks pass. The SDK mount-refresh negative control fails without the forwarding change.

Acceptance row Result
Loaded overview survives background error and Retry Passed in isolated app
Run start refreshes raw script content Passed in isolated app, second client
Re-entry rereads raw script content Passed in isolated app
Draft survives detail error and successful Retry Passed in isolated app
Load more failure preserves loaded runs and Retry works Passed: 50 → 53 rows
History refresh retains rows without skeleton Passed: held 52 rows → 53; failed refresh kept 53 → Retry 54
First detail entry avoids duplicate read Passed: one request in fresh client
Initial load failure has Retry and recovers Passed in fresh client
Handler-context nested-prefix rename Not applicable: contract declarations replace imperative context tagging
Pagination toast/reset-to-first-page reference behavior Deliberately different: inline Retry and retained contiguous positional windows

Source CLI also verified UI pause persistence, the new batch RPC's distinct positional windows, and existing cursor pagination. The full report and evidence are at /Users/michael/.bb/thread-storage/thr_n2p6uq8hfm/automations-report.md. Earlier implementation failures were fixed. One transient server build-failure-status test passed on its focused rerun and in the final full run. Synthetic fixtures and isolated processes/store were removed.

Diff from the supplied step 2 base: +502 / −379 (881 changed lines); 281 test/support lines. Commits: 50fc276461 (mechanism), d1451b661e (automations). Committed locally; not pushed.

Part of #4944

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from d1451b6 to 8414615 Compare October 17, 2026 01:24
ymichael added a commit that referenced this pull request Oct 17, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from 91b10be to 9facbda Compare October 17, 2026 03:36
@ymichael
ymichael changed the base branch from bb/live-data-stack-2-plugin-reads-and-writes-on-cor-thr_agngjehcrj to bb/live-data-stack-5-theme-preview-thr_x3tzyie8jq October 17, 2026 03:36
@ymichael
ymichael force-pushed the bb/live-data-stack-5-theme-preview-thr_x3tzyie8jq branch from 421881d to 0f7ca0b Compare October 17, 2026 04:51
ymichael added a commit that referenced this pull request Oct 17, 2026
ymichael added a commit that referenced this pull request Oct 17, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from 9facbda to a67a476 Compare October 17, 2026 04:51
@ymichael
ymichael force-pushed the bb/live-data-stack-5-theme-preview-thr_x3tzyie8jq branch from 0f7ca0b to c436076 Compare October 17, 2026 05:19
ymichael added a commit that referenced this pull request Oct 17, 2026
ymichael added a commit that referenced this pull request Oct 17, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from a67a476 to 7bc91a0 Compare October 17, 2026 05:19
@ymichael
ymichael force-pushed the bb/live-data-stack-5-theme-preview-thr_x3tzyie8jq branch from c436076 to 1499b19 Compare October 19, 2026 22:20
ymichael added a commit that referenced this pull request Oct 19, 2026
ymichael added a commit that referenced this pull request Oct 19, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from 7bc91a0 to e3857cf Compare October 19, 2026 22:20
@ymichael
ymichael force-pushed the bb/live-data-stack-5-theme-preview-thr_x3tzyie8jq branch from 1499b19 to 71fa0c7 Compare October 19, 2026 22:49
ymichael added a commit that referenced this pull request Oct 19, 2026
ymichael added a commit that referenced this pull request Oct 19, 2026
@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from e3857cf to 2e416a7 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-5-theme-preview-thr_x3tzyie8jq branch from 71fa0c7 to 37a95ea 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-8-automations-thr_n2p6uq8hfm branch from 2e416a7 to 1d78119 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-5-theme-preview-thr_x3tzyie8jq branch from 37a95ea to 12738d4 Compare October 20, 2026 21:19
@ymichael
ymichael force-pushed the bb/live-data-stack-8-automations-thr_n2p6uq8hfm branch from 1d78119 to 3e8d4c8 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
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