Repository navigation
feat(cluster): settings changes reach every replica (settings lane) - #31785
Conversation
A fifth MetadataClusterBridgePlugin lane, settings.changed: a settings write publishes its address (namespace, key, scope, action, time; never a value) and peers emit their own local settings:changed, so every subscriber re-reads the shared store. Attaches only where several replicas are declared over the redis driver. Joins cluster.resync. Claude-Session: https://claude.ai/code/session_01ADHkmNwiZZUkMiBsD19UEZ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmNwiZZUkMiBsD19UEZ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmNwiZZUkMiBsD19UEZ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmNwiZZUkMiBsD19UEZ Co-authored-by: Claude <noreply@anthropic.com>
…e settings engine bind A peer change delivered before the settings service bound its engine would have every subscriber read the in-memory defaults (check:settings-bind-window). Claude-Session: https://claude.ai/code/session_01ADHkmNwiZZUkMiBsD19UEZ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 7 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 2 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 14 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 8c75993bf71d7ea72cb589a9a0da6d5c22ee099c && git checkout 8c75993bf71d7ea72cb589a9a0da6d5c22ee099c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e253f3ab09717234fedae8e4d7a193cd1a12b0da 2600469454ec3e8ff7f063b0260a432708b9e21c && git checkout -B drift-repro e253f3ab09717234fedae8e4d7a193cd1a12b0da && git merge --no-ff 2600469454ec3e8ff7f063b0260a432708b9e21c
node scripts/docs-audit/affected-docs.mjs --json e253f3ab09717234fedae8e4d7a193cd1a12b0da
|
|
domain:server#1 · os-steve · session_01ADHkmPF1skfu2kx89BEXZi 席位 ACCEPT · head
|
Requested by Steve · project thread
Fixes #31597
Clause-②: yes (widening)
Metadata-protocol: none
Measured on the built declarations at head:
@objectstack/service-settingsdist/index.d.tsgainsSETTINGS_CHANGE_CLUSTER_CHANNEL, theClusterSettingsChangePayloadtype and three public methods onSettingsService(attachSettingsChangePubSub(),detachSettingsChangePubSub(),resyncSettingsChangePubSub()); none of the five names occurs in that package's source at base9e1f1f90.@objectstack/service-clustergains only private members. Nothing is removed, renamed or made required. The claim readno; the measurement saysyes (widening). No metadata an author writes changes.维护者速读
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
@objectstack/service-cluster).MetadataClusterBridgePlugingainsattachSettingsLane, shaped like lanes 1 to 4: it duck-types thesettingsservice'sattachSettingsChangePubSub(pubsub, nodeId)seam atkernel:bootstrapped(one phase after lanes 1 to 4, because the settings service binds its engine atkernel:readyand a peer's change must not reach a subscriber before that;check:settings-bind-windowcaught the first spelling atkernel:ready), reportsbridged settings.changed → cluster.pubsubat info, and detaches onkernel: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 behinddeclaresMultiReplicaOnRedis(process.env, cluster.driver):OS_CLUSTER_REPLICASgreater than 1 (orOS_EXPECT_MULTI_NODE=true) AND theredisdriver (R3). The split-brain guard is untouched.@objectstack/service-settings). The write door (setMany, whichsetand every reset go through) publishes after its localsettings:changed. The payload is spelled field by field inpublishSettingsChange:{ originNode, namespace, key, scope, action, at }, the fields the local event already carries, never a value, ciphertext handle or secret. A peer drops its ownoriginNode, validates the address, and emits its own localsettings: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. Channelsettings.changed(SETTINGS_CHANGE_CLUSTER_CHANNEL, in the newsettings-cluster-channel.ts), partitioned per namespace.cluster.resync. The lane registersresyncSettingsChangePubSubthroughregisterLaneResync, 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.emitEveryNamespace()that the resync reuses; the events it emits are unchanged. Every other emit site is untouched.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): twoLiteKernelreplicas, each with its ownSettingsServiceover its own realObjectQLengine, 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 realMetadataClusterBridgePluginand aclusterservice naming theredisdriver. The auth-posture subscriber has plugin-auth's binding shape:subscribe('auth'), then re-readrequire_email_verification.seton A turns B's posture within one second (vi.waitFor, 1000 ms), read from the shared store; a reset travels the same way.action, at, key, namespace, originNode, scope, and the serialized payload does not contain the written value; B reads the value from the store.cluster.resync: a write lost during a bus outage reaches B on reconnect; nothing more goes on the wire.kernel:shutdowna replica neither publishes nor hears.rediswith no declaration emits exactly the events a loneSettingsServiceemits today and nothing crosses; declared replicas overpostgresget 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 atkernel:bootstrapped, not atkernel: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 asettingsslot defaulting tonone, so every earlier case reads as before.Forced test edits: none.
Test resolution: the new suite boots the cluster bridge, so
service-settingsgains@objectstack/service-clusteras a devDependency, aliased to source in itsvitest.config.tslike its other workspace imports.Ablations (each through
scripts/ablation-replace.mjs; every mutation landed, went red, and every restore leftgit diff HEADempty; the suites resolve the mutated files from source, so no rebuild leg):Acceptance notes
SettingsServiceholds no row cache (every read goes to the engine), so a receiver re-reads through its subscribers: each one callsget/getNamespaceon the change, which reads the shared store. Nothing in the service needed invalidating.service-settingsdoes not depend on.settings.changed(the family's dot spelling, beside the localsettings:changed), the constantSETTINGS_CHANGE_CLUSTER_CHANNEL, the typeClusterSettingsChangePayloadand the three methods.Verification
All on head
260046945after a freshpnpm install --frozen-lockfileandturbo 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 typecheckfor both: exit 0 (service-cluster'scheck:test-typecheckincluded).--no-inline-configon both package directories, exit 0.dispatch-gates.mjs --commandsderived 114 commands on the final head260046945; each was run, all 114 exited 0, and--ranreconciled: 114 derived, 114 run, 0 NOT-MEASURED, 0 UNRUN. The first round (ona6384788) went red oncheck:settings-bind-window(lane 5 read thesettingsservice in akernel:readyhook, inside the pre-bind window); the fix moved the attach tokernel:bootstrapped.check-plugin-teardown-shape --self-testneeded its pinned fixture fetched (git fetch origin 621a4876…) before it could run.260046945: the table above holds on the final head.origin/mainmoved toc2bb879feduring the round; none of its 43 files overlaps this diff, so main was not merged.Generated by Claude Code