Skip to content

Commit 02f55c5

Browse files
fix(metadata-protocol)!: a name a disabled package holds through a stored row is judged over the served set, never by save order (ADR-0150 D3) (#33130)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DJY4PjkLW3oxuaYHFL3pHBd)_ Part of #32354 Clause-②: yes (narrowing) — on both transports, a bare read (plain and `/published`) of a name held by the stored rows of two or more enabled packages beside a disabled one is refused `409 RESOURCE_CONFLICT` naming only the enabled holders, where it answered by save order; on `RestServer`, `?package=PAIR` of a disabled customization pair whose base is enabled answers 404 where it served the base's item. Three bare reads widen from 404 or 409 to 200 with the one enabled holder's row (table below). `?package=DISABLED` (case 3) is not a move: 18.4.0 already answers 404. Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is which stored row a by-name read answers while a package is disabled. Skills-docs: none — no skill or doc teaches the by-name answer for a name a disabled package holds through a stored row; `content/docs/deployment/marketplace-handbook.mdx` already says a disabled module is hidden. Supersedes #32811 (same work: that PR's head branch belongs to an earlier card thread, which this thread cannot push; this branch resumes from its head `cd1143c19` and merges `main` once). ## 维护者速读 - **改了什么:** 不指名包读取一个元数据名时,如果某个包已停用、而这个名字由多个包的存储行持有,现在按「在用的持有者」判定:只剩一个在用包就答它的行,两个以上就 409 且只点名在用包,不再按保存顺序答,也不再点名停用包。另外 `?package=停用的定制包` 现在答 404,不再透出它基础包的内容。 - **为什么改:** 专题 ADR-0150 D3:停用一个包,它在每个读门上都应消失,结果不随保存顺序变化。本轮同时落实了契约复审 6856157850 的 S1–S4。 - **风险与回滚:** 第一方 0 处(没有第一方应用在启动时停用包)。收窄两处(三包存储行同名且其一停用 → 409;停用定制包的地址 → 404);进程内的分层读取(安全目录回显、打包权限集锁)保持原答案、不会抛错。回滚即 revert 本 PR。 - **先看:** `packages/metadata-protocol/src/protocol-meta-item-face.ts` 的 `servedRowHolderOf` 与 `servedAddressJudgment`;`protocol-meta-layered-reads.ts` 的两处调用(只改址、不拒绝);`protocol-exact-qualifier.ts` 新增的一行。 - **两分钟验证:** `pnpm --filter @objectstack/rest exec vitest run src/meta-disabled-package-doors.test.ts`,预期 27 例全过(`main` 上其中 9 例红)。 - **需要你做的:** 无,席位落地。 ## What changes Head `5c37471ba5`, on `main` `2c98485db5` (merged once). The diff against `main` is this card's 7 files, +619 / −11. #32808 (#32501) has landed, so nothing of it rides here any more. **The fix**, three hunks in `@objectstack/metadata-protocol`: 1. **Row holders judged over the served set** (`protocol-meta-item-face.ts`: `servedRowHolderOf`, `servedAddressJudgment`, `servedAddressOf`). A read naming no package, of a name a disabled package holds, takes the registry's served holder as before (#32183), else the stored rows' one served holder: the registry's served holders together with the packages the active rows are bound to, less every disabled package. One → read at its address; two or more → the by-name read's own refusal (`ambiguous-in-environment`) naming only those (seat ruling 6817756360 Q2); none → the read as before. Asked only while some installed package is disabled, of a type the registry reads by package, when no enabled package ships the name in code and no package-less row or environment item is stored. The item's active rows are read once (`readItemActiveRows`), and two kinds of row hold nothing: a row the reads decline (`declinesStoredRow`, review S4) and a row bound to a customization pair of any holder of the name (`pairsOf`, review N2 widened by `5c37471b`): a pair row is bound over every holder it is a pair of (#32408), never a holder of its own. 2. **Who refuses** (review S1). `servedAddressJudgment` answers the refusal, never throws it. The plain read (`readMetaItemFace`) throws it through `servedAddressOf`. `getMetaItemLayered` only re-addresses to a served holder and otherwise leaves the read as it was, so its in-process resolution readers (the security catalog echo, the packaged-permission-set lock gate) keep the answer they had, as the `packagelessLayeredReadRefusal` docblock requires; that method returns the refusal to the `/layers` door's step 1c. The docblock gains one paragraph saying so. 3. **A disabled package's own address** (`protocol-exact-qualifier.ts` `disabledExactAddressHolder`, one line): an address naming a disabled package is its withheld item whether it holds the name in the registry, only as a stored row, or not at all (a customization pair: review S2). Review N1: the plain read resolves the member selector once (`resolveBundleMemberSelector`), as the layered read does. **Moved answers.** FROM = `main` `2c98485db5` (18.4.0 plus later merges) with this change's four source files put back; TO = this head. D disabled, E (and F) enabled. Both transports, both registration orders, the save orders as listed, unless a row names one transport. | # | state | door | FROM `main` | TO this head | arm | |:--|:--|:--|:--|:--|:--| | C1a | rows of E and D only, no shipper, D's row saved first | bare plain read, `/layers`, `/published` | 404 | 200, E's row | widening | | C1b | the same, E's row saved first | bare `/layers` | 409 naming E and D | 200, E's layers | widening | | C1b′ | the same | bare plain read, `/published` | 200, E's row | the same | none | | C1c | D ships the name in code, E holds it only as a row | bare plain read, `/layers`, `/published` | 404 | 200, E's row | widening | | N2 | D ships it, D's pair holds D's declared override row, E holds a row (`RestServer`) | bare plain read, `/layers`, `/published` | 404 | 200, E's row | widening (C1c's) | | N2′ | the same without E's row (`RestServer`) | the same | 404 | 404 | none | | Q2 | rows of D, E, F, no shipper | bare plain read | 404 (D saved first) † | 409 `RESOURCE_CONFLICT` naming E and F, `details.candidates` | narrowing | | Q2 | the same | bare `/published` | as the plain read † | 409 naming E and F | narrowing | | Q2′ | the same | bare `/layers` | 409 naming D, E and F † | 409 naming E and F | same status, D unnamed | | S2 | PAIR disabled, its base enabled and shipping the name (`RestServer`) | `?package=PAIR`, with PAIR's declared override row | 200, the override (stamped with the base) | 404 | narrowing | | S2′ | the same, no override row (`RestServer`) | `?package=PAIR` | 200, the base's item | 404 | narrowing | | S4 | D ships a flow name, E and F hold undeclared (declined) rows (`RestServer`) | bare plain read, `/layers`, `/published` | 404 | 404 | none | | C3 | E ships the name in code, D holds it only as a row | `?package=D` | 404 | 404 | none (second guard; review S3) | | C2 | the environment's package-less row beside E and D both shipping | bare `/layers` code layer | E's | E's | none (CONTROL) | † A pin stops at its first failing assertion, so on the FROM leg the Q2 pins stop at the plain read. The plain read's FROM is the card's development-round reading (D saved first: 404; an enabled row saved first: 200 with it); `/published` asks the plain read first and answers its answer; `/layers` is the development-round reading. Every case re-enabled: the answers go back (the C1 pins re-enable D and see `/layers` refuse naming both). ## Merge - `6abfd47e0a` merges `origin/main` `2c98485db5` into `cd1143c19` once. #32808 landed squashed (`c50d10c0`), so two files conflicted on its own hunks: the `getMetaItemLayered` host `Pick` list takes the union of both sides (`main` added `isStoredEntryOfDeclinedName`, this card `packagelessAddress` and `shippedArtifactsOf`), and `packages/runtime/src/domains/meta-legacy-pair-served.test.ts` takes `main`'s landed version (this branch never touched it past #32501's head). - `.changeset/32501-pair-address-reads-its-package.md`, which this branch carried from #32501's head, was consumed by Version Packages #29963 on `main`; the merge would have re-added it, so it is dropped. ## Tests Pins (`packages/rest/src/meta-disabled-package-doors.test.ts`, the two `[#32354]` describes; `packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts`, the `[#32354]` describe, real ObjectQL engine with an SQL store, reboot included). New in this round: Q2's bare `/published` on both transports (S3), the in-process layered read and `packagelessLayeredReadRefusal` in the Q2 state (S1), the shipped flow name with declined rows (S4), the disabled pair address with and without its override row (S2), and the disabled base's pair override row alone and beside an enabled row (N2). Legs, each through `scripts/ablation-replace.mjs --hold` with a string-literal marker (MAIN: the four source files put back at `origin/main`), each rebuilding `@objectstack/metadata-protocol` (both suites read its `dist/`) and proving the marker reached `dist/` with `scripts/ablation-dist-preflight.mjs` (MAIN: `servedRowHolderOf` absent), each restored with `git checkout HEAD --` and `git diff HEAD` empty; the final rebuild carries none of the four markers (`--absent`, exit 0 each). Cells: cases failed / cases in the file. | leg | REST (27) | runtime (16) | red cases | |:--|:--|:--|:--| | head | 0 | 0 | — | | MAIN | 9 | 8 | C1 (4 + 4 with reboot), C1c (2, runtime), Q2 (2 + 2), S2 (2), N2 beside E (1); C3, S4, N2 alone and C2 green, as declared | | S1 off (the layered read throws the refusal again) | 2 | 0 | Q2 (2): `promise rejected "PackageScopedNameRefusedError: … held by 2 packages …" instead of resolving` | | S4 off (declined rows counted) | 2 | 0 | S4 (2): `The flow "shipped_flow" is held by 2 packages … package "app.healthy_demo"; package "app.third_demo"` | | N2 off (a disabled base's pair override counted for the pair) | 1 | 0 | N2 beside E: `The dashboard "pair_dash" is held by 2 packages … package "com.qa.other"; package "com.qa.pair-base.custom"` | | H2 off (the new `disabledExactAddressHolder` line) | 2 | 0 | S2 (2): 200 with the base's item / the override | | PAIR off (pair rows counted as holders of their own, on `5c37471ba5`) | 1 | 0 | N2 beside E; and `packages/objectql` `package-scoped-exact-qualifier.test.ts` 2/230 red (the two `[#32408]` pins: the bare read served the pair row with every holder disabled) | The previous round's legs on `cd1143c19` (ROWS, FACE, LREF, LADDR, F1, F1+H2 off; the #32811 body) cover the C1/Q2 hunks, which this round does not change. ## Verification All on head `5c37471ba5` unless stated, under `scripts/pm/os-verify-lock.sh` where it builds or tests. - `packages/objectql` `package-scoped-exact-qualifier.test.ts` (the `[#32408]` pins that went red in Test Core (4/8) on `032a1edad8`): 230/230. - `pnpm --filter @objectstack/metadata-protocol test`: Test Files 337 passed, 7 skipped (344); Tests 22799 passed, 36 skipped (22835); lock VERDICT command-exit 0. - `pnpm --filter @objectstack/metadata-protocol typecheck`, and `typecheck` of `rest` and `runtime`: exit 0 each. - The pin files: `rest` `meta-disabled-package-doors.test.ts` 27/27; `runtime` `meta-disabled-holder-served-stack.test.ts` + `meta-legacy-pair-served.test.ts` 35/35. - `pnpm lint` (eslint over the whole tree, `--no-inline-config`): exit 0. - `node scripts/pm/dispatch-gates.mjs --commands`: 72 families derived for this diff, all run on `5c37471ba5` (and before on `032a1edad8`, after a full `pnpm -r build`, exit 0), 72 exit 0; `--ran` reconciliation exit 0, 0 NOT-MEASURED. Among them `check-adr-0087-registration --base origin/main`, `check-changeset-no-major`, `check-empty-changeset`, `check:type-check-debt` and `check:dual-build-cjs-loads` (both under the lock). - Dogfood battery (owed: the title carries `!`, `Clause-②:` carries `(narrowing)`), `pnpm --filter @objectstack/dogfood test` on `5c37471ba5` after the full build: Test Files 460 passed, 3 skipped (463); Tests 3874 passed, 42 skipped (3916); lock VERDICT command-exit 0. (On `032a1edad8`: the same counts.) ## Acceptance notes - **`Part of`, not `Fixes`.** Epic note 6820147040 carried list cases here (a disabled sole holder's pair member row and a dependent's added locale listed by the unscoped list; the list scoped to a disabled base lists its pair's member row), and #32670 says this card owns them. No list door is touched here, so merging should not close the card; the seat routes those cases (review ③). - **Review dispositions (6856157850):** S1 option one (keep the ⛔: the layered read never refuses in process). S2 declared and pinned (`RestServer`). S3 done: C3 restated as no move, out of the BREAKING headline; bare `/published` added to Q2 and pinned on both transports. S4: declined rows hold nothing, pinned. N1 done. N2 measured: the pair override of a disabled base was already withheld by its stamp alone, but counted for the enabled pair it turned a C1c read beside another enabled row into a 409 naming the pair; it now holds nothing, pinned. N3 (the bare read reads the active rows twice while a package is disabled) left as is: one extra read only in that state. - **Delta review 6859717745 (review#1, head `5c37471ba5`): PASS**, no must-fix or should-fix; nits n1 (the pair describe's docblock still says nothing moves on `main`; the pins and the changeset are right) and n2 (`pairRow` asks the registry's holders, not also `rows.candidates`; derived, not shown reachable) left for a later push, as the record allows. - **Fix round `5c37471ba5`:** `Test Core (4/8)` was red on `032a1edad8` on two `[#32408]` pins in `packages/objectql`; the pair-row exclusion now covers every pair of a holder (`pairsOf`). CI on `5c37471ba5`: 35 success, 16 skipped, none failed. - **Case 2:** premise unreachable (`overlaySlotBinding` answers the environment's item only when no package ships the name); one CONTROL pin per registration order (seat ruling 6817756360 Q3). - **Not here:** the save door (#32605); two enabled packages' stored rows with no package disabled (#32607, which merges this after it lands). - **Branch:** `claude/project-thread-saq29l`, this card thread's harness-pinned branch, resumed from `claude/project-thread-pv4nip@cd1143c` (#32811). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (`packages/spec` untouched.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. (Supersedes #32811, see above.) - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [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. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4d1FGsHCVfNAwXgN9sE)_ <!-- 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 6482c08 commit 02f55c5

7 files changed

Lines changed: 621 additions & 11 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol)!: a name a disabled package holds through a stored row is judged over the served set, never by save order (ADR-0150 D3, #32354)
6+
7+
Clause-②: yes (narrowing)
8+
Metadata-protocol: none
9+
Skills-docs: none — no skill or doc teaches the by-name answer for a name a disabled package holds through a stored row; `content/docs/deployment/marketplace-handbook.mdx` already says a disabled module is hidden.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answers are reads of stored rows under a reversible package state, so there is nothing for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** answer narrowing at the `/meta` bare reads: a name held by the stored rows of two or more enabled packages beside a disabled one is refused `409 RESOURCE_CONFLICT` naming only the enabled holders, where the plain read and `/published` answered by save order; and an address naming a disabled customization pair whose base is enabled answers 404, where it served the base's item.
14+
15+
A read naming no package of a name a disabled package holds now judges the name's holders over the stored rows as well as the registry. The registry keeps one bare slot per name, so it holds at most one of two packages' stored rows of a name nobody ships, and the answer followed save order. The holders are the registry's served holders and the packages the active stored rows are bound to, less every disabled package. A row the reads decline (a shipped flow name's undeclared row, a sealed managed name's row) and a row bound to a holder's customization pair (bound over every holder it is a pair of, #32408) hold nothing of their own. This applies only while some installed package is disabled, to a type the registry reads by package, when no enabled package ships the name in code, and when no package-less row or environment item of the name is stored. The in-process layered read (`getMetaItemLayered`) is re-addressed to the one served holder but never refuses: its resolution readers (the security catalog echo, the packaged-permission-set lock gate) keep the answer they had, and the `/layers` door refuses.
16+
17+
**Every moved answer, before → after** (before = 18.4.0). Both transports (`RestServer` and the runtime `HttpDispatcher`), both registration orders, both save orders, before and after a reboot, except where a line names one transport. First-party count 0 for each: no first-party app disables a package at boot.
18+
19+
Widening:
20+
21+
- Stored rows only (no package ships the name), a row bound to an enabled package E and one bound to a disabled package D. Bare `GET /meta/:type/:name`, `/layers` and `/published`, D's row saved first: 404 → 200 with E's row. E's row saved first: the plain read and `/published` unchanged (E's row); `/layers` 409 naming E and D → 200 with E's layers.
22+
- D ships the name in code and E holds it only as a stored row, D disabled: the bare plain read, `/layers` and `/published` 404 → 200 with E's row. The same when D's customization pair also holds D's declared override row of the name (`RestServer`).
23+
24+
Narrowing:
25+
26+
- Stored rows of two or more enabled packages and of a disabled one, no shipper, the bare plain read and `/published`: 404 (D's row read first and withheld) or 200 with the first-saved enabled row → 409 `RESOURCE_CONFLICT` naming only the enabled holders, with `details.candidates` on the plain read.
27+
- `GET /meta/:type/:name?package=PAIR`, PAIR a disabled customization pair whose base is enabled and ships the name, with or without PAIR's declared override row: 200 with the base's item (the override's body when there is one) → 404, PAIR's withheld item (`RestServer`).
28+
29+
Same status, the disabled package no longer named:
30+
31+
- Two or more enabled packages' rows and a disabled one's, bare `/layers`: 409 naming every row's package, D included → 409 naming only the enabled holders.
32+
33+
**Not moved.** `GET /meta/:type/:name?package=D`, D disabled and holding the name only as a stored row while an enabled package ships it: 404 since 18.4.0 (the strict envelope of #32501 leaves D's row its own stamp, which the item face withholds); this change adds a second guard for the same answer. With no disabled package, nothing moves (two enabled packages' stored rows of a name nobody ships keep their answers; #32607 carries that case). A name an enabled package ships in code is judged as before (#32183's registry read). A shipped flow name whose shipper is disabled, with rows of two other packages, answers the missing name as before. Re-enabling the package restores every answer above. The save door is unchanged (#32605 carries it). The environment's own item beside an enabled and a disabled shipper keeps the enabled holder's code layer on `/layers`: the registry answers the environment's item only when no package ships the name, so that shape cannot arise.

‎packages/metadata-protocol/src/protocol-exact-qualifier.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ export async function admitExactQualifier(
322322

323323
/**
324324
* [#32183, ruling (c)] The disabled package an exact address reads, when every
325-
* package it reads is disabled: the package `packageId` names when it holds the
326-
* name, else the bases it is a pair of when none of them is enabled (the
325+
* package it reads is disabled: the package `packageId` names when it is
326+
* disabled ([#32354] whether it holds the name in the registry or only as a
327+
* stored row), else the bases it is a pair of when none of them is enabled (the
327328
* bases {@link admitExactQualifier} admits it at). `undefined` when the
328329
* address reads an enabled package, reads no holder, or the type is not
329330
* package-scoped. The item face answers such an address as that package's
@@ -339,8 +340,14 @@ export function disabledExactAddressHolder(
339340
const registry = registryOf(host) as (Partial<ExactQualifierRegistry> & { isPackageDisabled?(id: string): boolean }) | undefined;
340341
if (typeof registry?.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
341342
const disabled = (id: string) => registry.isPackageDisabled!(id) === true;
343+
// [#32354] A disabled package named is its own withheld item whether it
344+
// holds the name in the registry or only as a stored row, which the
345+
// registry need not know (one bare slot per name): the read reached its
346+
// row, and served its body under the envelope of the package that ships
347+
// the name.
348+
if (disabled(request.packageId)) return request.packageId;
342349
const every = registry.packageScopedHoldersOf(request.type, request.name, request.packageId, { includeDisabledPackages: true }) ?? [];
343-
if (every.includes(request.packageId)) return disabled(request.packageId) ? request.packageId : undefined;
350+
if (every.includes(request.packageId)) return undefined;
344351
const installed = installedManifestsOfEngine(host.engine);
345352
const bases = every.filter((holder) => pairsOf(holder, installed).includes(request.packageId));
346353
return bases.length > 0 && bases.every(disabled) ? bases[0] : undefined;

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

Lines changed: 157 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@
3434
* surface does not move.
3535
*/
3636

37+
import {
38+
PackageScopedNameRefusedError,
39+
packageScopedRefusalMessage,
40+
type PackageScopedResolvableType,
41+
} from '@objectstack/core';
3742
import type { ObjectStackProtocolImplementation } from './protocol.js';
43+
import { shippingPackageIds } from './protocol-environment-rows.js';
44+
import { resolveBundleMemberSelector } from './protocol-bundle-members.js';
45+
import { installedManifestsOfEngine } from './installed-manifests.js';
46+
import { pairsOf } from '@objectstack/metadata-core';
3847
import { disabledExactAddressHolder } from './protocol-exact-qualifier.js';
3948
import {
4049
isActionWithheldByDisabledPackage,
@@ -53,8 +62,17 @@ import {
5362
export interface MetaItemFaceHost {
5463
readonly engine: ObjectStackProtocolImplementation['engine'];
5564
readonly readMetaItem: ObjectStackProtocolImplementation['readMetaItem'];
65+
readonly packagelessAddress: ObjectStackProtocolImplementation['packagelessAddress'];
66+
readonly shippedArtifactsOf: ObjectStackProtocolImplementation['shippedArtifactsOf'];
67+
readonly readItemActiveRows: ObjectStackProtocolImplementation['readItemActiveRows'];
68+
readonly declinesStoredRow: ObjectStackProtocolImplementation['declinesStoredRow'];
69+
readonly rethrowUnlessMetadataStoreUnprovisioned: ObjectStackProtocolImplementation['rethrowUnlessMetadataStoreUnprovisioned'];
5670
}
5771

72+
/** The host {@link servedRowHolderOf} and {@link servedAddressJudgment} read. */
73+
type ServedRowHost = Pick<MetaItemFaceHost,
74+
'engine' | 'packagelessAddress' | 'shippedArtifactsOf' | 'readItemActiveRows' | 'declinesStoredRow' | 'rethrowUnlessMetadataStoreUnprovisioned'>;
75+
5876
/**
5977
* [#32183] The package holding `(type, name)` when every package that holds
6078
* it is disabled; `undefined` when none holds it or an enabled one does.
@@ -104,6 +122,136 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
104122
return served[0];
105123
}
106124

125+
/**
126+
* [#32354, ADR-0150 D3] The served holder of a name for a read naming no
127+
* package, judged over the stored rows too: what {@link servedHolderAddressOf}
128+
* answers from the registry alone, for the names whose holders live only in
129+
* `sys_metadata`. The registry keeps one bare slot per name, so a stored row a
130+
* package saved under a name no enabled package ships is in it only when it
131+
* was the last one written or hydrated; the rows themselves name every
132+
* package that holds the name ({@link packagelessAddress}'s candidates).
133+
*
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
139+
* environment item is stored (a customization of no one holder, judged as
140+
* before). Then the holders are the registry's served holders and the
141+
* packages the active rows are bound to, less every disabled package:
142+
*
143+
* - one → `{ kind: 'served' }`, read at its address, as the registry's
144+
* served holder is;
145+
* - two or more → `{ kind: 'refused' }`, the by-name read's own refusal
146+
* (`ambiguous-in-environment`), naming only the served holders (epic ruling
147+
* on #32354, Q2): a disabled package is never named;
148+
* - none, or no disabled package among them → `undefined`, the read as it was.
149+
*
150+
* [#32354 contract review S4] A row the reads decline
151+
* ({@link ObjectStackProtocolImplementation.declinesStoredRow}: a shipped flow
152+
* name's undeclared row, a sealed managed name's row) serves nothing at its
153+
* package's address, so it makes that package no holder here: counted, it
154+
* re-addressed the read to an address that serves nothing, and two of them
155+
* were refused naming two such addresses. It still counts toward whether a
156+
* disabled package holds the name, and an unbound one still leaves the read
157+
* as it was.
158+
*
159+
* [#32354 contract review N2, #32408] Nor does a row bound to a holder's
160+
* customization pair (`pairsOf`): a pair row is bound over every holder it
161+
* is a pair of, never a holder of its own, so a disable never moves it (a
162+
* disabled holder's declared override row is that holder's item, ADR-0146
163+
* D9, withheld with it). Counted for the enabled pair, it served a disabled
164+
* holder's customization at the bare address, where the read answered the
165+
* missing name.
166+
*
167+
* Every holder is judged by save order no more: the disabled package's row
168+
* read first answered the missing name, the enabled one's served it.
169+
*/
170+
export async function servedRowHolderOf(
171+
host: ServedRowHost,
172+
type: string, name: string, member?: string,
173+
): Promise<{ kind: 'served'; packageId: string } | { kind: 'refused'; error: PackageScopedNameRefusedError } | undefined> {
174+
const registry: any = host.engine?.registry;
175+
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
176+
if (typeof registry.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
177+
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'
181+
&& !(registry.getAllPackages() as ReadonlyArray<{ enabled?: unknown; status?: unknown } | undefined>)
182+
.some((pkg) => pkg?.enabled === false || pkg?.status === 'disabled')) {
183+
return undefined;
184+
}
185+
if ([...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))].some((id) => !disabled(id))) return undefined;
186+
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) {
187+
return undefined;
188+
}
189+
// The item's active rows, read once: every row binds a holder, and only
190+
// the rows the reads serve make a served one (S4). An unprovisioned store
191+
// holds no row.
192+
let activeRows: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>;
193+
try {
194+
activeRows = await host.readItemActiveRows(type, name);
195+
} catch (error) {
196+
host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata');
197+
activeRows = [];
198+
}
199+
const rows = await host.packagelessAddress(type, name, member, 'active', activeRows);
200+
if (rows.unbound) return undefined;
201+
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
202+
if (![...every, ...rows.candidates].some(disabled)) return undefined;
203+
const installed = installedManifestsOfEngine(host.engine);
204+
const pairRow = (row: { package_id?: unknown }): boolean =>
205+
typeof row.package_id === 'string' && every.some((holder) => pairsOf(holder, installed).includes(row.package_id as string));
206+
const servingRows = await host.packagelessAddress(type, name, member, 'active', activeRows.filter((row) =>
207+
!host.declinesStoredRow(type, name, row) && !pairRow(row)));
208+
const served = [...new Set([...(registry.packageScopedHoldersOf(type, name, null) ?? []), ...servingRows.candidates])]
209+
.filter((id) => !disabled(id));
210+
if (served.length === 1) return { kind: 'served', packageId: served[0] };
211+
if (served.length === 0) return undefined;
212+
const base = {
213+
status: 'refused' as const,
214+
reason: 'ambiguous-in-environment' as const,
215+
type: type as PackageScopedResolvableType,
216+
name,
217+
callerPackageId: null,
218+
candidates: served.sort().map((packageId) => ({ kind: 'package' as const, packageId })),
219+
};
220+
return { kind: 'refused', error: new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }) };
221+
}
222+
223+
/**
224+
* [#32183, #32354] The judgment of the address a read naming no package takes
225+
* for a name a disabled package also holds: the registry's served holder
226+
* ({@link servedHolderAddressOf}), else the stored rows' ({@link
227+
* servedRowHolderOf}), which may be the refusal naming two or more served
228+
* holders; `undefined` leaves the read as it was. Answered, never thrown: the
229+
* plain read throws the refusal ({@link servedAddressOf}); the layered read
230+
* only re-addresses, and leaves the refusal to its door (contract review S1).
231+
*/
232+
export async function servedAddressJudgment(
233+
host: ServedRowHost,
234+
type: string, name: string, member?: string,
235+
): Promise<{ kind: 'served'; packageId: string } | { kind: 'refused'; error: PackageScopedNameRefusedError } | undefined> {
236+
const registryAddress = servedHolderAddressOf(host.engine?.registry, type, name);
237+
if (registryAddress !== undefined) return { kind: 'served', packageId: registryAddress };
238+
return servedRowHolderOf(host, type, name, member);
239+
}
240+
241+
/**
242+
* [#32183, #32354] {@link servedAddressJudgment} for the plain read: the
243+
* served address, or `undefined`; throws the refusal when two or more served
244+
* packages hold the name.
245+
*/
246+
export async function servedAddressOf(
247+
host: ServedRowHost,
248+
type: string, name: string, member?: string,
249+
): Promise<string | undefined> {
250+
const judged = await servedAddressJudgment(host, type, name, member);
251+
if (judged?.kind === 'refused') throw judged.error;
252+
return judged?.packageId;
253+
}
254+
107255
/**
108256
* [#32183, contract review M4] Whether `copy`, the metadata service's copy of
109257
* a name read at `address` (the served holder {@link servedHolderAddressOf}
@@ -127,7 +275,7 @@ export function isAnotherHoldersCopy(registry: any, type: string, name: string,
127275

128276
/** The body of `ObjectStackProtocolImplementation#readMetaItemFace`; the method's docblock there is its contract. */
129277
export async function readMetaItemFace(
130-
this: Pick<MetaItemFaceHost, 'engine' | 'readMetaItem'>,
278+
this: Pick<MetaItemFaceHost, 'readMetaItem'> & ServedRowHost,
131279
request: {
132280
type: string, name: string, packageId?: string, state?: 'active' | 'draft', previewDrafts?: boolean,
133281
member?: string,
@@ -139,8 +287,14 @@ export async function readMetaItemFace(
139287
}
140288
// [#32183] A name a disabled package also holds is read at the served
141289
// holder's address ({@link servedHolderAddressOf}), so no layer of the
142-
// read can be the disabled holder's.
143-
const servedAddress = request.packageId ? undefined : servedHolderAddressOf(this.engine?.registry, request.type, request.name);
290+
// read can be the disabled holder's. [#32354] …judged over the stored
291+
// rows too ({@link servedAddressOf}), so the answer never follows save order.
292+
// [contract review N1] The member selector resolved once, as the layered
293+
// read resolves it: a malformed one is the read's own 400, never a 409
294+
// judged at a member nobody named.
295+
const servedAddress = request.packageId
296+
? undefined
297+
: await servedAddressOf(this, request.type, request.name, resolveBundleMemberSelector(request.type, request.member));
144298
const answer = await this.readMetaItem(servedAddress === undefined ? request : { ...request, packageId: servedAddress }, { face });
145299
// [#28877] The served read of an `action` also withholds one that launches
146300
// into a disabled package, as the served list does.

0 commit comments

Comments
 (0)