Skip to content

Commit ca23ce3

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-4jg54r
2 parents bfc1d99 + ad622d3 commit ca23ce3

22 files changed

Lines changed: 1107 additions & 46 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/service-cluster': patch
4+
---
5+
6+
fix(cluster): an object authored while the cluster store was unreachable is served by every replica once its driver reconnects, without a restart
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
The `metadata.mutated` lane (the one that makes a peer register an object authored on another replica) now has a resync seam, `ObjectStackProtocolImplementation.resyncMetadataMutationPubSub()`, and `MetadataClusterBridgePlugin` calls it on the cluster driver's local `cluster.resync` event, as it already did for the other lanes. Before, a hint lost during a store outage left every other replica answering `OBJECT_NOT_FOUND` for the object (or serving its old body, or still serving it after a delete) until restart.
12+
13+
On the event the replica reads `sys_metadata`'s active rows once (address and checksum only) and re-converges each item a lost hint could have touched — a row whose checksum moved, an item with no active row left, and an item a hint or local write named since the last convergence — through the same applier a delivered hint runs, from its own re-read. Nothing travels on the wire. A failed read is never a delete: the registry is left as it is and the next resync re-reads. The in-process `memory` driver never emits the event, so a single node is unchanged.
14+
15+
New public surface: the method above and its result type `MetadataMutationResyncReport`, exported from `@objectstack/metadata-protocol`. Nothing is removed or made required.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth): the forced-reset flag and its clear are audited under the person who caused them
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
An administrator's forced password reset (`POST /api/v1/auth/admin/set-user-password`) and the user's own password change (`POST /api/v1/auth/change-password`) each write `sys_user.must_change_password`, and plugin-audit recorded both writes with a null `actor` and `user_id`, as if the system had made them. Both writes now carry their caller on the attribution seam every identity write already uses (`authSystemWriteContext`), so the `sys_audit_log` row for the set names the administrator (and, from an impersonation session, the administrator at the keyboard as `impersonated_by`), and the row for the clear names the user.
11+
12+
- **Unchanged.** Both writes still run as the system: what they may write, the values they write and both doors' answers are the same. The sign-in stamp row is unchanged. A password change is credited only to the account's own holder: a request whose session names nobody (the emailed-link reset) or another account leaves the row the system's, as before.
13+
- **Also attributed.** The administrator-created user's `must_change_password` set (`POST /api/v1/auth/admin/create-user`) goes through the same write and is now credited to the creating administrator.

‎content/docs/kernel/cluster.mdx‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,24 @@ channel's own doc comment:
375375
event is never published to peers; each replica emits its own when its own
376376
connection returns. `MetadataClusterBridgePlugin` re-reads every attached
377377
lane on it: lane 1 drops the metadata list caches
378-
(`MetadataManager.resyncClusterPubSub()`), lane 3 re-converges every stored
379-
datasource and every held pool
380-
(`DatasourceAdminService.resyncDatasourceMutationPubSub()`), and lane 4
378+
(`MetadataManager.resyncClusterPubSub()`), lane 2 re-converges the object
379+
registry (`ObjectStackProtocolImplementation.resyncMetadataMutationPubSub()`),
380+
lane 3 re-converges every stored datasource and every held pool
381+
(`DatasourceAdminService.resyncDatasourceMutationPubSub()`), lane 4
381382
runs the connector reconcile
382383
(`AutomationEngine.resyncConnectorCredentialPubSub()`), and lane 5
383384
announces every settings namespace locally so each subscriber re-reads it
384385
(`SettingsService.resyncSettingsChangePubSub()`).
385386
`AuthzClusterBridgePlugin` advances the engine's write epoch, which retires
386-
cached grants. **Lane 2 has no resync yet**: it converges per item on the
387-
signals that are delivered, and fully at boot. A cache of your own
387+
cached grants. Lane 2 reads `sys_metadata`'s active rows once (address and
388+
checksum, never a body) and re-converges each item a lost signal could have
389+
touched: a row whose checksum moved since the replica last converged on it,
390+
an item it converged on that has no active row now, and an item a signal or
391+
a local write named since. Each goes through the same applier a delivered
392+
signal runs, from the replica's own re-read, so a row that is gone takes the
393+
delete's heal walk. A read that fails is never a delete: when the row read
394+
fails nothing changes, and an item whose own re-read fails is kept as the
395+
replica holds it, logged once, and re-read on the next resync. A cache of your own
388396
subscribes with `onClusterResync(cluster, handler)` from
389397
`@objectstack/service-cluster`. On the `memory` driver that subscription is
390398
a no-op, because nothing there can lose a connection.

‎docs/audits/2026-09-self-test-shape-census.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ tree against the ~30 s a per-PR gate can spend.
373373
| `scripts/pm/check-label-desc-cap.mjs` | ROSTER | HELD | ✗ check-label-desc-cap self-test: selfTest() returned without reaching i |
374374
| `scripts/pm/check-skill-id-lint.mjs` | ROSTER | HELD | ✗ check-skill-id-lint self-test: selfTest() returned without reaching it |
375375
| `scripts/pm/check-skill-line-ratchet.mjs` | ROSTER | HELD | ✗ check-skill-line-ratchet self-test: selfTest() returned without reachi |
376-
| `scripts/pm/ci-failure.mjs` | ROSTER | HELD | ✗ ci-failure self-test: selfTest() returned without reaching its verdict |
376+
| `scripts/pm/ci-failure.mjs` | ROSTER | HELD | ✗ ci-failure self-test: selfTest() returned without reaching its verdict (note: tool deleted in #31752) |
377377
| `scripts/pm/dispatch-gates.mjs` | NONE | HELD | ✗ dispatch-gates self-test: selfTest() returned without reaching its ver |
378378
| `scripts/pm/git-history.mjs` | ROSTER | HELD | ✗ git-history self-test: selfTest() returned without reaching its verdic |
379379
| `scripts/pm/release-rehearsal-clone.mjs` | ROSTER | HELD | ✗ release-rehearsal-clone self-test: selfTest() returned without reachin |

‎packages/metadata-protocol/src/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ export type { MetadataMutationEvent, MetadataMutationProjector, MutationProjecti
164164
// never trusted content (receipt re-reads `sys_metadata` locally).
165165
export { METADATA_MUTATION_CLUSTER_CHANNEL } from './protocol.js';
166166
export type { ClusterMetadataMutationPayload } from './protocol.js';
167+
// [#31722] What the lane's resync seam (`resyncMetadataMutationPubSub()`)
168+
// reports after a cluster outage.
169+
export type { MetadataMutationResyncReport } from './protocol.js';
167170
// [#10219] The per-item publish notification the host bridges to the
168171
// kernel-wide `metadata:reloaded` announce. Exported for the same reason its
169172
// mutation sibling is: the subscriber lives in another package.

‎packages/metadata-protocol/src/protocol-class-head.ts‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* `registerStoredObjectExtension`, `resyncStoredObjectExtensions`,
1212
* `onMetadataMutation`, `emitMetadataMutation`, `attachMetadataMutationPubSub`,
1313
* `detachMetadataMutationPubSub`, `applyRemoteMetadataMutation`,
14+
* `resyncMetadataMutationPubSub` (#31722, written here beside its lane),
1415
* `onMetaItemPublished`, `getOverlayRepo` moved out of `protocol.ts` whole by
1516
* `scripts/codemod-split-protocol.mjs`; `registerUninstallGuard` (#31232) was
1617
* written here in the same shape, beside `registerUninstallCleanup`.
@@ -56,6 +57,8 @@ import type {
5657
UninstallGuard,
5758
} from './protocol-package-lifecycle-types.js';
5859
import { METADATA_MUTATION_CLUSTER_CHANNEL } from './protocol-mutation-events.js';
60+
import { MetadataMutationResyncLedger, RESYNC_ROW_FIELDS } from './protocol-mutation-resync.js';
61+
import type { MetadataMutationResyncReport } from './protocol-mutation-resync.js';
5962
import type {
6063
ClusterMetadataMutationPayload,
6164
MetaItemPublishedEvent,
@@ -323,19 +326,34 @@ export class ProtocolClassHeadFacet {
323326
* surface hand-announcing. Local listeners first, then the bus, matching
324327
* `MetadataManager.notifyWatchers`' order.
325328
*/
326-
static emitMetadataMutation(host: Pick<ProtocolHost, 'notifyMutationListenersLocal' | 'publishMetadataMutation'>, evt: MetadataMutationEvent): void {
329+
static emitMetadataMutation(host: Pick<ProtocolHost, 'clusterResync' | 'notifyMutationListenersLocal' | 'publishMetadataMutation'>, evt: MetadataMutationEvent): void {
330+
// [#31722] A local write moves what this replica's registry holds for
331+
// the item, so the lane's resync re-reads it rather than trust the
332+
// row's checksum (a later revert can bring an earlier one back).
333+
if (evt.state !== 'draft') host.clusterResync?.touch(evt);
327334
host.notifyMutationListenersLocal(evt);
328335
host.publishMetadataMutation(evt);
329336
}
330337

331338
/** The body of `ObjectStackProtocolImplementation#attachMetadataMutationPubSub`; the method's docblock there is its contract. */
332-
static attachMetadataMutationPubSub(host: Pick<ProtocolHost, 'applyRemoteMetadataMutation' | 'clusterNodeId' | 'clusterPubSub' | 'clusterUnsubscribe' | 'detachMetadataMutationPubSub'>, pubsub: IPubSub, nodeId: string): () => void {
339+
static attachMetadataMutationPubSub(host: Pick<ProtocolHost, 'applyRemoteMetadataMutation' | 'clusterNodeId' | 'clusterPubSub' | 'clusterResync' | 'clusterUnsubscribe' | 'detachMetadataMutationPubSub' | 'findEnvironmentRows'>, pubsub: IPubSub, nodeId: string): () => void {
333340
if (host.clusterPubSub === pubsub && host.clusterNodeId === nodeId) {
334341
return () => host.detachMetadataMutationPubSub();
335342
}
336343
host.detachMetadataMutationPubSub();
337344
host.clusterPubSub = pubsub;
338345
host.clusterNodeId = nodeId;
346+
// [#31722] The resync baseline: which stored row each registry entry
347+
// was converged on, taken by one read now (see
348+
// `protocol-mutation-resync.ts`).
349+
const ledger = new MetadataMutationResyncLedger();
350+
host.clusterResync = ledger;
351+
ledger.seed(() => host.findEnvironmentRows('sys_metadata', {
352+
where: { state: 'active' },
353+
fields: [...RESYNC_ROW_FIELDS],
354+
// Platform plumbing: no caller to authorize, as the repository's own reads.
355+
context: { isSystem: true },
356+
}));
339357
host.clusterUnsubscribe = pubsub.subscribe<ClusterMetadataMutationPayload>(
340358
METADATA_MUTATION_CLUSTER_CHANNEL,
341359
(msg) => {
@@ -350,6 +368,7 @@ export class ProtocolClassHeadFacet {
350368
// `applyRegistryWriteThrough`'s `mode === 'publish'` gate),
351369
// and this guard keeps a peer honest about the same rule.
352370
if (p.event.state === 'draft') return;
371+
host.clusterResync?.touch(p.event);
353372
void host.applyRemoteMetadataMutation(p.event).catch((err) => {
354373
console.warn(
355374
`[Protocol] cluster metadata-mutation apply failed for `
@@ -365,13 +384,29 @@ export class ProtocolClassHeadFacet {
365384
}
366385

367386
/** The body of `ObjectStackProtocolImplementation#detachMetadataMutationPubSub`; the method's docblock there is its contract. */
368-
static detachMetadataMutationPubSub(host: Pick<ProtocolHost, 'clusterNodeId' | 'clusterPubSub' | 'clusterUnsubscribe'>): void {
387+
static detachMetadataMutationPubSub(host: Pick<ProtocolHost, 'clusterNodeId' | 'clusterPubSub' | 'clusterResync' | 'clusterUnsubscribe'>): void {
369388
if (host.clusterUnsubscribe) {
370389
try { host.clusterUnsubscribe(); } catch { /* idempotent */ }
371390
host.clusterUnsubscribe = undefined;
372391
}
373392
host.clusterPubSub = undefined;
374393
host.clusterNodeId = undefined;
394+
host.clusterResync = undefined;
395+
}
396+
397+
/** The body of `ObjectStackProtocolImplementation#resyncMetadataMutationPubSub`; the method's docblock there is its contract. */
398+
static async resyncMetadataMutationPubSub(host: Pick<ProtocolHost, 'applyRemoteMetadataMutation' | 'clusterPubSub' | 'clusterResync' | 'findEnvironmentRows'>): Promise<MetadataMutationResyncReport | undefined> {
399+
// No transport, no lane: a single node never missed a hint.
400+
const ledger = host.clusterResync;
401+
if (!host.clusterPubSub || !ledger) return undefined;
402+
return ledger.resync({
403+
readActiveRows: () => host.findEnvironmentRows('sys_metadata', {
404+
where: { state: 'active' },
405+
fields: [...RESYNC_ROW_FIELDS],
406+
context: { isSystem: true },
407+
}),
408+
converge: (evt) => host.applyRemoteMetadataMutation(evt),
409+
});
375410
}
376411

377412
/**

‎packages/metadata-protocol/src/protocol-host.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface ProtocolHost {
8383
readonly classifyObjectContribution: ObjectStackProtocolImplementation['classifyObjectContribution'];
8484
clusterNodeId: ObjectStackProtocolImplementation['clusterNodeId'];
8585
clusterPubSub: ObjectStackProtocolImplementation['clusterPubSub'];
86+
clusterResync: ObjectStackProtocolImplementation['clusterResync'];
8687
clusterUnsubscribe: ObjectStackProtocolImplementation['clusterUnsubscribe'];
8788
readonly codeOnlyCreateError: (typeof ObjectStackProtocolImplementation)['codeOnlyCreateError'];
8889
readonly codeOnlyOverrideError: (typeof ObjectStackProtocolImplementation)['codeOnlyOverrideError'];

0 commit comments

Comments
 (0)