Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/34441-shipped-base-canonical-member-one-answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/spec': patch
---

fix(metadata-protocol)!: a dependent's row of a bundle member moves no read naming no package across a restart, and a row-held base's own member is served beside a dependent's copy of it (#28802 R2, ADR-0150 red line 2)

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — `skills/objectstack-platform/SKILL.md` (the ADR-0146 paragraph) and `content/docs/concepts/metadata-lifecycle.mdx` teach that a locale a dependent adds under a base's name is served only under its own `?package=`. This change makes `/published` and `/layers` hold to that for the canonical member of a base that ships only another member, before and after a restart, and makes a row-held base's own member the base's. No taught sentence moves.

<!-- adr-0087: registered shipped-base-dependent-canonical-row-not-published -->

**BREAKING**: one answer of `GET /meta/TYPE/NAME/published` naming no package moves from served to 404. Name the package (`?package=DEPENDENT&member=CANONICAL`) to read the row, as before.

**Every moved answer, before → after.** On the runtime dispatcher, in both registration orders, before and after a restart.

- **A dependent's canonical member over a base that ships only another one** (base A ships `email_template` `welcome` in `fr-FR` only; dependent D, which declares A, stores `en-US`). `GET /meta/email_template/welcome/published` moves FROM D's row (200, before a restart only) TO `404 RESOURCE_NOT_FOUND`, its answer with no D row stored. `GET /meta/email_template/welcome/layers` (no member) moves FROM `404` after a restart TO A's `fr-FR` (200), its answer with no D row stored and before a restart; before a restart its `overlay` layer moves FROM D's row TO `null`, as with no D row stored. The layered read had reported D's row as an orphan of A's name although A ships no `en-US`, and after a restart the hydrated row took the registry's bare slot the code layer read A's `fr-FR` from.
- **A member a row-held base and its dependent both store** (A stores `en-US`, D stores `en-US` and `fr-FR`, no package ships the name). Each door below moves FROM `409 RESOURCE_CONFLICT` naming A and D (the execution read threw `PackageScopedNameRefusedError`) TO A's row (200), as when A ships `en-US`. D's row of it is a bundle addition, never a second holder. Bundled types only (a type with no members has no additions). Naming the member: `GET /meta/email_template/welcome?member=en-US`, `/layers?member=en-US` and the execution read at `en-US`. Naming no member, which addresses the canonical member `en-US`: the plain read (`packageId` A), `/layers` (effective and overlay A's row), `/published` (A's row) and the execution read. The writes naming no package do not move: the save, delete, publish, draft and history doors still refuse these rows naming A and D, so `/layers` loads A's stack where the save it then sends is refused; a follow-up card judges whether the writes follow the base.

**Not moved.** The plain read, `?member=CANONICAL` and the execution read of the first shape (A's `fr-FR` naming no member, 404 at `en-US`). Each exact address (`?package=D&member=en-US` serves D's row). A package-less row beside two holders is still refused (#33210). A dependent's canonical row over a base that holds only another member as a row is still served (the `S1` pin of #33210). Two dependents storing the same member over a base that holds none of it are still refused naming both. A name of a type with no members (`dashboard`, `permission`, `tool`, …) that a base and its dependent both store as rows, no package shipping it, is still refused naming both on every door naming no package (#32607). The shipped CONTROL of the second shape (A ships `en-US`): the plain read and the execution read serve A's `en-US`, and `/layers` naming no member and `/published` report D's row as the overlay A's code shadows (#28409), as before.
127 changes: 100 additions & 27 deletions packages/metadata-protocol/src/protocol-meta-item-face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ const STORED_ROW_HOLDERS_REFUSAL: unique symbol = Symbol.for('objectstack.metada
* them, as `/layers` refuses the same rows (`packagelessLayeredReadRefusal`),
* where it served a row by store order; beside one holder or none it leaves
* the read as it was.
*
* [#34441 cell 2] Not refused, of a bundled type: two or more holders at the
* member where one is the base the others' rows are bundle additions to
* ({@link rowHeldBaseAddressOf}), with no package-less row beside them. The
* read is that base's, as a shipped base's own member is served.
*/
async function storedRowHoldersRefusal(
host: ServedRowHost,
Expand Down Expand Up @@ -463,6 +468,16 @@ async function storedRowHoldersRefusal(
return ownAndPair ? { kind: 'served', packageId: holder } : undefined;
}
if (holding.candidates.length < 2) return undefined;
// [#34441 cell 2, ADR-0146] Two or more packages holding the member as
// rows, where one is the base and every other one's row is a bundle
// addition to it ({@link rowHeldBaseAddressOf}): no ambiguity, as the
// registry names the base the one holder. The read is the base's, as a
// shipped base's own member is. Beside a package-less row the refusal
// above stands (#33210).
if (!holding.unbound) {
const rowHeldBase = await rowHeldBaseAddressOf(host, type, name, member, activeRows);
if (rowHeldBase !== undefined && holding.candidates.includes(rowHeldBase)) return { kind: 'served', packageId: rowHeldBase };
}
const base = {
status: 'refused' as const,
reason: 'ambiguous-in-environment' as const,
Expand Down Expand Up @@ -630,46 +645,102 @@ export async function declaredMemberOverrideAddressOf(
* hold only as stored rows never clashes. A dependent that also stores a
* member the base stores (D's `en-US` and `fr-FR` over A's `en-US`) stays an
* addition, as the registry names A the one holder there; the read at the
* shared member is left to the rows' own judgment (A holds a row there). The
* shared member is A's (below, #34441 cell 2). The
* base is the one row-holding package that is no addition;
* the read is moved only when there is exactly one, it holds no row at the
* member, and no package at the member is a customization pair of another
* row-holding package (`pairsOf`: a pair's added member is served on its
* base's address already, #28802 ruling A). So a second dependent adding a
* the read is moved only when there is exactly one and no package at the
* member is a customization pair of another row-holding package (`pairsOf`:
* a pair's added member is served on its base's address already, #28802
* ruling A). Where the base holds no row at the member, the read moves at a
* named non-canonical member only (the S1 guard); where it holds one, see
* the #34441 cell 2 paragraph below. So a second dependent adding a
* member of its own (D1 `fr-FR`, D2 `de-DE` over A's `en-US`) leaves A the
* base at each dependent's member, as the registry names A the one holder
* whichever packages are installed, and a dependent of a dependent is an
* addition to it. The arm applies only to a bundled type the registry reads
* by package, for a name no package ships (a shipped name is the shipper's
* already), at a named member other than the canonical one, with no
* environment item at the member and no disabled package among the
* row-holding packages (the served-holder judgment above reads those).
* addition to it. Both arms apply only to a bundled type the registry reads
* by package (a type with no members has no additions: its row holders stay
* holders, #34441 contract review M1), for a name no package ships (a shipped
* name is the shipper's already), with no environment item at the member and
* no disabled package among the row-holding packages (the served-holder
* judgment above reads those).
*
* [#34441 cell 2] …and, at ANY member the base itself holds as a row (the
* canonical one included), beside one or more dependents' rows of the same
* member: that base, as the registry names it the one holder there and as a
* shipped base's own member is served. The dependents' rows of it are
* additions, served at their own addresses. The item face's refusal of two
* row holders ({@link storedRowHoldersRefusal}) and the layered door's
* (`packagelessLayeredReadRefusal`) ask this first, so the plain read,
* `/layers` and the execution face serve the base's row where they refused
* naming both; beside a package-less row they still refuse (#33210). The
* writes naming no package do not ask it: the save, delete, publish, draft
* and history doors still refuse these rows naming base and dependent
* (`packagelessAddress`), so the read serves the base's stack where the
* write it would send is refused (#34441 contract review S1).
* `preread` is the item's active rows when the caller read them already.
*/
export async function rowHeldBaseAddressOf(
host: ServedRowHost,
type: string, name: string, member: string | undefined,
preread?: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>,
): Promise<string | undefined> {
const judged = await rowHeldBaseJudgment(host, type, name, member, preread);
if (judged === undefined || judged.pairAmongHolders) return undefined;
const { base, atMember } = judged;
// [#34441 cell 2] A member the base holds as a row beside a dependent's
// addition of the same member (D's `en-US` over A's `en-US`, the canonical
// member included) is the base's, as the registry names A the one holder
// there and as a shipped base's own member is served: the dependent's row
// is an addition, never a second holder. FROM (`main` 31096af83d): two
// holders, refused `409` naming A and D, where a shipped base served A's.
if (atMember.has(base)) return atMember.size >= 2 ? base : undefined;
// [#33210 contract review S1] A member only additions hold moves for a
// NAMED non-canonical member only. `overlayMemberValue` answers null for
// the canonical member, named or not, and the read naming no member
// addresses it (reachable without `?member=` and from `/published`). That
// mirror is left as it was: a dependent's canonical row over a base that
// holds only another member is served naming no package (the S1 pin).
return typeof overlayMemberValue(PLURAL_TO_SINGULAR[type] ?? type, member) === 'string' ? base : undefined;
}

/**
* The row-grain judgment {@link rowHeldBaseAddressOf} answers from: over a
* name no package ships, of a bundled type the registry reads by package, the
* one row-holding package that is no addition to another (the base), the
* packages holding a row at `member`, and whether one of those is a
* customization pair of a holder. `undefined` when the shape does not apply
* (see that function's docblock for each exclusion). `preread` is the item's
* active rows when the caller read them already (#24371: one read).
*/
async function rowHeldBaseJudgment(
host: ServedRowHost,
type: string, name: string, member: string | undefined,
preread?: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>,
): Promise<{ base: string; atMember: ReadonlySet<string>; pairAmongHolders: boolean } | undefined> {
const registry: any = host.engine?.registry;
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
const singular = PLURAL_TO_SINGULAR[type] ?? type;
// [#33210 contract review S1] A NAMED non-canonical member only.
// `overlayMemberValue` answers null for the canonical member, named or
// not, and the read naming no member addresses it (reachable without
// `?member=` and from `/published`). That mirror is left as it was: with
// a shipped base holding only another member, its answers move across a
// reboot and the read naming no member serves the base's other member,
// so there is no one shipped answer to align it with.
if (typeof overlayMemberValue(singular, member) !== 'string') return undefined;
// [#34441 contract review M1] A bundled type only. For a type with no
// members every row of the name is at the member, and the registry names
// every holder (`packageScopedHoldersOf` with no discriminator: a bundle
// addition exists only for a bundled type), so two packages holding such
// a name as rows stay two holders, refused naming both (#32607), whatever
// their dependencies. Judged before the rows are read: such a read reads
// nothing more than it did.
if (overlayMemberValue(singular, member) === undefined) return undefined;
if (shippingPackageIds(host.shippedArtifactsOf(type, name)).size > 0) return undefined;
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) {
return undefined;
}
let activeRows: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>;
try {
activeRows = await host.readItemActiveRows(type, name);
} catch (error) {
host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata');
activeRows = [];
if (preread !== undefined) {
activeRows = preread;
} else {
try {
activeRows = await host.readItemActiveRows(type, name);
} catch (error) {
host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata');
activeRows = [];
}
}
const rows = activeRows.filter((row) => rowMatchesOverlayWhere(row, { type: singular, name, state: 'active' }));
const memberWhere = { type: singular, name, state: 'active', ...overlayMemberWhere(singular, member) };
Expand Down Expand Up @@ -698,11 +769,10 @@ export async function rowHeldBaseAddressOf(
const bases = holders.filter((id) => !holders.some((other) => isAdditionTo(id, other)));
if (bases.length !== 1) return undefined;
const [base] = bases;
const additions = new Set(atMember.map((row) => packageOf(row)!));
if (additions.has(base)) return undefined;
const atMemberPackages = new Set(atMember.map((row) => packageOf(row)!));
const installed = installedManifestsOfEngine(host.engine);
const isPairOfAHolder = (id: string): boolean => holders.some((other) => other !== id && pairsOf(other, installed).includes(id));
return [...additions].some(isPairOfAHolder) ? undefined : base;
return { base, atMember: atMemberPackages, pairAmongHolders: [...atMemberPackages].some(isPairOfAHolder) };
}

/** The body of `ObjectStackProtocolImplementation#readMetaItemFace`; the method's docblock there is its contract. */
Expand All @@ -727,7 +797,9 @@ export async function readMetaItemFace(
// [#32607] …and refuses two enabled row holders of a name nobody ships.
// The rows that judgment reads are read on the face's key and handed to
// the read below, which takes them instead of reading them again
// (#24371: the item's active rows, one read).
// (#24371: the item's active rows, one read). [#34441 cell 2] Every
// judgment below that reads them takes the rows read already, so the
// served-holder and row-held-base judgments together are still one read.
let activeRows: PrereadActiveRows | undefined;
const host = this;
const judgeHost: ServedRowHost = {
Expand All @@ -737,6 +809,7 @@ export async function readMetaItemFace(
declinesStoredRow: (...a) => this.declinesStoredRow(...a),
rethrowUnlessMetadataStoreUnprovisioned: (...a) => this.rethrowUnlessMetadataStoreUnprovisioned(...a),
readItemActiveRows: async (type, name) => {
if (activeRows !== undefined && activeRows.type === type && activeRows.name === name) return [...activeRows.rows];
const rows = await this.readItemActiveRows(type, name, true);
activeRows = { type, name, rows };
return rows;
Expand Down
32 changes: 31 additions & 1 deletion packages/metadata-protocol/src/protocol-meta-layered-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ export async function packagelessLayeredReadRefusal(host: Pick<ProtocolHost, 'de
if (judged?.kind === 'refused') return judged.error;
if (judged !== undefined) return undefined;
const address = await host.packagelessAddress(PLURAL_TO_SINGULAR[type] ?? type, name, member);
// [#34441 cell 2] …and a base whose dependents' rows at the member are
// bundle additions to it is the one holder, read at its address by
// {@link getMetaItemLayered} ({@link rowHeldBaseAddressOf}), as the plain
// read serves it: no ambiguity to refuse. Beside a package-less row the
// refusal stands (#33210).
if (address.candidates.length > 1 && !address.unbound) {
const base = await rowHeldBaseAddressOf(host, type, name, member);
if (base !== undefined && address.candidates.includes(base)) return undefined;
}
return address.candidates.length > 1
? withPackageCandidates(
packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates),
Expand Down Expand Up @@ -404,6 +413,18 @@ export async function getMetaItemLayered(host: Pick<ProtocolHost, 'artifactLockL
if (alt) regItem = namedMemberOnly(runtimeOnly(host.engine.registry.getItem(alt, request.name, request.packageId, member)));
}
if (regItem !== undefined) code = regItem;

// [#34441 cell 1, #21059] Naming no member, the bare-name read answers
// a bundle that ships no canonical member with the member it ships,
// until a stored row is hydrated into that bare slot: the hydrated
// row is no artifact read (dropped above), and the shipped member it
// displaced is the artifact the bare name reads. Without this the same
// read answered `code` = the base's `fr-FR` before a restart and
// `null` after it (404 on `/layers`), with a dependent's `en-US` row
// stored. A named member is never answered here (its own lookups ran).
if (code === null && member === undefined && bareActionAnswer === undefined) {
code = host.lookupArtifactItem(request.type, request.name, request.packageId) ?? null;
}
}

// [#5840] The code half of the rule #5707 wrote for the overlay half,
Expand Down Expand Up @@ -601,7 +622,16 @@ export async function getMetaItemLayered(host: Pick<ProtocolHost, 'artifactLockL
// With several such rows, the pair's is reported, else the first
// package's in id order.
let orphaned = false;
if (overlay === null && code !== null && typeof contentPackageId === 'string' && contentPackageId !== '') {
// [#34441 cell 1] …and only over a code layer of the member this read
// addresses. Naming no member, a bundle whose base ships no canonical
// member takes the base's other member as its code layer (the registry's
// bare-name read, above); a dependent's row of the canonical member is
// then no row the base's document shadows but the dependent's addition
// (#28802 R2), and reported as an orphan it became `/published`'s
// document, before a restart only. FROM (`main` 31096af83d): A ships
// `fr-FR` only, D stores `en-US`: `/published` served D's row (200), where
// with no D row it answers 404.
if (overlay === null && code !== null && isWantedMember(code) && typeof contentPackageId === 'string' && contentPackageId !== '') {
const base = contentPackageId;
let rows: readonly StoredOverlayRow[] = [];
try {
Expand Down
Loading
Loading