Repository navigation
Commit 4db1992
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
- .changeset
- packages/metadata/src
- loaders
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2930 | 2930 | | |
2931 | 2931 | | |
2932 | 2932 | | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
657 | 668 | | |
658 | 669 | | |
659 | 670 | | |
| |||
2674 | 2685 | | |
2675 | 2686 | | |
2676 | 2687 | | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
2677 | 2692 | | |
2678 | 2693 | | |
2679 | 2694 | | |
| |||
2686 | 2701 | | |
2687 | 2702 | | |
2688 | 2703 | | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
2689 | 2708 | | |
2690 | 2709 | | |
2691 | 2710 | | |
| |||
2704 | 2723 | | |
2705 | 2724 | | |
2706 | 2725 | | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
2707 | 2740 | | |
2708 | 2741 | | |
2709 | 2742 | | |
| |||
3845 | 3878 | | |
3846 | 3879 | | |
3847 | 3880 | | |
3848 | | - | |
3849 | | - | |
| 3881 | + | |
| 3882 | + | |
| 3883 | + | |
| 3884 | + | |
3850 | 3885 | | |
3851 | 3886 | | |
3852 | 3887 | | |
| |||
0 commit comments