Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/33851-revert-non-object-write-through-fault.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol): `revertCommit` reports an item of any type whose registry write-through or heal faults

Clause-②: no
Metadata-protocol: none

`revertCommit` now puts a restored `view`, `permission`, `object_extension` or other non-object item into `failed[]` when the runtime registry write-through for its restored body throws, and the answer's `success` is `false`. The entry names the row state ("its row was restored to the body of version N") beside the registry's reason, and carries the reason's `code` where it declares one, the same way a refused `object` has been reported since the previous change to this door. Before, the write-through's non-object branches (the overlay hydration, and the `object_extension` registration) only logged the fault at `warn`, so such a revert answered `success: true` with the item in `reverted[]`, while the process kept serving the body the revert replaced. `rollbackToPackageCommit` carries each such item into its own `failed[]` and answers `success: false`.

A removed item is reported the same way. When the revert soft-removes an item the reverted commit created and the registry heal after the removal stops (a registry throw, or the registry refusing a row of the item still stored under another package), the item goes into `failed[]` naming "its row was removed from sys_metadata" and that the registry may still serve the removed row, with the reason and its `code`. Before, the heal's stop was only an `error` line in the server log, and the item answered `removed`. The `error` line is unchanged.

This supersedes the sentence of the note on the previous change to this door that says a write-through fault of every type other than `object` "is still not seen by the revert": after this change, the revert sees it, and a stopped heal too.

Save, publish and delete do not change. Save and publish do not ask the write-through for these faults: under the same fault, `saveMetaItem` and `publishMetaItem` of a non-object item still answer success with no advisory, and the fault is still the same `warn` line in the server log. `deleteMetaItem`, a publish's undo and a peer's convergence ignore the heal's answer, so a stopped heal still answers what it answered before there, with the same `error` line.
19 changes: 18 additions & 1 deletion packages/metadata-protocol/src/protocol-package-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,19 @@ export class ProtocolPackageCommitsFacet {
// `object` serves no field afterwards, so it changes none.
const removedCapture = captureStoredExpressionChange(host.engine, PLURAL_TO_SINGULAR[it.type] ?? it.type, it.name);
if (removedCapture && !storedExpressions.has(removedCapture.object)) storedExpressions.set(removedCapture.object, removedCapture);
await host.restoreArtifactRegistryView(it.type, it.name, null, commitPackageId, member);
// [#33851] The heal's stop is this item's outcome too, the way
// the restore limb reports the write-through's refusal: the
// row is removed and the registry may still serve it. Only
// where a row was removed; with none, the heal is a
// self-heal of nothing this revert wrote, and stays logged.
const healStop = await host.restoreArtifactRegistryView(it.type, it.name, null, commitPackageId, member);
if (healStop && current) {
notApplied.push(
'the runtime registry was not healed after the removal, so it may still serve the removed row ('
+ `${clientFacingFailureText(healStop.error, 'the reason is in the server log')})`,
);
notAppliedCode = clientFacingFailureCode(healStop.error);
}
// [#14179] …and announce it on the ONE choke point,
// {@link emitMetadataMutation}, exactly as the sibling
// delete caller {@link deleteMetaItem} does after its own
Expand Down Expand Up @@ -1744,6 +1756,10 @@ export class ProtocolPackageCommitsFacet {
// [#33563] The registry's refusal of the restored object is
// this item's outcome, not a line on stderr: the row holds
// the pre-commit body and the registry does not serve it.
// [#33851] …and so is a fault of any other type's branch
// (the overlay hydration, the `object_extension`
// registration), which the write-through answers only to a
// caller that asks (`answerFaults`).
const registryRefusal = await host.applyRegistryWriteThrough({
type: PLURAL_TO_SINGULAR[it.type] ?? it.type,
name: it.name,
Expand All @@ -1757,6 +1773,7 @@ export class ProtocolPackageCommitsFacet {
// said "the row's OWN scope" while passing the REQUEST's
// org; the resolution above is what makes the comment true.
organizationId: null,
answerFaults: true,
});
if (registryRefusal) {
notApplied.push(
Expand Down
99 changes: 82 additions & 17 deletions packages/metadata-protocol/src/protocol-registry-hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,21 +1458,14 @@ export class ProtocolRegistryHydrationFacet {
* The orphan adoption ({@link reassignOrphanedMetadata}) calls it for each
* view row it rebinds, with `reboundFrom`, and [#23646] for each object
* row, once {@link releaseAdoptedObjectOwner} has handed it the name.
*
* [#33851] What it answers: the registry's refusal of an object (the
* object branch, #33005), and nothing else unless the caller asks
* ({@link RegistryWriteThroughRequest.answerFaults}). A non-object branch
* that throws logs the fault at `warn` and, for a caller that asked,
* answers it in the same shape.
*/
static async applyRegistryWriteThrough(host: Pick<ProtocolHost, 'applyObjectRegistryMutation' | 'hydrateOverlayIntoRegistry' | 'registerStoredObjectExtension' | 'registryTakesStoredRows'>, request: {
type: string;
name: string;
item?: any;
packageId?: string | null;
/** The row's org scope — `null` for an env-wide row. [#6602] */
organizationId: string | null;
/**
* [#23198] The binding the write moved the row from, when it moved it
* (an orphan adoption): `null` for the package-less row. See
* {@link HydrationOptions}.
*/
reboundFrom?: { readonly packageId: string | null };
}): Promise<ObjectRegistryRefusal | undefined> {
static async applyRegistryWriteThrough(host: Pick<ProtocolHost, 'applyObjectRegistryMutation' | 'hydrateOverlayIntoRegistry' | 'registerStoredObjectExtension' | 'registryTakesStoredRows'>, request: RegistryWriteThroughRequest): Promise<ObjectRegistryRefusal | undefined> {
// [#8862] The `|| request.type === 'objects'` limb is GONE — this
// branch admitted the plural that {@link applyObjectRegistryMutation}
// then consumed. All four call sites of this method fold at their
Expand Down Expand Up @@ -1527,6 +1520,8 @@ export class ProtocolRegistryHydrationFacet {
console.warn(
`[Protocol] registry write-through failed for ${request.type}/${request.name}: ${err?.message ?? err}`,
);
// [#33851] …and answered, to a caller that asked.
if (request.answerFaults === true) return { error: err };
}
return undefined;
}
Expand All @@ -1546,6 +1541,10 @@ export class ProtocolRegistryHydrationFacet {
console.warn(
`[Protocol] registry write-through failed for ${request.type}/${request.name}: ${err?.message ?? err}`,
);
// [#33851] …and answered, to a caller that asked: the write is
// still not failed here, the caller decides what the fault means
// for its own answer.
if (request.answerFaults === true) return { error: err };
}
return undefined;
}
Expand Down Expand Up @@ -1734,6 +1733,15 @@ export class ProtocolRegistryHydrationFacet {
* naming no package answers the store's refusal, naming every holder. So it
* does for a row bound to a non-holder of the name whose pair relation names
* zero or several bases (epic ruling 6818436831, #32620).
*
* [#33851] What it answers: the walk's stop ({@link RegistryHealStop}),
* when a throw stopped it (the logged stop above) or the registry refused or
* faulted on a row still stored (the step that registers it again);
* otherwise `undefined`, a designed outcome included (a refused baseline
* read that retires the entry, a degraded read that keeps it). Only
* `revertCommit` reads it, and reports the item in `failed[]`; every other
* caller ignores it, so a delete, a publish undo and a peer's convergence
* answer what they answered before.
*/
static async restoreArtifactRegistryView(host: Pick<ProtocolHost, 'anotherPackageShips' | 'applyRegistryWriteThrough' | 'convertStoredItem' | 'engine' | 'findEnvironmentRows' | 'isArtifactBacked' | 'isUnservedSealedOverlay' | 'readItemFromMetadataService' | 'reconcileViewExpansions' | 'registryTakesStoredRows' | 'resyncStoredObjectExtensions' | 'rethrowUnlessMetadataStoreUnprovisioned'>, type: string,
name: string,
Expand All @@ -1755,7 +1763,7 @@ export class ProtocolRegistryHydrationFacet {
* rows are still stored and served, so their registry entries stay.
* No effect for a type with no members.
*/
member?: string,): Promise<void> {
member?: string,): Promise<RegistryHealStop | undefined> {
// [#6780] ADR-0005 — the plain-key entry belongs to the env-wide row,
// so only an env-wide removal may heal (or retire) it.
if (organizationId !== null && organizationId !== undefined) return;
Expand Down Expand Up @@ -1895,16 +1903,22 @@ export class ProtocolRegistryHydrationFacet {
}
}
}
// [#33851] A remaining row the registry does not take is the
// heal's stop too: the first refusal or fault is answered, after
// every row has been tried.
let refused: RegistryHealStop | undefined;
for (const row of remainingRows) {
await host.applyRegistryWriteThrough({
const refusal = await host.applyRegistryWriteThrough({
type: canonical,
name,
item: host.convertStoredItem(String(row.type ?? canonical), storedRowDocument(row)),
packageId: boundPackageOf(row.package_id) ?? null,
organizationId: null,
answerFaults: true,
});
refused ??= refusal;
}
return;
return refused;
}
if (healed) return;

Expand Down Expand Up @@ -2074,7 +2088,10 @@ export class ProtocolRegistryHydrationFacet {
// [#32366] Best-effort, never silent: the delete has committed and
// is not failed here, and what stopped the walk is said once.
console.error(registryHealStoppedMessage(type, name, error));
// [#33851] …and answered: `revertCommit` reports it per item.
return { error };
}
return undefined;
}

/**
Expand Down Expand Up @@ -2473,11 +2490,59 @@ export function objectStorageSyncRefusedNotice(name: string, err: unknown): Runt
* answers when the registry refused the object it was asked to register: the
* thrown value, whole. The row is already persisted; this is the one fact the
* write-through used to keep to a `warn` line.
*
* [#33851] The write-through answers a non-object branch's fault in this
* shape too, to a caller that asked ({@link RegistryWriteThroughRequest.answerFaults}).
*/
export interface ObjectRegistryRefusal {
readonly error: unknown;
}

/**
* [#33851] What {@link ProtocolRegistryHydrationFacet.restoreArtifactRegistryView}
* answers when its walk stopped (a throw, logged at `error` as before) or a row
* still stored was refused by the registry: the thrown or refused value, whole.
* The row removal is already committed; this is the fact the heal used to keep
* to its log line.
*/
export interface RegistryHealStop {
readonly error: unknown;
}

/**
* What {@link ProtocolRegistryHydrationFacet.applyRegistryWriteThrough} is
* asked to make live: the row's type, name and body, its binding and scope.
*/
export interface RegistryWriteThroughRequest {
type: string;
name: string;
item?: any;
packageId?: string | null;
/** The row's org scope — `null` for an env-wide row. [#6602] */
organizationId: string | null;
/**
* [#23198] The binding the write moved the row from, when it moved it
* (an orphan adoption): `null` for the package-less row. See
* {@link HydrationOptions}.
*/
reboundFrom?: { readonly packageId: string | null };
/**
* [#33851] `true`: a non-object branch whose registration throws (the
* `object_extension` registration, the overlay hydration) answers the
* fault as the object branch answers the registry's refusal, beside the
* `warn` line it logs. `revertCommit` asks, so a revert whose restored
* body the registry does not serve answers the item in `failed[]`
* (ADR-0067 D3, the method's docblock: a revert that answers success is
* one the running process has acted on).
*
* Left unset, the fault is only logged and the answer is `undefined`, as
* before. The save and publish doors leave it unset: they report a
* returned refusal as an object's (`object-registry-refused`), and their
* answers for every other type do not change.
*/
answerFaults?: boolean;
}

/**
* [#33005] The rule id of the advisory a publish answers with when the runtime
* registry refused an object the publish made live. Stable across releases,
Expand Down
Loading
Loading