From 9d731b0e85ee522496faf86a89f8b02732c917de Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 18:26:35 +0000 Subject: [PATCH 01/11] fix(metadata-protocol): the bare writes beside a disabled holder's row refuse naming the holders the read names Criterion (#34346): two enabled packages ship a name and its stored rows are bound to a disabled package and to one of them. The bare publish save, the bare draft save and the bare delete refuse 409 naming the two enabled holders, as the bare read does, never the disabled package, and write or remove nothing; ?package=E saves and deletes as before. The publish save wrote the one enabled binding's row (200); the draft save and the delete refused naming that package and the disabled one. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../src/protocol-diff-delete-load.ts | 16 ++- .../metadata-protocol/src/protocol-save.ts | 121 +++++++++++++++--- .../meta-disabled-holder-served-stack.test.ts | 52 +++++++- 3 files changed, 166 insertions(+), 23 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-diff-delete-load.ts b/packages/metadata-protocol/src/protocol-diff-delete-load.ts index 092841c7fb6..b504afc6061 100644 --- a/packages/metadata-protocol/src/protocol-diff-delete-load.ts +++ b/packages/metadata-protocol/src/protocol-diff-delete-load.ts @@ -67,7 +67,7 @@ import { withRefusalAudit } from './protocol-refusal-audit.js'; import { captureStoredExpressionChange, fillStoredExpressionChange } from './protocol-stored-expression-fill.js'; import type { RuntimeAuthoringIssue } from './runtime-authoring-gate.js'; import type { ProtocolHost } from './protocol-host.js'; -import { packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js'; +import { disabledRowHoldersRefusal, packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js'; import { isPlatformRecordRow } from '@objectstack/metadata'; import { retireOverlayCacheOnRollback } from './meta-overlay-cache.js'; @@ -729,7 +729,11 @@ export class ProtocolDiffDeleteLoadFacet { if (draftAddress?.kind === 'ambiguous') { const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member); if (base === undefined) { - addressRefusal = packagelessAddressAmbiguityRefusal( + // [#34346] …naming the holders the read counts where a + // row is bound to a disabled package ({@link disabledRowHoldersRefusal}). + addressRefusal = disabledRowHoldersRefusal( + host, 'delete', request.type, singularTypeForRepo, request.name, member, draftAddress.candidates, + ) ?? packagelessAddressAmbiguityRefusal( 'delete', request.type, request.name, draftAddress.candidates, ); throw addressRefusal; @@ -743,7 +747,13 @@ export class ProtocolDiffDeleteLoadFacet { if (request.packageId == null && draftAddress === undefined && rowsAtAddress.candidates.length > 1) { const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member); if (base === undefined) { - addressRefusal = packagelessAddressAmbiguityRefusal( + // [#34346, ADR-0150 D3/D5] Rows bound to a disabled + // package too are refused naming the holders the read + // naming no package counts, never the disabled one + // ({@link disabledRowHoldersRefusal}). + addressRefusal = disabledRowHoldersRefusal( + host, 'delete', request.type, singularTypeForRepo, request.name, member, rowsAtAddress.candidates, + ) ?? packagelessAddressAmbiguityRefusal( 'delete', request.type, request.name, rowsAtAddress.candidates, ); throw addressRefusal; diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index c61f3bf9df9..7d0168d49d0 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -946,6 +946,17 @@ export class ProtocolSaveFacet { followedBase = base; } } + // [#34346, ADR-0150 D3/D5] …and an ambiguous draft address whose + // rows are bound to a disabled package too is refused naming the + // holders the read naming no package counts, never the disabled one + // ({@link disabledRowHoldersRefusal}); the repository's `409` named + // the rows' bindings. + if (draftAddress?.kind === 'ambiguous') { + const besideDisabled = disabledRowHoldersRefusal( + host, 'save', request.type, singularType, request.name, itemDiscriminator(singularType, request.item), draftAddress.candidates, + ); + if (besideDisabled) throw besideDisabled; + } // [ADR-0150 D4] The environment's own action draft is one slot per // name, and its per-item publish writes the one package-unbound row: // a holder's customization stored in either is refused, never moved @@ -3145,10 +3156,10 @@ export class ProtocolSaveFacet { * disabled packages hold (no served holder to take the write; that judgment * refuses it naming no package). * - * Known gap: two or more ENABLED packages hold the name and the stored rows - * are bound to a disabled package and to exactly one of them. The enabled - * bindings above pick that one (the save answers 200) where the read refuses - * `409` naming every enabled holder. A follow-up card is filed. + * [#34346] Two or more ENABLED packages hold the name and the stored rows + * are bound to a disabled package and to exactly one of them: refused naming + * the enabled holders, as the read refuses it. The enabled binding picked + * that one package (the save answered 200). * * Without it the save door counted the disabled holder as a holder: over no * stored row it wrote a package-unbound row (an environment-own item that @@ -3186,6 +3197,15 @@ async function servedPackagelessSaveAddress( if (!address.candidates.some(disabled)) return undefined; const enabled = address.candidates.filter((id) => !disabled(id)); if (enabled.length > 1) throw packagelessAddressAmbiguityRefusal('save', type, name, enabled); + // [#34346, ADR-0150 D5] …and where the rows name one enabled package but + // two or more enabled packages hold the name (they ship it), the bare + // read refuses naming those, so the save does too: the one row's binding + // wrote that package's row. A package-unbound row at the address is the + // row the write edits, as with no disabled holder. + if (!address.unbound && !atObject) { + const enabledHolders = enabledHoldersRefusal(registry as HolderRegistry, 'save', type, type, name, member); + if (enabledHolders) throw enabledHolders; + } if (enabled.length === 1) return { packageId: enabled[0] ?? null }; if (address.unbound) return { packageId: null }; if (atObject) { @@ -3621,10 +3641,10 @@ export async function packagelessRowHeldBaseDraftAddress( * leave to the write), a type the registry does not read by package, or a * registry without the reads. * - * Known gap: with an enabled and a disabled holder, the draft save and the - * delete have no {@link servedPackagelessSaveAddress} step and still take - * their address from the rows, and that step's own gap stands for the publish - * save. A follow-up card is filed. + * [#34346] With an enabled and a disabled holder, the draft save and the + * delete take their address from the rows, so their refusal of rows bound to + * two or more packages is judged by {@link disabledRowHoldersRefusal}, which + * never names the disabled package. */ export function packagelessHolderRefusal( host: Pick, @@ -3660,17 +3680,9 @@ export function packagelessHolderRefusal( // A package-unbound row at the address leaves the ENABLED holders' answer // as it was (the write edits that row); only the disabled-holders // judgment below reads past it. - if (arms === 'all' && verb !== 'rollback' && !address.unbound && typeof registry.resolveItem === 'function') { - try { - registry.resolveItem(type, name, null, member); - } catch (error) { - const refusal = packageScopedRefusalOf(error); - if (refusal === undefined) throw error; - const held = refusal.reason === 'ambiguous-in-environment' - ? refusal.candidates.flatMap((candidate) => (candidate.kind === 'package' ? [candidate.packageId] : [])) - : []; - if (held.length > 1) return packagelessAddressAmbiguityRefusal(verb, shownType, name, held); - } + if (arms === 'all' && verb !== 'rollback' && !address.unbound) { + const enabledHolders = enabledHoldersRefusal(registry, verb, shownType, type, name, member); + if (enabledHolders) return enabledHolders; } if (typeof registry.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined; const disabled = (id: string): boolean => registry.isPackageDisabled?.(id) === true; @@ -3691,6 +3703,77 @@ export function packagelessHolderRefusal( } /** The registry reads {@link packagelessHolderRefusal} asks, each optional-called. */ +/** + * The package-scoped resolver's own refusal of a name two or more ENABLED + * packages hold (`resolveItem` naming no package, the judgment the by-name + * read asks before any layer), restated as the write's refusal naming those + * packages; `undefined` when the resolver serves the name or the registry + * cannot judge it. A disabled package is never among them (ADR-0150 D3). + */ +function enabledHoldersRefusal( + registry: HolderRegistry, + verb: Exclude, + shownType: string, + type: string, + name: string, + member: string | undefined, +): (Error & { code: 'RESOURCE_CONFLICT'; status: 409 }) | undefined { + if (typeof registry.resolveItem !== 'function') return undefined; + try { + registry.resolveItem(type, name, null, member); + } catch (error) { + const refusal = packageScopedRefusalOf(error); + if (refusal === undefined) throw error; + const held = refusal.reason === 'ambiguous-in-environment' + ? refusal.candidates.flatMap((candidate) => (candidate.kind === 'package' ? [candidate.packageId] : [])) + : []; + if (held.length > 1) return packagelessAddressAmbiguityRefusal(verb, shownType, name, held); + } + return undefined; +} + +/** + * [#34346, ADR-0150 D3/D5] The refusal a write naming no package gives where + * the item's stored rows are bound to a disabled package and its address is + * otherwise judged from those rows alone (the draft save's ambiguous draft + * address, the delete's and the draft discard's rows). The holders are the + * ones the read naming no package counts, never the disabled package: + * + * - two or more ENABLED packages hold the name in the registry: the + * package-scoped resolver's refusal naming them + * ({@link enabledHoldersRefusal}), as the bare read refuses it; + * - else two or more enabled packages the rows are bound to: refused + * naming only those; + * - `undefined` otherwise (no row bound to a disabled package, a type the + * registry does not read by package, the environment's own item, or one + * enabled holder or none): the door answers as before. + * + * The refusal named the rows' bindings, the disabled package among them, + * while the read refused naming the enabled holders. + */ +export function disabledRowHoldersRefusal( + host: Pick, + verb: Exclude, + shownType: string, + type: string, + name: string, + member: string | undefined, + candidates: readonly string[], +): (Error & { code: 'RESOURCE_CONFLICT'; status: 409 }) | undefined { + const registry = host.engine?.registry as HolderRegistry | undefined; + if (typeof registry?.isPackageDisabled !== 'function') return undefined; + if (typeof registry.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined; + const disabled = (id: string): boolean => registry.isPackageDisabled?.(id) === true; + if (!candidates.some(disabled)) return undefined; + if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) { + return undefined; + } + const enabledHolders = enabledHoldersRefusal(registry, verb, shownType, type, name, member); + if (enabledHolders) return enabledHolders; + const enabled = candidates.filter((id) => !disabled(id)); + return enabled.length > 1 ? packagelessAddressAmbiguityRefusal(verb, shownType, name, enabled) : undefined; +} + interface HolderRegistry { readsByPackage?(type: string): boolean; getEnvironmentScopedItem?(type: string, name: string, member?: string): unknown; diff --git a/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts b/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts index ae16d23c8b4..56ea7f1fd7a 100644 --- a/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts +++ b/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts @@ -1225,7 +1225,9 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol const BOTH_SHIP = ['ship_none_dash', 'ship_drow_dash', 'ship_de_dash', 'ship_ed_dash']; const E_SHIPS = ['e_only_dash', 'e_authored_drow_dash', 'e_unbound_drow_dash', 'e_two_authored_dash']; // [#33955] Names two ENABLED packages ship (neither disabled), and [#34144] names only D ships. - const TWO_SHIP = ['two_none_dash', 'two_erow_dash', 'two_drow_dash', 'two_rows_dash', 'two_unbound_dash', 'two_draft_dash', 'two_del_dash', 'two_norow_dash']; + const TWO_SHIP = ['two_none_dash', 'two_erow_dash', 'two_drow_dash', 'two_rows_dash', 'two_unbound_dash', 'two_draft_dash', 'two_del_dash', 'two_norow_dash', + // [#34346] Two enabled packages ship it; stored rows bound to a disabled authored D and to E. + 'two_dis_pub_dash', 'two_dis_draft_dash', 'two_dis_del_dash', 'two_dis_named_dash']; const D_SHIPS = ['d_none_dash', 'd_drow_dash', 'd_unbound_dash', 'd_draft_dash', 'd_del_dash', 'd_norow_dash', // [ADR-0150 D3, the 2026-11-26 note] Names only D ships, each with a package-unbound row or draft stored. 'd_unbound_hidden_draft_dash', 'd_unbound_draft_only_dash', 'd_unbound_drow_dash']; @@ -1720,6 +1722,54 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol expect(await everyRow(booted!.engine, 'two_del_dash')).toEqual([]); }); + // [#34346, ADR-0150 D3/D5] Two ENABLED packages ship the name and the + // stored rows are bound to a disabled authored D and to E: the bare + // read refuses naming E and the other shipper, so the bare publish + // save, the bare draft save and the bare delete refuse naming the + // same two, never the disabled D, and nothing is written or removed. + // FROM (`main` 7213177e): the publish save answered 200 and wrote E's + // row; the draft save and the delete refused naming E and D. + it('[#34346] two enabled packages ship it, rows bound to a disabled D and to E: the bare publish save, draft save and delete refuse naming the two shippers, never D, and nothing moves', async () => { + const protocol = booted!.kernel.getService('protocol'); + const names = ['two_dis_pub_dash', 'two_dis_draft_dash', 'two_dis_del_dash']; + for (const name of names) { + await layRow(booted!.engine, name, AUTH_D, 'disabled row'); + await layRow(booted!.engine, name, CODE_E, 'E row'); + } + const before = Object.fromEntries(await Promise.all(names.map(async (name) => [name, await everyRowBytes(booted!.engine, name)] as const))); + const namingShippers = (answer: { status: number | undefined; body: any }, door: string) => { + expect([door, answer.status, codeOf(answer.body)], JSON.stringify(answer.body)).toEqual([door, 409, 'RESOURCE_CONFLICT']); + for (const id of [CODE_E, CODE_D]) expect(JSON.stringify(answer.body), door).toContain(id); + expect(JSON.stringify(answer.body), door).not.toContain(AUTH_D); + }; + await withDisabled(AUTH_D, async () => { + namingShippers(await get(booted!.kernel, '/meta/dashboard/two_dis_pub_dash'), 'read'); + namingShippers(await booted!.put('two_dis_pub_dash', 'edited'), 'publish save'); + namingShippers(await booted!.put('two_dis_draft_dash', 'drafted', { mode: 'draft' }), 'draft save'); + namingShippers(await booted!.del('two_dis_del_dash'), 'delete'); + const refusal = await refusalOf(protocol.deleteMetaItem({ type: 'dashboard', name: 'two_dis_del_dash' })); + expect([refusal?.code, refusal?.status], JSON.stringify(refusal?.resolved ?? String(refusal?.message))).toEqual(['RESOURCE_CONFLICT', 409]); + for (const id of [CODE_E, CODE_D]) expect(String(refusal?.message)).toContain(id); + expect(String(refusal?.message)).not.toContain(AUTH_D); + for (const name of names) expect(await everyRowBytes(booted!.engine, name), name).toEqual(before[name]); + }); + }); + + it('[#34346] CONTROL: the same rows, ?package=E saves and deletes E\'s row as before, and D\'s row is byte-unchanged', async () => { + await layRow(booted!.engine, 'two_dis_named_dash', AUTH_D, 'disabled row'); + await layRow(booted!.engine, 'two_dis_named_dash', CODE_E, 'E row'); + const before = await storedRows(booted!.engine, 'two_dis_named_dash'); + await withDisabled(AUTH_D, async () => { + const saved = await booted!.put('two_dis_named_dash', 'named', { package: CODE_E }); + expect(saved.status, JSON.stringify(saved.body)).toBe(200); + const rows = await storedRows(booted!.engine, 'two_dis_named_dash'); + expect(rows[CODE_E]?.label).toBe('named'); + expect(rows[AUTH_D]?.bytes).toBe(before[AUTH_D]?.bytes); + expect(await booted!.kernel.getService('protocol').deleteMetaItem({ type: 'dashboard', name: 'two_dis_named_dash', packageId: CODE_E })).toMatchObject({ success: true }); + expect(Object.keys(await storedRows(booted!.engine, 'two_dis_named_dash'))).toEqual([AUTH_D]); + }); + }); + // [#33955 review#1 S2] Over NO stored row the bare delete and the bare // draft discard answered the no-op receipt. They are refused naming // both, as the bare read is. From 0a14e9007fc720e48d196853586f9650491ac949 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 18:30:41 +0000 Subject: [PATCH 02/11] fix(metadata-protocol): a hydrated package-less doc row of a name two packages ship wears no holder's envelope Criterion (#34417, rewritten by the seat to ruling 6942962369): the environment's package-less doc row, hydrated after the artifacts registered (loadMetaFromDb), answers first on every bare door on both transports and in both registration orders, and each holder's exact address (plain read and /layers) reads that holder's own doc. The hydrator grafted the first registered holder's envelope onto the row, so ?package=FIRST served the environment's row under that holder's name and the bare doors refused 409. The review M1 CONTROL that pinned the FROM is replaced by the criterion's pin. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../src/protocol-registry-hydration.ts | 12 +++++- ...meta-disabled-holder-artifact-door.test.ts | 40 ++++++++++++------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index 8421b125368..bab8d411dff 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -920,10 +920,20 @@ export class ProtocolRegistryHydrationFacet { const envelopePackage = pairHolder !== NOT_A_PAIR_ROW ? pairHolder : options.packageId ?? (scoped ? soleHolderOf(registry, canonicalType, rowName) : undefined); + // [#34417, ruling 6942962369] …and a package-less `doc` row of a name + // two or more packages ship wears none either: it is the environment's + // own item, which answers first on every read naming no package, and + // never one holder's. A `doc` is no type the registry reads by package, + // so the lookup naming no package grafted the FIRST registered + // holder's envelope onto it, and that holder's exact address then + // served the environment's row under its name while the bare doors + // refused naming both. + const environmentDoc = canonicalType === 'doc' && !options.packageId + && [...shippingPackageIds(host.shippedArtifactsOf(type, rowName))].length > 1; // [ADR-0150 D2] A stored permission row wears its own package's // envelope only ({@link ownPermissionEnvelope}), never the envelope of // another namespace's set the lookup falls back to. - const artifact = envelopePackage === null ? undefined : ownPermissionEnvelope(registry, canonicalType, boundPackageOf(options.packageId), host.lookupArtifactItem( + const artifact = envelopePackage === null || environmentDoc ? undefined : ownPermissionEnvelope(registry, canonicalType, boundPackageOf(options.packageId), host.lookupArtifactItem( type, (data as any).name, envelopePackage ?? undefined, bundleMemberOf(type, data), )); // [#29600] See the header: a dashboard, report or email-template row diff --git a/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts b/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts index 256eaae3774..13ff3e55005 100644 --- a/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts +++ b/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts @@ -575,23 +575,35 @@ describe.each([ } }); - // [review M1] The same stored row hydrated by the production read - // (`loadMetaFromDb`) after the artifacts registered: the hydrator grafts - // the first holder's envelope onto it, so no package-less entry exists - // and every bare door refuses naming both, as on main (measured at - // origin/main c9346317 and at this head). The other holder's address - // reads its own doc. - it('CONTROL [#34248]: the row hydrated after the artifacts (`loadMetaFromDb`) wears the first holder\'s envelope, and the bare doors refuse 409 naming both on both transports', async () => { + // [#34417, ruling 6942962369] The same stored row hydrated by the + // production read (`loadMetaFromDb`) after the artifacts registered is + // the environment's own item, as when it was hydrated before them: it + // wears no holder's envelope, every bare door serves it, and each + // holder's exact address (the plain read and /layers; `/published` takes + // no `?package=`) reads that holder's own doc. FROM (`main` 7213177e, this rig, both orders; pinned + // here as review M1's CONTROL): the hydrator grafted the FIRST holder's + // envelope onto the row (`_packageId` that holder, `_provenance: + // 'package'`), so `?package=FIRST` served the environment's row under + // that holder's name and every bare door refused 409 naming both. + it('[#34417] the row hydrated after the artifacts (`loadMetaFromDb`) wears no holder\'s envelope: every bare door serves it on both transports, and each holder\'s exact address reads its own doc on the plain read and /layers', async () => { await layRowOnce(); const hydrated = await (booted!.kernel.getService('protocol') as { loadMetaFromDb(): Promise<{ loaded: number; errors: number }> }).loadMetaFromDb(); expect([hydrated.loaded > 0, hydrated.errors]).toEqual([true, 0]); - const entry = docRegistryOf(booted!).get('shared_doc') as { _packageId?: unknown; _provenance?: unknown } | undefined; - expect([entry?._packageId, entry?._provenance]).toEqual([packages[0], 'package']); - await expectRefusedNamingBoth(); - const second = packages[1]!; - for (const answer of await exactDocDoors(booted!, second)) { - expect([answer.status, (answer.body?.item ?? answer.body)?.label, answer.door], JSON.stringify(answer.body)) - .toEqual([200, `${second.split('.').pop()} doc`, answer.door]); + const entry = docRegistryOf(booted!).get('shared_doc') as { label?: unknown; _packageId?: unknown; _provenance?: unknown } | undefined; + expect([entry?.label, entry?._packageId, entry?._provenance]).toEqual(['environment doc', undefined, 'org']); + await expectBareDoorsServe({ item: 'environment doc', code: undefined, overlay: 'environment doc' }); + for (const packageId of packages) { + const label = `${packageId.split('.').pop()} doc`; + // `/layers` reports the environment's row as the `env`-scoped + // overlay beside the holder's code, as on `main`; the served + // (`effective`) layer is the holder's own doc. + for (const answer of await exactDocAndLayers(booted!, packageId)) { + const served = answer.door.includes('/layers') + ? [answer.body?.code?.label, answer.body?.effective?.label] + : [(answer.body?.item ?? answer.body)?.label, (answer.body?.item ?? answer.body)?._packageId]; + const want = answer.door.includes('/layers') ? [label, label] : [label, packageId]; + expect([answer.status, ...served, answer.door], JSON.stringify(answer.body)).toEqual([200, ...want, answer.door]); + } } docRegistryOf(booted!).delete('shared_doc'); }); From a8bf4118981c005774c63962c7b6d6eeee6af184 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 18:38:59 +0000 Subject: [PATCH 03/11] fix(metadata-protocol): a package-less overlay row whose every holder is disabled wears no envelope and stays recorded for the heal #33127 heal 2. With no holder of the name served, the hydrator's lookup naming no package answered a disabled holder's artifact, and the heal run by an enable in that state rebuilt through the same lookup and dropped its record. The entry kept the disabled holder's envelope, and the enable that then served one holder had nothing to rebuild: its slot answered its code, not the row, until the next unscoped hydration. Now, for the three healed overlay types, a package-less row with no holder served wears none (a disabled package holds no name, #32354) and is recorded with no holder, by the hydrator and by the heal alike, so the enable that serves one holder builds it under that holder's envelope, as the hydrator lays it then. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../src/protocol-registry-hydration.ts | 31 +++++++++++--- ...ol.lookup-artifact-item-call-sites.test.ts | 6 +-- .../package-scoped-exact-qualifier.test.ts | 41 +++++++++++++++++++ 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index bab8d411dff..ba70ea5ed62 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -372,8 +372,8 @@ interface SoleHolderEnvelope { readonly name: string; readonly member: string | undefined; readonly data: unknown; - /** The holder whose envelope the entry wears. */ - readonly holder: string; + /** The holder whose envelope the entry wears; `undefined` while no holder is served and it wears none (#33127 heal 2). */ + readonly holder: string | undefined; /** The entry as registered: the heal touches the slot only while it still holds this object. */ readonly registered: unknown; } @@ -447,10 +447,16 @@ function healSoleHolderEnvelopes(registry: EnvelopeRegistry, records: Map 1; + // [#33127 heal 2, #32354] …and a package-less row of a healed overlay + // type ({@link HEALED_OVERLAY_TYPES}) whose every holder is disabled + // wears none: a disabled package holds no name, so no holder is served + // to claim the row, and the lookup naming no package answered the + // first registered holder's artifact although that package is off. + // Worn, it withheld the environment's own row on the bare door with + // its holder, and the hydrator recorded no envelope, so the next + // enable had nothing to build again. It registers as the environment's + // tenant row and is recorded ({@link recordSoleHolderEnvelope}), so the + // enable that serves one holder builds it under that holder's envelope. + const noHolderServed = !options.packageId && envelopePackage === undefined && scoped + && HEALED_OVERLAY_TYPES.has(canonicalType) && holdersOfEvery(registry, canonicalType, rowName).length > 0; // [ADR-0150 D2] A stored permission row wears its own package's // envelope only ({@link ownPermissionEnvelope}), never the envelope of // another namespace's set the lookup falls back to. - const artifact = envelopePackage === null || environmentDoc ? undefined : ownPermissionEnvelope(registry, canonicalType, boundPackageOf(options.packageId), host.lookupArtifactItem( + const artifact = envelopePackage === null || environmentDoc || noHolderServed ? undefined : ownPermissionEnvelope(registry, canonicalType, boundPackageOf(options.packageId), host.lookupArtifactItem( type, (data as any).name, envelopePackage ?? undefined, bundleMemberOf(type, data), )); // [#29600] See the header: a dashboard, report or email-template row @@ -1010,8 +1028,9 @@ export class ProtocolRegistryHydrationFacet { // of the key forgets it. [#33127] A package overlay slot is another key. const member = bundleMemberOf(type, data); if (!overlaySlot) recordSoleHolderEnvelope(registry, envelopeKey(type, rowName, member), - !options.packageId && typeof envelopePackage === 'string' && envelope && HEALED_OVERLAY_TYPES.has(canonicalType) - ? { host, type, canonicalType, name: rowName, member, data, holder: envelopePackage, registered } + !options.packageId && HEALED_OVERLAY_TYPES.has(canonicalType) + && ((typeof envelopePackage === 'string' && envelope) || noHolderServed) + ? { host, type, canonicalType, name: rowName, member, data, holder: noHolderServed ? undefined : envelopePackage as string, registered } : undefined); await host.hydrateExpandedViewItems(type, data, options); return true; diff --git a/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts b/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts index ee638b642b5..c662e144a1a 100644 --- a/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts +++ b/packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts @@ -165,9 +165,9 @@ const SITES: ReadonlyArray { + const slot = (at === undefined ? registry.getItem('email_template', 'welcome', undefined, 'en-US') : registry.getPackageScopedItem('email_template', 'welcome', at)) as { label?: string; _packageId?: string } | undefined; + return [slot?.label, slot?._packageId]; + }; + + it('[#33127 heal 2] an enable while no holder is served (A disabled, B disabled, an unrelated C enabled) builds the entry under no envelope and keeps it recorded: the enable that serves B alone makes it B\'s customization, as the hydrator lays it then', async () => { + holderOwn('email_template', A); + holderOwn('email_template', B); + storeEnvRow('email_template'); + registry.disablePackage(B); + registry.disablePackage(C); + await protocol.getMetaItems({ type: 'email_template' } as never); + expect(slotOf(A), 'B disabled, hydrated: A alone served').toEqual(['env row', A]); + registry.disablePackage(A); + registry.enablePackage(C); + // No holder served: the environment's row, under no disabled holder's envelope (#32354). + expect(slotOf(), 'A and B disabled, C enabled').toEqual(['env row', undefined]); + registry.enablePackage(B); + expect(slotOf(B), 'B enabled: B alone served').toEqual(['env row', B]); + expect(await readers('email_template', A), 'B enabled: A\'s own, withheld with A').toMatchObject({ stamp: A, slot: 'alpha own' }); + // CONTROL — what the hydrator lays for the same holders served. + const healed = registry.getItem('email_template', 'welcome', undefined, 'en-US'); + await protocol.getMetaItems({ type: 'email_template' } as never); + expect(registry.getItem('email_template', 'welcome', undefined, 'en-US')).toEqual(healed); + }); + + it('[#33127 heal 2] the hydrator run while no holder is served lays the row under no envelope and records it: the enable that serves B alone builds it under B\'s', async () => { + holderOwn('email_template', A); + holderOwn('email_template', B); + storeEnvRow('email_template'); + registry.disablePackage(A); + registry.disablePackage(B); + await protocol.getMetaItems({ type: 'email_template' } as never); + expect(slotOf(), 'A and B disabled, hydrated').toEqual(['env row', undefined]); + registry.enablePackage(B); + expect(slotOf(B), 'B enabled: B alone served').toEqual(['env row', B]); + registry.enablePackage(A); + expect(await readers('email_template', A), 'both enabled').toEqual(own(A)); + expect(await readers('email_template', B), 'both enabled').toEqual(own(B)); + }); + it('a package-less permission row is not recorded: an enable leaves the hydrated slot as the hydrator laid it (review s1; the heal moves only the three declared overlay types)', async () => { admitSecondPermissionHolder(); holderOwn('permission', A); From 616d76d86aeffe0893109a40030baa6b55c62675 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 18:59:59 +0000 Subject: [PATCH 04/11] fix(metadata-protocol): the doors naming no package answer the environment's own action on another object first #33904, ADR-0150 D4, ruling 6942962369. With a package's action of a name on one object and the environment's own package-less action of the name on another (no package's action of the name binds it), the two are items of their own at D4's key (package, objectName, name), as the save door (ruling 6902014292) and the action route already key them. The doors that name neither a package nor an object took the one package the stored rows are bound to: - the plain read, `/layers` `effective` and `/published` served the package's item, and the plain read's `version` was the package's; - the merged list slotted actions by name, so it named the package's item only; - the delete removed the package's row and left the environment's. Now one predicate, holdsEnvironmentOwnAction, reads the environment's own action off the item's active rows. The read naming no package serves its row and version, the list slots an action by (name, object), and the delete removes its row and retires the registry's bare-slot entry it left. With no such row every door answers as before. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../src/protocol-diff-delete-load.ts | 13 +- .../src/protocol-lock-version-gates.ts | 17 +- .../src/protocol-meta-item-reads.ts | 14 +- .../src/protocol-overlay-merge.ts | 13 +- .../src/protocol-registry-hydration.ts | 12 ++ .../protocol.packageless-save-address.test.ts | 57 +++++- packages/metadata-protocol/src/protocol.ts | 2 + .../src/sys-metadata-repository.ts | 29 +++ ...t-packageless-other-object.dogfood.test.ts | 19 +- ...e-packageless-other-object.dogfood.test.ts | 32 +-- ...ironment-action-other-object-33904.test.ts | 187 ++++++++++++++++++ 11 files changed, 363 insertions(+), 32 deletions(-) create mode 100644 packages/runtime/src/domains/meta-environment-action-other-object-33904.test.ts diff --git a/packages/metadata-protocol/src/protocol-diff-delete-load.ts b/packages/metadata-protocol/src/protocol-diff-delete-load.ts index b504afc6061..dce3e7b336b 100644 --- a/packages/metadata-protocol/src/protocol-diff-delete-load.ts +++ b/packages/metadata-protocol/src/protocol-diff-delete-load.ts @@ -27,6 +27,7 @@ import { applyOldShapeFormRowRemovals, healOldShapeFormRowRemovals, type OldShap import { overlayMemberWhere } from './migrations/overlay-index.js'; import { historyRowsOfMember, + holdsEnvironmentOwnAction, isVersionOf, packagelessAddressAmbiguityRefusal, versionNotFoundError, @@ -800,8 +801,18 @@ export class ProtocolDiffDeleteLoadFacet { throw addressRefusal; } } + // [#33904, ADR-0150 D4, ruling 6942962369] A delete naming no + // package of an action whose package-unbound row is the + // environment's own item, on an object no package's row binds + // ({@link holdsEnvironmentOwnAction}), removes that row: the + // environment's own item answers first, as on the read naming + // no package. It removed the one package's row the rows are + // bound to, on another object, and left the environment's. + const environmentAction = request.packageId == null && targetState === 'active' && rowsAtAddress.unbound + && singularTypeForRepo === 'action' && rowsAtAddress.candidates.length > 0 + && holdsEnvironmentOwnAction(singularTypeForRepo, await host.readItemActiveRows(singularTypeForRepo, request.name)); const packageId: string | null = request.packageId - ?? (draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId); + ?? (environmentAction ? null : draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId); // [ADR-0150 D2, #34401] Whether a code-shipped item sits under // THIS address, which the two receipts below claim: a package's // own permission set beside sets other namespaces' packages ship diff --git a/packages/metadata-protocol/src/protocol-lock-version-gates.ts b/packages/metadata-protocol/src/protocol-lock-version-gates.ts index ba98e4c14c2..f1995710154 100644 --- a/packages/metadata-protocol/src/protocol-lock-version-gates.ts +++ b/packages/metadata-protocol/src/protocol-lock-version-gates.ts @@ -49,7 +49,7 @@ import type { ObjectStackProtocolImplementation, MetadataAuditEntry } from './protocol.js'; import { canonicalMetaType } from './protocol.js'; -import { SysMetadataRepository, actionHeldOnlyOnOtherObjects, unboundItemDraftAddress } from './sys-metadata-repository.js'; +import { SysMetadataRepository, actionHeldOnlyOnOtherObjects, holdsEnvironmentOwnAction, unboundItemDraftAddress } from './sys-metadata-repository.js'; import { packagelessContentPackage } from './protocol-environment-rows.js'; import { resolveItemLockLazily } from './item-lock.js'; import { ConflictError } from '@objectstack/metadata-core'; @@ -440,9 +440,22 @@ export async function readVersionToken( /** The body of `ObjectStackProtocolImplementation#packagelessReadAddress`; the method's docblock there is its contract. */ export async function packagelessReadAddress( - this: Pick, + this: Pick, type: string, name: string, member?: string): Promise { const singular = PLURAL_TO_SINGULAR[type] ?? type; + // [#33904, ADR-0150 D4, ruling 6942962369] The environment's own action + // ({@link holdsEnvironmentOwnAction}) is the package-unbound row: the + // layered read's `effective` and `/published` serve it, as the plain read + // does, never the one package the rows are bound to on another object. + if (singular === 'action') { + let activeRows: Awaited> = []; + try { + activeRows = await this.readItemActiveRows(singular, name); + } catch (error) { + this.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata'); + } + if (holdsEnvironmentOwnAction(singular, activeRows)) return null; + } return packagelessContentPackage(await this.packagelessAddress(singular, name, member), this.shippedArtifactsOf(singular, name)); } diff --git a/packages/metadata-protocol/src/protocol-meta-item-reads.ts b/packages/metadata-protocol/src/protocol-meta-item-reads.ts index ac8a8b5c414..57846980e37 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-reads.ts @@ -72,7 +72,7 @@ import { } from './protocol-package-bindings.js'; import type { ServedOverrideRow } from './served-override.js'; import { withServedRowChangedAt } from './served-row-changed-at.js'; -import { canonicalIsoInstant } from './sys-metadata-repository.js'; +import { canonicalIsoInstant, holdsEnvironmentOwnAction } from './sys-metadata-repository.js'; /** * [ADR-0150 D3, #32244] The package-scoped refusal `error` carries — the @@ -1033,18 +1033,26 @@ export async function readMetaItem(host: Pick(); const order: string[] = []; // first-seen slot order → stable output + // [#33904, ADR-0150 D4] An `action` is keyed `(package, objectName, + // name)`: its slot is `(name, object)` (object-less is its own key), so + // the environment's own action on an object no package's action binds is + // listed beside the package's, as the read naming no package and the + // action route serve it, and never stands in for the package's slot on + // another object. Slotted by name alone, the list dropped it. + const actionObjectKey = (item: unknown): string => { + const object = canonicalMetaUrlType(type) === 'action' ? boundObjectOf(item) : undefined; + return object === undefined ? '' : `\u0001${object}`; + }; const slotOf = (item: unknown, name: unknown): string => { const disc = itemDiscriminator(type, item); - return disc === undefined ? String(name) : `${String(name)}\u0000${disc}`; + return (disc === undefined ? String(name) : `${String(name)}\u0000${disc}`) + actionObjectKey(item); }; // [#32606] The name each slot is of, so a slot's name grain reads its // sibling members' slots too. diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index ba70ea5ed62..f4849f0bfa2 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -1969,6 +1969,18 @@ export class ProtocolRegistryHydrationFacet { registry.removePackageOverlaySlots(singular, name, memberKey, (id: string) => !bindings.has(id)); } if (remainingRows.length > 0) { + // [#33904, ADR-0150 D4] A removed PACKAGE-LESS row (the + // environment's own action, which the delete naming no package + // removes) beside rows that are all bound to packages: those + // rows take their packages' overlay slots, so the bare slot's + // entry is the removed row's, and it is retired here. Kept, it + // went on standing as the environment's item, and the read + // naming no package refused naming it beside the package. + if (packageId === null && !slotRetired && remainingRows.every((row) => boundPackageOf(row.package_id) !== undefined) + && typeof registry.removeOverlayEntry === 'function') { + registry.removeOverlayEntry(singular, name, memberKey); + if (type !== singular) registry.removeOverlayEntry(type, name, memberKey); + } if (canonical === 'object' && !host.isArtifactBacked(canonical, name)) { const bindings = new Set(remainingRows.map((row) => boundPackageOf(row.package_id) ?? 'sys_metadata')); const owner = typeof registry.getObjectOwner === 'function' ? registry.getObjectOwner(name) : undefined; diff --git a/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts b/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts index 1b0950729c5..33f1a0a9413 100644 --- a/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts +++ b/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts @@ -707,7 +707,11 @@ describe('[ADR-0150 D4] a package-less save of an ACTION on an object the holder }); }); - it('FROM (the read half): the version the read naming no package serves is P\'s item\'s, so a save on `task` carrying it as the parent is refused as a version conflict, before and after the environment\'s row exists', async () => { + // [#33904, ruling 6942962369] The read half: once the environment's own + // row on `task` exists, the read naming no package serves it and its + // version (FROM: P's item and P's version, so the save carrying it was + // refused as a version conflict after the environment's row existed too). + it('[#33904] the version the read naming no package serves is P\'s item\'s until the environment\'s row exists (a save on `task` carrying it is refused), then the environment\'s, which a save on `task` carries as its parent', async () => { const { protocol, rows } = makeProtocol(); await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'p', 'invoice'), packageId: WRITABLE }); const atPackage = await protocol.getMetaItem({ type: 'action', name: NAME, packageId: WRITABLE }); @@ -723,12 +727,51 @@ describe('[ADR-0150 D4] a package-less save of an ACTION on an object the holder await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'env', 'task') }); const after = await protocol.getMetaItem({ type: 'action', name: NAME }); - expect(after.version).toBe(atPackage.version); - const again = resolveThrownHttpError(await refusalOf(() => protocol.saveMetaItem({ - type: 'action', name: NAME, item: action(NAME, 'env2', 'task'), parentVersion: after.version, - }))); - expect([again.status, again.code]).toEqual([409, 'METADATA_CONFLICT']); - expect(stored(rows('action', NAME))).toEqual([[WRITABLE, 'invoice', 'p'], [null, 'task', 'env']]); + expect([(after.item as any)?.objectName, (after.item as any)?.label]).toEqual(['task', 'env']); + expect(after.version).toEqual(expect.any(String)); + expect(after.version).not.toBe(atPackage.version); + await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'env2', 'task'), parentVersion: after.version }); + expect(stored(rows('action', NAME))).toEqual([[WRITABLE, 'invoice', 'p'], [null, 'task', 'env2']]); + expect(await protocol.getMetaItem({ type: 'action', name: NAME, packageId: WRITABLE })).toMatchObject({ version: atPackage.version }); + }); + + // [#33904, ADR-0150 D4, ruling 6942962369] The environment's own action on + // `task` beside P's on `invoice` is a second item of the name, in both save + // orders: the list names both, the layered read's `effective` and + // `/published` serve the environment's as the plain read does, and the + // delete naming no package removes the environment's row, never P's. + for (const order of ['P first', 'environment first'] as const) { + it(`[#33904] ${order}: the list names both items, the layered and published reads serve the environment's, and the delete naming no package removes the environment's row`, async () => { + const { protocol, rows } = makeProtocol(); + const saveP = () => protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'p', 'invoice'), packageId: WRITABLE }); + const saveEnv = () => protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'env', 'task') }); + if (order === 'P first') { await saveP(); await saveEnv(); } else { await saveEnv(); await saveP(); } + expect(stored(rows('action', NAME))).toEqual([[WRITABLE, 'invoice', 'p'], [null, 'task', 'env']]); + const face = (item: any) => [item?.objectName ?? null, item?.label ?? null]; + + const listed = ((await protocol.getMetaItems({ type: 'action' })).items as any[]) + .filter((item) => item?.name === NAME).map(face) + .sort((a, b) => String(a[0]).localeCompare(String(b[0]))); + // FROM: `[['invoice', 'p']]`, the environment's item left out. + expect(listed).toEqual([['invoice', 'p'], ['task', 'env']]); + // FROM: P's item. + expect(face((await protocol.getMetaItem({ type: 'action', name: NAME })).item)).toEqual(['task', 'env']); + expect(face((await protocol.getMetaItemLayered({ type: 'action', name: NAME })).effective)).toEqual(['task', 'env']); + expect(face((await protocol.getMetaItem({ type: 'action', name: NAME, packageId: WRITABLE })).item)).toEqual(['invoice', 'p']); + + const deleted = await protocol.deleteMetaItem({ type: 'action', name: NAME }); + // FROM: `Deleted action '…' (package=P)`, P's row removed and the environment's left. + expect(deleted.message).not.toContain(`(package=${WRITABLE})`); + expect(stored(rows('action', NAME))).toEqual([[WRITABLE, 'invoice', 'p']]); + }); + } + + it('[#33904] CONTROL: with no environment row on another object, the delete naming no package removes P\'s row, as the generic re-addressing does', async () => { + const { protocol, rows } = makeProtocol(); + await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'p', 'invoice'), packageId: WRITABLE }); + const deleted = await protocol.deleteMetaItem({ type: 'action', name: NAME }); + expect(deleted.message).toContain(`package=${WRITABLE}`); + expect(rows('action', NAME)).toEqual([]); }); // The at-object judgment declines here (no disabled holder on `task`), so diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index 23e455d866e..79f0302b0a8 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -7808,6 +7808,8 @@ export class ObjectStackProtocolImplementation implements // [#25467 cut 5] The body moved to `protocol-lock-version-gates.ts` (see `LockVersionGateHost`). const host: ThisParameterType = { packagelessAddress: (...a) => this.packagelessAddress(...a), + readItemActiveRows: (...a) => this.readItemActiveRows(...a), + rethrowUnlessMetadataStoreUnprovisioned: (...a) => this.rethrowUnlessMetadataStoreUnprovisioned(...a), shippedArtifactsOf: (...a) => this.shippedArtifactsOf(...a), }; return packagelessReadAddress.call(host, type, name, member); diff --git a/packages/metadata-protocol/src/sys-metadata-repository.ts b/packages/metadata-protocol/src/sys-metadata-repository.ts index 7501eed67ee..a68b1795b3b 100644 --- a/packages/metadata-protocol/src/sys-metadata-repository.ts +++ b/packages/metadata-protocol/src/sys-metadata-repository.ts @@ -772,6 +772,35 @@ export function actionHeldOnlyOnOtherObjects( return held.length > 0 && actionRowsBindingObjectOf(item, held).length === 0; } +/** + * [#33904, ADR-0150 D4, ruling 6942962369] Whether `activeRows` (an action's + * active rows, every binding) hold the ENVIRONMENT'S OWN item of the name: a + * package-unbound row bound to an object no package's row binds + * ({@link actionHeldOnlyOnOtherObjects}), which is no customization of a + * package's item but an item of its own at D4's key `(package, objectName, + * name)`. A door that names neither a package nor an object (the by-name + * read, `?package=_env`, the delete) addresses that item first: the + * environment's own item answers first, whatever packages hold the name. A + * package-unbound row that does not parse is never read as one. `false` for + * every other type. + */ +export function holdsEnvironmentOwnAction( + type: string, + activeRows: ReadonlyArray<{ package_id?: unknown; metadata?: unknown }>, +): boolean { + if ((PLURAL_TO_SINGULAR[type] ?? type) !== 'action') return false; + return activeRows.some((row) => { + if (isPackageBoundRow(row)) return false; + let body: unknown; + try { + body = typeof row.metadata === 'string' ? JSON.parse(row.metadata) : row.metadata; + } catch { + return false; + } + return body !== null && typeof body === 'object' && actionHeldOnlyOnOtherObjects(type, body, activeRows); + }); +} + /** * [ADR-0150 D4] The rows of `rows` that bind the object `item` binds * ({@link boundObjectOf}; object-less is its own key): the rows of the action diff --git a/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts b/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts index 39124ff663a..46250c8b202 100644 --- a/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts +++ b/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts @@ -21,6 +21,11 @@ // the package) is pinned here only as "the list answers what the by-name // read answers"; the save door's choice is not this file's subject. // +// [#33904] Since #34059 the two saves keep two items (P's on its object, the +// environment's own on the other), and the doors naming no package answer +// the environment's first (ruling 6942962369): the list names both, as the +// action route serves both. +// // The file is ISOLATED: it writes `/meta` and creates a package. import { describe, it, expect, beforeAll, afterAll } from 'vitest'; @@ -70,17 +75,25 @@ describe('[#33904] the action list agrees with the by-name read beside a package }; for (const order of ['the package\'s save first', 'the environment\'s save first'] as const) { - it(`${order}: the list, \`?names=\` and \`?package=\` each answer exactly what the by-name read answers`, async () => { + it(`${order}: the list and \`?names=\` name both items, the by-name read serves the environment's, and \`?package=\` serves P's`, async () => { const name = order === 'the package\'s save first' ? 'qa_list_agree_pf' : 'qa_list_agree_ef'; const savePackage = () => put(`/meta/action/${name}?package=${PKG}`, action(name, 'package on task', 'showcase_task')); const saveEnvironment = () => put(`/meta/action/${name}`, action(name, 'environment on product', 'showcase_product')); if (order === 'the package\'s save first') { await savePackage(); await saveEnvironment(); } else { await saveEnvironment(); await savePackage(); } + // [#33904, ADR-0150 D4] Two items, keyed by object: the bare read + // serves the environment's own item (ruling 6942962369), the list names + // both (FROM: P's item only, while the action route served the + // environment's), and the list scoped to P names P's. const bare = await byName(`/meta/action/${name}`); - expect(await listed('/meta/action', name)).toEqual([bare]); - expect(await listed(`/meta/action?names=${name}`, name)).toEqual([bare]); + expect(bare).toEqual(['showcase_product', 'environment on product', null]); const atPackage = await byName(`/meta/action/${name}?package=${PKG}`); + expect(atPackage).toEqual(['showcase_task', 'package on task', PKG]); + const both = [atPackage, bare].sort((a, b) => String(a[0]).localeCompare(String(b[0]))); + const sorted = (items: unknown[][]) => [...items].sort((a, b) => String(a[0]).localeCompare(String(b[0]))); + expect(sorted(await listed('/meta/action', name))).toEqual(both); + expect(sorted(await listed(`/meta/action?names=${name}`, name))).toEqual(both); expect(await listed(`/meta/action?package=${PKG}`, name)).toEqual([atPackage]); }, 120_000); } diff --git a/packages/qa/dogfood/test/action-save-packageless-other-object.dogfood.test.ts b/packages/qa/dogfood/test/action-save-packageless-other-object.dogfood.test.ts index 2b550e28c0f..42d79cb3857 100644 --- a/packages/qa/dogfood/test/action-save-packageless-other-object.dogfood.test.ts +++ b/packages/qa/dogfood/test/action-save-packageless-other-object.dogfood.test.ts @@ -26,6 +26,10 @@ // representation hash, which no save resolves as a parent), so no leg here // reads that token. // +// [#33904] The read naming no package and the delete naming no package +// address the environment's own item first (FROM: P's item, and P's row +// removed), pinned in the first case below. +// // The file is ISOLATED: it writes `/meta` and creates a package. import { describe, it, expect, beforeAll, afterAll } from 'vitest'; @@ -96,24 +100,22 @@ describe('[ADR-0150 D4] a package-less action save on an object the package does // FROM: 404, the environment held no item of the name. expect(await routeTarget(`/actions/_env/showcase_task/${name}`)).toEqual([400, 'env']); - // FROM pins: what does NOT move yet (#33904, the read, list and delete - // half). Each turns when that card keys its door by object. - // FROM: the by-name read naming no package serves P's item, never the - // environment's row on `showcase_task`. - expect(await read(`/meta/action/${name}`)).toEqual(['showcase_invoice', 'pkg', PKG]); - // FROM: a package-less DELETE of the name removes P's row on - // `showcase_invoice`, and leaves the environment's row. + // [#33904, ruling 6942962369] The read, list and delete half: the doors + // naming no package answer the environment's own item first, keyed by + // object as the save and the route are. + // FROM: the by-name read naming no package served P's item. + expect(await read(`/meta/action/${name}`)).toEqual(['showcase_task', 'env', null]); + // FROM: a package-less DELETE of the name removed P's row on + // `showcase_invoice`, and left the environment's row. const deleted = await stack.apiAs(admin, 'DELETE', `/meta/action/${name}`); const deletedText = await deleted.text(); expect(deleted.status, deletedText).toBe(200); - expect(deletedText).toContain(`package=${PKG}`); - // …so P no longer holds the name: the read naming P is refused 409, the - // name held by the environment only. - const afterDelete = await stack.apiAs(admin, 'GET', `/meta/action/${name}?package=${PKG}`); - const afterText = await afterDelete.text(); - expect(afterDelete.status, afterText).toBe(409); - expect(afterText).toContain('RESOURCE_CONFLICT'); - expect(await routeTarget(`/actions/_env/showcase_task/${name}`)).toEqual([400, 'env']); + expect(deletedText).not.toContain(`(package=${PKG})`); + // …so P still holds its item, which the bare read now serves, and the + // environment's is gone. + expect(await read(`/meta/action/${name}?package=${PKG}`)).toEqual(['showcase_invoice', 'pkg', PKG]); + expect(await read(`/meta/action/${name}`)).toEqual(['showcase_invoice', 'pkg', PKG]); + expect(await routeTarget(`/actions/showcase_invoice/${name}`)).toEqual([400, 'pkg']); }, 120_000); it('the DRAFT save on `showcase_task` and its per-item publish write the environment\'s item; P\'s item on `showcase_invoice` is untouched', async () => { diff --git a/packages/runtime/src/domains/meta-environment-action-other-object-33904.test.ts b/packages/runtime/src/domains/meta-environment-action-other-object-33904.test.ts new file mode 100644 index 00000000000..583396f0794 --- /dev/null +++ b/packages/runtime/src/domains/meta-environment-action-other-object-33904.test.ts @@ -0,0 +1,187 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [#33904, ADR-0150 D4, ruling 6942962369] A writable package P holds the +// action `qa_x` on `account`; the environment saved its own package-less +// `qa_x` on `contact`, an object no package's action of the name binds. D4 +// keys an action `(package, objectName, name)`, so these are two items, and +// the environment's own item answers first on every door naming no package. +// Driven on a real ObjectQL engine and `sys_metadata` store (SQLite file), +// through the runtime dispatcher and the `RestServer` routes, in both save +// orders and after a restart. +// +// FROM (main, measured on this harness): the plain read, `/layers` +// `effective` and `/published` served P's item on `account`; the list named +// P's item only; the delete naming no package removed P's row and left the +// environment's. + +import '@objectstack/metadata'; +import { afterEach, describe, expect, it } from 'vitest'; +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { ObjectQL } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; +import { SysMetadata, SysMetadataHistoryObject, SysMetadataAuditObject } from '@objectstack/platform-objects/metadata'; +import { RestServer } from '@objectstack/rest'; +import { HttpDispatcher } from '../http-dispatcher.js'; + +const P = 'com.qa.envaction'; +const NAME = 'qa_x'; +const AUTHOR = { userId: 'u_admin', isSystem: false, systemPermissions: ['manage_metadata'] }; + +const live: ObjectQL[] = []; +const roots: string[] = []; +afterEach(async () => { + while (live.length) { + try { await live.pop()?.destroy(); } catch { /* noop */ } + } + while (roots.length) rmSync(roots.pop()!, { recursive: true, force: true }); +}); + +function makeRes() { + const res: any = { statusCode: 200, body: undefined }; + res.status = (code: number) => { res.statusCode = code; return res; }; + res.json = (body: unknown) => { res.body = body; return res; }; + res.send = () => res; + res.end = () => res; + res.header = () => res; + res.setHeader = () => {}; + return res; +} + +async function boot(file: string) { + const engine = new ObjectQL(); + live.push(engine); + engine.registerDriver(new SqlDriver({ client: 'better-sqlite3', connection: { filename: file }, useNullAsDefault: true }), true); + await engine.init(); + engine.registry.registerObject(SysMetadata as any, 'objectstack-test'); + engine.registry.registerObject(SysMetadataHistoryObject as any, 'objectstack-test'); + engine.registry.registerObject(SysMetadataAuditObject as any, 'objectstack-test'); + // A writable base: installed, no read-only manifest scope, no code item of the name. + engine.registry.installPackage({ id: P, name: P, namespace: 'envaction', version: '1.0.0', type: 'app' } as any, 'code'); + for (const object of ['account', 'contact']) { + engine.registry.registerObject({ name: object, label: object, fields: { name: { type: 'text', label: 'Name' } } } as any, P); + } + await engine.syncSchemas(); + const protocol = new ObjectStackProtocolImplementation(engine as any); + const services: Record = { protocol, objectql: engine }; + const get = (name: string) => services[name] ?? null; + const kernel: any = { context: { getService: get }, getService: get, getServiceAsync: async (name: string) => get(name) }; + const dispatcher = new HttpDispatcher(kernel); + (dispatcher as any).timedResolveExecutionContext = async () => ({ ...AUTHOR }); + const call = async (method: string, path: string, body?: unknown, query: Record = {}) => { + const res = await dispatcher.dispatch(method, path, body, query, { request: { headers: {} } } as any); + return { status: res.response?.status as number | undefined, body: res.response?.body }; + }; + const noop = () => {}; + const rest: any = new RestServer({ get: noop, post: noop, put: noop, delete: noop, patch: noop, use: noop, listen: async () => {}, close: async () => {} } as any, protocol as any, { api: { requireAuth: false } } as any); + rest.resolveExecCtx = async () => ({ ...AUTHOR }); + rest.registerRoutes(); + const restCall = async (method: 'GET' | 'DELETE', path: string, params: Record) => { + const route = rest.getRoutes().find((r: any) => r.method === method && r.path === path); + const res = makeRes(); + await route.handler({ method, path: '/api/v1/meta/action', params, headers: {}, query: {}, body: undefined }, res); + return { status: res.statusCode as number, body: res.body }; + }; + return { engine, protocol, call, restCall }; +} + +const action = (label: string, objectName: string) => ({ + name: NAME, label, objectName, type: 'url', target: `https://example.invalid/${label}`, locations: ['record_page'], component: 'action:menu', +}); +const faceOf = (item: any) => [item?.objectName ?? null, item?.label ?? null, item?._packageId ?? null]; +const itemOf = (body: any) => body?.data?.item ?? body?.item ?? body?.data; + +async function stored(engine: ObjectQL) { + const rows = (await engine.find('sys_metadata', { where: { type: 'action', name: NAME }, context: { isSystem: true } })) as any[]; + return rows.map((row) => [row.package_id ?? null, JSON.parse(row.metadata).objectName]).sort((a, b) => String(a[0]).localeCompare(String(b[0]))); +} + +type Booted = Awaited>; +async function doors({ call, restCall }: Booted) { + const read = async (query: Record = {}) => { + const a = await call('GET', `/meta/action/${NAME}`, undefined, query); + expect(a.status, JSON.stringify(a.body).slice(0, 300)).toBe(200); + return faceOf(itemOf(a.body)); + }; + const layers = await call('GET', `/meta/action/${NAME}/layers`); + const published = await call('GET', `/meta/action/${NAME}/published`); + const env = await restCall('GET', '/api/v1/meta/:type/:ns/:name', { type: 'action', ns: '_env', name: NAME }); + const listed = await call('GET', '/meta/action'); + return { + bare: await read(), + restBare: faceOf(itemOf((await restCall('GET', '/api/v1/meta/:type/:name', { type: 'action', name: NAME })).body)), + atPackage: await read({ package: P }), + environment: [env.status, ...faceOf(itemOf(env.body))], + layersEffective: [layers.status, ...faceOf((layers.body?.data ?? layers.body)?.effective)].slice(0, 3), + published: [published.status, ...faceOf(itemOf(published.body))].slice(0, 3), + list: ((listed.body?.data?.items ?? listed.body?.items ?? []) as any[]) + .filter((item) => item?.name === NAME).map(faceOf).sort((a, b) => String(a[0]).localeCompare(String(b[0]))), + }; +} + +const ENV = ['contact', 'env', null]; +const PKG = ['account', 'pkg', P]; + +describe('[#33904] the environment\'s own action on an object no package\'s action of the name binds', () => { + for (const order of ['P\'s save first', 'the environment\'s save first'] as const) { + it(`${order}: every door naming no package answers the environment's item, the list names both, and after a restart too`, async () => { + const root = mkdtempSync(join(tmpdir(), 'os-33904-')); + roots.push(root); + const file = join(root, 'db.sqlite'); + let booted = await boot(file); + const saveP = () => booted.call('PUT', `/meta/action/${NAME}`, action('pkg', 'account'), { package: P }); + const saveEnv = () => booted.call('PUT', `/meta/action/${NAME}`, action('env', 'contact')); + for (const save of order === 'P\'s save first' ? [saveP, saveEnv] : [saveEnv, saveP]) { + expect((await save()).status).toBe(200); + } + expect(await stored(booted.engine)).toEqual([[P, 'account'], [null, 'contact']]); + + const expected = { + bare: ENV, + restBare: ENV, + atPackage: PKG, + environment: [200, ...ENV], + layersEffective: [200, 'contact', 'env'], + published: [200, 'contact', 'env'], + list: [PKG, ENV], + }; + expect(await doors(booted)).toEqual(expected); + + await booted.engine.destroy(); + booted = await boot(file); + await (booted.protocol as any).loadMetaFromDb(); + expect(await doors(booted)).toEqual(expected); + }, 60_000); + } + + it('the delete naming no package removes the environment\'s row; P\'s item is then the one the bare read serves', async () => { + const root = mkdtempSync(join(tmpdir(), 'os-33904-')); + roots.push(root); + const booted = await boot(join(root, 'db.sqlite')); + expect((await booted.call('PUT', `/meta/action/${NAME}`, action('pkg', 'account'), { package: P })).status).toBe(200); + expect((await booted.call('PUT', `/meta/action/${NAME}`, action('env', 'contact'))).status).toBe(200); + + const deleted = await booted.restCall('DELETE', '/api/v1/meta/:type/:name', { type: 'action', name: NAME }); + expect(deleted.status).toBe(200); + expect(String(deleted.body?.message ?? deleted.body?.data?.message)).not.toContain(`(package=${P})`); + expect(await stored(booted.engine)).toEqual([[P, 'account']]); + // The registry's bare slot held the environment's entry: retired with its row. + const read = await booted.call('GET', `/meta/action/${NAME}`); + expect([read.status, ...faceOf(itemOf(read.body))]).toEqual([200, ...PKG]); + expect(faceOf(itemOf((await booted.call('GET', `/meta/action/${NAME}`, undefined, { package: P })).body))).toEqual(PKG); + }, 60_000); + + it('CONTROL: with no environment row, the bare doors answer P\'s item and the delete naming no package removes P\'s row', async () => { + const root = mkdtempSync(join(tmpdir(), 'os-33904-')); + roots.push(root); + const booted = await boot(join(root, 'db.sqlite')); + expect((await booted.call('PUT', `/meta/action/${NAME}`, action('pkg', 'account'), { package: P })).status).toBe(200); + const read = await booted.call('GET', `/meta/action/${NAME}`); + expect(faceOf(itemOf(read.body))).toEqual(PKG); + const deleted = await booted.restCall('DELETE', '/api/v1/meta/:type/:name', { type: 'action', name: NAME }); + expect(String(deleted.body?.message ?? deleted.body?.data?.message)).toContain(`package=${P}`); + expect(await stored(booted.engine)).toEqual([]); + }, 60_000); +}); From fa541404f8f7d592d17e9b4dec90c3474c378418 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 19:04:17 +0000 Subject: [PATCH 05/11] fix(metadata-protocol): a package-less action row is withheld or served by the holders at its own (object, name) key #34258, ADR-0150 D3/D4. The read naming no package judged a package-less action row against the name's holders, not its key's: - the envelope lookup with an owner key answered the FIRST registered holder's artifact when it was bound to the key, so with a disabled and an enabled holder both on the row's object the row wore the disabled one's envelope when it registered first, and the read withheld it (404) where it serves the enabled holder's customization with the disabled holder absent (the card's CONTROL, measured on main); - with that fixed, the face's fallback for two or more holders at the key (disabledOnlyHolderOf) judged the name, so an enabled package holding the name on another object kept a key whose every holder is disabled served (the card's acceptance 1). Now the lookup lends the ONE enabled holder's envelope when two or more holders are bound to the key (a disabled package holds no name); with two enabled, or none, it answers as before. The face judges the key's holders (actionKeyHoldersOf). Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../src/protocol-artifact-lookup.ts | 29 ++++++++++++----- .../src/protocol-meta-item-face.ts | 27 ++++++++++++++++ .../src/meta-qualified-item-route.test.ts | 31 +++++++++++++++++++ 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-artifact-lookup.ts b/packages/metadata-protocol/src/protocol-artifact-lookup.ts index 288b99c4f89..fcfbaa9cfc0 100644 --- a/packages/metadata-protocol/src/protocol-artifact-lookup.ts +++ b/packages/metadata-protocol/src/protocol-artifact-lookup.ts @@ -84,22 +84,37 @@ export function lookupArtifactItem( // no envelope. A package-less item's holder is the ONE package whose own // artifact is bound to the item's owner key; none, or two, and no // artifact answers (an ambiguity is not guessed). - if (artifact !== undefined && boundObjectOf(artifact) === owner.object) return artifact; - if (currentPackageId) return undefined; + if (currentPackageId) return artifact !== undefined && boundObjectOf(artifact) === owner.object ? artifact : undefined; const registry = (this.engine as any)?.registry; - if (typeof registry?.packageScopedHoldersOf !== 'function') return undefined; + // [#34258] With no package named, the by-name answer is the FIRST + // registered holder's artifact, so it is that answer only when no other + // package's artifact is bound to the key (below): two holders at the key, + // one disabled, wore the disabled one's envelope when it registered + // first, and the read withheld the environment's row with it. + const boundToKey = artifact !== undefined && boundObjectOf(artifact) === owner.object ? artifact : undefined; + if (typeof registry?.packageScopedHoldersOf !== 'function') return boundToKey; let holders: unknown; try { holders = registry.packageScopedHoldersOf(singular, name, null, { includeDisabledPackages: true }); } catch { - return undefined; + return boundToKey; } - const owners: unknown[] = []; + const owners: Array<{ _packageId?: unknown }> = []; for (const packageId of new Set(Array.isArray(holders) ? holders : [])) { const own = lookupArtifactItemByName.call(this, type, name, packageId, member) as { _packageId?: unknown } | undefined; - if (own?._packageId === packageId && boundObjectOf(own) === owner.object) owners.push(own); + if (own !== undefined && own._packageId === packageId && boundObjectOf(own) === owner.object) owners.push(own); } - return owners.length === 1 ? owners[0] : undefined; + if (owners.length === 1) return owners[0]; + // [#34258, #32354, ADR-0150 D3] …and of two or more, a disabled package + // holds no name: the ONE enabled package whose own artifact is bound to + // the key lends the envelope, as with the disabled holder absent. Two + // enabled, or none, and the answer is the one before #34258: the first + // holder's artifact when it is bound to the key (the bare read refuses two + // enabled holders before any envelope), else none. + const enabled = typeof registry.isPackageDisabled === 'function' + ? owners.filter((own) => registry.isPackageDisabled(own._packageId) !== true) + : []; + return enabled.length === 1 ? enabled[0] : boundToKey; } /** The artifact {@link lookupArtifactItem} answers by name alone, as it did before #33456. */ diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index 206d8ae1935..68d314d62d9 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -47,6 +47,7 @@ import { packageDependencyClosure, pairsOf, type PackageClosureRegistry } from ' import { disabledExactAddressHolder } from './protocol-exact-qualifier.js'; import type { PrereadActiveRows } from './protocol-meta-item-reads.js'; import { PLURAL_TO_SINGULAR } from '@objectstack/spec/shared'; +import { boundObjectOf } from '@objectstack/metadata/stored-item-package'; import { RELATED_LISTS_ARRANGEMENT_DECORATION, type RelatedListsArrangement } from '@objectstack/spec/data'; import { overlayMemberValue, overlayMemberWhere } from './migrations/overlay-index.js'; import { isServedOverrideRowOf } from './served-override.js'; @@ -151,9 +152,35 @@ function packagelessRowWithheldHolder(registry: any, type: string, name: string, const holder: unknown = registry.overlayRowBinding(type, name, item, { includeDisabledPackages: true }); if (holder === null) return undefined; if (typeof holder === 'string') return registry.isPackageDisabled(holder) === true ? holder : undefined; + // [#34258, ADR-0150 D4] An action's key is `(object, name)`: two or more + // holders at the row's key are judged at that key, never at the name's, + // so a key whose every holder is disabled withholds the row although an + // enabled package holds the name on another object, and an enabled + // holder at the key keeps it served. + if (type === 'action') { + const atKey = actionKeyHoldersOf(registry, name, item); + return atKey.length > 0 && atKey.every((id) => registry.isPackageDisabled(id) === true) ? atKey[0] : undefined; + } return disabledOnlyHolderOf(registry, type, name); } +/** + * [#34258, ADR-0150 D4] The packages holding the action `name` at the key of + * `item` (its object, object-less its own key): every holder of the name, a + * disabled one included, whose own artifact is bound to `item`'s object, in + * the registry's holder order. The grain the registry's owner rule + * (`overlayRowBinding`) binds a package-less action row at. + */ +function actionKeyHoldersOf(registry: any, name: string, item: unknown): string[] { + if (typeof registry?.packageScopedHoldersOf !== 'function' || typeof registry?.getArtifactItem !== 'function') return []; + const object = boundObjectOf(item); + const every: readonly string[] = registry.packageScopedHoldersOf('action', name, null, { includeDisabledPackages: true }) ?? []; + return every.filter((id) => { + const own = registry.getArtifactItem('action', name, id) as { _packageId?: unknown } | undefined; + return own?._packageId === id && boundObjectOf(own) === object; + }); +} + /** * [#33401, review#2 S5] Whether an enabled package holds `(type, name)` * through a stored active row the reads serve: a row bound to an enabled diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index 2dfa78a1fc7..1e8a8e6787b 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -1263,6 +1263,37 @@ describe('#33456 — the bare action read grafts a holder\'s envelope only at it } }); + /** + * [#34258, ADR-0150 D3/D4] The package-less action row is judged at its + * own key `(object, name)`: a key whose every holder is disabled withholds + * it although an enabled package holds the name on another object, and an + * enabled holder at the key keeps it served under that holder's envelope, + * whichever holder registered first. + */ + describe('[#34258] the withhold of a package-less action row is judged at its key', () => { + const withC = () => registry.installPackage({ id: C, name: C, version: '1.0.0', type: 'app', namespace: 'gamma' } as never, 'code'); + it('A and B disabled on `account`, C enabled on `contact`, the environment\'s row on `account`: withheld (404), in both orders', async () => { + for (const steps of bothOrders([() => shipAction(A, 'account'), () => shipAction(B, 'account'), () => shipAction(C, 'contact'), () => environmentAction('account')])) { + compose(); + withC(); + steps.forEach((step) => step()); + registry.disablePackage(A); + registry.disablePackage(B); + expect((await envelopeOf())[0]).toBe(404); + } + }); + + it('CONTROL: A disabled and C enabled both on `account`, the environment\'s row on `account`: served as C\'s customization (BASE: withheld 404 under A\'s envelope when A registered first)', async () => { + for (const steps of bothOrders([() => shipAction(A, 'account'), () => shipAction(C, 'account'), () => environmentAction('account')])) { + compose(); + withC(); + steps.forEach((step) => step()); + registry.disablePackage(A); + expect(await envelopeOf()).toEqual([200, 'env', 'account', C, true]); + } + }); + }); + describe('CONTROLs (unchanged)', () => { it('one package on one object with the environment\'s item on that object: its customization, under the package\'s envelope', async () => { shipAction(A, 'account'); From 10c011f9ba062e3bf1577e9fa43463c94f2fb289 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 19:16:08 +0000 Subject: [PATCH 06/11] chore(spec): the ADR-0087 ledger names the four same-name write, restart and action moves, with their changeset Four semantic entries under step 19: bare-write-beside-disabled-row-refused-naming-shippers (#34346), hydrated-doc-row-wears-no-holder-envelope (#34417), environment-action-on-another-object-answers-first (#33904) and package-less-action-row-judged-at-its-key (#34258). The changeset declares the narrowing and its FROM and TO. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../34452-same-name-writes-and-hydration.md | 22 +++++++++++ ...de-disabled-row-refused-naming-shippers.ts | 37 ++++++++++++++++++ ...-action-on-another-object-answers-first.ts | 39 +++++++++++++++++++ ...drated-doc-row-wears-no-holder-envelope.ts | 35 +++++++++++++++++ ...ckage-less-action-row-judged-at-its-key.ts | 34 ++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 .changeset/34452-same-name-writes-and-hydration.md create mode 100644 packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts create mode 100644 packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts create mode 100644 packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts create mode 100644 packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts diff --git a/.changeset/34452-same-name-writes-and-hydration.md b/.changeset/34452-same-name-writes-and-hydration.md new file mode 100644 index 00000000000..e57df11b7b9 --- /dev/null +++ b/.changeset/34452-same-name-writes-and-hydration.md @@ -0,0 +1,22 @@ +--- +'@objectstack/metadata-protocol': patch +'@objectstack/spec': patch +--- + +fix(metadata-protocol)!: the writes, the restart and the action doors that name no package give the answer the read names + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a caller that writes or reads a shared name without naming a package, shipped as `patch`: no key an author writes changes (`Metadata-protocol: none`). Four doors that name no package answered by save or registration order, or disagreed with the read of the same name; each now gives the read's answer. Naming the package (`?package=ID`, or `packageId` in process) writes or reads that package's item exactly as before. + +- **A bare write beside a disabled package's row** (#34346). Two enabled packages ship the name and its stored rows are bound to a disabled package and to one shipper. FROM the bare publish save answering 200 and writing that shipper's row, and the bare draft save and delete refusing naming that shipper and the disabled package, TO all three refusing `409 RESOURCE_CONFLICT` naming the two shippers, as the bare read does, never the disabled package, and writing or removing nothing. +- **A doc row hydrated after a restart beside two holders** (#34417, ruling 6942962369). FROM the row wearing the first registered holder's envelope, so `?package=FIRST` served the environment's row and every read naming no package refused 409, TO every read naming no package serving the environment's row and `?package=FIRST` serving that holder's own doc. +- **The environment's own action on another object** (#33904, ADR-0150 D4). A package holds an action name on one object and the environment stores its own package-less action of the name on another. FROM the plain read, `/layers` and `/published` naming no package serving the package's action, the merged list naming only it, and the bare delete removing the package's row, TO those reads serving the environment's action, the list naming both, and the bare delete removing the environment's row. +- **A package-less action row beside an enabled and a disabled holder on its object** (#34258). FROM the read naming no package answering 404 when the disabled holder registered first, TO 200 serving the row as the enabled holder's customization in both orders. A key whose every holder is disabled still answers 404. + +The registry's heal for a package-less overlay row whose every holder is disabled (#33127) now keeps it recorded with no holder, so enabling one holder rebuilds it under that holder's envelope; no door's answer moves. + +The fix for a caller that relied on the old answer: name the package it means. `os migrate meta --from 18` lists the four entries. diff --git a/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts b/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts new file mode 100644 index 00000000000..4a3454ce1b4 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts @@ -0,0 +1,37 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A narrowing of the bare publish save, not of any key: ADR-0150 D3/D5 +// (#34346) has the writes that name no package give the answer the bare read +// gives. Two enabled packages ship the name and its stored rows are bound to a +// disabled package and to one of the shippers: the bare read refuses naming +// the two shippers, while the bare publish save wrote the one enabled +// binding's row and the bare draft save and delete refused naming that +// binding and the disabled package. No key is added, removed or re-shaped and +// no stored row changes shape, so no tombstone and no D2 conversion. No +// relevance question: the move turns on which installed packages are +// disabled, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'bare-write-beside-disabled-row-refused-naming-shippers', + surface: + 'The save that names no package (PUT /api/v1/meta/TYPE/NAME, as a publish save and as a draft save, and the ' + + 'in-process save with no packageId) and the delete that names no package (DELETE /api/v1/meta/TYPE/NAME and the ' + + 'in-process delete with no packageId) of a name two or more enabled packages ship while its stored rows are ' + + 'bound to a disabled package and to one of the shippers', + replacement: + 'Name the package: PUT or DELETE /api/v1/meta/TYPE/NAME?package=PACKAGE (and the in-process save and delete with ' + + 'packageId) writes or removes that enabled package\'s row, as before. The write that names no package answers ' + + '409 RESOURCE_CONFLICT naming the enabled shippers, as the bare read does, and writes or removes nothing.', + reason: + 'A disabled package holds no name (ADR-0150 D3), and reads and writes give the same answer (ruling 6942962369). ' + + 'The bare read of such a name refused naming the enabled shippers, while the bare publish save wrote the one ' + + 'enabled binding\'s row as if it were the only holder, and the bare draft save and delete refused naming that ' + + 'binding and the disabled package, one shipper short and one disabled package over. There is no mechanical ' + + 'rewrite: which package\'s row a caller meant is a judgement about that caller.', + acceptanceCriteria: + 'For every such name while its disabled holder stays disabled: the bare publish save, the bare draft save and the ' + + 'bare delete each answer 409 RESOURCE_CONFLICT naming the enabled shippers and never the disabled package, and ' + + 'every stored row stays byte-unchanged; the same writes naming an enabled shipper save or remove its own row and ' + + 'leave the disabled package\'s row byte-unchanged.', +}; diff --git a/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts b/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts new file mode 100644 index 00000000000..2532ecfc868 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts @@ -0,0 +1,39 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A change of answer of the action doors that name no package, not of any +// key: ADR-0150 D4 keys an action by (package, objectName, name), and ruling +// 6942962369 (#33904) has the environment's own item answer first. With a +// package's action of a name on one object and the environment's own +// package-less action of the name on another, the two are items of their own, +// as the save door and the action route already key them; the doors that +// name neither a package nor an object took the package's. No key is added, +// removed or re-shaped and no stored row changes shape, so no tombstone and +// no D2 conversion. No relevance question: the move turns on which installed +// packages hold a name, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'environment-action-on-another-object-answers-first', + surface: + 'For an action name a package holds on one object while the environment stores its own package-less action of ' + + 'the name on another object (and no package\'s action of the name binds that object): ' + + 'GET /api/v1/meta/action/NAME, /layers and /published naming no package, the in-process item read with no ' + + 'packageId, the merged action list (GET /api/v1/meta/action and the in-process list), and ' + + 'DELETE /api/v1/meta/action/NAME naming no package', + replacement: + 'To read or delete the package\'s action, name the package: GET or DELETE /api/v1/meta/action/NAME?package=PACKAGE ' + + 'reads or removes that package\'s action, as before. The reads that name no package serve the environment\'s ' + + 'action (its version too), the list names both actions, and the delete that names no package removes the ' + + 'environment\'s row and leaves the package\'s.', + reason: + 'The environment\'s own item answers first, and reads and writes give the same answer (ruling 6942962369). The ' + + 'plain read, /layers effective and /published served the package\'s action, the list slotted actions by name and ' + + 'named the package\'s only, and the bare delete removed the package\'s row and left the environment\'s, while ' + + 'the save door and the action route keyed the two apart. There is no mechanical rewrite: which action a caller ' + + 'meant is a judgement about that caller.', + acceptanceCriteria: + 'For every such name, before and after a restart and in both save orders: every read that names no package ' + + 'answers the environment\'s action, ?package=PACKAGE answers the package\'s, the list names both, and the ' + + 'delete that names no package removes only the environment\'s row, after which the reads that name no package ' + + 'answer the package\'s action.', +}; diff --git a/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts b/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts new file mode 100644 index 00000000000..d654d75e77b --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts @@ -0,0 +1,35 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A change of answer of the doc reads after a restart, not of any key: ruling +// 6942962369 (#34417) has the environment's own package-less doc row answer +// first whatever number of packages hold the same name. Hydrated after the +// packages registered, the row wore the first registered holder's envelope, +// so the read naming that holder served the environment's row under the +// holder's name and the reads naming no package refused. No key is added, +// removed or re-shaped and no stored row changes shape, so no tombstone and +// no D2 conversion. No relevance question: the move turns on which installed +// packages hold a name, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'hydrated-doc-row-wears-no-holder-envelope', + surface: + 'After a restart (the stored rows hydrated after the packages registered), the read of a doc two or more enabled ' + + 'packages ship while the environment stores its own package-less doc row of the same name: ' + + 'GET /api/v1/meta/doc/NAME, /layers and /published naming no package, and the same reads with ' + + '?package=PACKAGE of the holder registered first', + replacement: + 'To read the environment\'s row, name no package: every read that names no package now serves it, on both ' + + 'transports and in both registration orders. To read a holder\'s doc, name the holder: ' + + 'GET /api/v1/meta/doc/NAME?package=PACKAGE (and /layers) serves that package\'s own doc, the first registered ' + + 'holder included.', + reason: + 'The environment\'s own item answers first whatever number of packages hold the same name (ruling 6942962369). ' + + 'After a restart the hydrated row took the envelope of the holder registered first, so the read naming that ' + + 'holder served the environment\'s row under its name, and every read naming no package refused 409 naming ' + + 'both holders, where the same stack before the restart served the row. There is no mechanical rewrite: which ' + + 'doc a caller meant is a judgement about that caller.', + acceptanceCriteria: + 'For every such name, after a restart and in both registration orders: every read that names no ' + + 'package answers the environment\'s row, and each read naming a holder answers that holder\'s own doc.', +}; diff --git a/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts b/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts new file mode 100644 index 00000000000..80a4d5714eb --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts @@ -0,0 +1,34 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A widening of the action read that names no package, not of any key: +// ADR-0150 D3/D4 (#34258) has a package-less action row judged by the holders +// at its own (object, name) key, and a disabled package holds no name. With +// an enabled and a disabled package both holding the name on the row's +// object, the row wore the envelope of whichever registered first, and the +// read withheld it (404) when that was the disabled one. No key is added, +// removed or re-shaped and no stored row changes shape, so no tombstone and +// no D2 conversion. No relevance question: the move turns on which installed +// packages are disabled, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'package-less-action-row-judged-at-its-key', + surface: + 'GET /api/v1/meta/action/NAME naming no package, and the in-process item read with no packageId, for an action ' + + 'name an enabled and a disabled package both hold on one object while the environment stores a package-less ' + + 'action row of the name on that object', + replacement: + 'None needed to read the customization: the read that names no package now serves the package-less row as the ' + + 'enabled holder\'s customization, in both registration orders. A key whose every holder is disabled still ' + + 'withholds its package-less row (404), whatever packages hold the name on other objects.', + reason: + 'A disabled package holds no name (ADR-0150 D3), and an action is keyed by (package, objectName, name) (D4). The ' + + 'row borrowed the envelope of the first registered holder bound to its object, so with the disabled holder ' + + 'registered first the read withheld the enabled holder\'s customization (404). Judged at the key, the one ' + + 'enabled holder lends its envelope. There is no mechanical rewrite: the 404 came from one registration order ' + + 'only, so no caller could rely on it.', + acceptanceCriteria: + 'For every such name while the disabled holder stays disabled, in both registration orders: the read that names ' + + 'no package answers 200 the package-less row under the enabled holder; with every holder at the row\'s key ' + + 'disabled it answers 404, an enabled holder on another object notwithstanding.', +}; From b0e3f1d16bbceaf242cf5b2edfca6fdfb57ff89e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 10:56:24 +0000 Subject: [PATCH 07/11] docs(metadata-protocol): #34258's every-holder-disabled key beside an enabled holder elsewhere is declared as the narrowing it is The changeset bullet and the ADR-0087 entry said that cell "still" answered 404; on main it answered 200, because the name's holders were judged. Each now gives its FROM 200 and TO 404, and the rest pin's title names its base. Two stale docblocks follow the code: the face's key-grain action judgment, and the HolderRegistry note above the two new refusals. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../34452-same-name-writes-and-hydration.md | 2 +- .../src/protocol-meta-item-face.ts | 4 ++- .../metadata-protocol/src/protocol-save.ts | 2 +- .../src/meta-qualified-item-route.test.ts | 2 +- ...ckage-less-action-row-judged-at-its-key.ts | 28 +++++++++++-------- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.changeset/34452-same-name-writes-and-hydration.md b/.changeset/34452-same-name-writes-and-hydration.md index e57df11b7b9..db962ffa46c 100644 --- a/.changeset/34452-same-name-writes-and-hydration.md +++ b/.changeset/34452-same-name-writes-and-hydration.md @@ -15,7 +15,7 @@ Metadata-protocol: none - **A bare write beside a disabled package's row** (#34346). Two enabled packages ship the name and its stored rows are bound to a disabled package and to one shipper. FROM the bare publish save answering 200 and writing that shipper's row, and the bare draft save and delete refusing naming that shipper and the disabled package, TO all three refusing `409 RESOURCE_CONFLICT` naming the two shippers, as the bare read does, never the disabled package, and writing or removing nothing. - **A doc row hydrated after a restart beside two holders** (#34417, ruling 6942962369). FROM the row wearing the first registered holder's envelope, so `?package=FIRST` served the environment's row and every read naming no package refused 409, TO every read naming no package serving the environment's row and `?package=FIRST` serving that holder's own doc. - **The environment's own action on another object** (#33904, ADR-0150 D4). A package holds an action name on one object and the environment stores its own package-less action of the name on another. FROM the plain read, `/layers` and `/published` naming no package serving the package's action, the merged list naming only it, and the bare delete removing the package's row, TO those reads serving the environment's action, the list naming both, and the bare delete removing the environment's row. -- **A package-less action row beside an enabled and a disabled holder on its object** (#34258). FROM the read naming no package answering 404 when the disabled holder registered first, TO 200 serving the row as the enabled holder's customization in both orders. A key whose every holder is disabled still answers 404. +- **A package-less action row beside an enabled and a disabled holder on its object** (#34258). FROM the read naming no package answering 404 when the disabled holder registered first, TO 200 serving the row as the enabled holder's customization in both orders. And where every holder on the row's object is disabled while an enabled package holds the name on another object: FROM 200 serving the row (the name, not the key, was judged, and it had an enabled holder) TO 404, as a key whose every holder is disabled answers with no other holder of the name. The registry's heal for a package-less overlay row whose every holder is disabled (#33127) now keeps it recorded with no holder, so enabling one holder rebuilds it under that holder's envelope; no door's answer moves. diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index 68d314d62d9..04de7334866 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -140,7 +140,9 @@ function isHoldersPairRow(engine: unknown, type: string, name: string, item: unk * (`overlayRowBinding`, every holder counted): `null` is the environment's * own item (D3 (a), no holder at its key, a same-name action on another * object included), served; one holder is withheld when it is disabled; two - * or more are judged as the name's holders are ({@link disabledOnlyHolderOf}). + * or more are judged as the name's holders are ({@link disabledOnlyHolderOf}), + * except for an `action`, whose two or more are judged at its key + * ({@link actionKeyHoldersOf}). * The row itself is untouched, so it is served again on re-enable. * `undefined` when the item is not such a row, or the registry cannot bind * one (optional-called: such a registry hides nothing more). diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 7d0168d49d0..6915fed20b3 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3702,7 +3702,6 @@ export function packagelessHolderRefusal( : disabledHoldersOnlyRefusal(verb, shownType, name); } -/** The registry reads {@link packagelessHolderRefusal} asks, each optional-called. */ /** * The package-scoped resolver's own refusal of a name two or more ENABLED * packages hold (`resolveItem` naming no package, the judgment the by-name @@ -3774,6 +3773,7 @@ export function disabledRowHoldersRefusal( return enabled.length > 1 ? packagelessAddressAmbiguityRefusal(verb, shownType, name, enabled) : undefined; } +/** The registry reads {@link packagelessHolderRefusal} and the two refusals above ask, each optional-called. */ interface HolderRegistry { readsByPackage?(type: string): boolean; getEnvironmentScopedItem?(type: string, name: string, member?: string): unknown; diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index 1e8a8e6787b..09e2efe176a 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -1272,7 +1272,7 @@ describe('#33456 — the bare action read grafts a holder\'s envelope only at it */ describe('[#34258] the withhold of a package-less action row is judged at its key', () => { const withC = () => registry.installPackage({ id: C, name: C, version: '1.0.0', type: 'app', namespace: 'gamma' } as never, 'code'); - it('A and B disabled on `account`, C enabled on `contact`, the environment\'s row on `account`: withheld (404), in both orders', async () => { + it('A and B disabled on `account`, C enabled on `contact`, the environment\'s row on `account`: withheld (404), in both orders (BASE: served 200, the name judged with C enabled)', async () => { for (const steps of bothOrders([() => shipAction(A, 'account'), () => shipAction(B, 'account'), () => shipAction(C, 'contact'), () => environmentAction('account')])) { compose(); withC(); diff --git a/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts b/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts index 80a4d5714eb..db67950c5eb 100644 --- a/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts +++ b/packages/spec/src/migrations/entries/semantic/19.package-less-action-row-judged-at-its-key.ts @@ -2,12 +2,15 @@ import type { SemanticMigration } from '../../types.js'; -// A widening of the action read that names no package, not of any key: -// ADR-0150 D3/D4 (#34258) has a package-less action row judged by the holders -// at its own (object, name) key, and a disabled package holds no name. With -// an enabled and a disabled package both holding the name on the row's -// object, the row wore the envelope of whichever registered first, and the -// read withheld it (404) when that was the disabled one. No key is added, +// A widening and a narrowing of the action read that names no package, not +// of any key: ADR-0150 D3/D4 (#34258) has a package-less action row judged by +// the holders at its own (object, name) key, and a disabled package holds no +// name. Widening: with an enabled and a disabled package both holding the +// name on the row's object, the row wore the envelope of whichever registered +// first, and the read withheld it (404) when that was the disabled one. +// Narrowing: with every holder on the row's object disabled and an enabled +// package holding the name on another object, the name's holders were judged, +// so the row was served (200); judged at its key it is withheld (404). No key is added, // removed or re-shaped and no stored row changes shape, so no tombstone and // no D2 conversion. No relevance question: the move turns on which installed // packages are disabled, which no question over one stack can name. @@ -16,19 +19,22 @@ export const entry: SemanticMigration = { surface: 'GET /api/v1/meta/action/NAME naming no package, and the in-process item read with no packageId, for an action ' + 'name an enabled and a disabled package both hold on one object while the environment stores a package-less ' - + 'action row of the name on that object', + + 'action row of the name on that object; and the same reads where every package holding the name on that ' + + 'object is disabled while an enabled package holds it on another object', replacement: 'None needed to read the customization: the read that names no package now serves the package-less row as the ' - + 'enabled holder\'s customization, in both registration orders. A key whose every holder is disabled still ' - + 'withholds its package-less row (404), whatever packages hold the name on other objects.', + + 'enabled holder\'s customization, in both registration orders. A key whose every holder is disabled now ' + + 'withholds its package-less row (404) also when an enabled package holds the name on another object, where it ' + + 'was served (200): to keep reading that row, enable a holder on its object or name the package that holds it.', reason: 'A disabled package holds no name (ADR-0150 D3), and an action is keyed by (package, objectName, name) (D4). The ' + 'row borrowed the envelope of the first registered holder bound to its object, so with the disabled holder ' + 'registered first the read withheld the enabled holder\'s customization (404). Judged at the key, the one ' + 'enabled holder lends its envelope. There is no mechanical rewrite: the 404 came from one registration order ' - + 'only, so no caller could rely on it.', + + 'only, so no caller could rely on it. The other cell judged the name, so an enabled holder on another object ' + + 'kept serving a row whose own key had only disabled holders, against D3.', acceptanceCriteria: 'For every such name while the disabled holder stays disabled, in both registration orders: the read that names ' + 'no package answers 200 the package-less row under the enabled holder; with every holder at the row\'s key ' - + 'disabled it answers 404, an enabled holder on another object notwithstanding.', + + 'disabled it answers 404 (it answered 200 where an enabled package held the name on another object).', }; From b61bcd2723976edb2ded11813761d94e8a25ea6f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 12:05:37 +0000 Subject: [PATCH 08/11] fix(metadata-protocol): an action's list slot takes its object only where a package's action of the name binds it #33904's list slot keyed every action by (name, object). That split a platform item bound to `lead` from the environment's object-less row of its name, which the action route reads as one slot whose key is the platform item's, so `/actions/_env/lead/approve` served the platform item instead of answering 404 (runtime action-package-addressing.test.ts, red on CI). The object now joins the slot only where a package's contribution of the name binds it: a package-less row there is that package's customization and shares its slot, and package-less contributions on no package's object keep the name's slot, as on main. The #33904 cell (a package's action on one object, the environment's own on another) still lists both. The local helper is renamed from `actionObjectKey`, the #14878 dead-member name the tree-wide repo pins refuse, to `actionSlotSuffix`. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../src/protocol-overlay-merge.ts | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-overlay-merge.ts b/packages/metadata-protocol/src/protocol-overlay-merge.ts index 0016b29cdd2..176d93bcfe5 100644 --- a/packages/metadata-protocol/src/protocol-overlay-merge.ts +++ b/packages/metadata-protocol/src/protocol-overlay-merge.ts @@ -409,18 +409,41 @@ export function mergePackageAwareOverlay( const buckets = new Map(); const order: string[] = []; // first-seen slot order → stable output // [#33904, ADR-0150 D4] An `action` is keyed `(package, objectName, - // name)`: its slot is `(name, object)` (object-less is its own key), so - // the environment's own action on an object no package's action binds is - // listed beside the package's, as the read naming no package and the - // action route serve it, and never stands in for the package's slot on - // another object. Slotted by name alone, the list dropped it. - const actionObjectKey = (item: unknown): string => { - const object = canonicalMetaUrlType(type) === 'action' ? boundObjectOf(item) : undefined; - return object === undefined ? '' : `\u0001${object}`; + // name)`: a package's action on one object and the environment's own + // package-less action of the name on an object no package's action binds + // are two items, so the latter is listed beside the package's, as the read + // naming no package and the action route serve it, and never stands in + // for the package's slot on another object. Slotted by name alone, the + // list dropped it. The object joins the slot only where a PACKAGE's + // contribution of the name binds it (object-less is its own key): a + // package-less row there is that package's customization and shares its + // slot, and package-less contributions on no package's object keep the + // name's slot, as before (a platform item and the environment's + // object-less row of its name stay one slot, which the action route reads + // as the platform item's key). + const canonicalSlotType = canonicalMetaUrlType(type); + const actionObjectOf = (item: unknown): string => boundObjectOf(item) ?? ''; + const packageHeldObjects = new Map>(); + if (canonicalSlotType === 'action') { + const hold = (name: unknown, item: unknown, pkg: unknown) => { + if (name === undefined || typeof pkg !== 'string' || pkg === '') return; + const objects = packageHeldObjects.get(String(name)) ?? new Set(); + objects.add(actionObjectOf(item)); + packageHeldObjects.set(String(name), objects); + }; + for (const raw of baseItems) hold(listSlotNameOf(canonicalSlotType, raw), raw, (raw as any)?._packageId); + for (const { data, packageId, stored } of records) { + hold(listSlotNameOf(canonicalSlotType, data) ?? (stored?.name || undefined), data, packageId); + } + } + const actionSlotSuffix = (item: unknown, name: unknown): string => { + if (canonicalSlotType !== 'action') return ''; + const object = actionObjectOf(item); + return object !== '' && packageHeldObjects.get(String(name))?.has(object) === true ? `\u0001${object}` : ''; }; const slotOf = (item: unknown, name: unknown): string => { const disc = itemDiscriminator(type, item); - return (disc === undefined ? String(name) : `${String(name)}\u0000${disc}`) + actionObjectKey(item); + return (disc === undefined ? String(name) : `${String(name)}\u0000${disc}`) + actionSlotSuffix(item, name); }; // [#32606] The name each slot is of, so a slot's name grain reads its // sibling members' slots too. From 73c2de844d0ba91d2c96a2cf4bbc693732e2dd59 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 13:24:40 +0000 Subject: [PATCH 09/11] fix(metadata-protocol): a package's object-less action is a list key of its own, and the list's moved cells are declared L2 S2: beside a package's OBJECT-LESS action, the read and the bare delete naming no package served and removed the environment's own action on another object, while the list slotted both by name and named the package's only. Object-less is now a key of its own in the list slot too, so the list names both, as the read does. L2 S1: the list's key slotting moves two cells with no environment-own action (two packages on two objects with a package-less row on one; a list scoped to a package beside the environment's row on another object). Each is pinned with its BASE in protocol.action-list-slot-key.test.ts and given its FROM and TO in the changeset and the ADR-0087 entry. N1: packagelessHolderRefusal's docblock keeps the one-enabled-shipper gap (#38769). N2: the bare-write entry's surface excludes a stored package-less row. N3: the hydrated-doc entry counts a disabled shipper, as the code does. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../34452-same-name-writes-and-hydration.md | 7 +- .../src/protocol-overlay-merge.ts | 14 +-- .../metadata-protocol/src/protocol-save.ts | 13 ++- .../src/protocol.action-list-slot-key.test.ts | 87 +++++++++++++++++++ .../protocol.packageless-save-address.test.ts | 21 +++++ ...de-disabled-row-refused-naming-shippers.ts | 2 +- ...-action-on-another-object-answers-first.ts | 32 +++++-- ...drated-doc-row-wears-no-holder-envelope.ts | 4 +- 8 files changed, 156 insertions(+), 24 deletions(-) create mode 100644 packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts diff --git a/.changeset/34452-same-name-writes-and-hydration.md b/.changeset/34452-same-name-writes-and-hydration.md index db962ffa46c..1480f28b495 100644 --- a/.changeset/34452-same-name-writes-and-hydration.md +++ b/.changeset/34452-same-name-writes-and-hydration.md @@ -12,9 +12,10 @@ Metadata-protocol: none **BREAKING** for a caller that writes or reads a shared name without naming a package, shipped as `patch`: no key an author writes changes (`Metadata-protocol: none`). Four doors that name no package answered by save or registration order, or disagreed with the read of the same name; each now gives the read's answer. Naming the package (`?package=ID`, or `packageId` in process) writes or reads that package's item exactly as before. -- **A bare write beside a disabled package's row** (#34346). Two enabled packages ship the name and its stored rows are bound to a disabled package and to one shipper. FROM the bare publish save answering 200 and writing that shipper's row, and the bare draft save and delete refusing naming that shipper and the disabled package, TO all three refusing `409 RESOURCE_CONFLICT` naming the two shippers, as the bare read does, never the disabled package, and writing or removing nothing. -- **A doc row hydrated after a restart beside two holders** (#34417, ruling 6942962369). FROM the row wearing the first registered holder's envelope, so `?package=FIRST` served the environment's row and every read naming no package refused 409, TO every read naming no package serving the environment's row and `?package=FIRST` serving that holder's own doc. -- **The environment's own action on another object** (#33904, ADR-0150 D4). A package holds an action name on one object and the environment stores its own package-less action of the name on another. FROM the plain read, `/layers` and `/published` naming no package serving the package's action, the merged list naming only it, and the bare delete removing the package's row, TO those reads serving the environment's action, the list naming both, and the bare delete removing the environment's row. +- **A bare write beside a disabled package's row** (#34346). Two enabled packages ship the name and its stored rows are bound to a disabled package and to one shipper, with no package-less row of the name. FROM the bare publish save answering 200 and writing that shipper's row, and the bare draft save and delete refusing naming that shipper and the disabled package, TO all three refusing `409 RESOURCE_CONFLICT` naming the two shippers, as the bare read does, never the disabled package, and writing or removing nothing. +- **A doc row hydrated after a restart beside two holders, a disabled one counted** (#34417, ruling 6942962369). FROM the row wearing the first registered holder's envelope, so `?package=FIRST` served the environment's row and every read naming no package refused 409, TO every read naming no package serving the environment's row and `?package=FIRST` serving that holder's own doc. +- **The environment's own action on another object** (#33904, ADR-0150 D4). A package holds an action name on one object (or object-less) and the environment stores its own package-less action of the name on another. FROM the plain read, `/layers` and `/published` naming no package serving the package's action, the merged list naming only it, and the bare delete removing the package's row, TO those reads serving the environment's action, the list naming both, and the bare delete removing the environment's row. +- **The merged action list where a package binds the object** (#33904, ADR-0150 D4). The list now slots an action at its `(package, objectName, name)` key wherever a package's action of the name binds the object, object-less being a key of its own. Two cells move with no environment-own action. Two packages hold the name on two objects and a package-less row is stored on one: FROM the row listed under both packages and the second package's own action dropped, TO the row listed under its object's package and the second package's own action listed. A list scoped to a package whose action is bound to one object, beside the environment's row on another: FROM that package's slot serving the environment's row, TO its own action. Where no package holds the name, the list slots by name as before. - **A package-less action row beside an enabled and a disabled holder on its object** (#34258). FROM the read naming no package answering 404 when the disabled holder registered first, TO 200 serving the row as the enabled holder's customization in both orders. And where every holder on the row's object is disabled while an enabled package holds the name on another object: FROM 200 serving the row (the name, not the key, was judged, and it had an enabled holder) TO 404, as a key whose every holder is disabled answers with no other holder of the name. The registry's heal for a package-less overlay row whose every holder is disabled (#33127) now keeps it recorded with no holder, so enabling one holder rebuilds it under that holder's envelope; no door's answer moves. diff --git a/packages/metadata-protocol/src/protocol-overlay-merge.ts b/packages/metadata-protocol/src/protocol-overlay-merge.ts index 176d93bcfe5..fea200e353f 100644 --- a/packages/metadata-protocol/src/protocol-overlay-merge.ts +++ b/packages/metadata-protocol/src/protocol-overlay-merge.ts @@ -415,12 +415,12 @@ export function mergePackageAwareOverlay( // naming no package and the action route serve it, and never stands in // for the package's slot on another object. Slotted by name alone, the // list dropped it. The object joins the slot only where a PACKAGE's - // contribution of the name binds it (object-less is its own key): a - // package-less row there is that package's customization and shares its - // slot, and package-less contributions on no package's object keep the - // name's slot, as before (a platform item and the environment's - // object-less row of its name stay one slot, which the action route reads - // as the platform item's key). + // contribution of the name binds it, object-less being a key of its own + // (`\u0001` alone): a package-less row there is that package's + // customization and shares its slot, and package-less contributions on no + // package's object keep the name's slot, as before (a platform item and + // the environment's object-less row of its name stay one slot, which the + // action route reads as the platform item's key). const canonicalSlotType = canonicalMetaUrlType(type); const actionObjectOf = (item: unknown): string => boundObjectOf(item) ?? ''; const packageHeldObjects = new Map>(); @@ -439,7 +439,7 @@ export function mergePackageAwareOverlay( const actionSlotSuffix = (item: unknown, name: unknown): string => { if (canonicalSlotType !== 'action') return ''; const object = actionObjectOf(item); - return object !== '' && packageHeldObjects.get(String(name))?.has(object) === true ? `\u0001${object}` : ''; + return packageHeldObjects.get(String(name))?.has(object) === true ? `\u0001${object}` : ''; }; const slotOf = (item: unknown, name: unknown): string => { const disc = itemDiscriminator(type, item); diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 6915fed20b3..83b4caf1e75 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3641,10 +3641,15 @@ export async function packagelessRowHeldBaseDraftAddress( * leave to the write), a type the registry does not read by package, or a * registry without the reads. * - * [#34346] With an enabled and a disabled holder, the draft save and the - * delete take their address from the rows, so their refusal of rows bound to - * two or more packages is judged by {@link disabledRowHoldersRefusal}, which - * never names the disabled package. + * [#34346] With two or more ENABLED shippers and a disabled holder, the draft + * save and the delete take their address from the rows, so their refusal of + * rows bound to two or more packages is judged by + * {@link disabledRowHoldersRefusal}, which never names the disabled package. + * + * Known gap (#38769): with ONE enabled shipper and the rows bound to it and to + * a disabled package, that helper answers `undefined` and the draft save and + * the delete still refuse `409` naming the disabled package, where the read + * serves the enabled shipper and the publish save writes its row. */ export function packagelessHolderRefusal( host: Pick, diff --git a/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts b/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts new file mode 100644 index 00000000000..4a7ad0e1085 --- /dev/null +++ b/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts @@ -0,0 +1,87 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#33904, ADR-0150 D4] The merged action list slots an action at D4's key + * `(package, objectName, name)` where a PACKAGE's contribution of the name + * binds the object (object-less being a key of its own), and by name + * elsewhere, as before. + * + * Each cell names its FROM (the list slotted every action by name) and its TO. + * A package-less row on a package's object is that package's customization + * and shares its slot; a package-less row on no package's object is the + * environment's own item and is listed beside the packages'. Package-less + * contributions with no package holding the name keep one slot, which the + * action route reads as the platform item's key + * (runtime `action-package-addressing.test.ts`). + * + * The read and delete halves, through the protocol, are pinned in + * `protocol.packageless-save-address.test.ts`. + */ + +import { describe, expect, it } from 'vitest'; +import { mergePackageAwareOverlay } from './protocol-overlay-merge.js'; + +const NAME = 'approve'; +const action = (label: string, objectName?: string, packageId?: string) => ({ + name: NAME, label, type: 'url', target: `https://example.invalid/${label}`, + ...(objectName ? { objectName } : {}), + ...(packageId ? { _packageId: packageId } : {}), +}); +const row = (data: object, packageId?: string, standIn = false) => ({ + data, packageId, stored: { type: 'action', name: NAME }, ...(standIn ? { standIn: true } : {}), +}); +/** `[label, objectName, package]` of each listed item, in list order. */ +const listed = (out: unknown[]) => (out as any[]).map((i) => [i.label, i.objectName ?? null, i._packageId ?? null]); + +describe('[#33904] the list slots an action at its key where a package binds the object', () => { + it('two packages on two objects, a package-less row on one of them: the row is that package\'s customization, and the other package\'s own item is listed (BASE: the row under both packages, P2\'s item dropped)', () => { + const out = mergePackageAwareOverlay('action', [action('p1', 'account', 'P1'), action('p2', 'contact', 'P2')], [row(action('env', 'account'))]); + expect(listed(out)).toEqual([['env', 'account', 'P1'], ['p2', 'contact', 'P2']]); + }); + + it('a list scoped to a code package P on `account`, the environment\'s row on `contact` passed as a stand-in: P\'s slot is P\'s own item, and the stand-in seats none (BASE: P\'s slot served the environment\'s body)', () => { + const unseated = new WeakSet(); + const out = mergePackageAwareOverlay('action', [action('p', 'account', 'P')], [row(action('env', 'contact'), undefined, true)], undefined, unseated); + expect(listed(out)[0]).toEqual(['p', 'account', 'P']); + // The stand-in reaches a slot of its own: emitted and recorded, so the + // caller drops it once the last layer has merged. + expect((out as any[]).slice(1).every((item) => unseated.has(item))).toBe(true); + }); + + it('a package\'s OBJECT-LESS action stored, the environment\'s row on `contact`: both listed (BASE: P\'s item only)', () => { + const out = mergePackageAwareOverlay('action', [], [row(action('p'), 'P'), row(action('env', 'contact'))]); + expect(listed(out)).toEqual([['p', null, 'P'], ['env', 'contact', null]]); + }); + + it('a code package\'s OBJECT-LESS action, the environment\'s row on `contact`: both listed (BASE: the environment\'s body under P\'s name)', () => { + const out = mergePackageAwareOverlay('action', [action('p', undefined, 'P')], [row(action('env', 'contact'))]); + expect(listed(out)).toEqual([['p', null, 'P'], ['env', 'contact', null]]); + }); + + it('a package on `account`, the environment\'s OBJECT-LESS row: both listed (BASE: P\'s item only)', () => { + const out = mergePackageAwareOverlay('action', [], [row(action('p', 'account'), 'P'), row(action('env'))]); + expect(listed(out)).toEqual([['p', 'account', 'P'], ['env', null, null]]); + }); + + describe('CONTROLs (unchanged)', () => { + it('a package-less row on the object a package binds is its customization', () => { + const out = mergePackageAwareOverlay('action', [action('p', 'account', 'P')], [row(action('env', 'account'))]); + expect(listed(out)).toEqual([['env', 'account', 'P']]); + }); + + it('a package-less OBJECT-LESS row beside a package\'s object-less action is its customization', () => { + const out = mergePackageAwareOverlay('action', [action('p', undefined, 'P')], [row(action('env'))]); + expect(listed(out)).toEqual([['env', null, 'P']]); + }); + + it('no package holds the name: a platform item on `lead` and the environment\'s object-less row stay one slot', () => { + const out = mergePackageAwareOverlay('action', [action('platform', 'lead')], [row(action('env'))]); + expect(listed(out)).toEqual([['env', null, null]]); + }); + + it('another type is slotted by name alone', () => { + const out = mergePackageAwareOverlay('flow', [{ name: NAME, label: 'p', objectName: 'account', _packageId: 'P' }], [row({ name: NAME, label: 'env', objectName: 'contact' })]); + expect(listed(out)).toEqual([['env', 'contact', 'P']]); + }); + }); +}); diff --git a/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts b/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts index 33f1a0a9413..d129312447c 100644 --- a/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts +++ b/packages/metadata-protocol/src/protocol.packageless-save-address.test.ts @@ -766,6 +766,27 @@ describe('[ADR-0150 D4] a package-less save of an ACTION on an object the holder }); } + // [#33904, ADR-0150 D4] P's OBJECT-LESS action is a key of its own, so + // the environment's row on `task` is its own item beside it: the list + // names both, as the read and the delete naming no package already serve + // and remove the environment's (BASE: the list named P's item only). + it('[#33904] P\'s action OBJECT-LESS, the environment\'s on `task`: the list names both, the read naming no package serves the environment\'s, and the delete naming no package removes it', async () => { + const { protocol, rows } = makeProtocol(); + await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'p'), packageId: WRITABLE }); + await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'env', 'task') }); + expect(stored(rows('action', NAME))).toEqual([[WRITABLE, null, 'p'], [null, 'task', 'env']]); + const face = (item: any) => [item?.objectName ?? null, item?.label ?? null]; + + const listed = ((await protocol.getMetaItems({ type: 'action' })).items as any[]) + .filter((item) => item?.name === NAME).map(face) + .sort((a, b) => String(a[0]).localeCompare(String(b[0]))); + expect(listed).toEqual([[null, 'p'], ['task', 'env']]); + expect(face((await protocol.getMetaItem({ type: 'action', name: NAME })).item)).toEqual(['task', 'env']); + + await protocol.deleteMetaItem({ type: 'action', name: NAME }); + expect(stored(rows('action', NAME))).toEqual([[WRITABLE, null, 'p']]); + }); + it('[#33904] CONTROL: with no environment row on another object, the delete naming no package removes P\'s row, as the generic re-addressing does', async () => { const { protocol, rows } = makeProtocol(); await protocol.saveMetaItem({ type: 'action', name: NAME, item: action(NAME, 'p', 'invoice'), packageId: WRITABLE }); diff --git a/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts b/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts index 4a3454ce1b4..9bbaf5971f1 100644 --- a/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts +++ b/packages/spec/src/migrations/entries/semantic/19.bare-write-beside-disabled-row-refused-naming-shippers.ts @@ -18,7 +18,7 @@ export const entry: SemanticMigration = { 'The save that names no package (PUT /api/v1/meta/TYPE/NAME, as a publish save and as a draft save, and the ' + 'in-process save with no packageId) and the delete that names no package (DELETE /api/v1/meta/TYPE/NAME and the ' + 'in-process delete with no packageId) of a name two or more enabled packages ship while its stored rows are ' - + 'bound to a disabled package and to one of the shippers', + + 'bound to a disabled package and to one of the shippers, and no package-less row of the name is stored', replacement: 'Name the package: PUT or DELETE /api/v1/meta/TYPE/NAME?package=PACKAGE (and the in-process save and delete with ' + 'packageId) writes or removes that enabled package\'s row, as before. The write that names no package answers ' diff --git a/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts b/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts index 2532ecfc868..8d67e329231 100644 --- a/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts +++ b/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts @@ -8,32 +8,50 @@ import type { SemanticMigration } from '../../types.js'; // package's action of a name on one object and the environment's own // package-less action of the name on another, the two are items of their own, // as the save door and the action route already key them; the doors that -// name neither a package nor an object took the package's. No key is added, +// name neither a package nor an object took the package's. Object-less is a +// key of its own on both sides. The merged list slots an action at that key +// wherever a package's action of the name binds the object, which also moves +// two list cells with no environment-own item: a package-less row on one +// package's object is listed as that package's customization only (it was +// listed under every package of the name, and another package's own action +// of the name was dropped), and a list scoped to a package lists the +// package's own action rather than the environment's row on another object. +// No key is added, // removed or re-shaped and no stored row changes shape, so no tombstone and // no D2 conversion. No relevance question: the move turns on which installed // packages hold a name, which no question over one stack can name. export const entry: SemanticMigration = { id: 'environment-action-on-another-object-answers-first', surface: - 'For an action name a package holds on one object while the environment stores its own package-less action of ' - + 'the name on another object (and no package\'s action of the name binds that object): ' + 'For an action name a package holds on one object (or object-less) while the environment stores its own ' + + 'package-less action of the name on another object, or object-less (and no package\'s action of the name binds ' + + 'that object): ' + 'GET /api/v1/meta/action/NAME, /layers and /published naming no package, the in-process item read with no ' + 'packageId, the merged action list (GET /api/v1/meta/action and the in-process list), and ' - + 'DELETE /api/v1/meta/action/NAME naming no package', + + 'DELETE /api/v1/meta/action/NAME naming no package. Also the merged action list, with no such environment ' + + 'action, where two packages hold the name on two objects and a package-less row is stored on one of them, ' + + 'and the list scoped to a package (GET /api/v1/meta/action?package=PACKAGE) whose action of the name is bound ' + + 'to one object while the environment\'s row is on another', replacement: 'To read or delete the package\'s action, name the package: GET or DELETE /api/v1/meta/action/NAME?package=PACKAGE ' + 'reads or removes that package\'s action, as before. The reads that name no package serve the environment\'s ' + 'action (its version too), the list names both actions, and the delete that names no package removes the ' - + 'environment\'s row and leaves the package\'s.', + + 'environment\'s row and leaves the package\'s. In the list, a package-less row on one package\'s object is that ' + + 'package\'s customization only, and the other package\'s own action is listed again; the list scoped to a ' + + 'package lists that package\'s own action, and the environment\'s row on another object is read naming no package.', reason: 'The environment\'s own item answers first, and reads and writes give the same answer (ruling 6942962369). The ' + 'plain read, /layers effective and /published served the package\'s action, the list slotted actions by name and ' - + 'named the package\'s only, and the bare delete removed the package\'s row and left the environment\'s, while ' + + 'named the package\'s only (so a package-less row on one package\'s object was also listed under every other ' + + 'package of the name, in place of that package\'s own action, and stood in for a scoped list\'s package on ' + + 'another object), and the bare delete removed the package\'s row and left the environment\'s, while ' + 'the save door and the action route keyed the two apart. There is no mechanical rewrite: which action a caller ' + 'meant is a judgement about that caller.', acceptanceCriteria: 'For every such name, before and after a restart and in both save orders: every read that names no package ' + 'answers the environment\'s action, ?package=PACKAGE answers the package\'s, the list names both, and the ' + 'delete that names no package removes only the environment\'s row, after which the reads that name no package ' - + 'answer the package\'s action.', + + 'answer the package\'s action. With two packages on two objects and a package-less row on one, the list names ' + + 'the row under that package and the other package\'s own action; a list scoped to a package names its own ' + + 'action.', }; diff --git a/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts b/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts index d654d75e77b..5abeb862ebc 100644 --- a/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts +++ b/packages/spec/src/migrations/entries/semantic/19.hydrated-doc-row-wears-no-holder-envelope.ts @@ -14,8 +14,8 @@ import type { SemanticMigration } from '../../types.js'; export const entry: SemanticMigration = { id: 'hydrated-doc-row-wears-no-holder-envelope', surface: - 'After a restart (the stored rows hydrated after the packages registered), the read of a doc two or more enabled ' - + 'packages ship while the environment stores its own package-less doc row of the same name: ' + 'After a restart (the stored rows hydrated after the packages registered), the read of a doc two or more packages ' + + 'ship (a disabled one counted) while the environment stores its own package-less doc row of the same name: ' + 'GET /api/v1/meta/doc/NAME, /layers and /published naming no package, and the same reads with ' + '?package=PACKAGE of the holder registered first', replacement: From 9910fbc3622b51a4e6b2716325f6aaad0e702dd5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 15:08:33 +0000 Subject: [PATCH 10/11] fix(metadata-protocol): declare and pin the list cell where a platform action sits at a key no package binds The list slot fix also lists a platform action of a name (no package, no stored row) beside a package's action of the name on another object, or object-less, where main dropped it (b61bcd27 moved the bound cells, 73c2de84 the object-less one). The changeset bullet and the environment-action-on-another-object-answers-first entry now name it, FROM and TO, and three pins plus a CONTROL hold it. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- .../34452-same-name-writes-and-hydration.md | 2 +- .../src/protocol.action-list-slot-key.test.ts | 23 ++++++++++++++++++- ...-action-on-another-object-answers-first.ts | 23 +++++++++++-------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.changeset/34452-same-name-writes-and-hydration.md b/.changeset/34452-same-name-writes-and-hydration.md index 1480f28b495..37ad39a8d16 100644 --- a/.changeset/34452-same-name-writes-and-hydration.md +++ b/.changeset/34452-same-name-writes-and-hydration.md @@ -15,7 +15,7 @@ Metadata-protocol: none - **A bare write beside a disabled package's row** (#34346). Two enabled packages ship the name and its stored rows are bound to a disabled package and to one shipper, with no package-less row of the name. FROM the bare publish save answering 200 and writing that shipper's row, and the bare draft save and delete refusing naming that shipper and the disabled package, TO all three refusing `409 RESOURCE_CONFLICT` naming the two shippers, as the bare read does, never the disabled package, and writing or removing nothing. - **A doc row hydrated after a restart beside two holders, a disabled one counted** (#34417, ruling 6942962369). FROM the row wearing the first registered holder's envelope, so `?package=FIRST` served the environment's row and every read naming no package refused 409, TO every read naming no package serving the environment's row and `?package=FIRST` serving that holder's own doc. - **The environment's own action on another object** (#33904, ADR-0150 D4). A package holds an action name on one object (or object-less) and the environment stores its own package-less action of the name on another. FROM the plain read, `/layers` and `/published` naming no package serving the package's action, the merged list naming only it, and the bare delete removing the package's row, TO those reads serving the environment's action, the list naming both, and the bare delete removing the environment's row. -- **The merged action list where a package binds the object** (#33904, ADR-0150 D4). The list now slots an action at its `(package, objectName, name)` key wherever a package's action of the name binds the object, object-less being a key of its own. Two cells move with no environment-own action. Two packages hold the name on two objects and a package-less row is stored on one: FROM the row listed under both packages and the second package's own action dropped, TO the row listed under its object's package and the second package's own action listed. A list scoped to a package whose action is bound to one object, beside the environment's row on another: FROM that package's slot serving the environment's row, TO its own action. Where no package holds the name, the list slots by name as before. +- **The merged action list where a package binds the object** (#33904, ADR-0150 D4). The list now slots an action at its `(package, objectName, name)` key wherever a package's action of the name binds the object, object-less being a key of its own. Three cells move with no environment-own action. Two packages hold the name on two objects and a package-less row is stored on one: FROM the row listed under both packages and the second package's own action dropped, TO the row listed under its object's package and the second package's own action listed. A list scoped to a package whose action is bound to one object, beside the environment's row on another: FROM that package's slot serving the environment's row, TO its own action. A platform action of the name (no package, no stored row) on one object, or object-less, beside a package's action on another object, or object-less: FROM the platform action dropped, TO both listed. Where no package holds the name, the list slots by name as before. - **A package-less action row beside an enabled and a disabled holder on its object** (#34258). FROM the read naming no package answering 404 when the disabled holder registered first, TO 200 serving the row as the enabled holder's customization in both orders. And where every holder on the row's object is disabled while an enabled package holds the name on another object: FROM 200 serving the row (the name, not the key, was judged, and it had an enabled holder) TO 404, as a key whose every holder is disabled answers with no other holder of the name. The registry's heal for a package-less overlay row whose every holder is disabled (#33127) now keeps it recorded with no holder, so enabling one holder rebuilds it under that holder's envelope; no door's answer moves. diff --git a/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts b/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts index 4a7ad0e1085..734687e76c9 100644 --- a/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts +++ b/packages/metadata-protocol/src/protocol.action-list-slot-key.test.ts @@ -9,7 +9,8 @@ * Each cell names its FROM (the list slotted every action by name) and its TO. * A package-less row on a package's object is that package's customization * and shares its slot; a package-less row on no package's object is the - * environment's own item and is listed beside the packages'. Package-less + * environment's own item and is listed beside the packages', as is a platform + * action (no package) at a key no package's action binds. Package-less * contributions with no package holding the name keep one slot, which the * action route reads as the platform item's key * (runtime `action-package-addressing.test.ts`). @@ -63,7 +64,27 @@ describe('[#33904] the list slots an action at its key where a package binds the expect(listed(out)).toEqual([['p', 'account', 'P'], ['env', null, null]]); }); + it('a platform action (no package) on `lead`, a code package\'s OBJECT-LESS action: both listed (BASE, on `main` and the first list fix: P\'s item only)', () => { + const out = mergePackageAwareOverlay('action', [action('platform', 'lead'), action('p', undefined, 'P')], []); + expect(listed(out)).toEqual([['platform', 'lead', null], ['p', null, 'P']]); + }); + + it('a platform action on `lead`, a code package on `account`: both listed (BASE: P\'s item only)', () => { + const out = mergePackageAwareOverlay('action', [action('platform', 'lead'), action('p', 'account', 'P')], []); + expect(listed(out)).toEqual([['platform', 'lead', null], ['p', 'account', 'P']]); + }); + + it('an OBJECT-LESS platform action, a code package on `account`: both listed (BASE: P\'s item only)', () => { + const out = mergePackageAwareOverlay('action', [action('platform'), action('p', 'account', 'P')], []); + expect(listed(out)).toEqual([['platform', null, null], ['p', 'account', 'P']]); + }); + describe('CONTROLs (unchanged)', () => { + it('a platform action on the object a package binds shares its slot', () => { + const out = mergePackageAwareOverlay('action', [action('platform', 'lead'), action('p', 'lead', 'P')], []); + expect(listed(out)).toEqual([['p', 'lead', 'P']]); + }); + it('a package-less row on the object a package binds is its customization', () => { const out = mergePackageAwareOverlay('action', [action('p', 'account', 'P')], [row(action('env', 'account'))]); expect(listed(out)).toEqual([['env', 'account', 'P']]); diff --git a/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts b/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts index 8d67e329231..e551c78c54b 100644 --- a/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts +++ b/packages/spec/src/migrations/entries/semantic/19.environment-action-on-another-object-answers-first.ts @@ -11,13 +11,14 @@ import type { SemanticMigration } from '../../types.js'; // name neither a package nor an object took the package's. Object-less is a // key of its own on both sides. The merged list slots an action at that key // wherever a package's action of the name binds the object, which also moves -// two list cells with no environment-own item: a package-less row on one +// three list cells with no environment-own item: a package-less row on one // package's object is listed as that package's customization only (it was // listed under every package of the name, and another package's own action -// of the name was dropped), and a list scoped to a package lists the -// package's own action rather than the environment's row on another object. -// No key is added, -// removed or re-shaped and no stored row changes shape, so no tombstone and +// of the name was dropped); a list scoped to a package lists the package's +// own action rather than the environment's row on another object; and a +// platform item of the name (no package, no stored row) at a key no +// package's action binds is listed beside the package's action (it was +// dropped). No key is added, removed or re-shaped and no stored row changes shape, so no tombstone and // no D2 conversion. No relevance question: the move turns on which installed // packages hold a name, which no question over one stack can name. export const entry: SemanticMigration = { @@ -31,20 +32,24 @@ export const entry: SemanticMigration = { + 'DELETE /api/v1/meta/action/NAME naming no package. Also the merged action list, with no such environment ' + 'action, where two packages hold the name on two objects and a package-less row is stored on one of them, ' + 'and the list scoped to a package (GET /api/v1/meta/action?package=PACKAGE) whose action of the name is bound ' - + 'to one object while the environment\'s row is on another', + + 'to one object while the environment\'s row is on another, and the merged list where a platform action of the ' + + 'name (no package) is on an object, or object-less, while every package\'s action of the name is on another ' + + 'object or object-less', replacement: 'To read or delete the package\'s action, name the package: GET or DELETE /api/v1/meta/action/NAME?package=PACKAGE ' + 'reads or removes that package\'s action, as before. The reads that name no package serve the environment\'s ' + 'action (its version too), the list names both actions, and the delete that names no package removes the ' + 'environment\'s row and leaves the package\'s. In the list, a package-less row on one package\'s object is that ' + 'package\'s customization only, and the other package\'s own action is listed again; the list scoped to a ' - + 'package lists that package\'s own action, and the environment\'s row on another object is read naming no package.', + + 'package lists that package\'s own action, and the environment\'s row on another object is read naming no package. ' + + 'A platform action at a key no package\'s action binds is listed beside the package\'s; read it by its object ' + + '(the action route) or override it in the environment.', reason: 'The environment\'s own item answers first, and reads and writes give the same answer (ruling 6942962369). The ' + 'plain read, /layers effective and /published served the package\'s action, the list slotted actions by name and ' + 'named the package\'s only (so a package-less row on one package\'s object was also listed under every other ' + 'package of the name, in place of that package\'s own action, and stood in for a scoped list\'s package on ' - + 'another object), and the bare delete removed the package\'s row and left the environment\'s, while ' + + 'another object, and a platform action at another key was dropped from the list), and the bare delete removed the package\'s row and left the environment\'s, while ' + 'the save door and the action route keyed the two apart. There is no mechanical rewrite: which action a caller ' + 'meant is a judgement about that caller.', acceptanceCriteria: @@ -53,5 +58,5 @@ export const entry: SemanticMigration = { + 'delete that names no package removes only the environment\'s row, after which the reads that name no package ' + 'answer the package\'s action. With two packages on two objects and a package-less row on one, the list names ' + 'the row under that package and the other package\'s own action; a list scoped to a package names its own ' - + 'action.', + + 'action; a platform action at a key no package\'s action binds is listed beside the package\'s.', }; From 5db4acc5c18d893fc2b0261b767c15bdaeb9e438 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 15:39:47 +0000 Subject: [PATCH 11/11] docs(metadata-protocol): the known-gap note cites the live card #38753 #38769 was closed as a duplicate into #38753. Claude-Session: https://claude.ai/code/session_01ADHkmQmQ1jpFsNcARMbY56 Co-authored-by: Claude --- packages/metadata-protocol/src/protocol-save.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 83b4caf1e75..5fa64130d91 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3646,7 +3646,7 @@ export async function packagelessRowHeldBaseDraftAddress( * rows bound to two or more packages is judged by * {@link disabledRowHoldersRefusal}, which never names the disabled package. * - * Known gap (#38769): with ONE enabled shipper and the rows bound to it and to + * Known gap (#38753): with ONE enabled shipper and the rows bound to it and to * a disabled package, that helper answers `undefined` and the draft save and * the delete still refuse `409` naming the disabled package, where the read * serves the enabled shipper and the publish save writes its row.