Repository navigation
Commit 01cbbba
feat(cluster): settings changes reach every replica (settings lane) (#31785)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9AcJE5U3g9Ed3gpotcHp5B4)_
Fixes #31597
Clause-②: yes (widening)
Metadata-protocol: none
Measured on the built declarations at head:
`@objectstack/service-settings` `dist/index.d.ts` gains
`SETTINGS_CHANGE_CLUSTER_CHANNEL`, the `ClusterSettingsChangePayload`
type and three public methods on `SettingsService`
(`attachSettingsChangePubSub()`, `detachSettingsChangePubSub()`,
`resyncSettingsChangePubSub()`); none of the five names occurs in that
package's source at base `9e1f1f90`. `@objectstack/service-cluster`
gains only private members. Nothing is removed, renamed or made
required. The claim read `no`; the measurement says `yes (widening)`. No
metadata an author writes changes.
## 维护者速读
- 改了什么:多副本(声明副本数大于 1 且使用 Redis
集群驱动)时,在一个副本上改了设置,其他副本也会立刻重新读取并生效,包括认证安全姿态。
- 为什么改:以前只有处理写请求的那个副本会重建配置,其他副本要到重启才看到新设置;实测一个副本已拒绝未验证邮箱的登录,另一个副本 95
秒后仍放行。
- 风险与回滚:单节点(未声明多副本或非 Redis 驱动)行为完全不变;广播消息只带命名空间和键,不带任何值或密钥。回滚即撤销本 PR。
- 先看:`service-settings/src/settings-service.ts`
的集群收发段(`attachSettingsChangePubSub`
起)、`service-cluster/src/metadata-cluster-bridge-plugin.ts` 的第五条通道
`attachSettingsLane`、新测试 `settings-cluster-lane.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/service-settings exec vitest run
src/settings-cluster-lane.test.ts`,预期 10 个用例全部通过(两个内核共享一条总线,A 写入后 B
一秒内生效)。
- 需要你做的:无,席位落地。
## What changes
- **A fifth cluster lane (`@objectstack/service-cluster`).**
`MetadataClusterBridgePlugin` gains `attachSettingsLane`, shaped like
lanes 1 to 4: it duck-types the `settings` service's
`attachSettingsChangePubSub(pubsub, nodeId)` seam at
`kernel:bootstrapped` (one phase after lanes 1 to 4, because the
settings service binds its engine at `kernel:ready` and a peer's change
must not reach a subscriber before that; `check:settings-bind-window`
caught the first spelling at `kernel:ready`), reports `bridged
settings.changed → cluster.pubsub` at info, and detaches on
`kernel:shutdown` (a throwing detach of another lane does not strand
it). Unlike lanes 1 to 4, which skip only the in-process driver, lane 5
attaches only behind `declaresMultiReplicaOnRedis(process.env,
cluster.driver)`: `OS_CLUSTER_REPLICAS` greater than 1 (or
`OS_EXPECT_MULTI_NODE=true`) AND the `redis` driver (R3). The
split-brain guard is untouched.
- **Send and receive (`@objectstack/service-settings`).** The write door
(`setMany`, which `set` and every reset go through) publishes after its
local `settings:changed`. The payload is spelled field by field in
`publishSettingsChange`: `{ originNode, namespace, key, scope, action,
at }`, the fields the local event already carries, never a value,
ciphertext handle or secret. A peer drops its own `originNode`,
validates the address, and emits its own local `settings:changed`, so
each subscriber re-reads the shared store. The receive path only emits;
it never publishes, so there is no echo. A publish failure is a warning
and never fails the write. Channel `settings.changed`
(`SETTINGS_CHANGE_CLUSTER_CHANNEL`, in the new
`settings-cluster-channel.ts`), partitioned per namespace.
- **Joins F3a's `cluster.resync`.** The lane registers
`resyncSettingsChangePubSub` through `registerLaneResync`, so when the
driver's connection returns after an outage every registered namespace
is announced locally once (`key: '*'`, the shape the engine bind already
uses) and every subscriber re-reads. A no-op until a transport is
attached; local only, never published.
- **No single-node change.** The engine bind's per-namespace
announcement moved into a private `emitEveryNamespace()` that the resync
reuses; the events it emits are unchanged. Every other emit site is
untouched.
- **Docs.** `content/docs/kernel/cluster.mdx` §6.2 lists lane 5, its
address-only payload, its resync, and its narrower attach condition.
## Tests
- `service-settings/src/settings-cluster-lane.test.ts` (new): two
`LiteKernel` replicas, each with its own `SettingsService` over its own
real `ObjectQL` engine, both engines over one shared Map driver (the
shared database), joined by one bus that delivers every publish to every
subscriber (publisher included). Each kernel runs the real
`MetadataClusterBridgePlugin` and a `cluster` service naming the `redis`
driver. The auth-posture subscriber has plugin-auth's binding shape:
`subscribe('auth')`, then re-read `require_email_verification`.
- ⭐ A `set` on A turns B's posture within one second (`vi.waitFor`, 1000
ms), read from the shared store; a reset travels the same way.
- The broadcast's keys are exactly `action, at, key, namespace,
originNode, scope`, and the serialized payload does not contain the
written value; B reads the value from the store.
- No echo: one write puts exactly one message on the bus, and the writer
and the peer each hear it once.
- `cluster.resync`: a write lost during a bus outage reaches B on
reconnect; nothing more goes on the wire.
- After `kernel:shutdown` a replica neither publishes nor hears.
- CONTROL: `redis` with no declaration emits exactly the events a lone
`SettingsService` emits today and nothing crosses; declared replicas
over `postgres` get no lane; a reconnect on an unattached replica and a
resync with no transport announce nothing; own-origin and malformed
messages are ignored.
- `service-cluster/src/metadata-cluster-bridge-plugin.test.ts`: a lane-5
describe (binds at `kernel:bootstrapped`, not at `kernel:ready`; attach
with the cluster's pubsub and node id; CONTROL undeclared on redis; one
replica; a non-redis remote driver; the memory driver; missing service
or seam; a throwing attach; shutdown detach; resync once per outage and
CONTROL undeclared). The harness gains a `settings` slot defaulting to
`none`, so every earlier case reads as before.
- Forced test edits: none.
- Test resolution: the new suite boots the cluster bridge, so
`service-settings` gains `@objectstack/service-cluster` as a
devDependency, aliased to source in its `vitest.config.ts` like its
other workspace imports.
- Ablations (each through `scripts/ablation-replace.mjs`; every mutation
landed, went red, and every restore left `git diff HEAD` empty; the
suites resolve the mutated files from source, so no rebuild leg):
| Ablation | Red |
| --- | --- |
| A1: the write publishes the event plus its value | 1 (the payload key
set) |
| A2: the receive path publishes what it received (echo) | 4 (the bus
storms; 683 local events) |
| A3: the loopback guard removed | 2 (the writer hears itself twice) |
| A4: lane 5's R3 guard replaced by the in-process guard | 3 of 10 in
the two-kernel suite, 4 of 42 in the bridge suite |
| A5: lane 5's shutdown detach removed | 1 in each suite |
| A6: the resync no-transport guard removed | 1 |
## Acceptance notes
- `SettingsService` holds no row cache (every read goes to the engine),
so a receiver re-reads through its subscribers: each one calls `get` /
`getNamespace` on the change, which reads the shared store. Nothing in
the service needed invalidating.
- The posture in the two-kernel test is a subscriber with plugin-auth's
binding shape, not plugin-auth itself, which `service-settings` does not
depend on.
- New names are the seat's call: the channel `settings.changed` (the
family's dot spelling, beside the local `settings:changed`), the
constant `SETTINGS_CHANGE_CLUSTER_CHANNEL`, the type
`ClusterSettingsChangePayload` and the three methods.
- #31722 (lane 2 resync) edits the same bridge file and the same docs
section; this PR lands first.
## Verification
All on head `260046945` after a fresh `pnpm install --frozen-lockfile`
and `turbo run build --filter='./packages/**'` (exit 0):
- `pnpm --filter @objectstack/service-settings --filter
@objectstack/service-cluster run test`: service-settings 75 files / 1430
tests, service-cluster 11 files / 154 tests, all passed.
- `run typecheck` for both: exit 0 (service-cluster's
`check:test-typecheck` included).
- Lint: root eslint `--no-inline-config` on both package directories,
exit 0.
- `dispatch-gates.mjs --commands` derived 114 commands on the final head
`260046945`; each was run, all 114 exited 0, and `--ran` reconciled: 114
derived, 114 run, 0 NOT-MEASURED, 0 UNRUN. The first round (on
`a6384788`) went red on `check:settings-bind-window` (lane 5 read the
`settings` service in a `kernel:ready` hook, inside the pre-bind
window); the fix moved the attach to `kernel:bootstrapped`.
`check-plugin-teardown-shape --self-test` needed its pinned fixture
fetched (`git fetch origin 621a487…`) before it could run.
- Ablations re-run on `260046945`: the table above holds on the final
head.
- `origin/main` moved to `c2bb879fe` during the round; none of its 43
files overlaps this diff, so main was not merged.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmNwiZZUkMiBsD19UEZ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ff8ef4c commit 01cbbba
11 files changed
Lines changed: 846 additions & 16 deletions
File tree
- .changeset
- content/docs/kernel
- packages/services
- service-cluster/src
- service-settings
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
341 | 342 | | |
342 | | - | |
| 343 | + | |
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
346 | 347 | | |
347 | | - | |
| 348 | + | |
| 349 | + | |
348 | 350 | | |
349 | 351 | | |
350 | 352 | | |
351 | | - | |
| 353 | + | |
| 354 | + | |
352 | 355 | | |
353 | 356 | | |
354 | 357 | | |
| |||
376 | 379 | | |
377 | 380 | | |
378 | 381 | | |
379 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
380 | 385 | | |
381 | 386 | | |
382 | 387 | | |
383 | 388 | | |
384 | 389 | | |
385 | 390 | | |
386 | 391 | | |
387 | | - | |
| 392 | + | |
388 | 393 | | |
389 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
390 | 404 | | |
391 | 405 | | |
392 | 406 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
76 | 85 | | |
| 86 | + | |
77 | 87 | | |
78 | 88 | | |
79 | 89 | | |
| |||
93 | 103 | | |
94 | 104 | | |
95 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
96 | 112 | | |
97 | 113 | | |
98 | 114 | | |
| |||
115 | 131 | | |
116 | 132 | | |
117 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
118 | 138 | | |
119 | 139 | | |
120 | 140 | | |
| |||
145 | 165 | | |
146 | 166 | | |
147 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
148 | 172 | | |
149 | 173 | | |
150 | 174 | | |
| |||
158 | 182 | | |
159 | 183 | | |
160 | 184 | | |
| 185 | + | |
161 | 186 | | |
162 | 187 | | |
163 | 188 | | |
| |||
592 | 617 | | |
593 | 618 | | |
594 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
0 commit comments