Skip to content

Commit 0bbb211

Browse files
fix(metadata-protocol): revertCommit reports a restored non-object item whose registry write-through faults (#33979)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbNTugWasvhTMrtCZiFGrZYK)_ Fixes #33851 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:撤销提交(revertCommit)现在对所有类型如实上报两类故障。第一类是恢复视图、权限、对象扩展等条目时,写入运行时注册表出错;这时该条目列入 failed[],写明「行已恢复到版本 N」。第二类是撤销删除条目后注册表修复(heal)中途停止;这时写明「行已从 sys_metadata 移除,注册表可能仍在提供被删的行」。两类都带出错原因和 code,success 为 false,和对象条目的处理一致。 - 为什么改:以前这些故障只记日志,撤销照样报 success:true,但进程实际还在使用旧内容,违反 revertCommit 自己的契约「success 即进程已生效」(ADR-0067 D3)。 - 风险与回滚:只有 revertCommit 读这两个新返回值。保存、发布、删除等其他调用方都忽略它们,同样的故障下仍答成功,日志也不变(有对照测试,另有消融证明对照测试能变红)。回滚即 revert 本 PR。 - 先看:`protocol-registry-hydration.ts` 中 `applyRegistryWriteThrough` 的两个 catch 和 `restoreArtifactRegistryView` 的外层 catch、剩余行循环;`protocol-package-commits.ts` 的 revertCommit 两个分支;`protocol.ts` 中两个转发方法的类型。 - 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol.revert-commit-honest-outcome.test.ts`,预期 31 个用例全绿(§3 共 12 个,§4 共 9 个)。 - 需要你做的:无,席位落地。#33563 那条变更说明里的一句旧话,在单独的纯文本 PR 中更正。 ## What changes `applyRegistryWriteThrough` has three branches. The `object` branch has answered the registry's refusal since #33805. The two non-object branches caught their faults and logged them at `warn`. The first is the overlay hydration, which every type except `object` and `object_extension` takes. The second is the `object_extension` registration. The registry heal that a removal runs (`restoreArtifactRegistryView`) logged its stop at `error` and returned nothing. - `protocol-registry-hydration.ts`, write-through. The request has its own exported type, `RegistryWriteThroughRequest`, with one new optional field, `answerFaults`. When it is `true`, a non-object branch that throws still logs the same `warn` line, and then returns the fault in the `ObjectRegistryRefusal` shape (`{ error }`). When it is unset, the answer is `undefined`, as before. - `protocol-registry-hydration.ts`, heal. `restoreArtifactRegistryView` now returns a `RegistryHealStop` (`{ error }`) in two cases. The first is when its outer catch stopped the walk; the `error` line it logs is unchanged. The second is when a row still stored under another package, which the heal registers again (with `answerFaults: true`), is refused or faults; every remaining row is still tried. Otherwise it returns `undefined`, and that includes the designed outcomes: a refused baseline read that retires the entry, and a degraded read that keeps it. - `protocol-package-commits.ts`, `revertCommit`. The restore limb sets `answerFaults: true`. The soft-remove limb reads the heal's stop, but only where a row was actually removed; with no row removed, the heal is a self-heal and stays logged. Both feed the existing `notApplied` / `settle` path, so the item lands in `failed[]` with the row state, the reason and its `code`. The revert's own commit still records the row change. `rollbackToPackageCommit` carries the item through its existing per-item channel. - `protocol.ts`, two private forwarders. The `restoreArtifactRegistryView` forwarder now returns `Promise` of `RegistryHealStop | undefined` (`ProtocolHost` derives its type from it). The `applyRegistryWriteThrough` forwarder's parameter is now `RegistryWriteThroughRequest`, in place of its inline copy. The `revertCommit` docblock sentence that said a non-object write-through fault "is not seen here" now says that every type, and a stopped heal, is reported. The `.d.ts` carries that docblock, so this change takes a `patch` changeset. - Every other caller ignores the new answers. Save and publish (`protocol-save.ts`, `protocol-history-and-publish.ts`) do not set `answerFaults`. They would report any returned refusal as an object's (`object-registry-refused`), which ablation A4 shows. The delete door, a publish's undo and a peer's convergence `await` the heal and discard its answer. - Changeset: `.changeset/33851-revert-non-object-write-through-fault.md` (`patch`). It says that it supersedes the sentence of the #33563 note claiming such a fault "is still not seen by the revert". The #33563 note itself is unchanged here: its one sentence is corrected in a separate text-only PR (DELIBERATE CORRECTION). ## Tests `packages/metadata-protocol/src/protocol.revert-commit-honest-outcome.test.ts`, the revert harness, gains two top-level describes. They go there as AGENTS.md requires (ruling record 6583487846). - §3 has 12 cases, 4 each for `view`, `permission` and `object_extension`: a clean restore control, which reaches the registry verb as a non-vacuity check; a write-through throw that goes to `failed[]` with `code`, "its row was restored to the body of version 1", the reason and `success: false`; a save control; and a publish control. The two controls hold under the same fault: `success: true`, no advisories, and the same `warn` line. - §4 has 9 cases, 4 each for `view` and `permission`: a clean soft-remove control; a heal stop that goes to `failed[]` with `code`, "its row was removed from sys_metadata", "may still serve the removed row", `success: false` and the heal's `error` line kept; a delete control (`success: true`, `error` line kept); and a save-and-publish control (both `success: true`, no advisories). The ninth case is an `action` row still stored under another package that the registry refuses: it goes to `failed[]`. As a non-vacuity check, the stop is the remaining row's write-through `warn`, not the heal's outer-catch `error`. Premise, measured on the code before each half. On the write-through half (source at `63e47feeca`), §3's 3 fault cases were red: each answered `success: true`. On the heal half (source at `2d23b49dd1`), §4's 3 fault cases were red, with 28 cases green. <details><summary>Ablations (scripts/ablation-replace.mjs, each landed, run, then restored to blob == HEAD with git diff HEAD empty)</summary> | Ablation | Red | Green | | --- | --- | --- | | A1: the overlay branch does not answer | 2 (§3 view, permission fault) | 20 of 22 | | A2: the extension branch does not answer | 1 (§3 object_extension fault) | 21 of 22 | | A3: revertCommit does not set `answerFaults` | 3 (every §3 fault case) | 19 of 22 | | A4: the overlay branch answers every caller | 4 (view and permission save and publish controls; the save answered an `object-registry-refused` advisory, "object 'ticket.grid' was published, but the runtime registry refused it") | 18 of 22 | | A5: the extension branch answers every caller | 2 (object_extension save and publish controls) | 20 of 22 | | B1: the heal's outer catch does not return its stop | 2 (§4 view, permission heal stop: "expected true to be false" on `success`) | 29 of 31 | | B2: the remaining row's refusal is dropped | 1 (§4 remaining-row case) | 30 of 31 | | B3: revertCommit does not read the heal's stop | 3 (every §4 fault case) | 28 of 31 | My first A1 to A3 attempt was a no-op: the replacement was a substring of the anchor, `ablation-replace` refused it, and no test ran. They were re-run with distinct markers, and the table shows those runs. A1 to A5 were run before §4 existed (22 cases). B1 to B3 were run on all 31 cases. </details> ## Acceptance notes - Out of scope, left as it is: in the heal, the object owner branch's `unregisterObject` refusal ("object 'x' was deleted from sys_metadata but stays registered") is still a `warn` line that answers no stop. It is an object-only path, and the card's ruling covered the outer catch and the remaining rows. ## Verification <details><summary>Readings, local, at head 999b09d</summary> - One locked run, at `999b09d9c3` with `origin/main` `68e726d631` merged in (lock VERDICT command-exit 0; queued 6m18s, after a first attempt's queue-timeout exit 99). It ran: the metadata-protocol dependency closure build; `typecheck` exit 0; `test` 342 files passed and 9 skipped, 22923 tests passed; the metadata-protocol build; and the objectql suite, 597 of 597 files and 13177 of 13177 tests. - The other direct dependents (runtime, cli, service-automation, cloud-connection) were not run locally. CI runs them (Test Core). The only type that moved is on private forwarders; `RegistryHealStop` and `RegistryWriteThroughRequest` are not exported from the package entry. - `pnpm lint`: exit 0. - `dispatch-gates --ran`: 73 derived families, each with its exit code recorded. 70 exit 0. 3 are NOT MEASURED, because each needs the whole workspace built: `check:dual-build-cjs-loads`, `check:lean-entry-closure` and `check:type-check-debt`, all exit 3 (PREREQUISITE NOT MET). CI runs them. The body gates (closing-keyword parity, Part-of, changeset no-major, ADR-0087 registration) exit 0. - `git merge-tree --write-tree --name-only`: clean against `origin/main` `68e726d631`, against #33885's head `fa7fb66a7c`, and against S5's `claude/area-E1b-33832` head `9c4f75f36e`. No open PR for #33308 was found. No other open PR touches `protocol.ts`, `protocol-registry-hydration.ts`, `protocol-package-commits.ts` or the harness file. - Dogfood: not run, because the title has no `!` and Clause-② has no (narrowing) arm. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jTkZnXtRhuEiiyidvJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b4ce310 commit 0bbb211

5 files changed

Lines changed: 423 additions & 37 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): `revertCommit` reports an item of any type whose registry write-through or heal faults
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`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`.
11+
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.
13+
14+
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.
15+
16+
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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,19 @@ export class ProtocolPackageCommitsFacet {
15671567
// `object` serves no field afterwards, so it changes none.
15681568
const removedCapture = captureStoredExpressionChange(host.engine, PLURAL_TO_SINGULAR[it.type] ?? it.type, it.name);
15691569
if (removedCapture && !storedExpressions.has(removedCapture.object)) storedExpressions.set(removedCapture.object, removedCapture);
1570-
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+
}
15711583
// [#14179] …and announce it on the ONE choke point,
15721584
// {@link emitMetadataMutation}, exactly as the sibling
15731585
// delete caller {@link deleteMetaItem} does after its own
@@ -1744,6 +1756,10 @@ export class ProtocolPackageCommitsFacet {
17441756
// [#33563] The registry's refusal of the restored object is
17451757
// this item's outcome, not a line on stderr: the row holds
17461758
// the pre-commit body and the registry does not serve it.
1759+
// [#33851] …and so is a fault of any other type's branch
1760+
// (the overlay hydration, the `object_extension`
1761+
// registration), which the write-through answers only to a
1762+
// caller that asks (`answerFaults`).
17471763
const registryRefusal = await host.applyRegistryWriteThrough({
17481764
type: PLURAL_TO_SINGULAR[it.type] ?? it.type,
17491765
name: it.name,
@@ -1757,6 +1773,7 @@ export class ProtocolPackageCommitsFacet {
17571773
// said "the row's OWN scope" while passing the REQUEST's
17581774
// org; the resolution above is what makes the comment true.
17591775
organizationId: null,
1776+
answerFaults: true,
17601777
});
17611778
if (registryRefusal) {
17621779
notApplied.push(

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

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,21 +1458,14 @@ export class ProtocolRegistryHydrationFacet {
14581458
* The orphan adoption ({@link reassignOrphanedMetadata}) calls it for each
14591459
* view row it rebinds, with `reboundFrom`, and [#23646] for each object
14601460
* row, once {@link releaseAdoptedObjectOwner} has handed it the name.
1461+
*
1462+
* [#33851] What it answers: the registry's refusal of an object (the
1463+
* object branch, #33005), and nothing else unless the caller asks
1464+
* ({@link RegistryWriteThroughRequest.answerFaults}). A non-object branch
1465+
* that throws logs the fault at `warn` and, for a caller that asked,
1466+
* answers it in the same shape.
14611467
*/
1462-
static async applyRegistryWriteThrough(host: Pick<ProtocolHost, 'applyObjectRegistryMutation' | 'hydrateOverlayIntoRegistry' | 'registerStoredObjectExtension' | 'registryTakesStoredRows'>, request: {
1463-
type: string;
1464-
name: string;
1465-
item?: any;
1466-
packageId?: string | null;
1467-
/** The row's org scope — `null` for an env-wide row. [#6602] */
1468-
organizationId: string | null;
1469-
/**
1470-
* [#23198] The binding the write moved the row from, when it moved it
1471-
* (an orphan adoption): `null` for the package-less row. See
1472-
* {@link HydrationOptions}.
1473-
*/
1474-
reboundFrom?: { readonly packageId: string | null };
1475-
}): Promise<ObjectRegistryRefusal | undefined> {
1468+
static async applyRegistryWriteThrough(host: Pick<ProtocolHost, 'applyObjectRegistryMutation' | 'hydrateOverlayIntoRegistry' | 'registerStoredObjectExtension' | 'registryTakesStoredRows'>, request: RegistryWriteThroughRequest): Promise<ObjectRegistryRefusal | undefined> {
14761469
// [#8862] The `|| request.type === 'objects'` limb is GONE — this
14771470
// branch admitted the plural that {@link applyObjectRegistryMutation}
14781471
// then consumed. All four call sites of this method fold at their
@@ -1527,6 +1520,8 @@ export class ProtocolRegistryHydrationFacet {
15271520
console.warn(
15281521
`[Protocol] registry write-through failed for ${request.type}/${request.name}: ${err?.message ?? err}`,
15291522
);
1523+
// [#33851] …and answered, to a caller that asked.
1524+
if (request.answerFaults === true) return { error: err };
15301525
}
15311526
return undefined;
15321527
}
@@ -1546,6 +1541,10 @@ export class ProtocolRegistryHydrationFacet {
15461541
console.warn(
15471542
`[Protocol] registry write-through failed for ${request.type}/${request.name}: ${err?.message ?? err}`,
15481543
);
1544+
// [#33851] …and answered, to a caller that asked: the write is
1545+
// still not failed here, the caller decides what the fault means
1546+
// for its own answer.
1547+
if (request.answerFaults === true) return { error: err };
15491548
}
15501549
return undefined;
15511550
}
@@ -1734,6 +1733,15 @@ export class ProtocolRegistryHydrationFacet {
17341733
* naming no package answers the store's refusal, naming every holder. So it
17351734
* does for a row bound to a non-holder of the name whose pair relation names
17361735
* 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.
17371745
*/
17381746
static async restoreArtifactRegistryView(host: Pick<ProtocolHost, 'anotherPackageShips' | 'applyRegistryWriteThrough' | 'convertStoredItem' | 'engine' | 'findEnvironmentRows' | 'isArtifactBacked' | 'isUnservedSealedOverlay' | 'readItemFromMetadataService' | 'reconcileViewExpansions' | 'registryTakesStoredRows' | 'resyncStoredObjectExtensions' | 'rethrowUnlessMetadataStoreUnprovisioned'>, type: string,
17391747
name: string,
@@ -1755,7 +1763,7 @@ export class ProtocolRegistryHydrationFacet {
17551763
* rows are still stored and served, so their registry entries stay.
17561764
* No effect for a type with no members.
17571765
*/
1758-
member?: string,): Promise<void> {
1766+
member?: string,): Promise<RegistryHealStop | undefined> {
17591767
// [#6780] ADR-0005 — the plain-key entry belongs to the env-wide row,
17601768
// so only an env-wide removal may heal (or retire) it.
17611769
if (organizationId !== null && organizationId !== undefined) return;
@@ -1895,16 +1903,22 @@ export class ProtocolRegistryHydrationFacet {
18951903
}
18961904
}
18971905
}
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;
18981910
for (const row of remainingRows) {
1899-
await host.applyRegistryWriteThrough({
1911+
const refusal = await host.applyRegistryWriteThrough({
19001912
type: canonical,
19011913
name,
19021914
item: host.convertStoredItem(String(row.type ?? canonical), storedRowDocument(row)),
19031915
packageId: boundPackageOf(row.package_id) ?? null,
19041916
organizationId: null,
1917+
answerFaults: true,
19051918
});
1919+
refused ??= refusal;
19061920
}
1907-
return;
1921+
return refused;
19081922
}
19091923
if (healed) return;
19101924

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

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

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+
2512+
/**
2513+
* What {@link ProtocolRegistryHydrationFacet.applyRegistryWriteThrough} is
2514+
* asked to make live: the row's type, name and body, its binding and scope.
2515+
*/
2516+
export interface RegistryWriteThroughRequest {
2517+
type: string;
2518+
name: string;
2519+
item?: any;
2520+
packageId?: string | null;
2521+
/** The row's org scope — `null` for an env-wide row. [#6602] */
2522+
organizationId: string | null;
2523+
/**
2524+
* [#23198] The binding the write moved the row from, when it moved it
2525+
* (an orphan adoption): `null` for the package-less row. See
2526+
* {@link HydrationOptions}.
2527+
*/
2528+
reboundFrom?: { readonly packageId: string | null };
2529+
/**
2530+
* [#33851] `true`: a non-object branch whose registration throws (the
2531+
* `object_extension` registration, the overlay hydration) answers the
2532+
* fault as the object branch answers the registry's refusal, beside the
2533+
* `warn` line it logs. `revertCommit` asks, so a revert whose restored
2534+
* body the registry does not serve answers the item in `failed[]`
2535+
* (ADR-0067 D3, the method's docblock: a revert that answers success is
2536+
* one the running process has acted on).
2537+
*
2538+
* Left unset, the fault is only logged and the answer is `undefined`, as
2539+
* before. The save and publish doors leave it unset: they report a
2540+
* returned refusal as an object's (`object-registry-refused`), and their
2541+
* answers for every other type do not change.
2542+
*/
2543+
answerFaults?: boolean;
2544+
}
2545+
24812546
/**
24822547
* [#33005] The rule id of the advisory a publish answers with when the runtime
24832548
* registry refused an object the publish made live. Stable across releases,

0 commit comments

Comments
 (0)