From cc4681d2b74d46294835a2c0f52f1bfd01bde4d3 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 00:17:16 +0000 Subject: [PATCH 1/4] fix(metadata-protocol)!: enabling a second holder of an overlay name takes back the package-less row the read-side hydrator laid into the first holder's registry slot while the second was disabled While one of two holders of an overlay name is disabled, the read-side hydrator lays a package-less row into the served holder's slot under its envelope (ADR-0150 D4: the one served holder's customization). Enabling the other holder ran no hydration, so that holder's registry item, its scoped list and its registry list answered the environment's row as its own until the next unscoped list read. The hydrator now records each entry it builds under a sole holder's envelope, and the registry's enable notice rebuilds it for the holders served then (none's envelope with two), synchronously inside the enable. An entry another write replaced is left alone. Pins: email_template, dashboard and report, both registration orders, the three registry readers, and three CONTROLs; one ablation each for the heal and its identity guard. ADR-0087 entry package-less-overlay-row-holder-slot-on-reenable, with its remedy measured as accepted at the save door. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01L6bhgV84zNSi6HwSHmMU2c --- ...32820-reenable-heal-upgrade-guide-entry.md | 10 ++ .../32820-reenable-heals-holder-slot.md | 25 +++++ .../src/protocol-registry-hydration.ts | 94 ++++++++++++++++++ .../package-scoped-exact-qualifier.test.ts | 98 +++++++++++++++++-- ...ess-overlay-row-holder-slot-on-reenable.ts | 44 +++++++++ 5 files changed, 265 insertions(+), 6 deletions(-) create mode 100644 .changeset/32820-reenable-heal-upgrade-guide-entry.md create mode 100644 .changeset/32820-reenable-heals-holder-slot.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts diff --git a/.changeset/32820-reenable-heal-upgrade-guide-entry.md b/.changeset/32820-reenable-heal-upgrade-guide-entry.md new file mode 100644 index 00000000000..ecdbe74ac2f --- /dev/null +++ b/.changeset/32820-reenable-heal-upgrade-guide-entry.md @@ -0,0 +1,10 @@ +--- +'@objectstack/spec': patch +--- + +docs(spec): the protocol upgrade guide names what a holder's registry item answers after a second holder of an overlay name is enabled again: its own item, not the package-less row the hydrator laid in while the second was disabled (ADR-0150 D4) + +Clause-②: no +Metadata-protocol: none + +The semantic entry `package-less-overlay-row-holder-slot-on-reenable` (`packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts`) registers the narrowing `.changeset/32820-reenable-heals-holder-slot.md` declares (ADR-0087, `adr-0087: registered`): no automatic rewrite, because which holder a package-less row customizes is a judgement only its author can make. It adds no key and no export. diff --git a/.changeset/32820-reenable-heals-holder-slot.md b/.changeset/32820-reenable-heals-holder-slot.md new file mode 100644 index 00000000000..573791c31fb --- /dev/null +++ b/.changeset/32820-reenable-heals-holder-slot.md @@ -0,0 +1,25 @@ +--- +'@objectstack/metadata-protocol': minor +--- + +fix(metadata-protocol)!: enabling a second holder of an overlay name takes back the package-less row the read-side hydrator laid into the first holder's registry slot while the second was disabled (ADR-0150 D4) + +Clause-②: no (narrowing) — a served answer that guessed a holder goes away: after the enable, a holder's registry item, its scoped list and its registry list answer the holder's own item where they answered the environment's package-less row as the holder's own. Nothing that was refused is now served, and no export is added (the heal is module-internal). +Metadata-protocol: narrowed +Skills-docs: none — `skills/**` and `content/docs/**` teach no registry read of a holder's item after a disable and enable; the prescription ships in the FROM → TO below. + + + +**BREAKING** for a registry reader of a holder's item of an overlay-type name (`email_template`, `dashboard`, `report`) that another installed package also holds, when a package-less `sys_metadata` row of the name is stored: `getPackageScopedItem(type, name, holder)` (what a send-time read takes), the list scoped to the holder (`GET /meta/:type?package=`) and the registry list scoped to it. + +While one of the two holders is disabled, the other is the one served holder (#32183), so the package-less row is its customization: the read-side hydrator (an unscoped list read, the boot load) lays the row into that holder's slot under its envelope. Enabling the disabled holder ran no hydration, so the slot kept the row, and until the next unscoped list read the holder's registry item and its scoped list answered the environment's row as the holder's own, and its registry list listed both. The protocol's exact read (`?package=`) already refused it `409` naming both holders. + +The enable now builds the entry again, as the hydrator builds it for the holders served then: with two served, no holder's envelope, so each holder's slot answers its own item, as when the hydrator ran with both served. It runs inside the enable, so every enable door (`PATCH /packages/:id/enable`, an install's `enableOnInstall`) answers after it. An entry another write replaced after the hydration is that write's, and is not touched. + +Not changed: the disabled period itself (the one served holder's slot serves the row, as #32183 rules), the exact reads, and a package installed after the hydration that ships the name (the slot keeps the row until the next unscoped hydration, as before: no registry notice reaches the protocol for a new holder). + +No first-party composition has two packages holding one overlay name with a package-less row, so no answer changes in this repository. + +The fix: + +- FROM a package-less overlay row of a name two packages hold, read as one holder's own through the registry after a disable and enable, TO the declared override of that holder in its paired `.custom` package (`?package=.custom` with `overrides: { package: , basedOn }`), saved after deleting the package-less row (a package-less delete removes the one bound row there is, so after the save it would remove the override). diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index c9c833059dd..66e0ffc2fc0 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -169,6 +169,91 @@ function soleHolderOf(registry: { packageScopedHoldersOf?(type: string, name: st return holders[0]; } +/** + * [#32820] A package-less row of a name ONE package held when the read-side + * hydrator laid it in, under that holder's artifact envelope + * ({@link soleHolderOf}): what the registry entry was built from, so it can be + * built again when the holder set changes. + */ +interface SoleHolderEnvelope { + readonly host: Pick; + readonly type: string; + readonly canonicalType: string; + readonly name: string; + readonly member: string | undefined; + readonly data: unknown; + /** The holder whose envelope the entry wears. */ + readonly holder: string; + /** The entry as registered: the heal touches the slot only while it still holds this object. */ + readonly registered: unknown; +} + +type EnvelopeRegistry = { + getItem?(type: string, name: string, currentPackageId?: string, member?: string): unknown; + registerItem(type: string, item: unknown, keyField: string): unknown; + packageScopedHoldersOf?(type: string, name: string): readonly string[] | undefined; + onPackageEnabled?(listener: (packageId: string) => void): () => void; +}; + +/** Per registry, the {@link SoleHolderEnvelope} of each bare-slot key (`type`, `name`, member). */ +const soleHolderEnvelopes = new WeakMap>(); + +const envelopeKey = (type: string, name: string, member: string | undefined) => `${type}\u0000${name}\u0000${member ?? ''}`; + +/** + * [#32820, ADR-0150 D4] Record (or, with no `holder`, forget) the envelope a + * package-less row's registry entry wears. The first record for a registry + * subscribes {@link healSoleHolderEnvelopes} to its package enables. + */ +function recordSoleHolderEnvelope(registry: EnvelopeRegistry, key: string, envelope: SoleHolderEnvelope | undefined): void { + let records = soleHolderEnvelopes.get(registry); + if (envelope === undefined) { + records?.delete(key); + return; + } + if (records === undefined) { + if (typeof registry.onPackageEnabled !== 'function') return; + const created = new Map(); + records = created; + soleHolderEnvelopes.set(registry, created); + registry.onPackageEnabled(() => healSoleHolderEnvelopes(registry, created)); + } + records.set(key, envelope); +} + +/** + * [#32820, ADR-0150 D4] A package-less overlay row the read-side hydrator laid + * into a holder's slot while that holder alone was served (another holder of + * the name disabled) wears that holder's envelope, so the registry reads it + * as that holder's own item (`getPackageScopedItem`, the scoped list, the + * execution list). An enable that serves a second holder makes it a + * customization no holder can claim: the entry is built again as the + * hydrator builds it for the holders served now (none's envelope with two), + * so each holder's slot answers its own item again, as with no hydration in + * the disabled period. Synchronous, inside the enable, so every enable door + * (`PATCH /packages/:id/enable`, an install's `enableOnInstall`) answers + * after it. + * + * Only an entry the slot still holds as registered: a later write, delete or + * hydration replaced it and owns the slot. + */ +function healSoleHolderEnvelopes(registry: EnvelopeRegistry, records: Map): void { + for (const [key, record] of [...records]) { + if (typeof registry.getItem !== 'function' + || registry.getItem(record.type, record.name, undefined, record.member) !== record.registered) { + records.delete(key); + continue; + } + const holder = soleHolderOf(registry, record.canonicalType, record.name); + if (holder === record.holder) continue; + const artifact = holder === null ? undefined : record.host.lookupArtifactItem(record.type, record.name, holder ?? undefined, record.member); + const registered = mergeArtifactProtection(record.type, stateTenantAuthorship(withRowBinding(record.data, undefined)), artifact); + registry.registerItem(record.type, registered, 'name'); + if (typeof holder === 'string' && artifact) records.set(key, { ...record, holder, registered }); + else records.delete(key); + } +} + export class ProtocolRegistryHydrationFacet { /** * Mirror an object-type overlay write into the in-memory engine @@ -667,6 +752,15 @@ export class ProtocolRegistryHydrationFacet { if (!incomingTakesStoredFlowSlot(held, registered, owner, installedManifestsOf(registry))) return true; } registry.registerItem(type, registered, 'name' as any); + // [#32820] A package-less row wearing the envelope of the one holder + // served now is recorded, so an enable serving a second holder builds + // it again ({@link healSoleHolderEnvelopes}); any other registration + // of the key forgets it. + const member = bundleMemberOf(type, data); + recordSoleHolderEnvelope(registry, envelopeKey(type, rowName, member), + !options.packageId && typeof envelopePackage === 'string' && envelope + ? { host, type, canonicalType, name: rowName, member, data, holder: envelopePackage, registered } + : undefined); await host.hydrateExpandedViewItems(type, data, options); return true; } diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index b25a96f3c67..79a30e0f735 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -1855,12 +1855,9 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for // row is that holder's customization (served at its address, and laid in // under its envelope), and a sealed type's row is declined. Re-enabled, // the protocol's exact read answers one thing per state: the overlay row - // is refused naming both, and each sealed holder serves its own. Not - // pinned here, and not healed by this card: an overlay type's copy stays - // in the enabled holder's registry slot after the re-enable, so that - // slot, the list scoped to it and its execution list answer the - // environment's row as its own until the next unscoped hydration (the - // re-enable heal, a follow-up under #32568). + // is refused naming both, and each sealed holder serves its own. The + // registry slot the hydrator laid the overlay row into is healed on the + // enable, pinned under `[#32820]` below. const BOTH = [{ kind: 'package', packageId: A }, { kind: 'package', packageId: B }]; for (const type of ['email_template', 'action', 'queue']) { it(`${type}, two holders, one disabled while the read-side hydrator runs, then re-enabled: one answer per state on the exact read`, async () => { @@ -1898,6 +1895,95 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for }); }); +/** + * [#32820, ADR-0150 D4] A package-less overlay row the read-side hydrator lays + * in while one of two holders is disabled wears the served holder's envelope: + * that holder's slot answers it as its own. Enabling the other holder builds + * the entry again for the holders served now, so each holder's slot, the list + * scoped to it and the registry's execution list answer the holder's own item, + * as when the hydrator ran with both served. + */ +describe('[#32820] re-enabling a holder: the package-less overlay row the hydrator laid into the other holder\'s slot leaves it', () => { + const body = (type: string, label: string) => (type === 'email_template' + ? { name: 'welcome', label, locale: 'en-US', subject: 's', bodyHtml: '

x

' } + : { name: 'welcome', label }); + const holderOwn = (type: string, id: string) => registry.registerItem(type, body(type, `${id.split('.').pop()} own`), 'name' as never, id); + const storeEnvRow = (type: string) => rows.push({ + id: `${type}_env`, type, name: 'welcome', state: 'active', package_id: null, bundle_member: null, + metadata: JSON.stringify(body(type, 'env row')), + }); + /** The three registry readers of a holder's item, and the slot's stamp. */ + const readers = async (type: string, at: string) => { + const slot = registry.getPackageScopedItem(type, 'welcome', at) as { label?: string; _packageId?: string } | undefined; + const scoped = ((await protocol.getMetaItems({ type, packageId: at } as never)) as { items?: Array<{ name?: string; label?: string }> }) + .items?.filter((i) => i.name === 'welcome').map((i) => i.label); + const execution = (registry.listItems(type, at) as Array<{ name?: string; label?: string }>) + .filter((i) => i.name === 'welcome').map((i) => i.label); + return { slot: slot?.label, stamp: slot?._packageId, scoped, execution }; + }; + const own = (id: string) => { + const label = `${id.split('.').pop()} own`; + return { slot: label, stamp: id, scoped: [label], execution: [label] }; + }; + + for (const type of ['email_template', 'dashboard', 'report']) { + for (const order of [[A, B], [B, A]]) { + it(`${type}, registered ${order.map((id) => id.split('.').pop()).join(' then ')}: B disabled while the hydrator runs, then enabled: A's slot, A's scoped list and A's execution list answer A's own (BASE: the environment's row, listed beside A's own)`, async () => { + for (const id of order) holderOwn(type, id); + storeEnvRow(type); + registry.disablePackage(B); + await protocol.getMetaItems({ type } as never); + // The disabled period: A is the one served holder, so the row is its customization. + expect((await readers(type, A)).slot, 'B disabled').toBe('env row'); + registry.enablePackage(B); + expect(await readers(type, A), 'B enabled').toEqual(own(A)); + expect(await readers(type, B), 'B enabled').toEqual(own(B)); + // The protocol's exact read is unchanged: refused naming both. + const err = await refusalOf(() => protocol.getMetaItem({ type, name: 'welcome', packageId: A } as never)); + expect([err.status, err.refusal.reason]).toEqual([409, 'ambiguous-in-closure']); + }); + } + } + + it('CONTROL — the slot after the heal is the one the hydrator builds with both holders served', async () => { + holderOwn('email_template', A); + holderOwn('email_template', B); + storeEnvRow('email_template'); + await protocol.getMetaItems({ type: 'email_template' } as never); + const hydrated = await readers('email_template', A); + expect(hydrated).toEqual(own(A)); + const bare = registry.getItem('email_template', 'welcome', undefined, 'en-US'); + registry.disablePackage(B); + await protocol.getMetaItems({ type: 'email_template' } as never); + registry.enablePackage(B); + expect(await readers('email_template', A)).toEqual(hydrated); + expect(registry.getItem('email_template', 'welcome', undefined, 'en-US')).toEqual(bare); + }); + + it('CONTROL — an enable that leaves A the one served holder keeps the row as A\'s customization', async () => { + holderOwn('email_template', A); + storeEnvRow('email_template'); + registry.disablePackage(C); + await protocol.getMetaItems({ type: 'email_template' } as never); + const before = await readers('email_template', A); + expect([before.slot, before.stamp]).toEqual(['env row', A]); + registry.enablePackage(C); + expect(await readers('email_template', A)).toEqual(before); + }); + + it('CONTROL — an entry written over the slot after the hydration is the slot\'s: the enable does not touch it', async () => { + holderOwn('email_template', A); + holderOwn('email_template', B); + storeEnvRow('email_template'); + registry.disablePackage(B); + await protocol.getMetaItems({ type: 'email_template' } as never); + const written = { ...body('email_template', 'written later'), _packageId: A }; + registry.registerItem('email_template', written, 'name' as never); + registry.enablePackage(B); + expect(registry.getItem('email_template', 'welcome', undefined, 'en-US')).toBe(written); + }); +}); + /** * [#32183, ruling (c)] An App's pair (`.custom`) is the pair of every * module of the App, so two modules holding one name are both its bases. A diff --git a/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts b/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts new file mode 100644 index 00000000000..ef7154b0263 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts @@ -0,0 +1,44 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// ADR-0150 D4 at the registry: a package-less row of an overlay type is the +// customization of the one served holder of its name, and of none when two +// are served. The read-side hydrator built the registry entry for the holders +// served when it ran, and an enable that served a second holder left the entry +// wearing the first holder's envelope. A narrowing of answers, not of any key: +// no schema key moves and no stored row changes shape, so no tombstone and no +// D2 conversion. No relevance question: the moved answer turns on what two +// installed packages hold and on a disable in between, which no question over +// one stack can name. +export const entry: SemanticMigration = { + id: 'package-less-overlay-row-holder-slot-on-reenable', + surface: + 'The registry\'s item of a holder of an overlay-type name (email_template, dashboard, report) that a second ' + + 'installed package also holds, when a package-less row of the name is stored and the read-side hydrator ran ' + + '(an unscoped list read, the boot load) while the other holder was disabled: the holder\'s package-scoped ' + + 'registry item, its scoped list (GET /api/v1/meta/TYPE?package=ID) and the registry list scoped to it, after ' + + 'the other holder is enabled again', + replacement: + 'Delete the package-less row (DELETE /api/v1/meta/TYPE/NAME, naming no package), then save the customization ' + + 'as the declared override of the holder it customizes: in the holder\'s paired .custom package ' + + '(PUT /api/v1/meta/TYPE/NAME?package=ID.custom with overrides: { package: ID, basedOn: VERSION }). Delete ' + + 'first: a package-less delete of the name removes the one bound row there is, so after the save it would ' + + 'remove the override', + reason: + 'A package-less row of an overlay type customizes one holder only while that holder is the one served holder ' + + 'of the name (ADR-0150 D4). With one of two holders disabled, the read-side hydrator laid the row into the ' + + 'served holder\'s registry slot under that holder\'s envelope, and enabling the other holder left it there, ' + + 'so until the next unscoped hydration the holder\'s registry item, its scoped list and its registry list ' + + 'answered the environment\'s row as the holder\'s own (the registry list carried both). The protocol\'s exact ' + + 'read already refused it 409 naming both holders. The enable now builds the entry again for the holders ' + + 'served, so each holder answers its own item, as when the hydrator ran with both served. Nothing is ' + + 'rewritten. Measured when the change landed: no first-party composition has two packages holding one ' + + 'overlay name with a package-less row.', + acceptanceCriteria: + 'For every package-less email_template, dashboard or report row of a name two installed packages hold, no ' + + 'package-less row of the name remains; the change lives in the declared override of the holder it customizes, ' + + 'in that holder\'s .custom package, and GET /api/v1/meta/TYPE/NAME?package=ID answers the override while ' + + '?package= naming the other holder answers that holder\'s own item, whether or not a holder was disabled and ' + + 'enabled in between.', +}; From dca268d3243714daedba6f2d49fc2172752ea5e4 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 00:29:18 +0000 Subject: [PATCH 2/4] test(metadata-protocol): the call-site censuses record the enable heal's artifact lookup and registration Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01L6bhgV84zNSi6HwSHmMU2c --- .../metadata-protocol/src/protocol-registry-hydration.ts | 3 ++- .../src/protocol.lookup-artifact-item-call-sites.test.ts | 2 ++ .../src/protocol.register-item-call-sites.test.ts | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index 66e0ffc2fc0..fd80044e165 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -188,9 +188,10 @@ interface SoleHolderEnvelope { readonly registered: unknown; } +/** The engine's registry, as the hydrator reads it (its registration is the hydrator's own call, untyped there too). */ type EnvelopeRegistry = { + readonly [member: string]: any; getItem?(type: string, name: string, currentPackageId?: string, member?: string): unknown; - registerItem(type: string, item: unknown, keyField: string): unknown; packageScopedHoldersOf?(type: string, name: string): readonly string[] | undefined; onPackageEnabled?(listener: (packageId: string) => void): () => void; }; diff --git a/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts b/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts index 9a3d99d4636..ee9cb6afaef 100644 --- a/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts +++ b/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts @@ -158,6 +158,8 @@ const SITES: ReadonlyArray Date: Fri, 13 Nov 2026 18:38:02 +0000 Subject: [PATCH 3/4] docs(spec): the re-enable heal entry's remedy keeps the package-less row's body and clears bound rows before the delete, as the landed remedy order prescribes Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_016WV4d1H7jxfU2FWB3HDdbs --- .changeset/32820-reenable-heals-holder-slot.md | 2 +- .../18.package-less-overlay-row-holder-slot-on-reenable.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.changeset/32820-reenable-heals-holder-slot.md b/.changeset/32820-reenable-heals-holder-slot.md index 573791c31fb..b6113ece7a1 100644 --- a/.changeset/32820-reenable-heals-holder-slot.md +++ b/.changeset/32820-reenable-heals-holder-slot.md @@ -22,4 +22,4 @@ No first-party composition has two packages holding one overlay name with a pack The fix: -- FROM a package-less overlay row of a name two packages hold, read as one holder's own through the registry after a disable and enable, TO the declared override of that holder in its paired `.custom` package (`?package=.custom` with `overrides: { package: , basedOn }`), saved after deleting the package-less row (a package-less delete removes the one bound row there is, so after the save it would remove the override). +- FROM a package-less overlay row of a name two packages hold, read as one holder's own through the registry after a disable and enable, TO the declared override of that holder in its paired `.custom` package (`?package=.custom` with `overrides: { package: , basedOn }`), saved after deleting the package-less row (a package-less delete removes the one bound row there is, so after the save it would remove the override). Before that delete, keep the package-less row's stored body and clear any row of the name bound to a package, as `package-less-row-exact-address-by-type-class` prescribes: the delete hard-deletes the row, and with a bound row present it addresses that row instead. diff --git a/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts b/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts index ef7154b0263..794bddf3ab8 100644 --- a/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts +++ b/packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts @@ -20,7 +20,10 @@ export const entry: SemanticMigration = { + 'registry item, its scoped list (GET /api/v1/meta/TYPE?package=ID) and the registry list scoped to it, after ' + 'the other holder is enabled again', replacement: - 'Delete the package-less row (DELETE /api/v1/meta/TYPE/NAME, naming no package), then save the customization ' + 'First keep the package-less row\'s stored body and clear any row of the name bound to a package, as the entry ' + + 'package-less-row-exact-address-by-type-class prescribes: the delete below hard-deletes the row, and with a ' + + 'bound row present it addresses that row instead. Then delete the package-less row (DELETE ' + + '/api/v1/meta/TYPE/NAME, naming no package; ?state=draft for a draft), then save the customization ' + 'as the declared override of the holder it customizes: in the holder\'s paired .custom package ' + '(PUT /api/v1/meta/TYPE/NAME?package=ID.custom with overrides: { package: ID, basedOn: VERSION }). Delete ' + 'first: a package-less delete of the name removes the one bound row there is, so after the save it would ' From 8715fcedd22ac73dceb41e546fbacbb1c822f47f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 20:30:32 +0000 Subject: [PATCH 4/4] fix(metadata-protocol): the re-enable heal records only the three declared overlay types, and two more pins run the holder set moving to the other holder alone and a permission row Contract review s1: a package-less permission row wears its sole holder's envelope too, so the record now takes only email_template, dashboard and report, the types the narrowing declares. Review s2: one pin runs the heal's fourth outcome (A and B hold, B disabled, hydrated, A disabled, B enabled, then A enabled), asserting the slot at each step. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_016WV4d1H7jxfU2FWB3HDdbs --- .../src/protocol-registry-hydration.ts | 12 ++++++- .../package-scoped-exact-qualifier.test.ts | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index aa4ea15ed59..71bac53651d 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -197,6 +197,16 @@ type EnvelopeRegistry = { onPackageEnabled?(listener: (packageId: string) => void): () => void; }; +/** + * [#32820] The overlay types whose package-less row the heal rebuilds: the + * three the narrowing declares (its changeset and ADR-0087 entry + * `package-less-overlay-row-holder-slot-on-reenable`). A package-less + * `permission` row also wears its sole holder's envelope, but two holders of a + * permission set are refused by the registry today; when that rule opens, the + * heal widens to it only in a change that declares it (contract review s1). + */ +const HEALED_OVERLAY_TYPES: ReadonlySet = new Set(['email_template', 'dashboard', 'report']); + /** Per registry, the {@link SoleHolderEnvelope} of each bare-slot key (`type`, `name`, member). */ const soleHolderEnvelopes = new WeakMap>(); @@ -768,7 +778,7 @@ export class ProtocolRegistryHydrationFacet { // of the key forgets it. const member = bundleMemberOf(type, data); recordSoleHolderEnvelope(registry, envelopeKey(type, rowName, member), - !options.packageId && typeof envelopePackage === 'string' && envelope + !options.packageId && typeof envelopePackage === 'string' && envelope && HEALED_OVERLAY_TYPES.has(canonicalType) ? { host, type, canonicalType, name: rowName, member, data, holder: envelopePackage, registered } : undefined); await host.hydrateExpandedViewItems(type, data, options); diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index 107ee795062..9b19645553c 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -2157,6 +2157,40 @@ describe('[#32820] re-enabling a holder: the package-less overlay row the hydrat registry.enablePackage(B); expect(registry.getItem('email_template', 'welcome', undefined, 'en-US')).toBe(written); }); + + it('the holder set moves from A alone to B alone, then to both: the entry is built again under B\'s envelope, then under none (review s2)', async () => { + holderOwn('email_template', A); + holderOwn('email_template', B); + storeEnvRow('email_template'); + registry.disablePackage(B); + await protocol.getMetaItems({ type: 'email_template' } as never); + const slotAt = (at: string) => { + const slot = registry.getPackageScopedItem('email_template', 'welcome', at) as { label?: string; _packageId?: string } | undefined; + return [slot?.label, slot?._packageId]; + }; + expect(slotAt(A), 'B disabled, hydrated: A alone served').toEqual(['env row', A]); + registry.disablePackage(A); + registry.enablePackage(B); + // B is now the one served holder: the row is its customization, recorded again under its envelope. + expect(slotAt(B), 'A disabled, B enabled: B alone served').toEqual(['env row', B]); + registry.enablePackage(A); + // Both served: the second heal builds it under no holder's envelope. + expect(await readers('email_template', A), 'both enabled').toEqual(own(A)); + expect(await readers('email_template', B), 'both enabled').toEqual(own(B)); + }); + + it('a package-less permission row is not recorded: an enable leaves the hydrated slot as the hydrator laid it (review s1; the heal moves only the three declared overlay types)', async () => { + admitSecondPermissionHolder(); + holderOwn('permission', A); + holderOwn('permission', B); + storeEnvRow('permission'); + registry.disablePackage(B); + await protocol.getMetaItems({ type: 'permission' } as never); + const hydrated = registry.getItem('permission', 'welcome') as { label?: string } | undefined; + expect(hydrated?.label, 'B disabled, hydrated: the row in A\'s slot').toBe('env row'); + registry.enablePackage(B); + expect(registry.getItem('permission', 'welcome')).toBe(hydrated); + }); }); /**