Skip to content

Commit 4db1992

Browse files
fix(metadata): unregistering the host package keeps the environment's own object, view, app, hook and dashboard rows (#32999)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuKZ12EQWmY4AzjWP4Xt7x17)_ Fixes #32986 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:宿主声明了自己的包并接了数据库存储时,启动时会给环境自己存的无包行(object、view、app、hook、dashboard 等)打上宿主的包印记。现在 `unregisterPackage(宿主包)` 不再把这些环境行当成宿主的东西删掉,内存里和数据库里都保留。 - 为什么改:#32198(尚未发版)让按包卸载开始读 `_packageId` 印记,于是卸载宿主包会把环境自己的数据一起删掉。这是 18.4.0 发版前必须堵上的数据丢失(p1)。 - 风险与回滚:印记本身不动,所以 ObjectQL 仍把这类 object 记为宿主包的贡献,其它读印记的地方答案都不变。宿主自己的条目(存储体里带宿主印记的行、代码或文件注册的宿主条目)照旧被卸载。按 `(package, name)` 存的十种类型不在本 PR 内(归 #32812)。回滚即 revert 本 PR。 - 先看:`packages/metadata/src/metadata-manager.ts`(`unregisterPackage` 里新加的 `isStampedEnvironmentRow` 一行,以及 `loadMany` 里给环境行做标记的那几行)。 - 两分钟验证:`pnpm --filter @objectstack/metadata exec vitest run --maxWorkers=2 src/loaders/database-loader.test.ts -t 32986`,预期 4 条全部通过。 - 需要你做的:无,席位落地。 ## What changes On a host that declares its package and wires a `DatabaseLoader`, the boot priming pass (`MetadataPlugin._loadFromFileSystem`) runs `applyProtection` with the host's package on every item it is handed. That includes a stored row whose body names no package, so the row gets `_packageId: HOST` and `_provenance: 'package'`. Since #32198, `MetadataManager.unregisterPackage` selects a package's items by `isPackageMember`, which also reads `_packageId`. For a type not stored per `(package, name)`, `unregisterPackage(HOST)` therefore removed every such row: the registry entry, the stored row (through each removal-target loader's `delete`), and a `deleted` announcement. The card left two ways to fix this. This PR keeps the stamp and leaves the stamped environment rows out of the removal: - `loadMany` already records, for the package-slotted types, the items a `datasource:` loader handed on naming no package (`storedPackagelessRows`, #32791). It now records the same thing for every other type in a separate `storedEnvironmentRows` set. The record is made before any caller stamps the item, so the two mechanisms stay apart. - `unregisterPackage`, for a type not stored per `(package, name)`, skips an item that is in `storedEnvironmentRows` and whose only claim to the package is `_packageId` (`isStampedEnvironmentRow`). An item whose own `packageId` or `package` names the package stays a member. Stopping the stamp would have changed the owner ObjectQL registers an environment object under (`_packageId ?? 'metadata-service'` at `packages/objectql/src/plugin.ts` L1865 on reload and L1942 on refresh) from the host's package to `metadata-service`, and with it every reader of the stamp. Keeping the stamp moves no answer except this removal. `packages/objectql` is not touched. ### FROM → TO | # | `unregisterPackage(HOST)` on a host declaring `HOST`, with the environment's own package-less stored row of… | FROM (`main` `cae2179a`) | TO | |---|---|---|---| | 1 | `object` | registry entry removed, stored row deleted, `deleted` announced | kept: registry entry, stored row, no announcement | | 2 | `view` | the same | kept | | 3 | `app` | the same | kept | | 4 | `hook` | the same | kept | | 5 | `dashboard` | the same | kept | The rule is not limited to these five. It covers every type outside `PACKAGE_SLOTTED_STORE_TYPES` that the pass stamps. The pins cover the five the card names. **The limit (triage should-fix S1).** A row is kept when the boot pass marked it and nothing has rewritten it since. It is not true that every such row of these types is kept. The mark is on the item object the pass registered. A later write can replace that item with a copy still stamped `_packageId: HOST`. That drops the mark and stores the stamp into the row's body through `DatabaseLoader.save`, and `unregisterPackage(HOST)` then deletes the row again, in this process and after a restart. Two such writes exist on the head, both outside this diff: - ObjectQL's late-manifest bridge: the `ownPreviousCopy` re-register and `restoreExtendedObjectCopies`; - `publishPackage` / `revertPackage` of the host. #33003 (p1, under #32986) closes that before the release that ships #32198. These are unchanged and pinned as CONTROLs: - the stamp: each row is still registered with `_packageId: HOST`; - the host's own row (its stored body carries `_packageId: HOST`, as a host item the pass seeded is stored) is still removed from the registry and from storage; - the host's own row whose stored body names it through the legacy `package` key (`package: HOST`) is still removed, as 18.3.0 removed it (triage should-fix S2); - an item registered in memory for the host is still removed; - `unregisterPackage` of another package leaves the rows alone; - on a host declaring no package, the rows stay unstamped and are left alone. Clause-②, re-derived after measuring: `no`. In the released 18.3.0, `isPackageMember` did not read `_packageId` (#32198 has not shipped), so `unregisterPackage(HOST)` left these rows in place. This PR keeps that answer, and the stamp and every reader of it answer as before. Metadata-protocol, re-derived: `none`. No `packages/metadata-protocol` file is touched and no protocol answer moves. ## Acceptance notes - **Owed item 1 (readers), measured on `main` `cae2179a`.** `_packageId` / `_provenance` appear on 597 non-test lines across 16 packages. This diff does not change the stamp: `applyProtection` and the priming pass are untouched. So no reader's answer for a stamped environment row moves except `unregisterPackage`'s. The readers the card named first: - the ObjectQL object contribution (`plugin.ts` L1865 reload, L1942 refresh) answers `HOST` for a stamped environment object, before and after; - the boot bridge (`bridgeObjectsToMetadataService`) skips an object the metadata service already holds, so it does not replace the marked item. The late-manifest bridge (`bridgeManifestObjectsToMetadataService`) does replace it, through `ownPreviousCopy`, when another package extends the object (triage S1, #33003); - authoring writes through the protocol carry no provenance keys (`protocol-tenant-authored-write.ts` refuses them), so an edited environment row is registered unstamped. The remaining lines were not answered one by one. The argument for them is the untouched stamp, not a line-by-line reading. - **Measured, not in this PR, reported to the seat.** `collectPackageMembers` (`publishPackage` / `revertPackage`) uses the same `isPackageMember`, so a stamped environment row is still a member of the host's publish and revert. That rule dates from #22113 (released), not #32198. The publish and revert doors refuse a non-writable package first. Not changed here: the card names only the removal. - **Order with #32812** (`domain:server#7`, claim 6840443478). Its claimed file surface (`metadata-manager.ts`, `plugin.ts`, `package-slotted-store.ts`) intersects this PR's `metadata-manager.ts`. The overlap is file surface only. Triage judged landing first safe (N3), and the seat released the order, so this PR does not wait for #32812. The two changes cover separate type sets: the ten package-slotted types are #32812's, every other type is this PR's. - First-party count: no first-party caller of `MetadataManager.unregisterPackage` in the repo (`git grep` on `main`: the method, the `IMetadataService` contract's optional member, and `MetadataFacade`'s own unrelated method). The removal is reached through the public service contract. ## Tests - `packages/metadata/src/loaders/database-loader.test.ts`: a new `[#32986]` describe with five cases. Each runs the real priming pass over a `DatabaseLoader` on the file's in-memory driver, with one row each of `object`, `view`, `app`, `hook` and `dashboard`: - stamped environment rows are kept by `unregisterPackage(HOST)` (red on `main`: all five removed); - an in-memory host item is removed while the environment rows are kept (red on `main`: both removed); - CONTROL: the host's own stamped-body rows are removed; - CONTROL: the host's own rows naming it by the legacy `package` key are removed (S2); - CONTROL: another package's unregister, and a host declaring no package. - Red on `main` (the test committed, the fix not yet written): 2 failed, 2 passed. The failure was the after-removal assertion, and the stamp assertion before it passed. - Ablation (fix committed first, through `scripts/ablation-replace.mjs`): deleting the `isStampedEnvironmentRow` guard line in `unregisterPackage` gave 2 failed (both pins) and 2 passed (both CONTROLs). Mutation landed: anchor 1 → 0, blob `2fd11c336850` → `b18647fd8ed1`. Restore verified: blob equal to `HEAD` (`2fd11c336850`), `git diff HEAD` empty. The suite imports `../metadata-manager.js` from source, so no rebuild is involved. - Ablation for S2 (same script, at `a43fc250`): dropping `&& meta.package !== packageId` from `isStampedEnvironmentRow` gave 1 failed (the legacy `package` CONTROL) and 4 passed. Mutation landed: anchor 1 → 0, blob `2fd11c336850` → `047f2c687c84`. Restore verified: blob equal to `HEAD`, `git diff HEAD` empty. ## Verification On head `a43fc250` (branch `claude/project-thread-im2gsb`, `origin/main` `c1a645e2` merged once, by merge, at `9a891ae9`). Two commits come after the merge: a test-only one at `426f47c9`, and the S2 pin with the changeset's limit text at `a43fc250`. <details><summary>Local runs</summary> - On `a43fc250`, the families the S1/S2 commit touches (the test file and the changeset) re-ran, all exit 0. `database-loader.test.ts`: 276 passed (276). The families: `check:query-options-erasure`, `check:type-check-debt`, `check:type-check-coverage`, `check:test-source-alias`, `check:where-matcher`, `check:engine-double-contract`, `check:cross-package-test-inputs`, `check:tier-file-adoption`, `check:nul-bytes`, `check:issue-citations`, `check:keyed-text-bounds`, `check-empty-changeset`, `check-changeset-no-major`, `check-adr-0087-registration`, `check-closing-keyword-parity`, `check:closed-ceremony-text`, `check:doc-authoring`, `check-affected-docs`. The full derived list below ran at the earlier heads. - `pnpm --filter @objectstack/metadata exec vitest run --maxWorkers=2 src/loaders/database-loader.test.ts`: 275 passed (275), on `426f47c9`. - `pnpm --filter @objectstack/metadata test` then `typecheck` (through `scripts/pm/os-verify-lock.sh`), with the dependency closure rebuilt after the merge: Test Files 76 passed (76), Tests 2088 passed (2088); `tsc --noEmit` exit 0. Run on `9a891ae9`. `426f47c9` changes one cast in the new test, and the file was re-run above. - `node scripts/pm/dispatch-gates.mjs --ran`: 64 derived, 64 run, 0 NOT-MEASURED, 0 UNRUN, every family recorded with its exit code (all 0, a derived zero). The full list ran on `9a891ae9`: - `check:query-options-erasure` answered 1 there: the new test's stored-row read was cast `as any`, which grew the test surface 236 → 237. It is now cast `as never`, as the file's other reads are, at `426f47c9`. - The families that read the test file ran again on `426f47c9`, all exit 0: `check:query-options-erasure`, `check:type-check-debt`, `check:type-check-coverage`, `check:test-source-alias`, `check:where-matcher`, `check:engine-double-contract`, `check:cross-package-test-inputs`, `check:tier-file-adoption`, `check:nul-bytes`, `check:issue-citations`, `check:keyed-text-bounds`. - `check-plugin-teardown-shape --self-test`, `check:dual-build-cjs-loads` and `check:lean-entry-closure` first answered exit 3: the clone was shallow and the build was not complete. They ran again after `git fetch --unshallow` and a packages build, and all three exited 0. </details> CI on this head: see the check runs. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic (not touched). - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` runs in CI on the final head. - [x] 4. One issue, one branch, one pull request. - [x] 5. A change that publishes carries a changeset (`@objectstack/metadata` patch), and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` not touched. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgThzreKNjha83MypKs)_ <!-- signed: domain:server#4 · os-sales · session_01L6bhgWRcTEB3toGxnWvuvX --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent cf1b55c commit 4db1992

3 files changed

Lines changed: 157 additions & 2 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/metadata': patch
3+
---
4+
5+
fix(metadata): unregistering the host package keeps the environment's own object, view, app, hook and dashboard rows
6+
7+
Clause-②: no — no released answer moves: `unregisterPackage` reads the `_packageId` stamp since #32198, which has not shipped, and with this change it leaves the environment's own rows the boot pass marked, as the released version does. The boot pass's stamp, and every reader of it, answer as before.
8+
Metadata-protocol: none
9+
10+
On a host that declares its package and stores metadata in a database, the boot pass stamps each stored row that names no package with the host's package. For a type not stored per `(package, name)` — `object`, `view`, `app`, `hook`, `dashboard` and the rest — that stamp stays, so ObjectQL still registers such an object as the host package's contribution. But `MetadataManager.unregisterPackage(host)` took the stamp as membership and deleted those rows, from memory and from the database: the environment's own items were lost when the host package was unregistered.
11+
12+
`unregisterPackage` now leaves an item that a stored-row loader handed on naming no package and that names the package only by the stamp. The host's own items (a row whose stored body carries the host's stamp or names it under the legacy `package` key, an item registered for the host in memory or from files) are removed as before. Types stored per `(package, name)` are unchanged here.
13+
14+
The limit: a row is kept when the boot pass marked it and nothing has rewritten it since. The mark is on the item the pass registered. A later write that replaces that item with a copy still stamped with the host (ObjectQL's late-manifest bridge, `publishPackage` and `revertPackage` of the host) drops the mark and stores the stamp in the row, and `unregisterPackage(host)` then deletes that row again. #33003 closes that before the release that ships #32198.

‎packages/metadata/src/loaders/database-loader.test.ts‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,3 +2930,109 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => {
29302930
expect((await new DatabaseLoader({ driver }).loadManyKeyed('email_template')).map((entry) => entry.packageId)).toEqual([ALPHA, BETA]);
29312931
});
29322932
});
2933+
2934+
/**
2935+
* [#32986; follow-up of #32198, ADR-0150 D4] On a host that declares its
2936+
* package, the boot priming pass stamps a package-less stored row of a type
2937+
* NOT stored per `(package, name)` (`object`, `view`, `app`, `hook`,
2938+
* `dashboard` …) with the host's package (`applyProtection`), and the stamp
2939+
* stays: an `object` row so stamped is still registered by ObjectQL as the
2940+
* host package's contribution (`_packageId ?? 'metadata-service'`). But since
2941+
* #32198 `unregisterPackage` selects a package's items by `_packageId` too,
2942+
* so `unregisterPackage(host)` deleted the environment's own rows — the
2943+
* registry entry and the stored row both. The removal now leaves an item a
2944+
* stored-row loader handed on naming no package, whose only claim to the
2945+
* package is the stamp the pass put on it.
2946+
*
2947+
* BEFORE (`main`): every case below not marked CONTROL lost the row (the
2948+
* registry entry gone, the stored row deleted). The CONTROLs answer on `main`
2949+
* as here.
2950+
*/
2951+
describe('[#32986] unregisterPackage of the host package keeps the environment\'s own rows the boot pass stamped with the host', () => {
2952+
const HOST = 'com.host.app';
2953+
const OTHER = 'com.other.app';
2954+
/** One name per type, each a name the type's own write rule keeps as it is. */
2955+
const ITEMS: ReadonlyArray<readonly [type: string, name: string]> = [
2956+
['object', 'env_account'], ['view', 'env_account.all'], ['app', 'env_app'], ['hook', 'env_hook'], ['dashboard', 'env_dashboard'],
2957+
];
2958+
let driver: IDataDriver;
2959+
2960+
const seed = (type: string, name: string, packageId: string | null, body: Record<string, unknown> = {}) =>
2961+
driver.create('sys_metadata', {
2962+
id: `${type}_${name}_${packageId ?? 'env'}`, type, name, state: 'active', version: 1, checksum: `${type}_${name}_${packageId ?? 'env'}`,
2963+
source: 'database', package_id: packageId, metadata: JSON.stringify({ name, label: packageId ?? 'env', ...body }),
2964+
});
2965+
/** The real pass over one database loader, on a host that declares `hostPackage`. */
2966+
const bootPass = async (hostPackage?: string) => {
2967+
const plugin = new MetadataPlugin({ ...(hostPackage ? { packageId: hostPackage } : {}), watch: false, config: { bootstrap: 'eager' } });
2968+
const m = (plugin as any).manager as MetadataManager;
2969+
(m as any).loaders.clear();
2970+
m.registerLoader(new DatabaseLoader({ driver }));
2971+
await (plugin as any)._loadFromFileSystem({ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() } });
2972+
return m;
2973+
};
2974+
/** Per item: the registry's stamp, what a read answers, and whether its stored row is still there. */
2975+
const state = async (m: MetadataManager) => {
2976+
const out: unknown[] = [];
2977+
for (const [type, name] of ITEMS) {
2978+
const held = (m as any).registry.get(type)?.get(name) as { _packageId?: string } | undefined;
2979+
const read = (await m.get(type, name)) as { label?: string } | undefined;
2980+
const rows = await driver.find('sys_metadata', { where: { type, name } } as never);
2981+
out.push([type, held?._packageId ?? null, read?.label ?? null, rows.length]);
2982+
}
2983+
return out;
2984+
};
2985+
2986+
beforeEach(() => {
2987+
driver = createMockDriver();
2988+
});
2989+
2990+
it('package-less rows of object, view, app, hook and dashboard, on a host declaring its package: the pass stamps them with the host as before, and unregisterPackage(host) keeps each registry entry and stored row (BEFORE: every one deleted)', async () => {
2991+
for (const [type, name] of ITEMS) await seed(type, name, null);
2992+
const m = await bootPass(HOST);
2993+
const primed = ITEMS.map(([type]) => [type, HOST, 'env', 1]);
2994+
expect(await state(m), 'the stamp, as before: the object contribution owner does not move').toEqual(primed);
2995+
await m.unregisterPackage(HOST);
2996+
expect(await state(m)).toEqual(primed);
2997+
});
2998+
2999+
it('CONTROL the host\'s own rows (their bodies carry the host\'s stamp, as a host item the pass seeded is stored): unregisterPackage(host) still removes each, from the registry and storage', async () => {
3000+
for (const [type, name] of ITEMS) await seed(type, name, null, { _packageId: HOST });
3001+
const m = await bootPass(HOST);
3002+
expect(await state(m)).toEqual(ITEMS.map(([type]) => [type, HOST, 'env', 1]));
3003+
await m.unregisterPackage(HOST);
3004+
expect(await state(m)).toEqual(ITEMS.map(([type]) => [type, null, null, 0]));
3005+
});
3006+
3007+
/**
3008+
* [#32986, review S2] The legacy `package` key is the item's own claim, as
3009+
* 18.3.0's `unregisterPackage` read it: the row is the host's, though its
3010+
* stored body names no package the store's reads index (`_packageId`).
3011+
*/
3012+
it('CONTROL the host\'s own rows naming it through the legacy `package` key in their stored bodies: unregisterPackage(host) still removes each, from the registry and storage', async () => {
3013+
for (const [type, name] of ITEMS) await seed(type, name, null, { package: HOST });
3014+
const m = await bootPass(HOST);
3015+
expect(await state(m)).toEqual(ITEMS.map(([type]) => [type, HOST, 'env', 1]));
3016+
await m.unregisterPackage(HOST);
3017+
expect(await state(m)).toEqual(ITEMS.map(([type]) => [type, null, null, 0]));
3018+
});
3019+
3020+
it('an item registered in memory for the host (code) beside the environment\'s rows: unregisterPackage(host) removes the host\'s item and keeps the environment\'s (BEFORE: both removed)', async () => {
3021+
for (const [type, name] of ITEMS) await seed(type, name, null);
3022+
const m = await bootPass(HOST);
3023+
await m.registerInMemory('object', 'host_thing', { name: 'host_thing', label: 'code', _packageId: HOST });
3024+
await m.unregisterPackage(HOST);
3025+
expect(await m.get('object', 'host_thing')).toBeUndefined();
3026+
expect(await state(m)).toEqual(ITEMS.map(([type]) => [type, HOST, 'env', 1]));
3027+
});
3028+
3029+
it('CONTROL unregisterPackage of another package, and a host declaring no package: the environment\'s rows are untouched, unstamped on the second', async () => {
3030+
for (const [type, name] of ITEMS) await seed(type, name, null);
3031+
const m = await bootPass(HOST);
3032+
await m.unregisterPackage(OTHER);
3033+
expect(await state(m)).toEqual(ITEMS.map(([type]) => [type, HOST, 'env', 1]));
3034+
const bare = await bootPass();
3035+
await bare.unregisterPackage(HOST);
3036+
expect(await state(bare)).toEqual(ITEMS.map(([type]) => [type, null, 'env', 1]));
3037+
});
3038+
});

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,17 @@ export class MetadataManager implements IMetadataService {
654654
* one with the host's package before it registers it ({@link slotViewOf}).
655655
*/
656656
private readonly storedPackagelessRows = new WeakSet<object>();
657+
/**
658+
* [#32986] The items of every OTHER type (one not stored per
659+
* `(package, name)`: `object`, `view`, `app`, `hook`, `dashboard` …) that
660+
* {@link loadMany} read from a stored-row loader (`datasource:`) naming no
661+
* package: the environment's own rows. The boot priming pass stamps one with
662+
* the host's declared package (`_packageId`), and the stamp stays — ObjectQL
663+
* registers such an `object` as the host package's contribution — but the
664+
* row is not the package's item, so {@link unregisterPackage} leaves it
665+
* ({@link isStampedEnvironmentRow}).
666+
*/
667+
private readonly storedEnvironmentRows = new WeakSet<object>();
657668
/**
658669
* [ADR-0150 D4, #32791] The {@link storedPackagelessRows} whose registration
659670
* replaced an item no loader handed out (one registered in memory or by
@@ -2674,6 +2685,10 @@ export class MetadataManager implements IMetadataService {
26742685
* `(package, name)` drops this package's slot and keeps another package's
26752686
* same-named item — and, for such a type, the storage half deletes only this
26762687
* package's row and the `deleted` event names this package.
2688+
*
2689+
* [#32986] Of every other type, an environment row the boot priming pass
2690+
* stamped with this package (the host's) is not one of its items, and stays
2691+
* ({@link isStampedEnvironmentRow}).
26772692
*/
26782693
async unregisterPackage(packageName: string): Promise<void> {
26792694
// Collect all items to delete (type and name pairs). [#32517] One entry
@@ -2686,6 +2701,10 @@ export class MetadataManager implements IMetadataService {
26862701
for (const [key, data] of typeStore) {
26872702
// [#32246] A by-package type: also every item in the package's slot,
26882703
// a package-less customization of its item (D4) included.
2704+
// [#32986] Not the environment's own row the boot pass stamped with
2705+
// this package: since #32198 the stamp alone made it a member, and the
2706+
// removal deleted it from the registry and from storage.
2707+
if (!slotted && this.isStampedEnvironmentRow(data, packageName)) continue;
26892708
if (isPackageMember(data, packageName) || (slotted && slotPackageOf(key) === packageName)) {
26902709
const slot = `${type}\u0000${slotOfKey(key)}`;
26912710
const entry = itemsToDelete.get(slot);
@@ -2704,6 +2723,20 @@ export class MetadataManager implements IMetadataService {
27042723
}
27052724
}
27062725

2726+
/**
2727+
* [#32986] Whether `data` is one of the {@link storedEnvironmentRows} that
2728+
* names `packageId` only by the `_packageId` stamp — the boot priming pass's
2729+
* host stamp, which `applyProtection` writes on an unstamped item alone. The
2730+
* row's own body named no package when the loader handed it on, so
2731+
* `packageId` / `package` naming the package is the item's own claim (the
2732+
* row is the package's, as {@link isPackageMember} reads it).
2733+
*/
2734+
private isStampedEnvironmentRow(data: unknown, packageId: string): boolean {
2735+
if (data === null || typeof data !== 'object' || !this.storedEnvironmentRows.has(data)) return false;
2736+
const meta = data as { packageId?: unknown; package?: unknown; _packageId?: unknown };
2737+
return meta._packageId === packageId && meta.packageId !== packageId && meta.package !== packageId;
2738+
}
2739+
27072740
/**
27082741
* [#22113] The registry items that belong to `packageId`, for the two
27092742
* package-wide writes ({@link publishPackage}, {@link revertPackage}).
@@ -3845,8 +3878,10 @@ export class MetadataManager implements IMetadataService {
38453878
if (item !== null && typeof item === 'object') {
38463879
this.loadedFrom.set(item, loader);
38473880
// [#32791] Read here, before any caller stamps it.
3848-
if (PACKAGE_SLOTTED_STORE_TYPES.has(type) && loader.contract.protocol === 'datasource:' && indexedItemPackageId(item) === undefined) {
3849-
this.storedPackagelessRows.add(item);
3881+
if (loader.contract.protocol === 'datasource:' && indexedItemPackageId(item) === undefined) {
3882+
if (PACKAGE_SLOTTED_STORE_TYPES.has(type)) this.storedPackagelessRows.add(item);
3883+
// [#32986] Read here too, before the boot pass stamps it.
3884+
else this.storedEnvironmentRows.add(item);
38503885
}
38513886
}
38523887
});

0 commit comments

Comments
 (0)