From 3bc64553fa41fe7edadffbbfc6d0f3c570c69542 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 12:23:30 +0000 Subject: [PATCH 1/4] fix(metadata-protocol)!: refuse a bare write over the package-unbound row of a name only disabled packages hold WIP: the holder refusal reads past the package-unbound row for the disabled-holders judgment (ADR-0150 D3), with the enable as the remedy; pins for the four write doors on both transports and registration orders. Claude-Session: https://claude.ai/code/session_01L6bhgWSCg5Qjw8A76bTFD6 Co-authored-by: Claude --- .../src/protocol-diff-delete-load.ts | 21 ++- .../metadata-protocol/src/protocol-save.ts | 99 +++++++++-- .../meta-disabled-holder-served-stack.test.ts | 165 +++++++++++++++--- 3 files changed, 247 insertions(+), 38 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-diff-delete-load.ts b/packages/metadata-protocol/src/protocol-diff-delete-load.ts index 1c2294d6482..f03bd9d13e3 100644 --- a/packages/metadata-protocol/src/protocol-diff-delete-load.ts +++ b/packages/metadata-protocol/src/protocol-diff-delete-load.ts @@ -754,11 +754,26 @@ export class ProtocolDiffDeleteLoadFacet { // are refused naming them, and a name only disabled packages hold // is refused naming none, never one row removed. Over no stored // row too (the delete and the draft discard answered the no-op - // receipt). A package-unbound row at the address is the - // environment's own, and its removal is left as it was. + // receipt). A package-unbound row at the address of a name + // an enabled package holds, or no package holds, is removed + // as it was. + // + // [ADR-0150 D3, the 2026-11-26 note] …but a package-unbound + // row or draft of a name ONLY disabled packages hold is + // their customization, hidden with them: the delete and the + // draft discard are refused, with the enable as the remedy. + // The delete removed the hidden row, so the next enable + // served the package's item without it. A draft discard + // reads the draft rows, so it asks whether the customization + // is the ACTIVE row too: with no draft stored it answers + // that remedy, never `?package=`. if (request.packageId == null) { + const customized = targetState === 'draft' && !rowsAtAddress.unbound + ? (await host.packagelessAddress(singularTypeForRepo, request.name, member, 'active')).unbound + : false; const holderRefusal = packagelessHolderRefusal( - host, 'delete', request.type, singularTypeForRepo, request.name, member, rowsAtAddress, + host, 'delete', request.type, singularTypeForRepo, request.name, member, + customized ? { ...rowsAtAddress, customized } : rowsAtAddress, ); if (holderRefusal) { addressRefusal = holderRefusal; diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 6c4d09bb3b0..36abce428e6 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -851,6 +851,18 @@ export class ProtocolSaveFacet { // The package-unbound row: `packageId` stays empty. } else if (served !== undefined) { if (served.packageId !== null) request = { ...request, packageId: served.packageId }; + else { + // [ADR-0150 D3, the 2026-11-26 note] The package-unbound + // row beside a disabled package's row is the row the read + // serves only while an enabled package holds the name. + // With every holder disabled it is their customization, + // hidden with them, and the save is refused, never + // written unseen ({@link packagelessHolderRefusal}). + const hiddenRefusal = packagelessHolderRefusal( + host, 'save', request.type, writeType, request.name, member, address, + ); + if (hiddenRefusal) throw hiddenRefusal; + } } else if (address.candidates.length > 1) { // [#34681] …where the read naming no package serves the // row-held base, the save writes the base's row @@ -864,7 +876,9 @@ export class ProtocolSaveFacet { // read naming no package counts ({@link packagelessHolderRefusal}): // two or more enabled holders are refused naming them, and a name // only disabled packages hold is refused naming none, never - // written at one row's package or as a new package-unbound row. + // written at one row's package or as a new package-unbound row, + // nor over the package-unbound row stored for it (their + // customization, hidden with them: the enable is the remedy). const holderRefusal = packagelessHolderRefusal( host, 'save', request.type, writeType, request.name, itemDiscriminator(writeType, request.item), address, ); @@ -945,7 +959,9 @@ export class ProtocolSaveFacet { // ({@link packagelessHolderRefusal}), judged over the item's active rows // and its drafts: the draft address alone took the one package with a // row, or a new package-unbound draft. An ambiguous draft address is - // left to the repository's `409`, as before. + // left to the repository's `409`, as before. A package-unbound row or + // draft of a name only disabled packages hold is their customization: + // the draft save is refused there too, with the enable as its remedy. if (draftAddress !== undefined && draftAddress.kind !== 'ambiguous') { const member = itemDiscriminator(singularType, request.item); const active = await host.packagelessAddress(singularType, request.name, member, 'active'); @@ -3251,6 +3267,41 @@ export function disabledHoldersOnlyRefusal( return err; } +/** + * [ADR-0150 D3, the 2026-11-26 note under it] The refusal of a write naming + * no package of a name every holder of which is disabled, where a + * PACKAGE-UNBOUND row or draft is stored for the name. That row is the + * holder's customization (a package-less row over a held name is never a + * second item), so it is hidden with its holder, from the reads and from the + * writes alike: the save edited it unseen, the draft save stored a draft no + * read reaches, and the delete and the draft discard removed what the next + * enable would have served. + * + * `409 RESOURCE_CONFLICT`, the refusal family of + * {@link disabledHoldersOnlyRefusal}, with no new code, and naming no package + * as that one does. Its remedy is the enable, never `?package=`: a write + * naming the package addresses that package's own row, so it leaves the + * hidden row where it is and stores a second row beside it. + */ +export function disabledHoldersCustomizationRefusal( + verb: 'save' | 'delete', + type: string, + name: string, +): Error & { code: 'RESOURCE_CONFLICT'; status: 409 } { + const nothing = verb === 'save' ? 'Nothing was written.' : 'Nothing was deleted.'; + const err = new Error( + `Enable the package that holds ${type} '${name}' first, then send this ${verb} again: GET /api/v1/packages ` + + `lists each installed package with whether it is enabled, and PATCH /api/v1/packages/:id/enable enables one. ` + + `${nothing} Every package that holds the name is disabled, and the row stored for it under no package is ` + + `that package's customization, hidden with it until the package is enabled, so no read would show this ` + + `${verb}. Naming the package (?package=, in process packageId) does not reach that row: it addresses the ` + + `package's own row beside it.`, + ) as Error & { code: 'RESOURCE_CONFLICT'; status: 409 }; + err.code = 'RESOURCE_CONFLICT'; + err.status = 409; + return err; +} + /** * [#34681, epic ruling 6781691009, #34348 ruling (b), ADR-0150 D3/D5] THE * ROW-HELD BASE a write naming no package takes, where the stored rows at the @@ -3417,10 +3468,21 @@ export async function packagelessRowHeldBaseDraftAddress( * customization pair is that holder's): {@link disabledHoldersOnlyRefusal}, * naming no package. The write edited the disabled package's row, or * stored a row every read then withholds. - * - `undefined` otherwise: no holder, one enabled holder, a package-unbound - * row stored at the address or the environment's own item (ADR-0150 D3 - * (a): the row the write edits), a type the registry does not read by - * package, or a registry without the reads. + * - …and a package-unbound row or draft is stored for the name + * (`address.unbound`, or `address.customized` for a door whose own rows + * are another state's): that row is the disabled holder's customization, + * hidden with it, so the write is refused all the same, with the enable + * as its remedy ({@link disabledHoldersCustomizationRefusal}; the dated + * note under ADR-0150 D3). The bare save edited the hidden row, the bare + * draft save stored a draft no read reaches, and the bare delete and the + * bare draft discard removed what the next enable would have served. + * - `undefined` otherwise: no holder (a name the environment alone holds, + * whatever row is stored for it), one enabled holder, the environment's + * own item (ADR-0150 D3 (a): the row the write edits), a package-unbound + * row at the address of a name some ENABLED package holds (the row the + * read serves, or the customization of no one holder two enabled holders + * leave to the write), a type the registry does not read by package, or a + * registry without the reads. * * Known gap: with an enabled and a disabled holder, the draft save and the * delete have no {@link servedPackagelessSaveAddress} step and still take @@ -3434,15 +3496,27 @@ export function packagelessHolderRefusal( type: string, name: string, member: string | undefined, - address: { readonly candidates: readonly string[]; readonly unbound: boolean }, + address: { + readonly candidates: readonly string[]; + readonly unbound: boolean; + /** + * A package-unbound row is stored for the name in a state other than + * the one `candidates` and `unbound` were read from (the draft + * discard's: its own rows are the drafts, and the customization may + * be the active row). Read by the disabled-holders judgment only. + */ + readonly customized?: boolean; + }, ): (Error & { code: 'RESOURCE_CONFLICT'; status: 409 }) | undefined { - if (address.unbound) return undefined; const registry = host.engine?.registry as HolderRegistry | undefined; if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined; if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) { return undefined; } - if (typeof registry.resolveItem === 'function') { + // A package-unbound row at the address leaves the ENABLED holders' answer + // as it was (the write edits that row); only the disabled-holders + // judgment below reads past it. + if (!address.unbound && typeof registry.resolveItem === 'function') { try { registry.resolveItem(type, name, null, member); } catch (error) { @@ -3464,7 +3538,12 @@ export function packagelessHolderRefusal( const disabledHoldersPair = (id: string): boolean => known.some((holder) => disabled(holder) && pairsOf(holder, installed).includes(id)); const every = [...new Set([...known, ...address.candidates])]; if (every.length === 0 || every.some((id) => !disabled(id) && !disabledHoldersPair(id))) return undefined; - return disabledHoldersOnlyRefusal(verb, shownType, name); + // [ADR-0150 D3, the 2026-11-26 note] A package-unbound row of a name only + // disabled packages hold is their customization, hidden with them: the + // write is refused with the enable as its remedy, never `?package=`. + return address.unbound || address.customized === true + ? disabledHoldersCustomizationRefusal(verb, shownType, name) + : disabledHoldersOnlyRefusal(verb, shownType, name); } /** The registry reads {@link packagelessHolderRefusal} asks, each optional-called. */ 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 cd5b6b6f86f..ce315fe228a 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 @@ -1110,7 +1110,9 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol const E_SHIPS = ['e_only_dash', 'e_authored_drow_dash', 'e_unbound_drow_dash', 'e_two_authored_dash']; // [#33955] Names two ENABLED packages ship (neither disabled), and [#34144] names only D ships. const TWO_SHIP = ['two_none_dash', 'two_erow_dash', 'two_drow_dash', 'two_rows_dash', 'two_unbound_dash', 'two_draft_dash', 'two_del_dash', 'two_norow_dash']; - const D_SHIPS = ['d_none_dash', 'd_drow_dash', 'd_unbound_dash', 'd_draft_dash', 'd_del_dash', 'd_norow_dash']; + const D_SHIPS = ['d_none_dash', 'd_drow_dash', 'd_unbound_dash', 'd_draft_dash', 'd_del_dash', 'd_norow_dash', + // [ADR-0150 D3, the 2026-11-26 note] Names only D ships, each with a package-unbound row or draft stored. + 'd_unbound_hidden_draft_dash', 'd_unbound_draft_only_dash', 'd_unbound_drow_dash']; const MAIL = 'save_beta_welcome'; const mailAt = (locale: string, subject: string) => ({ name: MAIL, label: 'Welcome', locale, subject, bodyHtml: `

${subject}

` }); const savePackageOf = (id: string) => ({ @@ -1120,7 +1122,15 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol ...(id === CODE_D ? { emailTemplates: [mailAt('en-US', 'D en')] } : {}), }); - interface SaveBooted extends Booted { put(name: string, label: string, query?: Record): Promise<{ status: number | undefined; body: any }> } + interface SaveBooted extends Booted { + put(name: string, label: string, query?: Record): Promise<{ status: number | undefined; body: any }>; + /** + * The delete (`state: 'draft'`: the draft discard) naming no package. The REST door is + * `DELETE /api/v1/meta/:type/:name`; the dispatcher mounts no `DELETE` on a metadata item + * (it answers 405), so on that arm this is the protocol call the REST door makes. + */ + del(name: string, state?: 'draft'): Promise<{ status: number | undefined; body: any }>; + } async function bootSaveKernel(order: readonly string[], transport: 'dispatcher' | 'rest'): Promise { const kernel = new ObjectKernel({ logger: { level: 'silent' }, gracefulShutdown: false }); @@ -1147,6 +1157,14 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol if (transport === 'dispatcher') { return { kernel, engine, root, + del: async (name, state) => { + try { + return { status: 200, body: await kernel.getService('protocol').deleteMetaItem({ type: 'dashboard', name, ...(state ? { state } : {}) }) }; + } catch (e) { + const thrown = resolveThrownHttpError(e); + return { status: thrown.status, body: { error: { code: thrown.code, message: String((e as Error)?.message ?? '') } } }; + } + }, put: async (name, label, query = {}) => { const dispatcher = new HttpDispatcher(kernel as any, undefined, { enforceProjectMembership: false }); (dispatcher as any).timedResolveExecutionContext = async () => ({ ...CALLER }); @@ -1170,24 +1188,31 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol rest.registerRoutes(); const route = rest.getRoutes().find((r: any) => r.method === 'PUT' && r.path === '/api/v1/meta/:type/:name'); if (!route) throw new Error('PUT /api/v1/meta/:type/:name is not registered'); + const deleteRoute = rest.getRoutes().find((r: any) => r.method === 'DELETE' && r.path === '/api/v1/meta/:type/:name'); + if (!deleteRoute) throw new Error('DELETE /api/v1/meta/:type/:name is not registered'); rest.resolveExecCtx = async () => ({ ...CALLER }); + const answerOf = async (handler: (req: any, res: any) => Promise, req: Record) => { + const res: any = { statusCode: 200, body: undefined, headers: {} as Record }; + res.status = (code: number) => { res.statusCode = code; return res; }; + res.json = (payload: any) => { res.body = payload; return res; }; + res.send = () => res; + res.end = () => res; + res.header = (k: string, v: string) => { res.headers[k] = v; return res; }; + res.setHeader = () => {}; + res.write = () => true; + await handler(req, res); + return { status: res.statusCode as number, body: res.body }; + }; return { kernel, engine, root, - put: async (name, label, query = {}) => { - const res: any = { statusCode: 200, body: undefined, headers: {} as Record }; - res.status = (code: number) => { res.statusCode = code; return res; }; - res.json = (payload: any) => { res.body = payload; return res; }; - res.send = () => res; - res.end = () => res; - res.header = (k: string, v: string) => { res.headers[k] = v; return res; }; - res.setHeader = () => {}; - res.write = () => true; - await route.handler({ - method: 'PUT', path: `/api/v1/meta/dashboard/${name}`, params: { type: 'dashboard', name }, - headers: {}, query, body: body(name, label), - }, res); - return { status: res.statusCode, body: res.body }; - }, + put: (name, label, query = {}) => answerOf(route.handler, { + method: 'PUT', path: `/api/v1/meta/dashboard/${name}`, params: { type: 'dashboard', name }, + headers: {}, query, body: body(name, label), + }), + del: (name, state) => answerOf(deleteRoute.handler, { + method: 'DELETE', path: `/api/v1/meta/dashboard/${name}`, params: { type: 'dashboard', name }, + headers: {}, query: state ? { state } : {}, + }), }; } @@ -1217,6 +1242,23 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol expect(JSON.stringify(answer.body)).toContain('?package='); for (const id of ids) expect(JSON.stringify(answer.body)).not.toContain(id); }; + /** + * [ADR-0150 D3, the 2026-11-26 note] Refused with the ENABLE as the remedy, leading with it, never + * the `?package=` remedy of the refusal above (its lead), and naming none of `ids`. + */ + const expectRefusedEnableFirst = (answer: { status: number | undefined; body: any }, ids: readonly string[]) => { + expect([answer.status, codeOf(answer.body)], JSON.stringify(answer.body)).toEqual([409, 'RESOURCE_CONFLICT']); + const message = String(answer.body?.error?.message ?? answer.body?.message ?? ''); + expect([message.startsWith('Enable the package that holds dashboard '), message.startsWith('Name the package')], message).toEqual([true, false]); + for (const id of ids) expect(JSON.stringify(answer.body)).not.toContain(id); + }; + /** Every stored row of the dashboard, active and draft, with its stored bytes: what a refused write must leave as it was. */ + const everyRowBytes = async (engine: ObjectQL, name: string) => ((await engine.find('sys_metadata', { where: { type: 'dashboard', name }, context: { isSystem: true } } satisfies EngineQueryOptions)) as any[]) + .map((row) => JSON.stringify([row.state, row.package_id ?? null, row.metadata, row.version, row.checksum ?? null])).sort(); + const layDraft = (engine: ObjectQL, name: string, packageId: string | null, label: string) => engine.insert('sys_metadata', { + type: 'dashboard', name, namespace: 'default', package_id: packageId, scope: 'platform', strategy: 'merge', state: 'draft', version: 1, + metadata: JSON.stringify({ name, label, widgets: [] }), + }, { context: { isSystem: true } } as any); /** Every stored row of the dashboard, active and draft: `state:binding:label`. */ const everyRow = async (engine: ObjectQL, name: string) => ((await engine.find('sys_metadata', { where: { type: 'dashboard', name }, context: { isSystem: true } } satisfies EngineQueryOptions)) as any[]) .map((row) => `${row.state}:${row.package_id ?? null}:${JSON.parse(String(row.metadata)).label}`).sort(); @@ -1440,16 +1482,89 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol }); }); - it('CONTROL: the environment\'s own items save as before beside a disabled D: a name no package holds, and the package-unbound row of a name only D ships (which the bare read withholds)', async () => { + it('CONTROL: the environment\'s own item, of a name no package holds, saves, drafts, discards and deletes as before beside a disabled D', async () => { await layRow(booted!.engine, 'env_only_dash', null, 'environment row'); - await layRow(booted!.engine, 'd_unbound_dash', null, 'environment row'); await withDisabled(CODE_D, async () => { - for (const name of ['env_only_dash', 'd_unbound_dash']) { - const saved = await booted!.put(name, 'edited'); - expect(saved.status, JSON.stringify(saved.body)).toBe(200); - const rows = await storedRows(booted!.engine, name); - expect([Object.keys(rows), rows.null?.label]).toEqual([['null'], 'edited']); - } + const saved = await booted!.put('env_only_dash', 'edited'); + expect(saved.status, JSON.stringify(saved.body)).toBe(200); + const rows = await storedRows(booted!.engine, 'env_only_dash'); + expect([Object.keys(rows), rows.null?.label]).toEqual([['null'], 'edited']); + const drafted = await booted!.put('env_only_dash', 'drafted', { mode: 'draft' }); + expect(drafted.status, JSON.stringify(drafted.body)).toBe(200); + expect(await everyRow(booted!.engine, 'env_only_dash')).toEqual(['active:null:edited', 'draft:null:drafted']); + const discarded = await booted!.del('env_only_dash', 'draft'); + expect(discarded.status, JSON.stringify(discarded.body)).toBe(200); + expect(await everyRow(booted!.engine, 'env_only_dash')).toEqual(['active:null:edited']); + const deleted = await booted!.del('env_only_dash'); + expect(deleted.status, JSON.stringify(deleted.body)).toBe(200); + expect(await everyRow(booted!.engine, 'env_only_dash')).toEqual([]); + }); + }); + + // [ADR-0150 D3, the 2026-11-26 note] A package-unbound row of a name + // only D ships is D's customization. With D disabled every read + // withholds it, and so does every write naming no package: each was + // answered 200 (`main` 5dbcc02b: the save edited the hidden row, the + // draft save stored a draft no read reaches, the draft discard + // removed it, and the delete removed the row, so the next enable + // served D's item without its customization). Each is refused with + // the enable as its remedy, and the row comes back as it was. + it('the package-unbound row of a name only the disabled D ships is hidden with it: the bare save, draft save, delete and draft discard are refused with the enable as the remedy, and re-enabled the row is served byte-identical (CONTROL: it then saves as before)', async () => { + await layRow(booted!.engine, 'd_unbound_dash', null, 'customization row'); + const before = await everyRowBytes(booted!.engine, 'd_unbound_dash'); + // CONTROL: enabled, the row is served. + expect(await bareLabel(booted!, 'd_unbound_dash')).toEqual([200, 'customization row']); + await withDisabled(CODE_D, async () => { + expect((await get(booted!.kernel, '/meta/dashboard/d_unbound_dash')).status).toBe(404); + expectRefusedEnableFirst(await booted!.put('d_unbound_dash', 'edited'), [CODE_D, CODE_E]); + expectRefusedEnableFirst(await booted!.put('d_unbound_dash', 'drafted', { mode: 'draft' }), [CODE_D, CODE_E]); + expectRefusedEnableFirst(await booted!.del('d_unbound_dash'), [CODE_D, CODE_E]); + // No draft is stored: the discard still answers the enable, never `?package=`. + expectRefusedEnableFirst(await booted!.del('d_unbound_dash', 'draft'), [CODE_D, CODE_E]); + expect((await get(booted!.kernel, '/meta/dashboard/d_unbound_dash')).status).toBe(404); + expect(await everyRowBytes(booted!.engine, 'd_unbound_dash')).toEqual(before); + }); + expect(await bareLabel(booted!, 'd_unbound_dash')).toEqual([200, 'customization row']); + expect(await everyRowBytes(booted!.engine, 'd_unbound_dash')).toEqual(before); + // CONTROL: re-enabled, the bare save edits the row and the bare delete removes it, as before. + const saved = await booted!.put('d_unbound_dash', 'edited'); + expect(saved.status, JSON.stringify(saved.body)).toBe(200); + expect(await everyRow(booted!.engine, 'd_unbound_dash')).toEqual(['active:null:edited']); + expect((await booted!.del('d_unbound_dash')).status).toBe(200); + expect(await everyRow(booted!.engine, 'd_unbound_dash')).toEqual([]); + }); + + it.each([ + { stored: 'beside the package-unbound row', name: 'd_unbound_hidden_draft_dash', active: true }, + { stored: 'alone', name: 'd_unbound_draft_only_dash', active: false }, + ])('a package-unbound draft of a name only the disabled D ships, stored $stored, is hidden with it: the bare draft discard and draft save are refused with the enable as the remedy; re-enabled, the discard removes it as before (CONTROL)', async ({ name, active }) => { + if (active) await layRow(booted!.engine, name, null, 'customization row'); + await layDraft(booted!.engine, name, null, 'customization draft'); + const before = await everyRowBytes(booted!.engine, name); + await withDisabled(CODE_D, async () => { + expectRefusedEnableFirst(await booted!.del(name, 'draft'), [CODE_D, CODE_E]); + expectRefusedEnableFirst(await booted!.put(name, 'redrafted', { mode: 'draft' }), [CODE_D, CODE_E]); + expect(await everyRowBytes(booted!.engine, name)).toEqual(before); + }); + const discarded = await booted!.del(name, 'draft'); + expect(discarded.status, JSON.stringify(discarded.body)).toBe(200); + expect(await everyRow(booted!.engine, name)).toEqual(active ? ['active:null:customization row'] : []); + }); + + it.each([ + { holder: 'D ships it and holds a row', name: 'd_unbound_drow_dash', id: CODE_D }, + { holder: 'an authored D holds only a row', name: 'authored_d_unbound_dash', id: AUTH_D }, + ])('a package-unbound row beside the disabled holder\'s own row ($holder) is hidden with it: every bare write is refused with the enable as the remedy and both rows are byte-unchanged', async ({ name, id }) => { + await layRow(booted!.engine, name, id, 'disabled row'); + await layRow(booted!.engine, name, null, 'customization row'); + const before = await everyRowBytes(booted!.engine, name); + await withDisabled(id, async () => { + expect((await get(booted!.kernel, `/meta/dashboard/${name}`)).status).toBe(404); + expectRefusedEnableFirst(await booted!.put(name, 'edited'), [id, CODE_E]); + expectRefusedEnableFirst(await booted!.put(name, 'drafted', { mode: 'draft' }), [id, CODE_E]); + expectRefusedEnableFirst(await booted!.del(name), [id, CODE_E]); + expectRefusedEnableFirst(await booted!.del(name, 'draft'), [id, CODE_E]); + expect(await everyRowBytes(booted!.engine, name)).toEqual(before); }); }); From f71b5f88aad965c7c745d6289c241fa99ec59b27 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 12:29:28 +0000 Subject: [PATCH 2/4] fix(metadata-protocol): the draft discard judges the holders over the active rows where a package-unbound row is stored; the refusal fits the client message cap Claude-Session: https://claude.ai/code/session_01L6bhgWSCg5Qjw8A76bTFD6 Co-authored-by: Claude --- .../src/protocol-diff-delete-load.ts | 22 +++++++++++++------ .../metadata-protocol/src/protocol-save.ts | 12 +++++----- .../meta-disabled-holder-served-stack.test.ts | 6 +++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-diff-delete-load.ts b/packages/metadata-protocol/src/protocol-diff-delete-load.ts index f03bd9d13e3..df0f81e3298 100644 --- a/packages/metadata-protocol/src/protocol-diff-delete-load.ts +++ b/packages/metadata-protocol/src/protocol-diff-delete-load.ts @@ -764,16 +764,24 @@ export class ProtocolDiffDeleteLoadFacet { // draft discard are refused, with the enable as the remedy. // The delete removed the hidden row, so the next enable // served the package's item without it. A draft discard - // reads the draft rows, so it asks whether the customization - // is the ACTIVE row too: with no draft stored it answers - // that remedy, never `?package=`. + // reads the draft rows, so where a package-unbound row or + // draft is stored it judges the holders over the active + // rows too, as the draft save does: a customization that is + // the ACTIVE row, or a holder that holds only an active row, + // answers that remedy, never `?package=` nor the receipt. if (request.packageId == null) { - const customized = targetState === 'draft' && !rowsAtAddress.unbound - ? (await host.packagelessAddress(singularTypeForRepo, request.name, member, 'active')).unbound - : false; + const active = targetState === 'draft' + ? await host.packagelessAddress(singularTypeForRepo, request.name, member, 'active') + : undefined; const holderRefusal = packagelessHolderRefusal( host, 'delete', request.type, singularTypeForRepo, request.name, member, - customized ? { ...rowsAtAddress, customized } : rowsAtAddress, + active !== undefined && (rowsAtAddress.unbound || active.unbound) + ? { + candidates: [...new Set([...rowsAtAddress.candidates, ...active.candidates])], + unbound: rowsAtAddress.unbound, + customized: active.unbound, + } + : rowsAtAddress, ); if (holderRefusal) { addressRefusal = holderRefusal; diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 36abce428e6..b3b1b013bf1 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3289,13 +3289,13 @@ export function disabledHoldersCustomizationRefusal( name: string, ): Error & { code: 'RESOURCE_CONFLICT'; status: 409 } { const nothing = verb === 'save' ? 'Nothing was written.' : 'Nothing was deleted.'; + // Kept well under the 500 characters a door's client message is cut at + // (`truncateClientMessage`), so the remedy's last sentence arrives. const err = new Error( - `Enable the package that holds ${type} '${name}' first, then send this ${verb} again: GET /api/v1/packages ` - + `lists each installed package with whether it is enabled, and PATCH /api/v1/packages/:id/enable enables one. ` - + `${nothing} Every package that holds the name is disabled, and the row stored for it under no package is ` - + `that package's customization, hidden with it until the package is enabled, so no read would show this ` - + `${verb}. Naming the package (?package=, in process packageId) does not reach that row: it addresses the ` - + `package's own row beside it.`, + `Enable the package that holds ${type} '${name}' first, then send this ${verb} again (GET /api/v1/packages ` + + `shows which packages are disabled; PATCH /api/v1/packages/:id/enable enables one). ${nothing} Every package ` + + `holding the name is disabled, and the row stored for it under no package is that package's customization, ` + + `hidden with it. Naming the package (?package=) does not reach that row.`, ) as Error & { code: 'RESOURCE_CONFLICT'; status: 409 }; err.code = 'RESOURCE_CONFLICT'; err.status = 409; 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 ce315fe228a..cbd40aa26b3 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 @@ -1248,8 +1248,10 @@ describe('[#32605] the bare save of a name an enabled and a disabled package hol */ const expectRefusedEnableFirst = (answer: { status: number | undefined; body: any }, ids: readonly string[]) => { expect([answer.status, codeOf(answer.body)], JSON.stringify(answer.body)).toEqual([409, 'RESOURCE_CONFLICT']); - const message = String(answer.body?.error?.message ?? answer.body?.message ?? ''); - expect([message.startsWith('Enable the package that holds dashboard '), message.startsWith('Name the package')], message).toEqual([true, false]); + // The REST door answers a thrown refusal `{ error: , code }`; the dispatcher nests it. + const message = String(typeof answer.body?.error === 'string' ? answer.body.error : answer.body?.error?.message ?? ''); + // …and the door cuts a client message at 500 characters: the remedy arrives whole. + expect([message.startsWith('Enable the package that holds dashboard '), message.endsWith('…')], JSON.stringify(answer.body)).toEqual([true, false]); for (const id of ids) expect(JSON.stringify(answer.body)).not.toContain(id); }; /** Every stored row of the dashboard, active and draft, with its stored bytes: what a refused write must leave as it was. */ From 7e668961961a0bcce141139047ec56b199faa053 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 12:36:38 +0000 Subject: [PATCH 3/4] docs(adr-0150): D3 note for the hidden package-less row's writes; migration entry, changeset and the objectql pin The ADR-0150 D3 note dated 2026-11-26 records the ruling of #37499: while every holder of a name is disabled, the four writes naming no package are refused with the enable remedy, and enabling the holder again serves the package-less row untouched. The semantic migration entry and the changeset carry the same fix; the objectql door pin that read the old 200 now reads the refusal and the round trip. Claude-Session: https://claude.ai/code/session_01L6bhgWSCg5Qjw8A76bTFD6 Co-authored-by: Claude --- ...d-holder-unbound-row-bare-write-refused.md | 28 ++++++++++++ ...package-objects-keep-the-literal-prefix.md | 21 +++++++++ ...abled-holder-packageless-row-doors.test.ts | 34 +++++++++++--- ...der-package-less-row-bare-write-refused.ts | 45 +++++++++++++++++++ 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 .changeset/37499-disabled-holder-unbound-row-bare-write-refused.md create mode 100644 packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts diff --git a/.changeset/37499-disabled-holder-unbound-row-bare-write-refused.md b/.changeset/37499-disabled-holder-unbound-row-bare-write-refused.md new file mode 100644 index 00000000000..47ff699ca33 --- /dev/null +++ b/.changeset/37499-disabled-holder-unbound-row-bare-write-refused.md @@ -0,0 +1,28 @@ +--- +'@objectstack/metadata-protocol': minor +'@objectstack/spec': minor +--- + +fix(metadata-protocol)!: refuse a write naming no package over the package-less row of a name only disabled packages hold + +Clause-②: no (narrowing) +Metadata-protocol: narrowed +Skills-docs: none — no page under `skills/**` or `content/docs/**` teaches a save, draft save, delete or draft discard naming no package over a name only disabled packages hold; the refusal's own sentence names the fix + + + +**BREAKING** for a deployment that writes, with no package named, to a metadata name whose every holder is disabled while a package-less row or draft is stored for it: the write is now refused where it answered `200`. Fix: enable a package that holds the name (`PATCH /api/v1/packages/:id/enable`; `GET /api/v1/packages` shows which are disabled), then send the same write again. Naming the package (`?package=`) is not the fix: it addresses that package's own row and leaves the hidden row where it is. + +A package-less row stored at a name a package holds is that package's customization, and a disabled package's items are hidden from every read naming no package (ADR-0150 D3, its 2026-11-26 note). The writes naming no package still reached the row: an admin could edit, draft, discard or delete an item no read showed, and a delete lost the customization for good, so enabling the package again served its item without it. + +Every moved answer, before → after, for a type the registry reads by package, while every holder of the name is disabled: + +- `PUT /api/v1/meta/:type/:name` over a stored package-less row: `200` (the hidden row edited) → `409 RESOURCE_CONFLICT`, nothing written. +- `PUT /api/v1/meta/:type/:name?mode=draft` over a stored package-less row or draft: `200` (a draft stored that the draft read answered `404` for) → `409 RESOURCE_CONFLICT`, nothing written. +- `DELETE /api/v1/meta/:type/:name` over a stored package-less row: `200` (the row removed) → `409 RESOURCE_CONFLICT`, nothing deleted. +- `DELETE /api/v1/meta/:type/:name?state=draft` over a stored package-less draft: `200` (the draft removed) → `409 RESOURCE_CONFLICT`, nothing deleted. With a package-less row stored and no draft, the discard answers the same refusal, where it answered the `?package=` refusal or a no-op receipt. +- The same four through the in-process `saveMetaItem` / `deleteMetaItem` with no `packageId`. + +The refusal's message starts with the fix ("Enable the package that holds …") and names no package. Once a holder is enabled again the read naming no package serves the package-less row as it was stored, and the same writes answer as before the disable. + +Not moved: a name no package holds (the environment's own item) saves, drafts, discards and deletes as before beside a disabled package; a package-less row at a name an enabled package holds; a name only disabled packages hold with no package-less row or draft stored, which keeps its `409` with the `?package=` remedy; the sealed types (`doc`, `action`), which answer `403 NOT_OVERRIDABLE` as before; every read. Migration entry `disabled-holder-package-less-row-bare-write-refused` (`@objectstack/spec`) carries the same fix for the upgrade guide. diff --git a/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md b/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md index b4b27454f7d..e6541a30339 100644 --- a/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md +++ b/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md @@ -227,6 +227,27 @@ A bare name, read by a caller that belongs to package P, resolves to: A caller with no package (an environment item, a context-free door, an MCP client) resolves against the whole environment: the environment item of that name first (ADR-0005 overlay precedence keeps the environment's own item ahead), else the unique package holder, else the refusal with candidates (`409` at a door, D5). +> **Amendment note (2026-11-26, #37499).** A package-less row stored at a name a package holds is that holder's customization, never the environment's own item (D4, "A package-less row that bears a package-held name is a customization, never a second item"). So it hides with its holder, on the reads and on the writes alike. The maintainer, in the triage session recorded on card #37499, verbatim: 「我觉得停用就该全部消失」, then 「同意」 to the split that card carries. +> +> While every package that holds the name is disabled, a caller with no package is answered as follows. +> +> - **Reads stay the missing name.** The by-name read, `/published`, `/layers`, the list and `_env` withhold the row and answer what they answer for the holder's own item (`404`). This was already so (#32183, #32814, #33401); the note records it beside the writes. +> - **Every write naming no package is refused**, `409 RESOURCE_CONFLICT` with no new code: the publish-mode save, the draft save, the delete and the draft discard. The refusal names no package, as the refusal of a name only disabled packages hold already did, and its remedy is the enable: `PATCH /api/v1/packages/:id/enable`, then the same request. It is never `?package=`. A write naming the package addresses that package's own row, so it would leave the hidden row where it is and store a second row beside it. +> - **A package-less draft counts as the row does.** A package-less draft stored for such a name is the same customization: the draft save and the draft discard are refused over it, and the draft discard is refused with the same remedy when no draft is stored and the customization is the active row. +> - **Re-enable serves the row untouched.** A refused write stores, edits and removes nothing, so the row the enable serves is byte-identical to the one stored before the disable. +> +> What this replaces, measured on `main` `5dbcc02b` for a `dashboard` on both transports and both registration orders: each of the four writes answered `200`. The save edited the hidden row, the draft save stored a draft that the draft read then answered `404 NO_DRAFT` for, the draft discard removed it, and the delete removed the row, so the next enable served the package's item without its customization. The save door skipped the disabled-holders judgment whenever a package-less row was stored at the address. +> +> Unchanged, and pinned as controls: +> +> - A name no package holds is the environment's own item (the rule above): its save, draft save, draft discard and delete answer as before beside a disabled package. +> - A package-less row at a name an ENABLED package holds is written as before, the two-enabled-holders cell included. +> - A name only disabled packages hold with no package-less row stored keeps its refusal and its `?package=` remedy (#34144): there the named write has one row to write and nothing hidden beside it. +> - A type sealed against overlays refuses these writes one step earlier, as it does with its holder enabled. Measured for `doc` and `action`, before and after a restart: the save, the draft save and the delete answer `403 NOT_OVERRIDABLE`, and the draft discard has no draft to remove. +> - No write door takes `_env`: neither transport routes a `PUT` or a `DELETE` there. +> +> Code: `packages/metadata-protocol/src/protocol-save.ts#packagelessHolderRefusal`, the one judgment the four doors ask, and `#disabledHoldersCustomizationRefusal`. Pins: `packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts` ("the package-unbound row of a name only the disabled D ships is hidden with it", "a package-unbound draft of a name only the disabled D ships", "a package-unbound row beside the disabled holder's own row") and `packages/objectql/src/disabled-holder-packageless-row-doors.test.ts` (review#2 S3). + **Two consequences of the rule, as R (#31637) implements it.** - **(a) A package caller never resolves to an environment-authored item by bare name.** A package cannot declare a dependency on the environment, so an environment item is in no package's closure. A name that only an environment item holds is refused for a package caller (`outside-closure`), and the refusal names the environment as the holder. **This is a declared narrowing**, added by this record within the letter of the ruled rule. Today `getItem` serves the bare slot first to every caller (D4's overlay row), so a package flow's `template: welcome` filled by an environment-authored template is served today and refused once its reader is wired. It is carried by the E rows that wire a package caller (E1–E6, E8) and by U only through G1's door: Studio's held id travels as `?package=` (`client.meta.getItem`), so at the door it is the exact qualifier (D5), never a caller. G1 declares what that refuses. It cannot be measured on a package tree (HotCRM holds no environment), so the D10 upgrade report names each such reference as the migration finds it. diff --git a/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts b/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts index fbc74535bc8..c8cd95d96e2 100644 --- a/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts +++ b/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts @@ -17,9 +17,12 @@ * refused 409 with the `?package=` remedy, naming no package, and stores * no row (#34144 ruling A, #34262: a disabled package holds no name, so a * save naming none has no row to write). Re-enabled, the same save is - * kept. A delete of the stored package-less row removes it while the - * package is disabled, as before. A save at a member the package ships is - * refused, as before. + * kept. With the package disabled again, a save and a delete of the + * stored package-less row are refused 409 with the enable as the remedy + * and the row is left as it was (ADR-0150 D3, the 2026-11-26 note: the + * row is the holder's customization, hidden with it; the delete removed + * it). Re-enabled, the row is served again and the delete removes it. A + * save at a member the package ships is refused, as before. * - S5: while an ENABLED package holds the name through a stored row the * registry has not read, the row is served and listed as on `main`, in * either read order. @@ -191,7 +194,7 @@ describe('[#33401, review#2 S1] the lists leave out the package-less row the by- }); describe('[#33401, review#2 S3] a package-less save and delete while every holder is disabled', () => { - it('a save at a member the package never ships is refused naming no package and stores no row; re-enabled it is kept; a delete removes it; a save at a shipped member is refused, as before', async () => { + it('a save at a member the package never ships is refused naming no package and stores no row; re-enabled it is kept; disabled again, a save and a delete of that row are refused with the enable as the remedy and the row stays; re-enabled, the delete removes it; a save at a shipped member is refused, as before', async () => { const stores: Stores = new Map(); const { engine, protocol } = await boot(stores); engine.registry.disablePackage(PKG); @@ -216,12 +219,31 @@ describe('[#33401, review#2 S3] a package-less save and delete while every holde .toMatchObject({ success: true, state: 'active' }); expect(packagelessRows(stores)).toEqual(['fr-FR']); expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr'); - // Unchanged: with the package disabled again, a delete naming no package removes the row. + // FROM (`main` 5dbcc02b): with the package disabled again, a delete + // naming no package removed the row (`success: true`), and a save + // edited it unseen. TO (ADR-0150 D3, the 2026-11-26 note): the row is + // the holder's customization, hidden with it, so both are refused 409 + // with the enable as the remedy, never `?package=`, and the row stays. engine.registry.disablePackage(PKG); + const storedRow = () => JSON.stringify(Array.from(stores.get('sys_metadata')?.values() ?? []) + .filter((r) => r.name === NAME && r.state === 'active').map((r) => [r.package_id ?? null, r.bundle_member ?? null, r.metadata, r.version])); + const before = storedRow(); + for (const write of [ + () => protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'EDITED fr') } as any), + () => protocol.deleteMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any), + ]) { + const hidden: any = await write().then(() => undefined, (error: unknown) => error); + expect([hidden?.status, hidden?.code], String(hidden?.message)).toEqual([409, 'RESOURCE_CONFLICT']); + expect(String(hidden?.message).startsWith('Enable the package that holds email_template ')).toBe(true); + expect(String(hidden?.message)).not.toContain(PKG); + } + expect(storedRow()).toBe(before); + // CONTROL — re-enabled: the row is served as it was, and the delete removes it, as before. + engine.registry.enablePackage(PKG); + expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr'); expect(await protocol.deleteMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)) .toMatchObject({ success: true }); expect(packagelessRows(stores)).toEqual([]); - engine.registry.enablePackage(PKG); expect(await subjectAt(protocol, 'fr-FR')).toBeUndefined(); }); }); diff --git a/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts new file mode 100644 index 00000000000..c30368efc9f --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts @@ -0,0 +1,45 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A narrowing of the metadata writes that name no package, not of any key: +// ADR-0150 D3 (its 2026-11-26 note) has a package-less row stored at a name a +// package holds hide with that holder, on the writes as on the reads. While +// every holder of the name is disabled, the save, the draft save, the delete +// and the draft discard naming no package are refused, where each answered 200 +// and edited, stored or removed a row no read served. No key is added, removed +// or re-shaped and no stored row changes shape, so no tombstone and no D2 +// conversion: whether to enable the holder again is the operator's judgement. +// No relevance question: the move turns on which installed packages are +// disabled, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'disabled-holder-package-less-row-bare-write-refused', + surface: + 'A write of a metadata item that names no package (PUT /api/v1/meta/TYPE/NAME in publish mode and with ' + + '?mode=draft, DELETE /api/v1/meta/TYPE/NAME, its draft discard with ?state=draft, and the in-process save ' + + 'and delete of a metadata item with no packageId), for a name every installed package holding it has ' + + 'disabled, of a type the registry reads by package, while a package-less row or a package-less draft is ' + + 'stored for that name', + replacement: + 'Enable a package that holds the name (PATCH /api/v1/packages/ID/enable; GET /api/v1/packages shows which ' + + 'packages are disabled), then send the same write again: it edits, drafts or removes the package-less row as ' + + 'it did before. While every holder stays disabled the write answers 409 RESOURCE_CONFLICT and stores, edits ' + + 'and removes nothing. Naming the package on the write (?package=ID) is not the fix: it addresses that ' + + 'package\'s own row, so it leaves the hidden row where it is and stores a second row beside it.', + reason: + 'A package-less row stored at a name a package holds is that package\'s customization, never a second item, ' + + 'and a disabled package\'s items are withheld from every read that names no package. The writes that name no ' + + 'package still reached the row: the save edited it unseen, the draft save stored a draft the draft read then ' + + 'answered 404 for, the draft discard removed it, and the delete removed the row, so enabling the package ' + + 'again served its item without the customization. They now judge the name\'s holders past a stored ' + + 'package-less row, as they already did with none stored. A name no package holds, a package-less row at a ' + + 'name an enabled package holds, and a name only disabled packages hold with no package-less row stored (its ' + + 'refusal keeps the ?package= remedy) answer as before. There is no mechanical rewrite: whether the disabled ' + + 'package should be enabled again is a judgement about the deployment.', + acceptanceCriteria: + 'For every name whose holders are all disabled and for which a package-less row or draft is stored: PUT ' + + '/api/v1/meta/TYPE/NAME (publish mode and ?mode=draft) and DELETE /api/v1/meta/TYPE/NAME (and ?state=draft) ' + + 'naming no package answer 409 RESOURCE_CONFLICT and leave every stored row of the name byte-identical; once ' + + 'a holder is enabled again, the read naming no package serves the package-less row as it was stored, and ' + + 'the same writes answer as they did before the disable.', +}; From 450813bf0bd2789c250675c48d53db8c20084f66 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 15:06:41 +0000 Subject: [PATCH 4/4] docs(adr-0150): the D3 note names the four writes it closes and the two doors not judged yet The note said every write naming no package is refused. Two doors are not asked the judgment at this head: the per-item publish and the per-item rollback. The note now states the four writes this change closes, names those two as not judged yet with their card, says the server-stated rewrites are not asked by design, names the draft reads, marks which controls are pinned and which are measured, and points at D4's exception for the platform's own record. The migration entry's surface reads "packages that are disabled". Claude-Session: https://claude.ai/code/session_01L6bhgWSCg5Qjw8A76bTFD6 Co-authored-by: Claude --- ...sed-by-package-objects-keep-the-literal-prefix.md | 12 +++++++----- ...led-holder-package-less-row-bare-write-refused.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md b/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md index e6541a30339..bb181ae8866 100644 --- a/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md +++ b/docs/adr/0150-behavioural-metadata-addressed-by-package-objects-keep-the-literal-prefix.md @@ -227,18 +227,20 @@ A bare name, read by a caller that belongs to package P, resolves to: A caller with no package (an environment item, a context-free door, an MCP client) resolves against the whole environment: the environment item of that name first (ADR-0005 overlay precedence keeps the environment's own item ahead), else the unique package holder, else the refusal with candidates (`409` at a door, D5). -> **Amendment note (2026-11-26, #37499).** A package-less row stored at a name a package holds is that holder's customization, never the environment's own item (D4, "A package-less row that bears a package-held name is a customization, never a second item"). So it hides with its holder, on the reads and on the writes alike. The maintainer, in the triage session recorded on card #37499, verbatim: 「我觉得停用就该全部消失」, then 「同意」 to the split that card carries. +> **Amendment note (2026-11-26, #37499).** A package-less row stored at a name a package holds is that holder's customization, never the environment's own item (D4, "A package-less row that bears a package-held name is a customization, never a second item"; the one package-less row D4's 2026-11-24 note excepts, the platform's own record, is not a customization and is outside this note). So it hides with its holder: on the reads, and on the four writes this note closes. Two more writes are not judged yet and are named below. The maintainer, in the triage session recorded on card #37499, verbatim: 「我觉得停用就该全部消失」, then 「同意」 to the split that card carries. > > While every package that holds the name is disabled, a caller with no package is answered as follows. > -> - **Reads stay the missing name.** The by-name read, `/published`, `/layers`, the list and `_env` withhold the row and answer what they answer for the holder's own item (`404`). This was already so (#32183, #32814, #33401); the note records it beside the writes. -> - **Every write naming no package is refused**, `409 RESOURCE_CONFLICT` with no new code: the publish-mode save, the draft save, the delete and the draft discard. The refusal names no package, as the refusal of a name only disabled packages hold already did, and its remedy is the enable: `PATCH /api/v1/packages/:id/enable`, then the same request. It is never `?package=`. A write naming the package addresses that package's own row, so it would leave the hidden row where it is and store a second row beside it. +> - **Reads stay the missing name.** The by-name read, `/published`, `/layers`, the list and `_env` withhold the row and answer what they answer for the holder's own item (`404`). This was already so (#32183, #32814, #33401); the note records it beside the writes. Of the draft reads, the by-name one answers `404 NO_DRAFT`; the one at `_env` still answers `409` at this head, and card #34261 carries its move to `404`. +> - **Four writes naming no package are refused**, `409 RESOURCE_CONFLICT` with no new code: the publish-mode save, the draft save, the delete and the draft discard. The refusal names no package, as the refusal of a name only disabled packages hold already did, and its remedy is the enable: `PATCH /api/v1/packages/:id/enable`, then the same request. It is never `?package=`. A write naming the package addresses that package's own row, so it would leave the hidden row where it is and store a second row beside it. > - **A package-less draft counts as the row does.** A package-less draft stored for such a name is the same customization: the draft save and the draft discard are refused over it, and the draft discard is refused with the same remedy when no draft is stored and the customization is the active row. -> - **Re-enable serves the row untouched.** A refused write stores, edits and removes nothing, so the row the enable serves is byte-identical to the one stored before the disable. +> - **Re-enable serves the row untouched**, as far as those four writes go. A refused write stores, edits and removes nothing, so the row the enable serves is byte-identical to the one stored before the disable. +> - **Not judged yet: the per-item publish and the per-item rollback.** A publish of one item naming no package (`promoteDraftForPublish`, `protocol-history-and-publish.ts`) and a rollback of one item naming no package (`rollbackMetaItem`, `protocol-package-commits.ts`) do not ask this judgment at this head. Read in the code, not measured: each resolves the package-less row or draft as its address, so each can still write the hidden row. Card #37608 carries both doors. Until it lands, "no write lands on a hidden item" holds for the four writes above and not for these two. +> - **Not asked, by design: the rewrites the server states itself.** A save the server issues with `source` set rewrites a row the store already holds (the stored-metadata migration, the stored flow-credential move), and the package duplicate (`writeFace: 'package-duplicate'`) always names its target. Neither is an author's write naming no package, and neither is asked this judgment. > > What this replaces, measured on `main` `5dbcc02b` for a `dashboard` on both transports and both registration orders: each of the four writes answered `200`. The save edited the hidden row, the draft save stored a draft that the draft read then answered `404 NO_DRAFT` for, the draft discard removed it, and the delete removed the row, so the next enable served the package's item without its customization. The save door skipped the disabled-holders judgment whenever a package-less row was stored at the address. > -> Unchanged, and pinned as controls: +> Unchanged. The first three are pinned as controls; the last two are measurements, with no pin in this change: > > - A name no package holds is the environment's own item (the rule above): its save, draft save, draft discard and delete answer as before beside a disabled package. > - A package-less row at a name an ENABLED package holds is written as before, the two-enabled-holders cell included. diff --git a/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts index c30368efc9f..fd0d81b5a01 100644 --- a/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts +++ b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts @@ -17,7 +17,7 @@ export const entry: SemanticMigration = { surface: 'A write of a metadata item that names no package (PUT /api/v1/meta/TYPE/NAME in publish mode and with ' + '?mode=draft, DELETE /api/v1/meta/TYPE/NAME, its draft discard with ?state=draft, and the in-process save ' - + 'and delete of a metadata item with no packageId), for a name every installed package holding it has ' + + 'and delete of a metadata item with no packageId), for a name held only by installed packages that are ' + 'disabled, of a type the registry reads by package, while a package-less row or a package-less draft is ' + 'stored for that name', replacement: