diff --git a/.changeset/31597-settings-changes-reach-every-replica.md b/.changeset/31597-settings-changes-reach-every-replica.md new file mode 100644 index 00000000000..5adede74710 --- /dev/null +++ b/.changeset/31597-settings-changes-reach-every-replica.md @@ -0,0 +1,17 @@ +--- +'@objectstack/service-settings': patch +'@objectstack/service-cluster': patch +--- + +feat(cluster): a settings change on one replica reaches every replica + +Clause-②: yes (widening) +Metadata-protocol: none + +Multi-replica deployments on the `redis` cluster driver only. The single-node default (no declared replicas, or any driver but `redis`) emits exactly what it emitted before. + +`settings:changed` is an in-process subscriber set, and its subscribers rebuild the auth posture, password / session / MFA policy, organization access policy, mail, SMS, storage and the AI provider. Under round-robin only the replica that took the write rebuilt; every peer kept the old configuration, security posture included, until it restarted. + +- **A fifth cluster lane (`@objectstack/service-cluster`).** `MetadataClusterBridgePlugin` attaches the settings service to the cluster bus on the `settings.changed` channel, only where the deployment declares several replicas (`OS_CLUSTER_REPLICAS` greater than 1, or `OS_EXPECT_MULTI_NODE=true`) over the `redis` driver (`declaresMultiReplicaOnRedis`). The split-brain guard is unchanged. +- **The message is an address, never a value (`@objectstack/service-settings`).** A write publishes the namespace, key, scope, action and time of the change. A peer emits its own local `settings:changed`, so each subscriber re-reads the shared store. A received change is never published again, and the writer's own message is dropped by its node id. New exports: `SETTINGS_CHANGE_CLUSTER_CHANNEL` and the `ClusterSettingsChangePayload` type; new methods `SettingsService.attachSettingsChangePubSub()`, `detachSettingsChangePubSub()` and `resyncSettingsChangePubSub()`. +- **Joins `cluster.resync`.** When the cluster driver's connection returns after an outage, every registered namespace is announced locally once (`key: '*'`), so a change whose message was lost during the outage still takes effect without a restart. diff --git a/content/docs/kernel/cluster.mdx b/content/docs/kernel/cluster.mdx index 1ea44980893..02cb85bf809 100644 --- a/content/docs/kernel/cluster.mdx +++ b/content/docs/kernel/cluster.mdx @@ -328,7 +328,7 @@ cache compare it on receipt. ### 6.2 The cluster-invalidation family Cross-node metadata invalidation is not one channel — it is a **family** of -four independent PubSub lanes, late-bound by `MetadataClusterBridgePlugin` +five independent PubSub lanes, late-bound by `MetadataClusterBridgePlugin` (`@objectstack/service-cluster`) at `kernel:ready`, one per state owner that goes stale when a shared record changes on a different node: @@ -338,17 +338,20 @@ goes stale when a shared record changes on a different node: | 2 — ObjectQL object registry | `metadata.mutated` (`METADATA_MUTATION_CLUSTER_CHANNEL`, #13331) | `ClusterMetadataMutationPayload` | `@objectstack/metadata-protocol` | ObjectQL's OBJECT registry, from a `sys_metadata` re-read; then, from the same replay, the automation service's armed flows and its materialized connectors (a `connector` mutation that is not a draft, #28002), each from the replica's own re-read | | 3 — ObjectQL driver registry | `datasource.mutated` (`DATASOURCE_MUTATION_CLUSTER_CHANNEL`, #13805) | `ClusterDatasourceMutationPayload` | `@objectstack/service-datasource` | ObjectQL's DRIVER registry, from a shared datasource-record re-read | | 4 — declarative connector instances | `connector-credential.mutated` (`CONNECTOR_CREDENTIAL_MUTATION_CLUSTER_CHANNEL`, #27428) | `ClusterConnectorCredentialMutationPayload` (`{ originNode, ref }`) | `@objectstack/service-automation` | the automation service's materialized connectors, from a reconcile that re-reads the shared `sys_connector_credential` rows; published by the credential door (`PUT` / `DELETE /api/v1/automation/connectors/credential-refs/:ref`) after the row is written or cleared | +| 5 — settings subscribers | `settings.changed` (`SETTINGS_CHANGE_CLUSTER_CHANNEL`, #31597) | `ClusterSettingsChangePayload` (`{ originNode, namespace, key, scope, action, at }`) | `@objectstack/service-settings` | every local `settings:changed` subscriber (auth posture, password / session / MFA policy, organization access policy, mail, SMS, storage, the AI provider), each re-reading the shared settings store; published by `SettingsService` after a row is written or cleared. Attaches only where several replicas are declared over the `redis` driver | -Lanes 2 to 4 share one contract, stated once here rather than in each +Lanes 2 to 5 share one contract, stated once here rather than in each channel's own doc comment: - **Address-only signal.** No message body ever rides these channels — the payload names only what changed (a metadata address, a datasource name, - or a connector credential reference), never the changed value. + a connector credential reference, or a settings namespace and key), never + the changed value. - **Receipt runs convergence, not trust.** A peer that receives a signal does not apply the payload as content; it re-reads its OWN copy of the source of truth (`sys_metadata` for lane 2, the shared datasource record for lane 3, - the shared credential rows for lane 4) and converges its local registry + the shared credential rows for lane 4, the shared settings store for + lane 5) and converges its local registry from that read. A duplicate or re-ordered delivery converges to the same state as a single one. - **`originNode` loopback suppression.** Every payload carries the publishing @@ -376,7 +379,9 @@ channel's own doc comment: datasource and every held pool (`DatasourceAdminService.resyncDatasourceMutationPubSub()`), and lane 4 runs the connector reconcile - (`AutomationEngine.resyncConnectorCredentialPubSub()`). + (`AutomationEngine.resyncConnectorCredentialPubSub()`), and lane 5 + announces every settings namespace locally so each subscriber re-reads it + (`SettingsService.resyncSettingsChangePubSub()`). `AuthzClusterBridgePlugin` advances the engine's write epoch, which retires cached grants. **Lane 2 has no resync yet**: it converges per item on the signals that are delivered, and fully at boot. A cache of your own @@ -384,9 +389,18 @@ channel's own doc comment: `@objectstack/service-cluster`. On the `memory` driver that subscription is a no-op, because nothing there can lose a connection. -All four lanes skip their fan-out on the same condition — the in-process +Lanes 1 to 4 skip their fan-out on the same condition — the in-process `memory` cluster driver, described for lane 1 immediately below, applies -identically to lanes 2 to 4 (#14021). +identically to lanes 2 to 4 (#14021). Lane 5 is narrower: it attaches only +where the deployment declares several replicas (`OS_CLUSTER_REPLICAS` greater +than 1, or `OS_EXPECT_MULTI_NODE=true`) over the `redis` driver +(`declaresMultiReplicaOnRedis`, cloud#3814 R3), so a single node emits +exactly the local `settings:changed` events it always did. It binds at +`kernel:bootstrapped`, one phase after the others, because the settings +service binds its engine at `kernel:ready` and a peer's change must not reach +a subscriber before that. A received +settings change is announced locally and never published again, so no +replica echoes it. #### Lane 1 — `metadata.changed` (the metadata service cache) diff --git a/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.test.ts b/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.test.ts index 9b8b13f57d4..770e0a386c4 100644 --- a/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.test.ts +++ b/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.test.ts @@ -24,7 +24,7 @@ * without that control a guard is indistinguishable from "never say bridged". */ -import { describe, it, expect, vi } from 'vitest'; +import { afterEach, describe, it, expect, vi } from 'vitest'; import type { PluginContext } from '@objectstack/core'; import { MetadataClusterBridgePlugin } from './metadata-cluster-bridge-plugin.js'; import { ClusterDriverLiveness, offerClusterDriverLiveness } from './cluster-resync.js'; @@ -67,6 +67,15 @@ interface HarnessOptions { automation?: 'none' | 'bare' | 'real'; /** When true, the automation seam throws on attach. */ automationAttachThrows?: boolean; + /** + * [#31597] The `settings` slot: `'none'` (getService throws — the default, + * so every earlier case reads exactly as it did), `'bare'` (present, no + * attachSettingsChangePubSub — an older implementation), or `'real'` + * (exposes attachSettingsChangePubSub). + */ + settings?: 'none' | 'bare' | 'real'; + /** When true, the settings seam throws on attach. */ + settingsAttachThrows?: boolean; } function makeHarness(opts: HarnessOptions = {}) { @@ -74,6 +83,7 @@ function makeHarness(opts: HarnessOptions = {}) { driver = 'redis', metadata = 'fallback', protocol = 'real', datasourceAdmin = 'none', datasourceAttachThrows = false, automation = 'none', automationAttachThrows = false, + settings = 'none', settingsAttachThrows = false, } = opts; const logger = { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }; @@ -93,6 +103,12 @@ function makeHarness(opts: HarnessOptions = {}) { return detachCredential; }); + const detachSettings = vi.fn(); + const attachSettings = vi.fn((_pubsub: unknown, _nodeId: string) => { + if (settingsAttachThrows) throw new Error('settings attach exploded'); + return detachSettings; + }); + const pubsub = { publish: vi.fn(), subscribe: vi.fn(), close: vi.fn() }; const cluster = driver === null @@ -115,6 +131,10 @@ function makeHarness(opts: HarnessOptions = {}) { automation === 'none' ? undefined : automation === 'bare' ? { execute: vi.fn() } : { attachConnectorCredentialPubSub: attachCredential }; + const settingsService = + settings === 'none' ? undefined + : settings === 'bare' ? { get: vi.fn(), subscribe: vi.fn() } + : { attachSettingsChangePubSub: attachSettings }; const hooks = new Map Promise | void>>(); const ctx = { @@ -145,6 +165,10 @@ function makeHarness(opts: HarnessOptions = {}) { if (!automationService) throw new Error('service not found: automation'); return automationService; } + if (name === 'settings') { + if (!settingsService) throw new Error('service not found: settings'); + return settingsService; + } throw new Error(`service not found: ${name}`); }, } as unknown as PluginContext; @@ -158,6 +182,7 @@ function makeHarness(opts: HarnessOptions = {}) { attachMetadata, detachMetadata, attachMutation, detachMutation, attachDatasource, detachDatasource, attachCredential, detachCredential, + attachSettings, detachSettings, }; } @@ -592,3 +617,156 @@ describe('cluster.resync — every attached lane re-reads what an outage made it expect(h.resyncCredential).not.toHaveBeenCalled(); }); }); + +describe('[#31597] lane 5 — the settings service’s settings.changed fan-out, behind declared replicas over redis', () => { + afterEach(() => { + vi.unstubAllEnvs(); + }); + /** Declare (or not) several replicas, the R3 switch the lane keys on. */ + const declare = (replicas: string) => { + vi.stubEnv('OS_CLUSTER_REPLICAS', replicas); + vi.stubEnv('OS_EXPECT_MULTI_NODE', ''); + }; + + it('⭐ attaches with the cluster’s pubsub and node id when 2 replicas are declared over redis, and reports it', async () => { + declare('2'); + const h = makeHarness({ settings: 'real' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).toHaveBeenCalledTimes(1); + expect(h.attachSettings).toHaveBeenCalledWith(h.pubsub, 'node-a'); + expect(infoLines(h).some((l) => l.includes('bridged settings.changed'))).toBe(true); + }); + + it('binds at kernel:bootstrapped, after the settings service bound its engine at kernel:ready', async () => { + declare('2'); + const h = makeHarness({ settings: 'real' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + expect(h.attachSettings).not.toHaveBeenCalled(); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).toHaveBeenCalledTimes(1); + }); + + it('CONTROL — the redis driver with no declaration attaches nothing and says nothing above debug', async () => { + declare(''); + const h = makeHarness({ settings: 'real' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).not.toHaveBeenCalled(); + expect(infoLines(h).some((l) => l.includes('settings.changed'))).toBe(false); + expect(warnLines(h).some((l) => l.includes('settings'))).toBe(false); + expect(debugLines(h).some((l) => l.includes('settings fan-out skipped'))).toBe(true); + // The other lanes keep their own guard: lane 2 still attaches on redis. + expect(h.attachMutation).toHaveBeenCalledTimes(1); + }); + + it('one declared replica is a single node: no lane', async () => { + declare('1'); + const h = makeHarness({ settings: 'real' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).not.toHaveBeenCalled(); + }); + + it('declared replicas over a driver other than redis: no lane', async () => { + declare('3'); + const h = makeHarness({ settings: 'real', driver: 'postgres' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).not.toHaveBeenCalled(); + }); + + it('declared replicas over the in-process memory driver: no lane', async () => { + declare('3'); + const h = makeHarness({ settings: 'real', driver: 'memory' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).not.toHaveBeenCalled(); + }); + + it('skips quietly when no settings service is registered, or it does not expose the seam', async () => { + declare('2'); + for (const settings of ['none', 'bare'] as const) { + const h = makeHarness({ settings }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.attachSettings).not.toHaveBeenCalled(); + expect(warnLines(h).some((l) => l.includes('settings'))).toBe(false); + expect(debugLines(h).some((l) => l.includes('settings fan-out'))).toBe(true); + } + }); + + it('a throwing attach is reported and does not take the other lanes down', async () => { + declare('2'); + const h = makeHarness({ settings: 'real', settingsAttachThrows: true, automation: 'real' }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + expect(h.logger.error).toHaveBeenCalledWith( + 'MetadataClusterBridgePlugin: settings-lane attach failed', + expect.any(Error), + ); + expect(h.attachMutation).toHaveBeenCalledTimes(1); + expect(h.attachCredential).toHaveBeenCalledTimes(1); + }); + + it('kernel:shutdown detaches lane 5, and a throwing lane-4 detach does not strand it', async () => { + declare('2'); + const h = makeHarness({ settings: 'real', automation: 'real' }); + h.detachCredential.mockImplementation(() => { + throw new Error('credential detach exploded'); + }); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + await h.fire('kernel:shutdown'); + expect(h.detachSettings).toHaveBeenCalledTimes(1); + }); + + describe('cluster.resync', () => { + function resyncHarness() { + const h = makeHarness({ settings: 'real' }); + const resyncSettings = vi.fn(async () => {}); + Object.assign(h.ctx.getService>('settings'), { + resyncSettingsChangePubSub: resyncSettings, + }); + const liveness = new ClusterDriverLiveness({ driver: 'redis', nodeId: 'node-a', logger: { warn: vi.fn(), info: vi.fn() } }); + offerClusterDriverLiveness(h.ctx.getService('cluster'), liveness); + const outage = async () => { + liveness.reportUp('command'); + liveness.reportDown('command', new Error('ECONNREFUSED')); + liveness.reportUp('command'); + await new Promise((r) => setTimeout(r, 0)); + }; + return { ...h, outage, resyncSettings }; + } + + it('the settings lane re-reads once per recovered outage', async () => { + declare('2'); + const h = resyncHarness(); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + await h.outage(); + expect(h.resyncSettings).toHaveBeenCalledTimes(1); + expect(infoLines(h).some((l) => l.includes('resynced settings.changed'))).toBe(true); + }); + + it('CONTROL — undeclared, the lane never attached, so a reconnect calls nothing', async () => { + declare(''); + const h = resyncHarness(); + await new MetadataClusterBridgePlugin().init(h.ctx); + await h.fire('kernel:ready'); + await h.fire('kernel:bootstrapped'); + await h.outage(); + expect(h.resyncSettings).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.ts b/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.ts index 54dab578bd1..0830ffffd50 100644 --- a/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.ts +++ b/packages/services/service-cluster/src/metadata-cluster-bridge-plugin.ts @@ -3,6 +3,7 @@ import type { Plugin, PluginContext } from '@objectstack/core'; import type { IClusterService } from '@objectstack/spec/contracts'; import { isInProcessClusterDriver } from './split-brain-guard.js'; +import { declaresMultiReplicaOnRedis } from './multi-replica.js'; import { onClusterResync, type ClusterResyncEvent } from './cluster-resync.js'; /** @@ -34,8 +35,10 @@ function resyncSeamOf(owner: unknown, method: string): (() => unknown) | undefin * state-owner packages only need the `IPubSub` interface, which lives in * `@objectstack/spec/contracts`. * - * FOUR lanes, late-bound independently at `kernel:ready`, because the state - * that goes stale lives in four different owners (#13331, #13805, #27428): + * FIVE lanes, late-bound independently (lanes 1 to 4 at `kernel:ready`, + * lane 5 at `kernel:bootstrapped`), because the state + * that goes stale lives in five different owners (#13331, #13805, #27428, + * #31597): * * 1. **Metadata service** (`attachClusterPubSub()` — `metadata.changed`): * replays watch events into peer `MetadataManager` caches @@ -72,6 +75,17 @@ function resyncSeamOf(owner: unknown, method: string): (() => unknown) | undefin * credential took effect on the replica that took the request, and an * instance its upstream had refused stayed held on every other replica * until a metadata reload or a restart. + * 5. **Settings service** (`attachSettingsChangePubSub()` — + * `settings.changed`): fans a settings write out to peers, which emit + * their own local `settings:changed` so every subscriber (auth posture, + * password / session / MFA policy, organization access policy, mail, SMS, + * storage, the AI provider) rebuilds from its OWN read of the shared + * settings store. The message is an address, never a value. Without it + * only the replica that took the write rebuilt, and every peer kept the + * old configuration, security posture included, until restart. Unlike + * lanes 1 to 4 it attaches only where the deployment DECLARES several + * replicas over the Redis driver (`declaresMultiReplicaOnRedis`, cloud#3814 + * R3), so a single node never sees it. * * Activates each lane only when the cluster service and that lane's state * owner are present and expose the seam. Late binding is achieved via the @@ -84,7 +98,9 @@ function resyncSeamOf(owner: unknown, method: string): (() => unknown) | undefin * `datasource.mutated` — payload shape defined by * `ClusterDatasourceMutationPayload` in `@objectstack/service-datasource`; * `connector-credential.mutated` — payload shape defined by - * `ClusterConnectorCredentialMutationPayload` in `@objectstack/service-automation`. + * `ClusterConnectorCredentialMutationPayload` in `@objectstack/service-automation`; + * `settings.changed` — payload shape defined by + * `ClusterSettingsChangePayload` in `@objectstack/service-settings`. * * ## Resync after an outage * @@ -97,7 +113,8 @@ function resyncSeamOf(owner: unknown, method: string): (() => unknown) | undefin * * 1. metadata service — `resyncClusterPubSub()`; * 3. datasource admin service — `resyncDatasourceMutationPubSub()`; - * 4. automation service — `resyncConnectorCredentialPubSub()`. + * 4. automation service — `resyncConnectorCredentialPubSub()`; + * 5. settings service — `resyncSettingsChangePubSub()`. * * Lane 2 has no resync seam yet: its convergence is a per-item registry * write-through, and a full re-convergence of the registry is its own change. @@ -115,6 +132,7 @@ export class MetadataClusterBridgePlugin implements Plugin { private detachMutation?: () => void; private detachDatasource?: () => void; private detachConnectorCredential?: () => void; + private detachSettings?: () => void; private detachResync?: () => void; private readonly laneResyncs: LaneResync[] = []; @@ -133,9 +151,22 @@ export class MetadataClusterBridgePlugin implements Plugin { this.attachProtocolLane(ctx, cluster); this.attachDatasourceLane(ctx, cluster); this.attachConnectorCredentialLane(ctx, cluster); - if (this.laneResyncs.length > 0) { - this.detachResync = onClusterResync(cluster, (event) => this.resyncLanes(ctx, event)); + this.subscribeResync(ctx, cluster); + }); + + // Lane 5 binds one phase later: the settings service binds its engine + // from its own `kernel:ready` hook, and a peer's change delivered + // before that bind would have every subscriber read the in-memory + // defaults (`check:settings-bind-window`). + ctx.hook('kernel:bootstrapped', async () => { + let cluster: IClusterService | undefined; + try { + cluster = ctx.getService('cluster'); + } catch { + return; } + this.attachSettingsLane(ctx, cluster); + this.subscribeResync(ctx, cluster); }); ctx.hook('kernel:shutdown', async () => { @@ -175,6 +206,15 @@ export class MetadataClusterBridgePlugin implements Plugin { ); } this.detachConnectorCredential = undefined; + try { + this.detachSettings?.(); + } catch (err) { + ctx.logger.error( + 'MetadataClusterBridgePlugin: settings-lane detach error', + err as Error, + ); + } + this.detachSettings = undefined; this.detachResync?.(); this.detachResync = undefined; this.laneResyncs.length = 0; @@ -207,6 +247,16 @@ export class MetadataClusterBridgePlugin implements Plugin { ); } + /** + * Subscribe to `cluster.resync` once, when at least one attached lane has a + * resync seam. The handler reads the lane list when the event fires, so a + * lane attached after the subscription is resynced too. + */ + private subscribeResync(ctx: PluginContext, cluster: IClusterService): void { + if (this.detachResync || this.laneResyncs.length === 0) return; + this.detachResync = onClusterResync(cluster, (event) => this.resyncLanes(ctx, event)); + } + /** Register `owner`'s resync seam `method` for `lane`, when the owner has one. */ private registerLaneResync(lane: string, owner: unknown, method: string): void { const run = resyncSeamOf(owner, method); @@ -457,4 +507,68 @@ export class MetadataClusterBridgePlugin implements Plugin { ); } } + + /** + * Lane 5 — the settings service's `settings.changed` fan-out (#31597): the + * settings store adopting the family lanes 2 to 4 established. + * + * Attached at `kernel:bootstrapped`, after the settings service has bound + * its engine at `kernel:ready`, so no peer change reaches a subscriber that + * would read the pre-bind in-memory defaults. + * + * Duck-typed exactly like lanes 1 to 4 feature-detect their seams: this + * package must not depend on `@objectstack/service-settings`. The settings + * service publishes on the write door it already owns, and a peer emits + * its own local `settings:changed`, so every subscriber re-reads the + * shared store; a received change is never published again. + * + * Guarded on the declared multi-replica switch over Redis + * ({@link declaresMultiReplicaOnRedis}, cloud#3814 R3) rather than on the + * in-process driver alone: the single-node default emits exactly what it + * emitted before, and the split-brain guard is untouched (a declaration + * over the in-process driver still refuses the boot before this runs). + */ + private attachSettingsLane(ctx: PluginContext, cluster: IClusterService): void { + let settings: unknown; + try { + settings = ctx.getService('settings'); + } catch { + ctx.logger.debug( + 'MetadataClusterBridgePlugin: no "settings" service registered, skipping settings fan-out', + ); + return; + } + + const attach = (settings as { attachSettingsChangePubSub?: unknown }) + .attachSettingsChangePubSub; + if (typeof attach !== 'function') { + ctx.logger.debug( + 'MetadataClusterBridgePlugin: settings service does not expose attachSettingsChangePubSub(), skipping settings fan-out', + ); + return; + } + + if (!declaresMultiReplicaOnRedis(process.env, cluster.driver)) { + ctx.logger.debug( + `MetadataClusterBridgePlugin: no multi-replica deployment declared over the redis cluster driver (driver "${cluster.driver}"); settings fan-out skipped`, + ); + return; + } + + try { + this.detachSettings = (attach as ( + pubsub: IClusterService['pubsub'], + nodeId: string, + ) => () => void).call(settings, cluster.pubsub, cluster.nodeId); + this.registerLaneResync('settings.changed', settings, 'resyncSettingsChangePubSub'); + ctx.logger.info( + `MetadataClusterBridgePlugin: bridged settings.changed → cluster.pubsub (node=${cluster.nodeId})`, + ); + } catch (err) { + ctx.logger.error( + 'MetadataClusterBridgePlugin: settings-lane attach failed', + err as Error, + ); + } + } } diff --git a/packages/services/service-settings/package.json b/packages/services/service-settings/package.json index 10a252ba734..d085e214098 100644 --- a/packages/services/service-settings/package.json +++ b/packages/services/service-settings/package.json @@ -33,6 +33,7 @@ }, "devDependencies": { "@objectstack/objectql": "workspace:*", + "@objectstack/service-cluster": "workspace:*", "@types/node": "^26.6.5", "typescript": "^6.0.3", "vitest": "^4.1.11" diff --git a/packages/services/service-settings/src/index.ts b/packages/services/service-settings/src/index.ts index ccdbc9177de..e7537132f9a 100644 --- a/packages/services/service-settings/src/index.ts +++ b/packages/services/service-settings/src/index.ts @@ -6,6 +6,12 @@ */ export { SettingsService } from './settings-service.js'; +// The settings lane of the cluster bridge: a write on one replica reaches every +// replica's `settings:changed` subscribers (an address on the wire, never a value). +export { + SETTINGS_CHANGE_CLUSTER_CHANNEL, + type ClusterSettingsChangePayload, +} from './settings-cluster-channel.js'; export { type CryptoAdapter, NoopCryptoAdapter, diff --git a/packages/services/service-settings/src/settings-cluster-channel.ts b/packages/services/service-settings/src/settings-cluster-channel.ts new file mode 100644 index 00000000000..79b60640923 --- /dev/null +++ b/packages/services/service-settings/src/settings-cluster-channel.ts @@ -0,0 +1,48 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SpecifierScope } from '@objectstack/spec/system'; + +/** + * Cluster channel for settings writes: the settings service's adopter of the + * cluster-invalidation family `metadata.mutated` established (the fifth lane + * of `MetadataClusterBridgePlugin` in `@objectstack/service-cluster`). + * + * `settings:changed` is an in-process subscriber set. Its subscribers rebuild + * the auth posture, the password / session / MFA policy, the organization + * access policy, mail, SMS, storage and the AI provider from the settings + * store. Without this channel only the replica that took the write rebuilt; + * every peer kept the old configuration, security posture included, until it + * restarted. + * + * Published by the {@link SettingsService} that performed a write (see + * `SettingsService.attachSettingsChangePubSub`) and consumed by every peer, + * which emits its own local `settings:changed` so each subscriber re-reads the + * shared store. Distinct from the local event name on purpose: that name is + * the in-process bus, this one is the wire. + */ +export const SETTINGS_CHANGE_CLUSTER_CHANNEL = 'settings.changed'; + +/** + * Payload for {@link SETTINGS_CHANGE_CLUSTER_CHANNEL}. + * + * ⭐ A SIGNAL, never content: only the ADDRESS of the change rides the + * channel (namespace, key, scope, action, time), the same fields the local + * `settings:changed` event carries. ⛔ Never a value, a ciphertext handle or a + * secret. The shared store stays the single source of truth: a receiver's + * subscribers re-read it, so a duplicate or re-ordered delivery converges to + * the same configuration as a single one. + */ +export interface ClusterSettingsChangePayload { + /** Origin nodeId, used for loopback suppression. */ + originNode?: string; + /** Namespace whose value changed. */ + namespace: string; + /** Specifier key that changed. */ + key: string; + /** Scope of the row that was written. */ + scope: SpecifierScope; + /** `'set'` when a value was written, `'reset'` when the row was cleared. */ + action: 'set' | 'reset'; + /** ISO 8601 time the write completed on the origin node. */ + at: string; +} diff --git a/packages/services/service-settings/src/settings-cluster-lane.test.ts b/packages/services/service-settings/src/settings-cluster-lane.test.ts new file mode 100644 index 00000000000..6153e45e01e --- /dev/null +++ b/packages/services/service-settings/src/settings-cluster-lane.test.ts @@ -0,0 +1,312 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#31597] The settings lane: a settings write on one replica reaches every + * replica's `settings:changed` subscribers. + * + * `settings:changed` is an in-process subscriber set. Its subscribers rebuild + * the auth posture (plugin-auth binds `settings.subscribe('auth', …)` and + * re-reads the namespace), password / session / MFA policy, organization + * access policy, mail, SMS, storage and the AI provider. Measured on a + * round-robin deployment before this lane: replica 1 set + * `require_email_verification` and refused sign-in, replica 2 still answered + * 200 after 95 s. + * + * Topology here: two `LiteKernel` boots ("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 (what a real remote + * driver does, and what the `originNode` loopback guard exists for). The + * cluster service names the `redis` driver, and the real + * `MetadataClusterBridgePlugin` attaches the lane at `kernel:ready`. + * + * The auth-posture subscriber below has plugin-auth's binding shape: + * subscribe to the `auth` namespace, and on every change re-read + * `require_email_verification` from the settings service. + */ + +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { LiteKernel, type Plugin, type PluginContext } from '@objectstack/core'; +import { ObjectQL } from '@objectstack/objectql'; +import { SysPlatformSetting, SysSecret, SysSetting } from '@objectstack/platform-objects/system'; +import type { IClusterService, IPubSub } from '@objectstack/spec/contracts'; +import type { SettingsChangeEvent } from '@objectstack/spec/system'; +import { + ClusterDriverLiveness, + MemoryPubSub, + MetadataClusterBridgePlugin, + offerClusterDriverLiveness, +} from '@objectstack/service-cluster'; +import { SettingsService } from './settings-service.js'; +import { wrapEngineAsSettingsEngine } from './settings-service-plugin.js'; +import { authSettingsManifest } from './manifests/auth.manifest.js'; +import { SETTINGS_CHANGE_CLUSTER_CHANNEL, type ClusterSettingsChangePayload } from './settings-cluster-channel.js'; +import { makeMemoryDriver } from './__tests__/settings-door.testkit.js'; +import { LEAN_ORGANIZATION_SOURCE, withEngineRegistry } from './__tests__/settings-organization.testkit.js'; + +const OWNER_PACKAGE = 'com.objectstack.test.settings-cluster-lane'; +const ADMIN = { enforced: true, permissions: ['manage_platform_settings', 'setup.access', 'setup.write'], userId: 'usr_admin' }; + +/** A probe namespace whose value is a string we can look for on the wire. */ +const PROBE_MANIFEST = { + namespace: 'lane_probe', + label: 'Lane probe', + specifiers: [{ type: 'text', key: 'endpoint', label: 'Endpoint', scope: 'global', default: '' }], +} as any; + +/** + * The shared bus, with every publish on the settings channel recorded and an + * optional "outage" during which publishes are lost (the at-most-once bus). + */ +function makeSharedBus() { + const inner = new MemoryPubSub({ onError: () => {} }); + const published: ClusterSettingsChangePayload[] = []; + let down = false; + const bus: IPubSub = { + async publish(channel, payload, opts) { + if (channel === SETTINGS_CHANGE_CLUSTER_CHANNEL) published.push(payload as ClusterSettingsChangePayload); + if (down) return; + await inner.publish(channel, payload, opts); + }, + subscribe: (channel, handler, opts) => inner.subscribe(channel, handler, opts), + close: () => inner.close(), + }; + return { + bus, + published, + setDown(value: boolean) { + down = value; + }, + }; +} + +/** Registers a prebuilt service under `name` (the slot a real plugin fills). */ +function servicePlugin(name: string, service: unknown): Plugin { + return { + name: `test.${name}`, + version: '1.0.0', + async init(ctx: PluginContext) { + ctx.registerService(name, service); + }, + } as Plugin; +} + +async function bootReplica(nodeId: string, shared: { driver: unknown; bus: IPubSub }, driverName = 'redis') { + const engine = new ObjectQL(); + engine.registerDriver(shared.driver as any, true); + await engine.init(); + for (const o of [SysSetting, SysPlatformSetting, SysSecret]) { + engine.registry.registerObject(o as any, OWNER_PACKAGE); + } + const settings = new SettingsService({ env: {} }); + settings.bindEngine(withEngineRegistry(wrapEngineAsSettingsEngine(engine as any), engine), undefined, { + organization: LEAN_ORGANIZATION_SOURCE, + }); + settings.registerManifest(authSettingsManifest); + settings.registerManifest(PROBE_MANIFEST); + + const cluster = { + nodeId, + driver: driverName, + pubsub: shared.bus, + lock: {}, + kv: {}, + counter: {}, + close: async () => {}, + } as unknown as IClusterService; + const liveness = new ClusterDriverLiveness({ driver: driverName, nodeId, logger: { warn: () => {}, info: () => {} } }); + offerClusterDriverLiveness(cluster, liveness); + + const kernel = new LiteKernel({ logger: { level: 'error' } as never }); + kernel.use(servicePlugin('cluster', cluster)); + kernel.use(servicePlugin('settings', settings)); + kernel.use(new MetadataClusterBridgePlugin()); + await kernel.bootstrap(); + + // plugin-auth's binding shape: re-read the namespace on every change. + const posture = { requireEmailVerification: false, rebuilds: 0 }; + const events: SettingsChangeEvent[] = []; + settings.subscribe(undefined, (e) => events.push(e)); + settings.subscribe('auth', () => { + void settings.get('auth', 'require_email_verification').then((r) => { + posture.requireEmailVerification = r.value === true; + posture.rebuilds += 1; + }); + }); + /** One reconnect after an outage: the driver's local `cluster.resync`. */ + const reconnect = async () => { + liveness.reportUp('command'); + liveness.reportDown('command', new Error('ECONNREFUSED')); + liveness.reportUp('command'); + await new Promise((r) => setTimeout(r, 0)); + }; + return { kernel, settings, posture, events, reconnect }; +} + +async function bootPair(opts: { declare?: boolean; driver?: string } = {}) { + vi.stubEnv('OS_CLUSTER_REPLICAS', opts.declare === false ? '' : '2'); + vi.stubEnv('OS_EXPECT_MULTI_NODE', ''); + const { driver } = makeMemoryDriver(); + const shared = makeSharedBus(); + const a = await bootReplica('replica-a', { driver, bus: shared.bus }, opts.driver); + const b = await bootReplica('replica-b', { driver, bus: shared.bus }, opts.driver); + // Settle the boot's own announcements (the engine bind's `key: '*'`). + await new Promise((r) => setTimeout(r, 0)); + a.events.length = 0; + b.events.length = 0; + return { a, b, shared }; +} + +const kernels: LiteKernel[] = []; +afterEach(async () => { + for (const k of kernels.splice(0)) await k.shutdown(); + vi.unstubAllEnvs(); +}); +const track = (pair: T): T => { + kernels.push(pair.a.kernel, pair.b.kernel); + return pair; +}; + +describe('[#31597] declared replicas over redis: a settings write reaches every replica', () => { + it('⭐ a write on A changes B’s auth posture within one second, read from the shared store', async () => { + const { a, b } = track(await bootPair()); + expect(b.posture.requireEmailVerification).toBe(false); + + await a.settings.set('auth', 'require_email_verification', true, ADMIN); + + await vi.waitFor(() => expect(b.posture.requireEmailVerification).toBe(true), { timeout: 1000, interval: 10 }); + expect(b.events).toEqual([ + expect.objectContaining({ namespace: 'auth', key: 'require_email_verification', scope: 'global', action: 'set' }), + ]); + + // A reset travels the same way. + await a.settings.set('auth', 'require_email_verification', null, ADMIN); + await vi.waitFor(() => expect(b.posture.requireEmailVerification).toBe(false), { timeout: 1000, interval: 10 }); + expect(b.events.map((e) => e.action)).toEqual(['set', 'reset']); + }); + + it('the broadcast carries the address of the change and never its value', async () => { + const { a, b, shared } = track(await bootPair()); + const value = 'https://lane-probe.invalid/7f3a9c'; + + await a.settings.set('lane_probe', 'endpoint', value, ADMIN); + await vi.waitFor(() => expect(b.events).toHaveLength(1), { timeout: 1000, interval: 10 }); + + expect(shared.published).toHaveLength(1); + const [payload] = shared.published; + expect(Object.keys(payload).sort()).toEqual(['action', 'at', 'key', 'namespace', 'originNode', 'scope']); + expect(payload).toMatchObject({ originNode: 'replica-a', namespace: 'lane_probe', key: 'endpoint', scope: 'global', action: 'set' }); + expect(JSON.stringify(payload)).not.toContain('lane-probe.invalid'); + // B's subscribers read the value from the shared store, not from the wire. + expect((await b.settings.get('lane_probe', 'endpoint')).value).toBe(value); + }); + + it('no echo: a received change is never published again, and the writer hears its own write once', async () => { + const { a, b, shared } = track(await bootPair()); + + await a.settings.set('auth', 'require_email_verification', true, ADMIN); + await vi.waitFor(() => expect(b.posture.requireEmailVerification).toBe(true), { timeout: 1000, interval: 10 }); + await new Promise((r) => setTimeout(r, 20)); + + expect(shared.published.map((p) => p.originNode)).toEqual(['replica-a']); + expect(a.events).toHaveLength(1); + expect(b.events).toHaveLength(1); + }); + + it('cluster.resync: a change lost during an outage reaches the peer on reconnect', async () => { + const { a, b, shared } = track(await bootPair()); + + shared.setDown(true); + await a.settings.set('auth', 'require_email_verification', true, ADMIN); + await new Promise((r) => setTimeout(r, 20)); + expect(b.posture.requireEmailVerification).toBe(false); + shared.setDown(false); + + await b.reconnect(); + await vi.waitFor(() => expect(b.posture.requireEmailVerification).toBe(true), { timeout: 1000, interval: 10 }); + // The resync announces every namespace locally; nothing goes on the wire. + expect(b.events.map((e) => `${e.namespace}.${e.key}`).sort()).toEqual(['auth.*', 'lane_probe.*']); + expect(shared.published).toHaveLength(1); + }); + + it('after kernel:shutdown the replica neither publishes nor hears', async () => { + const { a, b, shared } = track(await bootPair()); + await b.kernel.shutdown(); + kernels.splice(kernels.indexOf(b.kernel), 1); + + await a.settings.set('auth', 'require_email_verification', true, ADMIN); + await new Promise((r) => setTimeout(r, 20)); + expect(b.events).toEqual([]); + + await b.settings.set('lane_probe', 'endpoint', 'x', ADMIN); + expect(shared.published.map((p) => p.originNode)).toEqual(['replica-a']); + }); +}); + +describe('[#31597] CONTROL: no declared multi-replica deployment over redis, single-node behaviour unchanged', () => { + /** What a lone service with no lane emits for the same write: today's behaviour. */ + async function todaysEvents(): Promise>> { + const { driver } = makeMemoryDriver(); + const engine = new ObjectQL(); + engine.registerDriver(driver, true); + await engine.init(); + for (const o of [SysSetting, SysPlatformSetting, SysSecret]) engine.registry.registerObject(o as any, OWNER_PACKAGE); + const lone = new SettingsService({ env: {} }); + lone.bindEngine(withEngineRegistry(wrapEngineAsSettingsEngine(engine as any), engine), undefined, { + organization: LEAN_ORGANIZATION_SOURCE, + }); + lone.registerManifest(authSettingsManifest); + const seen: SettingsChangeEvent[] = []; + lone.subscribe(undefined, (e) => seen.push(e)); + await lone.set('auth', 'require_email_verification', true, ADMIN); + return seen.map(({ at: _at, ...rest }) => rest); + } + + it('redis driver without a declaration: the writer emits exactly what it emits today, nothing crosses', async () => { + const { a, b, shared } = track(await bootPair({ declare: false })); + + await a.settings.set('auth', 'require_email_verification', true, ADMIN); + await new Promise((r) => setTimeout(r, 20)); + + expect(a.events.map(({ at: _at, ...rest }) => rest)).toEqual(await todaysEvents()); + expect(shared.published).toEqual([]); + expect(b.events).toEqual([]); + expect(b.posture.requireEmailVerification).toBe(false); + }); + + it('declared replicas over a driver other than redis: no lane', async () => { + const { a, b, shared } = track(await bootPair({ driver: 'postgres' })); + + await a.settings.set('auth', 'require_email_verification', true, ADMIN); + await new Promise((r) => setTimeout(r, 20)); + + expect(shared.published).toEqual([]); + expect(b.events).toEqual([]); + }); + + it('a reconnect on an unattached replica announces nothing', async () => { + const { b } = track(await bootPair({ declare: false })); + await b.reconnect(); + expect(b.events).toEqual([]); + }); + + it('resync on a service with no transport attached announces nothing', async () => { + const lone = new SettingsService({ env: {} }); + lone.registerManifest(authSettingsManifest); + const seen: SettingsChangeEvent[] = []; + lone.subscribe(undefined, (e) => seen.push(e)); + await lone.resyncSettingsChangePubSub(); + expect(seen).toEqual([]); + }); + + it('a malformed or own-origin message is ignored', async () => { + const { b, shared } = track(await bootPair()); + const raw = (payload: unknown) => + shared.bus.publish(SETTINGS_CHANGE_CLUSTER_CHANNEL, payload) as Promise; + await raw({ originNode: 'replica-b', namespace: 'auth', key: 'k', scope: 'global', action: 'set', at: 'x' }); + await raw({ originNode: 'replica-x', namespace: '', key: 'k', scope: 'global', action: 'set', at: 'x' }); + await raw({ originNode: 'replica-x', namespace: 'auth', key: 'k', scope: 'global', action: 'drop', at: 'x' }); + await raw(undefined); + expect(b.events).toEqual([]); + }); +}); diff --git a/packages/services/service-settings/src/settings-service.ts b/packages/services/service-settings/src/settings-service.ts index 2c3e7c69cde..9af482adf71 100644 --- a/packages/services/service-settings/src/settings-service.ts +++ b/packages/services/service-settings/src/settings-service.ts @@ -19,6 +19,11 @@ import { firstMapShapeMiss, mapMissSentence, } from './map-shape.js'; +import type { IPubSub } from '@objectstack/spec/contracts'; +import { + SETTINGS_CHANGE_CLUSTER_CHANNEL, + type ClusterSettingsChangePayload, +} from './settings-cluster-channel.js'; import { type CryptoAdapter, NoopCryptoAdapter, @@ -1017,6 +1022,12 @@ export class SettingsService { ns?: string; handler: SettingsChangeHandler; }>(); + /** The cluster transport, when a bridge attached one (the settings lane). */ + private clusterPubSub?: IPubSub; + /** This node's cluster id: stamps `originNode` for loopback suppression. */ + private clusterNodeId?: string; + /** Disposer for the cluster subscription, when attached. */ + private clusterUnsubscribe?: () => void; constructor(opts: SettingsServiceOptions = {}) { this.engine = opts.engine; @@ -1078,6 +1089,11 @@ export class SettingsService { // provider settings) can re-fetch with real DB-backed values rather // than only the in-memory defaults that were visible at // `kernel:ready` ordering before the engine was wired. + this.emitEveryNamespace(); + } + + /** One local `key: '*'` change per registered namespace: every subscriber re-reads. */ + private emitEveryNamespace(): void { for (const ns of this.registry.keys()) { this.emitChange({ namespace: ns, @@ -1329,6 +1345,119 @@ export class SettingsService { } } + // --------------------------------------------------------------------- + // Cluster lane: settings changes reach every replica + // --------------------------------------------------------------------- + + /** + * Attach a cluster pub/sub transport so this replica's settings writes fan + * out on {@link SETTINGS_CHANGE_CLUSTER_CHANNEL} and a peer's writes reach + * this replica's `settings:changed` subscribers. Called by + * `MetadataClusterBridgePlugin` in `@objectstack/service-cluster` (its fifth + * lane) once per boot at `kernel:ready`, and only where the deployment + * declares several replicas over the Redis cluster driver; a single node + * never attaches, so it emits exactly what it emitted before. Only `IPubSub` + * crosses this seam: this package takes no dependency on the cluster + * service. Idempotent on the `(pubsub, nodeId)` pair. + * + * Receipt re-emits, it never re-publishes: a peer's change is announced to + * the LOCAL subscribers only, so no replica echoes what it received and the + * bus carries one message per write. The payload is an address; every + * subscriber re-reads the shared store, which holds the value. + * + * @returns a disposer that detaches the lane. + */ + attachSettingsChangePubSub(pubsub: IPubSub, nodeId: string): () => void { + if (this.clusterPubSub === pubsub && this.clusterNodeId === nodeId) { + return () => this.detachSettingsChangePubSub(); + } + this.detachSettingsChangePubSub(); + this.clusterPubSub = pubsub; + this.clusterNodeId = nodeId; + this.clusterUnsubscribe = pubsub.subscribe( + SETTINGS_CHANGE_CLUSTER_CHANNEL, + (msg) => { + const p = msg.payload; + // Loopback guard: this node's own subscribers heard the write at the + // door that persisted it. + if (p?.originNode && p.originNode === this.clusterNodeId) return; + if (typeof p?.namespace !== 'string' || p.namespace.length === 0) return; + if (typeof p.key !== 'string' || p.key.length === 0) return; + if (p.action !== 'set' && p.action !== 'reset') return; + if (typeof p.scope !== 'string') return; + this.emitChange({ + namespace: p.namespace, + key: p.key, + scope: p.scope, + action: p.action, + at: typeof p.at === 'string' ? p.at : new Date().toISOString(), + }); + }, + ); + return () => this.detachSettingsChangePubSub(); + } + + /** Tear down the cluster wiring. Safe to call multiple times. */ + detachSettingsChangePubSub(): void { + if (this.clusterUnsubscribe) { + try { + this.clusterUnsubscribe(); + } catch { + /* idempotent */ + } + this.clusterUnsubscribe = undefined; + } + this.clusterPubSub = undefined; + this.clusterNodeId = undefined; + } + + /** + * The `cluster.resync` answer for the settings lane: the cluster driver's + * connection came back after an outage, during which any change a peer + * published was lost (the bus is at-most-once). Which namespaces changed is + * what the lost signals carried, so every registered namespace is announced + * locally (`key: '*'`, the shape the engine bind uses) and every subscriber + * re-reads the shared store. Local only, never published. A no-op until a + * transport is attached. + */ + async resyncSettingsChangePubSub(): Promise { + if (!this.clusterPubSub) return; + this.emitEveryNamespace(); + } + + /** + * The cluster half of a write: publish the change's ADDRESS to peers. + * Best-effort and fire-and-forget: a publish failure never fails the write + * it announces (the row is persisted and this replica's subscribers already + * heard it). No-op until a bridge attaches a transport. + */ + private publishSettingsChange(event: SettingsChangeEvent): void { + const pubsub = this.clusterPubSub; + if (!pubsub) return; + // Spelled field by field so nothing but the address can ride along. + const payload: ClusterSettingsChangePayload = { + originNode: this.clusterNodeId, + namespace: event.namespace, + key: event.key, + scope: event.scope, + action: event.action, + at: event.at, + }; + const warn = (err: unknown) => + this.logger?.warn?.( + `settings: publishing the change to ${event.namespace}.${event.key} to peer replicas failed (${String( + (err as { message?: unknown } | undefined)?.message ?? err, + )}); peers pick it up on their next reload or restart`, + ); + try { + void pubsub + .publish(SETTINGS_CHANGE_CLUSTER_CHANNEL, payload, { partitionKey: `settings:${event.namespace}` }) + .catch(warn); + } catch (err) { + warn(err); + } + } + // --------------------------------------------------------------------- // Manifest registry // --------------------------------------------------------------------- @@ -3141,13 +3270,15 @@ export class SettingsService { } } - this.emitChange({ + const change: SettingsChangeEvent = { namespace, key, scope, action: isNull ? 'reset' : 'set', at: new Date().toISOString(), - }); + }; + this.emitChange(change); + this.publishSettingsChange(change); } // Re-resolve so callers see the post-write effective values. diff --git a/packages/services/service-settings/vitest.config.ts b/packages/services/service-settings/vitest.config.ts index d39ab2c9e4d..4ef86a214d1 100644 --- a/packages/services/service-settings/vitest.config.ts +++ b/packages/services/service-settings/vitest.config.ts @@ -98,6 +98,12 @@ export default defineConfig({ find: /^@objectstack\/spec$/, replacement: path.resolve(__dirname, '../../spec/src/index.ts'), }, + // [#31597] The settings-lane suite boots the real cluster bridge + // (`settings-cluster-lane.test.ts`); its source, like every sibling here. + { + find: /^@objectstack\/service-cluster$/, + replacement: path.resolve(__dirname, '../service-cluster/src/index.ts'), + }, { find: /^@objectstack\/types$/, replacement: path.resolve(__dirname, '../../types/src/index.ts'), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b6e68ca817..c2c1dee32a3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3309,6 +3309,9 @@ importers: '@objectstack/objectql': specifier: workspace:* version: link:../../objectql + '@objectstack/service-cluster': + specifier: workspace:* + version: link:../service-cluster '@types/node': specifier: ^26.6.5 version: 26.6.5