Skip to content

Commit 84c66d3

Browse files
fix(metadata-protocol)!: enabling a second holder of an overlay name takes back the package-less row the read-side hydrator laid into the first holder's registry slot while the second was disabled (ADR-0150 D4) (#33149)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDUKRjQSg19phJJRHRL22WQ)_ Fixes #32820 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: none — `skills/**` and `content/docs/**` teach no registry read of a holder's item after a disable and enable; the prescription ships in the ADR-0087 entry and the changeset's FROM → TO. > **BREAKING** (narrowing, `minor` on `@objectstack/metadata-protocol`, ADR-0087 entry `package-less-overlay-row-holder-slot-on-reenable` registered): after a second holder of an overlay name is enabled again, a holder's registry item, its scoped list and its registry list stop answering the environment's package-less row as the holder's own. ## 维护者速读 - 改了什么:两个包 A、B 都持有同名的可覆盖条目(email_template、dashboard、report),环境里还有一条不带包的同名行。B 停用期间做一次不带包的列表读,读侧回填会把这条环境行按 A 的外壳放进 A 的槽位(这时 A 是唯一被服务的持有者,按 ADR-0150 D4 是对的);但 B 重新启用后没人把它收回,A 的 registry 槽位、带 A 的列表和执行列表一直把环境行当成 A 自己的答出来。现在启用 B 时立刻按当下两个持有者重建这条,A、B 各自答自己的条目。 - 为什么改:专题 #31527 红线 2(歧义要报、不能猜成某个持有者的);发送时读取、带包列表、执行列表直接读 registry,会用错正文。 - 风险与回滚:窄化(Clause-② no (narrowing),Metadata-protocol narrowed):仓内第一方组合没有两个包持有同名可覆盖条目加不带包行的情形,答案不变。只动内存 registry 槽位,不改任何键、值或存储形状;精确读(`?package=`)本来就 409 列出两者,不变。回滚即 revert 本 PR。 - 先看:`packages/metadata-protocol/src/protocol-registry-hydration.ts`(`recordSoleHolderEnvelope`、`healSoleHolderEnvelopes`、`HEALED_OVERLAY_TYPES`、`hydrateOverlayIntoRegistry` 里注册后的记录点);`packages/objectql/src/package-scoped-exact-qualifier.test.ts` 的 `[#32820]` 段;`packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts`。 - 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/package-scoped-exact-qualifier.test.ts -t 32820`,预期 11 个全部通过(三种类型 × 两种注册顺序、三条对照、持有方集合先换到另一方再到两方的一条、permission 行不被重建的一条)。 - 需要你做的:无,席位落地。 ## What changes While one of two holders of an overlay name is disabled, the other is the one served holder (#32183), so a package-less `sys_metadata` row of the name is its customization: the read-side hydrator (an unscoped list read, the boot load) lays the row into that holder's registry slot under its artifact envelope. Enabling the disabled holder ran no hydration, so until the next unscoped list read the holder's `getPackageScopedItem(type, name, holder)` (what a send-time read takes), its scoped list (`GET /meta/:type?package=HOLDER`) and the registry list scoped to it answered the environment's row as the holder's own (the registry list carried both). All in `packages/metadata-protocol/src/protocol-registry-hydration.ts`: - `hydrateOverlayIntoRegistry` records, per registry, each entry it registers for a package-less row under a sole holder's envelope (host, type, name, bundle member, row data, holder, and the registered object), for the three overlay types the narrowing declares only (`HEALED_OVERLAY_TYPES`: `email_template`, `dashboard`, `report`). Any other registration of the same key forgets the record. - The first record for a registry subscribes `healSoleHolderEnvelopes` to the registry's existing `onPackageEnabled` notice. On an enable it rebuilds each recorded entry exactly as the hydrator would build it for the holders served then (`soleHolderOf`): with two served, no holder's envelope, so each holder's slot answers its own item again. Synchronous inside the enable, so every enable door (`PATCH /packages/:id/enable`, an install's `enableOnInstall`) answers after it. - Identity guard: an entry the slot no longer holds as registered (a later write, delete or hydration replaced it) belongs to that write and is left alone; its record is dropped. Merged with `main` once (`bf02d33b`), which brought #33126's edit of the same file (the flow-slot gate judged against every shipper). The two touch different branches of `hydrateOverlayIntoRegistry` (that gate returns before registration; the record sits after it), merged without conflict, and every pin below was re-run and re-ablated on the merged head. The ADR-0087 entry's remedy and the changeset's FROM → TO were re-read against the remedy order that landed for #32968 (`152b53c77`) and now say the same: keep the package-less row's stored body and clear any row of the name bound to a package first, then delete the package-less row, then save the declared override in the holder's `.custom` pair. ### FROM → TO | case (two holders A and B of an overlay name, a package-less row stored) | FROM (`main`) | TO | |---|---|---| | B disabled, unscoped list read, B enabled: A's `getPackageScopedItem` | the environment's row, stamped A | A's own item | | same: list scoped to A (`GET /meta/:type?package=A`) | the environment's row | A's own item | | same: registry list scoped to A | A's own item and the environment's row | A's own item | | same: B's three readers | B's own item | B's own item (unchanged) | | protocol exact read `?package=A` | `409 ambiguous-in-closure` naming both | unchanged | Unchanged, pinned as CONTROLs: the healed slot equals the one the hydrator builds with both holders served; an enable that still leaves A the one served holder keeps the row as A's customization; an entry written over the slot after the hydration is untouched by the enable. ## Contract review round 1 (record 6864058135, PASS at `1484f1cd`): answers - **s1** (the record had no type list; a package-less `permission` row is a fourth type by reading): the record is limited to the three declared types (`HEALED_OVERLAY_TYPES`), so the change moves exactly what the changeset and the ADR-0087 entry name. Pinned: a package-less `permission` row reached through `admitSecondPermissionHolder` (two holders, B disabled, hydrated, B enabled) keeps the slot as the hydrator laid it. Red on `1484f1cd` (the heal rebuilt it: `expected { name: 'welcome', …(2) } to be { name: 'welcome', …(3) } // Object.is equality`), green with the limit, and red again with the limit ablated. - **s2** (the heal's fourth outcome ran in no pin): one pin runs A and B hold, B disabled, hydrated (A's slot: the row, stamped A), A disabled, B enabled (B's slot: the row, stamped B, so it was built again under B's envelope and recorded again), then A enabled (all three readers at both holders answer their own: the second heal). Under the heal ablation it is red at the B-alone step; with the re-record ablated it is red at the final step. - **n1** (no code change): named below with the install residue. ### Carried, not here (findings, not widened) - A holder **installed** (not re-enabled) after the hydration that ships the name: the slot keeps the row until the next unscoped hydration, as before. No registry notice reaches the protocol for a new holder; the fix needs `packages/objectql/src/registry.ts`, outside this card's file surface. Stated in the changeset's "Not changed". - When no holder is served at the enable (review n1), the heal rebuilds through the artifact lookup that names no package and drops the record, whatever envelope the rebuilt entry wears; if that lookup answers a disabled holder's artifact, a later enable has nothing to rebuild. This is what the hydrator itself would leave for that state; no code change here. - The remedy order: the package-less row must be deleted before the holder's `.custom` override is saved (run after, the same delete removes the override), and a save at `?package=HOLDER` on a code package answers `403 NOT_OVERRIDABLE` naming its pair. Both are written into the ADR-0087 entry. ## Tests - `packages/objectql/src/package-scoped-exact-qualifier.test.ts`, `[#32820]` describe (11): `email_template`, `dashboard`, `report` × both registration orders: B disabled, unscoped list read (A's slot reads the env row), B enabled: A's slot, stamp, scoped list and execution list answer A's own; B's answer B's own; the exact read still 409 `ambiguous-in-closure`. Three CONTROLs as above. Review round 1 added two: the holder set moving from A alone to B alone and then to both (s2), and a package-less `permission` row the enable leaves alone (s1). The `[#32568]` comment that named this gap now points here. - `packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts` and `protocol.register-item-call-sites.test.ts`: the call-site censuses record the heal's artifact lookup and registration. <details><summary>Pins on the merged head ffa02b3 (fix unchanged at 1484f1c)</summary> ``` pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/package-scoped-exact-qualifier.test.ts Test Files 1 passed (1) Tests 252 passed (252) pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 src/protocol.lookup-artifact-item-call-sites.test.ts src/protocol.register-item-call-sites.test.ts Test Files 2 passed (2) Tests 11 passed (11) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Round 2 ablations on head `8715fced` (same method)</summary> - **Type limit** (`&& HEALED_OVERLAY_TYPES.has(canonicalType)` widened to every type by a marker that is always true): `[#32820]` 1 failed, 10 passed: exactly the `permission` pin. Quote: `AssertionError: expected { name: 'welcome', …(2) } to be { name: 'welcome', …(3) } // Object.is equality`. - **Heal** again (enable listener a no-op): 8 failed, 3 passed: the six type × order pins, the "slot after the heal" CONTROL and the new s2 pin (`A disabled, B enabled: B alone served: expected [ 'beta own', 'com.acme.beta' ] to deeply equal [ 'env row', 'com.acme.beta' ]`); the two other CONTROLs and the `permission` pin stay green. - **Re-record** (the rebuilt entry under another sole holder's envelope never recorded again): 1 failed, 10 passed: the s2 pin at its last step (`both enabled: expected { slot: 'env row', …(3) } to deeply equal { slot: 'beta own', …(3) }`). That leg's build exited 1 (the declaration step), but the marker was proved present in `dist/index.js` and `dist/index.cjs` and the suite ran it; the restore rebuild exited 0. - Every restore: blob equal to HEAD, `git diff HEAD` empty, `--absent` preflight exit 0, tree clean. </details> <details><summary>Round 1 ablations on the merged head (fix committed first; scripts/ablation-replace.mjs; each leg rebuilt @objectstack/metadata-protocol and proved by ablation-dist-preflight; each restore: blob equal to HEAD, git diff HEAD empty, --absent preflight exit 0, tree clean)</summary> The objectql suite imports `@objectstack/metadata-protocol` through its `exports` (built `dist/`, no vitest alias), so each leg was rebuilt and the marker proved present in `dist/index.js` and `dist/index.cjs` before reading. - **Heal**: the enable listener made a no-op (`registry.onPackageEnabled(() => console.debug('ABLATION32820-HEAL', ...))`). `[#32820]`: 7 failed, 2 passed: all six type × order pins and the "slot after the heal" CONTROL; the two other CONTROLs (one served holder kept; later write untouched) stay green, as they should. Quote: `AssertionError: B enabled: expected { slot: 'env row', …(3) } to deeply equal { slot: 'alpha own', …(3) }`. - **Identity guard**: `registry.getItem(...) !== record.registered` replaced by a marker that is never true. `[#32820]`: 1 failed, 8 passed: exactly the "entry written over the slot after the hydration" CONTROL. Quote: `AssertionError: expected { name: 'welcome', …(5) } to be { name: 'welcome', …(5) } // Object.is equality`. - Restore legs: `ok restored: blob == HEAD (aa4ea15) and git diff HEAD is empty`; rebuild exit 0; `marker absent from all 24 built files`; `working tree clean against HEAD`. </details> ## Acceptance notes - Epic red lines: (1) resolution is not loosened: the exact read is unchanged and nothing refused is now served; (2) the ambiguity is no longer guessed into a holder's slot; (3) independently releasable: no key, column, URL or stored shape moves, the phase-1 one-holder tests in the same suite stay green, and bare-name behaviour is unchanged. - No new export: the heal is module-internal. ## Verification ### Round 2, head `8715fced` (review round 1 answers; no `main` merge: no conflict) - Gates reading the two files this round changes (`node scripts/pm/dispatch-gates.mjs --commands packages/metadata-protocol/src/protocol-registry-hydration.ts packages/objectql/src/package-scoped-exact-qualifier.test.ts`, 57 commands) plus `@objectstack/metadata-protocol` and `@objectstack/objectql` test + typecheck: 61 of 61 exit 0. - Dogfood battery: `8715fced` · `pnpm --filter @objectstack/dogfood test` under the lock, no shard, no path · `VERDICT command-exit 0` · Test Files 460 passed, 3 skipped (463) · Tests 3886 passed, 42 skipped (3928) · no failures. <details><summary>Round 2 --ran file (COMMAND :: exit CODE)</summary> ``` node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-engine-split-ratio.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-status-conformance :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:object-def-param-keys :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:optional-error-sink :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 pnpm --filter @objectstack/metadata-protocol test :: exit 0 pnpm --filter @objectstack/metadata-protocol typecheck :: exit 0 pnpm --filter @objectstack/objectql test :: exit 0 pnpm --filter @objectstack/objectql typecheck :: exit 0 ``` </details> ### Round 1, head `1484f1cd` All local readings on head `1484f1cd` (after the one `main` merge and the remedy-text commit). - Full build first (`pnpm turbo run build --concurrency=2`: 120/120 successful), which is the precondition `check:dual-build-cjs-loads` exited 3 on at the pause; it now exits 0. - `node scripts/pm/dispatch-gates.mjs --ran FILE`: `✓ dispatch-gates --ran: 89 derived famil(ies) accounted for — 89 run, 0 NOT-MEASURED`. - `check-plugin-teardown-shape --self-test` first exited 3 on this shallow clone (its positive control is pinned to commit `621a4876`, not fetched); after fetching that commit it exits 0 (48 cases pass). - `pnpm lint`: exit 0. - Affected packages: `@objectstack/metadata-protocol` test + typecheck, `@objectstack/objectql` test + typecheck, `@objectstack/spec` `src/migrations` tests + typecheck: all exit 0. - Dogfood battery: `1484f1cd` · `pnpm --filter @objectstack/dogfood test` under the lock, no shard, no path · `VERDICT command-exit 0` · Test Files 460 passed, 3 skipped (463) · Tests 3886 passed, 42 skipped (3928) · no failures. <details><summary>--ran file (COMMAND :: exit CODE)</summary> ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dev-prereqs.mjs --self-test :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-engine-split-ratio.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm --filter @objectstack/spec run check:api-surface :: exit 0 pnpm --filter @objectstack/spec run check:authorable-surface :: exit 0 pnpm --filter @objectstack/spec run check:browser-reachable-entries :: exit 0 pnpm --filter @objectstack/spec run check:docs :: exit 0 pnpm --filter @objectstack/spec run check:dual-source-exports :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:empty-state :: exit 0 pnpm --filter @objectstack/spec run check:entry-nameability :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm --filter @objectstack/spec run check:export-origins :: exit 0 pnpm --filter @objectstack/spec run check:exported-any :: exit 0 pnpm --filter @objectstack/spec run check:liveness :: exit 0 pnpm --filter @objectstack/spec run check:llms-txt :: exit 0 pnpm --filter @objectstack/spec run check:skill-refs :: exit 0 pnpm --filter @objectstack/spec run check:spec-changes :: exit 0 pnpm --filter @objectstack/spec run check:strictness-ledger :: exit 0 pnpm --filter @objectstack/spec run check:upgrade-guide :: exit 0 pnpm --filter @objectstack/spec run check:variant-docs :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-status-conformance :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:merge-driver :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:object-def-param-keys :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:optional-error-sink :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:pm-prior-rulings :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:role-word :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:spec-docblock-symbol-anchors :: exit 0 pnpm check:spec-parsed-alias :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 pnpm lint :: exit 0 pnpm --filter @objectstack/metadata-protocol test :: exit 0 pnpm --filter @objectstack/metadata-protocol typecheck :: exit 0 pnpm --filter @objectstack/objectql test :: exit 0 pnpm --filter @objectstack/objectql typecheck :: exit 0 pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2 src/migrations :: exit 0 pnpm --filter @objectstack/spec typecheck :: exit 0 ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4d1H7jxfU2FWB3HDdbs)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4d1H7jxfU2FWB3HDdbs <!-- signed: epic:#31527#2 · os-elon-musk · session_016WV4czFhtRVZNBeHdQA6PW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 89d7bef commit 84c66d3

7 files changed

Lines changed: 321 additions & 6 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
docs(spec): the protocol upgrade guide names what a holder's registry item answers after a second holder of an overlay name is enabled again: its own item, not the package-less row the hydrator laid in while the second was disabled (ADR-0150 D4)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The semantic entry `package-less-overlay-row-holder-slot-on-reenable` (`packages/spec/src/migrations/entries/semantic/18.package-less-overlay-row-holder-slot-on-reenable.ts`) registers the narrowing `.changeset/32820-reenable-heals-holder-slot.md` declares (ADR-0087, `adr-0087: registered`): no automatic rewrite, because which holder a package-less row customizes is a judgement only its author can make. It adds no key and no export.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/metadata-protocol': minor
3+
---
4+
5+
fix(metadata-protocol)!: enabling a second holder of an overlay name takes back the package-less row the read-side hydrator laid into the first holder's registry slot while the second was disabled (ADR-0150 D4)
6+
7+
Clause-②: no (narrowing) — a served answer that guessed a holder goes away: after the enable, a holder's registry item, its scoped list and its registry list answer the holder's own item where they answered the environment's package-less row as the holder's own. Nothing that was refused is now served, and no export is added (the heal is module-internal).
8+
Metadata-protocol: narrowed
9+
Skills-docs: none — `skills/**` and `content/docs/**` teach no registry read of a holder's item after a disable and enable; the prescription ships in the FROM → TO below.
10+
11+
<!-- adr-0087: registered package-less-overlay-row-holder-slot-on-reenable -->
12+
13+
**BREAKING** for a registry reader of a holder's item of an overlay-type name (`email_template`, `dashboard`, `report`) that another installed package also holds, when a package-less `sys_metadata` row of the name is stored: `getPackageScopedItem(type, name, holder)` (what a send-time read takes), the list scoped to the holder (`GET /meta/:type?package=<holder>`) and the registry list scoped to it.
14+
15+
While one of the two holders is disabled, the other is the one served holder (#32183), so the package-less row is its customization: the read-side hydrator (an unscoped list read, the boot load) lays the row into that holder's slot under its envelope. Enabling the disabled holder ran no hydration, so the slot kept the row, and until the next unscoped list read the holder's registry item and its scoped list answered the environment's row as the holder's own, and its registry list listed both. The protocol's exact read (`?package=<holder>`) already refused it `409` naming both holders.
16+
17+
The enable now builds the entry again, as the hydrator builds it for the holders served then: with two served, no holder's envelope, so each holder's slot answers its own item, as when the hydrator ran with both served. It runs inside the enable, so every enable door (`PATCH /packages/:id/enable`, an install's `enableOnInstall`) answers after it. An entry another write replaced after the hydration is that write's, and is not touched.
18+
19+
Not changed: the disabled period itself (the one served holder's slot serves the row, as #32183 rules), the exact reads, and a package installed after the hydration that ships the name (the slot keeps the row until the next unscoped hydration, as before: no registry notice reaches the protocol for a new holder).
20+
21+
No first-party composition has two packages holding one overlay name with a package-less row, so no answer changes in this repository.
22+
23+
The fix:
24+
25+
- FROM a package-less overlay row of a name two packages hold, read as one holder's own through the registry after a disable and enable, TO the declared override of that holder in its paired `.custom` package (`?package=<holder>.custom` with `overrides: { package: <holder>, basedOn }`), saved after deleting the package-less row (a package-less delete removes the one bound row there is, so after the save it would remove the override). Before that delete, keep the package-less row's stored body and clear any row of the name bound to a package, as `package-less-row-exact-address-by-type-class` prescribes: the delete hard-deletes the row, and with a bound row present it addresses that row instead.

‎packages/metadata-protocol/src/protocol-registry-hydration.ts‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,102 @@ function soleHolderOf(registry: { packageScopedHoldersOf?(type: string, name: st
170170
return holders[0];
171171
}
172172

173+
/**
174+
* [#32820] A package-less row of a name ONE package held when the read-side
175+
* hydrator laid it in, under that holder's artifact envelope
176+
* ({@link soleHolderOf}): what the registry entry was built from, so it can be
177+
* built again when the holder set changes.
178+
*/
179+
interface SoleHolderEnvelope {
180+
readonly host: Pick<ProtocolHost, 'lookupArtifactItem'>;
181+
readonly type: string;
182+
readonly canonicalType: string;
183+
readonly name: string;
184+
readonly member: string | undefined;
185+
readonly data: unknown;
186+
/** The holder whose envelope the entry wears. */
187+
readonly holder: string;
188+
/** The entry as registered: the heal touches the slot only while it still holds this object. */
189+
readonly registered: unknown;
190+
}
191+
192+
/** The engine's registry, as the hydrator reads it (its registration is the hydrator's own call, untyped there too). */
193+
type EnvelopeRegistry = {
194+
readonly [member: string]: any;
195+
getItem?(type: string, name: string, currentPackageId?: string, member?: string): unknown;
196+
packageScopedHoldersOf?(type: string, name: string): readonly string[] | undefined;
197+
onPackageEnabled?(listener: (packageId: string) => void): () => void;
198+
};
199+
200+
/**
201+
* [#32820] The overlay types whose package-less row the heal rebuilds: the
202+
* three the narrowing declares (its changeset and ADR-0087 entry
203+
* `package-less-overlay-row-holder-slot-on-reenable`). A package-less
204+
* `permission` row also wears its sole holder's envelope, but two holders of a
205+
* permission set are refused by the registry today; when that rule opens, the
206+
* heal widens to it only in a change that declares it (contract review s1).
207+
*/
208+
const HEALED_OVERLAY_TYPES: ReadonlySet<string> = new Set(['email_template', 'dashboard', 'report']);
209+
210+
/** Per registry, the {@link SoleHolderEnvelope} of each bare-slot key (`type`, `name`, member). */
211+
const soleHolderEnvelopes = new WeakMap<object, Map<string, SoleHolderEnvelope>>();
212+
213+
const envelopeKey = (type: string, name: string, member: string | undefined) => `${type}\u0000${name}\u0000${member ?? ''}`;
214+
215+
/**
216+
* [#32820, ADR-0150 D4] Record (or, with no `holder`, forget) the envelope a
217+
* package-less row's registry entry wears. The first record for a registry
218+
* subscribes {@link healSoleHolderEnvelopes} to its package enables.
219+
*/
220+
function recordSoleHolderEnvelope(registry: EnvelopeRegistry, key: string, envelope: SoleHolderEnvelope | undefined): void {
221+
let records = soleHolderEnvelopes.get(registry);
222+
if (envelope === undefined) {
223+
records?.delete(key);
224+
return;
225+
}
226+
if (records === undefined) {
227+
if (typeof registry.onPackageEnabled !== 'function') return;
228+
const created = new Map<string, SoleHolderEnvelope>();
229+
records = created;
230+
soleHolderEnvelopes.set(registry, created);
231+
registry.onPackageEnabled(() => healSoleHolderEnvelopes(registry, created));
232+
}
233+
records.set(key, envelope);
234+
}
235+
236+
/**
237+
* [#32820, ADR-0150 D4] A package-less overlay row the read-side hydrator laid
238+
* into a holder's slot while that holder alone was served (another holder of
239+
* the name disabled) wears that holder's envelope, so the registry reads it
240+
* as that holder's own item (`getPackageScopedItem`, the scoped list, the
241+
* execution list). An enable that serves a second holder makes it a
242+
* customization no holder can claim: the entry is built again as the
243+
* hydrator builds it for the holders served now (none's envelope with two),
244+
* so each holder's slot answers its own item again, as with no hydration in
245+
* the disabled period. Synchronous, inside the enable, so every enable door
246+
* (`PATCH /packages/:id/enable`, an install's `enableOnInstall`) answers
247+
* after it.
248+
*
249+
* Only an entry the slot still holds as registered: a later write, delete or
250+
* hydration replaced it and owns the slot.
251+
*/
252+
function healSoleHolderEnvelopes(registry: EnvelopeRegistry, records: Map<string, SoleHolderEnvelope>): void {
253+
for (const [key, record] of [...records]) {
254+
if (typeof registry.getItem !== 'function'
255+
|| registry.getItem(record.type, record.name, undefined, record.member) !== record.registered) {
256+
records.delete(key);
257+
continue;
258+
}
259+
const holder = soleHolderOf(registry, record.canonicalType, record.name);
260+
if (holder === record.holder) continue;
261+
const artifact = holder === null ? undefined : record.host.lookupArtifactItem(record.type, record.name, holder ?? undefined, record.member);
262+
const registered = mergeArtifactProtection(record.type, stateTenantAuthorship(withRowBinding(record.data, undefined)), artifact);
263+
registry.registerItem(record.type, registered, 'name');
264+
if (typeof holder === 'string' && artifact) records.set(key, { ...record, holder, registered });
265+
else records.delete(key);
266+
}
267+
}
268+
173269
export class ProtocolRegistryHydrationFacet {
174270
/**
175271
* Mirror an object-type overlay write into the in-memory engine
@@ -676,6 +772,15 @@ export class ProtocolRegistryHydrationFacet {
676772
if (!incomingTakesStoredFlowSlot(held, registered, shippers, installedManifestsOf(registry))) return true;
677773
}
678774
registry.registerItem(type, registered, 'name' as any);
775+
// [#32820] A package-less row wearing the envelope of the one holder
776+
// served now is recorded, so an enable serving a second holder builds
777+
// it again ({@link healSoleHolderEnvelopes}); any other registration
778+
// of the key forgets it.
779+
const member = bundleMemberOf(type, data);
780+
recordSoleHolderEnvelope(registry, envelopeKey(type, rowName, member),
781+
!options.packageId && typeof envelopePackage === 'string' && envelope && HEALED_OVERLAY_TYPES.has(canonicalType)
782+
? { host, type, canonicalType, name: rowName, member, data, holder: envelopePackage, registered }
783+
: undefined);
679784
await host.hydrateExpandedViewItems(type, data, options);
680785
return true;
681786
}

‎packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ const SITES: ReadonlyArray<Site & { readonly noPackage: boolean; readonly dispos
166166
why: '[#25467 cut 15] the class member\'s host closure: it forwards the moved body\'s two calls (the rows above) unchanged, so its disposition is theirs' },
167167
{ file: 'protocol-registry-hydration.ts', member: 'hydrateOverlayIntoRegistry', args: 'type, (data as any).name, envelopePackage ?? undefined, bundleMemberOf(type, data)', noPackage: true, disposition: 'no',
168168
why: 'scoped to the row\'s own package; [#32568] for a package-less row of a type ADR-0150 addresses by (package, name), its one holder, and no lookup at all with two (never the first-registered\'s); undefined only for another type\'s package-less row, whose body names no package; [#23074] at the row\'s own bundle member' },
169+
{ file: 'protocol-registry-hydration.ts', member: 'healSoleHolderEnvelopes', args: 'record.type, record.name, holder ?? undefined, record.member', noPackage: true, disposition: 'no',
170+
why: '[#32820] the hydrator\'s own lookup, run again on an enable for the holders served then: the one served holder\'s envelope on a package-less row, and no lookup at all with two (holder null); undefined only when no package holds the name, as in the hydrator; at the row\'s own bundle member' },
169171
{ file: 'protocol-exact-qualifier.ts', member: 'declinedCopyReplaced', args: 'request.type, request.name, holder, wantedMember', noPackage: false, disposition: 'no',
170172
why: '[#32568] the admitted holder\'s own shipped item, served in place of a declined package-less copy at that holder\'s exact address: body and envelope are one artifact of the address\'s holder' },
171173
{ file: 'protocol-registry-hydration.ts', member: 'expandRuntimeViewContainer', args: 'type, String(item.name), ownPackageId', noPackage: false, disposition: 'no',

‎packages/metadata-protocol/src/protocol.register-item-call-sites.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ const SITES: ReadonlyArray<Site & {
135135
+ 'reads answer it from its row; a package-less row, and every other type, register as before (#4624)',
136136
viewOnlyBy: 'const bound = canonicalType === \'view\' ? boundPackageOf(options.packageId) : undefined;',
137137
},
138+
{
139+
file: 'protocol-registry-hydration.ts', member: 'healSoleHolderEnvelopes', args: 'record.type, registered, \'name\'', disposition: 'no',
140+
path: '[#32820] the registry\'s enable notice (onPackageEnabled), for an entry the read-side hydrator built under a sole holder\'s envelope that the slot still holds',
141+
why: 'the same package-less row the hydrator registered, built again for the holders served now: its body binds to no '
142+
+ 'package (withRowBinding with none), and it wears the one served holder\'s envelope or, with two, none',
143+
},
138144
{
139145
// [#23198] Moved from hydrateExpandedViewItems into the one reconcile, which that hydration calls.
140146
// [#30147] The reconcile's body moved to its facet module by the codemod's members pass; the disposition is unchanged.

0 commit comments

Comments
 (0)