From 0571f19254e5a553610ac0fe8d4fa17a111696cc Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:58:07 +0000 Subject: [PATCH 01/10] fix(metadata-protocol, rest): every /layers refusal of a name several packages hold carries details.candidates (ADR-0150 D5) The REST /meta/:type/:name/layers catch now asks handleRouteError for the package-scoped candidates, as the plain read's catch does, so the plain read's refusal the door's owner step answers and the served-holders refusal of step 1c carry details.candidates on RestServer as on the dispatcher. The step-1c refusal of a name whose active rows two packages hold (the package-less writes' sentence, code and status, unchanged) now carries its holders by shape as a package-scoped refusal, so both transports answer them as details.candidates. The save and delete doors' answer does not move. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../src/protocol-meta-layered-reads.ts | 36 ++++++++++++++++++- ...l.packageless-layered-read-refusal.test.ts | 8 +++++ .../src/meta-disabled-package-doors.test.ts | 7 ++-- packages/rest/src/meta-item-read-routes.ts | 7 +++- .../src/meta-layers-ambiguous-package.test.ts | 20 ++++++++--- .../meta-disabled-holder-served-stack.test.ts | 5 +-- .../meta-layers-ambiguous-package.test.ts | 18 +++++++--- .../domains/meta-qualified-item-read.test.ts | 6 ++-- 8 files changed, 88 insertions(+), 19 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts index 19511372f35..b51f5bff21a 100644 --- a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts @@ -103,10 +103,44 @@ export async function packagelessLayeredReadRefusal(host: Pick 1 - ? packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates) + ? withPackageCandidates( + packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates), + PLURAL_TO_SINGULAR[type] ?? type, name, address.candidates, + ) : undefined; } +/** + * [#32622, ADR-0150 D5] The package-less writes' refusal, as the layered door + * answers it (#28337: its sentence, code, status and `?package=` remedy, + * unchanged), with the holders it names carried as a package-scoped refusal's + * `refusal.candidates` (`[{ kind: 'package', packageId }, …]`, the `/actions` + * shape), so each transport answers them as `details.candidates`, as for every + * other `/layers` refusal. Carried by SHAPE (`refusal.status: 'refused'`), + * which the one recogniser reads (`packageScopedRefusalCandidates` in + * `@objectstack/types`), because the type this refusal judges need not be one + * the package-scoped resolver covers. The save and delete doors' answer of + * the same rows does not move. + */ +function withPackageCandidates( + error: Error & { code: 'RESOURCE_CONFLICT'; status: 409 }, + type: string, + name: string, + packageIds: readonly string[], +): Error & { code: 'RESOURCE_CONFLICT'; status: 409 } { + return Object.assign(error, { + refusal: { + status: 'refused' as const, + reason: 'ambiguous-in-environment' as const, + type, + name, + callerPackageId: null, + candidates: packageIds.map((packageId) => ({ kind: 'package' as const, packageId })), + message: error.message, + }, + }); +} + /** The body of `ObjectStackProtocolImplementation#getMetaItemLayered`; the method's docblock there is its contract. */ export async function getMetaItemLayered(host: Pick, request: { type: string; diff --git a/packages/metadata-protocol/src/protocol.packageless-layered-read-refusal.test.ts b/packages/metadata-protocol/src/protocol.packageless-layered-read-refusal.test.ts index 942bbb94d0f..a34c9c0adf6 100644 --- a/packages/metadata-protocol/src/protocol.packageless-layered-read-refusal.test.ts +++ b/packages/metadata-protocol/src/protocol.packageless-layered-read-refusal.test.ts @@ -139,6 +139,14 @@ describe('[#28337] packagelessLayeredReadRefusal', () => { ); // The holder list is the save's, sorted. expect(saveRefusal.message).toContain(`('${PKG_A}', '${PKG_B}')`); + // [#32622, ADR-0150 D5] …and carried as the package-scoped refusal's + // candidates, which each door answers as `details.candidates`. + expect((refusal as any).refusal?.status).toBe('refused'); + expect((refusal as any).refusal?.candidates).toEqual([ + { kind: 'package', packageId: PKG_A }, + { kind: 'package', packageId: PKG_B }, + ]); + expect(saveRefusal.refusal, 'the save\'s answer does not move').toBeUndefined(); // The plural URL spelling is the same item. expect((await protocol.packagelessLayeredReadRefusal({ type: 'dashboards', name: 'twin_dash' }))?.message) .toBe(refusal!.message); diff --git a/packages/rest/src/meta-disabled-package-doors.test.ts b/packages/rest/src/meta-disabled-package-doors.test.ts index a761de531a5..b4a8110c5a1 100644 --- a/packages/rest/src/meta-disabled-package-doors.test.ts +++ b/packages/rest/src/meta-disabled-package-doors.test.ts @@ -569,10 +569,11 @@ describe('[#32354] RestServer: stored rows judged over the served set', () => { expect([read.status, read.body?.code], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']); expect([...(read.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(read.body)) .toEqual([OTHER_PKG, THIRD_PKG].sort()); - // The layered door answers a package-scoped refusal by its sentence alone, as for two registry holders (#32622). + // [#32622, ADR-0150 D5] The layered door names the same served holders as `details.candidates`. const layers = await host.layers('dashboard', 'three_rows_dash'); - expect(layers.status, JSON.stringify(layers.body)).toBe(409); - for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(JSON.stringify(layers.body)).toContain(pkg); + expect([layers.status, layers.body?.code], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']); + expect([...(layers.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(layers.body)) + .toEqual([OTHER_PKG, THIRD_PKG].sort()); // [contract review S3] Bare /published asks the plain read first and answers its refusal. const published = await host.published('dashboard', 'three_rows_dash'); expect([published.status, published.body?.code ?? published.body?.error?.code], JSON.stringify(published.body)) diff --git a/packages/rest/src/meta-item-read-routes.ts b/packages/rest/src/meta-item-read-routes.ts index d8e5ffd54ca..356116bd6b7 100644 --- a/packages/rest/src/meta-item-read-routes.ts +++ b/packages/rest/src/meta-item-read-routes.ts @@ -366,7 +366,12 @@ export function registerMetaItemReadRoutes(this: MetaItemReadRouteHost, scope: M } await this.serveMetaItemLayered(req, res, environmentId, p, maskPosture); } catch (error: any) { - handleRouteError(res, error); + // [#32622, ADR-0150 D5] A package-scoped refusal of the + // layered read carries its holders as `details.candidates`, + // as the plain read's catch answers it (#32201) and the + // deprecated `?layers=` spelling, which that catch serves, + // already did; anything else answers as before. + handleRouteError(res, error, undefined, { packageScopedCandidates: true }); } }, metadata: { diff --git a/packages/rest/src/meta-layers-ambiguous-package.test.ts b/packages/rest/src/meta-layers-ambiguous-package.test.ts index 1fe68507708..f92031f7bbd 100644 --- a/packages/rest/src/meta-layers-ambiguous-package.test.ts +++ b/packages/rest/src/meta-layers-ambiguous-package.test.ts @@ -45,8 +45,11 @@ const matchesWhere = (row: Record, where: Record) { const registry = new SchemaRegistry({ multiTenant: false }); (registry as any).logLevel = 'silent'; const rows = new Map(); @@ -93,7 +96,7 @@ function makeHarness() { }, async syncObjectSchema() { /* no physical storage in this double */ }, }; - const protocol = new ObjectStackProtocolImplementation(engine, undefined, 'env_test'); + const protocol = new ObjectStackProtocolImplementation(engine, services ? () => services as Map : undefined, 'env_test'); return { protocol, registry, rows }; } @@ -173,8 +176,14 @@ describe('[#28337] RestServer: the layered view of a name two packages hold, nam for (const read of [host.layers, host.layersFlag]) { const refused = await read('twin_dash'); expect({ status: refused.status, code: codeOf(refused) }).toEqual({ status: save.status, code: codeOf(save) }); - // One envelope shape for the read and the writes on this transport. - expect(Object.keys(refused.body ?? {}).sort()).toEqual(Object.keys(save.body ?? {}).sort()); + // One envelope shape for the read and the writes on this transport, and + // [#32622, ADR-0150 D5] the read's holders as `details.candidates` beside it. + expect(Object.keys(refused.body ?? {}).sort()).toEqual([...Object.keys(save.body ?? {}), 'details'].sort()); + expect(refused.body?.details?.candidates).toEqual([ + { kind: 'package', packageId: PKG_A }, + { kind: 'package', packageId: PKG_B }, + ]); + expect(save.body?.details, 'the writes\' answer does not move').toBeUndefined(); const message = messageOf(refused); expect(message.startsWith('Name the package this layered read is for, then send it again')).toBe(true); expect(message).toContain('?package='); @@ -211,3 +220,4 @@ describe('[#28337] RestServer: the layered view of a name two packages hold, nam } }, 60_000); }); + diff --git a/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts b/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts index e74e76fc6cb..9ce20885e12 100644 --- a/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts +++ b/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts @@ -285,10 +285,11 @@ describe.each([ expect([read.status, codeOf(read.body)], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']); expect([...(read.body?.error?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(read.body)) .toEqual([ROW_E, ROW_F].sort()); - // The layered door answers a package-scoped refusal by its sentence alone, as for two registry holders (#32622). + // [#32622, ADR-0150 D5] The layered door names the same served holders as `details.candidates`. const layers = await get(booted.kernel, '/meta/dashboard/three_rows_dash/layers'); expect([layers.status, codeOf(layers.body)], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']); - for (const id of [ROW_E, ROW_F]) expect(JSON.stringify(layers.body)).toContain(id); + expect([...(layers.body?.error?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(layers.body)) + .toEqual([ROW_E, ROW_F].sort()); // [contract review S3] Bare /published asks the plain read first and answers its refusal. const published = await get(booted.kernel, '/meta/dashboard/three_rows_dash/published'); expect([published.status, codeOf(published.body)], JSON.stringify(published.body)).toEqual([409, 'RESOURCE_CONFLICT']); diff --git a/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts b/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts index 9d3345aa0fd..82ece2cb0e9 100644 --- a/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts +++ b/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts @@ -204,12 +204,20 @@ for (const [doorName, boot] of DOORS) { const read = await door.send('GET', path, query); expect([read.status, codeOf(read.body)], `${spelling}: ${JSON.stringify(read.body)}`) .toEqual([save.status, codeOf(save.body)]); - // The same envelope this door wraps the writes' refusal in. + // The same envelope this door wraps the writes' refusal in, and + // [#32622, ADR-0150 D5] the read's holders as `details.candidates` + // where this door's envelope carries the refusal's fields. const keys = (b: any) => Object.keys(b ?? {}).sort(); - expect(keys(read.body), spelling).toEqual(keys(save.body)); - if (read.body?.error && typeof read.body.error === 'object') { - expect(keys(read.body.error), spelling).toEqual(keys(save.body.error)); - } + const withDetails = (b: any) => [...Object.keys(b ?? {}), 'details'].sort(); + const nested = read.body?.error && typeof read.body.error === 'object'; + expect(keys(read.body), spelling).toEqual(nested ? keys(save.body) : withDetails(save.body)); + if (nested) expect(keys(read.body.error), spelling).toEqual(withDetails(save.body.error)); + const fields = nested ? read.body.error : read.body; + expect(fields?.details?.candidates, spelling).toEqual([ + { kind: 'package', packageId: PKG_A }, + { kind: 'package', packageId: PKG_B }, + ]); + expect((nested ? save.body.error : save.body)?.details, `${spelling}: the writes' answer does not move`).toBeUndefined(); const message = messageOf(read.body); expect(message.startsWith('Name the package this layered read is for, then send it again'), message).toBe(true); expect(message, spelling).toContain('?package='); 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..7f6911d4ffe 100644 --- a/packages/runtime/src/domains/meta-qualified-item-read.test.ts +++ b/packages/runtime/src/domains/meta-qualified-item-read.test.ts @@ -872,8 +872,10 @@ describe('#32183 × #32310 — the caller arm judges the served holders', () => * two packages register answers the read's `409 RESOURCE_CONFLICT` naming both * holders as `details.candidates`, as the item read does. The refusal leaves * through `errorFromThrown`, which composes `details` from - * `resolveThrownHttpError`. Only this cell of #32622 is covered here: a stored - * row's layered refusal, and the REST `/layers` door, are not. + * `resolveThrownHttpError`. This is the dispatcher's registry-holder cell; the + * stored-row cells and the REST `/layers` door are pinned beside the #28337 + * and #32354 pins (`meta-layers-ambiguous-package.test.ts`, + * `meta-disabled-holder-served-stack.test.ts` and their REST twins). */ describe('#32250 — the dispatcher /layers 409 names the holders', () => { it('a name two packages register: 409 RESOURCE_CONFLICT with both as details.candidates', async () => { From ee6fa50186f63bfa71aefd016ac405b612b473d4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:58:08 +0000 Subject: [PATCH 02/10] fix(metadata-protocol): the layered read naming no package refuses a name two served packages register, as the plain read does (ADR-0150 D3) getMetaItemLayered now asks the registry's package-scoped resolver for a type addressed by package, as getMetaItem does, before any layer is read: a name two or more served packages hold is refused naming each (PackageScopedNameRefusedError, 409 RESOURCE_CONFLICT), whatever the metadata service holds. Its code layer used to fall back to the artifact lookup's first composite, so the read in process, and the REST /layers door on a host with no engine wired, answered the holder that registered first. A name one holder holds keeps its layers; stored-row holders stay the door's step 1c. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../src/protocol-meta-layered-reads.ts | 15 +++ .../src/meta-layers-ambiguous-package.test.ts | 111 ++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts index b51f5bff21a..6866306e831 100644 --- a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts @@ -250,6 +250,21 @@ export async function getMetaItemLayered(host: Pick { + const ORDERS = [['alpha first', [PKG_A, PKG_B]], ['beta first', [PKG_B, PKG_A]]] as const; + /** The composition the door runs in: an engine wired for the door chain or not, and the metadata service's copy. */ + const SHAPES = [ + ['engine wired, no service copy', { wired: true, copy: false }], + ['no engine wired, no service copy', { wired: false, copy: false }], + ['no engine wired, a service copy of the first holder', { wired: false, copy: true }], + ] as const; + + async function registered(order: readonly string[], shape: { wired: boolean; copy: boolean }) { + // The partial copy: a `metadata` service holding the first holder's body only. + const copyOf = (pkg: string) => ({ name: 'sales', label: `${pkg} code`, widgets: [], _packageId: pkg }); + const services = shape.copy + ? new Map([['metadata', { get: async (type: string, name: string) => (type === 'dashboard' && name === 'sales' ? copyOf(order[0]) : undefined) }]]) + : undefined; + const h = makeHarness(services); + for (const pkg of order) { + h.registry.installPackage({ id: pkg, name: pkg, version: '1.0.0' } as any, 'code'); + h.registry.registerItem('dashboard', { name: 'sales', label: `${pkg} code`, widgets: [] } as any, 'name' as any, pkg); + } + h.registry.installPackage({ id: 'app.solo_demo', name: 'app.solo_demo', version: '1.0.0' } as any, 'code'); + h.registry.registerItem('dashboard', { name: 'solo', label: 'solo code', widgets: [] } as any, 'name' as any, 'app.solo_demo'); + const server = { + get: vi.fn(), post: vi.fn(), put: vi.fn(), delete: vi.fn(), patch: vi.fn(), use: vi.fn(), + listen: vi.fn().mockResolvedValue(undefined), close: vi.fn().mockResolvedValue(undefined), + }; + const rest = new RestServer(server as any, h.protocol as any, { api: { requireAuth: false } } as any); + (rest as any).resolveExecCtx = async () => AUTHOR; + if (shape.wired) (rest as any).objectQLProvider = async () => ({ registry: h.registry }); + rest.registerRoutes(); + const get = async (pattern: string, path: string, name: string, query: Record = {}) => { + const route = rest.getRoutes().find((r: any) => r.method === 'GET' && r.path === `${META}${pattern}`); + if (!route) throw new Error(`GET ${pattern} is not registered`); + const res = makeRes(); + await route.handler({ method: 'GET', path: `${META}${path}`, params: { type: 'dashboard', name }, query, body: {}, headers: {} }, res); + return { status: res.statusCode as number, body: res.body }; + }; + return { + ...h, + plain: (name: string) => get('/:type/:name', `/dashboard/${name}`, name), + spellings: (name: string, query: Record = {}) => [ + ['/layers', () => get('/:type/:name/layers', `/dashboard/${name}/layers`, name, query)], + ['?layers=true', () => get('/:type/:name', `/dashboard/${name}`, name, { ...query, layers: 'true' })], + ] as const, + }; + } + + const candidatesOf = (body: any) => [...(body?.details?.candidates ?? [])].map((c: any) => `${c.kind}:${c.packageId}`).sort(); + const BOTH = [`package:${PKG_A}`, `package:${PKG_B}`]; + + for (const [shapeLabel, shape] of SHAPES) { + it.each(ORDERS)(`${shapeLabel}, %s: both spellings answer the plain read's 409 with details.candidates, serving neither holder`, async (_label, order) => { + const host = await registered(order, shape); + const plain = await host.plain('sales'); + expect([plain.status, codeOf(plain)], JSON.stringify(plain.body)).toEqual([409, 'RESOURCE_CONFLICT']); + expect(candidatesOf(plain.body)).toEqual(BOTH); + for (const [spelling, read] of host.spellings('sales')) { + const refused = await read(); + expect([refused.status, codeOf(refused)], `${spelling}: ${JSON.stringify(refused.body)}`).toEqual([409, 'RESOURCE_CONFLICT']); + expect(candidatesOf(refused.body), spelling).toEqual(BOTH); + for (const pkg of order) expect(JSON.stringify(refused.body), spelling).not.toContain(`${pkg} code`); + } + }, 60_000); + } + + it.each(ORDERS)('in process, %s: the layered read refuses naming both, with or without a service copy', async (_label, order) => { + for (const [shapeLabel, shape] of SHAPES) { + const host = await registered(order, shape); + const refused: any = await host.protocol.getMetaItemLayered({ type: 'dashboard', name: 'sales' }).then( + (served) => ({ served }), + (error) => error, + ); + expect([refused?.code, refused?.status], `${shapeLabel}: ${JSON.stringify(refused?.served ?? refused?.message)}`) + .toEqual(['RESOURCE_CONFLICT', 409]); + expect([...(refused?.refusal?.candidates ?? [])].map((c: any) => `${c.kind}:${c.packageId}`).sort(), shapeLabel).toEqual(BOTH); + // Each holder's layers stay readable at its package. + for (const pkg of order) { + const scoped: any = await host.protocol.getMetaItemLayered({ type: 'dashboard', name: 'sales', packageId: pkg }); + expect(scoped.code?.label, `${shapeLabel}, ${pkg}`).toBe(`${pkg} code`); + } + } + }, 60_000); + + it('CONTROL: a name one package registers is served, in process and on both spellings', async () => { + for (const [shapeLabel, shape] of SHAPES) { + const host = await registered([PKG_A, PKG_B], shape); + const layered: any = await host.protocol.getMetaItemLayered({ type: 'dashboard', name: 'solo' }); + expect(layered.effective?.label, shapeLabel).toBe('solo code'); + for (const [spelling, read] of host.spellings('solo')) { + const served = await read(); + expect([served.status, served.body?.effective?.label], `${shapeLabel} ${spelling}: ${JSON.stringify(served.body)}`) + .toEqual([200, 'solo code']); + } + for (const [spelling, read] of host.spellings('sales', { package: PKG_B })) { + const served = await read(); + expect([served.status, served.body?.code?.label], `${shapeLabel} ${spelling} ?package=`).toEqual([200, `${PKG_B} code`]); + } + } + }, 60_000); +}); From d0a5dbd220519e9ee94b562d31c3249821534b71 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 10:08:05 +0000 Subject: [PATCH 03/10] chore(changeset): the layered read of a name two packages hold refuses as the plain read does Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../32622-layers-two-holders-candidates.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .changeset/32622-layers-two-holders-candidates.md diff --git a/.changeset/32622-layers-two-holders-candidates.md b/.changeset/32622-layers-two-holders-candidates.md new file mode 100644 index 00000000000..ea407d06171 --- /dev/null +++ b/.changeset/32622-layers-two-holders-candidates.md @@ -0,0 +1,16 @@ +--- +'@objectstack/metadata-protocol': patch +'@objectstack/rest': patch +--- + +fix(metadata-protocol, rest): the layered read of a name two packages hold refuses as the plain read does, naming the holders as `details.candidates` (ADR-0150 D3/D5) + +Clause-②: no +Metadata-protocol: none + +`GET /meta/:type/:name/layers` (and the deprecated `?layers=true`) of a name two or more packages hold, read naming no package, now answers like the plain read on every exit and on both transports: `409 RESOURCE_CONFLICT` with the holders as `details.candidates` (`[{ kind: 'package', packageId }, …]`), never one holder's layers. + +- A name two served packages register in code: the protocol's layered read (`getMetaItemLayered`) asks the registry's package-scoped resolver before it reads any layer, as `getMetaItem` does, so it throws the same `PackageScopedNameRefusedError` naming both, in process too, whatever the metadata service holds. It used to answer the holder that registered first, and so did the REST door on a host that wires no engine for its door chain. `?package=` still reads each holder's layers; a name one package holds is unchanged. +- The REST `/layers` route's catch carries the candidates of a package-scoped refusal, as the plain read's catch does. Before, it answered the refusal by its sentence alone (the dispatcher already carried them). +- A name whose active rows two packages hold keeps the package-less writes' refusal (its sentence, code, status and `?package=` remedy) and gains the same `details.candidates`. The save and delete doors' answer does not move. +- Stored-row holders beside a disabled package keep their in-process answer: the protocol's layered read still serves its in-process readers there, and the door refuses. From 6e50dbd5c79dc8352f7703b495cc5834187f6288 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 11:02:41 +0000 Subject: [PATCH 04/10] test(runtime): pay the metadata service's first load at collection in the layered ambiguity pins Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../runtime/src/domains/meta-layers-ambiguous-package.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts b/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts index 82ece2cb0e9..be4ad348543 100644 --- a/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts +++ b/packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts @@ -27,6 +27,8 @@ * `Request` into the real `HttpDispatcher.dispatch()`. */ +// Pays the metadata service's first load at collection, never inside a clocked case. +import '@objectstack/metadata'; import { describe, it, expect, afterEach } from 'vitest'; import { ObjectQL } from '@objectstack/objectql'; import { SqlDriver } from '@objectstack/driver-sql'; From fa7fb66a7cb99de027985268a47cf97c4435d6f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 14:00:50 +0000 Subject: [PATCH 05/10] changeset: declare the two-holder layered read refusal as a narrowing The no-engine REST /layers answer (200 with the first holder, now 409 with the holders as candidates) and the in-process getMetaItemLayered answer (first holder, now PackageScopedNameRefusedError) are narrowings of what a caller was served, so the changeset carries the narrowing arm, the BREAKING banner with both moves and the ADR-0087 disposition. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .changeset/32622-layers-two-holders-candidates.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.changeset/32622-layers-two-holders-candidates.md b/.changeset/32622-layers-two-holders-candidates.md index ea407d06171..a29e7945084 100644 --- a/.changeset/32622-layers-two-holders-candidates.md +++ b/.changeset/32622-layers-two-holders-candidates.md @@ -3,11 +3,22 @@ '@objectstack/rest': patch --- -fix(metadata-protocol, rest): the layered read of a name two packages hold refuses as the plain read does, naming the holders as `details.candidates` (ADR-0150 D3/D5) +fix(metadata-protocol, rest)!: the layered read of a name two packages hold refuses as the plain read does, naming the holders as `details.candidates` (ADR-0150 D3/D5) -Clause-②: no +Clause-②: no (narrowing) Metadata-protocol: none + + +**BREAKING** for a reader of the layers of a name two or more served packages register in code, naming no package. Such a name has no one holder (ADR-0150 D3/D5), and the plain read already refused it. Two answers move, measured in both registration orders: + +- FROM: on a host that wires no engine for the REST door chain, `GET /meta/:type/:name/layers` (and `?layers=true`) answered 200 with the layers of the holder that registered first. TO: it answers `409 RESOURCE_CONFLICT` naming both holders as `details.candidates`. +- FROM: in process, the protocol's `getMetaItemLayered({ type, name })` with no `packageId` resolved the holder that registered first. TO: it throws `PackageScopedNameRefusedError` (`RESOURCE_CONFLICT`, 409) naming both, as `getMetaItem` does. + +**Not moved.** A name one package holds, and every read naming the package (`?package=`, `packageId`), answer as before. On a host whose door chain has an engine, `/layers` already refused 409; it now also names the holders. The save and delete doors do not move. + +The fix for a caller: name the package whose layers it means. + `GET /meta/:type/:name/layers` (and the deprecated `?layers=true`) of a name two or more packages hold, read naming no package, now answers like the plain read on every exit and on both transports: `409 RESOURCE_CONFLICT` with the holders as `details.candidates` (`[{ kind: 'package', packageId }, …]`), never one holder's layers. - A name two served packages register in code: the protocol's layered read (`getMetaItemLayered`) asks the registry's package-scoped resolver before it reads any layer, as `getMetaItem` does, so it throws the same `PackageScopedNameRefusedError` naming both, in process too, whatever the metadata service holds. It used to answer the holder that registered first, and so did the REST door on a host that wires no engine for its door chain. `?package=` still reads each holder's layers; a name one package holds is unchanged. From e516f3534bd5f0d4eb74c140f8da53b2d4ec31ff Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 15:09:11 +0000 Subject: [PATCH 06/10] docs(metadata-protocol): the layered read refusal docblock names its candidates and the registry judgment packagelessLayeredReadRefusal's docblock now says its refusal carries the holders as a package-scoped refusal, and that the in-process readers of getMetaItemLayered meet the registry's refusal of a name two packages register in code. Comment only; the emitted JS differs in comment lines alone. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- packages/metadata-protocol/src/protocol.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index 1affb8b7198..b5b0bf5adf9 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -4208,7 +4208,9 @@ export class ObjectStackProtocolImplementation implements * `409 RESOURCE_CONFLICT`, the holders sorted and the `?package=` * prescription), asked of the same resolution * ({@link packagelessAddress} at `active`, at the addressed bundle member, - * read in full): one answer to one ambiguity. `undefined` for a name one + * read in full): one answer to one ambiguity. [#32622] It also carries + * its holders as a package-scoped refusal (`refusal.candidates`), so both + * transports answer them as `details.candidates`. `undefined` for a name one * package holds, none does, or only the package-unbound row does, and for * every request that names a package (the caller asks only without one). * @@ -4222,7 +4224,10 @@ export class ObjectStackProtocolImplementation implements * `createMetaLayeredAnswer`), ⛔ never inside {@link getMetaItemLayered}: * its in-process resolution readers (the security catalog echo, the * packaged-permission-set lock gate, `/published`) read the layers of a - * name with no package and keep the answer they had. + * name with no package and keep the answer they had. [#32914] Those + * readers do meet the registry's own refusal of a name two packages + * register in code, which {@link getMetaItemLayered} asks as + * `getMetaItem` does. * * [#32354, ADR-0150 D3] While a package is disabled, a name the stored * rows of two or more served packages hold beside it is refused here From 113f19244dfb7ed7dfa53bd2449c43d65bc67cfb Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:27:23 +0000 Subject: [PATCH 07/10] fix(metadata-protocol): the bare layered read serves a member's declared override as effective, as the plain read does The layered read naming no package takes the address the plain read takes for a bundle member whose one shipper's declared override is stored (declaredMemberOverrideAddressOf, now exported from the item face), so `effective` is the override `?package=` serves instead of the shipper's own member. The draft layer stays at the strict draft read's address, which that arm does not move. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../src/protocol-meta-item-face.ts | 5 +- .../src/protocol-meta-layered-reads.ts | 24 ++++- .../package-scoped-exact-qualifier.test.ts | 91 +++++++++++++++++++ 3 files changed, 113 insertions(+), 7 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index ec8a3e1c1ea..f6bac9b63a7 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -422,9 +422,10 @@ export function isAnotherHoldersCopy(registry: any, type: string, name: string, * another package (the #32606 shape), an undeclared pair row, the * environment's own item, a disabled shipper, and the strict draft read. * The rows are read through `host.readItemActiveRows`, so the read below takes - * them instead of reading them again (#24371). + * them instead of reading them again (#24371). The layered read naming no + * package takes the same address for its layers (`getMetaItemLayered`). */ -async function declaredMemberOverrideAddressOf( +export async function declaredMemberOverrideAddressOf( host: ServedRowHost, type: string, name: string, member: string | undefined, ): Promise { diff --git a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts index 6866306e831..70eb6082836 100644 --- a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts @@ -78,7 +78,7 @@ import { boundPackageOf, withRowBinding } from './protocol-package-bindings.js'; import type { RowlessExpandedView } from './protocol-stored-overlay-types.js'; import { type ServedOverrideRow, isServedOverrideRowOf } from './served-override.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; -import { isAnotherHoldersCopy, servedAddressJudgment } from './protocol-meta-item-face.js'; +import { declaredMemberOverrideAddressOf, isAnotherHoldersCopy, servedAddressJudgment } from './protocol-meta-item-face.js'; import { packagelessAddressAmbiguityRefusal } from './sys-metadata-repository.js'; /** The body of `ObjectStackProtocolImplementation#packagelessLayeredReadRefusal`; the method's docblock there is its contract. */ @@ -216,6 +216,18 @@ export async function getMetaItemLayered(host: Pick` serves, never the + // shipper's own member beside it. The draft layer stays at the address the + // strict draft read takes, which this arm does not move (the plain read + // leaves its strict draft read where it was). + const declaredOverrideAt = request.packageId || judged !== undefined + ? undefined + : await declaredMemberOverrideAddressOf(host, request.type, request.name, resolveBundleMemberSelector(request.type, request.member)); + const draftPackageId = request.packageId; + if (declaredOverrideAt !== undefined) request = { ...request, packageId: declaredOverrideAt }; // [#26699] Ruling 6116165299 (Q2 i), extended to this read by the // option-A ruling on #26649: ONE member of a bundled type, the // selector's or else the canonical one, read exactly as @@ -647,7 +659,7 @@ export async function getMetaItemLayered(host: Pick { + const APP = 'com.acme.suite'; + const X = 'com.acme.suitex'; + const Z = 'com.acme.zeta'; + const PAIR = `${APP}.custom`; + const moduleOf = (id: string, dependencies: Record) => ({ + id, name: id, version: '1.0.0', type: 'module', namespace: id.split('.').pop()!, dependencies, + }) as never; + const installZ = () => registry.installPackage(moduleOf(Z, { [APP]: '^1.0.0', [X]: '^1.0.0' }), 'code'); + const tpl = (locale: string, packageId: string) => registry.registerItem('email_template', { + name: 'welcome', label: `${packageId.split('.').pop()} ${locale}`, locale, + subject: `${packageId.split('.').pop()} ${locale}`, bodyHtml: '

x

', + }, 'name' as never, packageId); + /** A row of the App's pair for `fr-FR`; an active one is hydrated as the boot lays it. */ + const pairRow = (over: Record = {}, state: 'active' | 'draft' = 'active') => { + const body = { name: 'welcome', label: state === 'draft' ? 'pair fr-FR draft' : 'pair fr-FR', locale: 'fr-FR', subject: 'pair fr-FR', bodyHtml: '

p

', ...over }; + rows.push({ id: `row_fr_${state}`, type: 'email_template', name: 'welcome', state, package_id: PAIR, bundle_member: 'fr-FR', metadata: JSON.stringify(body) }); + if (state === 'active') registry.registerItem('email_template', { ...body, _packageId: PAIR, _provenance: 'org' }, 'name' as never); + }; + type Layers = { code?: { label?: string } | null; overlay?: { label?: string } | null; effective?: { label?: string; _packageId?: string } | null; draft?: { label?: string } | null; packageId?: string }; + const layered = (member: string, packageId?: string, withDraft = false) => protocol.getMetaItemLayered({ + type: 'email_template', name: 'welcome', member, ...(packageId ? { packageId } : {}), + } as never, { withDraft } as never) as Promise; + const layersOf = (a: Layers) => [a.code?.label ?? null, a.overlay?.label ?? null, a.effective?.label ?? null, a.packageId]; + + beforeEach(() => { + registry.installPackage(manifest(APP), 'code'); + registry.installPackage(moduleOf(X, { [APP]: '^1.0.0' }), 'code'); + registry.installPackage(manifest(PAIR), 'code'); + }); + + it.each([ + ['addition installed first', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); pairRow({ overrides: { package: Z } }); }], + ['row stored first', () => { tpl('en-US', X); pairRow({ overrides: { package: Z } }); installZ(); tpl('fr-FR', Z); }], + ] as const)('the bare layered read of `fr-FR` answers Z\'s layers with the override as `effective` (%s; BASE: `effective` `zeta fr-FR`, no overlay)', async (_order, arrange) => { + arrange(); + const atZ = await layered('fr-FR', Z); + expect(layersOf(atZ), 'CONTROL: `?package=Z&member=fr-FR&layers=true` (UNCHANGED)').toEqual(['zeta fr-FR', 'pair fr-FR', 'pair fr-FR', Z]); + expect(await protocol.packagelessLayeredReadRefusal({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never), 'the door\'s step 1c refuses nothing').toBeUndefined(); + const bare = await layered('fr-FR'); + expect(layersOf(bare), 'bare `?member=fr-FR&layers=true`').toEqual(['zeta fr-FR', 'pair fr-FR', 'pair fr-FR', Z]); + expect(bare.effective?._packageId, '`effective` is stamped Z').toBe(Z); + expect(labelOf(await protocol.getMetaItem({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never)), '`effective` is what the plain bare read serves').toBe('pair fr-FR'); + // CONTROL: X's own member is untouched by the override of Z's. + expect(layersOf(await layered('en-US')), 'bare `?member=en-US` (UNCHANGED)').toEqual(['suitex en-US', null, 'suitex en-US', X]); + }); + + it('the draft layer stays the strict draft read\'s, which the arm does not move: the pair\'s pending draft of `fr-FR` (UNCHANGED; at Z\'s address it is no draft)', async () => { + installZ(); tpl('en-US', X); tpl('fr-FR', Z); + pairRow({ overrides: { package: Z } }); + pairRow({ overrides: { package: Z } }, 'draft'); + const strictDraft = labelOf(await protocol.getMetaItem({ type: 'email_template', name: 'welcome', member: 'fr-FR', state: 'draft' } as never)); + expect(strictDraft, 'the plain bare strict draft read').toBe('pair fr-FR draft'); + const bare = await layered('fr-FR', undefined, true); + expect([bare.effective?.label, bare.draft?.label ?? null], 'bare `?member=fr-FR&layers=true` with drafts').toEqual(['pair fr-FR', strictDraft]); + expect((await layered('fr-FR', Z, true)).draft ?? null, 'CONTROL: `?package=Z` reads no draft there (UNCHANGED)').toBeNull(); + }); + + it.each([ + ['no row stored', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); }], + ['an undeclared pair row of the locale', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); pairRow(); }], + ] as const)('CONTROL — no override of Z declared (%s): the bare layered read answers Z\'s own `fr-FR` and no overlay (UNCHANGED)', async (_order, arrange) => { + arrange(); + expect(layersOf(await layered('fr-FR'))).toEqual(['zeta fr-FR', null, 'zeta fr-FR', Z]); + }); + + it('CONTROL — the row declares X (the #32606 shape): the bare layered read is not moved to Z, and keeps its refusal naming both (UNCHANGED)', async () => { + installZ(); tpl('en-US', X); tpl('fr-FR', Z); + pairRow({ overrides: { package: X } }); + const err = await refusalOf(() => layered('fr-FR')); + expect([err.code, err.status, err.refusal.candidates.map((c) => (c as { packageId?: string }).packageId).sort()]) + .toEqual(['RESOURCE_CONFLICT', 409, [X, Z].sort()]); + }); +}); + /** * [#32183, epic rulings R4-B and R4-B2] A name only a disabled package holds, * read at an address that neither holds it nor is a pair of a holder (a From 880bcc4c18ce442612ed163be8690261c48c0f3c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:36:46 +0000 Subject: [PATCH 08/10] chore(changeset): the bare layered read serves a member's declared override as effective Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../32849-bare-layered-read-declared-override.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/32849-bare-layered-read-declared-override.md diff --git a/.changeset/32849-bare-layered-read-declared-override.md b/.changeset/32849-bare-layered-read-declared-override.md new file mode 100644 index 00000000000..90be42dd06f --- /dev/null +++ b/.changeset/32849-bare-layered-read-declared-override.md @@ -0,0 +1,12 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol): the layered read naming no package serves an App pair's declared override of a bundle addition's own member as `effective` + +Clause-②: no +Metadata-protocol: none + +An App's customization pair (`.custom`) can store a row that declares `overrides: { package: Z }` for the bundle member a bundle addition Z ships, for example the `fr-FR` locale Z adds to an email template another package of the App ships in `en-US`. The plain read naming no package (`?member=fr-FR`) and `?package=Z&member=fr-FR&layers=true` already served that row. The layered read naming no package (`?member=fr-FR&layers=true`, `getMetaItemLayered` without a package) answered Z's shipped `fr-FR` as `effective`, with no `overlay`, and so disagreed with the read it describes. + +It now reads such a member at the one enabled package that ships it, as the plain read does: `code` is Z's shipped member, `overlay` the pair's row, `effective` the override, and the envelope names Z. The pending draft layer stays the one the strict draft read serves. Nothing else moves: a member two packages ship, a row declaring another package, an undeclared pair row, the environment's own item and a disabled shipper answer as before. No stored row changes shape. From e57e7c05668dc6989a54f4ff616a6e5a0002498e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 17:56:50 +0000 Subject: [PATCH 09/10] changeset: declare the REST /published move; docblock @throws for the two-holder refusal The changeset's BREAKING banner gains a third FROM/TO. A bare GET /meta/:type/:name/published on a REST host with no objectQLProvider went on to its published exit and now answers 409 without candidates. The getMetaItemLayered docblock names the PackageScopedNameRefusedError it throws for a name two packages register in code. Comment and prose only. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .changeset/32622-layers-two-holders-candidates.md | 3 ++- packages/metadata-protocol/src/protocol.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.changeset/32622-layers-two-holders-candidates.md b/.changeset/32622-layers-two-holders-candidates.md index a29e7945084..1f9db8947af 100644 --- a/.changeset/32622-layers-two-holders-candidates.md +++ b/.changeset/32622-layers-two-holders-candidates.md @@ -10,10 +10,11 @@ Metadata-protocol: none -**BREAKING** for a reader of the layers of a name two or more served packages register in code, naming no package. Such a name has no one holder (ADR-0150 D3/D5), and the plain read already refused it. Two answers move, measured in both registration orders: +**BREAKING** for a reader of the layers, or of the REST published view, of a name two or more served packages register in code, naming no package. Such a name has no one holder (ADR-0150 D3/D5), and the plain read already refused it. Three answers move, measured in both registration orders: - FROM: on a host that wires no engine for the REST door chain, `GET /meta/:type/:name/layers` (and `?layers=true`) answered 200 with the layers of the holder that registered first. TO: it answers `409 RESOURCE_CONFLICT` naming both holders as `details.candidates`. - FROM: in process, the protocol's `getMetaItemLayered({ type, name })` with no `packageId` resolved the holder that registered first. TO: it throws `PackageScopedNameRefusedError` (`RESOURCE_CONFLICT`, 409) naming both, as `getMetaItem` does. +- FROM: on a REST host with no `objectQLProvider`, `GET /meta/:type/:name/published` went on past its overlay read to the published exit: what the host's metadata service `getPublished` answers, or `501 NOT_IMPLEMENTED` when the host resolves no metadata service. TO: it answers `409 RESOURCE_CONFLICT`, without `details.candidates`. The dispatcher's `/published` swallows the same refusal and still serves its snapshot. **Not moved.** A name one package holds, and every read naming the package (`?package=`, `packageId`), answer as before. On a host whose door chain has an engine, `/layers` already refused 409; it now also names the holders. The save and delete doors do not move. diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index b5b0bf5adf9..2b0b97425ee 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -4292,6 +4292,10 @@ export class ObjectStackProtocolImplementation implements * layer's MetadataService read reporting `degraded` with nothing * in the registry to answer instead, carrying the failing loaders' * messages on `cause`. + * @throws `PackageScopedNameRefusedError` — [#32914, ADR-0150 D3/D5] 409 / + * `RESOURCE_CONFLICT`, naming no package, for a name two or more + * served packages register in code: the registry's own refusal, as + * {@link getMetaItem} throws it, before any layer is read. * * [#29814] `opts.withDraft` adds the `draft` layer * (`GetMetaItemLayeredResponseSchema.draft`): the pending draft row the From 96a0a52e20debdbe9f89a64066a1a84a46a36508 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 18:07:31 +0000 Subject: [PATCH 10/10] test(objectql): pin the bare layered read's effective to the document the shipper's address serves Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- packages/objectql/src/package-scoped-exact-qualifier.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index 82bac7a184b..3c37e2a4b17 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -1333,7 +1333,7 @@ describe('[#32849] the bare layered read serves the pair\'s declared override of expect(await protocol.packagelessLayeredReadRefusal({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never), 'the door\'s step 1c refuses nothing').toBeUndefined(); const bare = await layered('fr-FR'); expect(layersOf(bare), 'bare `?member=fr-FR&layers=true`').toEqual(['zeta fr-FR', 'pair fr-FR', 'pair fr-FR', Z]); - expect(bare.effective?._packageId, '`effective` is stamped Z').toBe(Z); + expect(bare.effective, '`effective` is the document `?package=Z` serves').toEqual(atZ.effective); expect(labelOf(await protocol.getMetaItem({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never)), '`effective` is what the plain bare read serves').toBe('pair fr-FR'); // CONTROL: X's own member is untouched by the override of Z's. expect(layersOf(await layered('en-US')), 'bare `?member=en-US` (UNCHANGED)').toEqual(['suitex en-US', null, 'suitex en-US', X]);