From 9d7be1547eb9db8d981d47c8c4e8ac37f87be2d0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 11:37:49 +0000 Subject: [PATCH 01/18] fix(metadata-protocol): the read naming no package withholds a package-less row of a key whose every holder is disabled A package-less row whose key an installed package holds is that holder's customization (ADR-0150 D4, owned over every holder, disabled included). With every holder disabled, the bare read on the served and execution faces now answers as if no row were stored, at any member, a locale the holder never shipped included; the row is kept and served again on re-enable. The environment's own item (no holder at its key) is served as before. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/protocol-meta-item-face.ts | 39 +++++- .../package-scoped-exact-qualifier.test.ts | 116 ++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index cf956ecdaf9..c923d40bb9e 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -118,6 +118,37 @@ function isHoldersPairRow(engine: unknown, type: string, name: string, item: unk return every.some((holder) => pairsOf(holder, installed).includes(stamp)); } +/** + * [#33401, ADR-0150 D4] The package a package-less row (stamped with no + * package, `''` or the `sys_metadata` sentinel) that the read naming no + * package reached is withheld with: the holder whose key the row customizes, + * when every holder of that key is disabled. Seat ruling 6882483833 on + * #32814: a package-less row whose key (`(type, name)`; `(object, name)` for + * an `action`) an installed package holds is that holder's overlay, owned + * over every holder, disabled included (epic ruling 6816940784 on #31699), so + * with every holder disabled the read answers as if no row were stored. The + * member is not part of the key: a locale the holder never shipped is still + * its customization. + * + * The key's holders are the registry's one owner rule + * (`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}). + * 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). + */ +function packagelessRowWithheldHolder(registry: any, type: string, name: string, item: unknown): string | undefined { + const stamp = (item as { _packageId?: unknown } | null | undefined)?._packageId; + if (stamp !== undefined && stamp !== null && stamp !== '' && stamp !== 'sys_metadata') return undefined; + if (typeof registry?.overlayRowBinding !== 'function' || typeof registry?.isPackageDisabled !== 'function') return undefined; + 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; + return disabledOnlyHolderOf(registry, type, name); +} + /** * [#32183] The package whose stack a read naming no package takes, for a * name a disabled package also holds: the one holder ADR-0150 D3 resolves @@ -459,6 +490,9 @@ export async function readMetaItemFace( // name's holders too, as it does when it reached nothing: a pair row of a // name only disabled packages hold is their withheld item, the answer the // same read gives with no row stored. + // [#33401] …and so does a package-less row of a key whose every holder is + // disabled ({@link packagelessRowWithheldHolder}): that holder's + // customization, withheld with it; the environment's own item is served. const withheldHolder = request.type === 'object' || request.type === 'package' ? undefined : (request.packageId ? disabledExactAddressHolder(this, { type: request.type, name: request.name, packageId: request.packageId }) : undefined) @@ -467,7 +501,10 @@ export async function readMetaItemFace( ? !isStoredUnder(answer.item, request.packageId) : isHoldersPairRow(this.engine, request.type, request.name, answer.item)) ? disabledOnlyHolderOf(this.engine?.registry, request.type, request.name) - : undefined); + : undefined) + ?? (request.packageId || answer?.item == null + ? undefined + : packagelessRowWithheldHolder(this.engine?.registry, request.type, request.name, answer.item)); if (withheldHolder === undefined && (request.type === 'object' || request.type === 'package' || (!withheldAction && !isItemOfDisabledPackage(this.engine?.registry, answer?.item)))) { return answer; diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index defbcaeb7ec..2e8f84092c8 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -2716,3 +2716,119 @@ describe('[#32814] the read naming no package withholds a pair row of a name onl }, ); }); + +/** + * [#33401, ADR-0150 D4] The read naming no package, at a member only a + * PACKAGE-LESS stored row carries, of a key whose every holder is disabled. + * Seat ruling 6882483833 on #32814: a package-less row whose key an installed + * package holds is that holder's overlay, owned over every holder, disabled + * included; the member is not part of the key, so a locale the holder never + * shipped is still its customization. With every holder disabled the read + * answers as if no row were stored; the row is kept and served on re-enable. + * + * FROM (`main` 1e65a389, measured on this fixture and on the REST door): the + * row (200), on the served and the execution face, in every order below. A + * row the holder's own member overlays, and the same row once hydrated into + * the registry, were already withheld (CONTROLs below). TO: the holder's + * withheld item, the answer with no row stored. + */ +describe('[#33401] the read naming no package withholds a package-less row of a key only disabled packages hold', () => { + const custom = (name: string, locale: string) => rows.push({ + id: `row_${name}_${locale}`, type: 'email_template', name, state: 'active', package_id: null, bundle_member: locale, + metadata: JSON.stringify({ name, label: `custom ${locale}`, locale, subject: `custom ${locale}`, bodyHtml: '

c

' }), + }); + const tpl = (packageId: string, name = 'welcome') => registry.registerItem('email_template', { + name, label: `${packageId.split('.').pop()} en-US`, locale: 'en-US', subject: 'en', bodyHtml: '

x

', + }, 'name' as never, packageId); + const bare = (member = 'fr-FR', name = 'welcome') => protocol.getMetaItem({ type: 'email_template', name, member } as never); + const bareForExecution = (member = 'fr-FR', name = 'welcome') => + protocol.getMetaItemForExecution({ type: 'email_template', name, member } as never); + /** The boot's hydration: the list read lays the stored row into the registry's slot. */ + const hydrate = () => protocol.getMetaItems({ type: 'email_template' } as never); + + const ORDERS = [ + ['the holder registered, then the row saved', false], + ['the row saved, then the holder registered', true], + ] as const; + const DISABLE = [['the holder disabled last', false], ['the holder disabled first', true]] as const; + const CASES = ORDERS.flatMap(([order, rowFirst]) => DISABLE.map(([when, disableFirst]) => [order, when, rowFirst, disableFirst] as const)); + + it.each(CASES)('%s, %s: the bare read at a locale the holder never shipped answers its withheld item (BASE: the row), on both faces; re-enabled, the row', async (_order, _when, rowFirst, disableFirst) => { + if (rowFirst) custom('welcome', 'fr-FR'); + tpl(A); + if (disableFirst) registry.disablePackage(A); + if (!rowFirst) custom('welcome', 'fr-FR'); + if (!disableFirst) registry.disablePackage(A); + const answer = await bare(); + expect(answer?.item).toBeUndefined(); + expect((answer as { packageId?: string } | undefined)?.packageId).toBe(A); + expect(JSON.stringify(answer ?? null)).not.toContain('custom fr-FR'); + const executed = await bareForExecution(); + expect(executed?.item).toBeUndefined(); + expect(JSON.stringify(executed ?? null)).not.toContain('custom fr-FR'); + // CONTROL — re-enabled: the row is served again, untouched. + registry.enablePackage(A); + expect(labelOf(await bare())).toBe('custom fr-FR'); + expect(labelOf(await bareForExecution())).toBe('custom fr-FR'); + }); + + // `version` is left out of the comparison, as in the #32814 pin above. + it('the holder disabled: the answer with the package-less row stored is the answer with none', async () => { + tpl(A); + registry.disablePackage(A); + const { version: _noRowVersion, ...withoutRow } = (await bare()) as Record; + custom('welcome', 'fr-FR'); + const { version: _rowVersion, ...withRow } = (await bare()) as Record; + expect(withRow).toEqual(withoutRow); + }); + + it('two holders, both disabled: withheld too; both re-enabled: the read\'s own refusal naming both, as before the disable', async () => { + tpl(A); + tpl(B); + custom('welcome', 'fr-FR'); + registry.disablePackage(A); + registry.disablePackage(B); + const answer = await bare(); + expect(answer?.item).toBeUndefined(); + expect(JSON.stringify(answer ?? null)).not.toContain('custom fr-FR'); + registry.enablePackage(A); + registry.enablePackage(B); + const err = await refusalOf(bare); + expect([err.status, err.refusal.candidates]).toEqual([409, [{ kind: 'package', packageId: A }, { kind: 'package', packageId: B }]]); + }); + + it('CONTROL — the holder enabled: the row is served, on both faces', async () => { + tpl(A); + custom('welcome', 'fr-FR'); + expect(labelOf(await bare())).toBe('custom fr-FR'); + expect(labelOf(await bareForExecution())).toBe('custom fr-FR'); + }); + + it('CONTROL — the environment\'s own item (no package holds its key) is served while another package\'s same-type item is disabled', async () => { + tpl(A); + custom('farewell', 'fr-FR'); + registry.disablePackage(A); + expect(labelOf(await bare('fr-FR', 'farewell'))).toBe('custom fr-FR'); + expect(labelOf(await bareForExecution('fr-FR', 'farewell'))).toBe('custom fr-FR'); + }); + + it.each([['stored', false], ['stored and hydrated', true]] as const)('CONTROL — a package-less row at the member the holder ships (%s): withheld, as on BASE', async (_state, hydrated) => { + tpl(A); + custom('welcome', 'en-US'); + if (hydrated) await hydrate(); + registry.disablePackage(A); + const answer = await bare('en-US'); + expect(answer?.item).toBeUndefined(); + expect(JSON.stringify(answer ?? null)).not.toContain('custom en-US'); + }); + + it('CONTROL — the fr-FR row hydrated into the registry: withheld, as on BASE', async () => { + tpl(A); + custom('welcome', 'fr-FR'); + await hydrate(); + registry.disablePackage(A); + const answer = await bare(); + expect(answer?.item).toBeUndefined(); + expect(JSON.stringify(answer ?? null)).not.toContain('custom fr-FR'); + }); +}); From 5488f4806bf1522e713530a3b3702ac8452d65e4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 11:37:50 +0000 Subject: [PATCH 02/18] fix(metadata-protocol): `_env` answers 404 for a name only disabled packages hold A disabled package holds no name, so `/meta/:type/_env/:name` of a name only disabled packages hold is admitted as a name no package holds and answers the read's own 404 on both transports, where it refused 409 naming the disabled packages. The item face withholds every customization of such a name with its holders, so the read never serves one. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/protocol-exact-qualifier.ts | 20 ++++++++----- .../package-scoped-exact-qualifier.test.ts | 17 +++++++---- .../src/meta-qualified-item-route.test.ts | 30 ++++++++++++++++--- .../rest/src/meta-qualified-item-route.ts | 5 ++-- .../domains/meta-qualified-item-read.test.ts | 30 ++++++++++++++++--- packages/runtime/src/domains/meta.ts | 7 +++-- 6 files changed, 83 insertions(+), 26 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-exact-qualifier.ts b/packages/metadata-protocol/src/protocol-exact-qualifier.ts index 9ea5a2e29f5..dccc96f360d 100644 --- a/packages/metadata-protocol/src/protocol-exact-qualifier.ts +++ b/packages/metadata-protocol/src/protocol-exact-qualifier.ts @@ -946,6 +946,8 @@ export function resolveMetaItemAddress( * environment does not hold and a package does is refused * (`not-held-by-qualifier`, `callerPackageId: null`); otherwise the read is a * caller with no package, which E8's resolver answers environment-first. + * [#33385] A disabled package holds no name here either: a name only + * disabled packages hold is admitted, and the item face answers its 404. * Types outside the covered set keep the bare read, as `?package=` does for * them. * @@ -970,14 +972,16 @@ export function admitEnvironmentQualifier( refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); return; } - // [#32183, epic ruling R4-B2] The served holders, or every holder when no - // package serves the name: a name only disabled packages hold is refused - // naming them, as before, never read as a caller with no package (that - // read can reach a disabled holder's customization pair row). - const served = registry.packageScopedHoldersOf(request.type, request.name) ?? []; - const holders = served.length > 0 - ? served - : registry.packageScopedHoldersOf(request.type, request.name, null, { includeDisabledPackages: true }) ?? []; + // [#32183] The served holders: a disabled package holds no name. + // [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] A name only + // disabled packages hold is admitted as a name no package holds, and read + // as a caller with no package, so it answers the read's own 404 and never + // names a disabled package. R4-B2 held it at a 409 naming them because + // that read could reach a disabled holder's customization: the item face + // now withholds every such row with its holders, the customization pair's + // row (#32814) and a package-less row of the holder's key (#33401), so it + // answers as if no row were stored. + const holders = registry.packageScopedHoldersOf(request.type, request.name) ?? []; if (holders.length === 0) { refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); return; diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index 2e8f84092c8..c4e45cc86c2 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -1240,8 +1240,13 @@ describe('[#31699 F2] a pair member row two holders could own is refused on both * its namespace path and `_env` refuse 409 naming X. The round-3 head served * the pair's row at the first two and at `_env`. TO: the first two answer 404 * (row 17: an exact address of such a name serves only a row stored under - * its own package); `_env` keeps `main`'s 409 (R4-B2: with no served holder, - * its admission judges every holder). + * its own package); `_env` kept `main`'s 409 (R4-B2: with no served holder, + * its admission judged every holder). + * + * [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] `_env` moves FROM that + * 409 naming X TO 404, the withheld answer of a name no package holds: the + * read naming no package withholds the pair's row with its disabled holder + * (#32814), so `_env` no longer needs the refusal to keep the row unserved. */ describe('[#32183] a name only a disabled package holds, at an address that neither holds it nor pairs a holder', () => { const APP = 'com.acme.suite'; @@ -1293,10 +1298,12 @@ describe('[#32183] a name only a disabled package holds, at an address that neit expect(JSON.stringify(answer ?? null)).not.toContain('pair fr-FR'); }); - it('X disabled: `_env` at that member refuses 409 naming X, as on main (R4-B2)', async () => { + it('[#33385, row 17 / R4-B2: FROM 409 naming X TO 404] X disabled: `_env` at that member answers the withheld item (404), never the pair\'s row and never a refusal', async () => { registry.disablePackage(X); - const err = await refusalOf(atEnvironment); - expect([err.status, err.refusal.reason, err.refusal.candidates]).toEqual([409, 'not-held-by-qualifier', [{ kind: 'package', packageId: X }]]); + const answer = await atEnvironment(); + expect(answer?.item).toBeUndefined(); + expect(JSON.stringify(answer ?? null)).not.toContain('pair fr-FR'); + expect(JSON.stringify(answer ?? null)).not.toContain(Y); }); it('CONTROL — X disabled: a row stored under Y\'s own package is served at Y', async () => { diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index 4d8a899bd96..dc45ee85f31 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -353,20 +353,42 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t expect(labelOf(await drive(ITEM, { type, name: 'shared' }, { package: `${A}.custom` }))).toBe(`alpha ${type}`); }); - // [epic ruling R4-B2] `_env` is held at `main`'s answer: with no served - // holder it judges every holder, so it refuses naming the disabled one. - it(`${type}: only a disabled holder — no holder: 404 on every package address, never a 409 naming it; \`_env\` refuses naming it, as on main`, async () => { + // [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] FROM `_env` + // 409 naming the disabled holder (R4-B2 held it there) TO 404: a + // disabled package holds no name, so `_env` answers as for a name no + // package holds, as every package address does, naming no package. + it(`${type}: only a disabled holder — no holder: 404 on every address, \`_env\` included, never a 409 naming it; re-enabled, \`_env\` refuses naming it`, async () => { ship(type, 'solo', B); registry.disablePackage(B); for (const [path, params, query] of [ [ITEM, { type, name: 'solo' }, {}], [ITEM, { type, name: 'solo' }, { package: C }], [QUALIFIED, { type, ns: 'gamma', name: 'solo' }, {}], + [QUALIFIED, { type, ns: '_env', name: 'solo' }, {}], ] as const) { const answer = await drive(path, params, query); - expect([answer.status, params, query], JSON.stringify(answer.body)).toEqual([404, params, query]); + expect([answer.status, codeOf(answer), params, query], JSON.stringify(answer.body)).toEqual([404, 'RESOURCE_NOT_FOUND', params, query]); expect(JSON.stringify(answer.body ?? null)).not.toContain(B); } + // CONTROL — the holder enabled: `_env` refuses naming it, unchanged. + registry.enablePackage(B); + refusedNaming(await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }), [B], [A]); + }); + + // [#33401, #33385] A package-less row of the disabled holder's key is + // its customization (seat ruling 6882483833 on #32814): `_env` and the + // bare read answer as if no row were stored, never the row. + it(`${type}: only a disabled holder, and a package-less row of its name — \`_env\`, the bare read and its layers answer 404, never the row; re-enabled, \`_env\` refuses naming it`, async () => { + ship(type, 'solo', B); + registry.registerItem(type, { name: 'solo', label: `custom ${type}`, _provenance: 'org' }, 'name' as never); + registry.disablePackage(B); + for (const [path, params] of [[ITEM, { type, name: 'solo' }], [LAYERS, { type, name: 'solo' }], [QUALIFIED, { type, ns: '_env', name: 'solo' }]] as const) { + const answer = await drive(path, params); + expect([answer.status, codeOf(answer), params], JSON.stringify(answer.body)).toEqual([404, 'RESOURCE_NOT_FOUND', params]); + expect(JSON.stringify(answer.body ?? null)).not.toContain(`custom ${type}`); + expect(JSON.stringify(answer.body ?? null)).not.toContain(B); + } + registry.enablePackage(B); refusedNaming(await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }), [B], [A]); }); diff --git a/packages/rest/src/meta-qualified-item-route.ts b/packages/rest/src/meta-qualified-item-route.ts index 01caad5b42d..afe946d7ffa 100644 --- a/packages/rest/src/meta-qualified-item-route.ts +++ b/packages/rest/src/meta-qualified-item-route.ts @@ -13,8 +13,9 @@ * the exact qualifier the protocol judges (`admitExactQualifier`): the * package's item with its bound overlay, or `409 RESOURCE_CONFLICT` naming * every holder; - * - `_env`: the environment's own item, or `409` naming every holder - * (`admitEnvironmentQualifier`), read as a caller with no package. + * - `_env`: the environment's own item, or `409` naming every served + * holder (`admitEnvironmentQualifier`), read as a caller with no package; + * a name only disabled packages hold answers that read's `404` (#33385). * * D5's order, as the runtime dispatcher's `/meta` domain reads the same path: * a sub-resource literal in the last position keeps its route — registered diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index 84b08a64d5a..5787c2e17e7 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -403,20 +403,42 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t expect(labelOf(await read(`/${type}/shared`, { package: `${A}.custom` }))).toBe(`alpha ${type}`); }); - // [epic ruling R4-B2] `_env` is held at `main`'s answer: with no served - // holder it judges every holder, so it refuses naming the disabled one. - it(`${type}: only a disabled holder — no holder: 404 on every package address, never a 409 naming it; \`_env\` refuses naming it, as on main`, async () => { + // [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] FROM `_env` + // 409 naming the disabled holder (R4-B2 held it there) TO 404: a + // disabled package holds no name, so `_env` answers as for a name no + // package holds, as every package address does, naming no package. + it(`${type}: only a disabled holder — no holder: 404 on every address, \`_env\` included, never a 409 naming it; re-enabled, \`_env\` refuses naming it`, async () => { ship(type, 'solo', B); registry.disablePackage(B); for (const [path, query] of [ [`/${type}/solo`, undefined], [`/${type}/solo`, { package: C }], [`/${type}/gamma/solo`, undefined], + [`/${type}/_env/solo`, undefined], ] as const) { const answer = await read(path, query); - expect([answer.status, path, query], JSON.stringify(answer.body)).toEqual([404, path, query]); + expect([answer.status, answer.body?.error?.code, path, query], JSON.stringify(answer.body)).toEqual([404, 'RESOURCE_NOT_FOUND', path, query]); expect(JSON.stringify(answer.body)).not.toContain(B); } + // CONTROL — the holder enabled: `_env` refuses naming it, unchanged. + registry.enablePackage(B); + refusedNaming(await read(`/${type}/_env/solo`), [B], [A]); + }); + + // [#33401, #33385] A package-less row of the disabled holder's key is + // its customization (seat ruling 6882483833 on #32814): `_env` and the + // bare read answer as if no row were stored, never the row. + it(`${type}: only a disabled holder, and a package-less row of its name — \`_env\`, the bare read and its layers answer 404, never the row; re-enabled, \`_env\` refuses naming it`, async () => { + ship(type, 'solo', B); + registry.registerItem(type, { name: 'solo', label: `custom ${type}`, _provenance: 'org' }, 'name' as never); + registry.disablePackage(B); + for (const path of [`/${type}/solo`, `/${type}/solo/layers`, `/${type}/_env/solo`]) { + const answer = await read(path); + expect([answer.status, answer.body?.error?.code, path], JSON.stringify(answer.body)).toEqual([404, 'RESOURCE_NOT_FOUND', path]); + expect(JSON.stringify(answer.body ?? null)).not.toContain(`custom ${type}`); + expect(JSON.stringify(answer.body ?? null)).not.toContain(B); + } + registry.enablePackage(B); refusedNaming(await read(`/${type}/_env/solo`), [B], [A]); }); diff --git a/packages/runtime/src/domains/meta.ts b/packages/runtime/src/domains/meta.ts index d7fd0cfbf51..8829fd113c0 100644 --- a/packages/runtime/src/domains/meta.ts +++ b/packages/runtime/src/domains/meta.ts @@ -2143,9 +2143,10 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin try { // [ADR-0150 D5, child G1] `/meta/:type/_env/:name`: the - // environment's own item, or `409` naming every holder — judged - // here, after the gates above, then read as a caller with no - // package (the resolver answers that caller environment-first). + // environment's own item, or `409` naming every served holder — + // judged here, after the gates above, then read as a caller with + // no package (the resolver answers that caller environment-first; + // a name only disabled packages hold answers its 404, #33385). if (environmentQualified) { const qualifierProtocol = await resolveProtocol(deps, _context); qualifierProtocol?.admitEnvironmentQualifier?.({ type: singularType, name, ...memberSelector }); From 0097f7f4dc48ed0c1b29f0f7ade788afd9ce9113 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 11:42:12 +0000 Subject: [PATCH 03/18] test(objectql): the hydrated package-less row is a moved cell, not a control Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/package-scoped-exact-qualifier.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index c4e45cc86c2..4cbf95a2113 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -2734,10 +2734,10 @@ describe('[#32814] the read naming no package withholds a pair row of a name onl * answers as if no row were stored; the row is kept and served on re-enable. * * FROM (`main` 1e65a389, measured on this fixture and on the REST door): the - * row (200), on the served and the execution face, in every order below. A - * row the holder's own member overlays, and the same row once hydrated into - * the registry, were already withheld (CONTROLs below). TO: the holder's - * withheld item, the answer with no row stored. + * row (200), on the served and the execution face, in every order below, + * stored or hydrated. A row the holder's own member overlays was already + * withheld (CONTROL below). TO: the holder's withheld item, the answer with + * no row stored. */ describe('[#33401] the read naming no package withholds a package-less row of a key only disabled packages hold', () => { const custom = (name: string, locale: string) => rows.push({ @@ -2829,7 +2829,7 @@ describe('[#33401] the read naming no package withholds a package-less row of a expect(JSON.stringify(answer ?? null)).not.toContain('custom en-US'); }); - it('CONTROL — the fr-FR row hydrated into the registry: withheld, as on BASE', async () => { + it('the fr-FR row stored and hydrated into the registry: withheld too (BASE: the row)', async () => { tpl(A); custom('welcome', 'fr-FR'); await hydrate(); From 71880ceb857acbf221f11b8bcb5978f52f3e7277 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 11:54:53 +0000 Subject: [PATCH 04/18] chore(changeset): metadata-protocol patch for the disabled-holder `_env` and package-less row reads Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .changeset/33385-disabled-holders-env-404.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/33385-disabled-holders-env-404.md diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md new file mode 100644 index 00000000000..35a7aebb45d --- /dev/null +++ b/.changeset/33385-disabled-holders-env-404.md @@ -0,0 +1,12 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol): a name only disabled packages hold answers 404 at `_env`, and an environment customization of such a name is hidden until a holder is enabled again + +Clause-②: no +Metadata-protocol: none + +**`GET /meta/:type/_env/:name`.** When every package that holds the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` and name the disabled packages. With an enabled holder it still refuses `409` naming that holder, and the environment's own item is still served. + +**The read that names no package (`GET /meta/:type/:name`, and the execution read).** An environment-level customization saved without a package for a name an installed package holds belongs to that package. When every package holding the name is disabled, the read now answers as if the customization were not saved. This also covers a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. Before, the read served that customization while the package was disabled. Nothing is deleted. Enable the package again and the customization is served again, unchanged. A customization of a name no installed package holds is the environment's own item and is served as before. From 4fe4ea47a79e7332783d64f69f0c431516d1b2ba Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 13:09:41 +0000 Subject: [PATCH 05/18] fix(metadata-protocol,rest,runtime): `_env` keeps the refusal when a package holds the name through a stored row The protocol's `_env` admission cannot read stored rows, so a name only disabled packages hold in the registry is still refused, now marked. Each `_env` door admits that marked refusal only when the read naming no package withholds the name, and answers its 404; when that read serves an item, an enabled package holds the name through its stored row and the 409 stands. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/protocol-exact-qualifier.ts | 54 ++++++++++++++----- .../package-scoped-exact-qualifier.test.ts | 27 ++++++---- .../src/meta-qualified-item-route.test.ts | 37 ++++++++++++- .../rest/src/meta-qualified-item-route.ts | 39 +++++++++++++- .../domains/meta-qualified-item-read.test.ts | 37 ++++++++++++- packages/runtime/src/domains/meta.ts | 39 +++++++++++++- 6 files changed, 205 insertions(+), 28 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-exact-qualifier.ts b/packages/metadata-protocol/src/protocol-exact-qualifier.ts index dccc96f360d..6cdec6f37dd 100644 --- a/packages/metadata-protocol/src/protocol-exact-qualifier.ts +++ b/packages/metadata-protocol/src/protocol-exact-qualifier.ts @@ -946,8 +946,8 @@ export function resolveMetaItemAddress( * environment does not hold and a package does is refused * (`not-held-by-qualifier`, `callerPackageId: null`); otherwise the read is a * caller with no package, which E8's resolver answers environment-first. - * [#33385] A disabled package holds no name here either: a name only - * disabled packages hold is admitted, and the item face answers its 404. + * [#33385] A name only disabled packages hold is refused with a mark the + * doors read ({@link DISABLED_HOLDERS_ONLY_REFUSAL}). * Types outside the covered set keep the bare read, as `?package=` does for * them. * @@ -972,20 +972,25 @@ export function admitEnvironmentQualifier( refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); return; } - // [#32183] The served holders: a disabled package holds no name. - // [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] A name only - // disabled packages hold is admitted as a name no package holds, and read - // as a caller with no package, so it answers the read's own 404 and never - // names a disabled package. R4-B2 held it at a 409 naming them because - // that read could reach a disabled holder's customization: the item face - // now withholds every such row with its holders, the customization pair's - // row (#32814) and a package-less row of the holder's key (#33401), so it - // answers as if no row were stored. - const holders = registry.packageScopedHoldersOf(request.type, request.name) ?? []; + // [#32183, epic ruling R4-B2] The served holders, or every holder when no + // package serves the name: a name only disabled packages hold is refused + // naming them here, never admitted on the registry's word alone. The + // registry does not see a package holding the name only through a stored + // row it has not hydrated, so a read admitted here could serve that + // package's row at the environment's address. + const served = registry.packageScopedHoldersOf(request.type, request.name) ?? []; + const holders = served.length > 0 + ? served + : registry.packageScopedHoldersOf(request.type, request.name, null, { includeDisabledPackages: true }) ?? []; if (holders.length === 0) { refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); return; } + // [#33385, #32183 row 17] …but marked ({@link DISABLED_HOLDERS_ONLY_REFUSAL}), + // once the read it would admit is judgeable: each door then asks the read + // naming no package, which judges the stored rows too, and answers the + // name as no package's (its 404) when that read withholds it. + if (served.length === 0) refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); const candidates: PackageScopedHolder[] = holders.map((holder) => ({ kind: 'package' as const, packageId: holder })); const base = { status: 'refused' as const, @@ -995,5 +1000,28 @@ export function admitEnvironmentQualifier( callerPackageId: null, candidates, }; - throw new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }); + const error = new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }); + if (served.length === 0) Object.defineProperty(error, DISABLED_HOLDERS_ONLY_REFUSAL, { value: true }); + throw error; } + +/** + * [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] The marker + * {@link admitEnvironmentQualifier} sets on its refusal of a name only + * disabled packages hold, a registered symbol (so every copy of this package + * reads the same key, and no envelope serializes it). The `_env` doors of + * `RestServer` and the runtime dispatcher read it by the same `Symbol.for` + * key (`RestServer` reaches the protocol only as a service, as with the item + * face's `storedRowHoldersRefusal` marker), and answer it in two steps, + * because only an asynchronous read sees a package that holds the name + * through a stored row alone: + * + * - the read naming no package (`getMetaItem`) withholds the name (no item): + * no package serves it, a disabled package holds no name, and the item face + * withholds every customization of its holders (the pair's row, #32814; a + * package-less row of their key, #33401). The door admits `_env` and its + * read answers 404, naming no package; + * - that read serves an item, or refuses: a package holds the name through + * its stored row, so the refusal stands, as before. + */ +const DISABLED_HOLDERS_ONLY_REFUSAL: unique symbol = Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal') as never; diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index 4cbf95a2113..442d595cc4e 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -1243,10 +1243,12 @@ describe('[#31699 F2] a pair member row two holders could own is refused on both * its own package); `_env` kept `main`'s 409 (R4-B2: with no served holder, * its admission judged every holder). * - * [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] `_env` moves FROM that - * 409 naming X TO 404, the withheld answer of a name no package holds: the - * read naming no package withholds the pair's row with its disabled holder - * (#32814), so `_env` no longer needs the refusal to keep the row unserved. + * [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] At each door `_env` + * moves FROM that 409 naming X TO 404: the protocol's refusal is marked as a + * name only disabled packages hold, and the doors admit it when the read + * naming no package withholds the name, which it does here (the pair's row is + * withheld with its disabled holder, #32814). The REST and runtime pins of + * the 404 live with those doors. */ describe('[#32183] a name only a disabled package holds, at an address that neither holds it nor pairs a holder', () => { const APP = 'com.acme.suite'; @@ -1298,12 +1300,19 @@ describe('[#32183] a name only a disabled package holds, at an address that neit expect(JSON.stringify(answer ?? null)).not.toContain('pair fr-FR'); }); - it('[#33385, row 17 / R4-B2: FROM 409 naming X TO 404] X disabled: `_env` at that member answers the withheld item (404), never the pair\'s row and never a refusal', async () => { + it('[#33385, row 17 / R4-B2] X disabled: `_env` at that member refuses naming X, MARKED as a name only disabled packages hold, and the read naming no package withholds it, so each door answers 404', async () => { registry.disablePackage(X); - const answer = await atEnvironment(); - expect(answer?.item).toBeUndefined(); - expect(JSON.stringify(answer ?? null)).not.toContain('pair fr-FR'); - expect(JSON.stringify(answer ?? null)).not.toContain(Y); + const err = await refusalOf(() => served.admitEnvironmentQualifier({ type: 'email_template', name: 'welcome', member: 'fr-FR' })); + expect([err.status, err.refusal.reason, err.refusal.candidates]).toEqual([409, 'not-held-by-qualifier', [{ kind: 'package', packageId: X }]]); + expect((err as unknown as Record)[Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal')]).toBe(true); + const bare = await served.getMetaItem({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never); + expect(bare?.item).toBeUndefined(); + expect(JSON.stringify(bare ?? null)).not.toContain('pair fr-FR'); + }); + + it('CONTROL — X enabled: `_env` refuses naming X, unmarked', async () => { + const err = await refusalOf(() => served.admitEnvironmentQualifier({ type: 'email_template', name: 'welcome', member: 'fr-FR' })); + expect((err as unknown as Record)[Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal')]).toBeUndefined(); }); it('CONTROL — X disabled: a row stored under Y\'s own package is served at Y', async () => { diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index dc45ee85f31..f22a3d7f6c4 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -70,15 +70,29 @@ const codeOf = (answer: { body?: any }) => answer.body?.code ?? answer.body?.err const messageOf = (answer: { body?: any }) => String(answer.body?.error?.message ?? answer.body?.error ?? ''); const labelOf = (answer: { body?: any }) => answer.body?.item?.label ?? answer.body?.data?.item?.label; +/** [#33385] The stored `sys_metadata` rows the engine double answers; empty unless a pin stores one. */ +let storedRows: Array> = []; +const storedRowsMatching = (where: Record | undefined) => storedRows.filter((row) => + Object.entries(where ?? {}).every(([key, value]) => { + if (value !== null && typeof value === 'object') { + const inList = (value as { $in?: unknown }).$in; + if (!Array.isArray(inList)) throw new Error(`engine double: operator ${Object.keys(value).join(', ')} is not implemented`); + return inList.includes(row[key]); + } + return (row[key] ?? null) === value; + })); + beforeEach(() => { + storedRows = []; registry = new SchemaRegistry({ multiTenant: false }); for (const id of [A, B, C]) { registry.installPackage({ id, name: id, version: '1.0.0', type: 'app', namespace: id.split('.').pop()! } as never, 'code'); } const engine = { registry, - find: vi.fn().mockResolvedValue([]), - findOne: vi.fn().mockResolvedValue(null), + // [#33385] Stored `sys_metadata` rows: equality on each `where` key, nothing else. + find: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)), + findOne: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)[0] ?? null), insert: vi.fn(), update: vi.fn(), delete: vi.fn(), @@ -392,6 +406,25 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t refusedNaming(await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }), [B], [A]); }); + // [#33385] CONTROL — an enabled package holding the name only through a + // stored row the registry has not read: `_env` keeps `main`'s 409, as + // its refusal stands whenever the read naming no package serves an item. + it(`${type}: only a disabled holder in the registry, and an enabled package's unhydrated stored row — \`_env\` refuses 409, as on main, never that row`, async () => { + ship(type, 'solo', B); + storedRows.push({ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, + metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }); + registry.disablePackage(B); + const bare = await drive(ITEM, { type, name: 'solo' }); + const env = await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }); + expect(JSON.stringify(env.body ?? null)).not.toContain(`gamma row ${type}`); + if (labelOf(bare) === `gamma row ${type}`) { + expect([env.status, codeOf(env)], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT']); + } else { + expect([bare.status, env.status], JSON.stringify([bare.body, env.body])).toEqual([404, 404]); + } + console.info(`#33385-row-holder ${type} bare=${bare.status} env=${env.status}`); + }); + it(`${type}: only disabled holders — the layered view serves none of their layers, at any address`, async () => { admitSecondPermissionHolder(type); ship(type, 'solo', B); diff --git a/packages/rest/src/meta-qualified-item-route.ts b/packages/rest/src/meta-qualified-item-route.ts index afe946d7ffa..2135ff57d80 100644 --- a/packages/rest/src/meta-qualified-item-route.ts +++ b/packages/rest/src/meta-qualified-item-route.ts @@ -55,6 +55,43 @@ type MetaItemAddress = interface QualifiedAddressProtocol { resolveMetaItemAddress?(request: { type: string; segment: string; name: string }): MetaItemAddress | undefined; admitEnvironmentQualifier?(request: { type: string; name: string; member?: string }): void; + getMetaItem?(request: { type: string; name: string; member?: string }): Promise<{ item?: unknown } | undefined>; +} + +/** + * [#33385, #32183 row 17] The `Symbol.for` key of the mark + * `admitEnvironmentQualifier` sets on its refusal of a name only disabled + * packages hold (`DISABLED_HOLDERS_ONLY_REFUSAL` in + * `@objectstack/metadata-protocol`; this package reaches the protocol as a + * service, never as an import). The runtime dispatcher reads the same key. + */ +const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal'); + +/** + * Admit `_env` for `request`, or throw the protocol's refusal. A refusal + * marked {@link DISABLED_HOLDERS_ONLY_REFUSAL} is admitted when the read + * naming no package withholds the name: a disabled package holds no name, + * so `_env` answers the read's own 404, naming no package. When that read + * serves an item or refuses, a package holds the name through a stored row + * the registry has not read, and the refusal stands. + */ +async function admitEnvironmentAddress( + p: QualifiedAddressProtocol, + request: { type: string; name: string; member?: string }, +): Promise { + try { + p.admitEnvironmentQualifier?.(request); + } catch (refusal) { + if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true + || typeof p.getMetaItem !== 'function') throw refusal; + let withheld: boolean; + try { + withheld = (await p.getMetaItem(request))?.item == null; + } catch { + throw refusal; + } + if (!withheld) throw refusal; + } } /** What the host answered this path before the route existed: its unmatched 404. */ @@ -112,7 +149,7 @@ export function registerMetaQualifiedItemRoute( query.package = address.packageId; } else { const member = typeof query.member === 'string' && query.member !== '' ? query.member : undefined; - p.admitEnvironmentQualifier?.({ type: params.type, name: params.name, ...(member ? { member } : {}) }); + await admitEnvironmentAddress(p, { type: params.type, name: params.name, ...(member ? { member } : {}) }); } await readItem(asItemRead(req, params, query), res); } catch (error: any) { diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index 5787c2e17e7..a6a0ea4143a 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -55,15 +55,29 @@ const read = async (path: string, query?: Record, context: any }; const labelOf = (answer: { body?: any }) => answer.body?.data?.item?.label ?? answer.body?.item?.label; +/** [#33385] The stored `sys_metadata` rows the engine double answers; empty unless a pin stores one. */ +let storedRows: Array> = []; +const storedRowsMatching = (where: Record | undefined) => storedRows.filter((row) => + Object.entries(where ?? {}).every(([key, value]) => { + if (value !== null && typeof value === 'object') { + const inList = (value as { $in?: unknown }).$in; + if (!Array.isArray(inList)) throw new Error(`engine double: operator ${Object.keys(value).join(', ')} is not implemented`); + return inList.includes(row[key]); + } + return (row[key] ?? null) === value; + })); + beforeEach(() => { + storedRows = []; registry = new SchemaRegistry({ multiTenant: false }); for (const id of [A, B, C]) { registry.installPackage({ id, name: id, version: '1.0.0', type: 'app', namespace: id.split('.').pop()! } as never, 'code'); } const engine = { registry, - find: vi.fn().mockResolvedValue([]), - findOne: vi.fn().mockResolvedValue(null), + // [#33385] Stored `sys_metadata` rows: equality on each `where` key, nothing else. + find: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)), + findOne: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)[0] ?? null), insert: vi.fn(), update: vi.fn(), delete: vi.fn(), @@ -442,6 +456,25 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t refusedNaming(await read(`/${type}/_env/solo`), [B], [A]); }); + // [#33385] CONTROL — an enabled package holding the name only through a + // stored row the registry has not read: `_env` keeps `main`'s 409, as + // its refusal stands whenever the read naming no package serves an item. + it(`${type}: only a disabled holder in the registry, and an enabled package's unhydrated stored row — \`_env\` refuses 409, as on main, never that row`, async () => { + ship(type, 'solo', B); + storedRows.push({ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, + metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }); + registry.disablePackage(B); + const bare = await read(`/${type}/solo`); + const env = await read(`/${type}/_env/solo`); + expect(JSON.stringify(env.body ?? null)).not.toContain(`gamma row ${type}`); + if (labelOf(bare) === `gamma row ${type}`) { + expect([env.status, env.body?.error?.code], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT']); + } else { + expect([bare.status, env.status], JSON.stringify([bare.body, env.body])).toEqual([404, 404]); + } + console.info(`#33385-row-holder ${type} bare=${bare.status} env=${env.status}`); + }); + it(`${type}: only disabled holders — the layered view serves none of their layers, at any address`, async () => { admitSecondPermissionHolder(type); ship(type, 'solo', B); diff --git a/packages/runtime/src/domains/meta.ts b/packages/runtime/src/domains/meta.ts index 8829fd113c0..d26cd7e93a7 100644 --- a/packages/runtime/src/domains/meta.ts +++ b/packages/runtime/src/domains/meta.ts @@ -1124,6 +1124,43 @@ function queryRefusalAnswer( return { handled: true, response: deps.error(refusal.message, refusal.status, { code: refusal.code }) }; } +/** + * [#33385, #32183 row 17] The `Symbol.for` key of the mark + * `admitEnvironmentQualifier` sets on its refusal of a name only disabled + * packages hold (`DISABLED_HOLDERS_ONLY_REFUSAL` in + * `@objectstack/metadata-protocol`). `RestServer`'s qualified route reads the + * same key. + */ +const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal'); + +/** + * [#33385] Admit `/meta/:type/_env/:name` for `request`, or throw the + * protocol's refusal, as `RestServer`'s qualified route admits it. A refusal + * marked {@link DISABLED_HOLDERS_ONLY_REFUSAL} is admitted when the read naming + * no package withholds the name: a disabled package holds no name, so `_env` + * answers the read's own 404, naming no package. When that read serves an + * item or refuses, a package holds the name through a stored row the + * registry has not read, and the refusal stands. + */ +async function admitEnvironmentAddress( + protocol: MetaDomainProtocol | undefined, + request: { type: string; name: string; member?: string }, +): Promise { + try { + protocol?.admitEnvironmentQualifier?.(request); + } catch (refusal) { + if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true + || typeof protocol?.getMetaItem !== 'function') throw refusal; + let withheld: boolean; + try { + withheld = ((await protocol.getMetaItem(request as never)) as { item?: unknown } | undefined)?.item == null; + } catch { + throw refusal; + } + if (!withheld) throw refusal; + } +} + /** * Handles Metadata requests * Standard: /metadata/:type/:name @@ -2149,7 +2186,7 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin // a name only disabled packages hold answers its 404, #33385). if (environmentQualified) { const qualifierProtocol = await resolveProtocol(deps, _context); - qualifierProtocol?.admitEnvironmentQualifier?.({ type: singularType, name, ...memberSelector }); + await admitEnvironmentAddress(qualifierProtocol, { type: singularType, name, ...memberSelector }); } // [#5882 · #20478] The DEPRECATED spelling of the layered view, From b21cdf110ff141289b99dc6d617c9cc244486881 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 13:15:03 +0000 Subject: [PATCH 06/18] test(rest,runtime): name the types whose by-name read serves the row-holder CONTROL's stored row Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- packages/rest/src/meta-qualified-item-route.test.ts | 10 ++++++++-- .../src/domains/meta-qualified-item-read.test.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index f22a3d7f6c4..2eaf697161b 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -317,6 +317,8 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t for (const id of unnamed) expect(JSON.stringify(answer.body)).not.toContain(id); }; + /** [#33385] The types whose by-name read serves the minimal stored row of the row-holder CONTROL below. */ + const ROW_SERVED_TYPES: readonly string[] = ['dashboard', 'email_template', 'permission', 'report']; for (const type of PACKAGE_SCOPED_READ_TYPES) { // [contract review M1, S2] Both registration orders: a reader that takes // the first registered holder serves the disabled one's body when it @@ -417,12 +419,16 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t const bare = await drive(ITEM, { type, name: 'solo' }); const env = await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }); expect(JSON.stringify(env.body ?? null)).not.toContain(`gamma row ${type}`); - if (labelOf(bare) === `gamma row ${type}`) { + // Measured on this fixture: these four types' by-name read serves + // the minimal stored row; the others serve no row of this shape, and + // `_env` answers as that read does (404). Named, so the 409 leg can + // never pass vacuously. + expect(labelOf(bare) === `gamma row ${type}`, JSON.stringify(bare.body)).toBe(ROW_SERVED_TYPES.includes(type)); + if (ROW_SERVED_TYPES.includes(type)) { expect([env.status, codeOf(env)], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT']); } else { expect([bare.status, env.status], JSON.stringify([bare.body, env.body])).toEqual([404, 404]); } - console.info(`#33385-row-holder ${type} bare=${bare.status} env=${env.status}`); }); it(`${type}: only disabled holders — the layered view serves none of their layers, at any address`, async () => { diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index a6a0ea4143a..810560d15c8 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -367,6 +367,8 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t for (const id of unnamed) expect(JSON.stringify(answer.body)).not.toContain(id); }; + /** [#33385] The types whose by-name read serves the minimal stored row of the row-holder CONTROL below. */ + const ROW_SERVED_TYPES: readonly string[] = ['dashboard', 'email_template', 'permission', 'report']; for (const type of PACKAGE_SCOPED_READ_TYPES) { // [contract review M1, S2] Both registration orders: a reader that takes // the first registered holder serves the disabled one's body when it @@ -467,12 +469,16 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t const bare = await read(`/${type}/solo`); const env = await read(`/${type}/_env/solo`); expect(JSON.stringify(env.body ?? null)).not.toContain(`gamma row ${type}`); - if (labelOf(bare) === `gamma row ${type}`) { + // Measured on this fixture: these four types' by-name read serves + // the minimal stored row; the others serve no row of this shape, and + // `_env` answers as that read does (404). Named, so the 409 leg can + // never pass vacuously. + expect(labelOf(bare) === `gamma row ${type}`, JSON.stringify(bare.body)).toBe(ROW_SERVED_TYPES.includes(type)); + if (ROW_SERVED_TYPES.includes(type)) { expect([env.status, env.body?.error?.code], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT']); } else { expect([bare.status, env.status], JSON.stringify([bare.body, env.body])).toEqual([404, 404]); } - console.info(`#33385-row-holder ${type} bare=${bare.status} env=${env.status}`); }); it(`${type}: only disabled holders — the layered view serves none of their layers, at any address`, async () => { From 6665c856b6f21b56813bb1250d9f76fface1d934 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 13:18:14 +0000 Subject: [PATCH 07/18] chore(changeset): rest and runtime patch for the `_env` admission Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .changeset/33385-disabled-holders-env-404.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md index 35a7aebb45d..7f2f2fb1e12 100644 --- a/.changeset/33385-disabled-holders-env-404.md +++ b/.changeset/33385-disabled-holders-env-404.md @@ -1,5 +1,7 @@ --- '@objectstack/metadata-protocol': patch +'@objectstack/rest': patch +'@objectstack/runtime': patch --- fix(metadata-protocol): a name only disabled packages hold answers 404 at `_env`, and an environment customization of such a name is hidden until a holder is enabled again @@ -7,6 +9,6 @@ fix(metadata-protocol): a name only disabled packages hold answers 404 at `_env` Clause-②: no Metadata-protocol: none -**`GET /meta/:type/_env/:name`.** When every package that holds the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` and name the disabled packages. With an enabled holder it still refuses `409` naming that holder, and the environment's own item is still served. +**`GET /meta/:type/_env/:name`.** When every package that holds the name is disabled, the environment address now answers `404` on both the REST server and the runtime dispatcher, as for a name no package holds. It used to refuse `409 RESOURCE_CONFLICT` and name the disabled packages. It still refuses `409` in two cases: an enabled package holds the name, or a package holds it only through a saved metadata row that the read of the name serves. The environment's own item is still served. -**The read that names no package (`GET /meta/:type/:name`, and the execution read).** An environment-level customization saved without a package for a name an installed package holds belongs to that package. When every package holding the name is disabled, the read now answers as if the customization were not saved. This also covers a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. Before, the read served that customization while the package was disabled. Nothing is deleted. Enable the package again and the customization is served again, unchanged. A customization of a name no installed package holds is the environment's own item and is served as before. +**The read that names no package (`GET /meta/:type/:name`, and the execution read).** An environment-level customization saved without a package, for a name an installed package holds, belongs to that package. When every package holding the name is disabled, the read now answers as if the customization were not saved. That includes a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. Before, the read served that customization while the package was disabled. Nothing is deleted: enable the package again and the customization is served again, unchanged. A customization of a name no installed package holds is the environment's own item and is still served. From b5ea0f63d037cf820af209b021702c0dbed68da6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 13:53:59 +0000 Subject: [PATCH 08/18] chore(changeset): declare the withhold as a narrowing with its BREAKING banner and ADR-0087 disposition Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .changeset/33385-disabled-holders-env-404.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md index 7f2f2fb1e12..3c8761e1d9a 100644 --- a/.changeset/33385-disabled-holders-env-404.md +++ b/.changeset/33385-disabled-holders-env-404.md @@ -4,11 +4,18 @@ '@objectstack/runtime': patch --- -fix(metadata-protocol): a name only disabled packages hold answers 404 at `_env`, and an environment customization of such a name is hidden until a holder is enabled again +fix(metadata-protocol,rest,runtime)!: a name only disabled packages hold answers 404 at `_env`, and an environment customization of such a name is hidden until a holder is enabled again (ADR-0150 D3, D4) -Clause-②: no +Clause-②: yes (narrowing) Metadata-protocol: none -**`GET /meta/:type/_env/:name`.** When every package that holds the name is disabled, the environment address now answers `404` on both the REST server and the runtime dispatcher, as for a name no package holds. It used to refuse `409 RESOURCE_CONFLICT` and name the disabled packages. It still refuses `409` in two cases: an enabled package holds the name, or a package holds it only through a saved metadata row that the read of the name serves. The environment's own item is still served. + -**The read that names no package (`GET /meta/:type/:name`, and the execution read).** An environment-level customization saved without a package, for a name an installed package holds, belongs to that package. When every package holding the name is disabled, the read now answers as if the customization were not saved. That includes a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. Before, the read served that customization while the package was disabled. Nothing is deleted: enable the package again and the customization is served again, unchanged. A customization of a name no installed package holds is the environment's own item and is still served. +**BREAKING** for a read of an environment customization of a name whose every holding package is disabled. Such a customization is a row saved without a package, for a name an installed package holds. It belongs to that package (ADR-0150 D4), and a disabled package holds no name (ADR-0150 D3). + +- **The read that names no package (`GET /meta/:type/:name`, and the execution read).** When every package holding the name is disabled, this read now answers as if the customization were not saved: `404`, where it served the row. That includes a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. A customization at a member the package ships was already hidden. +- **`GET /meta/:type/_env/:name`.** When every package holding the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` naming the disabled packages. It still refuses `409` in two cases: an enabled package holds the name, or a package holds it through a saved metadata row that the read of the name serves. + +**Not moved.** With an enabled holder, every answer is unchanged. A customization of a name no installed package holds is the environment's own item and is still served. + +**No migration.** Nothing is deleted or rewritten. Enable the package again and the customization is served again, unchanged. The fix for a caller who needs the row while the package is disabled is to re-enable the package. From 00d7daf563dbe22bf9241f0383fbb6a596e619cb Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 14:30:50 +0000 Subject: [PATCH 09/18] test(rest,runtime): the qualified-read engine doubles keep findOne as on main The stored-row double answers `find` only, which is what the bare read uses for the row-holder CONTROL; `findOne` returns to main's null, so the doubles declare no findOne body the engine-double contract has to pin. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- packages/rest/src/meta-qualified-item-route.test.ts | 4 ++-- packages/runtime/src/domains/meta-qualified-item-read.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index 2eaf697161b..e2e968c2a85 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -90,9 +90,9 @@ beforeEach(() => { } const engine = { registry, - // [#33385] Stored `sys_metadata` rows: equality on each `where` key, nothing else. + // [#33385] Stored `sys_metadata` rows for `find`: equality on each `where` key, nothing else. find: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)), - findOne: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)[0] ?? null), + findOne: vi.fn().mockResolvedValue(null), insert: vi.fn(), update: vi.fn(), delete: vi.fn(), diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index 810560d15c8..4f4e7be4742 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -75,9 +75,9 @@ beforeEach(() => { } const engine = { registry, - // [#33385] Stored `sys_metadata` rows: equality on each `where` key, nothing else. + // [#33385] Stored `sys_metadata` rows for `find`: equality on each `where` key, nothing else. find: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)), - findOne: vi.fn(async (_object: string, opts?: { where?: Record }) => storedRowsMatching(opts?.where)[0] ?? null), + findOne: vi.fn().mockResolvedValue(null), insert: vi.fn(), update: vi.fn(), delete: vi.fn(), From 4c28847889579aa505b2d0b9d5a4e032da042307 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 15:35:31 +0000 Subject: [PATCH 10/18] chore(changeset): declare the direction arm as no (narrowing) The diff narrows (a served customization now answers 404) and widens nothing: the `_env` move replaces one refusal with another. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .changeset/33385-disabled-holders-env-404.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md index 3c8761e1d9a..890ad390797 100644 --- a/.changeset/33385-disabled-holders-env-404.md +++ b/.changeset/33385-disabled-holders-env-404.md @@ -6,7 +6,7 @@ fix(metadata-protocol,rest,runtime)!: a name only disabled packages hold answers 404 at `_env`, and an environment customization of such a name is hidden until a holder is enabled again (ADR-0150 D3, D4) -Clause-②: yes (narrowing) +Clause-②: no (narrowing) Metadata-protocol: none From e5bf5bba335621101d6bafc4e6ae488fdf40af3d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:05:29 +0000 Subject: [PATCH 11/18] fix(rest,runtime): `_env` admits a marked refusal only for the read that judged the name A draft read (`?state=draft`, `?preview=draft`) or the deprecated layered view (`?layers=`) reads other rows than the plain read the door judges with, so for it the refusal of a name only disabled packages hold stands, as on main. Read off the raw query, so the answer depends neither on the caller's draft admission nor on whether a draft exists. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/meta-qualified-item-route.test.ts | 23 +++++++++++++++++++ .../rest/src/meta-qualified-item-route.ts | 22 +++++++++++++++++- .../domains/meta-qualified-item-read.test.ts | 23 +++++++++++++++++++ packages/runtime/src/domains/meta.ts | 11 ++++++++- 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index e2e968c2a85..32524bdc0c6 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -431,6 +431,29 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t } }); + // [#33385, review S1] CONTROL — the door judges the read it admits. A + // draft read (`?state=draft`, `?preview=draft`) and the deprecated + // layered view (`?layers=`) are not the read naming no package that + // judged the name, so a marked refusal stands for them: `main`'s 409, + // never an enabled package's draft or stored row at `_env`. + it(`${type}: only a disabled holder in the registry — \`_env\` with a draft or layered switch refuses 409, as on main, never an enabled package's draft or row`, async () => { + const refusedAtEnv = async (query: Record) => { + const env = await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }, query); + expect([env.status, codeOf(env), query], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT', query]); + for (const label of [`gamma draft ${type}`, `gamma row ${type}`]) expect(JSON.stringify(env.body ?? null)).not.toContain(label); + }; + ship(type, 'solo', B); + registry.disablePackage(B); + // An enabled package's draft row, and no active row of the name. + storedRows.push({ id: 'draft_gamma', type, name: 'solo', state: 'draft', package_id: C, + metadata: JSON.stringify({ name: 'solo', label: `gamma draft ${type}` }) }); + for (const query of [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]) await refusedAtEnv(query); + // An enabled package's unhydrated active row: the layered view. + storedRows = [{ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, + metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }]; + await refusedAtEnv({ layers: 'true' }); + }); + it(`${type}: only disabled holders — the layered view serves none of their layers, at any address`, async () => { admitSecondPermissionHolder(type); ship(type, 'solo', B); diff --git a/packages/rest/src/meta-qualified-item-route.ts b/packages/rest/src/meta-qualified-item-route.ts index 2135ff57d80..5e910d31fa9 100644 --- a/packages/rest/src/meta-qualified-item-route.ts +++ b/packages/rest/src/meta-qualified-item-route.ts @@ -32,6 +32,7 @@ import { sendError } from '@objectstack/types'; import { handleRouteError } from './error-response.js'; +import { wantsMetaItemLayers } from './meta-item-read-gate.js'; import type { MetaRouteScope } from './meta-collection-routes.js'; import type { MetaItemReadHandler } from './meta-item-read-routes.js'; import type { RestServer } from './rest-server.js'; @@ -74,15 +75,22 @@ const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol. * so `_env` answers the read's own 404, naming no package. When that read * serves an item or refuses, a package holds the name through a stored row * the registry has not read, and the refusal stands. + * + * [#33385, review S1] Only the read that judged the name is admitted this + * way. A draft read (`?state=draft`, `?preview=draft`) or the deprecated + * layered view (`?layers=`) reads other rows than the plain read, so for it + * the marked refusal stands, as on `main` ({@link readsAsJudged}). */ async function admitEnvironmentAddress( p: QualifiedAddressProtocol, request: { type: string; name: string; member?: string }, + query: Readonly>, ): Promise { try { p.admitEnvironmentQualifier?.(request); } catch (refusal) { if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true + || !readsAsJudged(query) || typeof p.getMetaItem !== 'function') throw refusal; let withheld: boolean; try { @@ -94,6 +102,18 @@ async function admitEnvironmentAddress( } } +/** + * [#33385, review S1] Whether the read `_env` would admit is the plain read + * naming no package that {@link admitEnvironmentAddress} judges the name with: + * no draft switch and no layered view. Read off the raw query, before either + * draft switch is admitted per caller, so the answer never depends on whether + * the caller may read drafts, nor on whether a draft exists. + */ +function readsAsJudged(query: Readonly>): boolean { + const draft = (value: unknown) => typeof value === 'string' && value.toLowerCase() === 'draft'; + return !draft(query.state) && !draft(query.preview) && !wantsMetaItemLayers(query); +} + /** What the host answered this path before the route existed: its unmatched 404. */ function routeNotFound(res: any): void { sendError(res, 404, 'ENDPOINT_NOT_FOUND', 'Not found'); @@ -149,7 +169,7 @@ export function registerMetaQualifiedItemRoute( query.package = address.packageId; } else { const member = typeof query.member === 'string' && query.member !== '' ? query.member : undefined; - await admitEnvironmentAddress(p, { type: params.type, name: params.name, ...(member ? { member } : {}) }); + await admitEnvironmentAddress(p, { type: params.type, name: params.name, ...(member ? { member } : {}) }, query); } await readItem(asItemRead(req, params, query), res); } catch (error: any) { diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index 4f4e7be4742..cfc9f300efe 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -481,6 +481,29 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t } }); + // [#33385, review S1] CONTROL — the door judges the read it admits. A + // draft read (`?state=draft`, `?preview=draft`) and the deprecated + // layered view (`?layers=`) are not the read naming no package that + // judged the name, so a marked refusal stands for them: `main`'s 409, + // never an enabled package's draft or stored row at `_env`. + it(`${type}: only a disabled holder in the registry — \`_env\` with a draft or layered switch refuses 409, as on main, never an enabled package's draft or row`, async () => { + const refusedAtEnv = async (query: Record) => { + const env = await read(`/${type}/_env/solo`, query); + expect([env.status, env.body?.error?.code, query], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT', query]); + for (const label of [`gamma draft ${type}`, `gamma row ${type}`]) expect(JSON.stringify(env.body ?? null)).not.toContain(label); + }; + ship(type, 'solo', B); + registry.disablePackage(B); + // An enabled package's draft row, and no active row of the name. + storedRows.push({ id: 'draft_gamma', type, name: 'solo', state: 'draft', package_id: C, + metadata: JSON.stringify({ name: 'solo', label: `gamma draft ${type}` }) }); + for (const query of [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]) await refusedAtEnv(query); + // An enabled package's unhydrated active row: the layered view. + storedRows = [{ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, + metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }]; + await refusedAtEnv({ layers: 'true' }); + }); + it(`${type}: only disabled holders — the layered view serves none of their layers, at any address`, async () => { admitSecondPermissionHolder(type); ship(type, 'solo', B); diff --git a/packages/runtime/src/domains/meta.ts b/packages/runtime/src/domains/meta.ts index d26cd7e93a7..0bc21a3bb3b 100644 --- a/packages/runtime/src/domains/meta.ts +++ b/packages/runtime/src/domains/meta.ts @@ -1141,15 +1141,24 @@ const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol. * answers the read's own 404, naming no package. When that read serves an * item or refuses, a package holds the name through a stored row the * registry has not read, and the refusal stands. + * + * [#33385, review S1] Only the read that judged the name is admitted this way: + * for a draft read (`?state=draft`, `?preview=draft`) or the deprecated layered + * view (`?layers=`), read off the raw query as `RestServer`'s route reads it, + * the marked refusal stands, as on `main`. The raw query, so the answer never + * depends on whether the caller may read drafts, nor on whether a draft exists. */ async function admitEnvironmentAddress( protocol: MetaDomainProtocol | undefined, request: { type: string; name: string; member?: string }, + query: Readonly> | undefined, ): Promise { try { protocol?.admitEnvironmentQualifier?.(request); } catch (refusal) { + const draft = (value: unknown) => typeof value === 'string' && value.toLowerCase() === 'draft'; if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true + || draft(query?.state) || draft(query?.preview) || wantsMetaItemLayers(query) || typeof protocol?.getMetaItem !== 'function') throw refusal; let withheld: boolean; try { @@ -2186,7 +2195,7 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin // a name only disabled packages hold answers its 404, #33385). if (environmentQualified) { const qualifierProtocol = await resolveProtocol(deps, _context); - await admitEnvironmentAddress(qualifierProtocol, { type: singularType, name, ...memberSelector }); + await admitEnvironmentAddress(qualifierProtocol, { type: singularType, name, ...memberSelector }, query); } // [#5882 · #20478] The DEPRECATED spelling of the layered view, From 386c240d722588131fd5c83787e90c3c925e58b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:05:29 +0000 Subject: [PATCH 12/18] fix(rest): the import door's `_env/NAME` admits a name only disabled packages hold as `/meta` does `namedMappingRead` now reads the refusal's mark: when the read naming no package withholds the name, the mapping answers not found, naming no package, where it was refused 409 naming the disabled holder. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- packages/rest/src/import-integration.test.ts | 21 ++++++++++++++ packages/rest/src/import-mapping.ts | 30 ++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/packages/rest/src/import-integration.test.ts b/packages/rest/src/import-integration.test.ts index 78f4ba4a864..43689d82807 100644 --- a/packages/rest/src/import-integration.test.ts +++ b/packages/rest/src/import-integration.test.ts @@ -830,6 +830,27 @@ describe('import route — named mapping artifact (#2611)', () => { expect(await engine.findOne('task', { where: { id: 'e2' } })).toBeFalsy(); }); + // [#33385, review S2] A disabled package holds no name: `_env/NAME` of a + // mapping only a disabled package holds answers as `GET + // /meta/mapping/_env/NAME` answers it — not found, naming no package — + // where it was refused 409 naming the disabled holder. + it('_env/NAME of a mapping only a disabled package holds: 404 MAPPING_NOT_FOUND naming no package, as GET /meta answers it; re-enabled, 409 naming it', async () => { + shipMapping(ALPHA, 1); + engine.registry.disablePackage(ALPHA); + const held = await call(route, { format: 'csv', csv: 'ID,Task Title\ne3,壬', mappingName: '_env/task_pkg_feed' }); + expect([held._status, held._json?.code], JSON.stringify(held._json)).toEqual([404, 'MAPPING_NOT_FOUND']); + expect(JSON.stringify(held._json)).not.toContain(ALPHA); + const meta = await metaQualifiedRead('_env', 'task_pkg_feed'); + expect([meta._status, meta._json?.code ?? meta._json?.error?.code], JSON.stringify(meta._json)).toEqual([404, 'RESOURCE_NOT_FOUND']); + expect(await engine.findOne('task', { where: { id: 'e3' } })).toBeFalsy(); + // CONTROL — the holder enabled: refused 409 naming it, as before. + engine.registry.enablePackage(ALPHA); + const back = await call(route, { format: 'csv', csv: 'ID,Task Title\ne4,癸', mappingName: '_env/task_pkg_feed' }); + expect([back._status, back._json?.code], JSON.stringify(back._json)).toEqual([409, 'RESOURCE_CONFLICT']); + expect(back._json.error).toContain(ALPHA); + expect(await engine.findOne('task', { where: { id: 'e4' } })).toBeFalsy(); + }); + it('a qualifier that is no address reads the whole string by name, as before: 404, never the name after the slash', async () => { // `task_feed_import` is registered: reading the part after the slash // would import through it. diff --git a/packages/rest/src/import-mapping.ts b/packages/rest/src/import-mapping.ts index 831e016715f..23cbc7f45aa 100644 --- a/packages/rest/src/import-mapping.ts +++ b/packages/rest/src/import-mapping.ts @@ -80,6 +80,15 @@ export interface NamedMappingProtocol { admitEnvironmentQualifier?: (req: { type: string; name: string }) => void; } +/** + * [#33385, review S2] The `Symbol.for` key of the mark + * `admitEnvironmentQualifier` sets on its refusal of a name only disabled + * packages hold (`DISABLED_HOLDERS_ONLY_REFUSAL` in + * `@objectstack/metadata-protocol`), the key the `/meta` door's qualified + * route reads (`meta-qualified-item-route.ts`). + */ +const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal'); + /** The by-name read a `mappingName` asks for. */ type MappingRead = { type: 'mapping'; name: string; packageId?: string }; @@ -98,6 +107,10 @@ type MappingRead = { type: 'mapping'; name: string; packageId?: string }; * - `_env`: the environment's own mapping. `admitEnvironmentQualifier` * refuses a name only packages hold, naming every holder; admitted, the * read is a caller with no package, which answers the environment's item. + * [#33385] Its refusal of a name only disabled packages hold is marked, + * and is admitted as the `/meta` door admits it: when the read naming no + * package withholds the name, which then answers not found, naming no + * package. When that read serves an item or refuses, the refusal stands. * * Anything else is no address, and is read exactly as before this spelling * existed: the whole string, by name. A mapping name is snake_case, so such a @@ -121,8 +134,21 @@ async function namedMappingRead(p: NamedMappingProtocol, mappingName: string): P const address = await p.resolveMetaItemAddress({ type: 'mapping', segment: mappingName.slice(0, slash), name }); if (address?.kind === 'namespace') return { type: 'mapping', name, packageId: address.packageId }; if (address?.kind === 'environment' && typeof p.admitEnvironmentQualifier === 'function') { - await p.admitEnvironmentQualifier({ type: 'mapping', name }); - return { type: 'mapping', name }; + const read: MappingRead = { type: 'mapping', name }; + try { + await p.admitEnvironmentQualifier(read); + } catch (refusal) { + if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true + || typeof p.getMetaItem !== 'function') throw refusal; + let withheld: boolean; + try { + withheld = ((await p.getMetaItem(read)) as { item?: unknown } | undefined)?.item == null; + } catch { + throw refusal; + } + if (!withheld) throw refusal; + } + return read; } return bare; } From 6b2dafe5b85ec565c5cf9fa08848b5ebd9ab46f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:06:20 +0000 Subject: [PATCH 13/18] docs(import-mappings): a mapping only disabled packages hold answers 404 at `_env/NAME` The changeset gains the Skills-docs line and names the import door's move and the draft and layered reads that keep the 409. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .changeset/33385-disabled-holders-env-404.md | 4 +++- content/docs/data-modeling/import-mappings.mdx | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md index 890ad390797..d9c191057f3 100644 --- a/.changeset/33385-disabled-holders-env-404.md +++ b/.changeset/33385-disabled-holders-env-404.md @@ -8,13 +8,15 @@ fix(metadata-protocol,rest,runtime)!: a name only disabled packages hold answers Clause-②: no (narrowing) Metadata-protocol: none +Skills-docs: updated here — content/docs/data-modeling/import-mappings.mdx (no `skills/**` file teaches an `_env` answer) **BREAKING** for a read of an environment customization of a name whose every holding package is disabled. Such a customization is a row saved without a package, for a name an installed package holds. It belongs to that package (ADR-0150 D4), and a disabled package holds no name (ADR-0150 D3). - **The read that names no package (`GET /meta/:type/:name`, and the execution read).** When every package holding the name is disabled, this read now answers as if the customization were not saved: `404`, where it served the row. That includes a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. A customization at a member the package ships was already hidden. -- **`GET /meta/:type/_env/:name`.** When every package holding the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` naming the disabled packages. It still refuses `409` in two cases: an enabled package holds the name, or a package holds it through a saved metadata row that the read of the name serves. +- **`GET /meta/:type/_env/:name`.** When every package holding the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` naming the disabled packages. It still refuses `409` in three cases: an enabled package holds the name; a package holds it through a saved metadata row that the read of the name serves; or the read carries `?state=draft`, `?preview=draft` or `?layers=`, which read other rows than the plain read. +- **The import door's `mappingName: "_env/NAME"`.** The same move, as `GET /meta/mapping/_env/NAME` answers it: `404 MAPPING_NOT_FOUND`, naming no package, where it was refused `409` naming the disabled package. **Not moved.** With an enabled holder, every answer is unchanged. A customization of a name no installed package holds is the environment's own item and is still served. diff --git a/content/docs/data-modeling/import-mappings.mdx b/content/docs/data-modeling/import-mappings.mdx index 497a43bf706..bbe84e562f6 100644 --- a/content/docs/data-modeling/import-mappings.mdx +++ b/content/docs/data-modeling/import-mappings.mdx @@ -94,7 +94,10 @@ address `GET /api/v1/meta/mapping//` reads, and the import door the same way (ADR-0150 D5). The import applies exactly that holder's mapping. When that namespace, or the environment, holds no mapping of the name and a package does, the import is refused with the `409 RESOURCE_CONFLICT` that read answers, naming every holder, -and no row is written. A first segment that is neither `_env` nor an installed namespace +and no row is written. A disabled package holds no name: when every package that holds the +name is disabled, `"_env/"` answers `404 MAPPING_NOT_FOUND`, naming no package, as +`GET /api/v1/meta/mapping/_env/` answers `404`. Enable a holder again and the address +is refused with the `409` naming it, as before. A first segment that is neither `_env` nor an installed namespace is no address: the whole string is read as the name, which no mapping has, so the import answers `404 MAPPING_NOT_FOUND`. Two limits come with the metadata read's address. Where two packages that share a namespace (`base`, `system`, `sys`) both hold the name, the @@ -274,8 +277,8 @@ These are whole-request failures — nothing is written, and there is no per-row | Status | `code` | Cause | |:---|:---|:---| -| 404 | `MAPPING_NOT_FOUND` | No mapping artifact is registered under that name. | -| 409 | `RESOURCE_CONFLICT` | Two or more packages hold a mapping under that name, and the environment holds none; or a qualified `mappingName` (`/`, `_env/`) names a holder that holds no mapping of that name while another does. The error names every holder. | +| 404 | `MAPPING_NOT_FOUND` | No mapping artifact is registered under that name, or every package that holds it is disabled. | +| 409 | `RESOURCE_CONFLICT` | Two or more packages hold a mapping under that name, and the environment holds none; or a qualified `mappingName` (`/`, `_env/`) names a holder that holds no mapping of that name while another, enabled, package does. The error names every holder. | | 400 | `MAPPING_TARGET_MISMATCH` | The artifact's `targetObject` is not the object in the URL. | | 400 | `MAPPING_FORMAT_UNSUPPORTED` | The artifact declares `sourceFormat: 'xml'` or `'sql'`; the endpoint accepts csv, json and xlsx payloads only. | | 400 | `MAPPING_FORMAT_MISMATCH` | The declared `sourceFormat` contradicts the payload actually sent. A `csv` mapping does apply to an `xlsx` payload — those rows are tabular in the same way — but a `json` mapping does not. | From 7b65fff0263084bd425eb6304bc6f46a2e9ac7b6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 18:03:09 +0000 Subject: [PATCH 14/18] test(rest,runtime): type the draft reads of the `_env` draft-switch CONTROL Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- packages/rest/src/meta-qualified-item-route.test.ts | 3 ++- packages/runtime/src/domains/meta-qualified-item-read.test.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index 32524bdc0c6..91f02564ab8 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -447,7 +447,8 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t // An enabled package's draft row, and no active row of the name. storedRows.push({ id: 'draft_gamma', type, name: 'solo', state: 'draft', package_id: C, metadata: JSON.stringify({ name: 'solo', label: `gamma draft ${type}` }) }); - for (const query of [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]) await refusedAtEnv(query); + const draftReads: Record[] = [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]; + for (const query of draftReads) await refusedAtEnv(query); // An enabled package's unhydrated active row: the layered view. storedRows = [{ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }]; diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index cfc9f300efe..876571299dc 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -497,7 +497,8 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t // An enabled package's draft row, and no active row of the name. storedRows.push({ id: 'draft_gamma', type, name: 'solo', state: 'draft', package_id: C, metadata: JSON.stringify({ name: 'solo', label: `gamma draft ${type}` }) }); - for (const query of [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]) await refusedAtEnv(query); + const draftReads: Record[] = [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]; + for (const query of draftReads) await refusedAtEnv(query); // An enabled package's unhydrated active row: the layered view. storedRows = [{ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }]; From e6b91bd1d4ddaa20bde3811b557fc821f8888f9d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 18:34:10 +0000 Subject: [PATCH 15/18] fix(rest,runtime): `_env` judges the draft switches as the caller is admitted to them The guard read the raw query, which the runtime draft-switch census reads as an unadmitted draft switch. Both doors now judge with the read the caller is actually answered: an admitted draft switch or the layered view keeps the marked refusal (409, as on main); a caller `mayReadPendingDrafts` does not admit is answered the plain read, and judged as it. The REST qualified route is handed `resolveExecCtx` for that, asked only once the refusal is marked. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/meta-qualified-item-route.test.ts | 12 +++++- .../rest/src/meta-qualified-item-route.ts | 41 ++++++++++--------- packages/rest/src/rest-server.ts | 2 +- .../domains/meta-qualified-item-read.test.ts | 11 ++++- packages/runtime/src/domains/meta.ts | 20 +++++---- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index 91f02564ab8..836e89f2762 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -436,7 +436,7 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t // layered view (`?layers=`) are not the read naming no package that // judged the name, so a marked refusal stands for them: `main`'s 409, // never an enabled package's draft or stored row at `_env`. - it(`${type}: only a disabled holder in the registry — \`_env\` with a draft or layered switch refuses 409, as on main, never an enabled package's draft or row`, async () => { + it(`${type}: only a disabled holder in the registry — \`_env\` with an admitted draft switch or the layered view refuses 409, as on main, a caller not admitted to drafts is answered the plain read's 404, never an enabled package's draft or row`, async () => { const refusedAtEnv = async (query: Record) => { const env = await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }, query); expect([env.status, codeOf(env), query], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT', query]); @@ -449,6 +449,16 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t metadata: JSON.stringify({ name: 'solo', label: `gamma draft ${type}` }) }); const draftReads: Record[] = [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]; for (const query of draftReads) await refusedAtEnv(query); + // A caller `mayReadPendingDrafts` does not admit is answered the plain + // read whatever it sends, so `_env` answers it as the plain read does: + // 404, never the draft, and never a 409 naming the disabled holder. + (rest as any).resolveExecCtx = async () => ({ userId: 'u_member' }); + for (const query of draftReads) { + const env = await drive(QUALIFIED, { type, ns: '_env', name: 'solo' }, query); + expect([env.status, codeOf(env), query], JSON.stringify(env.body)).toEqual([404, 'RESOURCE_NOT_FOUND', query]); + for (const text of [`gamma draft ${type}`, B]) expect(JSON.stringify(env.body ?? null)).not.toContain(text); + } + (rest as any).resolveExecCtx = async () => ({ isSystem: true, userId: 'u1' }); // An enabled package's unhydrated active row: the layered view. storedRows = [{ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }]; diff --git a/packages/rest/src/meta-qualified-item-route.ts b/packages/rest/src/meta-qualified-item-route.ts index 5e910d31fa9..93658d8cb3f 100644 --- a/packages/rest/src/meta-qualified-item-route.ts +++ b/packages/rest/src/meta-qualified-item-route.ts @@ -30,17 +30,20 @@ * (#32310). */ +import { rethrowAuthzStoreUnavailable } from '@objectstack/core'; import { sendError } from '@objectstack/types'; import { handleRouteError } from './error-response.js'; import { wantsMetaItemLayers } from './meta-item-read-gate.js'; import type { MetaRouteScope } from './meta-collection-routes.js'; import type { MetaItemReadHandler } from './meta-item-read-routes.js'; -import type { RestServer } from './rest-server.js'; +import { mayReadPendingDrafts, type RestServer } from './rest-server.js'; /** The `RestServer` members {@link registerMetaQualifiedItemRoute} reads. */ export interface MetaQualifiedItemRouteHost { readonly routeManager: RestServer['routeManager']; resolveProtocol: RestServer['resolveProtocol']; + /** [#33385, review S1] The caller, asked only to judge an admitted draft switch at `_env`. */ + resolveExecCtx: RestServer['resolveExecCtx']; } /** @@ -77,21 +80,22 @@ const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol. * the registry has not read, and the refusal stands. * * [#33385, review S1] Only the read that judged the name is admitted this - * way. A draft read (`?state=draft`, `?preview=draft`) or the deprecated - * layered view (`?layers=`) reads other rows than the plain read, so for it - * the marked refusal stands, as on `main` ({@link readsAsJudged}). + * way. An admitted draft read (`?state=draft`, `?preview=draft`) or the + * deprecated layered view (`?layers=`) reads other rows than the plain read, + * so for it the marked refusal stands, as on `main` (`readsAsJudged`, asked + * only once the refusal is marked). */ async function admitEnvironmentAddress( p: QualifiedAddressProtocol, request: { type: string; name: string; member?: string }, - query: Readonly>, + readsAsJudged: () => Promise, ): Promise { try { p.admitEnvironmentQualifier?.(request); } catch (refusal) { if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true - || !readsAsJudged(query) - || typeof p.getMetaItem !== 'function') throw refusal; + || typeof p.getMetaItem !== 'function' + || !(await readsAsJudged())) throw refusal; let withheld: boolean; try { withheld = (await p.getMetaItem(request))?.item == null; @@ -102,18 +106,6 @@ async function admitEnvironmentAddress( } } -/** - * [#33385, review S1] Whether the read `_env` would admit is the plain read - * naming no package that {@link admitEnvironmentAddress} judges the name with: - * no draft switch and no layered view. Read off the raw query, before either - * draft switch is admitted per caller, so the answer never depends on whether - * the caller may read drafts, nor on whether a draft exists. - */ -function readsAsJudged(query: Readonly>): boolean { - const draft = (value: unknown) => typeof value === 'string' && value.toLowerCase() === 'draft'; - return !draft(query.state) && !draft(query.preview) && !wantsMetaItemLayers(query); -} - /** What the host answered this path before the route existed: its unmatched 404. */ function routeNotFound(res: any): void { sendError(res, 404, 'ENDPOINT_NOT_FOUND', 'Not found'); @@ -169,7 +161,16 @@ export function registerMetaQualifiedItemRoute( query.package = address.packageId; } else { const member = typeof query.member === 'string' && query.member !== '' ? query.member : undefined; - await admitEnvironmentAddress(p, { type: params.type, name: params.name, ...(member ? { member } : {}) }, query); + // [#33385, review S1] The read the item read answers this caller: the + // plain read unless `?layers=` asks for the layered view, or a + // draft switch is sent by a caller `mayReadPendingDrafts` admits. + const readsAsJudged = async (): Promise => { + if (wantsMetaItemLayers(query)) return false; + const draft = (value: unknown) => typeof value === 'string' && value.toLowerCase() === 'draft'; + if (!draft(query.state) && !draft(query.preview)) return true; + return !mayReadPendingDrafts(await this.resolveExecCtx(environmentId, req).catch(rethrowAuthzStoreUnavailable)); + }; + await admitEnvironmentAddress(p, { type: params.type, name: params.name, ...(member ? { member } : {}) }, readsAsJudged); } await readItem(asItemRead(req, params, query), res); } catch (error: any) { diff --git a/packages/rest/src/rest-server.ts b/packages/rest/src/rest-server.ts index 244bca4ec64..9743e15af39 100644 --- a/packages/rest/src/rest-server.ts +++ b/packages/rest/src/rest-server.ts @@ -5763,7 +5763,7 @@ export class RestServer { // `/layers`, `/publish`, `/rollback`, `book/:name/tree`), which keep // their routes (ruling Q1 on #31691). registerMetaQualifiedItemRoute.call( - { routeManager: this.routeManager, resolveProtocol: (...a) => this.resolveProtocol(...a) }, + { routeManager: this.routeManager, resolveProtocol: (...a) => this.resolveProtocol(...a), resolveExecCtx: (...a) => this.resolveExecCtx(...a) }, scope, readMetaItem, ); diff --git a/packages/runtime/src/domains/meta-qualified-item-read.test.ts b/packages/runtime/src/domains/meta-qualified-item-read.test.ts index 876571299dc..9149fb5c5df 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -486,7 +486,7 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t // layered view (`?layers=`) are not the read naming no package that // judged the name, so a marked refusal stands for them: `main`'s 409, // never an enabled package's draft or stored row at `_env`. - it(`${type}: only a disabled holder in the registry — \`_env\` with a draft or layered switch refuses 409, as on main, never an enabled package's draft or row`, async () => { + it(`${type}: only a disabled holder in the registry — \`_env\` with an admitted draft switch or the layered view refuses 409, as on main, a caller not admitted to drafts is answered the plain read's 404, never an enabled package's draft or row`, async () => { const refusedAtEnv = async (query: Record) => { const env = await read(`/${type}/_env/solo`, query); expect([env.status, env.body?.error?.code, query], JSON.stringify(env.body)).toEqual([409, 'RESOURCE_CONFLICT', query]); @@ -499,6 +499,15 @@ describe('#32183 — a disabled package holds no name: the by-name read judges t metadata: JSON.stringify({ name: 'solo', label: `gamma draft ${type}` }) }); const draftReads: Record[] = [{ state: 'draft' }, { state: 'DRAFT' }, { preview: 'draft' }]; for (const query of draftReads) await refusedAtEnv(query); + // A caller `mayReadPendingDrafts` does not admit is answered the plain + // read whatever it sends, so `_env` answers it as the plain read does: + // 404, never the draft, and never a 409 naming the disabled holder. + const member = { ...ctx(), executionContext: { userId: 'u_member', systemPermissions: [] } }; + for (const query of draftReads) { + const env = await read(`/${type}/_env/solo`, query, member); + expect([env.status, env.body?.error?.code, query], JSON.stringify(env.body)).toEqual([404, 'RESOURCE_NOT_FOUND', query]); + for (const text of [`gamma draft ${type}`, B]) expect(JSON.stringify(env.body ?? null)).not.toContain(text); + } // An enabled package's unhydrated active row: the layered view. storedRows = [{ id: 'row_gamma', type, name: 'solo', state: 'active', package_id: C, metadata: JSON.stringify({ name: 'solo', label: `gamma row ${type}` }) }]; diff --git a/packages/runtime/src/domains/meta.ts b/packages/runtime/src/domains/meta.ts index 0bc21a3bb3b..178415ad614 100644 --- a/packages/runtime/src/domains/meta.ts +++ b/packages/runtime/src/domains/meta.ts @@ -1142,23 +1142,24 @@ const DISABLED_HOLDERS_ONLY_REFUSAL = Symbol.for('objectstack.metadata-protocol. * item or refuses, a package holds the name through a stored row the * registry has not read, and the refusal stands. * - * [#33385, review S1] Only the read that judged the name is admitted this way: - * for a draft read (`?state=draft`, `?preview=draft`) or the deprecated layered - * view (`?layers=`), read off the raw query as `RestServer`'s route reads it, - * the marked refusal stands, as on `main`. The raw query, so the answer never - * depends on whether the caller may read drafts, nor on whether a draft exists. + * [#33385, review S1] Only the read that judged the name is admitted this way. + * `judged` is false when the read the caller is answered is not that plain + * read: an ADMITTED draft switch (`?state=draft`, `?preview=draft`, as + * `mayReadPendingDrafts` admits it) or the deprecated layered view + * (`?layers=`). Then the marked refusal stands, as on `main`. A caller the + * draft switches do not admit is answered the plain read, so it is judged. + * `RestServer`'s qualified route passes the same judgment. */ async function admitEnvironmentAddress( protocol: MetaDomainProtocol | undefined, request: { type: string; name: string; member?: string }, - query: Readonly> | undefined, + judged: boolean, ): Promise { try { protocol?.admitEnvironmentQualifier?.(request); } catch (refusal) { - const draft = (value: unknown) => typeof value === 'string' && value.toLowerCase() === 'draft'; if ((refusal as Record | null)?.[DISABLED_HOLDERS_ONLY_REFUSAL] !== true - || draft(query?.state) || draft(query?.preview) || wantsMetaItemLayers(query) + || !judged || typeof protocol?.getMetaItem !== 'function') throw refusal; let withheld: boolean; try { @@ -2195,7 +2196,8 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin // a name only disabled packages hold answers its 404, #33385). if (environmentQualified) { const qualifierProtocol = await resolveProtocol(deps, _context); - await admitEnvironmentAddress(qualifierProtocol, { type: singularType, name, ...memberSelector }, query); + await admitEnvironmentAddress(qualifierProtocol, { type: singularType, name, ...memberSelector }, + !isDraftRead && !previewDrafts && !wantsMetaItemLayers(query)); } // [#5882 · #20478] The DEPRECATED spelling of the layered view, From d86adb40b2c7fc53143d830ed9f2dcfdb33aa117 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 19:20:25 +0000 Subject: [PATCH 16/18] fix(rest): hand the qualified route its resolveExecCtx in the shape every registrar host spells The execctx consumer census reads each host's forwarding member on its own line; the one-line object it could not read. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- packages/rest/src/rest-server.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/rest/src/rest-server.ts b/packages/rest/src/rest-server.ts index 9743e15af39..c9da3bbeb97 100644 --- a/packages/rest/src/rest-server.ts +++ b/packages/rest/src/rest-server.ts @@ -5763,7 +5763,11 @@ export class RestServer { // `/layers`, `/publish`, `/rollback`, `book/:name/tree`), which keep // their routes (ruling Q1 on #31691). registerMetaQualifiedItemRoute.call( - { routeManager: this.routeManager, resolveProtocol: (...a) => this.resolveProtocol(...a), resolveExecCtx: (...a) => this.resolveExecCtx(...a) }, + { + routeManager: this.routeManager, + resolveProtocol: (...a) => this.resolveProtocol(...a), + resolveExecCtx: (...a) => this.resolveExecCtx(...a), + }, scope, readMetaItem, ); From 69f4887137d0a16819e4df05e067e23087ed6fc0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 22:42:17 +0000 Subject: [PATCH 17/18] fix(metadata-protocol): judge the package-less withhold over the active rows, and let the lists agree with it The by-name read now serves a package-less row when an enabled package holds the name through one of the stored rows the face already read, as on main. The list and the execution list leave out the package-less item the by-name read withholds. The `_env` 409 that stands names the disabled registry holder. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .changeset/33385-disabled-holders-env-404.md | 6 +- .../src/protocol-meta-item-face.ts | 67 ++++- .../src/protocol-meta-list-reads.ts | 19 +- ...abled-holder-packageless-row-doors.test.ts | 238 ++++++++++++++++++ .../src/meta-qualified-item-route.test.ts | 4 + .../domains/meta-qualified-item-read.test.ts | 4 + 6 files changed, 332 insertions(+), 6 deletions(-) create mode 100644 packages/objectql/src/disabled-holder-packageless-row-doors.test.ts diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md index d9c191057f3..f8636a7a84f 100644 --- a/.changeset/33385-disabled-holders-env-404.md +++ b/.changeset/33385-disabled-holders-env-404.md @@ -15,9 +15,11 @@ Skills-docs: updated here — content/docs/data-modeling/import-mappings.mdx (no **BREAKING** for a read of an environment customization of a name whose every holding package is disabled. Such a customization is a row saved without a package, for a name an installed package holds. It belongs to that package (ADR-0150 D4), and a disabled package holds no name (ADR-0150 D3). - **The read that names no package (`GET /meta/:type/:name`, and the execution read).** When every package holding the name is disabled, this read now answers as if the customization were not saved: `404`, where it served the row. That includes a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. A customization at a member the package ships was already hidden. -- **`GET /meta/:type/_env/:name`.** When every package holding the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` naming the disabled packages. It still refuses `409` in three cases: an enabled package holds the name; a package holds it through a saved metadata row that the read of the name serves; or the read carries `?state=draft`, `?preview=draft` or `?layers=`, which read other rows than the plain read. +- **The list and the execution list (`GET /meta/:type`).** They now leave out the same customization, so they agree with the read of the name: while every package holding the name is disabled, neither list carries any item of it. Enable a holder again and both list it again. +- **A save or delete naming no package while every holder is disabled.** A save at a member the package never ships is accepted and kept, as before, but it is now hidden from the reads above until a holder is enabled again. A delete of it still removes the row. A save at a member the package ships is still refused `403 NOT_OVERRIDABLE`. +- **`GET /meta/:type/_env/:name`.** When every package holding the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` naming the disabled packages. It still refuses `409` in three cases: an enabled package holds the name; a package holds it through a saved metadata row that the read of the name serves; or the read carries `?state=draft`, `?preview=draft` or `?layers=`, which read other rows than the plain read. That `409` names only the disabled package the registry holds the name for, as before; it does not name an enabled package that holds the name through a saved row. - **The import door's `mappingName: "_env/NAME"`.** The same move, as `GET /meta/mapping/_env/NAME` answers it: `404 MAPPING_NOT_FOUND`, naming no package, where it was refused `409` naming the disabled package. -**Not moved.** With an enabled holder, every answer is unchanged. A customization of a name no installed package holds is the environment's own item and is still served. +**Not moved.** With an enabled holder, every answer is unchanged. That includes an enabled package that holds the name only through a saved row the registry has not read yet: the customization is still served and listed, whether the list or the read of the name comes first. A customization of a name no installed package holds is the environment's own item and is still served. **No migration.** Nothing is deleted or rewritten. Enable the package again and the customization is served again, unchanged. The fix for a caller who needs the row while the package is disabled is to re-enable the package. diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index 869ac1b1475..7ea08253470 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -153,6 +153,63 @@ function packagelessRowWithheldHolder(registry: any, type: string, name: string, return disabledOnlyHolderOf(registry, type, name); } +/** + * [#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 + * package that the reads do not decline (`declinesStoredRow`) and that is no + * holder's customization pair row (a pair row is that holder's item, never a + * holder of its own). The registry's owner rule does not see such a row + * until it is hydrated, so {@link packagelessRowWithheldHolder} alone would + * withhold a package-less row while an enabled package holds the name, and + * the answer would follow hydration order. + */ +function enabledRowHolds( + host: Pick, + type: string, name: string, + rows: ReadonlyArray>[number]>, +): boolean { + const registry: any = host.engine?.registry; + const every: readonly string[] = registry?.packageScopedHoldersOf?.(type, name, null, { includeDisabledPackages: true }) ?? []; + const installed = installedManifestsOfEngine(host.engine); + return rows.some((row) => { + const bound = typeof row.package_id === 'string' && row.package_id !== '' && row.package_id !== 'sys_metadata' + ? row.package_id : undefined; + return bound !== undefined && registry?.isPackageDisabled?.(bound) !== true + && !host.declinesStoredRow(type, name, row) + && !every.some((holder) => pairsOf(holder, installed).includes(bound)); + }); +} + +/** + * [#33401] The holder a package-less `item` of `(type, name)` is withheld + * with ({@link packagelessRowWithheldHolder}), unless an enabled package + * holds the name through a stored active row ({@link enabledRowHolds}, + * review#2 S5): then the answer is `main`'s, whichever order the rows were + * hydrated in. `rows` are the item's active rows when the caller already + * read them; otherwise they are read here, only once the registry would + * withhold the item. The read naming no package and the list naming no + * package (`protocol-meta-list-reads.ts`) both ask this, so the list carries + * no row the by-name read withholds. + */ +export async function packagelessRowWithheld( + host: Pick, + type: string, name: string, item: unknown, + rows?: ReadonlyArray>[number]>, +): Promise { + const holder = packagelessRowWithheldHolder(host.engine?.registry, type, name, item); + if (holder === undefined) return undefined; + let active: ReadonlyArray>[number]> | undefined = rows; + if (active === undefined) { + try { + active = await host.readItemActiveRows(type, name); + } catch (error) { + host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata'); + active = []; + } + } + return enabledRowHolds(host, type, name, active) ? undefined : holder; +} + /** * [#32183] The package whose stack a read naming no package takes, for a * name a disabled package also holds: the one holder ADR-0150 D3 resolves @@ -554,8 +611,10 @@ export async function readMetaItemFace( // name only disabled packages hold is their withheld item, the answer the // same read gives with no row stored. // [#33401] …and so does a package-less row of a key whose every holder is - // disabled ({@link packagelessRowWithheldHolder}): that holder's - // customization, withheld with it; the environment's own item is served. + // disabled ({@link packagelessRowWithheld}): that holder's customization, + // withheld with it; the environment's own item is served, and so is the + // row while an enabled package holds the name through a stored row + // (review#2 S5), judged over the active rows read above. const withheldHolder = request.type === 'object' || request.type === 'package' ? undefined : (request.packageId ? disabledExactAddressHolder(this, { type: request.type, name: request.name, packageId: request.packageId }) : undefined) @@ -567,7 +626,9 @@ export async function readMetaItemFace( : undefined) ?? (request.packageId || answer?.item == null ? undefined - : packagelessRowWithheldHolder(this.engine?.registry, request.type, request.name, answer.item)); + : await packagelessRowWithheld(this, request.type, request.name, answer.item, + activeRows !== undefined && activeRows.type === request.type && activeRows.name === request.name + ? activeRows.rows : undefined)); if (withheldHolder === undefined && (request.type === 'object' || request.type === 'package' || (!withheldAction && !isItemOfDisabledPackage(this.engine?.registry, answer?.item)))) { return answer; diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.ts index 523b698988f..8be8dda9805 100644 --- a/packages/metadata-protocol/src/protocol-meta-list-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-list-reads.ts @@ -49,6 +49,7 @@ import { storedEntryRow } from './protocol-stored-overlay-types.js'; import { viewIdentityPatch } from './protocol-view-normalization.js'; import { isServedOverrideRowOf, type ServedOverrideRow } from './served-override.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; +import { packagelessRowWithheld } from './protocol-meta-item-face.js'; import { declinesPackageLessRowAt, disabledExactAddressHolder, @@ -161,7 +162,7 @@ function disabledHolderListing( } /** The body of `ObjectStackProtocolImplementation#readFlattenedMetaItems`; the method's docblock there is its contract. */ -export async function readFlattenedMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }, +export async function readFlattenedMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }, audience: 'served' | 'execution', layer: 'effective' | 'per-package' = 'effective',) { const { packageId } = request; @@ -952,6 +953,22 @@ export async function readFlattenedMetaItems(host: Pick