Skip to content

Commit d635599

Browse files
fix(metadata-protocol)!: a name two or more enabled packages hold only as stored rows, and no package ships, is refused by the read naming no package instead of served by save order (ADR-0150 D3) (#33182)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DN286opJo9xyaJevg5Unj4B)_ Fixes #32607 Clause-②: yes (narrowing) Metadata-protocol: narrowed Skills-docs: none — no skill and no doc teaches what the read naming no package answers for a name only stored rows of several packages hold (`skills/**` and `content/docs/**` grepped: the `ambiguous-in-environment` mentions are about flow, queue and permission-set references, not `/meta` reads); the refusal's own sentence names the `?package=` remedy. > **BREAKING** (ADR-0087 `registered`, semantic entry `two-row-holders-bare-read-refused`): the read naming no package of a name two or more enabled packages hold only as stored rows, and that no package ships in code, answers 409 `RESOURCE_CONFLICT` naming each holder, where it served the row saved first. First-party count: 0. Remedy: name the package (`?package=`), which serves that package's row. ## 维护者速读 - 改了什么:两个都启用的包各自存了一行同名元数据、而没有任何包在代码里自带这个名字时,不带包名的读取(裸读 `GET /meta/TYPE/NAME`、`/published`、执行读)现在答 409 并点名这两个包;以前它按保存顺序返回先存的那一行。`/layers` 本来就答 409,保持原样不动。 - 为什么改:同一个名字,裸读答“先保存的那一行”、`/layers` 却答 409,答案取决于保存顺序,等于替调用方猜了一个包,违反史诗红线 2(歧义要报告,不许猜)。 - 风险与回滚:收紧(narrowing,BREAKING,metadata-protocol minor),第一方 0 处。只有一个包存了行、有包在代码里自带该名字、带 `?package=` 的精确读、被拒的行(declined)、某包的定制配对行、依赖包给行持有的基础包追加的语言成员,答案都不变。第 2 轮按复审修了 5 处(见 Round 2)。回滚 = revert 本 PR。 - 先看:`packages/metadata-protocol/src/protocol-meta-item-face.ts` 的 `storedRowHoldersRefusal`(只按行的粒度判持有者)与 `readMetaItemFace`(把读到的行交给 `readMetaItem`);`packages/rest/src/rest-server.ts` 与 `packages/runtime/src/domains/meta.ts` 各一个 catch 块(让 `/layers` 继续答写入口的 409);`packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts` 的 `[#32607]` 组。 - 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run src/meta-disabled-package-doors.test.ts -t 32607`,预期全部通过:两种注册顺序 × 两种保存顺序下裸读都是 409 点名两个包,单持有者 CONTROL 仍答 200。 - 需要你做的:无,席位落地。 ## What changes `servedRowHolderOf` (`@objectstack/metadata-protocol`, the row-aware served-holder judgment #32354 landed in #33130) answered only when some package was disabled. With no disabled package it returned `undefined`, so the plain read fell through to `findServedOverlayRow`, which takes the first row by save order, while `packagelessLayeredReadRefusal` counted both bindings and refused 409. Same name, two doors, two answers, and one of them a guess. Now the item face (`readMetaItemFace`, which the plain read, `/published` and the execution face share) asks the judgment with `{ refuseWithoutDisabled: true }`: - With no disabled holder, and only for a name no enabled package ships at any member (`shippedArtifactsOf(type, name)`, the set `packagelessContentPackage` already counts), `storedRowHoldersRefusal` judges the holders at ONE grain: the packages the item's active rows are bound to at the member, as the read binds them (`packagelessAddress`), less rows the reads decline and rows of a customization pair of another package the rows or the registry name. It never unites them with the registry's holders of the name (one bare slot, the row written or hydrated last). Two or more are refused with the by-name read's own refusal (`ambiguous-in-environment`, `details.candidates`); one or none: `undefined`, the read as it was. - The rows that judgment reads are read on the face's cache key and handed to `readMetaItem` (`PrereadActiveRows`), which takes them for the same item: the item face reads the item's active rows once (#24371). - A shipped name never fell to save order: the read's own content judgment counts the shipper. So a bundled type's base shipping one member beside another package's row of another member (an email template's `en-US` shipped, a dependent's `fr-FR` row) keeps its answer. The first dogfood run on `3b9a447dc3` caught exactly that over-reach (three #28802 pins, `expected { status: 409 } to deeply equal { status: 404 }`); `abd91aad9e` adds the guard. - Every other caller of the judgment (the layered read's re-addressing and `packagelessLayeredReadRefusal`) passes no option and is unchanged, so `/layers` keeps the package-less writes' refusal (#28337, ruling Q1 = A, 6820653691). - A1 (6821134180) and its runtime twin (6836791341): each transport's layered chain reads the plain read first to find a disabled owner (step 1b). That read now refuses, so step 1b catches the refusal and, when it is this judgment's own refusal (marked under the registered symbol `objectstack.metadata-protocol.storedRowHoldersRefusal`) and step 1c (`packagelessLayeredReadRefusal`) has a refusal for the address, hands over to it; every other error is rethrown as before. | Door, naming no package (E, F enabled, each storing a row of `d1`; no package ships `d1`) | Before | Now | |:--|:--|:--| | `GET /meta/:type/:name` | 200, the row saved first | 409 `RESOURCE_CONFLICT`, `details.candidates` = E, F | | `GET /meta/:type/:name/published` | 200, a row (`RestServer`: the row saved first; runtime dispatcher: the same package in every save order) | 409 `RESOURCE_CONFLICT` naming E, F | | execution face (`getMetaItemForExecution`) | the row saved first | the same refusal | | `GET /meta/:type/:name/layers` | 409, the package-less writes' refusal | unchanged | | `?package=E` / `?package=F` | that package's row | unchanged | | one package storing a row (CONTROL) | 200, that row | unchanged | | a name an enabled package ships at any member (e.g. base ships `en-US`, a dependent stores `fr-FR`), package-less `fr-FR` read | 404 / the pair's row | unchanged | | a package's row beside its customization pair's undeclared row (M1) | that read's own pick | unchanged: no door refuses or names the pair | | `email_template`: base stores `en-US` (nobody ships it), a dependent stores `fr-FR` (M2): plain read, `/layers`, execution face at `fr-FR` | the dependent's row | unchanged | | `/layers` of a name two packages ship in code, each with its own stored row (S1) | the plain read's refusal | unchanged | Both transports (`RestServer`, the runtime `HttpDispatcher`), both registration orders, both save orders, and on the runtime dispatcher before and after a reboot. Files: `protocol-meta-item-face.ts`, `protocol-meta-item-reads.ts` and `protocol.ts` (the hand-over of the rows read once), the A1 hunks in `rest-server.ts` and `runtime/src/domains/meta.ts`, the pins in `rest/src/meta-disabled-package-doors.test.ts` and `runtime/src/domains/meta-disabled-holder-served-stack.test.ts`, the semantic entry `packages/spec/src/migrations/entries/semantic/18.two-row-holders-bare-read-refused.ts`, and two changesets (`metadata-protocol` minor + `rest`, `runtime` patch, BREAKING, `adr-0087: registered`; `spec` patch for the entry). ## Tests - `packages/rest/src/meta-disabled-package-doors.test.ts`, describe `[#32607] RestServer: two enabled row holders and no shipper`: NARROWING over 2 registration orders × 2 save orders (plain read 409 with `details.candidates`, `/layers` and `/published` 409 naming both and serving no row, execution face rejects `RESOURCE_CONFLICT`/409, each `?package=` serves its own row); A1 (`/layers` of two enabled row holders leads with the writes' sentence); A1 CONTROLs (two code holders, and two served row holders beside a disabled one, keep the plain read's refusal on `/layers`); CONTROL (one row holder served on every bare door). - `packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts`, describe `[#32607] two enabled row holders and no shipper`: the same NARROWING on a booted kernel over the runtime dispatcher, 2 registration orders × 2 save orders, before and after a reboot, plus the `/layers` vs `/published` sentence split; CONTROL one row holder, before and after a reboot. - `runtime/src/domains/meta-disabled-holder-served-stack.test.ts`, describe `[#32607 M1, M2] the no-disabled arm judges holders at the rows' grain`: M1, a package (`com.qa.rowpairbase`) and its pair each storing an undeclared row, both save orders, before and after a reboot: the plain read and `/published` answer 200 and no door refuses or names the pair, each order answering the same before and after the reboot. M2 (n1: a bundled type at a non-canonical member), base storing `en-US`, dependent storing `fr-FR`, both save orders, before and after a reboot: the plain read, `/layers` and the execution face at `fr-FR` serve the dependent's row; the base's `en-US` stays the base's. `/published` takes no member selector (400 `VALIDATION_ERROR`), so it is not asked at `fr-FR`. - REST, `A1 CONTROL (S1)`: two packages ship a name in code, each with its own stored row; `/layers` keeps the plain read's refusal, not the writes' sentence. - The #28337 pins (`rest/src/meta-layers-ambiguous-package.test.ts` and the runtime twin) are untouched and green. - The #24371 one-read pins in `objectql/src/protocol-meta.test.ts` (red on CI at `5d3a6c757c`, Test Core 4/8) are green again. - The shipped-name guard is pinned by the existing dogfood file `packages/qa/dogfood/test/email-template-dependent-unshipped-locale-read.dogfood.test.ts` (#28802, booted showcase), which this PR leaves untouched. **Premise re-measured on `main` `89d7bef033`** (this branch's tests, main's three source files): the runtime `[#32607]` NARROWING pins went 4 failed / 2 passed; quoted: `{"success":true,"data":{… "label":"enabled row", "_packageId":"com.qa.row_alpha" …}}: expected [ 200, undefined ] to deeply equal [ 409, 'RESOURCE_CONFLICT' ]` (E saved first) and `… "label":"third row", "_packageId":"com.qa.row_gamma" …` (F saved first). The bare read still answered by save order. **Ablation 1** (the item face's `{ refuseWithoutDisabled: true }` replaced by an expression esbuild folds to `false`; `metadata-protocol` rebuilt; `ablation-dist-preflight` found `refuseWithoutDisabled: false }` in 2 built files, and `refuseWithoutDisabled: true }` in 0): runtime 4 failed / 18 passed of 22, REST 6 failed / 33 passed of 39, exactly the NARROWING and A1 pins. Quoted: ``AssertionError: {"type":"dashboard","name":"two_rows_dash","item":{… "label":"healthy row" …}}: expected [ 200, undefined ] to deeply equal [ 409, 'RESOURCE_CONFLICT' ]``. Restore leg: `ablation-replace --restore` blob equals HEAD, `git diff HEAD` empty, rebuilt, preflight `--absent`: marker absent from all 24 built files, tree clean. **Ablation 3** (the shipped-name guard: `!anyDisabled` replaced by `(globalThis as any).__ABL32607B === 1`; `metadata-protocol` rebuilt; preflight: marker present in 2 built files): the #28802 dogfood file 3 failed / 10 passed of 13, quoted `AssertionError: expected { status: 409 } to deeply equal { status: 404 }` (×2) and `expected { status: 409 } to deeply equal { status: 200, …(3) }`. Restore leg: blob equals HEAD, `git diff HEAD` empty, rebuilt, preflight `--absent`: absent from all 24 built files, tree clean. **Round 2, measured before the fix** (head `1ab9370442`, the shared-read fix alone): M1 409 naming `com.qa.rowpairbase` and `com.qa.rowpairbase.custom`; M2 409 naming the base and the dependent. **On `main` `89d7bef033`** (main's five source files put back): M2 green, and M1 answers exactly as on this head (no refusal; the row served follows the save order, see Carried). **Ablation 4** (the one grain: the registry's holders united back into the holders, marker `__ABLU32607` in 2 built files): runtime 3 failed / 22 passed of 25, the M1 and both M2 pins, quoted `RESOURCE_CONFLICT … package "com.qa.rowpairbase"; package "com.qa.rowpairbase.custom"` and `… package "com.qa.mailrowaddon"; package "com.qa.mailrowbase"`. Restored, rebuilt, `--absent` clean. (A first attempt was a no-op: its replacement text contained the anchor and `ablation-replace` refused it; that run is not counted.) **Ablation 5** (S1: the REST hand-over takes any error, marker condition dropped; src import, no build): 2 failed / 42 passed of 44, the two `A1 CONTROL (S1)` pins, quoted `{"error":"Name the package this layered read is for, …` where the plain read's sentence was expected. Restored, `git diff HEAD` empty. **Ablation 2** (REST A1: step 1b's hand-over `return false` replaced by `throw error`; the suite imports `./rest-server.js`, no build): 3 failed / 39 passed of 42: the two `[#32607] … A1` pins and the #28337 pin (`both spellings answer the package-less writes' 409 …`). Restore leg: blob equals HEAD, `git diff HEAD` empty. ## Acceptance notes - This branch resumes `claude/project-thread-j3i5j5@d721d9a` and merges `origin/main` once (`89d7bef033`, merge commit `3b9a447dc3`). The merge takes main's landed copies of every file the old branch carried from #32354's `pv4nip` and #32501 (main's #33130 and #33148), drops the patch copy `cb73bf6c`, and replays the card's own seven commits (`ef9fceb2` … `d721d9a1`) onto them. Two files conflicted: `protocol-meta-item-face.ts` (main's served-row filter for declined and pair rows, `servedAddressJudgment` and the member-selector resolution, with the card's option threaded through them) and the REST doors test (two describe blocks appended at the same place, both kept). The diff against `main` is this card's ten files only; three commits follow the merge (`abd91aad9e`, the shipped-name guard, `5d3a6c757c`, its changeset sentence, and `2eb2f7c258`, round 2). At the seat's landing request (the head was 25 commits behind), `origin/main` was merged a second and last time (`67274acad6`, merge commit `f20d249baf`): clean, `protocol.ts` auto-merged (#33119's hunks are elsewhere in the file), and the diff against `main` is still the card's ten files, 613+/21−. - Declaration moved since the claim of record: `Metadata-protocol: none` (seat ruling 6820653691) → `narrowed`, per review#1's ruling on #33121 (a refusal of a read that served before) and the seat's re-posted claim 6866219396. Hence `minor`, the BREAKING banner, `!` and the ADR-0087 entry. - Not moved here, carried elsewhere: the paired customization address after a reboot (`?package=HOLDER.custom`, #32662); `details.candidates` on `/layers` (#32622); the REST `/layers` answer for two registry holders (#32624, sequenced after this card on the same chain). ## Round 2 (review#1 FAIL 6868755969 on `5d3a6c757c`, and CI Test Core 4/8) - **S2 / CI**: one read of the item's active rows on the item face again (`PrereadActiveRows`); objectql `protocol-meta.test.ts` 94/94. - **M1, M2**: holders judged at the rows' grain only (`storedRowHoldersRefusal`); pinned as asked, red before the fix, green after; ablation 4. - **S1**: only the row judgment's own refusal is handed over (registered-symbol marker read by both transports); pinned; ablation 5. - **n1**: M2 is the first pin on a bundled type at a non-canonical member. - The changeset's "Not moved" paragraph now states the one grain, the marker, M1 and M2. ## Carried (for the seat to route) - A package-less row beside two packages' rows of the name: `rows.unbound` leaves the read as it was, so the plain read still takes a row by store order while `/layers` refuses naming both. Not covered by this PR. **Carried by #33210** (p2, triage ruling 6870700526: red line 2 decides, refuse 409 as `/layers` does), together with review#1's n2 of 6870642184 (a row-held base's added member answers the dependent's row where a shipped base answers 404). - M1's shape (a package's row beside its customization pair's undeclared row, nobody ships the name): no refusal and no pair named any more, but which row the plain read and the execution face serve follows the save order (X then pair saved: X's row; pair then X: the pair's row; `/published` serves X's row in both), measured identically on `main` `89d7bef033`. It is the plain read's own pick between a base row and its pair's undeclared row, not this judgment's. **Folded into #32662** (triage ruling 6870700526). - #32663 (the registry's one bare slot per stored name) lands after this card; this judgment no longer reads the registry's holders, so it does not move with it. ## Verification All readings on the final head `f20d249baf` (the second merge of `main`), under the lock, `VERDICT command-exit 0`. Round 2's readings on `2eb2f7c258` (objectql 12863, metadata-protocol 22803, rest 8360, runtime 10599, dogfood 3905) were all green as well, and are superseded here. <details><summary>Affected suites and typecheck</summary> One locked run: the dogfood closure rebuilt (`pnpm --filter '@objectstack/dogfood^...' build`), then each suite in full. - `pnpm --filter @objectstack/objectql test`: Test Files 595 passed (595); Tests 12903 passed (12903), including the #24371 one-read pins CI's Test Core 4/8 failed on at `5d3a6c757c`. - `pnpm --filter @objectstack/metadata-protocol test`: Test Files 338 passed, 7 skipped (345); Tests 22810 passed, 36 skipped (22846). - `pnpm --filter @objectstack/rest test`: Test Files 409 passed (409); Tests 8360 passed, 332 skipped (8692). - `pnpm --filter @objectstack/runtime test`: Test Files 597 passed (597); Tests 10624 passed, 19 skipped (10643). - `typecheck` of `metadata-protocol`, `objectql`, `rest`: exit 0. `runtime`: its `check:test-typecheck` ran out of heap locally (the session's `NODE_OPTIONS` overrode the script's 4096 MB default, leaving 2 GB); re-run with `--max-old-space-size=4096`, as CI sets it: exit 0, "27 file(s) / 183 error(s) / 66 pinned signature(s) held". - `test:repo` (vitest `repo` project) not run locally: the diff touches no file of that project; CI's `Test Core` runs it. </details> <details><summary>dispatch-gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived the same 97 commands from 10 paths vs merge base. All 97 exit 0 on `f20d249baf`, including `check:dual-build-cjs-loads`, `type-check-coverage`, `type-check-debt`, `dts-closure`, `lean-entry-closure`, `published-files` and spec `check:browser-reachable-entries`. `dispatch-gates --ran` (record `/mnt/project-files/epic-31527-seat2/cards/32607-thread/ran-r3.txt`): "97 derived famil(ies) accounted for — 97 run, 0 NOT-MEASURED". `node scripts/check-test-source-alias.mjs` exit 0; `node scripts/check-nul-bytes.mjs` exit 0. </details> <details><summary>Lint and dogfood</summary> `pnpm lint` (eslint, whole repo) on `f20d249baf`: exit 0. Full dogfood battery on `f20d249baf` (`!` title, `Clause-②: yes (narrowing)`), closure rebuilt after the merge, no shard, no path: Test Files 464 passed, 3 skipped (467) · Tests 3927 passed, 42 skipped (3969) · no failure. The #28802 file (`email-template-dependent-unshipped-locale-read.dogfood.test.ts`) is green in it. Round 1 for the record: the first battery on `3b9a447dc3` was red in that file, 3 tests (`expected { status: 409 } to deeply equal { status: 404 }`), fixed in `abd91aad9e`. </details> --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4czBmkW6UeWPazkWq7L <!-- signed: epic:#31527#2 · os-elon-musk · session_016WV4czFhtRVZNBeHdQA6PW --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 0b89b33 commit d635599

10 files changed

Lines changed: 613 additions & 21 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@objectstack/metadata-protocol': minor
3+
'@objectstack/rest': patch
4+
'@objectstack/runtime': patch
5+
---
6+
7+
fix(metadata-protocol)!: a name two enabled packages hold only as stored rows is refused by the plain read, never served by save order (ADR-0150 D3, #32607)
8+
9+
Clause-②: yes (narrowing)
10+
Metadata-protocol: narrowed
11+
Skills-docs: none — no skill and no doc teaches what the read naming no package answers for a name only stored rows of several packages hold (`skills/**` and `content/docs/**` grepped: the `ambiguous-in-environment` mentions are about flow, queue and permission-set references, not `/meta` reads); the refusal's own sentence names the `?package=` remedy.
12+
13+
<!-- adr-0087: registered two-row-holders-bare-read-refused -->
14+
15+
**BREAKING** answer narrowing at the `/meta` bare item reads: a name that two or more enabled packages hold only as stored rows, and that no package ships in code, answers 409 `RESOURCE_CONFLICT` naming each of them, where the plain read and `/published` served one of the rows. `/layers` already refused it.
16+
17+
The row-aware served-holder judgment that a disabled holder brings in (#32354) now also judges, on the item read, a name with no disabled holder. The holders are judged at one grain, the packages the item's active stored rows are bound to at the member the read addresses, as the read itself binds them, and never united with the registry's holders of the name (with no shipper the registry knows a row-only name through one bare slot, the row written or hydrated last). Two or more of them are refused as the by-name read refuses two package holders (`ambiguous-in-environment`). One holder reads as before. It applies to a type the registry reads by package, when no enabled package ships the name in code at any member, and when no package-less row or environment item of the name is stored.
18+
19+
**Every moved answer, before → after.** Both transports (`RestServer` and the runtime `HttpDispatcher`), both registration orders, both save orders, and on the runtime dispatcher before and after a reboot. First-party count 0: no first-party app saves one name into two packages' stored rows.
20+
21+
Narrowing:
22+
23+
- Bare `GET /meta/:type/:name`: 200 with the row saved first → 409 `RESOURCE_CONFLICT` naming each holder, with `details.candidates`.
24+
- Bare `GET /meta/:type/:name/published`: 200 with a row (on `RestServer` the row saved first; on the runtime dispatcher the same package in every save order) → 409 `RESOURCE_CONFLICT` naming each holder.
25+
- The execution face (`getMetaItemForExecution`) of the same name: the row saved first → the same refusal.
26+
27+
**Not moved.** Bare `GET /meta/:type/:name/layers` keeps its 409 `RESOURCE_CONFLICT`, the package-less writes' own refusal naming the same holders with its `?package=` prescription (#28337), on both transports: each transport's layered chain (`RestServer`'s and the runtime `HttpDispatcher`'s) reads the plain read first to find a disabled owner, and now leaves that read's refusal of row holders, and only that refusal (the protocol marks it), to the package-less refusal step, rethrowing every other refusal as before (two code holders, with or without a stored row each, and two row holders beside a disabled one, keep the plain read's refusal). `?package=` naming either holder serves that holder's row. A name one package holds as a stored row is served as before. A row the reads decline (a shipped flow name's undeclared row, a sealed managed name's row) and a row of a customization pair of another package the rows or the registry name make no holder here, as they make none beside a disabled holder (#32354), so they never turn one holder into a refusal: a package's row beside its pair's undeclared row is one holder in either save order, and no door names the pair. A dependent's added member over a base that holds the name only as a stored row (`email_template`: the base's `en-US` row, the dependent's `fr-FR` row) is the dependent's alone at that member (#28802): the plain read, `/layers` and the execution face at `fr-FR` keep serving the dependent's row. A name an enabled package ships in code at any member (for a bundled type such as `email_template`, a base shipping `en-US` beside another package's `fr-FR` row: the package-less `fr-FR` read keeps its answer), or one with a package-less row or an environment item, is judged as before. The paired customization addresses (`?package=HOLDER.custom`), which after a reboot follow the registry's one bare slot, are unchanged here (#32662 carries them).
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 the bare item read #32607 narrows: a name two or more enabled packages hold only as stored rows, which no package ships in code, is refused naming each holder instead of served by save order
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The semantic entry `two-row-holders-bare-read-refused` (`packages/spec/src/migrations/entries/semantic/18.two-row-holders-bare-read-refused.ts`) registers the narrowing `.changeset/32607-two-enabled-row-holders.md` declares (ADR-0087, `adr-0087: registered`). There is no automatic rewrite, because which package's row a caller meant is a judgement about that caller. The remedy it names is the exact read (`?package=`), which serves each holder's row. It adds no key and no export.

‎packages/metadata-protocol/src/protocol-meta-item-face.ts‎

Lines changed: 119 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { resolveBundleMemberSelector } from './protocol-bundle-members.js';
4545
import { installedManifestsOfEngine } from './installed-manifests.js';
4646
import { pairsOf } from '@objectstack/metadata-core';
4747
import { disabledExactAddressHolder } from './protocol-exact-qualifier.js';
48+
import type { PrereadActiveRows } from './protocol-meta-item-reads.js';
4849
import {
4950
isActionWithheldByDisabledPackage,
5051
isItemOfDisabledPackage,
@@ -131,11 +132,12 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
131132
* was the last one written or hydrated; the rows themselves name every
132133
* package that holds the name ({@link packagelessAddress}'s candidates).
133134
*
134-
* Asked only when a package is disabled, of a type the registry reads by
135-
* package, when an enabled package ships no code item of the name (otherwise
136-
* the shipped item is the name's, ADR-0048 §3.3, and a row of another package
137-
* never stands in for it: {@link servedHolderAddressOf} and
138-
* `packagelessContentPackage` judge it), and when no package-less row and no
135+
* Asked only when a package is disabled ([#32607] or when the item face
136+
* asks, below), of a type the registry reads by package, when an enabled
137+
* package ships no code item of the name (otherwise the shipped item is the
138+
* name's, ADR-0048 §3.3, and a row of another package never stands in for
139+
* it: {@link servedHolderAddressOf} and `packagelessContentPackage` judge
140+
* it), and when no package-less row and no
139141
* environment item is stored (a customization of no one holder, judged as
140142
* before). Then the holders are the registry's served holders and the
141143
* packages the active rows are bound to, less every disabled package:
@@ -145,7 +147,17 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
145147
* - two or more → `{ kind: 'refused' }`, the by-name read's own refusal
146148
* (`ambiguous-in-environment`), naming only the served holders (epic ruling
147149
* on #32354, Q2): a disabled package is never named;
148-
* - none, or no disabled package among them → `undefined`, the read as it was.
150+
* - none → `undefined`, the read as it was.
151+
*
152+
* [#32607] With no disabled package among the holders, and only when
153+
* `options.refuseWithoutDisabled` asks (the item face, {@link
154+
* readMetaItemFace}), two or more are refused the same way, naming each: the
155+
* plain read served the row saved first while `/layers` refused naming both.
156+
* That arm is {@link storedRowHoldersRefusal}, which judges the holders at
157+
* the rows' grain alone.
158+
* Otherwise, and for one holder, `undefined` (the read already reads there).
159+
* The layered reads keep their own refusal for that case, the one the
160+
* package-less writes give (#28337).
149161
*
150162
* [#32354 contract review S4] A row the reads decline
151163
* ({@link ObjectStackProtocolImplementation.declinesStoredRow}: a shipped flow
@@ -170,14 +182,16 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
170182
export async function servedRowHolderOf(
171183
host: ServedRowHost,
172184
type: string, name: string, member?: string,
185+
options: { readonly refuseWithoutDisabled?: boolean } = {},
173186
): Promise<{ kind: 'served'; packageId: string } | { kind: 'refused'; error: PackageScopedNameRefusedError } | undefined> {
174187
const registry: any = host.engine?.registry;
175188
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
176189
if (typeof registry.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
177190
const disabled = (id: string): boolean => registry.isPackageDisabled(id) === true;
178-
// No disabled package at all: no read moves, and no row is read for it.
179-
// The predicate `isPackageDisabled` reads, asked of each installed record.
180-
if (typeof registry.getAllPackages === 'function'
191+
// No disabled package at all, and no refusal asked of that case: no read
192+
// moves, and no row is read for it. The predicate `isPackageDisabled`
193+
// reads, asked of each installed record.
194+
if (options.refuseWithoutDisabled !== true && typeof registry.getAllPackages === 'function'
181195
&& !(registry.getAllPackages() as ReadonlyArray<{ enabled?: unknown; status?: unknown } | undefined>)
182196
.some((pkg) => pkg?.enabled === false || pkg?.status === 'disabled')) {
183197
return undefined;
@@ -199,7 +213,8 @@ export async function servedRowHolderOf(
199213
const rows = await host.packagelessAddress(type, name, member, 'active', activeRows);
200214
if (rows.unbound) return undefined;
201215
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
202-
if (![...every, ...rows.candidates].some(disabled)) return undefined;
216+
const anyDisabled = [...every, ...rows.candidates].some(disabled);
217+
if (!anyDisabled) return options.refuseWithoutDisabled === true ? storedRowHoldersRefusal(host, type, name, member, every, activeRows, rows.candidates) : undefined;
203218
const installed = installedManifestsOfEngine(host.engine);
204219
const pairRow = (row: { package_id?: unknown }): boolean =>
205220
typeof row.package_id === 'string' && every.some((holder) => pairsOf(holder, installed).includes(row.package_id as string));
@@ -220,6 +235,73 @@ export async function servedRowHolderOf(
220235
return { kind: 'refused', error: new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }) };
221236
}
222237

238+
/**
239+
* [#32607] The marker {@link storedRowHoldersRefusal} sets on its refusal, a
240+
* registered symbol (so every copy of this package reads the same key, and
241+
* no envelope serializes it). The layered chains' owner step in `RestServer`
242+
* and the runtime dispatcher reads it by the same `Symbol.for` key (neither
243+
* depends on this package at run time): it hands over to the package-less
244+
* refusal step only the refusal this judgment made, and rethrows every other
245+
* (contract review S1).
246+
*/
247+
const STORED_ROW_HOLDERS_REFUSAL: unique symbol = Symbol.for('objectstack.metadata-protocol.storedRowHoldersRefusal') as never;
248+
249+
/**
250+
* [#32607] The item face's judgment of a name with no disabled holder
251+
* ({@link servedRowHolderOf} with `refuseWithoutDisabled`): two or more
252+
* packages holding it only as stored rows are refused naming each, where the
253+
* plain read served the row saved first. `undefined` leaves the read as it
254+
* was.
255+
*
256+
* Only a name no enabled package ships, at any member: a shipped name keeps
257+
* the read's own content judgment, which counts the shipper
258+
* (`packagelessContentPackage` over the name's shipped artifacts), so there is
259+
* no save order to guess there (a bundled type's base shipping one locale
260+
* beside another package's row of another).
261+
*
262+
* [contract review M1, M2] The holders are judged at ONE grain: the packages
263+
* the item's active rows are bound to at the member, as the read itself
264+
* binds them ({@link packagelessAddress}), and never united with the
265+
* registry's holders of the name. With no shipper the registry knows a
266+
* row-only name through one bare slot, the row written or hydrated last, at
267+
* the name's grain, so the union followed save order (a customization pair
268+
* named as a holder when its row was the slot's entry) and counted a holder
269+
* of another member (a base's `en-US` row against a dependent's added
270+
* `fr-FR`). Excluded, as beside a disabled holder: a row the reads decline
271+
* ({@link ObjectStackProtocolImplementation.declinesStoredRow}) and a row of a
272+
* customization pair of another package the rows or the registry name
273+
* (`pairsOf`), which is that package's customization, never a holder of its
274+
* own. An unbound package-less row among them leaves the read as it was.
275+
*/
276+
async function storedRowHoldersRefusal(
277+
host: ServedRowHost,
278+
type: string, name: string, member: string | undefined,
279+
every: readonly string[],
280+
activeRows: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>,
281+
bound: readonly string[],
282+
): Promise<{ kind: 'refused'; error: PackageScopedNameRefusedError } | undefined> {
283+
const registry: any = host.engine?.registry;
284+
if ([...shippingPackageIds(host.shippedArtifactsOf(type, name))].some((id) => registry.isPackageDisabled(id) !== true)) return undefined;
285+
const installed = installedManifestsOfEngine(host.engine);
286+
const known = [...new Set([...every, ...bound])];
287+
const pairOfAnother = (row: { package_id?: unknown }): boolean => typeof row.package_id === 'string'
288+
&& known.some((holder) => holder !== row.package_id && pairsOf(holder, installed).includes(row.package_id as string));
289+
const holding = await host.packagelessAddress(type, name, member, 'active', activeRows.filter((row) =>
290+
!host.declinesStoredRow(type, name, row) && !pairOfAnother(row)));
291+
if (holding.unbound || holding.candidates.length < 2) return undefined;
292+
const base = {
293+
status: 'refused' as const,
294+
reason: 'ambiguous-in-environment' as const,
295+
type: type as PackageScopedResolvableType,
296+
name,
297+
callerPackageId: null,
298+
candidates: [...holding.candidates].sort().map((packageId) => ({ kind: 'package' as const, packageId })),
299+
};
300+
const error = new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) });
301+
Object.defineProperty(error, STORED_ROW_HOLDERS_REFUSAL, { value: true });
302+
return { kind: 'refused', error };
303+
}
304+
223305
/**
224306
* [#32183, #32354] The judgment of the address a read naming no package takes
225307
* for a name a disabled package also holds: the registry's served holder
@@ -228,14 +310,18 @@ export async function servedRowHolderOf(
228310
* holders; `undefined` leaves the read as it was. Answered, never thrown: the
229311
* plain read throws the refusal ({@link servedAddressOf}); the layered read
230312
* only re-addresses, and leaves the refusal to its door (contract review S1).
313+
* `options` as on {@link servedRowHolderOf}: only the item face asks it, so
314+
* [#32607] two enabled row holders of a name nobody ships are refused there
315+
* alone.
231316
*/
232317
export async function servedAddressJudgment(
233318
host: ServedRowHost,
234319
type: string, name: string, member?: string,
320+
options: { readonly refuseWithoutDisabled?: boolean } = {},
235321
): Promise<{ kind: 'served'; packageId: string } | { kind: 'refused'; error: PackageScopedNameRefusedError } | undefined> {
236322
const registryAddress = servedHolderAddressOf(host.engine?.registry, type, name);
237323
if (registryAddress !== undefined) return { kind: 'served', packageId: registryAddress };
238-
return servedRowHolderOf(host, type, name, member);
324+
return servedRowHolderOf(host, type, name, member, options);
239325
}
240326

241327
/**
@@ -246,8 +332,9 @@ export async function servedAddressJudgment(
246332
export async function servedAddressOf(
247333
host: ServedRowHost,
248334
type: string, name: string, member?: string,
335+
options: { readonly refuseWithoutDisabled?: boolean } = {},
249336
): Promise<string | undefined> {
250-
const judged = await servedAddressJudgment(host, type, name, member);
337+
const judged = await servedAddressJudgment(host, type, name, member, options);
251338
if (judged?.kind === 'refused') throw judged.error;
252339
return judged?.packageId;
253340
}
@@ -292,10 +379,28 @@ export async function readMetaItemFace(
292379
// [contract review N1] The member selector resolved once, as the layered
293380
// read resolves it: a malformed one is the read's own 400, never a 409
294381
// judged at a member nobody named.
382+
// [#32607] …and refuses two enabled row holders of a name nobody ships.
383+
// The rows that judgment reads are read on the face's key and handed to
384+
// the read below, which takes them instead of reading them again
385+
// (#24371: the item's active rows, one read).
386+
let activeRows: PrereadActiveRows | undefined;
387+
const host = this;
388+
const judgeHost: ServedRowHost = {
389+
get engine() { return host.engine; },
390+
packagelessAddress: (...a) => this.packagelessAddress(...a),
391+
shippedArtifactsOf: (...a) => this.shippedArtifactsOf(...a),
392+
declinesStoredRow: (...a) => this.declinesStoredRow(...a),
393+
rethrowUnlessMetadataStoreUnprovisioned: (...a) => this.rethrowUnlessMetadataStoreUnprovisioned(...a),
394+
readItemActiveRows: async (type, name) => {
395+
const rows = await this.readItemActiveRows(type, name, true);
396+
activeRows = { type, name, rows };
397+
return rows;
398+
},
399+
};
295400
const servedAddress = request.packageId
296401
? undefined
297-
: await servedAddressOf(this, request.type, request.name, resolveBundleMemberSelector(request.type, request.member));
298-
const answer = await this.readMetaItem(servedAddress === undefined ? request : { ...request, packageId: servedAddress }, { face });
402+
: await servedAddressOf(judgeHost, request.type, request.name, resolveBundleMemberSelector(request.type, request.member), { refuseWithoutDisabled: true });
403+
const answer = await this.readMetaItem(servedAddress === undefined ? request : { ...request, packageId: servedAddress }, { face, ...(activeRows !== undefined ? { activeRows } : {}) });
299404
// [#28877] The served read of an `action` also withholds one that launches
300405
// into a disabled package, as the served list does.
301406
const withheldAction = request.type === 'action' && face === 'served'

0 commit comments

Comments
 (0)