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
19 changes: 19 additions & 0 deletions .changeset/34452-same-name-bare-reads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/spec': patch
---

fix(metadata-protocol)!: the reads that name no package give one answer per name: the environment's doc entry first, and a disabled holder read as absent

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: registered doc-bare-read-environment-entry-first, disabled-holder-package-less-row-bare-read-judged-as-absent -->

**BREAKING** for a caller that reads a shared name without naming a package, shipped as `patch`: no key an author writes changes (`Metadata-protocol: none`). Three reads that named no package answered by registration or save order, or disagreed with the registry's own read of the same name; each now gives one answer. Naming the package (`?package=ID`, or `packageId` in process) reads that package's item exactly as before.

- **A doc the environment stores beside one enabled package's doc of the same name** (#34452, ruling 6942962369). FROM `GET /api/v1/meta/doc/NAME`, `/layers` and `/published` serving the package's doc while the registry and the metadata facade served the environment's own entry, TO every read that names no package serving the environment's entry, as it already did beside two or more holders. `?package=ID` still reads the package's doc. Known deviation, tracked in #38659: the plain read naming no package serves the entry under a holder's envelope (`_packageId` that holder, `_provenance: package`, lock `full`), as it already did beside two or more holders.
- **The in-process layered read of a doc two or more enabled packages hold, with no environment entry** (#34190). FROM the layered read naming no package serving the layers of the package registered last, TO a `409 RESOURCE_CONFLICT` rejection naming each holder in `refusal.candidates`, as the item read and every HTTP door already answered.
- **A package-less row beside a disabled package's row and enabled packages' rows of a name no enabled package ships** (#34440). FROM the plain read and the execution read following save order, `/published` serving the package-less row, `/layers` refusing with the disabled package among the candidates, and one save order answering 404 (every bare door answered 404 when the disabled package held the name in code alone beside two or more enabled packages' rows), TO the answer the reads give without the disabled holder: two or more enabled holders refused `409 RESOURCE_CONFLICT` naming exactly them in `details.candidates`, one enabled holder served, in every save order and after a restart. `?package=` of the disabled package still answers 404.

The fix for a caller that relied on the old answer: name the package it means. `os migrate meta --from 18` lists both entries.
39 changes: 28 additions & 11 deletions packages/metadata-protocol/src/protocol-meta-item-face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,18 @@ const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet<string> = new Set(['object', '
* package ships no code item of the name (otherwise the shipped item is the
* name's, ADR-0048 §3.3, and a row of another package never stands in for
* it: {@link servedHolderAddressOf} and `packagelessContentPackage` judge
* it), and when no package-less row and no
* environment item is stored (a customization of no one holder, judged as
* before). [#33210] On the item face (`options.refuseWithoutDisabled`) a
* it). [#33210] On the item face (`options.refuseWithoutDisabled`) a
* package-less row, or the registry's environment item, beside rows bound to
* two or more packages with no disabled package among them is judged with
* those rows instead ({@link storedRowHoldersRefusal}), so it is refused
* naming them; beside one holder, none, or a disabled holder the read is left
* as it was. Then the holders are the registry's served holders and the
* naming them; beside one holder or none the read is left as it was.
* [#34440] Beside rows bound to two or more packages, with a disabled holder
* of the name (its own stored row among them, or the name in its code alone:
* contract review S4), it is judged below with those rows on every door, as
* the item face judges it with no disabled holder: a package-less row is no
* holder and no tie-break. Beside one bound package or none the read is left
* as it was.
* Then the holders are the registry's served holders and the
* packages the active rows are bound to, less every disabled package:
*
* - one → `{ kind: 'served' }`, read at its address, as the registry's
Expand All @@ -306,8 +310,7 @@ const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet<string> = new Set(['object', '
* package's address, so it makes that package no holder here: counted, it
* re-addressed the read to an address that serves nothing, and two of them
* were refused naming two such addresses. It still counts toward whether a
* disabled package holds the name, and an unbound one still leaves the read
* as it was.
* disabled package holds the name.
*
* [#32354 contract review N2, #32408] Nor does a row bound to a holder's
* customization pair (`pairsOf`): a pair row is bound over every holder it
Expand Down Expand Up @@ -340,7 +343,11 @@ export async function servedRowHolderOf(
if ([...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))].some((id) => !disabled(id))) return undefined;
const environmentItem = typeof registry.getEnvironmentScopedItem === 'function'
&& registry.getEnvironmentScopedItem(type, name, member) !== undefined;
if (environmentItem && options.refuseWithoutDisabled !== true) return undefined;
// [#34440] Not left as it was here when a package is disabled: the
// environment item may be a package-less row beside rows bound to two or
// more packages, a disabled one among them, which is judged below over
// the served set on every door (the plain read's face, `/layers`'s
// refusal and the save door alike).
// The item's active rows, read once: every row binds a holder, and only
// the rows the reads serve make a served one (S4). An unprovisioned store
// holds no row.
Expand All @@ -363,10 +370,20 @@ export async function servedRowHolderOf(
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
const anyDisabled = [...every, ...rows.candidates].some(disabled);
// [#33210] The no-disabled arm judges a package-less row itself
// ({@link storedRowHoldersRefusal}); beside a disabled holder it leaves
// the read as it was.
// ({@link storedRowHoldersRefusal}).
if (!anyDisabled) return options.refuseWithoutDisabled === true ? storedRowHoldersRefusal(host, type, name, member, every, activeRows, rows.candidates) : undefined;
if (rows.unbound) return undefined;
// [#34440 contract review S2] Beside rows bound to one package or none, a
// package-less row leaves the read as it was, as its twin
// {@link storedRowHoldersRefusal} leaves it (`holding.unbound` with fewer
// than two candidates): whether the bare slot holds an environment item
// then moves no answer.
if (rows.unbound && rows.candidates.length < 2) return undefined;
// [#34440, ADR-0150 D3] Beside a disabled holder a package-less row is
// judged over the served set as it is with no disabled holder (#33210):
// two or more served holders are refused naming only them, one is served
// at its address, so every bare door gives the answer it gives when the
// disabled holder is absent. Left as it was, the read followed save
// order (one order answered 404) and `/layers` named the disabled package.
const installed = installedManifestsOfEngine(host.engine);
const pairRow = (row: { package_id?: unknown }): boolean =>
typeof row.package_id === 'string' && every.some((holder) => pairsOf(holder, installed).includes(row.package_id as string));
Expand Down
23 changes: 14 additions & 9 deletions packages/metadata-protocol/src/protocol-meta-item-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,18 @@ export async function judgeBareActionRead(
* slot (a stamp-less registration, or a hydrated or saved row stamped with
* the store's sentinel) exempts the name: it is the environment's own item,
* which answers first, as the registry and `MetadataFacade.get` serve it.
* That entry is returned when two or more enabled packages hold the name,
* That entry is returned when one or more enabled packages hold the name,
* because the layers must then serve it: the MetadataService keeps a doc by
* name alone, so its copy is the holder registered last, and it answered
* first ({@link bareDocServiceCopyDisplacesEntry}).
* name alone, so its copy is a holder's (the one registered last), and it
* answered first ({@link bareDocServiceCopyDisplacesEntry}).
*
* @returns the environment's entry beside two or more enabled holders, else
* `undefined` (no such entry, or a name one package or none holds).
* [#34452, ruling 6942962369] Beside ONE enabled holder too: the
* environment's own item answers first whatever number of packages hold the
* name, so the bare doors agree with the registry and `MetadataFacade.get`.
* They served the one holder's doc while those two served the entry.
*
* @returns the environment's entry beside one or more enabled holders, else
* `undefined` (no such entry, or a name no enabled package holds).
* @throws {PackageScopedNameRefusedError} two or more enabled package holders.
*/
export function refuseAmbiguousBareDocRead(host: Pick<ProtocolHost, 'engine'>, name: string, member: string | undefined): unknown {
Expand All @@ -357,9 +362,9 @@ export function refuseAmbiguousBareDocRead(host: Pick<ProtocolHost, 'engine'>, n
if (typeof registry?.resolveItem !== 'function') return undefined;
const answer = registry.resolveItem('doc', name, null, member);
// The registry's answer naming no package is the exempting entry (or a
// name one package or none holds, which the count below leaves alone).
// name no enabled package holds, which the count below leaves alone).
if (answer === undefined || answer === null || storedItemPackageId(answer) !== undefined) return undefined;
return (registry.packageScopedHoldersOf?.('doc', name) ?? []).length >= 2 ? answer : undefined;
return (registry.packageScopedHoldersOf?.('doc', name) ?? []).length >= 1 ? answer : undefined;
}

/**
Expand Down Expand Up @@ -1372,8 +1377,8 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
&& !(bareActionAnswer && (!serviceAnswerFitsBareAction(bareActionAnswer, fromService.data)
|| await servedFromDisabledHolder(host, request.name, fromService.data)))
&& !anotherPackagesCopy
// [#34248] …or, at a bare doc read the environment's own entry
// answers beside two holders, a package's copy
// [#34248, #34452] …or, at a bare doc read the environment's own
// entry answers beside one or more holders, a package's copy
// ({@link bareDocServiceCopyDisplacesEntry}): step 3 serves the entry.
&& !bareDocServiceCopyDisplacesEntry(bareDocEnvironmentEntry, fromService.data)) {
// [#22877] …when it is the member this read addresses. The
Expand Down
26 changes: 13 additions & 13 deletions packages/metadata-protocol/src/protocol-meta-layered-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,19 @@ async function getGenericMetaItemLayered(host: LayeredReadHost, request: {
? await judgeBareActionRead(host, request.name)
: undefined;
const exactAddress = await admitExactQualifier(host, { type: request.type, name: request.name, packageId: request.packageId, member });
// [#34248, ruling 6893582352] …and a bare doc read of a name two enabled
// packages hold, beside the environment's own entry, reads that entry as
// [#34248, #34452, ruling 6893582352] …and a bare doc read of a name one
// or more enabled packages hold, beside the environment's own entry, reads that entry as
// {@link getMetaItem} serves it ({@link refuseAmbiguousBareDocRead}): as
// its code layer, never the package copy the service kept. Its refusal
// without such an entry stays the door's, as before.
let bareDocEnvironmentEntry: unknown;
if (!request.packageId && request.type === 'doc') {
try {
bareDocEnvironmentEntry = refuseAmbiguousBareDocRead(host, request.name, member);
} catch (error) {
if (packageScopedRefusalOf(error) === undefined) throw error;
}
}
// its code layer, never the package copy the service kept.
// [#34190, ADR-0150 D3/D5] Without such an entry, a name two or more
// enabled packages hold is refused here as the plain read refuses it
// (`409 RESOURCE_CONFLICT` naming each holder), before any layer is read.
// The refusal was dropped and left to the doors, so an in-process caller
// (`getMetaItemLayered` naming no package) read the layers of the holder
// the metadata service registered last while `getMetaItem` refused.
const bareDocEnvironmentEntry: unknown = !request.packageId && request.type === 'doc'
? refuseAmbiguousBareDocRead(host, request.name, member)
: undefined;
// [ADR-0150 D3, #32914] …and, naming no package, a type addressed by
// package is judged by the registry's package-scoped resolver, as the
// plain read judges it ({@link getMetaItem}, its `packagelessScopedRead`):
Expand Down Expand Up @@ -903,7 +903,7 @@ async function getGenericMetaItemLayered(host: LayeredReadHost, request: {
// [#28409] …and an orphaned row (above) is a shadowed layer of the
// same kind: `effective` is the code layer the by-name read serves.
// [#34248, ruling 6893582352] …but not the package-less row behind a bare
// doc read's environment entry, beside two enabled holders: the entry the
// doc read's environment entry, beside one or more enabled holders: the entry the
// hydrator lays for it is tenant-authored, so it is no code layer (#21059,
// above), and the row it came from is the environment's own item, which
// answers first. Declined, `effective` was the empty code layer while the
Expand Down
Loading
Loading