Skip to content

Commit 005970d

Browse files
committed
fix(metadata-protocol): the per-item rollback restores into the row the by-name read serves
A .custom pair's declared override beside a row bound to its read-only base was addressed through a package-agnostic binding read, so its rollback restored (and was refused on) the base row. The door now derives the package from the served row (findServedOverlayRow at packagelessReadAddress, the declared override first) and hands it to restoreVersion. Claude-Session: https://claude.ai/code/session_01Utp6CXdBvpJrhnHyW825Hb Co-authored-by: Claude <noreply@anthropic.com>
1 parent b200c72 commit 005970d

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ export class ProtocolPackageCommitsFacet {
19061906
}
19071907

19081908
/** [#28355] The body of {@link rollbackMetaItem} before its refusal audit; that method's docblock is the contract. */
1909-
static async rollbackMetaItemUnaudited(host: Pick<ProtocolHost, 'applyRegistryWriteThrough' | 'assertLockAllowsWrite' | 'emitMetadataMutation' | 'ensureOverlayIndex' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'metadataConflictRefusal' | 'namedBaseOverlayWriteRefusal' | 'packagelessOverlayWriteRefusal' | 'receiptVersion' | 'recordMetadataAudit' | 'recordOptimisticConflictAudit' | 'refuseOrganizationScopedWrite' | 'resolveOverlayPackageBinding' | 'restoreWriteFor' | 'runMutationProjector'>, request: RollbackMetaItemRequest): Promise<{
1909+
static async rollbackMetaItemUnaudited(host: Pick<ProtocolHost, 'applyRegistryWriteThrough' | 'assertLockAllowsWrite' | 'emitMetadataMutation' | 'ensureOverlayIndex' | 'findServedOverlayRow' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'metadataConflictRefusal' | 'namedBaseOverlayWriteRefusal' | 'packagelessOverlayWriteRefusal' | 'packagelessReadAddress' | 'receiptVersion' | 'recordMetadataAudit' | 'recordOptimisticConflictAudit' | 'refuseOrganizationScopedWrite' | 'resolveOverlayPackageBinding' | 'restoreWriteFor' | 'runMutationProjector'>, request: RollbackMetaItemRequest): Promise<{
19101910
success: boolean;
19111911
version: string;
19121912
seq: number;
@@ -2025,7 +2025,31 @@ export class ProtocolPackageCommitsFacet {
20252025
// it afterwards would put a fallible query downstream of a write that
20262026
// already succeeded — the shape that ends in a `catch {}` swallowing a
20272027
// real outage (#4867).
2028-
const rollbackPackageId = await host.resolveOverlayPackageBinding(singularType, request.name, member);
2028+
//
2029+
// [#29848, ADR-0146 D8 item 2] The row is the one the by-name read
2030+
// naming no package SERVES ({@link findServedOverlayRow} at
2031+
// {@link packagelessReadAddress}, its declared override first), so a
2032+
// rollback restores the item the caller sees. Beside a row bound to the
2033+
// read-only base (stored before #28905's close), the base's paired
2034+
// `.custom` row that declares the override is served, and its rollback
2035+
// restores it; the package-agnostic binding read answered whichever
2036+
// active row of the name the store returned first, so the pair's
2037+
// rollback addressed the base row and the named-base close below
2038+
// refused it, naming a row the caller never meant. No row served (a
2039+
// row only another package binds under the name): that row's binding,
2040+
// as before.
2041+
const servedPackage = await host.packagelessReadAddress(singularType, request.name, member);
2042+
const served = await host.findServedOverlayRow({
2043+
type: singularType,
2044+
name: request.name,
2045+
state: 'active',
2046+
...(servedPackage !== undefined ? { packageId: servedPackage } : {}),
2047+
...memberOption(member),
2048+
servedOverride: true,
2049+
});
2050+
const rollbackPackageId = served !== undefined
2051+
? ((served.row as { package_id?: string | null } | null)?.package_id ?? null)
2052+
: await host.resolveOverlayPackageBinding(singularType, request.name, member);
20292053
// [ADR-0146 D11, D1] A rollback writes the row its binding names, so
20302054
// a rollback of a packaged item's package-less row (an overlay type's
20312055
// row the ceremony has not moved, or none stored, whose restore writes
@@ -2081,6 +2105,9 @@ export class ProtocolPackageCommitsFacet {
20812105
deriveRestoredBody,
20822106
// [#22877] The member whose lineage `toVersion` is taken from.
20832107
...memberOption(member),
2108+
// [#29848, #29414] The row the binding above names, and no other
2109+
// package's row of the name: its parent hash, and the write.
2110+
packageId: rollbackPackageId,
20842111
});
20852112
// #4521 — a rollback is a live write like any other: the restored
20862113
// body must be the one the runtime dispatches on immediately, not

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13085,6 +13085,10 @@ export class ObjectStackProtocolImplementation implements
1308513085
* (`VERSION_NOT_FOUND`) when the target version doesn't exist;
1308613086
* 409 (`VERSION_NOT_RESTORABLE`) when the target is a delete
1308713087
* tombstone (no body to bring back).
13088+
*
13089+
* [#29848, ADR-0146 D8 item 2] The door names no package: it restores
13090+
* into the row the by-name read naming no package serves, a `.custom`
13091+
* pair's declared override over a row bound to its read-only base.
1308813092
*/
1308913093
async rollbackMetaItem(request: RollbackMetaItemRequest) {
1309013094
// [#28355] A refusal that carries no row of its own leaves its `denied` row here.

0 commit comments

Comments
 (0)