From 0571f19254e5a553610ac0fe8d4fa17a111696cc Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:58:07 +0000 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 e57e7c05668dc6989a54f4ff616a6e5a0002498e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 17:56:50 +0000 Subject: [PATCH 7/8] 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 53ca1e7bde141ca895e61e6dd29d24bf39a1033a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 22:14:23 +0000 Subject: [PATCH 8/8] test(rest), changeset: pin the other /layers refusal exits' candidates; declare the stored-row /published move Two REST /layers exits now carry details.candidates through the route's catch: the bare action read weighing the package-less holder, and the exact qualifier of a package holding none. Each is pinned against the item read's candidates. The stale comment that said /layers carries the refusal's text only is corrected. The changeset's /published row adds a state. A name with a package-unbound active row, on a REST host with no objectQLProvider, was served that row (200) and is now refused 409. The dispatcher sentence now covers that state: it moves from the row to the code snapshot. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ --- .../32622-layers-two-holders-candidates.md | 2 +- .../src/meta-qualified-item-route.test.ts | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.changeset/32622-layers-two-holders-candidates.md b/.changeset/32622-layers-two-holders-candidates.md index 1f9db8947af..895343bd0e4 100644 --- a/.changeset/32622-layers-two-holders-candidates.md +++ b/.changeset/32622-layers-two-holders-candidates.md @@ -14,7 +14,7 @@ Metadata-protocol: none - 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. +- FROM: on a REST host with no `objectQLProvider`, `GET /meta/:type/:name/published` served the name's package-unbound active row (200) when one stands. With no such row, it 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`, where its engine registry is not reachable, swallows the same refusal. With no such row it serves its snapshot as before. With one, it served that row and now serves the code snapshot instead. **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/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index b794c6ec928..4cf643d022f 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -834,7 +834,7 @@ describe('#32365 — the bare action read weighs the package-less holder and ser expect(messageOf(answer)).toContain('The platform\'s item binds it to object "contact"'); const layers = await drive(LAYERS, { type: 'action', name: 'approve' }); expect([layers.status, codeOf(layers)], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']); - // `/layers` and `/published` carry the refusal's text, not its candidates. + // `/layers` carries the refusal's candidates too (#32622, pinned below); `/published` carries its text, not its candidates. const published = await drive(PUBLISHED, { type: 'action', name: 'approve' }); expect([published.status, codeOf(published)], JSON.stringify(published.body)).toEqual([409, 'RESOURCE_CONFLICT']); expect(messageOf(published)).toContain(`package "${A}"`); @@ -868,6 +868,40 @@ describe('#32365 — the bare action read weighs the package-less holder and ser }); }); +/** + * [#32622, ADR-0150 D5] The two `/layers` refusal exits of this route that the + * candidates option reaches beyond the two-holder read: the bare action read + * weighing the package-less holder, and the exact qualifier of a package that + * holds nothing. Each answers the plain read's `details.candidates`. + */ +describe('#32622 — the other `/layers` refusal exits carry `details.candidates`', () => { + const LAYERS = '/api/v1/meta/:type/:name/layers'; + const pkg = (packageId: string) => ({ kind: 'package', packageId }); + const conflictOf = (answer: { status: number; body?: any }) => + [answer.status, codeOf(answer), answer.body?.details?.candidates]; + + it('the bare action read, the platform\'s item beside A\'s: `/layers` names A and the platform, as the item read does', async () => { + const shipAction = (packageId: string | undefined, objectName: string) => registry.registerItem('action', { + name: 'approve', label: packageId?.split('.').pop() ?? 'platform', type: 'script', objectName, target: 'approve', + body: { language: 'js', source: 'return 1;', capabilities: [] }, + }, 'name' as never, packageId); + shipAction(A, 'account'); + shipAction(undefined, 'contact'); + const plain = await drive(ITEM, { type: 'action', name: 'approve' }); + const layers = await drive(LAYERS, { type: 'action', name: 'approve' }); + expect(conflictOf(layers), JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT', [pkg(A), { kind: 'platform' }]]); + expect(layers.body?.details?.candidates).toEqual(plain.body?.details?.candidates); + }); + + it('`/layers?package=` of a package that holds nothing: the holder, as the item read does', async () => { + ship('page', 'home', A); + const plain = await drive(ITEM, { type: 'page', name: 'home' }, { package: C }); + const layers = await drive(LAYERS, { type: 'page', name: 'home' }, { package: C }); + expect(conflictOf(layers), JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT', [pkg(A)]]); + expect(layers.body?.details?.candidates).toEqual(plain.body?.details?.candidates); + }); +}); + /** * [#32501, ADR-0150 D5, epic red line 2] An exact address reads one package, * and its answer names that package: its envelope (`_packageId`) and, on