From 044e8f285497f6a7a77444b322bf93ada8a39caf Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 19:44:28 +0000 Subject: [PATCH 1/5] wip(objectql, runtime): the bare function read counts the platform and a disabled package Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 Co-Authored-By: Claude --- .../src/engine-hooks-and-functions.ts | 50 +++--- packages/objectql/src/engine.ts | 22 ++- .../objectql/src/package-scoped-resolver.ts | 46 ++++- ...are-name-one-holder-request-family.test.ts | 162 +++++++++++++++++- packages/runtime/src/app-artifact-handlers.ts | 19 +- 5 files changed, 252 insertions(+), 47 deletions(-) diff --git a/packages/objectql/src/engine-hooks-and-functions.ts b/packages/objectql/src/engine-hooks-and-functions.ts index 9c02d9914b8..f348c559fac 100644 --- a/packages/objectql/src/engine-hooks-and-functions.ts +++ b/packages/objectql/src/engine-hooks-and-functions.ts @@ -47,6 +47,7 @@ import { resolvePackageScopedHolders, type PackageScopedHolderSource, } from '@objectstack/core'; +import { callerlessFunctionResolution } from './package-scoped-resolver.js'; import { hookStoppedRefusal } from './summary-errors.js'; import { startSummaryRefreshOnEnable } from './summary-enable-refresh.js'; import { HookTargetRebindError } from './hook-target-rebind-errors.js'; @@ -93,31 +94,39 @@ export interface HooksAndFunctionsHost { /** The bodies of the "Class head: units, hooks, functions, body runners, hook dispatch" section of `ObjectQL`: a stateless facet, called by the class's stubs. */ /** - * [ADR-0150 D3/D4, #31700; epic seat ruling R2-C, 6812862622] The bare - * function map's entry for `name` — the last registration of the name — - * unless two PACKAGES hold it, which two namespaces may since #31700: then no - * entry is picked, and the read is refused as the rule refuses a caller with - * no package (`resolvePackageScopedHolders`, `ambiguous-in-environment`), - * naming every holder. A name one package holds, and an owner-less (platform) - * registration, answer as before. A reader that knows its package resolves - * through `functionHoldersOf` (the flow `script` node, #32073). + * [ADR-0150 D3/D4, #31700, #32907; epic seat ruling R2-C, 6812862622] The + * bare function map's entry for `name` — the last registration of the name — + * when ONE holder holds it. Two or more holders get no pick, in whatever + * order they registered: two PACKAGES (two namespaces may each hold one since + * #31700), or the PLATFORM (an owner-less registration) beside a package. The + * read is refused as the rule refuses a caller with no package + * (`resolvePackageScopedHolders`, `ambiguous-in-environment`), naming every + * holder. A disabled package is counted and never answered + * ({@link callerlessFunctionResolution}, #32933). A name one package holds, + * and one only the platform holds, answer as before. A reader that knows its + * package resolves through `functionHoldersOf` (the flow `script` node, + * #32073). * * @throws {PackageScopedNameRefusedError} `409 RESOURCE_CONFLICT`, every holder named. */ function bareFunctionEntry( - host: Pick, + host: Pick, name: string, ): Readonly | undefined { - const holders = host.functionHolders.get(name); - if (holders && [...holders.keys()].filter((holder) => holder !== null).length > 1) { - const refused = resolvePackageScopedHolders( + const resolution = callerlessFunctionResolution( + resolvePackageScopedHolders( { type: ENGINE_FUNCTION_TYPE, name, callerPackageId: null }, HooksAndFunctionsFacet.functionHoldersOf.call(host, name), () => new Set(), - ); - if (refused.status === 'refused') throw new PackageScopedNameRefusedError(refused); - } - return host.functions.get(name); + ), + (packageId) => host._registry.isPackageDisabled(packageId), + ); + if (resolution.status === 'refused') throw new PackageScopedNameRefusedError(resolution); + // The one holder's answer is the bare map's entry, as it always was: the + // holder set keeps the same entry object for it (`registerFunction`), and + // `unregisterFunctionsByPackage` puts it back when the last registration + // leaves (#32534). + return resolution.status === 'resolved' ? host.functions.get(name) : undefined; } export class HooksAndFunctionsFacet { @@ -303,12 +312,12 @@ export class HooksAndFunctionsFacet { } /** The body of `ObjectQL#resolveFunction`; the method's docblock there is its contract. */ - static resolveFunction(this: Pick, name: string): HookHandler | undefined { + static resolveFunction(this: Pick, name: string): HookHandler | undefined { return bareFunctionEntry(this, name)?.handler; } /** The body of `ObjectQL#resolveFunctionEntry`; the method's docblock there is its contract. */ - static resolveFunctionEntry(this: Pick, name: string): Readonly | undefined { + static resolveFunctionEntry(this: Pick, name: string): Readonly | undefined { return bareFunctionEntry(this, name); } @@ -331,8 +340,9 @@ export class HooksAndFunctionsFacet { // [#32534] The bare entry left with the last registration while ONE // holder of the name remains: that holder's entry is the bare answer, as // a one-holder name's always is. Two or more remaining holders get no - // pick (the bare read of two packages' name stays refused, naming them), - // and an owner-less registration never leaves with a package. + // pick (the bare read of two holders' name stays refused, naming them, + // the platform's owner-less registration among them, #32907), and an + // owner-less registration never leaves with a package. else if (holders.size === 1 && !this.functions.has(name)) this.functions.set(name, [...holders.values()][0]); } if (removed > 0) { diff --git a/packages/objectql/src/engine.ts b/packages/objectql/src/engine.ts index 5d84cb5566a..74609aef739 100644 --- a/packages/objectql/src/engine.ts +++ b/packages/objectql/src/engine.ts @@ -761,13 +761,16 @@ export class ObjectQL implements IObjectQLEngine { /** * Look up a registered function by name, with no package: the last - * registration of the name. [ADR-0150 D3/D4, #31700; epic seat ruling R2-C] - * A name two packages hold (two namespaces may each bind one) is refused, - * `409 RESOURCE_CONFLICT` naming every holder, never answered with one of - * them; a reader that knows its package resolves through - * {@link functionHoldersOf}. + * registration of the name. [ADR-0150 D3/D4, #31700, #32907; epic seat + * ruling R2-C] A name two holders hold — two packages (two namespaces may + * each bind one), or the platform (an owner-less registration) beside a + * package — is refused, `409 RESOURCE_CONFLICT` naming every holder, never + * answered with one of them, whichever registered last. [#32933] A disabled + * package is counted as a holder and never answered: a name only a disabled + * package holds answers nothing. A reader that knows its package resolves + * through {@link functionHoldersOf}. * - * @throws {PackageScopedNameRefusedError} for a name two packages hold. + * @throws {PackageScopedNameRefusedError} for a name two holders hold. */ resolveFunction(name: string): HookHandler | undefined { // [#29986 codemod] The body moved to `engine-hooks-and-functions.ts` (see `HooksAndFunctionsHost`). @@ -780,9 +783,10 @@ export class ObjectQL implements IObjectQLEngine { * it"; a caller that must also report what the call did (the automation * engine's `script` node, feeding the #4354 run summary) needs the * declaration, and reading it off the same registry keeps the two from - * drifting. Refused alike for a name two packages hold (above). + * drifting. Refused alike for a name two holders hold, and answers nothing + * alike for a name only a disabled package holds (above). * - * @throws {PackageScopedNameRefusedError} for a name two packages hold. + * @throws {PackageScopedNameRefusedError} for a name two holders hold. */ resolveFunctionEntry(name: string): Readonly | undefined { // [#29986 codemod] The body moved to `engine-hooks-and-functions.ts` (see `HooksAndFunctionsHost`). @@ -799,7 +803,7 @@ export class ObjectQL implements IObjectQLEngine { * `script` node resolves through it (#32073), and `bindHooksToEngine` reads * a hook's own package's entry from it. `resolveFunction` and * `resolveFunctionEntry` answer the one last-registered entry per name, and - * refuse a name two packages hold (#31700). + * refuse a name two holders hold (#31700, #32907). */ functionHoldersOf(name: string): PackageScopedHolderSource> { // [#31716] The body lives in `engine-hooks-and-functions.ts` (see `HooksAndFunctionsHost`). diff --git a/packages/objectql/src/package-scoped-resolver.ts b/packages/objectql/src/package-scoped-resolver.ts index 7ea672fa607..be02c13d762 100644 --- a/packages/objectql/src/package-scoped-resolver.ts +++ b/packages/objectql/src/package-scoped-resolver.ts @@ -177,6 +177,34 @@ export interface PackageScopedFunctionQuery { /** The engine slice the function adapter reads — every member of it, and no other. */ export type PackageScopedFunctionEngine = Pick; +/** + * [ADR-0150 D3, #32933; ruling A 6824698376, #32497] A function read that + * names no package — the engine's bare read (`ObjectQL#resolveFunction` / + * `resolveFunctionEntry`) and {@link resolvePackageScopedFunction} with no + * caller package — COUNTS every holder of the name and never RESOLVES TO a + * disabled one. + * + * Counted: `resolution` is the rule's answer over every holder, a disabled + * package's included, so a name a disabled package makes ambiguous stays + * refused, naming it (ruling A: a disabled package is still a holder; a + * disable never turns a refusal into an answer). Never resolved to: when the + * one holder the rule picked for a caller with no package (`unique-holder`, + * the step only such a caller reaches) is a disabled package, nothing answers + * — the served holders (#32497's default) are none. Every other answer passes + * through unchanged: a refusal, the platform's item, and a caller package's + * own item or its closure's holder (`own` / `closure`, a reader that names + * its package). + */ +export function callerlessFunctionResolution( + resolution: PackageScopedResolution, + isPackageDisabled: (packageId: string) => boolean, +): PackageScopedResolution { + if (resolution.status !== 'resolved' || resolution.via !== 'unique-holder' || resolution.holder.kind !== 'package') { + return resolution; + } + return isPackageDisabled(resolution.holder.packageId) ? { status: 'not-found' } : resolution; +} + /** * Resolve the function a flow's `script` node names, in the package of that * flow (ADR-0150 D4's last row): the rule (`resolvePackageScopedHolders`) @@ -194,17 +222,23 @@ export type PackageScopedFunctionEngine = Pick> { const registry = engine.registry; - return resolvePackageScopedHolders( - { type: ENGINE_FUNCTION_TYPE, name: query.name, callerPackageId: query.callerPackageId }, - engine.functionHoldersOf(query.name), - (callerPackageId) => packageResolutionClosure(registry, callerPackageId), + return callerlessFunctionResolution( + resolvePackageScopedHolders( + { type: ENGINE_FUNCTION_TYPE, name: query.name, callerPackageId: query.callerPackageId }, + engine.functionHoldersOf(query.name), + (callerPackageId) => packageResolutionClosure(registry, callerPackageId), + ), + (packageId) => registry.isPackageDisabled(packageId), ); } diff --git a/packages/objectql/src/registry-bare-name-one-holder-request-family.test.ts b/packages/objectql/src/registry-bare-name-one-holder-request-family.test.ts index 54a915daf7b..49673ea336f 100644 --- a/packages/objectql/src/registry-bare-name-one-holder-request-family.test.ts +++ b/packages/objectql/src/registry-bare-name-one-holder-request-family.test.ts @@ -53,7 +53,9 @@ import { bareNameReason, handlerOwnerPackageId, } from './bare-name-one-holder.js'; -import type { HookHandler, ObjectQL } from './engine.js'; +import { ObjectQL } from './engine.js'; +import type { HookHandler } from './engine.js'; +import { resolvePackageScopedFunction } from './package-scoped-resolver.js'; type ManifestService = { register(m: unknown): void | Promise }; type Holder = { kind: string; packageId?: string }; @@ -880,13 +882,12 @@ describe('[#32534] the bare engine function read after a holder leaves', () => { expect(ql.resolveFunction('platform_fn')).toBe(platform); }); - // CURRENT BEHAVIOUR, see #32907 — not the rule. ADR-0150 D4 refuses a caller - // with no package `ambiguous-in-environment` when the platform and a package - // both hold a name (a 409 naming each); the bare read counts package holders - // only (epic seat ruling R2-C), so this pair answers nothing here. #32907 - // aligns the bare read with D4 and flips this pin on purpose. What it pins - // for #32534: the restore picks no holder of two. - it('CONTROL (current behaviour, see #32907) — the platform and one package remain after the last-registered package leaves: two holders, so the restore picks nothing', async () => { + // [#32907] Flipped from the CONTROL that pinned the current behaviour: ADR-0150 + // D4 refuses a caller with no package `ambiguous-in-environment` when the + // platform and a package both hold a name, and the bare read now counts the + // platform beside the packages. What it still pins for #32534: the restore + // picks no holder of two (FROM nothing TO 409 naming both). + it('the platform and one package remain after the last-registered package leaves: two holders, so the restore picks nothing and the bare read is refused naming both (FROM nothing TO 409)', async () => { const { ql } = await boot(); ql.registerFunction('platform_fn', fn('platform')); ql.registerFunction('platform_fn', fn('alpha'), { packageId: 'app:com.acme.alpha' }); @@ -894,6 +895,149 @@ describe('[#32534] the bare engine function read after a holder leaves', () => { ql.unregisterFunctionsByPackage('app:com.acme.beta'); expect(ql.functionHoldersOf('platform_fn').packageHolders).toEqual(['com.acme.alpha']); expect(ql.functionHoldersOf('platform_fn').platformItem?.()).toBeDefined(); - expect(ql.resolveFunctionEntry('platform_fn')).toBeUndefined(); + expectPlatformAndPackageRefused(await caught(() => ql.resolveFunctionEntry('platform_fn')), 'com.acme.alpha'); + expectPlatformAndPackageRefused(await caught(() => ql.resolveFunction('platform_fn')), 'com.acme.alpha'); + }); +}); + +/** A bare read refused because the platform and `packageId` both hold the name: the ADR-0112 envelope and both holders, the package first. */ +function expectPlatformAndPackageRefused(err: Refusal | undefined, packageId: string) { + expect(err, 'the bare read was refused').toBeDefined(); + expect(err!.name).toBe('PackageScopedNameRefusedError'); + expect(err!.code).toBe('RESOURCE_CONFLICT'); + expect(err!.status).toBe(409); + expect((err as Refusal & { refusal?: { reason: string; candidates: unknown[] } }).refusal).toMatchObject({ + reason: 'ambiguous-in-environment', + callerPackageId: null, + candidates: [{ kind: 'package', packageId }, { kind: 'platform' }], + }); +} + +// [#32907, ADR-0150 D4] The bare function read (`resolveFunction`, +// `resolveFunctionEntry`: a caller with no package) when the platform (an +// owner-less registration) and one package hold a name: refused with the same +// 409 as two packages, naming both, in either registration order. Before, it +// answered whichever registered last. +describe('[#32907] the bare engine function read when the platform and one package hold the name', () => { + it.each([ + ['the package registered last (FROM the package\'s entry TO 409)', ['platform', 'package']], + ['the platform registered last (FROM the platform\'s entry TO 409)', ['package', 'platform']], + ] as const)('%s', async (_case, order) => { + const { ql } = await boot(); + for (const holder of order) { + if (holder === 'platform') ql.registerFunction('shared_fn', fn('platform')); + else ql.registerFunction('shared_fn', fn('alpha'), { packageId: 'app:com.acme.alpha' }); + } + expectPlatformAndPackageRefused(await caught(() => ql.resolveFunctionEntry('shared_fn')), 'com.acme.alpha'); + expectPlatformAndPackageRefused(await caught(() => ql.resolveFunction('shared_fn')), 'com.acme.alpha'); + // The caller-less package-scoped read already refused it: the two reads agree. + expect(resolvePackageScopedFunction(ql, { name: 'shared_fn', callerPackageId: null })).toMatchObject({ + status: 'refused', reason: 'ambiguous-in-environment', + }); + }); + + it('CONTROL — the platform alone, and one package alone, answer their own entry, unchanged', async () => { + const { ql } = await boot(); + const platform = fn('platform'); + const alpha = fn('alpha'); + ql.registerFunction('platform_only', platform); + ql.registerFunction('alpha_only', alpha, { packageId: 'app:com.acme.alpha' }); + expect(ql.resolveFunction('platform_only')).toBe(platform); + expect(ql.resolveFunction('alpha_only')).toBe(alpha); + expect(ql.resolveFunctionEntry('alpha_only')?.packageId).toBe('app:com.acme.alpha'); + }); + + it('CONTROL — a caller package that holds the name itself still resolves its own, beside the platform', async () => { + const { ql, register } = await boot(); + expect(await register(pkg('com.acme.alpha'))).toBeUndefined(); + ql.registerFunction('shared_fn', fn('platform')); + bindFunctions(ql, 'com.acme.alpha', ['shared_fn']); + expect(resolvePackageScopedFunction(ql, { name: 'shared_fn', callerPackageId: 'com.acme.alpha' })).toMatchObject({ + status: 'resolved', via: 'own', holder: { kind: 'package', packageId: 'com.acme.alpha' }, + }); + }); +}); + +// [#32933; ruling A 6824698376, #32497] A function read that names no package +// counts a disabled package as a holder and is never answered with its +// function; the every-holder doors (the hook binder's bind after the seal, the +// seal itself) count it as before. +describe('[#32933] the engine function holder set and a disabled package', () => { + /** Alpha installed and binding `alpha_fn` after the seal, then disabled. */ + const disabledAlpha = async () => { + const booted = await boot(); + expect(await booted.register(pkg('com.acme.alpha'))).toBeUndefined(); + bindFunctions(booted.ql, 'com.acme.alpha', ['alpha_fn']); + booted.registry.disablePackage('com.acme.alpha'); + return booted; + }; + + it('a name only a disabled package holds: the bare read and the caller-less read answer nothing; enabled again, both answer it (FROM its entry TO nothing)', async () => { + const { ql, registry } = await disabledAlpha(); + const alphas = ql.functionHoldersOf('alpha_fn').packageItem('com.acme.alpha'); + expect(alphas, 'precondition: alpha still registers it').toBeDefined(); + + expect(ql.resolveFunctionEntry('alpha_fn')).toBeUndefined(); + expect(ql.resolveFunction('alpha_fn')).toBeUndefined(); + expect(resolvePackageScopedFunction(ql, { name: 'alpha_fn', callerPackageId: null })).toEqual({ status: 'not-found' }); + + registry.enablePackage('com.acme.alpha'); + expect(ql.resolveFunctionEntry('alpha_fn')).toBe(alphas); + expect(resolvePackageScopedFunction(ql, { name: 'alpha_fn', callerPackageId: null })).toMatchObject({ + status: 'resolved', via: 'unique-holder', item: alphas, + }); + }); + + it('CONTROL — the disabled package\'s own read (a caller of that package) resolves its own function, unchanged', async () => { + const { ql } = await disabledAlpha(); + expect(resolvePackageScopedFunction(ql, { name: 'alpha_fn', callerPackageId: 'com.acme.alpha' })).toMatchObject({ + status: 'resolved', via: 'own', holder: { kind: 'package', packageId: 'com.acme.alpha' }, + }); + }); + + it('counted: the platform beside a disabled package is still two holders — the bare read is refused naming both, never answered with the platform', async () => { + const { ql } = await disabledAlpha(); + ql.registerFunction('alpha_fn', fn('platform')); + expectPlatformAndPackageRefused(await caught(() => ql.resolveFunctionEntry('alpha_fn')), 'com.acme.alpha'); + expect(resolvePackageScopedFunction(ql, { name: 'alpha_fn', callerPackageId: null })).toMatchObject({ + status: 'refused', candidates: [{ kind: 'package', packageId: 'com.acme.alpha' }, { kind: 'platform' }], + }); + }); + + it('CONTROL — counted: two namespaces\' packages, one disabled, stay refused naming both, unchanged', async () => { + const { ql, register, registry } = await boot(); + expect(await register(pkg('com.acme.alpha'))).toBeUndefined(); + expect(await register(pkg('com.acme.beta'))).toBeUndefined(); + bindFunctions(ql, 'com.acme.alpha', ['shared_fn']); + bindFunctions(ql, 'com.acme.beta', ['shared_fn']); + registry.disablePackage('com.acme.beta'); + const err = await caught(() => ql.resolveFunctionEntry('shared_fn')); + expect(err?.code).toBe('RESOURCE_CONFLICT'); + expect(err?.status).toBe(409); + expect((err as Refusal & { refusal?: { candidates: unknown[] } }).refusal?.candidates).toEqual([ + { kind: 'package', packageId: 'com.acme.alpha' }, + { kind: 'package', packageId: 'com.acme.beta' }, + ]); + }); + + it('CONTROL — every holder at the door: after the seal, a co-owner\'s bind of a name a disabled package holds is refused naming it, unchanged', async () => { + const { ql, register } = await disabledAlpha(); + expect(await register(rival('function', 'com.acme.beta'))).toBeUndefined(); + const err = await caught(() => bindFunctions(ql, 'com.acme.beta', ['alpha_fn'])); + expect(err?.code).toBe(NAMESPACE_CONFLICT_CODE); + expect(err!.conflicts!.map((c) => c.existingHolder)).toEqual([{ kind: 'package', packageId: 'com.acme.alpha' }]); + }); + + it('CONTROL — every holder at the seal: a cold boot whose co-owners both bind a name, one of them disabled, reports the clash, unchanged', () => { + const ql = new ObjectQL(); + ql.registry.logLevel = 'silent'; + ql.registry.installPackage(pkg('com.acme.alpha') as never, 'code' as never); + ql.registry.installPackage(rival('function', 'com.acme.beta') as never, 'code' as never); + bindFunctions(ql, 'com.acme.alpha', ['shared_fn']); + bindFunctions(ql, 'com.acme.beta', ['shared_fn']); + ql.registry.disablePackage('com.acme.alpha'); + expect(ql.registry.sealBareNameHolders().map((c) => [c.type, c.name, c.existingHolder, c.incomingPackageId])).toEqual([ + ['function', 'shared_fn', { kind: 'package', packageId: 'com.acme.alpha' }, 'com.acme.beta'], + ]); }); }); diff --git a/packages/runtime/src/app-artifact-handlers.ts b/packages/runtime/src/app-artifact-handlers.ts index 60c48287482..5853e8de5a7 100644 --- a/packages/runtime/src/app-artifact-handlers.ts +++ b/packages/runtime/src/app-artifact-handlers.ts @@ -548,10 +548,10 @@ interface FunctionHoldingEngine { readonly registry?: { releaseBareNameFunctions?(owner: string | undefined, stillHolds: (name: string) => boolean): void }; unregisterFunctionsByPackage?(packageId: string): number; registerFunction?(name: string, handler: any, options?: { packageId?: string; effect?: unknown }): void; - resolveFunctionEntry?(name: string): { readonly handler: any; readonly packageId?: string; readonly effect?: unknown } | undefined; functionHoldersOf?(name: string): { readonly packageHolders: readonly string[]; packageItem(packageId: string): { readonly handler: any; readonly packageId?: string; readonly effect?: unknown } | undefined; + platformItem?(): unknown; }; } @@ -581,7 +581,19 @@ function hookHandlersOf(groups: readonly HookBindingGroup[], owner: string): str * [#31700, epic seat ruling R3-B] Only for a name one package holds: two * namespaces' packages may each hold one function name, and the bare read of * such a name is refused (409, ADR-0150 D3) and answers no reader, so for it - * `holder`'s own entry is all that is read and put back. + * `holder`'s own entry is all that is read and put back. [#32907] The same + * for a name the platform (an owner-less registration) holds beside + * `holder`: its bare read is refused too. + * + * [#32907, #32933] The bare slot is read off the holder set, never through + * the bare read: for a name `holder`'s package alone holds, the bare map's + * entry IS that package's holder entry (`registerFunction` stores one entry + * object in both, and the engine puts the holder's entry back in the bare map + * when another holder's last registration leaves). The bare read is a + * resolution, not that slot: it refuses a name the platform holds beside the + * package, which would abort this teardown, and answers nothing for a + * disabled package, which would re-register the kept function under + * `holder`'s spelling only and drop the spelling the slot held. */ function releaseMovedFunctions(engine: FunctionHoldingEngine, holder: string, moved: readonly string[], known: Iterable): void { if (typeof engine.registerFunction !== 'function' || typeof engine.functionHoldersOf !== 'function') return; @@ -592,7 +604,8 @@ function releaseMovedFunctions(engine: FunctionHoldingEngine, holder: string, mo if (leaving.has(name)) continue; const holders = engine.functionHoldersOf(name); const entry = holders.packageItem(packageId); - if (entry) keep.push({ name, entry, bare: holders.packageHolders.length > 1 ? undefined : engine.resolveFunctionEntry?.(name) }); + const shared = holders.packageHolders.length > 1 || holders.platformItem?.() !== undefined; + if (entry) keep.push({ name, entry, bare: shared ? undefined : entry }); } engine.unregisterFunctionsByPackage?.(holder); for (const { name, entry, bare } of keep) { From 90423f6b40d4fb9fc65d6809e6f40226667edcee Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 19:50:26 +0000 Subject: [PATCH 2/5] test(objectql, runtime): pins for the bare function read, the disabled holder and the release's runtime rows Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 Co-Authored-By: Claude --- .../runtime/src/app-artifact-handlers.test.ts | 138 +++++++++++++++++- 1 file changed, 134 insertions(+), 4 deletions(-) diff --git a/packages/runtime/src/app-artifact-handlers.test.ts b/packages/runtime/src/app-artifact-handlers.test.ts index 2d4611ed3bb..381f2a86fc3 100644 --- a/packages/runtime/src/app-artifact-handlers.test.ts +++ b/packages/runtime/src/app-artifact-handlers.test.ts @@ -656,9 +656,12 @@ describe('[ADR-0150 D4] a multi-package artifact binds each body\'s hooks and fu // or by beta and a package of another namespace too, as two namespaces may // hold one function name since #31700: a bare read of that name is refused // (409), so the teardown reads beta's own entry and never aborts on it. + // [#32907] …or by beta and the platform (an owner-less registration): that + // bare read is refused too since #32907, and the teardown still runs whole. it.each([ ['beta alone holds the name it keeps (CONTROL: the bare slot answers as before)', false], - ['another namespace\'s package holds the name beta keeps too', true], + ['another namespace\'s package holds the name beta keeps too', 'package'], + ['the platform holds the name beta keeps too (#32907: its bare read is refused, and the teardown never asks it)', 'platform'], ] as const)('a re-bind that moves a function to another owner takes it off the owner the previous bind gave it, which keeps its other functions — %s', async (_case, sharedKept) => { const GAMMA = 'com.qa.bodies.gamma'; const body = (ns: Ns, hooks: unknown[]) => ({ @@ -680,19 +683,26 @@ describe('[ADR-0150 D4] a multi-package artifact binds each body\'s hooks and fu const ql = engineFor(first, logger); bind(ql, first, logger); expect(ql.functionHoldersOf('qa_moving').packageHolders, 'precondition: only beta\'s hook names it').toEqual([BETA]); - if (sharedKept) ql.registerFunction('qa_kept', stamp('gamma'), { packageId: appArtifactHandlerOwner(GAMMA) }); + if (sharedKept === 'package') ql.registerFunction('qa_kept', stamp('gamma'), { packageId: appArtifactHandlerOwner(GAMMA) }); + if (sharedKept === 'platform') ql.registerFunction('qa_kept', stamp('platform')); // Now the top level names it too: one function two owners' hooks name, under the artifact's id. bind(ql, artifactWith([hookOn('alpha', 'qa_res_moving', 'qa_moving')]), logger); expect(errors.map((e) => e.message), 'the teardown ran whole').toEqual([]); expect(ql.functionHoldersOf('qa_moving').packageHolders, 'held once, by the artifact\'s id').toEqual([ALPHA]); - expect([...ql.functionHoldersOf('qa_kept').packageHolders].sort(), 'beta keeps the function only its hook names').toEqual(sharedKept ? [BETA, GAMMA] : [BETA]); + expect([...ql.functionHoldersOf('qa_kept').packageHolders].sort(), 'beta keeps the function only its hook names').toEqual(sharedKept === 'package' ? [BETA, GAMMA] : [BETA]); expect(String(await insertInto(ql, 'beta')).split(';').filter(Boolean).sort()).toEqual(['kept', 'moving']); expect(await insertInto(ql, 'alpha')).toBe('moving;'); - if (sharedKept) { + if (sharedKept === 'package') { expect(ql.functionHoldersOf('qa_kept').packageItem(GAMMA)?.packageId, 'the other holder keeps its own').toBe(appArtifactHandlerOwner(GAMMA)); expect(() => ql.resolveFunctionEntry('qa_kept'), 'the bare read of a name two packages hold stays refused').toThrow(/com\.qa\.bodies\.beta[\s\S]*com\.qa\.bodies\.gamma|com\.qa\.bodies\.gamma[\s\S]*com\.qa\.bodies\.beta/); + } else if (sharedKept === 'platform') { + expect(ql.functionHoldersOf('qa_kept').platformItem?.(), 'the platform keeps its own').toBeDefined(); + let refused: any; + try { ql.resolveFunctionEntry('qa_kept'); } catch (e) { refused = e; } + expect([refused?.code, refused?.status], 'the bare read of a name the platform and beta hold is refused').toEqual(['RESOURCE_CONFLICT', 409]); + expect(refused.refusal.candidates).toEqual([{ kind: 'package', packageId: BETA }, { kind: 'platform' }]); } else { expect(ql.resolveFunctionEntry('qa_kept')?.packageId).toBe(appArtifactHandlerOwner(BETA)); } @@ -873,6 +883,126 @@ describe('[ADR-0150 D4] a multi-package artifact binds each body\'s hooks and fu expect(kept?.code, 'CONTROL: beta still holds what it keeps').toBe('NAMESPACE_CONFLICT'); expect(holdersNamed(kept)).toEqual([BETA]); }); + + // [#32910] The release's three runtime rows the registry-method pins did + // not reach: a re-bind before the seal, the ordering of the move path, + // and the owner-spelling order where the bare-id registration comes first. + describe('[#32910] the release through a runtime re-bind: before the seal, the move path\'s ordering, and the other owner-spelling order', () => { + const betaMovingHooks = [hookOn('beta', 'qa_beta_moving', 'qa_moving'), hookOn('beta', 'qa_beta_kept', 'qa_kept')]; + const fns = { qa_moving: stamp('moving'), qa_kept: stamp('kept') }; + + // N4: the release runs on a re-bind made before the cold-boot seal too, + // so the seal finds no clash the re-bind left behind. Gamma (a + // co-owner of beta's namespace) binds the name before the seal, so a + // claim beta kept would be a clash for the seal to report. + it.each([ + ['a function moved to the artifact\'s own package', 'moved'], + ['a dropped body\'s function', 'dropped'], + ] as const)('a re-bind before the seal releases the old owner\'s claim on %s: the seal reports no clash', (_case, shape) => { + const first = shape === 'moved' + ? movingArtifact(betaMovingHooks, [], fns) + : movingArtifact([hookOn('beta', 'qa_beta_only', 'qa_moving')], [], { qa_moving: stamp('moving') }); + const { errors, logger } = recordingErrors(); + const ql = engineFor(first, logger); + installGamma(ql); + bind(ql, first, logger); + bind(ql, shape === 'moved' + ? movingArtifact(betaMovingHooks, [hookOn('alpha', 'qa_res_moving', 'qa_moving')], fns) + : { ...first, packages: [first.packages[0]], functions: { qa_alpha_own: stamp('alpha_own') } }, logger); + if (shape === 'dropped') expect(gammaBinds(ql, 'qa_moving'), 'before the seal nothing is refused').toBeUndefined(); + + expect(errors.map((e) => e.message), 'every group bound').toEqual([]); + expect(ql.functionHoldersOf('qa_moving').packageHolders).toEqual(shape === 'moved' ? [ALPHA] : [GAMMA]); + expect(ql.registry.sealBareNameHolders(), 'beta holds no claim on it any more').toEqual([]); + }); + + // D2-N1: what the old owner keeps is registered again BEFORE the + // release asks the engine what it still holds. A function the previous + // bind gave beta that the new bind neither moves nor gives back to it + // is held again only by that registration, and nothing re-claims it: + // the ordering alone keeps its claim. + it('CONTROL — the move path releases after the old owner\'s kept functions are registered again: a function the new bind neither moves nor gives back keeps its claim', () => { + const first = movingArtifact( + [...betaMovingHooks, hookOn('beta', 'qa_beta_prev_hook', 'qa_prev')], + [], + { ...fns, qa_prev: stamp('prev') }, + ); + const { errors, logger } = recordingErrors(); + const ql = engineFor(first, logger); + installGamma(ql); + bind(ql, first, logger); + expect(ql.registry.sealBareNameHolders()).toEqual([]); + + bind(ql, movingArtifact(betaMovingHooks, [hookOn('alpha', 'qa_res_moving', 'qa_moving')], fns), logger); + + expect(errors.map((e) => e.message), 'every group bound').toEqual([]); + expect(ql.functionHoldersOf('qa_moving').packageHolders).toEqual([ALPHA]); + expect(ql.functionHoldersOf('qa_prev').packageHolders, 'beta keeps the function the new bind does not name').toEqual([BETA]); + const prev = gammaBinds(ql, 'qa_prev'); + expect(prev?.code, 'beta keeps its claim on it').toBe('NAMESPACE_CONFLICT'); + expect(holdersNamed(prev)).toEqual([BETA]); + }); + + // D2-N2: the bare-id registration FIRST, then the bind under + // `app:`: the engine's one holder entry for beta is the bind's, so + // the removal by `app:` takes the name off beta and the release + // frees its claim. (The bare-id-last order is the two CONTROLs above.) + it.each([ + ['moved: the gaining owner\'s group binds', 'moved'], + ['dropped: a co-owner binds the name', 'dropped'], + ] as const)('the package\'s bare-id registration before the bind: the removal takes the holder entry the bind replaced it with, and the claim is released — %s', (_case, shape) => { + const first = shape === 'moved' + ? movingArtifact([hookOn('beta', 'qa_beta_moving', 'qa_moving')], [], { qa_moving: stamp('moving') }) + : movingArtifact([hookOn('beta', 'qa_beta_only', 'qa_moving')], [], { qa_moving: stamp('moving') }); + const { errors, logger } = recordingErrors(); + const ql = engineFor(first, logger); + installGamma(ql); + // A host's own registration for beta, under the bare id, BEFORE the bind. + ql.registerFunction('qa_moving', stamp('host'), { packageId: BETA }); + bind(ql, first, logger); + expect(ql.functionHoldersOf('qa_moving').packageItem(BETA)?.packageId, 'precondition: the bind replaced beta\'s entry').toBe(appArtifactHandlerOwner(BETA)); + expect(ql.registry.sealBareNameHolders()).toEqual([]); + + bind(ql, shape === 'moved' + ? movingArtifact([hookOn('beta', 'qa_beta_moving', 'qa_moving')], [hookOn('alpha', 'qa_res_moving', 'qa_moving')], { qa_moving: stamp('moving') }) + : { ...first, packages: [first.packages[0]], functions: { qa_alpha_own: stamp('alpha_own') } }, logger); + + expect(errors.map((e) => e.message), 'every group bound').toEqual([]); + if (shape === 'moved') { + expect(ql.functionHoldersOf('qa_moving').packageHolders, 'held by the gaining owner alone').toEqual([ALPHA]); + expect(holdersNamed(gammaBinds(ql, 'qa_moving'))).toEqual([ALPHA]); + } else { + expect(ql.functionHoldersOf('qa_moving').packageHolders, 'no holder is left').toEqual([]); + expect(gammaBinds(ql, 'qa_moving'), 'no claim is left to refuse it').toBeUndefined(); + } + }); + + // [#32933] The move path reads the bare slot of a kept name off the + // holder set, never through the bare read, which answers nothing for + // a disabled package: a disabled old owner keeps what it keeps under + // the owner spelling it held it by, and its claim. + it('CONTROL — a disabled old owner keeps a kept function under the spelling it held it by, and its claim', () => { + const first = movingArtifact( + [...betaMovingHooks, hookOn('beta', 'qa_beta_prev_hook', 'qa_prev')], + [], + { ...fns, qa_prev: stamp('prev') }, + ); + const { errors, logger } = recordingErrors(); + const ql = engineFor(first, logger); + installGamma(ql); + bind(ql, first, logger); + // A host's own registration for beta, under the bare id, after the bind: the slot it holds. + ql.registerFunction('qa_prev', stamp('host'), { packageId: BETA }); + expect(ql.registry.sealBareNameHolders()).toEqual([]); + ql.registry.disablePackage(BETA); + + bind(ql, movingArtifact(betaMovingHooks, [hookOn('alpha', 'qa_res_moving', 'qa_moving')], fns), logger); + + expect(errors.map((e) => e.message), 'every group bound').toEqual([]); + expect(ql.functionHoldersOf('qa_prev').packageItem(BETA)?.packageId, 'the bare-id spelling it held').toBe(BETA); + expect(holdersNamed(gammaBinds(ql, 'qa_prev')), 'its claim stays').toEqual([BETA]); + }); + }); }); it('CONTROL — on a built artifact a body\'s hook binds the handler ref its runtime module serves at the top level; a residual hook binds under the artifact\'s id', async () => { From e8106eb3327cd05e610b722591225ee0969024d8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 19:52:01 +0000 Subject: [PATCH 3/5] fix(runtime): the re-bind puts back the kept function's own holder entry, read off the holder set Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 Co-Authored-By: Claude --- packages/runtime/src/app-artifact-handlers.ts | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/runtime/src/app-artifact-handlers.ts b/packages/runtime/src/app-artifact-handlers.ts index 5853e8de5a7..67609a21d71 100644 --- a/packages/runtime/src/app-artifact-handlers.ts +++ b/packages/runtime/src/app-artifact-handlers.ts @@ -551,7 +551,6 @@ interface FunctionHoldingEngine { functionHoldersOf?(name: string): { readonly packageHolders: readonly string[]; packageItem(packageId: string): { readonly handler: any; readonly packageId?: string; readonly effect?: unknown } | undefined; - platformItem?(): unknown; }; } @@ -581,19 +580,19 @@ function hookHandlersOf(groups: readonly HookBindingGroup[], owner: string): str * [#31700, epic seat ruling R3-B] Only for a name one package holds: two * namespaces' packages may each hold one function name, and the bare read of * such a name is refused (409, ADR-0150 D3) and answers no reader, so for it - * `holder`'s own entry is all that is read and put back. [#32907] The same - * for a name the platform (an owner-less registration) holds beside - * `holder`: its bare read is refused too. - * - * [#32907, #32933] The bare slot is read off the holder set, never through - * the bare read: for a name `holder`'s package alone holds, the bare map's - * entry IS that package's holder entry (`registerFunction` stores one entry - * object in both, and the engine puts the holder's entry back in the bare map - * when another holder's last registration leaves). The bare read is a - * resolution, not that slot: it refuses a name the platform holds beside the - * package, which would abort this teardown, and answers nothing for a - * disabled package, which would re-register the kept function under - * `holder`'s spelling only and drop the spelling the slot held. + * `holder`'s own entry is all that is read and put back. + * + * [#32907, #32933] What is put back is `holder`'s package's own holder entry, + * read off the holder set, never through the bare read. For a name that + * package alone holds, that entry IS the bare slot (`registerFunction` stores + * one entry object in both, and the engine puts the holder's entry back in + * the bare map when another holder's last registration leaves). The bare read + * is a resolution, not that slot: it refuses a name the platform (an + * owner-less registration) holds beside the package, which would abort this + * teardown, and answers nothing for a disabled package, which would drop the + * owner spelling the package held the kept function by. Beside the platform, + * the package's entry is put back under its own spelling too; the bare read + * of that name is refused either way. */ function releaseMovedFunctions(engine: FunctionHoldingEngine, holder: string, moved: readonly string[], known: Iterable): void { if (typeof engine.registerFunction !== 'function' || typeof engine.functionHoldersOf !== 'function') return; @@ -604,8 +603,7 @@ function releaseMovedFunctions(engine: FunctionHoldingEngine, holder: string, mo if (leaving.has(name)) continue; const holders = engine.functionHoldersOf(name); const entry = holders.packageItem(packageId); - const shared = holders.packageHolders.length > 1 || holders.platformItem?.() !== undefined; - if (entry) keep.push({ name, entry, bare: shared ? undefined : entry }); + if (entry) keep.push({ name, entry, bare: holders.packageHolders.length > 1 ? undefined : entry }); } engine.unregisterFunctionsByPackage?.(holder); for (const { name, entry, bare } of keep) { From 039e6bb2e6a6400dba7ba7f79f928db047ba2466 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 19:54:35 +0000 Subject: [PATCH 4/5] chore(changeset): the bare function read's platform and disabled-holder answers Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 Co-Authored-By: Claude --- ...tion-read-platform-and-disabled-holders.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .changeset/32907-bare-function-read-platform-and-disabled-holders.md diff --git a/.changeset/32907-bare-function-read-platform-and-disabled-holders.md b/.changeset/32907-bare-function-read-platform-and-disabled-holders.md new file mode 100644 index 00000000000..bbb2b1787d0 --- /dev/null +++ b/.changeset/32907-bare-function-read-platform-and-disabled-holders.md @@ -0,0 +1,21 @@ +--- +'@objectstack/objectql': patch +'@objectstack/runtime': patch +--- + +fix(objectql, runtime)!: a function's bare-name read is refused naming both when the platform and a package hold the name, and answers nothing for a name only a disabled package holds (ADR-0150 D4) + +Clause-②: no (narrowing) — two engine function reads that name no package stop answering: `ObjectQL#resolveFunction` / `resolveFunctionEntry` refuse `409 RESOURCE_CONFLICT`, naming both, a name the platform (an owner-less registration) and a package hold, where they answered whichever registered last or, after another holder left, nothing; and they, with `resolvePackageScopedFunction` for a caller with no package (a flow `script` node of an environment-authored flow), answer nothing for a name only a disabled package holds, where they answered its function. Nothing that was refused is now answered, and no export is added. +Metadata-protocol: none + + + +**BREAKING** for a caller of `ObjectQL#resolveFunction` / `resolveFunctionEntry` (or a flow `script` node of an environment-authored flow) naming a function that host code or a plugin registers under no package and an installed package also registers: the call is now refused, naming both. Address the function by its package (`resolvePackageScopedFunction` with the caller's package, or a packaged flow), or rename one of the two. A caller naming a function only a disabled package registers now gets no function; enable the package to get it back. + +The engine keeps every holder of a function name: each package that registered one, and the platform for a registration under no package. A read that names no package resolves it by ADR-0150 D3 over those holders. + +- **The platform beside a package.** The bare read refused a name two packages hold, but counted packages only, so with the platform and one package it answered the last registration: the package's function if the package registered last, the platform's if the platform did, and nothing once a third package that registered last had left. It is now refused like two packages are, `409 RESOURCE_CONFLICT` with reason `ambiguous-in-environment`, naming the package and the platform, in every registration order. The package-scoped read with no caller package already refused it; the two reads now agree. +- **A disabled package.** A disabled package is still counted as a holder, so a name it makes ambiguous stays refused, naming it (ruling 6824698376: a disable never turns a refusal into an answer). It is no longer answered: a name only a disabled package holds answers nothing to a read that names no package, and answers again once the package is enabled. A reader naming the package itself (a flow of that package) still resolves its own function, and the hook binder's bind after the seal and the cold-boot seal still count the disabled package as a holder. +- **The runtime's re-bind** (`bindAppArtifactHandlers`, when a re-bind moves a function off a package) puts back the functions that package keeps from the package's own holder entry instead of the bare read. The bare read now refuses a name the platform holds beside the package, which would have aborted the re-bind's teardown, and answers nothing for a disabled package, which would have dropped the owner spelling the package held a kept function by. + +Not changed: a name one enabled package holds, or only the platform holds, answers its function as before; a name two packages hold stays refused naming both; a reader that names its package resolves as before. From a7b1de2a7510319114366953c7f169dbdd528a23 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 21:22:59 +0000 Subject: [PATCH 5/5] docs(objectql): point callerlessFunctionResolution at the core rule steps it relies on Review nit N1: a caller package stops at resolvePackageScopedHolders' steps 1-3; only the environment-wide branch answers unique-holder. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 --- packages/objectql/src/package-scoped-resolver.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/objectql/src/package-scoped-resolver.ts b/packages/objectql/src/package-scoped-resolver.ts index be02c13d762..d9d3da788f8 100644 --- a/packages/objectql/src/package-scoped-resolver.ts +++ b/packages/objectql/src/package-scoped-resolver.ts @@ -194,6 +194,12 @@ export type PackageScopedFunctionEngine = Pick( resolution: PackageScopedResolution,