Skip to content

Commit 3ddfa1c

Browse files
committed
fix(#29594): the overlay-write closes keep refusing a kernel item, naming no pair
Ruling record 6691217245 serves every kernel object as not customizable in this version, so the package-less close and the close of a write naming the base stay shut on a kernel item exactly where they were shut before the ensure door's kernel verdict: 403 NOT_OVERRIDABLE, with a sentence that names no pair. The ensure door's other judgements are read with its kernel verdict left out (judgeKernel: false), and the fix carries kernelScope. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzCo6pa7SSUFmosQD8
1 parent 20c8cd6 commit 3ddfa1c

4 files changed

Lines changed: 110 additions & 23 deletions

File tree

‎packages/metadata-protocol/src/protocol-customization-package.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ function kernelPackageScopeOf(row: PairPackageRow | undefined): string | undefin
173173
* know beforehand that a kernel package has none (the "new similar" doors).
174174
*/
175175
export function kernelPackageScope(engine: unknown, packageId: string): string | undefined {
176-
const registry = (engine as { registry?: Partial<PairRegistry> } | null | undefined)?.registry;
177-
if (!registry || typeof registry.getPackage !== 'function') return undefined;
178-
return kernelPackageScopeOf(registry.getPackage(packageId));
176+
const manifest = installedManifestsOfEngine(engine)(packageId);
177+
return kernelPackageScopeOf(manifest === undefined ? undefined : { manifest });
179178
}
180179

181180
/**
@@ -338,6 +337,15 @@ export function customizationPairEnsureRefusal(
338337
registry: PairRegistry,
339338
baseId: string,
340339
pairId: string,
340+
options: {
341+
/**
342+
* `false` asks every other judgement of the door with the kernel
343+
* verdict left out: the overlay-write closes read it so that a
344+
* kernel item stays closed exactly where it was closed before the
345+
* verdict (`overlayPairFixOf`). The door itself always judges it.
346+
*/
347+
readonly judgeKernel?: boolean;
348+
} = {},
341349
): Error | undefined {
342350
const base = registry.getPackage(baseId);
343351
if (!base) {
@@ -350,7 +358,7 @@ export function customizationPairEnsureRefusal(
350358
// version of this door created for a kernel package stays installed, and
351359
// the overrides inside it stay served and writable (the override gate and
352360
// the served-override read never ask this door).
353-
const kernelScope = kernelPackageScopeOf(base);
361+
const kernelScope = options.judgeKernel === false ? undefined : kernelPackageScopeOf(base);
354362
if (kernelScope !== undefined) {
355363
return refusal(409, `Package '${baseId}' is a kernel package (scope '${kernelScope}'): kernel objects are not `
356364
+ `customizable in this version, so '${baseId}' has no paired customization package and '${pairId}' is `

‎packages/metadata-protocol/src/protocol-packaged-base-refusal.ts‎

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
} from './packaged-base-regime.js';
4646
import { SysMetadataRepository } from './sys-metadata-repository.js';
4747
import { OBJECT_EXTENSION_TYPE } from './protocol-object-extension-item.js';
48-
import { customizationPairEnsureRefusal, type PairRegistry } from './protocol-customization-package.js';
48+
import { customizationPairEnsureRefusal, kernelPackageScope, type PairRegistry } from './protocol-customization-package.js';
4949
import { resolveOverlaySchema } from './protocol-meta-type-schema.js';
5050
import { resolvePackageClosure } from '@objectstack/lint/runtime';
5151
import { overlayMemberField, overlayMemberOfBody, overlayMemberValue } from './migrations/overlay-index.js';
@@ -263,9 +263,12 @@ export type PackagelessWriteOperation = 'save' | 'publish' | 'delete' | 'rollbac
263263
*/
264264
export function packagelessOverlayWriteRefusal(
265265
request: { type: string; name: string },
266-
closed: { base: string; pair: string },
266+
closed: OverlayWriteClose,
267267
operation: PackagelessWriteOperation,
268268
): Error {
269+
if (closed.kernelScope !== undefined) {
270+
return kernelOverlayWriteRefusal(request, closed.base, closed.kernelScope, 'packageless', operation);
271+
}
269272
const { item, shipped, pair, declared, writeInto, ceremony } = closedOverlayWriteClauses(request, closed);
270273
const rule = `A write naming no package is closed where ${ceremony} can move its row `
271274
+ `(ADR-0146 D11); a package-less row stored before it is served until that command moves it into '${closed.pair}'.`;
@@ -310,6 +313,37 @@ function closedOverlayWriteClauses(
310313
return { item, shipped, pair, declared, writeInto, ceremony, boundRowServed };
311314
}
312315

316+
/**
317+
* [#29594, ruling record 6691217245] Both closes' refusal of a write onto an
318+
* item a kernel package ships ({@link OverlayWriteClose.kernelScope}). Kernel
319+
* objects are not customizable in this version and the kernel has no pair, so
320+
* the sentence names no pair and no fix: the write stays closed (ADR-0146 D11)
321+
* where it was closed before the kernel verdict, under the same
322+
* `403 NOT_OVERRIDABLE`, until a later version's kernel whitelist opens the
323+
* item. A row stored before the close stays served; a row bound to the base
324+
* is still removed by a delete naming it.
325+
*/
326+
function kernelOverlayWriteRefusal(
327+
request: { type: string; name: string },
328+
base: string,
329+
kernelScope: string,
330+
address: 'packageless' | 'named_base',
331+
operation: PackagelessWriteOperation,
332+
): Error {
333+
const type = PLURAL_TO_SINGULAR[request.type] ?? request.type;
334+
const item = `'${type}/${request.name}' ships in kernel package '${base}' (scope '${kernelScope}')`;
335+
const write = address === 'packageless'
336+
? (operation === 'delete' || operation === 'rollback'
337+
? `a ${operation} of its package-less row`
338+
: 'a write naming no package')
339+
: (operation === 'rollback' ? `a rollback of its row bound to '${base}'` : `a write naming '${base}'`);
340+
const stored = address === 'packageless'
341+
? 'A package-less row stored before the close stays served.'
342+
: `A row bound to '${base}' stored before the close stays served until a delete naming '${base}' removes it.`;
343+
return closedOverlayWriteError(`${item}: kernel objects are not customizable in this version, so ${write} is `
344+
+ `refused (ADR-0146 D3, D11). ${stored}`);
345+
}
346+
313347
/** `403 NOT_OVERRIDABLE`, the code and status the sealed write already answers, so neither close gains a code. */
314348
function closedOverlayWriteError(message: string): Error {
315349
const err = new Error(message);
@@ -357,9 +391,12 @@ export type NamedBaseWriteOperation = Exclude<PackagelessWriteOperation, 'delete
357391
*/
358392
export function namedBaseOverlayWriteRefusal(
359393
request: { type: string; name: string },
360-
closed: { base: string; pair: string },
394+
closed: OverlayWriteClose,
361395
operation: NamedBaseWriteOperation,
362396
): Error {
397+
if (closed.kernelScope !== undefined) {
398+
return kernelOverlayWriteRefusal(request, closed.base, closed.kernelScope, 'named_base', operation);
399+
}
363400
const { item, shipped, pair, declared, writeInto, boundRowServed } = closedOverlayWriteClauses(request, closed);
364401
const message = operation === 'rollback'
365402
? `${item} ${shipped}, and a rollback of its row bound to the read-only base is closed (ADR-0146 D1, D11): `
@@ -388,6 +425,27 @@ export interface OverlayPairFix {
388425
* about the write the fix takes.
389426
*/
390427
readonly pendingPairScope?: WrittenPackageScope;
428+
/**
429+
* [#29594, ruling record 6691217245] The base's kernel scope (`system` /
430+
* `cloud`), present only for a kernel base. In this version a kernel
431+
* object is not customizable and the ensure door creates no pair for it,
432+
* so this fix cannot be taken: a close that reads it still refuses the
433+
* write, exactly where it refused it before that verdict, but with
434+
* {@link kernelOverlayWriteRefusal}'s sentence, which names no pair. The
435+
* kernel whitelist (a later version) is what reopens such a write.
436+
*/
437+
readonly kernelScope?: string;
438+
}
439+
440+
/**
441+
* The subject an overlay-write close refuses ({@link packagelessOverlayWriteRefusal},
442+
* {@link namedBaseOverlayWriteRefusal}): the base, its pair, and — for a
443+
* kernel base — its kernel scope ({@link OverlayPairFix.kernelScope}).
444+
*/
445+
export interface OverlayWriteClose {
446+
readonly base: string;
447+
readonly pair: string;
448+
readonly kernelScope?: string;
391449
}
392450

393451
/** A written package and the closure of its declared dependencies, as `resolveWritePackageScope` answers it. */
@@ -411,7 +469,10 @@ export type OverrideWriteVerdictAsk = (request: OverrideWriteSubject, writtenSco
411469
* - the base has a pair id ({@link pairOf}; an id ending in
412470
* `.custom` has none);
413471
* - the ensure door would answer or create the pair
414-
* ({@link customizationPairEnsureRefusal});
472+
* ({@link customizationPairEnsureRefusal}), its kernel verdict left out:
473+
* [#29594] a kernel base answers a fix carrying its `kernelScope`, so
474+
* both closes keep refusing a kernel item where they did before that
475+
* verdict, naming no pair;
415476
* - the base records a version (`basedOn`, its `manifest.version`, the value
416477
* the ceremony records too).
417478
*
@@ -432,14 +493,17 @@ export function overlayPairFixOf(
432493
const pair = pairId.value;
433494
const registry = (host.engine as { registry?: PairRegistry } | undefined)?.registry;
434495
if (!registry || typeof registry.getPackage !== 'function') return null;
435-
if (customizationPairEnsureRefusal(host.engine, registry, base, pair) !== undefined) return null; // the ensure door would refuse
496+
// The ensure door's other judgements; its kernel verdict is read below.
497+
if (customizationPairEnsureRefusal(host.engine, registry, base, pair, { judgeKernel: false }) !== undefined) return null;
436498
const basedOn = registry.getPackage(base)?.manifest?.version;
437499
if (typeof basedOn !== 'string' || basedOn === '') return null; // no `basedOn` to declare
438-
if (registry.getPackage(pair)) return { base, pair, basedOn };
500+
const kernelScope = kernelPackageScope(host.engine, base);
501+
const kernel = kernelScope === undefined ? {} : { kernelScope };
502+
if (registry.getPackage(pair)) return { base, pair, basedOn, ...kernel };
439503
// The pair the ensure door would create: one dependency, the base.
440504
const baseClosure = resolvePackageClosure(base, (id) => registry.getPackage(id) as { manifest?: unknown } | undefined);
441505
const dependencies = [base, ...(baseClosure?.dependencies ?? []).filter((id) => id !== pair)];
442-
return { base, pair, basedOn, pendingPairScope: { packageId: pair, dependencies } };
506+
return { base, pair, basedOn, pendingPairScope: { packageId: pair, dependencies }, ...kernel };
443507
}
444508

445509
/**
@@ -589,7 +653,7 @@ export interface NamedBaseWriteSubject {
589653
export function namedBaseCloseSubject(
590654
this: NamedBaseCloseHost,
591655
request: NamedBaseWriteSubject,
592-
): { base: string; pair: string } | null {
656+
): OverlayWriteClose | null {
593657
const base = typeof request.packageId === 'string' && request.packageId.length > 0 ? request.packageId : undefined;
594658
if (base === undefined) return null; // the package-less write: #28576's close
595659
// A body carrying `overrides` keeps its answer: the D2 gate refuses a
@@ -607,7 +671,7 @@ export function namedBaseCloseSubject(
607671
? overlayMemberOfBody(type, written)
608672
: overlayMemberValue(type, request.member);
609673
if (!overlayPairFixAdmits(this, fix, { type, name: request.name, body: written, member })) return null;
610-
return { base, pair: fix.pair };
674+
return fix.kernelScope === undefined ? { base, pair: fix.pair } : { base, pair: fix.pair, kernelScope: fix.kernelScope };
611675
}
612676

613677
// ─────────────────────────────────────────────────────────────────────────

‎packages/metadata-protocol/src/protocol-packageless-overlay-migration.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ import type { ObjectStackProtocolImplementation } from './protocol.js';
144144
import {
145145
overlayPairFixAdmits,
146146
overlayPairFixOf,
147+
type OverlayWriteClose,
147148
overrideDeclarationRefusedByShape,
148149
overrideWriteMemberOf,
149150
type OverrideWriteVerdictAsk,
@@ -756,15 +757,19 @@ export interface PackagelessWriteSubject {
756757
* locale the base does not ship is refused there (#28777) and stays open:
757758
* the ceremony moves such a row as the pair's own member, declaring
758759
* nothing (#28904), and the close reaches only the declared-override
759-
* moves, so its package-less write is the one it had before the close.
760+
* moves, so its package-less write is the one it had before the close;
761+
* - [#29594] an item a kernel package ships stays closed where it was
762+
* before the kernel verdict, though the ensure door creates no pair for
763+
* it: the subject carries the base's `kernelScope`, and the refusal says
764+
* kernel objects are not customizable in this version, naming no pair.
760765
*
761766
* Registry reads first; the one store read (the item's rows) only for a name
762767
* the registry has not already left open.
763768
*/
764769
export async function packagelessCloseSubject(
765770
this: PackagelessCloseHost,
766771
request: PackagelessWriteSubject,
767-
): Promise<{ base: string; pair: string } | null> {
772+
): Promise<OverlayWriteClose | null> {
768773
if (typeof request.packageId === 'string' && request.packageId.length > 0) return null;
769774
const type = PLURAL_TO_SINGULAR[request.type] ?? request.type;
770775
const shippers = this.overlayBaseShippers(request.type, request.name);
@@ -803,5 +808,5 @@ export async function packagelessCloseSubject(
803808

804809
// Step 2's gate: the declared body, into the pair.
805810
if (!overlayPairFixAdmits(this, fix, { type, name: request.name, body, member })) return null;
806-
return { base, pair: fix.pair };
811+
return fix.kernelScope === undefined ? { base, pair: fix.pair } : { base, pair: fix.pair, kernelScope: fix.kernelScope };
807812
}

‎packages/objectql/src/protocol-custom-override-effective-read.test.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ describe('[#28409] a same-named item outside X\'s closure is served under its ow
470470
* `<kernel>.custom` with overrides in it. The verdict refuses the ENSURE call
471471
* only: the pair stays installed, the overrides in it stay served by every
472472
* read of the base's name, and a further override saved into it is admitted
473-
* by the write gate, which never asks the ensure door.
473+
* by the write gate, which never asks the ensure door. The overlay-write
474+
* closes (ADR-0146 D11) stay shut on a kernel item, naming no pair.
474475
*/
475476
describe('[#29594] a kernel base\'s pair an earlier version created keeps serving its overrides', () => {
476477
it('the ensure call is refused 409; the override already in the pair is served, and another save into it lands', async () => {
@@ -496,7 +497,7 @@ describe('[#29594] a kernel base\'s pair an earlier version created keeps servin
496497
expect(columnsOf(await read(protocol))).toEqual(BASE_COLUMNS.slice(0, 3));
497498
});
498499

499-
it('the closes that named the pair leave a kernel item\'s save open: there is no pair to send it to', async () => {
500+
it('the closes keep refusing a kernel item\'s save, naming no pair: kernel objects are not customizable in this version', async () => {
500501
const body = listBody(UNBOUND_COLUMNS);
501502
// Control: an App's item — the package-less save and the save naming the base are closed onto the pair.
502503
const app = await boot();
@@ -505,11 +506,20 @@ describe('[#29594] a kernel base\'s pair an earlier version created keeps servin
505506
await expect(app.protocol.saveMetaItem({ type: 'view', name: VIEW, item: body, mode: 'draft', packageId: BASE } as any))
506507
.rejects.toMatchObject({ code: 'NOT_OVERRIDABLE', status: 403, message: expect.stringContaining(PAIR) });
507508

508-
// A kernel item: the ensure door creates no pair, so neither close names one.
509+
// A kernel item: still closed, 403 as before the kernel verdict, but
510+
// the ensure door creates no pair for it, so neither sentence names one.
509511
const kernel = await boot(baseManifest({ scope: 'system' }));
510-
await kernel.protocol.saveMetaItem({ type: 'view', name: VIEW, item: body, mode: 'draft' } as any);
511-
expect(kernel.rowsOf(VIEW).map((r) => r.package_id ?? null)).toEqual([null]);
512-
await kernel.protocol.saveMetaItem({ type: 'view', name: VIEW, item: body, mode: 'draft', packageId: BASE } as any);
513-
expect(kernel.rowsOf(VIEW).map((r) => r.package_id ?? null)).toEqual([null, BASE]);
512+
const packageless = await kernel.protocol.saveMetaItem({ type: 'view', name: VIEW, item: body, mode: 'draft' } as any)
513+
.then(() => null, (error: any) => error);
514+
expect(packageless).toMatchObject({ code: 'NOT_OVERRIDABLE', status: 403 });
515+
expect(packageless.message).toContain(`ships in kernel package '${BASE}' (scope 'system')`);
516+
expect(packageless.message).toContain('kernel objects are not customizable in this version, so a write naming no package is refused');
517+
expect(packageless.message).not.toContain(PAIR);
518+
const named = await kernel.protocol.saveMetaItem({ type: 'view', name: VIEW, item: body, mode: 'draft', packageId: BASE } as any)
519+
.then(() => null, (error: any) => error);
520+
expect(named).toMatchObject({ code: 'NOT_OVERRIDABLE', status: 403 });
521+
expect(named.message).toContain(`kernel objects are not customizable in this version, so a write naming '${BASE}' is refused`);
522+
expect(named.message).not.toContain(PAIR);
523+
expect(kernel.rowsOf(VIEW)).toEqual([]);
514524
});
515525
});

0 commit comments

Comments
 (0)