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
15 changes: 15 additions & 0 deletions .changeset/38659-bare-read-own-envelope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/spec': patch
---

fix(metadata-protocol): the bare doc read of the environment's own entry carries the environment's envelope, never a package holder's

Clause-②: no
Metadata-protocol: none

A doc read that names no package (`GET /api/v1/meta/doc/NAME`, and the in-process `getMetaItem` with no `packageId`) answers the environment's own doc entry when one or more enabled packages ship the same name. It served that entry's content under the first registered holder's envelope: `item._packageId` and `item._packageVersion` that holder's, `_provenance: 'package'`, and the read envelope's `packageId`, `packageVersion` and `provenance` likewise. A client trusting the envelope read the environment's item as that package's, and with two holders the package it named followed registration order.

FROM the entry under the first registered holder's envelope, TO the entry under its own: no `_packageId` or `_packageVersion`, its own `_provenance` (`org` for a stored row the environment saved), and no `packageId` on the envelope. The lock is unchanged: it is still the write doors' answer at that address, and a save naming no package is still refused while a holder ships the name, so the envelope still reports `lock: full`. `?package=PACKAGE` still reads that package's doc under that package's envelope. `/layers` and `/published` carried no package envelope and are unchanged.

The fix for a caller that read the holder's id from the bare read: name the package (`?package=PACKAGE`, or `packageId` in process). The `os migrate meta --from 18` entry `doc-bare-read-environment-entry-first` no longer lists this as a known deviation.
6 changes: 6 additions & 0 deletions packages/metadata-protocol/src/protocol-meta-item-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
envelopePackageId,
exactAddressArtifact,
mergeArtifactProtection,
servesEnvironmentOwnItem,
withRowBinding,
} from './protocol-package-bindings.js';
import type { ServedOverrideRow } from './served-override.js';
Expand Down Expand Up @@ -1574,11 +1575,16 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
// [ADR-0150 D4, #33456] …and, for an action, at the served item's own
// owner key: an artifact another object binds the name to is another
// item, and lends this one no envelope ({@link artifactOwnerKeyOf}).
// [#38659, ruling 6942962369] …and the environment's own entry, served
// first beside one or more holders, wears none at all
// ({@link servesEnvironmentOwnItem}): never the first registered holder's.
const artifactOwner = artifactOwnerKeyOf(request.type, item);
const artifactItem = exactAddress
? exactAddressArtifact(exactAddress, (packageId) => host.lookupArtifactItem(
request.type, request.name, packageId, bundleMemberOf(request.type, item), artifactOwner,
))
: servesEnvironmentOwnItem(bareDocEnvironmentEntry, item)
? undefined
: host.lookupArtifactItem(
request.type, request.name, envelopePackageId(request.packageId, item), bundleMemberOf(request.type, item),
artifactOwner,
Expand Down
33 changes: 33 additions & 0 deletions packages/metadata-protocol/src/protocol-package-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
itemDiscriminator,
type InstalledManifestLookup,
} from '@objectstack/metadata-core';
import { storedItemPackageId } from '@objectstack/metadata/stored-item-package';
import { isServedOverrideRowOf } from './served-override.js';
import { canonicalMetaType } from './protocol-meta-type-schema.js';

Expand Down Expand Up @@ -238,6 +239,37 @@ function envelopePackageId(requestedPackageId: string | undefined, served: unkno
return requestedPackageId ?? (served as { _packageId?: string } | null | undefined)?._packageId;
}

/**
* [#38659, ruling 6942962369] Does a read that names no package serve the
* environment's own item where packages hold the same name? Then the answer
* wears NO artifact envelope: it keeps the item's own `_packageId` (none) and
* `_provenance`. Its lock is not chosen here and does not move: it is the
* write doors' answer at the read's address (the one item-lock resolution,
* {@link resolveItemLock}, and the sealed-base refusal, through the read's
* `servedLockState`), which refuse a save and a delete there while a holder
* ships the name, so the envelope still reports both refused.
*
* `environmentEntry` is the read's own verdict that the environment's entry
* answers first beside one or more enabled holders (the bare doc read's
* `refuseAmbiguousBareDocRead`), and `served` is the item the read's layers
* reached. Both must hold: the verdict, and a served item bound to no package
* ({@link storedItemPackageId}, the store's own reading, sentinel included).
*
* {@link envelopePackageId} names no package for such an item, so the
* package-less artifact lookup fell back to the first registered holder's
* artifact, and the environment's entry was served under that holder's
* `_packageId`, `_packageVersion` and `_provenance: 'package'`: a client
* trusting the envelope read the environment's item as that package's, and
* which package it named followed registration order. A package-less item
* the read did NOT judge to be the environment's own entry (a package-less
* row standing in for a base) keeps the base's envelope, as before.
*/
function servesEnvironmentOwnItem(environmentEntry: unknown, served: unknown): boolean {
return environmentEntry !== undefined && environmentEntry !== null
&& served !== undefined && served !== null
&& storedItemPackageId(served) === undefined;
}

/**
* [#32501, ADR-0150 D5, epic red line 2] The artifact envelope a read at an
* admitted exact address wears: the artifact of the ONE package that address
Expand Down Expand Up @@ -540,6 +572,7 @@ export {
isShippedViewItem,
mergeArtifactProtection,
perPackageLayerEnvelope,
servesEnvironmentOwnItem,
servesSealedOverrideRow,
stateTenantAuthorship,
stripDerivedProvenance,
Expand Down
Loading
Loading