From 7a3dbeccbaeac331f774e53c4e68501b4ce412be Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 02:07:44 +0000 Subject: [PATCH 1/4] fix(metadata)!: the boot priming pass leaves a package-less stored row of a by-package type unstamped, so the host's package is never counted as a holder of its name On a host that declares its package, the boot priming pass no longer gives the host's stamp to a package-less row a DatabaseLoader hands out for a type stored per (package, name). The registry files it where the store files any write that carries no package, so after a package-less write the bare action read answers the written item instead of a 409 naming the host's package, and the bare removal counts the same holders. #32791's read-time filing of the stamped row has nothing left to file and is removed (its CONTROL pins pass unchanged); #32521's contestedNames is subsumed. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgVSjQBHNkZd6Eqx2XX --- ...2-boot-pass-leaves-stored-row-unstamped.md | 24 +++ .../src/loaders/database-loader.test.ts | 180 ++++++++++++++---- packages/metadata/src/metadata-manager.ts | 90 +-------- .../metadata/src/package-slotted-store.ts | 48 +---- packages/metadata/src/plugin.ts | 63 +++--- 5 files changed, 205 insertions(+), 200 deletions(-) create mode 100644 .changeset/32812-boot-pass-leaves-stored-row-unstamped.md diff --git a/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md new file mode 100644 index 00000000000..022f18c8151 --- /dev/null +++ b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md @@ -0,0 +1,24 @@ +--- +'@objectstack/metadata': patch +--- + +fix(metadata)!: the boot priming pass leaves a package-less stored row of a type stored per `(package, name)` unstamped, so the host's package is never counted as a holder of its name (ADR-0150 D4) + +Clause-②: no (narrowing) — on a host that declares its package (`MetadataPlugin`'s `packageId`) and wires a `DatabaseLoader`, a package-less `sys_metadata` row of `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping` or `dataset` is no longer served as the host package's item after the boot priming pass: its body no longer carries `_packageId` set to the host's package or `_provenance: 'package'`, the metadata list filtered by the host's package (`?package=` naming it) no longer lists it, and `publishPackage`, `revertPackage` and `unregisterPackage` naming the host's package no longer take it as one of that package's items. The `409` this lifts (the bare read naming the host's package, which holds nothing, after a write that carries no package) is #32560's, which has not shipped. +Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is which package the boot pass gives a stored row that names none. + + + +**BREAKING** for a host that declares its package and stores rows that name no package for one of these ten types. Such a row is the environment's own item, or the customization of the one package that holds its name (ADR-0150 D4); it was never the host package's, but the boot pass stamped it so. To keep an item in the host's package, save it naming that package (`?package=` on the write, or `packageId` on `register`). A row whose stored body an earlier release's boot pass wrote the host's stamp into is still read as the host package's (its column is bound from that body), and is not moved. Every other type, and the host's own file items, are stamped as before. No first-party package, app or example declares a package and wires a `DatabaseLoader`. + +Moved answers, all on such a host, each now the answer the same composition gives on a host that declares no package: + +- One package's row and a package-less row saved last (`action`): after `register` with no package, or `registerInMemory` of a package-less item, the bare `get` and `getDiagnosed` go from `409 RESOURCE_CONFLICT` naming the host's package, the holder and the environment to the written item. The removal naming no package goes from that `409` to removing the package-less row, so it names the holders the bare read names. +- The same composition, every one of the ten types: the registry holds the package-less row in the name's bare slot, not the host's; a read naming the holder answers its customization (the package-less row) where it answered the holder's own row; on a host declaring the holder's package, a read naming another package that holds nothing answers the package-less row, as the bare read does. +- A package-less row and one package's `action` item registered in memory after the pass: the bare read answers that package's item, where it answered the package-less row (the by-host difference #32752 tracked). +- The package-less row deleted from the table behind the manager: the bare read answers the registry's copy, where it was refused naming the host's package and the holder. +- `email_template`, one package's row and a package-less row: the bare read after the pass is no longer refused naming the host's package. + +This replaces #32791's read-time filing of the stamped row (`MetadataManager`'s record of stored package-less rows, its overwrite mark and the judged view's filing), which has nothing left to file and is removed; every #32791 pin marked CONTROL passes unchanged. Candidate order in a refusal is not promised. + +Skills-docs: none — `skills/**` and `content/docs/**` do not teach that the boot pass gives a stored row the host's package; the migration step ships here and in the upgrade notes. diff --git a/packages/metadata/src/loaders/database-loader.test.ts b/packages/metadata/src/loaders/database-loader.test.ts index 933c1192d32..75e7310b0bb 100644 --- a/packages/metadata/src/loaders/database-loader.test.ts +++ b/packages/metadata/src/loaders/database-loader.test.ts @@ -2055,27 +2055,26 @@ describe('[#31699 R5-A] the priming pass never writes back a row it read from th }); /** - * [#32791; ADR-0150 D3/D4, regression of #32560] On a host that declares its - * package, the boot priming pass stamps a package-less stored row with the - * host's package before it registers it (`applyProtection`), so the registry - * holds that row in the host's slot. A read naming no package of an action - * name is judged over the registry and the loaders (#32560's + * [#32791, #32812; ADR-0150 D3/D4, regression of #32560] On a host that + * declares its package, the boot priming pass stamped a package-less stored + * row with the host's package before it registered it (`applyProtection`), so + * the registry held that row in the host's slot. A read naming no package of + * an action name is judged over the registry and the loaders (#32560's * `judgesLoaderSlots`), and the loaders still store the row package-less: one * row was counted twice, as the host's package and as the environment, and - * the refusal named a holder that does not exist. The judged view now files - * that row as the store files a write that carries no package - * (`packagelessWriteKeyOf`: the name's one holder's customization, else the - * environment's own item), with the write order of the slot it came from. - * Only a row stamped with its slot's package is filed so, and not one whose - * registration replaced an item registered in memory (that item's package - * holds the name: epic ruling B). + * the refusal named a holder that does not exist. #32791 corrected the count + * right after the pass; after a write that carries no package the host was + * named again (#32812). The pass now leaves a package-less stored row of a + * type stored per `(package, name)` unstamped (`unstampedStoredRow` in + * `plugin.ts`), so the registry files it where the store files any write + * that carries no package (the name's one holder's customization, else the + * environment's own item), whatever package the host declares. * - * BEFORE (`main` with #32676): each case below not marked CONTROL was refused - * naming `com.host.app`. The CONTROLs answer on that `main` as here; the two - * marked with a review finding were red on this branch at an earlier head. - * The boot state only: after a write that carries no package the host is - * named again (#32812), and a removal naming no package still names it - * (#32813). + * BEFORE (`main` before #32791, with #32676): each case below not marked + * CONTROL was refused naming `com.host.app`. The CONTROLs answer on that + * `main` as here. Where #32812 moved a #32791 pin, its comment names the + * FROM (`main` `25ee5076`) and the TO, which is the cell's answer on a host + * that declares no package. */ describe('[#32791] a stored package-less row the boot pass files under the host\'s package is one holder of an action name, not two', () => { const ALPHA = 'com.alpha.app'; @@ -2146,11 +2145,15 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ await seed('action', ALPHA, 1); await seed('action', null, 2); const m = await bootPass(HOST); - expect(registryKeys(m, 'action'), 'the pass files the row in the host\'s slot, as before').toEqual([`${HOST}\u0000helper`]); + // [#32812] FROM `main` `25ee5076`: the host's key (`com.host.app` and + // `helper` joined by a NUL), and the read naming the holder answering + // ALPHA's own row. TO: the row unstamped, filed in the name's bare slot, + // the holder's customization, as on a host that declares no package. + expect(registryKeys(m, 'action'), 'the pass leaves the row package-less').toEqual(['helper']); expect(await answer(m, 'action')).toBe('env'); const diagnosed = await m.getDiagnosed('action', 'helper'); expect([(diagnosed.data as { label?: string } | undefined)?.label, diagnosed.degraded]).toEqual(['env', false]); - expect(await answer(m, 'action', ALPHA), 'a read naming the holder, as before').toBe(ALPHA); + expect(await answer(m, 'action', ALPHA), 'a read naming the holder answers its customization').toBe('env'); expect(await answer(m, 'action', HOST), 'a read naming the host, as before').toBe('env'); }); @@ -2180,7 +2183,8 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ await seed('action', ALPHA, 1, { objectName: 'account' }); await seed('action', null, 2); const m = await bootPass(HOST); - expect(registryKeys(m, 'action')).toEqual([`${HOST}\u0000helper`]); + // [#32812] FROM `main` `25ee5076`: the host's key. TO: the bare slot. + expect(registryKeys(m, 'action')).toEqual(['helper']); expect(await bareAnswers(m)).toEqual(['env', 'env']); }); @@ -2272,11 +2276,14 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ /** * [#32791] A package's item registered in memory, and the package-less row - * the pass stamped with the host's package into a slot no other item held: - * the row is counted once, as the store files it beside that one holder - * (its customization). BEFORE (main): refused naming the host's package too. + * the pass registers: the row is counted once, never with the host's + * package beside it. BEFORE (main before #32791): refused naming the + * host's package too. [#32812] FROM `main` `25ee5076`, the first cell + * (ALPHA's item registered after the pass) answered the package-less row; + * TO: ALPHA's item, the answer on a host that declares no package or ALPHA + * (the by-host difference #32752 tracked is gone). */ - it('action, one package\'s item in memory beside the package-less row the pass stamped into an empty slot: the row is counted once', async () => { + it('action, one package\'s item in memory beside the package-less row the pass registers: the row is counted once, and a host that declares another package answers as one that declares none', async () => { const cells: InMemoryCell[] = [ [HOST, [[null]], [], [ALPHA]], [HOST, [[null]], [ALPHA], []], @@ -2284,7 +2291,8 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ ]; const seen: unknown[] = []; for (const cell of cells) seen.push(await bareAfterPass(cell)); - expect(seen).toEqual(cells.map(() => ['env', 'env'])); + expect(seen).toEqual([[`${ALPHA} code`, `${ALPHA} code`], ['env', 'env'], ['env', 'env']]); + expect(await bareAfterPass([undefined, [[null]], [], [ALPHA]]), 'the same cell on a host that declares no package').toEqual([`${ALPHA} code`, `${ALPHA} code`]); }); it('action, two packages\' items in memory beside the package-less row the pass stamped, in either order: the bare read is refused naming both and the environment, never the host (BEFORE: the host named too)', async () => { @@ -2383,17 +2391,24 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ }); /** - * [#32791, review N1] The row is counted once only while a loader still - * stores it: removed from the table behind the manager, the registry's - * slot is counted as before (after the removal main answers the same). + * [#32791, review N1; #32812] The package-less row removed from the table + * behind the manager: the registry's copy is counted as the one holder's + * customization, as on a host that declares no package. FROM `main` + * `25ee5076`: refused naming the host's package, which holds nothing, and + * ALPHA. TO: the registry's copy. */ - it('action, the package-less row removed from the table behind the manager after the pass: the row is no longer counted once, and the host\'s slot is a holder again', async () => { - await seedRows([[ALPHA], [null]]); - const m = await bootPass(HOST); - expect(await bareAnswers(m)).toEqual(['env', 'env']); - await driver.delete('sys_metadata', 'action_env_2'); - for (const loader of (m as any).loaders.values()) (loader as DatabaseLoader).invalidateAll(); - expect(await bareAnswers(m)).toEqual([REFUSED(HOST, ALPHA), REFUSED(HOST, ALPHA)]); + it('action, the package-less row removed from the table behind the manager after the pass: the host\'s package is never a holder, as on a host that declares none', async () => { + const seen: unknown[] = []; + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seedRows([[ALPHA], [null]]); + const m = await bootPass(hostPackage); + seen.push(await bareAnswers(m)); + await driver.delete('sys_metadata', 'action_env_2'); + for (const loader of (m as any).loaders.values()) (loader as DatabaseLoader).invalidateAll(); + seen.push(await bareAnswers(m)); + } + expect(seen).toEqual([['env', 'env'], ['env', 'env'], ['env', 'env'], ['env', 'env']]); }); it('CONTROL every by-package type, one package\'s row and a package-less row: the bare read answers the row the pass registered — the package-less row saved last, the holder\'s row saved last — on a host declaring no package, the holder, or another (action\'s package-less row saved last on another host: the first case)', async () => { @@ -2429,6 +2444,90 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ expect(registryKeys(m, 'action')).toEqual([`${ALPHA}\u0000helper`, `${HOST}\u0000helper`]); expect(await bareAnswers(m)).toEqual([REFUSED(ALPHA, HOST), REFUSED(ALPHA, HOST)]); }); + + /** + * [#32812] The state after the pass and a write that carries no package + * (PR #32802's TO held for the boot state only, epic ruling C). One + * package's row, a package-less row saved last, a host declaring another + * package; then `register` with no package, or `registerInMemory` of a + * package-less item, of the name. The written item is that one holder's + * customization (D4), so the bare read answers it, as before #32560. + * BEFORE (main `25ee5076`): `409` naming the host's package, which holds + * nothing, beside the holder and the environment. + */ + it('action, after the pass on a host declaring another package, a register with no package of a name one package holds: the bare read answers the written body, and getDiagnosed agrees (BEFORE: 409 naming the host, the holder and the environment)', async () => { + await seedRows([[ALPHA], [null]]); + const m = await bootPass(HOST); + await m.register('action', 'helper', { name: 'helper', label: 'written' }); + expect(await bareAnswers(m)).toEqual(['written', 'written']); + }); + + it('action, after the pass on a host declaring another package, a registerInMemory of a package-less item of a name one package holds: the bare read answers the item, and getDiagnosed agrees (BEFORE: 409 naming the host, the holder and the environment)', async () => { + await seedRows([[ALPHA], [null]]); + const m = await bootPass(HOST); + m.registerInMemory('action', 'helper', { name: 'helper', label: 'in memory' }); + expect(await bareAnswers(m)).toEqual(['in memory', 'in memory']); + }); + + /** + * [#32812, #32813's subject in this composition] The removal naming no + * package counts the holders the bare read counts: right after the pass + * and after a register with no package, on a host declaring another + * package exactly as on one declaring none. FROM `main` `25ee5076`: the + * removal right after the pass was refused naming the host's package, + * ALPHA and the environment while the bare read answered the package-less + * row (PR #32802's acceptance note). TO: it removes the package-less row, + * and the bare read then answers ALPHA's row; after the write, which the + * table took into ALPHA's row (its customization, D4), ALPHA's row answers + * the written body. + */ + it('action, one package\'s row and a package-less row saved last: the removal naming no package agrees with the bare read, on a host declaring another package as on one declaring none', async () => { + const removal = async (m: MetadataManager) => answerOf(async () => { + await m.unregister('action', 'helper'); + return { label: 'removed' }; + }); + const seen: Record = {}; + for (const hostPackage of [HOST, undefined]) { + for (const write of [false, true]) { + driver = createMockDriver(); + await seedRows([[ALPHA], [null]]); + const m = await bootPass(hostPackage); + if (write) await m.register('action', 'helper', { name: 'helper', label: 'written' }); + const before = await bareAnswers(m); + const removed = await removal(m); + seen[`${hostPackage ?? 'none'} ${write ? 'after a write' : 'after the pass'}`] = [...before, removed, ...(await bareAnswers(m))]; + } + } + expect(seen).toEqual({ + [`${HOST} after the pass`]: ['env', 'env', 'removed', ALPHA, ALPHA], + [`${HOST} after a write`]: ['written', 'written', 'removed', 'written', 'written'], + 'none after the pass': ['env', 'env', 'removed', ALPHA, ALPHA], + 'none after a write': ['written', 'written', 'removed', 'written', 'written'], + }); + }); + + /** + * [#32812] Every by-package type, the card's composition and a register + * with no package after the pass: the bare read answers the written body + * on a host declaring another package, as on one declaring none. CONTROL + * for the eight types other than `action`, whose bare read does not judge + * the loaders' slots (`judgesLoaderSlots`); `action` is the card's first + * row. + */ + it('every by-package type, one package\'s row and a package-less row saved last, then a register with no package: the bare read answers the written body on a host declaring another package or none', async () => { + const seen: unknown[] = []; + for (const type of UNBUNDLED) { + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seed(type, ALPHA, 1); + await seed(type, null, 2); + const m = await bootPass(hostPackage); + await m.register(type, 'helper', { name: 'helper', label: 'written' }); + seen.push([type, hostPackage ?? 'none', await answer(m, type)]); + } + } + expect(seen).toEqual(UNBUNDLED.flatMap((type) => [[type, HOST, 'written'], [type, 'none', 'written']])); + }); }); /** @@ -2755,6 +2854,11 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => { * package-less row of a name, measured at `efd4ea3a` (before this change) * and unchanged by it: `[order, host package, DatabaseLoader.loadMany, * registry keys, bare read, read naming ALPHA, read naming HOST]`. + * [#32812] The package-less row saved last, on a host declaring ALPHA or + * another package, now answers as on a host declaring none: the pass leaves + * the row unstamped. FROM `main` `25ee5076`: host ALPHA, key ALPHA's, read + * naming HOST nothing; host HOST, key the host's, read naming ALPHA ALPHA's + * own row. TO: the bare key, every read the package-less row. */ /** * The same across two loaders, one holding ALPHA's item and the other a @@ -2768,8 +2872,8 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => { ]; const ONE_HOLDER_AND_A_PACKAGELESS_ROW = [ ['package-less row saved last', 'no host package', ['env'], ['helper'], 'env', 'env', 'env'], - ['package-less row saved last', ALPHA, ['env'], [`${ALPHA}\u0000helper`], 'env', 'env', undefined], - ['package-less row saved last', HOST, ['env'], [`${HOST}\u0000helper`], 'env', ALPHA, 'env'], + ['package-less row saved last', ALPHA, ['env'], ['helper'], 'env', 'env', 'env'], + ['package-less row saved last', HOST, ['env'], ['helper'], 'env', 'env', 'env'], ['package-less row saved first', 'no host package', [ALPHA], [`${ALPHA}\u0000helper`], ALPHA, ALPHA, undefined], ['package-less row saved first', ALPHA, [ALPHA], [`${ALPHA}\u0000helper`], ALPHA, ALPHA, undefined], ['package-less row saved first', HOST, [ALPHA], [`${ALPHA}\u0000helper`], ALPHA, ALPHA, undefined], diff --git a/packages/metadata/src/metadata-manager.ts b/packages/metadata/src/metadata-manager.ts index b361653b8d8..09e65b1dcbe 100644 --- a/packages/metadata/src/metadata-manager.ts +++ b/packages/metadata/src/metadata-manager.ts @@ -98,7 +98,6 @@ import { readStoreEntry, inheritStoreWriteOrder, judgesLoaderSlots, - packagelessWriteKeyOf, platformSlotsOf, recordStoreWrite, slotPackageOf, @@ -647,20 +646,6 @@ export class MetadataManager implements IMetadataService { private loaders: Map = new Map(); /** [#31699 R5-A] The loader {@link loadMany} read each item object from ({@link MetadataRegisterOptions}). */ private readonly loadedFrom = new WeakMap(); - /** - * [ADR-0150 D4, #32791] The items of a type stored per `(package, name)` - * that {@link loadMany} read from a stored-row loader (`datasource:`) held - * for no package: the environment's rows. The boot priming pass may stamp - * one with the host's package before it registers it ({@link slotViewOf}). - */ - private readonly storedPackagelessRows = new WeakSet(); - /** - * [ADR-0150 D4, #32791] The {@link storedPackagelessRows} whose registration - * replaced an item no loader handed out (one registered in memory or by - * code): that item's package held the name before the row took its slot, so - * the slot is a holder, not only the row ({@link slotViewOf}). - */ - private readonly storedRowsOverOwnItems = new WeakSet(); // Protected so subclasses can access serializers if needed protected serializers: Map; protected logger: Logger; @@ -1298,13 +1283,6 @@ export class MetadataManager implements IMetadataService { const { key, replaces } = slot === undefined ? storeWriteKey(typeStore, type, name, data) : { key: slot, replaces: [] }; if (!typeStore) this.registry.set(type, (typeStore = new Map())); const existed = typeStore.has(key) || replaces.length > 0; - if (data !== null && typeof data === 'object' && this.storedPackagelessRows.has(data)) { - const before = typeStore.get(key); - // [review S3] A row that replaces a marked row (the pass run again) carries its mark. - if (before !== null && typeof before === 'object' && before !== data && (!this.loadedFrom.has(before) || this.storedRowsOverOwnItems.has(before))) { - this.storedRowsOverOwnItems.add(data); - } - } for (const replaced of replaces) typeStore.delete(replaced); typeStore.set(key, data); recordStoreWrite(typeStore, key); @@ -1474,10 +1452,7 @@ export class MetadataManager implements IMetadataService { // stores it — judged only over loaders that all answered: with one down, // the slot is read as the environment's, as before. const platformKeys = errors.length === 0 ? platformSlotsOf(this.registry.get(type), type, name, loaderStore) : undefined; - // [#32791] A read naming none counts a stored row the boot pass stamped - // with the host's package once, as the loaders store it. - const view = this.slotViewOf(type, name, loaderStore, !isPackageCaller(packageId)); - const entry = readStoreEntry(view, type, name, packageId, platformKeys); + const entry = readStoreEntry(this.slotViewOf(type, name, loaderStore), type, name, packageId, platformKeys); return entry.found ? { data: entry.data, degraded: false, errors } : { data: null, degraded: errors.length > 0, errors }; @@ -1518,71 +1493,26 @@ export class MetadataManager implements IMetadataService { * registry's slots of the name, then the loaders' stored items keyed as the * store keys them ({@link slotStoreOf}), what the registry (then an earlier * loader) holds kept over a later item of the same slot. Reads and removals - * judge a name the registry cannot answer alone over this view. - * - * [ADR-0150 D4, #32791] `asStored`, for a read naming no package: a - * registry slot of a package whose item is a stored package-less row - * ({@link storedPackagelessRows}) stamped with that same package (the boot - * pass stamps it with the host's package before it registers it), while a - * loader still stores the row, is that row, not a holder of its own. It is - * filed in the view as the store files a write that carries no package - * ({@link packagelessWriteKeyOf}: the name's one holder's customization, - * else the environment's own item) in place of the loader's copy of the - * row, and keeps the write order of the registry slot it came from, so one - * row is counted once, never as the host's package and as the environment. - * A package's own item, a host's own item that no stored row is, an - * unstamped row the registry's own write rule filed in its one holder's - * slot (that holder's customization), and a row whose registration replaced - * an item no loader handed out ({@link storedRowsOverOwnItems}: that item's - * package holds the name) keep their slots. A removal judges - * the view without `asStored`, so in that composition the read and the - * removal naming no package do not count the same holders. + * judge a name the registry cannot answer alone over this view, so they + * agree on who holds it. */ private slotViewOf( type: string, name: string, loaderStore: ReadonlyMap, - asStored = false, ): Map { const registryStore = this.registry.get(type); const view = new Map(); - const storedRows: Array<{ key: string; data: unknown }> = []; - const storedKeys = new Set(); // [#32517] Each slot's member written last first: a slot no key of which // came from the registry answers its first member (`latestMemberOf`). if (registryStore) { - for (const key of latestMembersFirst(registryStore, storeKeysNamed(registryStore, type, name))) { - const data = registryStore.get(key); - const stampedWith = slotPackageOf(key); - if ( - asStored && stampedWith !== undefined && data !== null && typeof data === 'object' - && this.storedPackagelessRows.has(data) && indexedItemPackageId(data) === stampedWith - && !this.storedRowsOverOwnItems.has(data) - ) { - const stored = storeSlotKey(type, name, undefined, data); - if (loaderStore.has(stored)) { - storedRows.push({ key, data }); - storedKeys.add(stored); - continue; - } - } - view.set(key, data); - } + for (const key of latestMembersFirst(registryStore, storeKeysNamed(registryStore, type, name))) view.set(key, registryStore.get(key)); } for (const [key, data] of loaderStore) { - if (!view.has(key) && !storedKeys.has(key)) view.set(key, data); - } - // [#32791] The row the boot pass primed, over the loader's copy of the - // slot it fills (its holder's row: the customization shadows it, D4), - // written when the registry's slot it came from was. - const aliases = new Map(); - for (const { key, data } of storedRows) { - const at = packagelessWriteKeyOf(view, type, name, data); - view.set(at, data); - aliases.set(at, key); + if (!view.has(key)) view.set(key, data); } // [#32560] "Written last" over the view is the registry's own order. - inheritStoreWriteOrder(view, registryStore, aliases); + inheritStoreWriteOrder(view, registryStore); return view; } @@ -3842,13 +3772,7 @@ export class MetadataManager implements IMetadataService { kept.add(key); } results.push(item); - if (item !== null && typeof item === 'object') { - this.loadedFrom.set(item, loader); - // [#32791] Read here, before any caller stamps it. - if (PACKAGE_SLOTTED_STORE_TYPES.has(type) && loader.contract.protocol === 'datasource:' && indexedItemPackageId(item) === undefined) { - this.storedPackagelessRows.add(item); - } - } + if (item !== null && typeof item === 'object') this.loadedFrom.set(item, loader); }); return results; } diff --git a/packages/metadata/src/package-slotted-store.ts b/packages/metadata/src/package-slotted-store.ts index 7b66ef824b1..bf120d33c03 100644 --- a/packages/metadata/src/package-slotted-store.ts +++ b/packages/metadata/src/package-slotted-store.ts @@ -264,15 +264,9 @@ function writtenLast(store: ReadonlyMap, keys: readonly string[ * [ADR-0150 D3, #32560] Give `view` (a store assembled from `from`'s slots and * others) `from`'s write order for the keys it took from it, so a read over * the view answers "written last" as the read over `from` does. A key `from` - * does not hold counts as written before every key it does. [#32791] A view - * key `aliases` maps to the key of `from` its item was taken from (the view - * filed that item under another key) takes that key's order. + * does not hold counts as written before every key it does. */ -export function inheritStoreWriteOrder( - view: ReadonlyMap, - from: ReadonlyMap | undefined, - aliases?: ReadonlyMap, -): void { +export function inheritStoreWriteOrder(view: ReadonlyMap, from: ReadonlyMap | undefined): void { const order = from ? writeOrder.get(from) : undefined; if (!order) return; // [#32517] A slot none of whose members came from `from` still answers its @@ -280,9 +274,8 @@ export function inheritStoreWriteOrder( inheritedViews.add(view); const inherited = new Map(); for (const key of view.keys()) { - const fromKey = aliases?.get(key) ?? key; - const at = order.get(fromKey); - if (at !== undefined && view.get(key) === from!.get(fromKey)) inherited.set(key, at); + const at = order.get(key); + if (at !== undefined && view.get(key) === from!.get(key)) inherited.set(key, at); } writeOrder.set(view, inherited); } @@ -654,41 +647,16 @@ function slottedWriteKey( const packageId = storedItemPackageId(data); return { key: keyed(packageId === undefined ? identity : slotKey(packageId, identity)), replaces: [] }; } - const packageId = storedItemPackageId(data); - if (packageId === undefined) return { key: keyed(packagelessSlotOf(store, identity)), replaces: [] }; const holders = packageSlotsOf(store, identity); + const packageId = storedItemPackageId(data); + if (packageId === undefined) { + return { key: keyed(holders.length === 1 ? slotKey(holders[0]!, identity) : identity), replaces: [] }; + } const others = holders.filter((holder) => holder !== packageId); const bare = keyed(identity); return { key: keyed(slotKey(packageId, identity)), replaces: others.length === 0 && store.has(bare) ? [bare] : [] }; } -/** - * [ADR-0150 D4] The slot a write that carries no package fills under - * `identity`: the holder's slot under a name exactly one package holds (a - * package-less row bearing a package-held name is that holder's - * customization, never a second item), else the identity's bare slot (the - * environment's own item). - */ -function packagelessSlotOf(store: ReadonlyMap, identity: string): string { - const holders = packageSlotsOf(store, identity); - return holders.length === 1 ? slotKey(holders[0]!, identity) : identity; -} - -/** - * [ADR-0150 D4, #32791] The key {@link storeWriteKey} gives `data` written to - * `store` as an item that carries no package, whatever package its body is - * stamped with now: the name's one holder's slot (its customization), else - * the identity's bare slot (the environment's own item); [#32517] a bundled - * type's member keyed under it. The manager files a stored package-less row - * the boot pass registered under the host's package by this rule when it - * judges a read naming no package over its view of the registry and the - * loaders, so the row is one holder of the name, as the loaders store it. - */ -export function packagelessWriteKeyOf(store: ReadonlyMap, type: string, name: string, data: unknown): string { - if (!PACKAGE_SLOTTED_STORE_TYPES.has(type)) return name; - return memberKeyOf(type, packagelessSlotOf(store, slotIdentityOf(type, name, data)), data); -} - /** * [#32246] {@link storeWriteKey} for a store with one slot per `(package, * name)` whatever object an action is bound to: `DatabaseLoader`'s rows, diff --git a/packages/metadata/src/plugin.ts b/packages/metadata/src/plugin.ts index 47649fc5c09..3cb7b0131ad 100644 --- a/packages/metadata/src/plugin.ts +++ b/packages/metadata/src/plugin.ts @@ -14,7 +14,7 @@ import { Plugin, PluginContext } from '@objectstack/core'; import { resolveArtifactPackageOrder, artifactPackageId } from '@objectstack/core'; import { NodeMetadataManager } from './node-metadata-manager.js'; import { MemoryLoader } from './loaders/memory-loader.js'; -import { PACKAGE_SLOTTED_STORE_TYPES, bundleEntryKey, isBundledStoreType, pluralEntryKeys, storedItemPackageId } from './package-slotted-store.js'; +import { PACKAGE_SLOTTED_STORE_TYPES, bundleEntryKey, isBundledStoreType, storedItemPackageId } from './package-slotted-store.js'; import { DEFAULT_METADATA_TYPE_REGISTRY, judgeCollectionItemOwnerStamp, OWNER_STAMP_JUDGED_COLLECTIONS } from '@objectstack/spec/kernel'; import type { MetadataPluginConfig } from '@objectstack/spec/kernel'; import { applyProtection } from '@objectstack/spec/shared'; @@ -1672,7 +1672,6 @@ export class MetadataPlugin implements Plugin { // the earlier loader's item keeps the entry — the file over its // own stale seed. One loader's own items never shadow each other. const primedBy = new Map(); - const contested = contestedNames(entry.type, items); for (const item of primingOrder(entry.type, items)) { const meta = item as any; if (meta?.name) { @@ -1682,14 +1681,13 @@ export class MetadataPlugin implements Plugin { // uses, so both load paths produce identical // _packageId/_provenance state. No-op when the // option is unset or the item is already stamped. - // [#32521] Not a package-less stored row of a name - // two packages hold: it stays the environment's own - // item (`contestedNames`). The host's own file item - // of such a name is stamped as before. + // [#32521, #32812] Never a package-less stored row + // of a type stored per `(package, name)`: it stays + // the environment's own item, which the store files + // by its write rule (`unstampedStoredRow`). The + // host's own file item is stamped as before. applyProtection(meta, { - packageId: storedItemPackageId(meta) === undefined - && contested.has(meta.name) - && this.manager.sourceLoaderOf(meta) === STORED_ROW_LOADER + packageId: unstampedStoredRow(entry.type, meta, this.manager.sourceLoaderOf(meta)) ? undefined : this.options.packageId, }); @@ -1729,36 +1727,23 @@ export class MetadataPlugin implements Plugin { const STORED_ROW_LOADER = 'database'; /** - * [#32521; epic #31527 red lines 2 and 3, contract reviews F1 and D1] The - * names two or more packages hold among a type's items, for an unbundled type - * stored per `(package, name)`. The boot priming pass does not stamp a - * package-less STORED ROW of such a name (an item `DatabaseLoader` handed on) - * with the host's declared package: ADR-0150 D4 makes a package-less row a - * holder's customization only under a name ONE package holds, so under a name - * two hold it is the environment's own item, and that is what a read without - * the pass answers. Stamped, the store would file it into the host's slot — - * over that holder's own item when the host is one of the holders (a read - * naming it would answer the package-less body and `list` would drop its - * item), or as a third holder when it is not. The host's own file item of such - * a name is the host package's item and keeps the stamp, so its edit still - * reaches the host's slot and row over a row an earlier boot seeded from it. A - * name one package holds is not here, so its package-less row is stamped as - * before. Every other type: none. + * [#32521, #32812; epic #31527 red line 2, ADR-0150 D4] Whether the boot + * priming pass keeps the host's declared package off `item`: a package-less + * STORED ROW (an item `DatabaseLoader` handed on, no package on its column or + * body) of a type stored per `(package, name)`. Such a row is the + * environment's own item, or the customization of the one package that holds + * its name (D4), and the store files it where it files any write that carries + * no package. Stamped with the host's package, the registry filed it into the + * host's slot while the loaders still stored it package-less: the host was + * counted as a holder it is not (a third holder beside two packages, #32521; + * a second beside one, which after a package-less write named the host in + * the bare read's refusal, #32812), and a read naming the host served the + * environment's row. Unstamped, every read answers what it answers on a host + * that declares no package. The host's own file items, and every other + * type's items, are stamped as before. */ -function contestedNames(type: string, items: unknown[]): ReadonlySet { - if (!PACKAGE_SLOTTED_STORE_TYPES.has(type) || isBundledStoreType(type)) return new Set(); - // `pluralEntryKeys` keys a name no package or one package holds once (a - // package-less item beside one holder takes that holder's key, D4), and a - // name two or more packages hold once per holder: a name of two or more - // keys is a name two or more packages hold. - const keysOf = new Map>(); - const names = items.map((item) => (item as { name?: unknown } | null)?.name); - pluralEntryKeys(type, items.map((item, at) => ({ name: names[at], data: item }))).forEach((key, at) => { - const name = names[at]; - if (key === undefined || typeof name !== 'string') return; - keysOf.set(name, (keysOf.get(name) ?? new Set()).add(key)); - }); - return new Set([...keysOf].filter(([, keys]) => keys.size > 1).map(([name]) => name)); +function unstampedStoredRow(type: string, item: unknown, loader: string | undefined): boolean { + return PACKAGE_SLOTTED_STORE_TYPES.has(type) && storedItemPackageId(item) === undefined && loader === STORED_ROW_LOADER; } /** @@ -1774,7 +1759,7 @@ function contestedNames(type: string, items: unknown[]): ReadonlySet { * customization and answer a read naming that package; registered before * them, the first one's item would take its bare slot over and `list` would * drop it. With the host's package stamp kept off such an item - * (`contestedNames`), the registry holds what a read without the pass + * (`unstampedStoredRow`), the registry holds what a read without the pass * answers, whatever order the loaders handed the items in and whatever * package the host declares. A name one package holds * hands on one item, whose order does not move. Every other type: as handed. From ec483d4fcb174f4a0d29ce7a94745a05ef26f55f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 02:46:38 +0000 Subject: [PATCH 2/4] fix(metadata): declare every moved answer of the unstamped stored row, and the one face that widens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The changeset now declares the removal moving on every by-package type, the reads naming a package that holds nothing, email_template's slot, the loadMany caller the read-time filing covered, the statements of the #32791 note that no longer hold, and the one widening against the last release (Clause-② yes, narrowing). Pin the email_template composition; comments only otherwise. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgVHhRMN8oWxaL4Ph3X --- ...2-boot-pass-leaves-stored-row-unstamped.md | 23 +++++++++++------- .../src/loaders/database-loader.test.ts | 24 ++++++++++++++++++- packages/metadata/src/plugin.ts | 12 +++++----- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md index 022f18c8151..0cce0b92dcc 100644 --- a/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md +++ b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md @@ -4,21 +4,28 @@ fix(metadata)!: the boot priming pass leaves a package-less stored row of a type stored per `(package, name)` unstamped, so the host's package is never counted as a holder of its name (ADR-0150 D4) -Clause-②: no (narrowing) — on a host that declares its package (`MetadataPlugin`'s `packageId`) and wires a `DatabaseLoader`, a package-less `sys_metadata` row of `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping` or `dataset` is no longer served as the host package's item after the boot priming pass: its body no longer carries `_packageId` set to the host's package or `_provenance: 'package'`, the metadata list filtered by the host's package (`?package=` naming it) no longer lists it, and `publishPackage`, `revertPackage` and `unregisterPackage` naming the host's package no longer take it as one of that package's items. The `409` this lifts (the bare read naming the host's package, which holds nothing, after a write that carries no package) is #32560's, which has not shipped. +Clause-②: yes (narrowing) — one face widens against the last release and the others narrow, all on a host that declares its package and wires a `DatabaseLoader`; the widening is named under the BREAKING banner below. Narrows: on a host that declares its package (`MetadataPlugin`'s `packageId`) and wires a `DatabaseLoader`, a package-less `sys_metadata` row of `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping` or `dataset` is no longer served as the host package's item after the boot priming pass: its body no longer carries `_packageId` set to the host's package or `_provenance: 'package'`, the metadata list filtered by the host's package (`?package=` naming it) no longer lists it, and `publishPackage`, `revertPackage` and `unregisterPackage` naming the host's package no longer take it as one of that package's items. The `409` this lifts (the bare read naming the host's package, which holds nothing, after a write that carries no package) is #32560's, which has not shipped. Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is which package the boot pass gives a stored row that names none. - + -**BREAKING** for a host that declares its package and stores rows that name no package for one of these ten types. Such a row is the environment's own item, or the customization of the one package that holds its name (ADR-0150 D4); it was never the host package's, but the boot pass stamped it so. To keep an item in the host's package, save it naming that package (`?package=` on the write, or `packageId` on `register`). A row whose stored body an earlier release's boot pass wrote the host's stamp into is still read as the host package's (its column is bound from that body), and is not moved. Every other type, and the host's own file items, are stamped as before. No first-party package, app or example declares a package and wires a `DatabaseLoader`. +**BREAKING** for a host that declares its package and stores rows that name no package for one of these ten types. Such a row is the environment's own item, or the customization of the one package that holds its name (ADR-0150 D4); it was never the host package's, but the boot pass stamped it so. To keep an item in the host's package, save it naming that package (`?package=` on the write, or the package stamped on the item `register` is given). A row whose stored body an earlier release's boot pass wrote the host's stamp into is still read as the host package's (its column is bound from that body), and is not moved. Every other type, and the host's own file items, are stamped as before. + +The one widening, a behaviour change for the same reason (ADR-0150 D4, and the answer a host that declares no package already gives): a package-less stored row of these types is no longer hidden when the host's own package is disabled, as on a host that declares no package. + +What reads the stamp moves with it: such a row with a `protection` block is locked from `'artifact'` rather than `'package'` (`_lock` kept), an MCP skill or agent face built from it is named by its own name rather than the host's namespace, and the realtime events of the boot pass carry no package for it. No first-party package, app or example declares a package and wires a `DatabaseLoader`. Moved answers, all on such a host, each now the answer the same composition gives on a host that declares no package: -- One package's row and a package-less row saved last (`action`): after `register` with no package, or `registerInMemory` of a package-less item, the bare `get` and `getDiagnosed` go from `409 RESOURCE_CONFLICT` naming the host's package, the holder and the environment to the written item. The removal naming no package goes from that `409` to removing the package-less row, so it names the holders the bare read names. -- The same composition, every one of the ten types: the registry holds the package-less row in the name's bare slot, not the host's; a read naming the holder answers its customization (the package-less row) where it answered the holder's own row; on a host declaring the holder's package, a read naming another package that holds nothing answers the package-less row, as the bare read does. +- One package's row and a package-less row saved last (`action`): after `register` with no package, or `registerInMemory` of a package-less item, the bare `get` and `getDiagnosed` go from `409 RESOURCE_CONFLICT` naming the host's package, the holder and the environment to the written item. +- The removal naming no package, the same composition: right after the pass and after such a write, it goes from a `409` naming the host's package to removing the package-less row, for every one of the ten types (`email_template`: the holder's slot), so it names the holders the bare read names. +- The same composition, the nine unbundled types: the registry holds the package-less row in the name's bare slot, not the host's, and a read naming the holder answers its customization (the package-less row) where it answered the holder's own row. `list` names the row once, package-less, where it named it twice (its customization and, again, the host's), so a consumer that counts the holders `list` names counts one holder where it counted two. +- A read naming a package that holds nothing (the host's own, on a host declaring the holder's package; any third package, on a host declaring another): it answers the package-less row (or the item written over it), as the bare read does, where it answered nothing. The other way, the read naming the host's package goes from the package-less row to nothing where a package's item registered in memory sits beside that row, and for `email_template` beside one package's row: the host's package holds nothing there. - A package-less row and one package's `action` item registered in memory after the pass: the bare read answers that package's item, where it answered the package-less row (the by-host difference #32752 tracked). - The package-less row deleted from the table behind the manager: the bare read answers the registry's copy, where it was refused naming the host's package and the holder. -- `email_template`, one package's row and a package-less row: the bare read after the pass is no longer refused naming the host's package. +- `email_template`, one package's row and a package-less row: the pass files the package-less row in the holder's slot (its customization) and no longer in the host's, so the bare read after the pass is no longer refused naming the host's package. +- A package-less `action` row alone, removed with no package: the registry's stamped copy no longer outlives the row (it answered reads and `list` until a restart). -This replaces #32791's read-time filing of the stamped row (`MetadataManager`'s record of stored package-less rows, its overwrite mark and the judged view's filing), which has nothing left to file and is removed; every #32791 pin marked CONTROL passes unchanged. Candidate order in a refusal is not promised. +This replaces #32791's read-time filing of the stamped row (`MetadataManager`'s record of stored package-less rows, its overwrite mark and the judged view's filing), which has nothing left to file for the boot pass and is removed; every #32791 pin marked CONTROL passes unchanged. Of #32791's own changeset, which ships in the same release, three statements no longer hold: the filing it describes is gone, a read naming a package is no longer unchanged (above), and its "after the pass" cell (a package-less row, a package's item registered in memory after the pass) answers that package's item. One caller the filing also covered moves back: a caller of the public `MetadataManager.loadMany` that stamps a package-less row it is handed with a package itself and registers it is now refused naming that package beside the name's holder, as after any write (no first-party caller does so). Candidate order in a refusal is not promised. -Skills-docs: none — `skills/**` and `content/docs/**` do not teach that the boot pass gives a stored row the host's package; the migration step ships here and in the upgrade notes. +Skills-docs: none — `skills/**` and `content/docs/**` do not teach that the boot pass gives a stored row the host's package; the migration step ships in this note and is carried into the release's upgrade notes when they are written. diff --git a/packages/metadata/src/loaders/database-loader.test.ts b/packages/metadata/src/loaders/database-loader.test.ts index 75e7310b0bb..9571ff71a2a 100644 --- a/packages/metadata/src/loaders/database-loader.test.ts +++ b/packages/metadata/src/loaders/database-loader.test.ts @@ -2074,7 +2074,10 @@ describe('[#31699 R5-A] the priming pass never writes back a row it read from th * CONTROL was refused naming `com.host.app`. The CONTROLs answer on that * `main` as here. Where #32812 moved a #32791 pin, its comment names the * FROM (`main` `25ee5076`) and the TO, which is the cell's answer on a host - * that declares no package. + * that declares no package. The comments and titles of the unmoved pins + * (the "stamped row", its overwrite mark, the judged view's filing, the + * earlier heads they cite) describe #32791's read-time mechanism, which + * #32812 removed; their answers hold unchanged with the row unstamped. */ describe('[#32791] a stored package-less row the boot pass files under the host\'s package is one holder of an action name, not two', () => { const ALPHA = 'com.alpha.app'; @@ -2528,6 +2531,25 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ } expect(seen).toEqual(UNBUNDLED.flatMap((type) => [[type, HOST, 'written'], [type, 'none', 'written']])); }); + + /** + * [#32812] `email_template` (bundled), one package's row and a package-less + * row saved last: the pass files the package-less row in the holder's slot + * (its customization), on a host declaring another package as on one + * declaring none. FROM `main` `25ee5076`: the host's slot beside the + * holder's, and the bare read refused naming the holder and the host. + */ + it('email_template, one package\'s row and a package-less row saved last: the pass files the row in the holder\'s slot and the bare read answers it, on a host declaring another package as on one declaring none', async () => { + const seen: unknown[] = []; + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seed('email_template', ALPHA, 1); + await seed('email_template', null, 2); + const m = await bootPass(hostPackage); + seen.push([hostPackage ?? 'none', registryKeys(m, 'email_template'), await answer(m, 'email_template')]); + } + expect(seen).toEqual([[HOST, [`${ALPHA}\u0000helper`], 'env'], ['none', [`${ALPHA}\u0000helper`], 'env']]); + }); }); /** diff --git a/packages/metadata/src/plugin.ts b/packages/metadata/src/plugin.ts index 3cb7b0131ad..c75ad4514ce 100644 --- a/packages/metadata/src/plugin.ts +++ b/packages/metadata/src/plugin.ts @@ -1729,17 +1729,17 @@ const STORED_ROW_LOADER = 'database'; /** * [#32521, #32812; epic #31527 red line 2, ADR-0150 D4] Whether the boot * priming pass keeps the host's declared package off `item`: a package-less - * STORED ROW (an item `DatabaseLoader` handed on, no package on its column or - * body) of a type stored per `(package, name)`. Such a row is the + * STORED ROW (an item `DatabaseLoader` handed on that names no package, as + * `loadMany` hands it on) of a type stored per `(package, name)`. Such a row is the * environment's own item, or the customization of the one package that holds * its name (D4), and the store files it where it files any write that carries * no package. Stamped with the host's package, the registry filed it into the * host's slot while the loaders still stored it package-less: the host was * counted as a holder it is not (a third holder beside two packages, #32521; * a second beside one, which after a package-less write named the host in - * the bare read's refusal, #32812), and a read naming the host served the - * environment's row. Unstamped, every read answers what it answers on a host - * that declares no package. The host's own file items, and every other + * the bare read's refusal, #32812), and the read naming the holder served + * the holder's own row over its customization. Unstamped, every read answers + * what it answers on a host that declares no package. The host's own file items, and every other * type's items, are stamped as before. */ function unstampedStoredRow(type: string, item: unknown, loader: string | undefined): boolean { @@ -1758,7 +1758,7 @@ function unstampedStoredRow(type: string, item: unknown, loader: string | undefi * package-less item would be filed into the first one's slot as its * customization and answer a read naming that package; registered before * them, the first one's item would take its bare slot over and `list` would - * drop it. With the host's package stamp kept off such an item + * drop it. With the host's package stamp kept off a package-less stored row * (`unstampedStoredRow`), the registry holds what a read without the pass * answers, whatever order the loaders handed the items in and whatever * package the host declares. A name one package holds From 317349aed3328a51b2feae3934d08bcb7b5ef761 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 04:02:53 +0000 Subject: [PATCH 3/4] fix(metadata): the boot pass tells a stored-row loader by its datasource: protocol, and pins the narrowing arm's answers Contract review r1 of #33006: M1, a loader that declares the datasource: protocol under another name than DatabaseLoader's had its package-less rows stamped with the host's package again. MetadataManager gains sourceLoaderProtocolOf beside sourceLoaderOf; the pass keys on it. S1: pins for the served row's stamps, list, unregisterPackage and publishPackage naming the host's package, and a lone package-less action row removed with no package. N1, N2: changeset wording. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgVHhRMN8oWxaL4Ph3X --- ...2-boot-pass-leaves-stored-row-unstamped.md | 4 +- .../src/loaders/database-loader.test.ts | 81 +++++++++++++++++++ packages/metadata/src/metadata-manager.ts | 12 +++ packages/metadata/src/plugin.ts | 15 ++-- 4 files changed, 103 insertions(+), 9 deletions(-) diff --git a/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md index 0cce0b92dcc..6284b4d871b 100644 --- a/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md +++ b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md @@ -4,7 +4,7 @@ fix(metadata)!: the boot priming pass leaves a package-less stored row of a type stored per `(package, name)` unstamped, so the host's package is never counted as a holder of its name (ADR-0150 D4) -Clause-②: yes (narrowing) — one face widens against the last release and the others narrow, all on a host that declares its package and wires a `DatabaseLoader`; the widening is named under the BREAKING banner below. Narrows: on a host that declares its package (`MetadataPlugin`'s `packageId`) and wires a `DatabaseLoader`, a package-less `sys_metadata` row of `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping` or `dataset` is no longer served as the host package's item after the boot priming pass: its body no longer carries `_packageId` set to the host's package or `_provenance: 'package'`, the metadata list filtered by the host's package (`?package=` naming it) no longer lists it, and `publishPackage`, `revertPackage` and `unregisterPackage` naming the host's package no longer take it as one of that package's items. The `409` this lifts (the bare read naming the host's package, which holds nothing, after a write that carries no package) is #32560's, which has not shipped. +Clause-②: yes (narrowing) — one face widens against the last release and the others narrow, all on a host that declares its package and wires a `DatabaseLoader`; the widening is named under the BREAKING banner below. Adds one method to the exported `MetadataManager`, `sourceLoaderProtocolOf(item)` (the protocol of the loader `loadMany` read an item from), which the pass asks. Narrows: on a host that declares its package (`MetadataPlugin`'s `packageId`) and wires a `DatabaseLoader` (or another loader of the `datasource:` protocol), a package-less stored row of `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping` or `dataset` is no longer served as the host package's item after the boot priming pass: its body no longer carries `_packageId` set to the host's package or `_provenance: 'package'`, the metadata list filtered by the host's package (`?package=` naming it) no longer lists it, and `publishPackage`, `revertPackage` and `unregisterPackage` naming the host's package no longer take it as one of that package's items (where the host's package itself holds the name, the row is that package's customization, ADR-0150 D4, and goes with its slot as for any holder). The `409` this lifts (the bare read naming the host's package, which holds nothing, after a write that carries no package) is #32560's, which has not shipped. Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is which package the boot pass gives a stored row that names none. @@ -13,7 +13,7 @@ Metadata-protocol: none — no key, value or metadata type an author writes chan The one widening, a behaviour change for the same reason (ADR-0150 D4, and the answer a host that declares no package already gives): a package-less stored row of these types is no longer hidden when the host's own package is disabled, as on a host that declares no package. -What reads the stamp moves with it: such a row with a `protection` block is locked from `'artifact'` rather than `'package'` (`_lock` kept), an MCP skill or agent face built from it is named by its own name rather than the host's namespace, and the realtime events of the boot pass carry no package for it. No first-party package, app or example declares a package and wires a `DatabaseLoader`. +Among the readers of the stamp, these move with it (the list is not complete; every one of them reads the row as a host that declares no package does): such a row with a `protection` block is locked from `'artifact'` rather than `'package'` (`_lock` kept), an MCP skill or agent face built from it is named by its own name rather than the host's namespace, and the realtime events of the boot pass carry no package for it. A loader of stored rows is told by its `datasource:` protocol, as #32791's filing told it, so a loader that declares the protocol under a name other than `DatabaseLoader`'s is treated the same. No first-party package, app or example declares a package and wires a `DatabaseLoader`. Moved answers, all on such a host, each now the answer the same composition gives on a host that declares no package: diff --git a/packages/metadata/src/loaders/database-loader.test.ts b/packages/metadata/src/loaders/database-loader.test.ts index 9571ff71a2a..cfc6274dc87 100644 --- a/packages/metadata/src/loaders/database-loader.test.ts +++ b/packages/metadata/src/loaders/database-loader.test.ts @@ -2550,6 +2550,87 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ } expect(seen).toEqual([[HOST, [`${ALPHA}\u0000helper`], 'env'], ['none', [`${ALPHA}\u0000helper`], 'env']]); }); + + /** + * [#32812, contract review r1 M1] A loader of stored rows is told by its + * protocol (`datasource:`), not by `DatabaseLoader`'s name: a loader that + * declares the protocol under another name hands out package-less rows the + * pass leaves unstamped too. FROM `main` `25ee5076`: right after the pass + * the bare read answered the package-less row (#32791's filing keyed on the + * protocol), and after a register with no package it was refused naming the + * host's package; at this PR's first head (keyed on the name) it was + * refused right after the pass as well. TO: the package-less row, then the + * written body, as through `DatabaseLoader`. + */ + it('action, the card\'s composition through a stored-row loader that declares `datasource:` under another name: the pass leaves the row unstamped, and the bare read answers it, then the written body', async () => { + await seedRows([[ALPHA], [null]]); + const plugin = new MetadataPlugin({ packageId: HOST, watch: false, config: { bootstrap: 'eager' } }); + const m = (plugin as any).manager as MetadataManager; + (m as any).loaders.clear(); + const loader = new DatabaseLoader({ driver }); + (loader as any).contract = { ...loader.contract, name: 'tenant-rows' }; + m.registerLoader(loader); + await (plugin as any)._loadFromFileSystem({ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() } }); + expect(registryKeys(m, 'action')).toEqual(['helper']); + expect(await bareAnswers(m)).toEqual(['env', 'env']); + await m.register('action', 'helper', { name: 'helper', label: 'written' }); + expect(await bareAnswers(m)).toEqual(['written', 'written']); + }); + + /** + * [#32812, contract review r1 S1] The narrowing arm's own answers, on a host + * declaring another package beside one declaring none, after the pass: the + * served package-less row carries no `_packageId` or `_provenance`, `list` + * names it once, and the package-wide verbs naming the host's package do + * not take it. FROM `main` `25ee5076`: stamped with the host's package and + * `_provenance: 'package'`, listed twice beside the holder's row (its + * customization and the host's), dropped from the registry by + * `unregisterPackage` and published (its row rebound to the host's package) + * by `publishPackage`. TO: as on a host that declares no package. Whether a + * disabled host package hides the row is read by `@objectstack/core` and + * `@objectstack/runtime` off the served `_packageId`, not pinned here. + */ + it('action, one package\'s row and a package-less row saved last: the served row carries no stamp, list names it once, and unregisterPackage or publishPackage naming the host\'s package leaves it, as on a host declaring none', async () => { + const seen: Record = {}; + for (const hostPackage of [HOST, undefined]) { + const stamps = async (m: MetadataManager) => { + const item = (await m.get('action', 'helper')) as Record | undefined; + return [item?._packageId, item?._provenance]; + }; + const listed = async (m: MetadataManager) => ((await m.list('action')) as Array<{ label?: string }>).map((item) => item.label).sort(); + const tableOf = async () => ((await driver.find('sys_metadata', { where: { type: 'action' } } as any)) as Array>) + .map((row) => [row.package_id ?? null, row.version]).sort(); + driver = createMockDriver(); + await seedRows([[ALPHA], [null]]); + const m = await bootPass(hostPackage); + const before = [await stamps(m), await listed(m)]; + const published = await m.publishPackage(HOST).then((r: any) => r?.success, (e: any) => e?.code ?? 'threw'); + const afterPublish = await tableOf(); + await m.unregisterPackage(HOST); + seen[hostPackage ?? 'none'] = [...before, published, afterPublish, await bareAnswers(m), await tableOf()]; + } + expect(seen[HOST]).toEqual(seen.none); + expect(seen.none).toEqual([[undefined, undefined], ['env'], false, [[null, 2], [ALPHA, 1]], ['env', 'env'], [[null, 2], [ALPHA, 1]]]); + }); + + /** + * [#32812, contract review r1 S1] A package-less `action` row alone, + * removed with no package after the pass: nothing of it is left to read. + * FROM `main` `25ee5076`: the row deleted, the registry's copy stamped with + * the host's package left in the host's slot, answering the bare read and + * `list` until a restart. TO: as on a host that declares no package. + */ + it('action, a package-less row alone removed with no package after the pass: the bare read and list answer nothing, on a host declaring another package as on one declaring none', async () => { + const seen: unknown[] = []; + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seedRows([[null]]); + const m = await bootPass(hostPackage); + await m.unregister('action', 'helper'); + seen.push([hostPackage ?? 'none', await answer(m, 'action'), (await m.list('action')).length, registryKeys(m, 'action')]); + } + expect(seen).toEqual([[HOST, undefined, 0, []], ['none', undefined, 0, []]]); + }); }); /** diff --git a/packages/metadata/src/metadata-manager.ts b/packages/metadata/src/metadata-manager.ts index 09e65b1dcbe..a708557f235 100644 --- a/packages/metadata/src/metadata-manager.ts +++ b/packages/metadata/src/metadata-manager.ts @@ -3712,6 +3712,18 @@ export class MetadataManager implements IMetadataService { return this.loadedFrom.get(item)?.contract.name; } + /** + * [#32812] The protocol of the loader {@link loadMany} read `item` — that + * very object — from (`'datasource:'` for a loader of stored rows, + * `DatabaseLoader` or another that declares the protocol under its own + * name); `undefined` for an object it did not hand out. The boot priming + * pass asks it to keep the host's package off a package-less stored row + * (`MetadataPlugin`'s pass). + */ + sourceLoaderProtocolOf(item: object): string | undefined { + return this.loadedFrom.get(item)?.contract.protocol; + } + /** * Load multiple metadata items from loaders. * Aggregates results from all loaders. diff --git a/packages/metadata/src/plugin.ts b/packages/metadata/src/plugin.ts index c75ad4514ce..c42d084bd1e 100644 --- a/packages/metadata/src/plugin.ts +++ b/packages/metadata/src/plugin.ts @@ -1687,7 +1687,7 @@ export class MetadataPlugin implements Plugin { // by its write rule (`unstampedStoredRow`). The // host's own file item is stamped as before. applyProtection(meta, { - packageId: unstampedStoredRow(entry.type, meta, this.manager.sourceLoaderOf(meta)) + packageId: unstampedStoredRow(entry.type, meta, this.manager.sourceLoaderProtocolOf(meta)) ? undefined : this.options.packageId, }); @@ -1723,14 +1723,15 @@ export class MetadataPlugin implements Plugin { } } -/** The loader whose items are stored rows: `DatabaseLoader`'s `contract.name`. */ -const STORED_ROW_LOADER = 'database'; +/** The protocol of a loader whose items are stored rows: `DatabaseLoader`'s, and any loader's that declares it. */ +const STORED_ROW_PROTOCOL = 'datasource:'; /** * [#32521, #32812; epic #31527 red line 2, ADR-0150 D4] Whether the boot * priming pass keeps the host's declared package off `item`: a package-less - * STORED ROW (an item `DatabaseLoader` handed on that names no package, as - * `loadMany` hands it on) of a type stored per `(package, name)`. Such a row is the + * STORED ROW (an item a `datasource:` loader, `DatabaseLoader` or another of + * that protocol, handed on that names no package, as `loadMany` hands it on) + * of a type stored per `(package, name)`. Such a row is the * environment's own item, or the customization of the one package that holds * its name (D4), and the store files it where it files any write that carries * no package. Stamped with the host's package, the registry filed it into the @@ -1742,8 +1743,8 @@ const STORED_ROW_LOADER = 'database'; * what it answers on a host that declares no package. The host's own file items, and every other * type's items, are stamped as before. */ -function unstampedStoredRow(type: string, item: unknown, loader: string | undefined): boolean { - return PACKAGE_SLOTTED_STORE_TYPES.has(type) && storedItemPackageId(item) === undefined && loader === STORED_ROW_LOADER; +function unstampedStoredRow(type: string, item: unknown, protocol: string | undefined): boolean { + return PACKAGE_SLOTTED_STORE_TYPES.has(type) && storedItemPackageId(item) === undefined && protocol === STORED_ROW_PROTOCOL; } /** From 65ab9b2b5a58299e4f4f8124347b8d84c171819c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 04:19:00 +0000 Subject: [PATCH 4/4] test(metadata): type the S1 table read's options as never, not any (#32812) The query-options erasure ratchet counted the S1 pin's driver.find options cast to any as a 237th test site. Use the file's own as never idiom. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgVHhRMN8oWxaL4Ph3X --- packages/metadata/src/loaders/database-loader.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/metadata/src/loaders/database-loader.test.ts b/packages/metadata/src/loaders/database-loader.test.ts index cfc6274dc87..a58ddba2032 100644 --- a/packages/metadata/src/loaders/database-loader.test.ts +++ b/packages/metadata/src/loaders/database-loader.test.ts @@ -2598,7 +2598,7 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ return [item?._packageId, item?._provenance]; }; const listed = async (m: MetadataManager) => ((await m.list('action')) as Array<{ label?: string }>).map((item) => item.label).sort(); - const tableOf = async () => ((await driver.find('sys_metadata', { where: { type: 'action' } } as any)) as Array>) + const tableOf = async () => ((await driver.find('sys_metadata', { where: { type: 'action' } } as never)) as Array>) .map((row) => [row.package_id ?? null, row.version]).sort(); driver = createMockDriver(); await seedRows([[ALPHA], [null]]);