diff --git a/.changeset/32620-non-holder-row-bare-slot-retire.md b/.changeset/32620-non-holder-row-bare-slot-retire.md new file mode 100644 index 00000000000..2f49171e9e2 --- /dev/null +++ b/.changeset/32620-non-holder-row-bare-slot-retire.md @@ -0,0 +1,14 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol): after a deployment removes its customization of a name two packages ship, the deleted body is no longer served from the registry until the next reload + +Clause-②: no +Metadata-protocol: none + +The case: a stored row bound to an installed package that ships no item of the name (an App's customization, ADR-0146), on a name two packages ship, where the pair relation names no single base. After that row was deleted, the registry heal's baseline read was refused (two holders), and the heal stopped with an `error` line. For a `flow` or a `permission`, whose bound row sits in the name's bare registry slot, the removed row's entry stayed there. Until the next reload, a read naming the customizing package served the deleted body, and a read naming either holder was refused with that package as its candidate, although its row no longer existed. + +The heal now retires that entry, as it already did for a package-less row (seat ruling 6812637203 Q2). Entry kept → retired, on the epic seat's ruling 6818436831. Retiring picks no holder and registers no baseline. Each holder's read answers its own item again, the read naming no package is the 409 naming both holders, and the list shows the two holders only. The retire verb still refuses a packaged artifact, so no holder's item can be removed. + +The other package-scoped types already retired the bound row's own package slot. For them only the `error` line changes: it now says that slot was retired, where it said the entry was left as it was. A peer replica converging on a cluster signal that names no package still keeps the logged stop, because it cannot tell whose entry the bare slot holds. diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index cdebe584667..4f9d7c44397 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -75,17 +75,24 @@ import { ObjectStackProtocolImplementationStatics as ObjectStackProtocolImplemen * hold) is named as one, with the package the refused read named as the store * read it (its `callerPackageId`: a package-less read is "no package") and the * holders its message lists. `entry` says what became of the registry entry: - * left as it was, retired from the bare slot (a refused package-less heal, - * seat ruling 6812637203 Q2), or none retired because the verb removed nothing - * (an empty slot, or a packaged artifact it refuses). + * left as it was, retired from the bare slot (a refused package-less or + * non-holder heal, seat ruling 6812637203 Q2 and epic ruling 6818436831), + * retired from the removed row's own package slot only (#32620: the bare slot + * held none the heal may remove), or none retired because the verb removed + * nothing (an empty slot, or a packaged artifact it refuses). */ -function registryHealStoppedMessage(type: string, name: string, error: unknown, entry: 'kept' | 'retired' | 'none-retired' = 'kept'): string { +function registryHealStoppedMessage(type: string, name: string, error: unknown, entry: 'kept' | 'retired' | 'slot-retired' | 'none-retired' = 'kept'): string { const reason = error instanceof Error ? error.message : String(error); const refusal = packageScopedRefusalOf(error); const named = boundPackageOf(refusal?.callerPackageId); const why = refusal !== undefined ? `the metadata service refused the baseline read, which named ${named === undefined ? 'no package' : `package '${named}'`}: ${reason}` : reason; + if (entry === 'slot-retired') { + return `[Protocol] the registry heal after the removal of ${type} '${name}' stopped: ${why}. ` + + 'The removed row\'s registry entry was retired from its own package\'s slot, the bare slot held none the heal may ' + + 'remove, and no baseline was registered, so a read naming no package answers the store\'s refusal naming every holder.'; + } if (entry === 'none-retired') { return `[Protocol] the registry heal after the removal of ${type} '${name}' stopped: ${why}. ` + 'No registry entry was retired, because the bare slot held none the heal may remove (it was empty, or it holds a ' @@ -125,7 +132,8 @@ type ServiceRead = { data: unknown; degraded: boolean; errors: string[] }; * package candidate the refusal lists is asked whether the removal is a pair * row of theirs ({@link isPairRowRemoval}, the delete door's own predicate). * Exactly one base ⇒ its baseline. Otherwise the refusal stands, and the - * walk stops with it, logged; + * walk stops with it, logged, retiring the removed row's bare-slot entry + * (epic ruling 6818436831, #32620); * - no holder at all (a clean miss) ⇒ the settled miss stands, and the walk * goes on to tier 3: the row was the item; * - a degraded read ⇒ degraded: the walk stops without retiring. @@ -1711,7 +1719,8 @@ export class ProtocolRegistryHydrationFacet { * {@link HEAL_BINDING_UNKNOWN} when it never learns the binding (a peer * converging on a cluster signal that names no package: one from a * replica that predates the signal's `packageId`, #32451). Both read with - * no package; only `null` retires on a refusal (below). A peer whose + * no package; only `null` retires on a refusal, as a known binding does + * (below), and {@link HEAL_BINDING_UNKNOWN} never. A peer whose * signal names the package passes that package, as the writer did. * * Best-effort: a failure must never block the delete that already @@ -1722,7 +1731,9 @@ export class ProtocolRegistryHydrationFacet { * baseline read is named as one, with the holders it lists. For a * package-less row that refusal also retires the removed row's bare-slot * entry and registers no baseline (seat ruling 6812637203 Q2): the next read - * naming no package answers the store's refusal, naming every holder. + * 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). */ static async restoreArtifactRegistryView(host: Pick, type: string, name: string, @@ -1909,22 +1920,30 @@ export class ProtocolRegistryHydrationFacet { // baseline is registered. A read naming no package then answers // the store's refusal, which names every holder, instead of the // removed row's body. `removeOverlayEntry` keeps refusing a - // packaged artifact, as on tier 3. A row bound to a package keeps - // the logged stop ({@link readHealBaseline}); the ruling names - // the package-less heal only. So does a caller that does not know - // the binding ({@link HEAL_BINDING_UNKNOWN}, a peer on a - // cluster signal naming no package): it cannot tell the removed - // row was the package-less one. - if (packageId === HEAL_BINDING_UNKNOWN || boundPackageOf(packageId) !== undefined - || packageScopedRefusalOf(error) === undefined) throw error; + // packaged artifact, as on tier 3. + // [#32620, epic ruling 6818436831] …and so does a row bound to a + // NON-HOLDER (a package holding no item of the name, ADR-0146), + // where the pair relation names zero or several bases: the only + // refusal {@link readHealBaseline} lets through for a bound row. + // Its entry sits in the bare slot for a type with no package + // overlay slot (`flow`, `permission`), where it kept serving the + // deleted body to the non-holder's read and stood as a refused + // holder read's candidate. Retiring it picks nobody and restores + // each holder's exact address (entry kept → retired). + // A caller that does not know the binding + // ({@link HEAL_BINDING_UNKNOWN}, a peer on a cluster signal + // naming no package) keeps the logged stop: it cannot tell + // whose entry the bare slot holds. + if (packageId === HEAL_BINDING_UNKNOWN || packageScopedRefusalOf(error) === undefined) throw error; // What the verb answers is what the line says: an empty slot, or - // a packaged artifact the verb refuses, retires nothing. + // a packaged artifact the verb refuses, retires nothing. A bound + // row's own package slot, retired above, is said too. let retired = false; if (typeof registry.removeOverlayEntry === 'function') { retired = registry.removeOverlayEntry(singular, name, memberKey) === true; if (type !== singular) retired = registry.removeOverlayEntry(type, name, memberKey) === true || retired; } - console.error(registryHealStoppedMessage(type, name, error, retired ? 'retired' : 'none-retired')); + console.error(registryHealStoppedMessage(type, name, error, retired ? 'retired' : slotRetired ? 'slot-retired' : 'none-retired')); return; } // [#22877] A baseline of ANOTHER member is no baseline of this one: diff --git a/packages/metadata-protocol/src/protocol.registry-heal-package-read.test.ts b/packages/metadata-protocol/src/protocol.registry-heal-package-read.test.ts index c6bdf1f806b..a946607d75d 100644 --- a/packages/metadata-protocol/src/protocol.registry-heal-package-read.test.ts +++ b/packages/metadata-protocol/src/protocol.registry-heal-package-read.test.ts @@ -295,19 +295,32 @@ describe('[#32366 S1, ADR-0146] a row bound to a package that holds no item of t expect(healLines(h.logged)).toEqual([]); }); - it('a row of a package that pairs no holder, on a name two packages hold: the refusal stands and is logged, nothing picked or retired', async () => { + it('a row of a package that pairs no holder, on a name two packages hold: the refusal is logged, nothing is picked, and the removed row\'s bare-slot entry is retired', async () => { const h = makeHarness({ rows: [overlayRow(OTHER)], holders: [[ALPHA, 'alpha'], [BETA, 'beta']], installed: [OTHER] }); const result = await h.protocol.deleteMetaItem({ type: 'action', name: NAME, packageId: OTHER }); expect(result.success).toBe(true); - // A row bound to a package keeps the logged stop: the Q2 retirement - // names the package-less heal only. - expect(tiers(h)).toEqual({ tier1: [false], tier2: [], tier3: [] }); + // [#32620, epic ruling 6818436831] Retired as the Q2 package-less row + // is (at a557fa38: kept, `tier3: []`); no holder's baseline is picked. + expect(tiers(h)).toEqual({ tier1: [false], tier2: [], tier3: [`action|${NAME}`] }); const lines = healLines(h.logged); expect(lines).toHaveLength(1); expect(lines[0]).toContain(ALPHA); expect(lines[0]).toContain(BETA); + expect(lines[0]).toContain('was retired from the bare slot'); + }); + + it('…and when the verb removes nothing for that row (an empty bare slot, or a packaged artifact): the line says no entry was retired', async () => { + const h = makeHarness({ rows: [overlayRow(OTHER)], holders: [[ALPHA, 'alpha'], [BETA, 'beta']], installed: [OTHER], retireAnswers: false }); + + await h.protocol.deleteMetaItem({ type: 'action', name: NAME, packageId: OTHER }); + + // The verb was asked and removed nothing: the line says so. + expect(tiers(h)).toEqual({ tier1: [false], tier2: [], tier3: [`action|${NAME}`] }); + const lines = healLines(h.logged); + expect(lines).toHaveLength(1); + expect(lines[0]).toContain('No registry entry was retired'); }); it('CONTROL — no package holds the name: the row was the item, and tier 3 retires its entry', async () => { diff --git a/packages/objectql/src/protocol-registry-heal-packageless-refusal.test.ts b/packages/objectql/src/protocol-registry-heal-packageless-refusal.test.ts index 5b9b92638b6..1b5fd23c0e0 100644 --- a/packages/objectql/src/protocol-registry-heal-packageless-refusal.test.ts +++ b/packages/objectql/src/protocol-registry-heal-packageless-refusal.test.ts @@ -37,17 +37,8 @@ const NAME = 'digest'; const manifest = (id: string) => ({ id, name: id, version: '1.0.0', type: 'app', namespace: id.split('.').pop()! }) as never; const body = (label: string, extra: Record = {}) => ({ name: NAME, label, type: 'script', target: `${label}_impl`, ...extra }); -function makeHarness(opts: { composite: boolean; row: boolean }) { - const registry = new SchemaRegistry({ multiTenant: false }); - for (const id of [A, B]) registry.installPackage(manifest(id), 'code'); - if (opts.composite) for (const id of [A, B]) registry.registerItem('action', body(id), 'name' as never, id); - // The removed row's entry, in the bare slot. - registry.registerItem('action', body('stale', opts.row ? { _provenance: 'org' } : {}), 'name' as never); - const manager = new MetadataManager({ formats: ['json'], loaders: [] }); - for (const id of [A, B]) manager.registerInMemory('action', NAME, body(id, { _packageId: id })); - const rows: Array> = opts.row - ? [{ id: 'row_digest', type: 'action', name: NAME, organization_id: null, package_id: null, state: 'active', checksum: 'sha256:head', metadata: JSON.stringify(body('stale')) }] - : []; +/** The one engine double both harnesses read: a control-plane kernel's `sys_metadata` over `rows`. */ +function engineOver(registry: SchemaRegistry, rows: Array>): Record { // The engine double: equality and `$in`, and nothing else — any other // operator or combinator is refused loudly rather than read as a field // (the matcher of `package-scoped-exact-qualifier.test.ts`). @@ -87,6 +78,21 @@ function makeHarness(opts: { composite: boolean; row: boolean }) { async transaction(fn: (ctx: unknown) => Promise) { return fn(undefined); }, async execute() { return {}; }, }; + return engine; +} + +function makeHarness(opts: { composite: boolean; row: boolean }) { + const registry = new SchemaRegistry({ multiTenant: false }); + for (const id of [A, B]) registry.installPackage(manifest(id), 'code'); + if (opts.composite) for (const id of [A, B]) registry.registerItem('action', body(id), 'name' as never, id); + // The removed row's entry, in the bare slot. + registry.registerItem('action', body('stale', opts.row ? { _provenance: 'org' } : {}), 'name' as never); + const manager = new MetadataManager({ formats: ['json'], loaders: [] }); + for (const id of [A, B]) manager.registerInMemory('action', NAME, body(id, { _packageId: id })); + const rows: Array> = opts.row + ? [{ id: 'row_digest', type: 'action', name: NAME, organization_id: null, package_id: null, state: 'active', checksum: 'sha256:head', metadata: JSON.stringify(body('stale')) }] + : []; + const engine = engineOver(registry, rows); // A control-plane kernel, whose registry takes stored rows. const protocol = new ObjectStackProtocolImplementation(engine as never, () => new Map([['metadata', manager]]) as never, undefined); const logged = vi.spyOn(console, 'error').mockImplementation(() => {}); @@ -140,3 +146,101 @@ describe('[#32366, ruling 6812637203 Q2] a refused package-less heal retires the expect(after.refusal.candidates).toEqual([{ kind: 'package', packageId: A }, { kind: 'package', packageId: B }]); }); }); + +/** + * [#32620, epic ruling 6818436831, ADR-0150 D3/D5, ADR-0146] A row bound to a + * NON-HOLDER (an installed package holding no item of the name) on a name two + * packages hold, where the pair relation names no single base: the heal's + * baseline read is refused, and the removed row's bare-slot entry is retired + * as the package-less row's is (Q2 above). Entry kept → retired. + * + * Measured at a557fa38 over this harness (boot hydration of the stored row, + * then the delete door naming the row's package), every package-slotted type + * in both registration orders: `flow` and `permission`, the two whose bound + * row has no package overlay slot, kept the removed row's entry in the bare + * slot, so the non-holder's read served the deleted body and each holder's + * read was refused with the non-holder as its candidate. Every other + * package-slotted type already retires the row's own package slot (#33127); + * for those only the line moves (`action` below, the CONTROL). + * + * The holders here are served by the metadata service only (no composite slot + * in the registry), the shape Q2's first pin measures. + */ +describe('[#32620, ruling 6818436831] a refused heal of a non-holder\'s row retires its bare-slot entry', () => { + const O = 'com.acme.other'; + const item = (label: string, extra: Record = {}) => ({ name: NAME, label, description: label, ...extra }); + + async function boot(type: string, order: readonly string[]) { + const registry = new SchemaRegistry({ multiTenant: false }); + registry.logLevel = 'silent' as never; + for (const id of [O, ...order]) registry.installPackage(manifest(id), 'code'); + const manager = new MetadataManager({ formats: ['json'], loaders: [] }); + for (const id of order) manager.registerInMemory(type as never, NAME, item(`shipped:${id}`, { _packageId: id })); + const rows: Array> = [{ + id: 'row_other', type, name: NAME, organization_id: null, package_id: O, state: 'active', checksum: 'sha256:head', + metadata: JSON.stringify(item('row:other')), + }]; + const engine = engineOver(registry, rows); + const protocol: any = new ObjectStackProtocolImplementation(engine as never, () => new Map([['metadata', manager]]) as never, undefined); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + const logged = vi.spyOn(console, 'error').mockImplementation(() => {}); + await protocol.loadMetaFromDb(); + const bareEntry = () => ((registry as any).metadata.get(type) as Map | undefined)?.get(NAME)?.label; + /** The label a read naming `packageId` serves, or the refusal's code, status and candidates. */ + const read = async (packageId?: string) => { + try { + const res = await protocol.getMetaItem({ type, name: NAME, ...(packageId ? { packageId } : {}) }); + return (res?.item as { label?: string } | undefined)?.label; + } catch (err) { + expect(err).toBeInstanceOf(PackageScopedNameRefusedError); + const refusal = err as PackageScopedNameRefusedError; + return [refusal.code, refusal.status, refusal.refusal.candidates]; + } + }; + return { protocol, rows, logged, bareEntry, read }; + } + + const holders = (order: readonly string[]) => [...order].map((id) => ({ kind: 'package', packageId: id })); + + for (const type of ['flow', 'permission']) { + for (const order of [[A, B], [B, A]] as const) { + it(`${type} (${order[0] === A ? 'alpha' : 'beta'} first): the non-holder's removed row leaves the bare slot; each holder's read answers its own item, the bare read is the 409 naming both holders, and the list shows the two holders only`, async () => { + const h = await boot(type, order); + // The row is in the bare slot, and a holder's read names it as a candidate. + expect(h.bareEntry()).toBe('row:other'); + expect(await h.read(A)).toEqual(['RESOURCE_CONFLICT', 409, [{ kind: 'package', packageId: O }]]); + + const result = await h.protocol.deleteMetaItem({ type, name: NAME, packageId: O }); + + expect(result.success).toBe(true); + expect(h.rows).toHaveLength(0); + // At a557fa38: 'row:other', still served to the non-holder's read. + expect(h.bareEntry()).toBeUndefined(); + expect(await h.read(O)).toBeUndefined(); + expect([await h.read(A), await h.read(B)]).toEqual([`shipped:${A}`, `shipped:${B}`]); + expect(await h.read()).toEqual(['RESOURCE_CONFLICT', 409, holders(order)]); + const listed: any = await h.protocol.getMetaItems({ type }); + const items: Array<{ label?: string; _packageId?: string }> = listed.items ?? listed; + expect(items.map((item) => item.label).sort()).toEqual([`shipped:${A}`, `shipped:${B}`]); + const lines = healLines(h.logged); + expect(lines).toHaveLength(1); + expect(lines[0]).toContain('was retired from the bare slot'); + }); + } + } + + it('CONTROL — action, whose bound row takes its package\'s own slot (#33127): the holders serve as before the move, and the line says that slot was retired', async () => { + const h = await boot('action', [A, B]); + expect(h.bareEntry()).toBeUndefined(); + + await h.protocol.deleteMetaItem({ type: 'action', name: NAME, packageId: O }); + + expect(h.bareEntry()).toBeUndefined(); + expect([await h.read(A), await h.read(B), await h.read(O)]).toEqual([`shipped:${A}`, `shipped:${B}`, undefined]); + expect(await h.read()).toEqual(['RESOURCE_CONFLICT', 409, holders([A, B])]); + const lines = healLines(h.logged); + expect(lines).toHaveLength(1); + // At a557fa38: "left as it was and may serve the removed row". + expect(lines[0]).toContain('retired from its own package\'s slot'); + }); +});