Repository navigation
Commit dd966fc
fix(metadata)!: MetadataManager.loadMany takes a by-package name's bodies and packages off the loader's keyed entries; loadManyKeyed entries carry their package (#33299)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDZYUbJbnXUTqZoZ56k4czR)_
Fixes #32680
Clause-②: yes (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill teaches how `MetadataManager`'s plural
reads stamp a loader's bodies or what `loadManyKeyed` entries carry; the
moved answers live in the metadata service's internal read path.
## 维护者速读
- 改了什么:`MetadataManager.loadMany` 对按包存放的类型,直接用加载器 keyed 条目里每行自己的 body
和包戳,不再按内容把 `loadMany` 的 body 配回行;`loadManyKeyed` 返回的条目带上 `packageId`。
- 为什么改:两个包同名、另有一行 body 也写着这个名字时,旧的内容配对放弃打戳,启动预载把一个 body 放进裸槽,启动后裸读答出这个
body 而不是 409;加载器两次读序列化不同也会无声不打戳;调用方拿到两个同名条目分不清是哪个包。
- 风险与回滚:只影响接了 `DatabaseLoader` 的宿主(工作区内 0 处);该形状下启动后裸读由答一个 body 改为 409
点名两个包(收窄,已声明);库里的行不动。回滚 = revert 本 PR。
- 先看:`packages/metadata/src/metadata-manager.ts` 的 `keyedEntryBodies`(风险
hunk:剩余 body 的按值比较只决定保留,不决定包);同文件
`keyedEntryOf`;`packages/metadata/src/loaders/database-loader.test.ts`
末尾的 `[#32680]` describe。
- 两分钟验证:`pnpm --filter @objectstack/metadata exec vitest run
src/loaders/database-loader.test.ts -t 32680`,预期 54 个用例全绿(本 PR 新增 53
个,加改写的 #32458 用例 1 个)。
- 需要你做的:无,席位落地。#32681(包外绑对象的 action 行该归哪个键)另需你拍板,见下方 Acceptance notes。
## What changes
`MetadataManager.loadMany`, for an unbundled type stored per `(package,
name)` (`PACKAGE_SLOTTED_STORE_TYPES`) on a loader that holds items per
package (`loadManySlots`: `DatabaseLoader`, the artifact door's
`MemoryLoader`), now hands on each keyed entry's own body, stamped
(`_packageId`) with the package the loader holds that entry for when the
body carries the entry's key as its `name` (`keyedEntryBodies`). It no
longer pairs `loader.loadMany`'s bodies to the keyed entries by their
`JSON.stringify` (the former `withLoaderEntryPackages`). Bodies the
keyed read cannot name (a row whose `name` column is empty) are still
handed on after them, unstamped: they are `loadMany`'s bodies less one
per keyed entry whose body is the same value (key order aside), so the
comparison decides only what is kept, never a package, and it runs only
when `loadMany` answers more bodies than the keyed read.
`MetadataManager.loadManyKeyed` entries carry `packageId` where the
loader's entry carries one (`keyedEntryOf`), for the slotted path and
the bundled one (`email_template`).
Every moved answer, FROM to TO (the changeset carries the same list):
| Shape (host wiring a `DatabaseLoader`) | Read | FROM | TO |
|:--|:--|:--|:--|
| Name two packages hold, beside another row whose body says the name
(F2) | `MetadataManager.loadMany` | one body, unstamped | both holders
stamped with their own row's package, the other row's body unstamped |
| same | boot pass registry | the one body in the bare slot | each
package's slot, the other row's body in the bare slot |
| same | bare read after the pass | that body | `409 RESOURCE_CONFLICT`
naming both packages (for `action` also `platform`, see notes); the same
as without the pass |
| Name one package holds, beside another row whose body says the name |
`loadMany` / boot pass | unstamped, filed in the bare slot | stamped,
filed in the holder's slot |
| same | read naming a package that holds no row, after the pass | the
holder's body | nothing, as without the pass |
| Loader whose two reads serialise a body differently (F3) | `loadMany`
| both holders unstamped | both stamped |
| Any type stored per `(package, name)` |
`MetadataManager.loadManyKeyed` | `{ name, data }` | `{ name, data,
packageId }` where the loader holds it for a package |
Not changed: a name one package holds with no other row's body saying it
(CONTROL pins), a name no package holds, and a loader without
`loadManySlots`. The number of entries both plural reads hand on is
unchanged for every shape but F2, where the other row's body is now kept
beside both holders.
## Tests
New top-level describe `[#32680]` in
`packages/metadata/src/loaders/database-loader.test.ts` (53 cases): F2
per boot-pass type with the other row stored first and last (bare read
409 naming both after the pass; reads naming ALPHA, BETA, GAMMA equal
the cold read); F3 with a key-reordering loader, plus a row whose name
column is empty kept once; F4 per slotted type and `email_template`; one
holder beside another row's body (every read equals the cold read);
CONTROL one holder per type. The #32458 pin "two holders of a name and
another row's body that says the same name" moves FROM `[[null, ALPHA]]`
TO `[[ALPHA, ALPHA], [BETA, BETA], [null, ALPHA]]`, its title rewritten
to say so.
BEFORE, on main `d4fbb4db` with the same fixtures: 43 of the 53 new
cases red, the 10 CONTROLs green. The F2 bare read after the pass
answered `com.alpha.app` with registry keys `['helper']` for every type.
Downstream readers (`MetadataManager.loadMany` / `loadManyKeyed`
callers), consumer direction: objectql `action-governance`,
`metadata-sync-flow-two-holders`, `plugin-governance-scoped-metadata`,
`webhook-stored-row-boot-hydration` (59 passed); runtime
`action-activation-unpackaged`, `actions-addressed-route`,
`mcp-package-object-discovery`, `action-governance-scope-divergence`
(218 passed).
Ablations (each through `scripts/ablation-replace.mjs`, mutation landed
on disk and restored to the HEAD blob with `git diff HEAD` empty; the
suite reads `src/` by relative import, so no build leg):
1. the keyed read swapped back for `loader.loadMany` (no stamp at all):
42 red (the CONTROLs among them, since this drops every stamp), the 12
F4 cases green;
2. `keyedEntryOf` without `packageId`: the 12 F4 cases red, nothing
else;
3. the remainder compared by `JSON.stringify` instead of by value: the
F3 case red (the empty-name row handed on twice);
4. the remainder dropped: F3 and the two #32458 pins that keep an
empty-name row red.
## Acceptance notes
- **#32681 is not in this PR.** It is returned to the PM for a decision:
which key a package-less action row bound to an object takes beside two
packages that bind the name to different objects. Re-measured on this
branch (the shape does not move here): ALPHA `approve` on `account`,
BETA's on `contact`, a package-less one on `account`; the cold read
naming ALPHA answers ALPHA's row, after the boot pass it answers the
package-less row. The mirror shape moves too: one holder ALPHA on
`account` and a package-less row on `contact` hand on one row (the
package-less one, folded into ALPHA by the loader's per-name D4 rule),
so after the pass a read naming ALPHA answers the `contact` row where
the cold read answers ALPHA's `account` row. ADR-0150 D4's action key
`(package, objectName, name)` and its R15 row ("two holders → the
ambiguous set") read the shape two ways, so it is not settled here.
- For `action`, the F2 bare refusal after the pass also names
`platform`: the other row (stored under its own key) is registered under
its body's name in the bare slot, and an action name's package-less
registry slot that no loader stores under that name counts as the
platform's (#32560). The boot pass registering a stored row under its
body's `name` rather than its row key is unchanged here.
- No change in `packages/metadata-protocol/src/**` and none in
`packages/metadata/src/loaders/database-loader.ts` (open PR #33193 edits
it).
- Local gates were narrowed to the package's tests, typecheck, the new
pins and the ablations; the derived gate families run in CI.
## Verification
<details><summary>metadata suite and typecheck on fad580c</summary>
```text
pnpm --filter @objectstack/metadata test && pnpm --filter @objectstack/metadata typecheck
Test Files 77 passed (77)
Tests 2367 passed (2367)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Targeted gates run locally</summary>
```text
EXIT=0 node scripts/check-adr-0087-registration.mjs --base origin/main
EXIT=0 node scripts/check-changeset-no-major.mjs --base origin/main
EXIT=0 node scripts/check-empty-changeset.mjs --base origin/main
EXIT=0 pnpm check:nul-bytes
EXIT=0 pnpm check:durability-log-level
EXIT=0 pnpm check:doc-authoring
EXIT=0 pnpm check:issue-citations
EXIT=0 pnpm check:slot-lookup
EXIT=0 pnpm check:test-source-alias
EXIT=0 pnpm check:cross-package-test-inputs
EXIT=0 node scripts/check-closing-keyword-parity.mjs
```
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cyrFFk86Jqf7Mp5Rzw)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e92487f commit dd966fc
4 files changed
Lines changed: 261 additions & 81 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 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3191 | 3191 | | |
3192 | 3192 | | |
3193 | 3193 | | |
3194 | | - | |
| 3194 | + | |
3195 | 3195 | | |
3196 | 3196 | | |
3197 | 3197 | | |
| |||
3201 | 3201 | | |
3202 | 3202 | | |
3203 | 3203 | | |
3204 | | - | |
| 3204 | + | |
3205 | 3205 | | |
3206 | 3206 | | |
3207 | 3207 | | |
| |||
3573 | 3573 | | |
3574 | 3574 | | |
3575 | 3575 | | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
| 3647 | + | |
| 3648 | + | |
| 3649 | + | |
| 3650 | + | |
| 3651 | + | |
| 3652 | + | |
| 3653 | + | |
| 3654 | + | |
| 3655 | + | |
| 3656 | + | |
| 3657 | + | |
| 3658 | + | |
| 3659 | + | |
| 3660 | + | |
| 3661 | + | |
| 3662 | + | |
| 3663 | + | |
| 3664 | + | |
| 3665 | + | |
| 3666 | + | |
| 3667 | + | |
| 3668 | + | |
| 3669 | + | |
| 3670 | + | |
| 3671 | + | |
| 3672 | + | |
| 3673 | + | |
| 3674 | + | |
| 3675 | + | |
| 3676 | + | |
| 3677 | + | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
| 3693 | + | |
| 3694 | + | |
| 3695 | + | |
| 3696 | + | |
| 3697 | + | |
| 3698 | + | |
| 3699 | + | |
| 3700 | + | |
| 3701 | + | |
| 3702 | + | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
0 commit comments