Skip to content

Commit efd9752

Browse files
committed
fix(metadata-protocol): revertCommit reports a removed item whose registry heal stops
The heal answers its stop (its outer catch, keeping the error line, or a row still stored that the registry refuses); the soft-remove limb reports it in failed[] with the removed row named. Every other caller ignores it. The forwarders in protocol.ts name the heal's stop and the write-through's request type. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ
1 parent 2d23b49 commit efd9752

6 files changed

Lines changed: 190 additions & 36 deletions

‎.changeset/33563-revert-commit-honest-outcome.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Metadata-protocol: none
99

1010
`revertCommit` now reports an item whose row was written but whose next step did not land in `failed[]`, not `reverted[]`, and the answer's `success` is `false`. The steps are: the runtime registry refusing the restored object, its storage not following the restored body (the `object-storage-sync-refused` advisory stays on `advisories`), the mutation projector failing, and any step after the row write throwing. The entry names the row state ("its row was restored to the body of version N", or "its row was removed from sys_metadata") beside the step that failed, and quotes no driver text. The revert's own commit still records the row change. Before, each of these answered `success: true` with the item in `reverted[]`, against the method's own contract ("a revert that answers `success: true` is one the running process has already acted on"). `rollbackToPackageCommit` carries each such item into its own `failed[]` and answers `success: false`.
1111

12-
A write-through fault the registry helper only logs (every metadata type other than `object`) is still not seen by the revert.
12+
The same holds for a restored item of any other metadata type whose registry write-through throws, and for a removed item whose registry heal stops (see the note on reporting a non-object item's registry fault).
1313

1414
A revert is now itself revertible, as ADR-0067 D3 says. The revert's own commit records, for each row it changed, the version that row held before the revert, so reverting the revert brings that body back, and an item the revert removed is written again. An item recorded as existing before the commit but carrying no version to restore, which is how every revert commit recorded by an earlier release records the items it restored, is named in `failed[]` with nothing written. Before, it was skipped: it appeared in neither `reverted[]` nor `failed[]`. To undo such an older revert, restore each item from its own version history (`GET /api/v1/meta/:type/:name/history`, then `POST /api/v1/meta/:type/:name/rollback`).
1515

‎.changeset/33851-revert-non-object-write-through-fault.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
'@objectstack/metadata-protocol': patch
33
---
44

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

77
Clause-②: no
88
Metadata-protocol: none
99

1010
`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`.
1111

12-
This replaces, for the restore limb, the line in the note on the previous change to this door that says such a fault "is still not seen by the revert".
12+
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.
1313

14-
Save and publish do not change. They 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.
15-
16-
Not changed: on the soft-remove limb (an item the reverted commit created), a stop of the registry heal is still only logged at `error`, and the item is still reported as `removed`.
14+
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.

‎packages/metadata-protocol/src/protocol-package-commits.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ import type { RollbackMetaItemRequest } from './protocol-door-requests.js';
9494
import { historySlotOf, refusePackageSelectorOutsideSlottedTypes } from './protocol-history-slots.js';
9595
import { withRefusalAudit } from './protocol-refusal-audit.js';
9696
import type { ProtocolHost } from './protocol-host.js';
97-
import type { RegistryWriteThroughRequest } from './protocol-registry-hydration.js';
9897
import type { ImportUnmanagedPackageAnswer, InstallPackageStoredRowHook, StoredPackageRow } from './protocol-package-install.js';
9998

10099
/**
@@ -1568,7 +1567,19 @@ export class ProtocolPackageCommitsFacet {
15681567
// `object` serves no field afterwards, so it changes none.
15691568
const removedCapture = captureStoredExpressionChange(host.engine, PLURAL_TO_SINGULAR[it.type] ?? it.type, it.name);
15701569
if (removedCapture && !storedExpressions.has(removedCapture.object)) storedExpressions.set(removedCapture.object, removedCapture);
1571-
await host.restoreArtifactRegistryView(it.type, it.name, null, commitPackageId, member);
1570+
// [#33851] The heal's stop is this item's outcome too, the way
1571+
// the restore limb reports the write-through's refusal: the
1572+
// row is removed and the registry may still serve it. Only
1573+
// where a row was removed; with none, the heal is a
1574+
// self-heal of nothing this revert wrote, and stays logged.
1575+
const healStop = await host.restoreArtifactRegistryView(it.type, it.name, null, commitPackageId, member);
1576+
if (healStop && current) {
1577+
notApplied.push(
1578+
'the runtime registry was not healed after the removal, so it may still serve the removed row ('
1579+
+ `${clientFacingFailureText(healStop.error, 'the reason is in the server log')})`,
1580+
);
1581+
notAppliedCode = clientFacingFailureCode(healStop.error);
1582+
}
15721583
// [#14179] …and announce it on the ONE choke point,
15731584
// {@link emitMetadataMutation}, exactly as the sibling
15741585
// delete caller {@link deleteMetaItem} does after its own
@@ -1748,10 +1759,8 @@ export class ProtocolPackageCommitsFacet {
17481759
// [#33851] …and so is a fault of any other type's branch
17491760
// (the overlay hydration, the `object_extension`
17501761
// registration), which the write-through answers only to a
1751-
// caller that asks (`answerFaults`). The request is handed
1752-
// whole through the class's forwarder, so it is built as the
1753-
// write-through's own request type.
1754-
const writeThrough: RegistryWriteThroughRequest = {
1762+
// caller that asks (`answerFaults`).
1763+
const registryRefusal = await host.applyRegistryWriteThrough({
17551764
type: PLURAL_TO_SINGULAR[it.type] ?? it.type,
17561765
name: it.name,
17571766
item: restored.item.body,
@@ -1765,8 +1774,7 @@ export class ProtocolPackageCommitsFacet {
17651774
// org; the resolution above is what makes the comment true.
17661775
organizationId: null,
17671776
answerFaults: true,
1768-
};
1769-
const registryRefusal = await host.applyRegistryWriteThrough(writeThrough);
1777+
});
17701778
if (registryRefusal) {
17711779
notApplied.push(
17721780
'the runtime registry refused to serve the restored body ('

‎packages/metadata-protocol/src/protocol-registry-hydration.ts‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,15 @@ export class ProtocolRegistryHydrationFacet {
17331733
* naming no package answers the store's refusal, naming every holder. So it
17341734
* does for a row bound to a non-holder of the name whose pair relation names
17351735
* zero or several bases (epic ruling 6818436831, #32620).
1736+
*
1737+
* [#33851] What it answers: the walk's stop ({@link RegistryHealStop}),
1738+
* when a throw stopped it (the logged stop above) or the registry refused or
1739+
* faulted on a row still stored (the step that registers it again);
1740+
* otherwise `undefined`, a designed outcome included (a refused baseline
1741+
* read that retires the entry, a degraded read that keeps it). Only
1742+
* `revertCommit` reads it, and reports the item in `failed[]`; every other
1743+
* caller ignores it, so a delete, a publish undo and a peer's convergence
1744+
* answer what they answered before.
17361745
*/
17371746
static async restoreArtifactRegistryView(host: Pick<ProtocolHost, 'anotherPackageShips' | 'applyRegistryWriteThrough' | 'convertStoredItem' | 'engine' | 'findEnvironmentRows' | 'isArtifactBacked' | 'isUnservedSealedOverlay' | 'readItemFromMetadataService' | 'reconcileViewExpansions' | 'registryTakesStoredRows' | 'resyncStoredObjectExtensions' | 'rethrowUnlessMetadataStoreUnprovisioned'>, type: string,
17381747
name: string,
@@ -1754,7 +1763,7 @@ export class ProtocolRegistryHydrationFacet {
17541763
* rows are still stored and served, so their registry entries stay.
17551764
* No effect for a type with no members.
17561765
*/
1757-
member?: string,): Promise<void> {
1766+
member?: string,): Promise<RegistryHealStop | undefined> {
17581767
// [#6780] ADR-0005 — the plain-key entry belongs to the env-wide row,
17591768
// so only an env-wide removal may heal (or retire) it.
17601769
if (organizationId !== null && organizationId !== undefined) return;
@@ -1894,16 +1903,22 @@ export class ProtocolRegistryHydrationFacet {
18941903
}
18951904
}
18961905
}
1906+
// [#33851] A remaining row the registry does not take is the
1907+
// heal's stop too: the first refusal or fault is answered, after
1908+
// every row has been tried.
1909+
let refused: RegistryHealStop | undefined;
18971910
for (const row of remainingRows) {
1898-
await host.applyRegistryWriteThrough({
1911+
const refusal = await host.applyRegistryWriteThrough({
18991912
type: canonical,
19001913
name,
19011914
item: host.convertStoredItem(String(row.type ?? canonical), storedRowDocument(row)),
19021915
packageId: boundPackageOf(row.package_id) ?? null,
19031916
organizationId: null,
1917+
answerFaults: true,
19041918
});
1919+
refused ??= refusal;
19051920
}
1906-
return;
1921+
return refused;
19071922
}
19081923
if (healed) return;
19091924

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

20792097
/**
@@ -2480,6 +2498,17 @@ export interface ObjectRegistryRefusal {
24802498
readonly error: unknown;
24812499
}
24822500

2501+
/**
2502+
* [#33851] What {@link ProtocolRegistryHydrationFacet.restoreArtifactRegistryView}
2503+
* answers when its walk stopped (a throw, logged at `error` as before) or a row
2504+
* still stored was refused by the registry: the thrown or refused value, whole.
2505+
* The row removal is already committed; this is the fact the heal used to keep
2506+
* to its log line.
2507+
*/
2508+
export interface RegistryHealStop {
2509+
readonly error: unknown;
2510+
}
2511+
24832512
/**
24842513
* What {@link ProtocolRegistryHydrationFacet.applyRegistryWriteThrough} is
24852514
* asked to make live: the row's type, name and body, its binding and scope.

0 commit comments

Comments
 (0)