Skip to content

Commit 2eb2f7c

Browse files
committed
fix(metadata-protocol): round 2 of #32607 — one read of the item's active rows, holders at the rows' grain, and only the row judgment's refusal handed over
Contract review 6868755969 (review#1) and CI on 5d3a6c7: - S2 / CI (objectql protocol-meta #24371 pins): the item face reads the active rows for its served-holder judgment on its own cache key and hands them to readMetaItem (PrereadActiveRows), which takes them for the same item: one read again. - M1, M2: the no-disabled arm (storedRowHoldersRefusal) judges holders at one grain, the packages the active rows bind at the member, never united with the registry's one bare slot; a row of a pair of another known package is no holder. - S1: the refusal carries a registered-symbol marker; both transports' layered owner step hands over only that refusal and rethrows every other. - n1: pins on a bundled type at a non-canonical member (M2), M1 in both save orders before and after a reboot, S1 on REST. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4czBmkW6UeWPazkWq7L
1 parent 5d3a6c7 commit 2eb2f7c

8 files changed

Lines changed: 283 additions & 24 deletions

File tree

‎.changeset/32607-two-enabled-row-holders.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Skills-docs: none — no skill and no doc teaches what the read naming no packag
1414

1515
**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.
1616

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 the registry's holders and the packages the active stored rows are bound to, and 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.
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.
1818

1919
**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.
2020

@@ -24,4 +24,4 @@ Narrowing:
2424
- 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.
2525
- The execution face (`getMetaItemForExecution`) of the same name: the row saved first → the same refusal.
2626

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 to the package-less refusal step, rethrowing every other refusal as before (two code holders, 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 bound to a holder's customization pair make no holder here, as they make none beside a disabled holder (#32354), so they never turn one holder into a refusal. 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).
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).

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

Lines changed: 90 additions & 15 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,
@@ -152,9 +153,8 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
152153
* `options.refuseWithoutDisabled` asks (the item face, {@link
153154
* readMetaItemFace}), two or more are refused the same way, naming each: the
154155
* plain read served the row saved first while `/layers` refused naming both.
155-
* That arm also requires that no enabled package ships the name at any member
156-
* (`shippedArtifactsOf` without a member, as `packagelessContentPackage`
157-
* reads it): a shipped name never fell to save order.
156+
* That arm is {@link storedRowHoldersRefusal}, which judges the holders at
157+
* the rows' grain alone.
158158
* Otherwise, and for one holder, `undefined` (the read already reads there).
159159
* The layered reads keep their own refusal for that case, the one the
160160
* package-less writes give (#28337).
@@ -214,23 +214,14 @@ export async function servedRowHolderOf(
214214
if (rows.unbound) return undefined;
215215
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
216216
const anyDisabled = [...every, ...rows.candidates].some(disabled);
217-
if (!anyDisabled && options.refuseWithoutDisabled !== true) return undefined;
218-
// [#32607] With no disabled holder, only a name no package ships moves. A
219-
// name an enabled package ships, at any member (a bundled type's base
220-
// shipping one locale beside another package's row of another), keeps the
221-
// read's own content judgment, which counts that shipper as it always has
222-
// (`packagelessContentPackage` over the name's shipped artifacts): there is
223-
// no save order to guess there.
224-
if (!anyDisabled && [...shippingPackageIds(host.shippedArtifactsOf(type, name))].some((id) => !disabled(id))) return undefined;
217+
if (!anyDisabled) return options.refuseWithoutDisabled === true ? storedRowHoldersRefusal(host, type, name, member, every, activeRows, rows.candidates) : undefined;
225218
const installed = installedManifestsOfEngine(host.engine);
226219
const pairRow = (row: { package_id?: unknown }): boolean =>
227220
typeof row.package_id === 'string' && every.some((holder) => pairsOf(holder, installed).includes(row.package_id as string));
228221
const servingRows = await host.packagelessAddress(type, name, member, 'active', activeRows.filter((row) =>
229222
!host.declinesStoredRow(type, name, row) && !pairRow(row)));
230223
const served = [...new Set([...(registry.packageScopedHoldersOf(type, name, null) ?? []), ...servingRows.candidates])]
231224
.filter((id) => !disabled(id));
232-
// [#32607] No disabled holder: only an ambiguity moves the read, and only the item face's.
233-
if (!anyDisabled && served.length < 2) return undefined;
234225
if (served.length === 1) return { kind: 'served', packageId: served[0] };
235226
if (served.length === 0) return undefined;
236227
const base = {
@@ -244,6 +235,73 @@ export async function servedRowHolderOf(
244235
return { kind: 'refused', error: new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }) };
245236
}
246237

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+
247305
/**
248306
* [#32183, #32354] The judgment of the address a read naming no package takes
249307
* for a name a disabled package also holds: the registry's served holder
@@ -322,10 +380,27 @@ export async function readMetaItemFace(
322380
// read resolves it: a malformed one is the read's own 400, never a 409
323381
// judged at a member nobody named.
324382
// [#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+
};
325400
const servedAddress = request.packageId
326401
? undefined
327-
: await servedAddressOf(this, request.type, request.name, resolveBundleMemberSelector(request.type, request.member), { refuseWithoutDisabled: true });
328-
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 } : {}) });
329404
// [#28877] The served read of an `action` also withholds one that launches
330405
// into a disabled package, as the served list does.
331406
const withheldAction = request.type === 'action' && face === 'served'

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,21 @@ export async function getMetaItemForExecution(host: Pick<ProtocolHost, 'readMeta
505505
}
506506

507507
/** The body of `ObjectStackProtocolImplementation#readMetaItem`; the method's docblock there is its contract. */
508+
/**
509+
* [#32607] The item's active rows a face read before {@link readMetaItem}
510+
* (`readItemActiveRows`, on the face's cache key), named by the type and name
511+
* they were read for: the read takes them only for that same item.
512+
*/
513+
export interface PrereadActiveRows {
514+
readonly type: string;
515+
readonly name: string;
516+
readonly rows: readonly StoredOverlayRow[];
517+
}
518+
508519
export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt' | 'convertStoredItem' | 'declinesStoredRow' | 'draftPublishVerdict' | 'engine' | 'findPairAddedMemberRow' | 'findServedOverlayRow' | 'foldObjectExtendersFromRegistry' | 'getServicesRegistry' | 'governServedObject' | 'isArtifactBacked' | 'isStoredEntryOfDeclinedName' | 'isStoredFlowEntryOfShippedName' | 'lookupArtifactItem' | 'overlayLockLayerAt' | 'packagelessAddress' | 'readItemActiveRows' | 'readItemFromMetadataService' | 'readVersionToken' | 'registryMemberServedAt' | 'resolveAppPackageIdKey' | 'resolveCascadeDeleteObjects' | 'resolveDisabledActionsReader' | 'resolveFlowRegistrationReader' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'servedLockState' | 'shippedArtifactsOf' | 'strictDraftReadAddress' | 'throwMetadataServiceUnavailable'>, request: {
509520
type: string, name: string, packageId?: string, state?: 'active' | 'draft', previewDrafts?: boolean,
510521
member?: string,
511-
}, opts: { face?: 'served' | 'execution' } = {}) {
522+
}, opts: { face?: 'served' | 'execution'; activeRows?: PrereadActiveRows } = {}) {
512523
// #4432 — CANONICAL TYPE KEY. See {@link canonicalMetaType}.
513524
request = canonicalizeMetaRequestType(request);
514525
// [#23183] ADR-0048 §3.1: the app read keyed by PACKAGE ID, resolved
@@ -725,7 +736,12 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
725736
// [#24535], execution) the read goes through the overlay cache; an
726737
// authoring read is never kept.
727738
let activeRows: StoredOverlayRow[] | undefined;
728-
if (readState === 'active') {
739+
// [#32607] …or taken from the face that already read them for its
740+
// served-holder judgment, when they are this item's: still one read.
741+
const preread = opts.activeRows;
742+
if (readState === 'active' && preread !== undefined && preread.type === request.type && preread.name === request.name) {
743+
activeRows = [...preread.rows];
744+
} else if (readState === 'active') {
729745
try {
730746
activeRows = await host.readItemActiveRows(request.type, request.name, opts.face !== undefined);
731747
} catch (error) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ import { legacyOrganizationRowsOf, withoutLegacyOrganizationRows } from './proto
359359
import { foldObjectExtendersFromRegistry } from './protocol-object-extender-fold.js';
360360
// [#25467 cut 31] The disabled-package face of the by-name item read.
361361
import { readMetaItemFace } from './protocol-meta-item-face.js';
362+
import type { PrereadActiveRows } from './protocol-meta-item-reads.js';
362363
// [#25467 cut 32] A stored commit row's `items` column read back as its revert plan.
363364
import { parseCommitItems } from './protocol-commit-items.js';
364365
// [#25467 cut 33] What a stored overlay row binds: the lock layer, the package binding, the external datasource.
@@ -4157,11 +4158,15 @@ export class ObjectStackProtocolImplementation implements
41574158
* [#24535] `face: 'execution'` skips the serving decorations at this
41584159
* read's exits, and nothing else: see {@link getMetaItemForExecution}. An
41594160
* authoring caller is decorated as the served face is, as before.
4161+
*
4162+
* [#32607] `activeRows`: the item's active rows a face already read for
4163+
* its served-holder judgment ({@link readMetaItemFace}), taken instead of
4164+
* a second read when they are this read's item's (#24371: one read).
41604165
*/
41614166
private async readMetaItem(request: {
41624167
type: string, name: string, packageId?: string, state?: 'active' | 'draft', previewDrafts?: boolean,
41634168
member?: string,
4164-
}, opts: { face?: 'served' | 'execution' } = {}) {
4169+
}, opts: { face?: 'served' | 'execution'; activeRows?: PrereadActiveRows } = {}) {
41654170
// [#25467 E1] The body moved to `protocol-meta-item-reads.ts`; it reaches this class through `protocol-host.ts`.
41664171
return readMetaItem(protocolHost(this), request, opts);
41674172
}

0 commit comments

Comments
 (0)