Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@objectstack/metadata-protocol': minor
'@objectstack/spec': minor
---

fix(metadata-protocol)!: refuse the per-item publish and rollback naming no package of a name only disabled packages hold, with or without a package-less row stored

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — no page under `skills/**` or `content/docs/**` teaches a per-item publish or rollback naming no package over a name only disabled packages hold; the refusal's own sentence names the fix

<!-- adr-0087: not-required (already-registered disabled-holder-package-less-row-bare-write-refused) the entry the six other writes of this narrowing registered now names these three cells too -->

**BREAKING** for a deployment that publishes or rolls back one metadata item, with no package named, at a name whose every holder is disabled and no package-less row is stored for it: the write is now refused where it answered `200`. Fix: send the same publish or rollback naming the package (`?package=ID`, in process `packageId`) where the refusal says "Name the package this publish is for" or "Name the package this rollback is for"; enable a package that holds the name (`PATCH /api/v1/packages/:id/enable`) where it says "Enable the package that holds …".

The bare save of such an item already answers `409 RESOURCE_CONFLICT` and writes nothing (a disabled package holds no name). The per-item publish and rollback naming no package asked that judgment only where a package-less row or draft was stored, so they still wrote the disabled package's own row, or stored the package-less row again from its history, and enabling the package again served a body no read had shown.

Every moved answer, before → after, for a type the registry reads by package, while every holder of the name is disabled, where the ADR-0146 D11 close leaves the write open:

- `POST /api/v1/meta/:type/:name/publish` whose draft address is the disabled package's own draft (beside a package-less row or with none stored): `200` (the draft promoted into that package's active row) → `409 RESOURCE_CONFLICT`, "Name the package this publish is for, then send it again …", nothing written. The publish naming the package still promotes it.
- `POST /api/v1/meta/:type/:name/rollback` that restores the disabled package's own row: `200` (that row rewritten to the version's body) → `409 RESOURCE_CONFLICT`, "Name the package this rollback is for, then send it again …", nothing written. The rollback naming the package still restores it.
- `POST /api/v1/meta/:type/:name/rollback` with the package-less row's history but no package-less row stored: `200` (a package-less row inserted with the version's body) → `409 RESOURCE_CONFLICT`, "Enable the package that holds …", nothing written.
- The same three through the in-process `publishMetaItem` / `rollbackMetaItem` with no `packageId`.

Once a holder is enabled again the same publish or rollback answers as before the disable.

Not moved: a publish or rollback naming a package, with the package enabled or disabled; a publish with no draft at its address, which keeps its `404 NO_DRAFT`; an item the ADR-0146 D11 close covers, which keeps that close's `403 NOT_OVERRIDABLE`; a name no package holds; a name an enabled package holds; every read. Correction to the note `37608-disabled-holder-publish-rollback-refused`, released in `19.0.0-next.1` and left as released: its "Not moved" list says that a rollback of a package-bound row is not moved, and that two writes on an item only disabled packages hold still land, left open for a separate decision (#37851): a publish whose draft address is the disabled package's own draft, and a rollback with no package-less row stored. From this release on, all three are refused as listed above, while the same publish or rollback naming the package, or sent once a holder is enabled again, answers as before. Migration entry `disabled-holder-package-less-row-bare-write-refused` (`@objectstack/spec`) now carries them for the upgrade guide.
23 changes: 16 additions & 7 deletions packages/metadata-protocol/src/protocol-history-and-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,25 @@ export class ProtocolHistoryAndPublishFacet {
// packages hold, that draft and that row are their
// customization, hidden with them, and the promotion wrote the
// active row the next enable serves. Refused with the enable
// as the remedy, nothing written. A promotion of a package's
// own draft into its own row (`key` and `into` that package)
// touches no package-less row and is not asked; nor is a
// publish with no draft, which keeps its `NO_DRAFT`.
if (addressRefusal === undefined && address.kind === 'draft' && (address.key === null || address.into === null)) {
// as the remedy, nothing written. A publish with no draft is
// not asked, and keeps its `NO_DRAFT`.
//
// [#37851 ruling A] …and a promotion of a package's own draft
// into its own row (`key` and `into` that package) is asked
// too, as the bare save of the item is: of a name only
// disabled packages hold it wrote the disabled package's
// active row, which the next enable served. It touches no
// package-less row, so it is asked the judgment's first state
// only ({@link disabledHoldersOnlyRefusal}, the `?package=`
// remedy, which the publish naming that package reaches),
// whatever package-less row is stored beside it.
if (addressRefusal === undefined && address.kind === 'draft') {
const ownDraft = address.key !== null && address.into !== null;
const active = await host.packagelessAddress(singularType, request.name, request.member, 'active');
if (active.unbound || address.drafts.unbound) {
if (ownDraft || active.unbound || address.drafts.unbound) {
addressRefusal = packagelessHolderRefusal(host, 'publish', request.type, singularType, request.name, request.member, {
candidates: [...new Set([...active.candidates, ...address.drafts.candidates])],
unbound: true,
unbound: !ownDraft,
}, 'disabled-holders');
}
}
Expand Down
28 changes: 20 additions & 8 deletions packages/metadata-protocol/src/protocol-package-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2307,15 +2307,27 @@ export class ProtocolPackageCommitsFacet {
// save and the delete ask ({@link packagelessHolderRefusal}, its
// disabled-holders judgment only), after the D11 close above, and is
// refused with the enable as the remedy, nothing written.
if (request.packageId === undefined && rollbackPackageId === null) {
//
// [#37851 ruling A] Whether or not a package-unbound row is stored
// now: with none stored but its history kept, the restore inserted
// the package-unbound row again, the same customization, so it is
// refused with the same remedy. And a rollback naming no package that
// restores a disabled package's OWN row (the binding read above names
// it) wrote that row, which the next enable served, while the bare
// save of the item is refused: it is asked the judgment's first state
// ({@link disabledHoldersOnlyRefusal}, the `?package=` remedy, which
// the rollback naming that package reaches).
if (request.packageId === undefined) {
const active = await host.packagelessAddress(singularType, request.name, member, 'active');
if (active.unbound) {
const holderRefusal = packagelessHolderRefusal(
host, 'rollback', request.type, singularType, request.name, member,
{ candidates: active.candidates, unbound: true }, 'disabled-holders',
);
if (holderRefusal) throw holderRefusal;
}
const holderRefusal = packagelessHolderRefusal(
host, 'rollback', request.type, singularType, request.name, member,
{
candidates: [...new Set([...active.candidates, ...(rollbackPackageId !== null ? [rollbackPackageId] : [])])],
unbound: rollbackPackageId === null,
},
'disabled-holders',
);
if (holderRefusal) throw holderRefusal;
}
// [ADR-0146 D2] A rollback of the base's paired `.custom` row is the
// pair's declared override, as its save is: it edits no managed item,
Expand Down
8 changes: 6 additions & 2 deletions packages/metadata-protocol/src/protocol-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3535,8 +3535,12 @@ export async function packagelessRowHeldBaseDraftAddress(
* whether or not a row is stored at the address (over none, the delete and
* the discard are refused too, not answered the no-op receipt).
* [ADR-0150 D3, the 2026-11-26 note] The bare per-item publish and the bare
* per-item rollback ask the second state only (`arms: 'disabled-holders'`),
* after the ADR-0146 D11 close, so they write nothing a disabled holder hides.
* per-item rollback ask the disabled-holders judgment only
* (`arms: 'disabled-holders'`), after the ADR-0146 D11 close, so they write
* nothing a disabled holder hides: [#37851 ruling A] its first state where
* they write a package's own row (the publish of its own draft, the rollback
* of its own row), its second where they write the package-unbound row,
* stored or not.
* Asked after {@link servedPackagelessSaveAddress} (a name an enabled and a
* disabled package both hold) and after the rows' own refusal (two or more
* bindings), so neither answer moves.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,22 +305,46 @@ describe('[ADR-0150 D3, the 2026-11-26 note] the per-item publish and the rollba
expect(await subjectAt(protocol, 'fr-FR')).toBe('DRAFT fr');
});

it('publish, the package\'s own draft beside the stored package-less row: promoted into the package\'s row as on `main`, the package-less row byte-identical', async () => {
it.each([['beside the stored package-less row', true], ['with no package-less row stored', false]] as const)('publish, the package\'s own draft %s: refused 409 with the `?package=` remedy, nothing written; the publish naming the package promotes it, the package-less row byte-identical', async (_cell, withRow) => {
const stores: Stores = new Map();
const { engine, protocol } = await boot(stores);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr') } as any);
if (withRow) await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr') } as any);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG DRAFT fr'), mode: 'draft', packageId: PKG } as any);
engine.registry.disablePackage(PKG);
const packageless = () => JSON.stringify(Array.from(stores.get('sys_metadata')?.values() ?? [])
.filter((r) => r.name === NAME && (r.package_id ?? null) === null).map((r) => [r.state, r.bundle_member ?? null, r.metadata, r.version]));
const before = packageless();
// The draft address is the package's own draft, promoted into the
// package's own row: no package-less row is read or written, so the
// judgment is not asked (the answer `main` 56c9cae6 gives).
expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).toMatchObject({ success: true });
expect(packageless()).toBe(before);
const before = storedRows(stores);
const packagelessBefore = packageless();
// FROM (`main` 73d5e347): `success: true`, the draft promoted into the
// disabled package's active row, which the next enable serves.
// TO (#37851 ruling A): refused as the bare save of the item is, with
// the `?package=` remedy (the promotion addresses the package's own
// draft and row, which the publish naming the package reaches), and
// nothing is written.
const refused = await refusalOf(protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any));
expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']);
expect(String(refused?.message).startsWith('Name the package this publish is for, then send it again')).toBe(true);
expect(String(refused?.message)).not.toContain(PKG);
expect(storedRows(stores)).toBe(before);
// CONTROL — the remedy: the publish naming the package promotes the
// draft into the package's own row, as on `main`, and leaves the
// package-less row byte-identical.
expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR', packageId: PKG } as any)).toMatchObject({ success: true });
expect(packageless()).toBe(packagelessBefore);
expect(Array.from(stores.get('sys_metadata')?.values() ?? [])
.filter((r) => r.name === NAME && r.state === 'active').map((r) => r.package_id ?? null).sort()).toEqual([PKG, null].sort());
.filter((r) => r.name === NAME && r.state === 'active').map((r) => r.package_id ?? null).sort())
.toEqual((withRow ? [PKG, null] : [PKG]).sort());
});

it('publish, the package\'s own draft, re-enabled: the bare publish promotes it as on `main`', async () => {
const stores: Stores = new Map();
const { engine, protocol } = await boot(stores);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG DRAFT fr'), mode: 'draft', packageId: PKG } as any);
engine.registry.disablePackage(PKG);
expect((await refusalOf(protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)))?.status).toBe(409);
engine.registry.enablePackage(PKG);
expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).toMatchObject({ success: true });
expect(await subjectAt(protocol, 'fr-FR')).toBe('PKG DRAFT fr');
});

it('publish with no draft stored, beside the stored package-less row: `NO_DRAFT` as on `main`, nothing written', async () => {
Expand Down Expand Up @@ -358,4 +382,56 @@ describe('[ADR-0150 D3, the 2026-11-26 note] the per-item publish and the rollba
.toMatchObject({ success: true, restoredFromVersion: first });
expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr 1');
});

it('rollback with the package-less row\'s history but no row stored: refused 409 with the enable as the remedy, no row inserted; re-enabled, the same rollback restores the version', async () => {
const stores: Stores = new Map();
const { engine, protocol } = await boot(stores);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr 1') } as any);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr 2') } as any);
const events = (await protocol.historyMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).events;
const first = Math.min(...events.map((e: any) => e.version as number));
await protocol.deleteMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any);
expect(packagelessRows(stores)).toEqual([]);
engine.registry.disablePackage(PKG);
const before = storedRows(stores);
// FROM (`main` 73d5e347): `success: true`, a new package-unbound
// active row inserted with the first version's body, which the next
// enable serves. TO (#37851 ruling A): refused, the enable as the
// remedy (the restore writes the package-unbound row, the disabled
// holder's customization, which naming the package does not reach),
// and no row is inserted.
const refused = await refusalOf(protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any));
expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']);
expect(String(refused?.message).startsWith('Enable the package that holds email_template ')).toBe(true);
expect(String(refused?.message)).not.toContain(PKG);
expect(storedRows(stores)).toBe(before);
// CONTROL — re-enabled: nothing is served at the member, and the same rollback restores the version.
engine.registry.enablePackage(PKG);
expect(await subjectAt(protocol, 'fr-FR')).toBeUndefined();
expect(await protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any))
.toMatchObject({ success: true, restoredFromVersion: first });
expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr 1');
});

it('rollback of the package\'s own row: refused 409 with the `?package=` remedy, nothing written; the rollback naming the package restores the version', async () => {
const stores: Stores = new Map();
const { engine, protocol } = await boot(stores);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG fr 1'), packageId: PKG } as any);
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG fr 2'), packageId: PKG } as any);
const events = (await protocol.historyMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR', packageId: PKG } as any)).events;
expect(events).toHaveLength(2);
const first = Math.min(...events.map((e: any) => e.version as number));
engine.registry.disablePackage(PKG);
const before = storedRows(stores);
const refused = await refusalOf(protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any));
expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']);
expect(String(refused?.message).startsWith('Name the package this rollback is for, then send it again')).toBe(true);
expect(String(refused?.message)).not.toContain(PKG);
expect(storedRows(stores)).toBe(before);
// CONTROL — the remedy: the rollback naming the package restores the package's row, as on `main`.
expect(await protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR', packageId: PKG } as any))
.toMatchObject({ success: true, restoredFromVersion: first });
engine.registry.enablePackage(PKG);
expect(await subjectAt(protocol, 'fr-FR')).toBe('PKG fr 1');
});
});
Loading
Loading