diff --git a/.changeset/31985-tool-names-per-namespace.md b/.changeset/31985-tool-names-per-namespace.md new file mode 100644 index 00000000000..ba213077e81 --- /dev/null +++ b/.changeset/31985-tool-names-per-namespace.md @@ -0,0 +1,53 @@ +--- +'@objectstack/objectql': minor +'@objectstack/core': minor +'@objectstack/metadata': minor +--- + +feat(objectql)!: two packages of two namespaces may each ship a tool of the same name, and the metadata service keeps each package's tool under its own (package, name) slot (ADR-0150 child B) + +Clause-②: yes (narrowing) — widened: the engine's package door (`SchemaRegistry.installPackage`), its item seam (`SchemaRegistry.registerItem`) and the cold boot's holder seal (`SchemaRegistry.sealBareNameHolders`) accept, for a tool, a second package holder they refused before: one that declares a namespace other than the holder's. Narrowed: `tool` joins `PACKAGE_SLOTTED_STORE_TYPES` (`@objectstack/metadata`) in the same change, as that set's rule requires, so the metadata service's in-process answers for a tool move the way they moved for the other types stored per package: (1) `MetadataManager.get('tool', NAME)` and `getDiagnosed` naming no package, of a name two packages hold, are refused `409 RESOURCE_CONFLICT` (`ambiguous-in-environment`, naming both) where they answered the item registered (or saved) last; (2) `get('tool', NAME, PKG)` and `getDiagnosed`, where `PKG` holds no slot of the name and another package does, answer `undefined` where they answered the stored item (the one holder's, or the survivor of two); (3) `unregister('tool', NAME)` naming no package, of a name two packages hold, is refused the same way before anything is deleted or announced, and so is a rollback of a name whose rows are two packages', or one package's beside the name's package-less row; (4) `DatabaseLoader.delete` naming no package of a name two packages hold is refused, where it deleted the first row; (5) `MetadataManager.getHistory`, `diff` and `rollback` of a tool name two packages saved through `DatabaseLoader`, naming no package, are refused `409 RESOURCE_CONFLICT` naming both, where they answered every version of the one row both saves wrote, and a rollback to a version a removed package wrote is refused where it wrote that version into the remaining holder's row. First-party callers of these in-process reads and writes for a tool in this repo: 0 (no production source calls `get`, `getDiagnosed`, `unregister`, `getHistory`, `diff` or `rollback` with the literal type `tool`; first-party tool records in `examples/`: 0). On a booted stack no HTTP or MCP door moves from served to refused: `/meta/tool/NAME` reads through the registry's `resolveItem`, which already resolved a tool by `(package, name)` (ADR-0150 child E8), and on both HTTP transports `/meta/tool/NAME/layers` asks that plain read before it serves a layer, so a bare layered read of a two-holder name is refused `409` naming both whether or not the metadata service keeps both copies (measured with `tool` taken back out of `PACKAGE_SLOTTED_STORE_TYPES`: still `409`). The cloud's calls on the metadata service for type `tool` (a fixed-name existence probe, and AI Studio's register and retract of its built-in tool mirror, cloud reading 6837767385) are outside this count and carried to the cloud with the resolver obligation below. +Metadata-protocol: added + + + +**BREAKING** for five in-process answers of the metadata service for a tool (first-party count in this repo: 0), listed above under the declaration line. The fix for each: + +- FROM `get('tool', NAME)` of a two-holder name TO `get('tool', NAME, PKG)`, a package the refusal names. +- FROM `get('tool', NAME, PKG)` for a package that does not hold the name TO `get('tool', NAME, HOLDER)`, the holding package (the bare read's refusal, or `list`, names it). +- FROM `unregister('tool', NAME)` of a two-holder name TO `unregister('tool', NAME, { packageId })`, or `unregisterPackage(PKG)`. +- FROM a rollback or a `DatabaseLoader.delete` by name of a two-holder name TO the same call naming the package, or removing the extra row first. +- FROM `getHistory('tool', NAME)` / `diff('tool', NAME, …)` of a name two packages saved TO the same call with `{ packageId }`, once per package. + +The bare-name one-holder rule (`bare-name-one-holder.ts`) has narrowed for `tool` from one package holder per deployment to one per namespace (ADR-0150 D2, D9), as it did for `agent`, `skill`, the object-less `action`, `email_template`, `flow`, the picklist family and `webhook`. The switch, `NAMESPACE_SCOPED_BARE_NAME_TYPES`, lives in `@objectstack/core` (`package-scoped-resolution.ts`) and `@objectstack/objectql` re-exports it under the same name. A package's `tool` record has one by-name reader, `GET /meta/tool/NAME`, which already answers by `(package, name)`: it refuses `409 RESOURCE_CONFLICT` naming every served holder when two packages hold the name, and `?package=ID` and `/meta/tool/NAMESPACE/NAME` serve that package's own. A disabled package holds no name for that read (ADR-0150 D3): of two namespaces' holders, one disabled, the bare read serves the enabled one, and refuses naming both again once it is re-enabled. The install door still counts every installed holder, disabled or not. So a package no longer has to rename a tool because a package of another namespace already ships one of that name. + +The metadata service stores a tool per `(package, name)` (`PACKAGE_SLOTTED_STORE_TYPES`, now `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping`, `dataset`, `webhook` and `tool`), by the rules `package-slotted-store.ts` already applies to the others: + +- The in-memory store keeps both packages' tools of one name; `list('tool')`, `loadMany('tool')` and `loadManyKeyed('tool')` answer both, where they answered the survivor. `GET /meta/tool` listed both packages' tools before this change and still does. +- `DatabaseLoader.save` of a tool: FROM one `sys_metadata` row per name with `package_id` empty TO one row per `(package, name)` with `package_id` filled; versions are numbered per name across the packages' rows, and each history row records the package whose row it snapshots. A legacy tool row the loader wrote before this release binds on its package's next save, or through `migrateDatabaseLoaderRowPackages(driver)` (`@objectstack/metadata/migrations`), which now covers `tool` rows too and can be re-run any number of times; the semantic entry `tool-names-per-namespace` registers it in the upgrade guide (ADR-0087). +- Unchanged, and now pinned for a tool on an artifact boot (`os dev`, `os start`): `GET /meta/tool/NAME/layers?package=PKG`, for a name two packages hold, serves that package's own code and effective layer. The layered read already judged the code layer at the exact address on the base, and the pin stays green with `tool` taken back out of `PACKAGE_SLOTTED_STORE_TYPES`. +- A composition whose metadata engine reads a tool through `getItem` (its registry's `readsByPackage('tool')` answers `false`) now refuses a bare `/meta/tool/NAME` read `501 NOT_IMPLEMENTED`, as it refuses every narrowed type it cannot judge. `SchemaRegistry` answers `true` for `tool` (ADR-0150 child E8), so no in-repo composition moves. + +Also moved, by the same rules `package-slotted-store.ts` and the replica lane already apply to every type in `PACKAGE_SLOTTED_STORE_TYPES`: + +- Replica convergence on a cluster signal for a tool: a signal naming a package FROM the first row the store returned by name TO that package's row; an unstamped signal (a writer that predates `packageId`) of a name whose active rows are bound to two or more packages FROM the first row TO a logged stop that keeps the ledger entry for the next resync (#32451). +- The boot priming pass (`@objectstack/metadata` plugin): a package-less stored tool row FROM stamped with the host's package TO left unstamped (#32812's rule for every type stored per `(package, name)`), so it is filed as its one holder's customization or the environment's own item, and under a name two packages hold as no holder's own (ADR-0150 D4). +- The protocol's in-process layered read (`getMetaItemLayered`) with a bare tool name on an artifact boot (`os dev`, `os start`), where the metadata service keeps both packages' copies: FROM the holder registered last TO `409` naming both, with the metadata service's bare read. + +Not moved by this change, and carried (both already reach every narrowed type): + +- The boot hydration of stored rows: two stored tool rows of one name, each naming its holder, leave only the one loaded last in the registry (the second case #32692 names for a webhook; #33127 carries it for every type stored per `(package, name)`, `tool` included). A package-less stored tool row is no longer grafted onto any holder's slot: a tool is a sealed type (no environment overlay), so since #32741 that row is declined at each holder's exact address, plain and layered, before and after the read-side hydrator, in both registration orders, and each address serves its own (pinned for a tool by name, unit and booted). +- The protocol's in-process layered read (`getMetaItemLayered`, called with a bare name and no package) runs no two-holder judgement of its own: where the metadata service gives it no copy of the tool, it falls back to the registry's by-name artifact lookup and answers the first-registered holder (#32914). Both HTTP transports refuse that read `409` before serving it (above); an in-process caller, or a host with no door chain, is not refused. Not pinned here for a boot with no service copy. + +Unchanged, and still refused with the same `422 NAMESPACE_CONFLICT` envelope and sentence: + +- a second package of the SAME namespace (a co-owner) holding the name: for a tool that is the namespace co-owner rule's `NamespaceNameConflictError` (child N), which judges a tool ahead of this rule at every install, boot included, exactly as before; +- a package that declares no namespace, beside any other holder of the name (a disabled one included), and any holder beside it; +- two packages of one shareable namespace (`base`, `system`, `sys`) holding the name; +- a built-in name (none for a tool: the platform requests no tool record by name). + +Every covered type not yet narrowed (connector) keeps one package holder per deployment. + +`os migrate stored-references` no longer lists two namespaces' holders of one tool name among the sealed clashes: they are not a clash. + +Carried to the cloud: the first cloud change that reads package `tool` records (today none does: the cloud reading of 2026-11-12 on cloud `main@9b50c62e` finds the cloud's tool registry and a skill's `tools` resolving against the AI service's live registry of code-defined tools, never a `tool` record) must resolve a name from the referring item's own package (ADR-0150 D3), refuse a name two packages hold naming every candidate, and never take the first one registered; `packages/spec/liveness/tool.json` records that precondition. The cloud's three bare-name calls on the metadata service for type `tool` (cloud reading 6837767385) are carried with it: a bare removal of a name two packages hold is now refused `409`, so the built-in mirror's retract can be refused where two namespaces each ship a tool named after a built-in. That refusal fails closed and picks no holder. diff --git a/.changeset/31985-tool-names-semantic-entry.md b/.changeset/31985-tool-names-semantic-entry.md new file mode 100644 index 00000000000..cb8eff182fb --- /dev/null +++ b/.changeset/31985-tool-names-semantic-entry.md @@ -0,0 +1,10 @@ +--- +'@objectstack/spec': patch +--- + +docs(spec): the protocol upgrade guide names the tool's per-namespace names: an in-process read, removal or history of a tool name two packages hold, naming no package, is refused naming every holder, and a legacy loader row of a tool binds to its package (#31985) + +Clause-②: no +Metadata-protocol: none + +The semantic entry `tool-names-per-namespace` (`packages/spec/src/migrations/entries/semantic/18.tool-names-per-namespace.ts`) registers the narrowing `.changeset/31985-tool-names-per-namespace.md` declares (ADR-0087, `adr-0087: registered`), and the row binding it names (`migrateDatabaseLoaderRowPackages`, re-runnable): no automatic rewrite of a caller, because which holder a caller meant is a judgement about that caller. It adds no key and no export. diff --git a/packages/cli/src/commands/migrate/stored-references.integration.test.ts b/packages/cli/src/commands/migrate/stored-references.integration.test.ts index eadedf2976c..d852deba998 100644 --- a/packages/cli/src/commands/migrate/stored-references.integration.test.ts +++ b/packages/cli/src/commands/migrate/stored-references.integration.test.ts @@ -17,13 +17,14 @@ * - C (`m31693c`) declares the picklist `m31693_hue`, which A does not depend on. * * A and B also each declare the agent `m31693_helper`, the skill - * `m31693_triage`, the object-less action `m31693_digest` and the email - * template `m31693_notice`: two namespaces' holders of one agent, one skill, - * one object-less action and one email template name, which the one-holder - * rule no longer calls a clash (#31701, #31697, #31699; ADR-0150 D2/D9), so - * the sealed-clash section never lists them; nor the picklist `m31693_tone` - * they both declare (#31700). The clash the seal still records is the tool - * `m31693_lookup` both declare: a tool name is held once per deployment. + * `m31693_triage`, the object-less action `m31693_digest`, the email + * template `m31693_notice` and the tool `m31693_lookup`: two namespaces' + * holders of one agent, one skill, one object-less action, one email template + * and one tool name, which the one-holder rule no longer calls a clash + * (#31701, #31697, #31699, #31985; ADR-0150 D2/D9), so the sealed-clash + * section never lists them; nor the picklist `m31693_tone` they both declare + * (#31700). The clash the seal still records is the connector `m31693_link` + * both declare: a connector name is held once per deployment. * * Over a database an older release left: two managed `sys_sharing_rule` rows * naming `m31693_share` (two holders: ambiguous) and `m31693_only_a` (one @@ -94,11 +95,9 @@ const rule = (name: string) => ({ accessLevel: 'read', sharedWith: { type: 'user', value: 'u1' }, active: true, }); const list = (name: string) => ({ name, label: name, options: [{ label: 'One', value: 'one' }] }); -/** - * The agent, the skill (#31701), the object-less action (#31697) and the email - * template (#31699) A and B both declare, in their own namespaces; and the - * tool, whose name is still held once per deployment: the sealed clash. - */ +/** The connector A and B both declare: a connector name is still held once per deployment, the sealed clash. */ +const link = (tag: string) => ({ name: 'm31693_link', label: `${tag} link`, type: 'api', description: `${tag} link`, enabled: false }); +/** The agent, the skill (#31701), the object-less action (#31697), the email template (#31699) and the tool (#31985) A and B both declare, in their own namespaces. */ const ai = (tag: string) => ({ agents: [{ name: 'm31693_helper', label: `${tag} helper`, role: `${tag} role`, instructions: `${tag} helper instructions` }], skills: [{ name: 'm31693_triage', label: `${tag} triage`, description: `${tag} triage`, instructions: `${tag} triage instructions`, tools: [] }], @@ -118,6 +117,7 @@ const pkgA = { }], sharingRules: [rule('m31693_share'), rule('m31693_only_a')], picklists: [list('m31693_tone')], + connectors: [link('a')], ...ai('a'), }, }; @@ -126,6 +126,7 @@ const pkgB = { id: B, name: 'm31693b', version: '1.0.0', type: 'app', namespace: 'm31693b', dependencies: { [A]: '^1.0.0' }, sharingRules: [rule('m31693_share')], picklists: [list('m31693_tone')], + connectors: [link('b')], ...ai('b'), }, }; @@ -306,10 +307,10 @@ describe('os migrate stored-references (the report)', () => { d8: 'R17', object: 'm31693a_task', field: 'hue', packageId: A, name: 'm31693_hue', reason: 'outside-closure', candidates: [{ holder: 'package', packageId: C, address: 'm31693c/m31693_hue' }], }]); - // [#31701, #31697, #31699, #31700] Only the tool: never the agent, the - // skill, the object-less action, the email template and the picklist A - // and B hold in two namespaces. - expect(payload.sealedClashes).toEqual([{ type: 'tool', name: 'm31693_lookup', candidates: [`package "${A}"`, `package "${B}"`] }]); + // [#31701, #31697, #31699, #31700, #31985] Only the connector: never the + // agent, the skill, the object-less action, the email template, the + // picklist and the tool A and B hold in two namespaces. + expect(payload.sealedClashes).toEqual([{ type: 'connector', name: 'm31693_link', candidates: [`package "${A}"`, `package "${B}"`] }]); // The served platform carries no automation or approvals table here: named, not silently skipped. expect(payload.tablesNotCarried).toEqual(expect.arrayContaining(['sys_automation_run', 'sys_flow_credential', 'sys_approval_request'])); }, CASE_TIMEOUT_MS); diff --git a/packages/core/src/package-scoped-resolution.ts b/packages/core/src/package-scoped-resolution.ts index db1b0ef4ffe..2d1fc30899f 100644 --- a/packages/core/src/package-scoped-resolution.ts +++ b/packages/core/src/package-scoped-resolution.ts @@ -137,8 +137,9 @@ export function isBareNameOneHolderType(type: unknown): type is BareNameOneHolde * `(package, name)`, and its doors, flow actions and flow endpoints resolve a * name by package), then the picklist family (#31700): `picklist`, * `mapping` and `dataset`, the `api` and the engine's `function` registry, - * then `webhook` (#31699 PR 2). A type not listed here keeps one package - * holder per deployment. + * then `webhook` (#31699 PR 2), and `tool` beside the AI family (#31985), + * whose one by-name reader (`/meta/tool/NAME`) resolves by package. A type + * not listed here keeps one package holder per deployment. * * Every member but {@link ENGINE_FUNCTION_TYPE} is a metadata type ADR-0150 * addresses by package ({@link PACKAGE_SCOPED_TYPES}). The function registry @@ -155,6 +156,8 @@ export function isBareNameOneHolderType(type: unknown): type is BareNameOneHolde export const NAMESPACE_SCOPED_BARE_NAME_TYPES: readonly BareNameOneHolderType[] = Object.freeze([ 'agent', 'skill', + // the AI family's third type, in its own change (#31985) + 'tool', 'action', 'email_template', 'flow', diff --git a/packages/metadata/src/metadata-manager-keyed-plural-read.test.ts b/packages/metadata/src/metadata-manager-keyed-plural-read.test.ts index 2e155fee74e..4339e041301 100644 --- a/packages/metadata/src/metadata-manager-keyed-plural-read.test.ts +++ b/packages/metadata/src/metadata-manager-keyed-plural-read.test.ts @@ -401,8 +401,9 @@ describe('#14423 item 2 — `MetadataManager.loadManyKeyed`: the plural read und describe('[#32517] the unscoped plural reads answer every package\'s item of an unbundled by-package type', () => { const A = 'com.acme.alpha'; const B = 'com.acme.beta'; - // [#31699 PR 2] `webhook` joins the slotted set, and so these plural reads. - const UNBUNDLED = ['api', 'agent', 'skill', 'action', 'flow', 'permission', 'picklist', 'mapping', 'dataset', 'webhook']; + // [#31699 PR 2] `webhook` joins the slotted set, and so these plural reads; + // [#31985] `tool` joins with its narrowing. + const UNBUNDLED = ['api', 'agent', 'skill', 'action', 'flow', 'permission', 'picklist', 'mapping', 'dataset', 'webhook', 'tool']; const NAME = 'shared_item'; const item = (packageId: string | undefined, extra: Record = {}) => ({ name: NAME, diff --git a/packages/metadata/src/metadata-manager-match-endpoint.test.ts b/packages/metadata/src/metadata-manager-match-endpoint.test.ts index 4716bfe4958..b2b66f90885 100644 --- a/packages/metadata/src/metadata-manager-match-endpoint.test.ts +++ b/packages/metadata/src/metadata-manager-match-endpoint.test.ts @@ -465,9 +465,9 @@ describe('the in-memory api store keeps one slot per (package, name) (ADR-0150 D * `(package, name)` for every type whose one-holder rule has narrowed to the * namespace — `agent` and `skill` (objectql's * `NAMESPACE_SCOPED_BARE_NAME_TYPES`, #31701; objectql pins that set a subset - * of `PACKAGE_SLOTTED_STORE_TYPES`), `flow` (#31696), and [#31700] the - * picklist family's `picklist`, `mapping` and `dataset` (`api` has its own - * describe above, the object-less `action` its own file). Two packages of two namespaces may each + * of `PACKAGE_SLOTTED_STORE_TYPES`), `flow` (#31696), [#31700] the + * picklist family's `picklist`, `mapping` and `dataset`, and `tool` (#31985) + * (`api` has its own describe above, the object-less `action` its own file). Two packages of two namespaces may each * install such a name, and the artifact door registers every package body's * items here through `register(…, { notify: false })`, stamped by * `applyProtection` (`_packageId`). On main 45f0f81f the store was keyed by @@ -476,7 +476,7 @@ describe('the in-memory api store keeps one slot per (package, name) (ADR-0150 D * answered the survivor. */ describe('the in-memory store keeps one slot per (package, name) for every namespace-scoped type (ADR-0150 D4, #32151)', () => { - const NAMESPACE_SCOPED = ['agent', 'skill', 'flow', 'picklist', 'mapping', 'dataset'] as const; + const NAMESPACE_SCOPED = ['agent', 'skill', 'flow', 'picklist', 'mapping', 'dataset', 'tool'] as const; const A = 'com.acme.alpha'; const B = 'com.acme.beta'; const shipped = (type: string, packageId: string, tag: string, envelope = false) => ({ diff --git a/packages/metadata/src/package-slotted-store.ts b/packages/metadata/src/package-slotted-store.ts index 8c3ee1ca8b6..cd51c0d4993 100644 --- a/packages/metadata/src/package-slotted-store.ts +++ b/packages/metadata/src/package-slotted-store.ts @@ -66,10 +66,11 @@ * * `api` (#32069), and every type whose one-holder rule has narrowed to the * namespace — objectql's `NAMESPACE_SCOPED_BARE_NAME_TYPES`, today `agent`, - * `skill` (#31701), `action` (#31697, below), `email_template` (#31699) and - * `flow` (#31696) and the picklist family's `picklist`, `mapping` and - * `dataset` (#31700). Two packages of two namespaces may each install such - * a name, so a store keyed by bare name would keep whichever registered last: + * `skill` (#31701), `tool` (#31985), `action` (#31697, below), + * `email_template` (#31699) and `flow` (#31696) and the picklist family's + * `picklist`, `mapping` and `dataset` (#31700). Two packages of two + * namespaces may each install such a name, so a store keyed by bare name + * would keep whichever registered last: * the artifact door registers every package body's items here, and a read * naming the other package (`get(type, name, packageId)`, the `/meta` code * layer) was served the survivor. ⛔ A type joins the narrowed set only in the @@ -136,11 +137,12 @@ import { peelStoredEnvelope } from './stored-envelope.js'; * (#31696), which joins in the same change that adds it to that set; then the * picklist family's `picklist`, `mapping` and `dataset` (#31700); then * `webhook` (#31699 PR 2), so a host with no registry lists each package's - * declaration of one name. + * declaration of one name; then `tool` (#31985, ADR-0150 child B), likewise + * in the change that narrows it. */ export const PACKAGE_SLOTTED_STORE_TYPES: ReadonlySet = new Set([ 'api', 'agent', 'skill', 'action', 'email_template', 'permission', 'flow', 'picklist', 'mapping', 'dataset', - 'webhook', + 'webhook', 'tool', ]); /** The provenance sentinel a rehydrated row carries in place of a package. */ diff --git a/packages/objectql/src/bare-name-one-holder.ts b/packages/objectql/src/bare-name-one-holder.ts index b660672a4bb..4dbbc0387ae 100644 --- a/packages/objectql/src/bare-name-one-holder.ts +++ b/packages/objectql/src/bare-name-one-holder.ts @@ -73,7 +73,7 @@ * and every reference to a tool carries its bare name alone: a skill's * `tools` list admits only a snake_case name, an AI tool definition and a * tool call carry a name and no package, and an MCP server registers one - * tool per name. + * tool per name (since narrowed to the namespace: "The narrowing"). * * Every one of them flips with registration order, and none says so (the * object-less action's handler bind warns that it replaces one, and names @@ -197,6 +197,16 @@ * refuse a name two packages hold, naming both; the door's * `webhook/NS/NAME` reaches each. * + * `tool` followed (#31985): `/meta/tool/NAME` reads through + * `readPackageScopedItem` (child E8), and a package's `tool` record has no + * other reader and no AI face to carry. Every tool an MCP client or a model is + * shown comes from the AI service's live tool registry (platform tools and + * action-backed tools), never from a `tool` record, and a skill's `tools` + * names resolve against that registry. Once tool records become live, the + * resolver of a skill's `tools` resolves from the skill's package (ADR-0150 + * D3) and refuses two holders, naming them (`packages/spec/liveness/tool.json` + * records that precondition). + * * Two holdings still meet under a narrowed type, whatever the namespaces: * * - a name the platform requests by its bare spelling @@ -327,7 +337,10 @@ const COLLECTION_KEY: Readonly> = Object.fr * `409`. The census found no other fixed-name action request in the * platform's own code (`packages/**` and `ui/**` sources). * - every other covered type: none — the platform ships no item of it under - * a name a package could take. + * a name a package could take. For `tool` (#31985) the platform requests no + * tool record by name (ADR-0150 D3's exception list holds none): the tools + * the AI service registers by name (`PLATFORM_PROVIDED_TOOL_NAMES`) live in + * its own tool registry, not in this registry, so none is a built-in here. */ export const BUILT_IN_BARE_NAMES: Readonly>> = Object.freeze({ picklist: new Set(), diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index eef55c9684c..a2beb50701c 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -468,9 +468,11 @@ describe('a covered type the registry reads through `getItem` (seat rulings (a), expect(thrown?.message).toContain(`has no package-scoped resolver for '${type}' items`); }); - it('CONTROL: a covered type not narrowed (tool) keeps `getItem` on the same view', async () => { - shipValid('tool', 'solo', A); - expect(labelOf(await readsNothingByPackage.getMetaItem({ type: 'tool', name: 'solo' }))).toBe('alpha tool'); + // [#31985] `tool` has narrowed, so the CONTROL is a package-scoped type no + // one-holder rule covers: no child B card ever narrows it. + it('CONTROL: a package-scoped type not narrowed (dashboard) keeps `getItem` on the same view', async () => { + shipValid('dashboard', 'solo', A); + expect(labelOf(await readsNothingByPackage.getMetaItem({ type: 'dashboard', name: 'solo' }))).toBe('alpha dashboard'); }); it('CONTROL: the registry WITH the resolver reads the narrowed AI types by package and serves them', async () => { @@ -1939,7 +1941,12 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for } }; - for (const type of ['action', 'queue']) { + // [#31985, epic ruling 3 on 6840825374] `tool` is sealed too (its registry + // entry has `allowEnvironmentOverlay: false`), and its narrowing makes two + // namespaces' holders of one name reachable, so the sealed-type rule is + // pinned for it by name: each holder's exact address serves its own, in + // every hydration state and both registration orders. + for (const type of ['action', 'queue', 'tool']) { for (const order of [[A, B], [B, A]]) { for (const state of STATES) { it(`${type}, two holders (${order.map((p) => p.split('.').pop()).join(' then ')}), ${state}: each exact address serves its own; the layered read reports no overlay (BASE: in the describe header)`, async () => { @@ -1974,7 +1981,7 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for // read's code step judged as the plain read judges it: the copy is // declined there too, never the holder's `code` (one holder) nor a 409 // naming both (two). - for (const type of ['action', 'queue']) { + for (const type of ['action', 'queue', 'tool']) { for (const holders of [[A], [A, B]]) { it(`${type}, ${holders.length} holder(s): a service copy of the package-less row is declined on the plain read and the layered read's code layer alike`, async () => { for (const p of holders) shipSealed(type, p); @@ -2030,7 +2037,7 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for // environment's row as its own until the next unscoped hydration (the // re-enable heal, a follow-up under #32568). const BOTH = [{ kind: 'package', packageId: A }, { kind: 'package', packageId: B }]; - for (const type of ['email_template', 'action', 'queue']) { + for (const type of ['email_template', 'action', 'queue', 'tool']) { it(`${type}, two holders, one disabled while the read-side hydrator runs, then re-enabled: one answer per state on the exact read`, async () => { const overlay = type === 'email_template'; if (overlay) { diff --git a/packages/objectql/src/registry-bare-name-one-holder-ai-family.test.ts b/packages/objectql/src/registry-bare-name-one-holder-ai-family.test.ts index 387f5c25834..9964cb074b9 100644 --- a/packages/objectql/src/registry-bare-name-one-holder-ai-family.test.ts +++ b/packages/objectql/src/registry-bare-name-one-holder-ai-family.test.ts @@ -18,14 +18,18 @@ * and another's of another under one name never meet (CONTROL); * - two packages' tools under different names both install (CONTROL). * - * [ADR-0150 D2/D9, child B, #31701] `agent` and `skill` have narrowed to the - * namespace (`NAMESPACE_SCOPED_BARE_NAME_TYPES`): the matrix below refuses - * their second holder as a CO-OWNER of the first holder's namespace (a - * package of namespace `alpha` that depends on `com.acme.alpha`), and a - * `tool`'s as a package of another namespace, as before. "the narrowing" pins - * what changed: two namespaces' packages each hold the name, at every door and - * through the cold boot, while a co-owner, a package with no namespace and a - * built-in name are still refused. + * [ADR-0150 D2/D9, child B, #31701 and #31985] `agent`, `skill` and `tool` + * have narrowed to the namespace (`NAMESPACE_SCOPED_BARE_NAME_TYPES`): the + * matrix below refuses an agent's or a skill's second holder as a CO-OWNER of + * the first holder's namespace (a package of namespace `alpha` that depends on + * `com.acme.alpha`), and a tool's as a package that declares NO namespace. A + * tool is also one of the namespace co-owner rule's types (child N, + * `namespace-co-owner-names.ts`), which refuses a co-owner's tool first, at + * every install, boot included, with its own envelope — as before this change. + * "the narrowing" pins what changed: two namespaces' packages each hold the + * name, at every door and through the cold boot, while a co-owner, a package + * with no namespace, two packages of one shareable namespace and a built-in + * name are still refused. * * Every refusal is asserted by its ADR-0112 envelope (`code` + `status`), the * two holders it names and the rename it carries. @@ -111,13 +115,21 @@ const pkg = (id: string, decl: Partial> = {}, extra: Re const narrowed = (type: AiType) => (NAMESPACE_SCOPED_BARE_NAME_TYPES as readonly string[]).includes(type); /** - * The package that rivals `com.acme.alpha` for a name of `type`: for a type - * narrowed to the namespace, a co-owner of alpha's namespace (it declares - * `alpha` and depends on alpha, as the namespace gate requires, and its object - * carries the namespace's prefix); otherwise a package of its own namespace. + * The package that rivals `com.acme.alpha` for a name of `type`: for an agent + * or a skill, narrowed to the namespace, a co-owner of alpha's namespace (it + * declares `alpha` and depends on alpha, as the namespace gate requires, and + * its object carries the namespace's prefix); for a tool, narrowed too, a + * package that declares no namespace — the namespace co-owner rule (child N) + * refuses a tool's co-owner ahead of this rule, pinned in "the narrowing"; + * otherwise a package of its own namespace. */ const rival = (type: AiType, id: string, decl: Partial> = {}, extra: Record = {}) => { if (!narrowed(type)) return pkg(id, decl, extra); + if (type === 'tool') { + const plain = pkg(id, decl, extra); + delete plain.namespace; + return plain; + } const tag = id.split('.').pop()!; return pkg(id, decl, { namespace: 'alpha', @@ -127,8 +139,11 @@ const rival = (type: AiType, id: string, decl: Partial> }); }; -/** The rename a refusal of `id`'s `name` carries: its namespace prefixed. */ -const renameOf = (type: AiType, id: string, name: string) => `${narrowed(type) ? 'alpha' : id.split('.').pop()}_${name}`; +/** The rename a refusal of `id`'s `name` carries: its namespace prefixed (none for a package with no namespace). */ +const renameOf = (type: AiType, id: string, name: string): string | undefined => { + if (!narrowed(type)) return `${id.split('.').pop()}_${name}`; + return type === 'tool' ? undefined : `alpha_${name}`; +}; const caught = async (fn: () => unknown): Promise => { try { @@ -295,7 +310,8 @@ describe.each(TYPES)('%s — after the cold boot, a second package declaring a n expect(warnings[0]).toContain(`the ${bareNameTypeLabel(type)} "${name}"`); expect(warnings[0]).toContain('com.acme.alpha'); expect(warnings[0]).toContain('com.acme.beta'); - expect(warnings[0]).toContain(renameOf(type, 'com.acme.beta', name)); + const rename = renameOf(type, 'com.acme.beta', name); + if (rename) expect(warnings[0]).toContain(rename); expect(warnings[0]).toContain('changes nothing about which holder each caller is served'); }); @@ -322,10 +338,10 @@ describe.each(TYPES)('%s — after the cold boot, a second package declaring a n }); }); -describe('the narrowing — agent and skill hold one name per namespace (ADR-0150 D2/D9, child B)', () => { - const NARROWED = ['agent', 'skill'] as const; +describe('the narrowing — agent, skill and tool hold one name per namespace (ADR-0150 D2/D9, child B)', () => { + const NARROWED = ['agent', 'skill', 'tool'] as const; - it('the switch holds agent and skill, the later families\' narrowed types, and no other covered type', () => { + it('the switch holds agent, skill and tool, the later families\' narrowed types, and no other covered type', () => { // Later child B cards append their own type, each pinned in its family's file. const SWITCHED: readonly string[] = [...NARROWED, 'action', 'email_template', 'flow', 'picklist', 'mapping', 'dataset', 'api', 'function', 'webhook']; expect(NAMESPACE_SCOPED_BARE_NAME_TYPES).toEqual(SWITCHED); @@ -359,14 +375,18 @@ describe('the narrowing — agent and skill hold one name per namespace (ADR-015 expect(await caught(() => registry.registerItem(type, body(type, name, 'beta'), 'name', 'com.acme.beta'))).toBeUndefined(); }); - it('a co-owner of the holder\'s namespace is still refused beside two namespaces\' holders, naming only its own namespace\'s holder', async () => { - const { register } = await boot(); - expect(await register(pkg('com.acme.alpha', { [type]: [name] }))).toBeUndefined(); - expect(await register(pkg('com.acme.beta', { [type]: [name] }))).toBeUndefined(); - const err = await register(rival(type, 'com.acme.gamma', { [type]: [name] })); - expectRefusal(err, 'com.acme.gamma', { kind: 'package', packageId: 'com.acme.alpha' }, `alpha_${name}`); - expect(err!.conflicts!.map((c) => c.existingHolder)).toEqual([{ kind: 'package', packageId: 'com.acme.alpha' }]); - }); + // A tool's co-owner is the namespace co-owner rule's to refuse, first + // ("a tool's co-owner" below); this rule's co-owner reading is an agent's and a skill's. + if (type !== 'tool') { + it('a co-owner of the holder\'s namespace is still refused beside two namespaces\' holders, naming only its own namespace\'s holder', async () => { + const { register } = await boot(); + expect(await register(pkg('com.acme.alpha', { [type]: [name] }))).toBeUndefined(); + expect(await register(pkg('com.acme.beta', { [type]: [name] }))).toBeUndefined(); + const err = await register(rival(type, 'com.acme.gamma', { [type]: [name] })); + expectRefusal(err, 'com.acme.gamma', { kind: 'package', packageId: 'com.acme.alpha' }, `alpha_${name}`); + expect(err!.conflicts!.map((c) => c.existingHolder)).toEqual([{ kind: 'package', packageId: 'com.acme.alpha' }]); + }); + } it('a package with no namespace is still refused beside a holder, and a holder with no namespace still refuses one', async () => { const { register } = await boot(); @@ -396,18 +416,22 @@ describe('the narrowing — agent and skill hold one name per namespace (ADR-015 expect(registry.sealBareNameHolders().filter((c) => c.type === type)).toEqual([]); }); - it('the cold boot of two namespaces\' holders and a co-owner reports the co-owner against its own namespace\'s holder only', async () => { - const registry = new SchemaRegistry(); - registry.logLevel = 'silent'; - for (const m of [ - pkg('com.acme.alpha', { [type]: [name] }), - pkg('com.acme.beta', { [type]: [name] }), - rival(type, 'com.acme.gamma', { [type]: [name] }), - ]) registry.installPackage(m as never, 'code'); - expect(registry.sealBareNameHolders()).toEqual([ - { type, name, incomingPackageId: 'com.acme.gamma', existingHolder: { kind: 'package', packageId: 'com.acme.alpha' }, rename: `alpha_${name}` }, - ]); - }); + // A tool's co-owner is the namespace co-owner rule's to refuse, first + // ("a tool's co-owner" below); this rule's co-owner reading is an agent's and a skill's. + if (type !== 'tool') { + it('the cold boot of two namespaces\' holders and a co-owner reports the co-owner against its own namespace\'s holder only', async () => { + const registry = new SchemaRegistry(); + registry.logLevel = 'silent'; + for (const m of [ + pkg('com.acme.alpha', { [type]: [name] }), + pkg('com.acme.beta', { [type]: [name] }), + rival(type, 'com.acme.gamma', { [type]: [name] }), + ]) registry.installPackage(m as never, 'code'); + expect(registry.sealBareNameHolders()).toEqual([ + { type, name, incomingPackageId: 'com.acme.gamma', existingHolder: { kind: 'package', packageId: 'com.acme.alpha' }, rename: `alpha_${name}` }, + ]); + }); + } it('a built-in name is still refused to a package of any namespace', async () => { const builtIns = BUILT_IN_BARE_NAMES[type] as Set; @@ -421,10 +445,89 @@ describe('the narrowing — agent and skill hold one name per namespace (ADR-015 }); }); - it('CONTROL — a tool has not narrowed: a package of another namespace is still refused its name', async () => { - const { register } = await boot(); + describe('[#31985] a tool\'s co-owner — refused by the namespace co-owner rule (child N), ahead of this one, as before', () => { + const coOwner = (id: string) => { + const tag = id.split('.').pop()!; + return pkg(id, { tool: ['shared_tool'] }, { + namespace: 'alpha', + objects: [itemObject(`alpha_${tag}`)], + dependencies: { 'com.acme.alpha': '^1.0.0' }, + }); + }; + const expectCoOwnerRefusal = (err: Refusal | undefined, incoming: string) => { + const refusal = err as (Refusal & { existingPackageIds?: string[]; namespace?: string }) | undefined; + expect(refusal, 'the registration was refused').toBeDefined(); + expect(refusal!.name).toBe('NamespaceNameConflictError'); + expect([refusal!.code, refusal!.status]).toEqual([NAMESPACE_CONFLICT_CODE, 422]); + expect(refusal!.incomingPackageId).toBe(incoming); + expect(refusal!.namespace).toBe('alpha'); + expect(refusal!.existingPackageIds).toEqual(['com.acme.alpha']); + }; + + it('beside two namespaces\' holders, at the package door, naming only its own namespace\'s holder', async () => { + const { registry, register } = await boot(); + expect(await register(pkg('com.acme.alpha', { tool: ['shared_tool'] }))).toBeUndefined(); + expect(await register(pkg('com.acme.beta', { tool: ['shared_tool'] }))).toBeUndefined(); + expectCoOwnerRefusal(await register(coOwner('com.acme.gamma')), 'com.acme.gamma'); + expect(registry.getPackage('com.acme.gamma')).toBeUndefined(); + }); + + it('during the cold boot too: the co-owner is refused at its registration, and the seal then reports no tool clash', async () => { + const registry = new SchemaRegistry(); + registry.logLevel = 'silent'; + registry.installPackage(pkg('com.acme.alpha', { tool: ['shared_tool'] }) as never, 'code'); + registry.installPackage(pkg('com.acme.beta', { tool: ['shared_tool'] }) as never, 'code'); + expectCoOwnerRefusal(await caught(() => registry.installPackage(coOwner('com.acme.gamma') as never, 'code')), 'com.acme.gamma'); + expect(registry.sealBareNameHolders().filter((c) => c.type === 'tool')).toEqual([]); + }); + }); + + it('[#31985] a tool of a package of another namespace installs beside the holder\'s and each package serves its own; the bare read refuses naming both', async () => { + const { registry, register } = await boot(); expect(await register(pkg('com.acme.alpha', { tool: ['shared_tool'] }))).toBeUndefined(); - expectRefusal(await register(pkg('com.acme.beta', { tool: ['shared_tool'] })), 'com.acme.beta', { kind: 'package', packageId: 'com.acme.alpha' }, 'beta_shared_tool'); + expect(await register(pkg('com.acme.beta', { tool: ['shared_tool'] }))).toBeUndefined(); + expect(marker(registry.resolveItem('tool', 'shared_tool', 'com.acme.alpha'))).toBe('alpha tool'); + expect(marker(registry.resolveItem('tool', 'shared_tool', 'com.acme.beta'))).toBe('beta tool'); + const refused = await caught(() => registry.resolveItem('tool', 'shared_tool')); + expect([refused?.code, refused?.status]).toEqual(['RESOURCE_CONFLICT', 409]); + expect(refused!.message).toContain('com.acme.alpha'); + expect(refused!.message).toContain('com.acme.beta'); + }); + + // [#31985, ADR-0150 D3 as #32183 reads it] Once two namespaces may each + // hold a tool name, the two holder reads part: a by-name read judges the + // SERVED holders (a disabled package holds no name), the install door every + // holder it has installed (a disable is reversible, so it never admits what + // the re-enable would refuse). + it.each([['enabled holder first', ['com.acme.alpha', 'com.acme.beta']], ['disabled holder first', ['com.acme.beta', 'com.acme.alpha']]] as const)('[#31985] one of two namespaces\' tool holders disabled (%s): the bare read serves the enabled one; re-enabled, refused naming both; the door still counts the disabled one', async (_order, order) => { + const { registry, register } = await boot(); + for (const id of order) expect(await register(pkg(id, { tool: ['shared_tool'] }))).toBeUndefined(); + registry.disablePackage('com.acme.beta'); + expect(registry.packageScopedHoldersOf('tool', 'shared_tool')).toEqual(['com.acme.alpha']); + expect([...registry.packageScopedHoldersOf('tool', 'shared_tool', null, { includeDisabledPackages: true })].sort()) + .toEqual(['com.acme.alpha', 'com.acme.beta']); + expect(marker(registry.resolveItem('tool', 'shared_tool'))).toBe('alpha tool'); + expect(marker(registry.resolveItem('tool', 'shared_tool', 'com.acme.alpha'))).toBe('alpha tool'); + + // The door: a package with no namespace is refused beside the disabled + // holder too, naming it — every installed holder counts there. + const bare = pkg('com.acme.plain', { tool: ['shared_tool'] }); + delete bare.namespace; + const err = await register(bare); + expect([err?.code, err?.status]).toEqual([NAMESPACE_CONFLICT_CODE, 422]); + expect(err!.conflicts!.map((c) => c.existingHolder)).toEqual( + expect.arrayContaining([{ kind: 'package', packageId: 'com.acme.alpha' }, { kind: 'package', packageId: 'com.acme.beta' }]), + ); + // …and a third namespace's tool installs beside both. + expect(await register(pkg('com.acme.gamma', { tool: ['shared_tool'] }))).toBeUndefined(); + registry.disablePackage('com.acme.gamma'); + + registry.enablePackage('com.acme.beta'); + const refused = await caught(() => registry.resolveItem('tool', 'shared_tool')); + expect([refused?.code, refused?.status]).toEqual(['RESOURCE_CONFLICT', 409]); + expect(refused!.message).toContain('com.acme.alpha'); + expect(refused!.message).toContain('com.acme.beta'); + expect(refused!.message).not.toContain('com.acme.gamma'); }); }); diff --git a/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts b/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts index 54b38d2f280..58e429d92ca 100644 --- a/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts +++ b/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts @@ -10,7 +10,7 @@ // // [#31701, ADR-0150 D2/D9, child B] An agent and a skill have since narrowed // to the namespace: two packages of two namespaces may each hold the name. -// A tool has not. +// [#31985] A tool has followed them. // // The registry's own pins (`registry-bare-name-one-holder-ai-family.test.ts`) // drive the engine's package door and the item seam in-process. This file @@ -18,9 +18,8 @@ // // - the cold boot of a deployment where two `AppPlugin` packages of two // namespaces, `alpha` and `beta`, ship one agent, one skill and one tool -// under the same names boots, and logs ONE bare-name warning line naming -// the tool alone: the agent and the skill are no clash between two -// namespaces; +// under the same names boots, and logs NO bare-name warning: none of the +// three is a clash between two namespaces; // - [#31680, ADR-0150 D3] the by-name read that names no package — // `/meta/agent/NAME`, `/meta/skill/NAME`, `/meta/tool/NAME` — refuses // `409 RESOURCE_CONFLICT` naming both holders; the read that names the @@ -30,18 +29,24 @@ // serves its own package's skill (`agent_prompt` is the stdio transport's // alone: its faces are pinned beside it, in `packages/mcp`); // - `POST /marketplace/install-local` of a package of a THIRD namespace -// declaring the held agent and skill names installs; of a co-owner of -// `alpha`'s namespace declaring either is 422 PLUGIN_REGISTER_FAILED -// naming the holder and the rename, as before; of a package declaring the -// held tool name is the same 422 naming both holders; none installs; +// declaring the held agent, skill and tool names installs; of a co-owner +// of `alpha`'s namespace declaring any of them is 422 +// PLUGIN_REGISTER_FAILED naming the holder, as before (the agent's and the +// skill's with the rename; the tool's with the namespace co-owner rule's +// sentence, which refuses it first), and does not install; // - CONTROL: a package declaring fresh agent, skill and tool names installs, // and every AI door serves it as before; // - [#32151, ADR-0150 D3/D4] on the ARTIFACT door (a second boot of its own, // the door `os dev` and `os start` load a compiled artifact through, which // registers every package body's items into the metadata service), the -// metadata service keeps each package's agent and skill, and the layered -// read `/meta/TYPE/NAME/layers?package=` serves each package's own code -// layer (it served the package registered last for both). +// metadata service keeps each package's agent, skill and tool ([#31985]), +// and the layered read `/meta/TYPE/NAME/layers?package=` serves each +// package's own code layer (it served the package registered last for the +// agent and the skill; a tool's was already its own, and stays pinned); +// - [#31985, #32741] a package-less tool row saved before two namespaces' +// packages install the name is declined at each holder's exact address +// (a tool is sealed: no environment overlay), both install orders, +// before and after the read-side hydrator. import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; @@ -123,7 +128,7 @@ function levelOf(line: string): string | undefined { const codeOf = (body: any) => (body?.error && typeof body.error === 'object' ? body.error.code : undefined) ?? body?.code ?? null; -describe('agent and skill names held per namespace, a tool name per deployment, on a booted showcase', () => { +describe('agent, skill and tool names held per namespace, on a booted showcase', () => { let stack: VerifyStack; let admin: string; let storageDir: string; @@ -230,19 +235,12 @@ describe('agent and skill names held per namespace, a tool name per deployment, if (storageDir) rmSync(storageDir, { recursive: true, force: true }); }); - it('two namespaces\' packages holding one agent, skill and tool name both boot; the cold boot warns once, naming the tool alone', async () => { + it('two namespaces\' packages holding one agent, skill and tool name both boot, with no bare-name warning', async () => { expect(await packageIds(), 'both packages booted').toEqual(expect.arrayContaining(['com.qa.bare.alpha', 'com.qa.bare.beta'])); - const warnings = bootLines.filter((l) => l.includes('Bare-name conflict at boot')); - expect(warnings, 'one warning line').toHaveLength(1); - const line = warnings[0]!; - expect(levelOf(line)).toBe('WARN'); - expect(line).toContain(`the tool "${TOOL}"`); - expect(line).toContain(`"beta_${TOOL}"`); - expect(line).toContain('package "com.qa.bare.alpha"'); - expect(line).toContain('package "com.qa.bare.beta"'); - // [#31701] Two namespaces' agents and skills are no clash. - expect(line).not.toContain(`the agent "${AGENT}"`); - expect(line).not.toContain(`the skill "${SKILL}"`); + // [#31701, #31985] Two namespaces' agents, skills and tools are no clash. + // The capture itself is live: it saw the boot's own output. + expect(bootLines.some((l) => levelOf(l) !== undefined), 'the capture saw the kernel logger').toBe(true); + expect(bootLines.filter((l) => l.includes('Bare-name conflict at boot'))).toEqual([]); }); it('the bare by-name read refuses 409 naming both holders; `?package=` serves each package\'s own', async () => { @@ -259,7 +257,7 @@ describe('agent and skill names held per namespace, a tool name per deployment, // namespace's address serves its own agent and skill; `_env` serves only an // environment item, so for a name only packages hold it is refused naming // them; the bare read stays the 409 naming both. - it('the qualified read `/meta/TYPE/:ns/NAME` serves each namespace\'s own agent and skill, `_env` none, on both transports', async () => { + it('the qualified read `/meta/TYPE/:ns/NAME` serves each namespace\'s own agent, skill and tool, `_env` none, on both transports', async () => { const dispatcher = new HttpDispatcher(stack.kernel as never); const viaDispatcher = async (path: string) => { const answered = await dispatcher.handleMetadata(path, { @@ -276,7 +274,7 @@ describe('agent and skill names held per namespace, a tool name per deployment, const itemOf = (body: any) => { const d = body?.data ?? body; return d?.item ?? d; }; const messageOf = (body: any) => String(typeof body?.error === 'string' ? body.error : body?.error?.message ?? body?.message ?? ''); for (const [transport, read] of [['rest', viaRest], ['dispatcher', viaDispatcher]] as const) { - for (const [type, name] of [['agent', AGENT], ['skill', SKILL]] as const) { + for (const [type, name] of [['agent', AGENT], ['skill', SKILL], ['tool', TOOL]] as const) { for (const ns of ['alpha', 'beta'] as const) { const answer = await read(`/${type}/${ns}/${name}`); expect([transport, type, ns, answer.status], JSON.stringify(answer.body)).toEqual([transport, type, ns, 200]); @@ -321,17 +319,18 @@ describe('agent and skill names held per namespace, a tool name per deployment, expect(await metaAt('agent', AGENT, 'com.qa.bare.alpha')).toEqual(['com.qa.bare.alpha', 'alpha agent']); }); - it('install-local of a package declaring the held tool name is 422 PLUGIN_REGISTER_FAILED naming both holders and the rename; nothing is installed', async () => { + // [#31985] A tool is also the namespace co-owner rule's type (child N), which + // refuses a co-owner's tool ahead of the bare-name rule, with its own sentence. + it('install-local of a co-owner of `alpha`\'s namespace declaring the held tool name is 422 PLUGIN_REGISTER_FAILED naming the namespace\'s holder, as before; nothing is installed', async () => { const before = await packageIds(); - const { status, body } = await installLocal(inline('zeta', { tools: [tool('zeta')] })); + const { status, body } = await installLocal(inline('alphatool', { tools: [tool('alphatool')] }, 'alpha')); expect([status, codeOf(body)], JSON.stringify(body)).toEqual([422, 'PLUGIN_REGISTER_FAILED']); const message = String(body?.error?.message ?? ''); - expect(message).toContain(`the tool "${TOOL}"`); - expect(message).toContain('com.qa.bare.alpha'); - expect(message).toContain('com.qa.bare.beta'); - expect(message).toContain(`"zeta_${TOOL}"`); + expect(message).toContain('Namespace name conflict'); + expect(message).toContain(`the tool "${TOOL}" in namespace "alpha", already held there by package "com.qa.bare.alpha"`); + expect(message).not.toContain('com.qa.bare.beta'); expect(await packageIds(), 'the package list is unchanged').toEqual(before); - await expectMetaRefused('tool', TOOL); + expect(await metaAt('tool', TOOL, 'com.qa.bare.alpha')).toEqual(['com.qa.bare.alpha', 'alpha tool']); }); it('CONTROL — install-local of a package declaring fresh agent, skill and tool names installs, and every AI door serves it', async () => { @@ -349,27 +348,72 @@ describe('agent and skill names held per namespace, a tool name per deployment, expect(await promptText('epsilon_skill'), 'one holder: the bare name still answers').toContain('epsilon skill instructions'); }); - it('[#31701] install-local of a package of a THIRD namespace declaring the held agent and skill names installs; the bare read then names all three holders', async () => { - const { status, body } = await installLocal(inline('gamma', { agents: [agent('gamma')], skills: [skill('gamma')] })); + it('[#31701, #31985] install-local of a package of a THIRD namespace declaring the held agent, skill and tool names installs; the bare read then names all three holders', async () => { + const { status, body } = await installLocal(inline('gamma', { agents: [agent('gamma')], skills: [skill('gamma')], tools: [tool('gamma')] })); expect(status, JSON.stringify(body)).toBeLessThan(300); expect(await packageIds()).toContain('com.qa.bare.gamma'); expect(await metaAt('agent', AGENT, 'com.qa.bare.gamma')).toEqual(['com.qa.bare.gamma', 'gamma agent']); expect(await metaAt('skill', SKILL, 'com.qa.bare.gamma')).toEqual(['com.qa.bare.gamma', 'gamma skill']); + expect(await metaAt('tool', TOOL, 'com.qa.bare.gamma')).toEqual(['com.qa.bare.gamma', 'gamma tool']); const all = ['com.qa.bare.alpha', 'com.qa.bare.beta', 'com.qa.bare.gamma']; await expectMetaRefused('agent', AGENT, all); await expectMetaRefused('skill', SKILL, all); + await expectMetaRefused('tool', TOOL, all); + expect(await metaAt('tool', TOOL, 'com.qa.bare.alpha')).toEqual(['com.qa.bare.alpha', 'alpha tool']); // The first packages' items are unchanged. expect(await metaAt('agent', AGENT, 'com.qa.bare.alpha')).toEqual(['com.qa.bare.alpha', 'alpha agent']); expect(await promptText(`alpha-${SKILL}`)).toContain('alpha skill instructions'); expect(await promptText(`gamma-${SKILL}`)).toContain('gamma skill instructions'); }); + + /** + * [#31985, epic ruling 3 on 6840825374; #32741's sealed-type rule, epic + * ruling 6817768147] A `tool` is a sealed managed type (no environment + * overlay), so a package-less row saved under a name two namespaces' packages + * then install is declined at each holder's exact address: each serves its + * own item, plain and layered (`overlay: null`), before and after the + * read-side hydrator, and the bare read refuses naming both. Both install + * orders: `kappa` then `lambda` for one name, `lambda` then `iota` for the + * other. FROM (this branch before `main`'s #32741 was merged in): the + * first-installed holder's exact address served the package-less row as its + * own; the second served its own. + */ + it('[#31985] a package-less tool row saved before two namespaces\' packages install the name is declined at each holder\'s exact address, both install orders, before and after the hydrator; the bare read refuses naming both', async () => { + const UP = 'qa_row_tool_up'; + const DOWN = 'qa_row_tool_down'; + for (const name of [UP, DOWN]) { + const saved = await stack.apiAs(admin, 'PUT', `/meta/tool/${name}`, tool('env', name)); + expect(saved.status, await saved.text()).toBeLessThan(300); + } + for (const [p, tools] of [['kappa', [UP]], ['lambda', [UP, DOWN]], ['iota', [DOWN]]] as const) { + const { status, body } = await installLocal(inline(p, { tools: tools.map((n) => tool(p, n)) })); + expect(status, `${p}: ${JSON.stringify(body)}`).toBeLessThan(300); + } + const layeredAt = async (name: string, pkg: string) => { + const r = await stack.apiAs(admin, 'GET', `/meta/tool/${name}/layers?package=${pkg}`); + const body = (await r.json()) as any; + return [r.status, body?.overlay ?? null, body?.effective?.label]; + }; + for (const when of ['before the hydrator', 'after the hydrator']) { + if (when === 'after the hydrator') expect((await stack.apiAs(admin, 'GET', '/meta/tool')).status).toBe(200); + for (const [name, holders] of [[UP, ['kappa', 'lambda']], [DOWN, ['lambda', 'iota']]] as const) { + for (const p of holders) { + const pkg = `com.qa.bare.${p}`; + expect(await metaAt('tool', name, pkg), `${when}: ${name} at ${p}`).toEqual([pkg, `${p} tool`]); + expect(await layeredAt(name, pkg), `${when}: ${name} layered at ${p}`).toEqual([200, null, `${p} tool`]); + } + await expectMetaRefused('tool', name, holders.map((p) => `com.qa.bare.${p}`)); + } + } + }); }); /** * [#32151, ADR-0150 D3/D4] The artifact door, which the boot above does not * reach: `bootStack` mounts `AppPlugin` as the stack's one registrar and a * `MetadataPlugin` with no artifact, so the metadata service there holds no - * agent or skill at all. `os dev` (HMR) and `os start` load the compiled + * agent or skill at all. [#31985] A tool joins the same slots in the change + * that narrows it, so each pin here runs for the tool too. `os dev` (HMR) and `os start` load the compiled * artifact through `MetadataPlugin`'s artifact door instead, which registers * every package body's items into the metadata service, stamped * `_packageId`. Its in-memory store was keyed by bare name for these types, so @@ -377,7 +421,9 @@ describe('agent and skill names held per namespace, a tool name per deployment, * `get` of the name, the one naming the other package included, answered the * survivor, and `GET /meta/TYPE/NAME/layers?package=` served the * survivor's body as both the code and the effective layer, under the - * survivor's `packageId`. + * survivor's `packageId`. (For a tool the layered read already served each + * package's own: it judges the code layer at the exact address, and its pin + * stays green with `tool` taken back out of the slotted store.) * * The one narrowing the slots bring is a read of the metadata service naming * a package that holds no slot of the name: it was answered the stored item @@ -385,16 +431,22 @@ describe('agent and skill names held per namespace, a tool name per deployment, * read naming such a package was already refused `409` (ADR-0150 D5) before * the service was asked, and still is. */ -describe('the artifact door keeps each namespace\'s agent and skill in the metadata service, and the layered read serves each package its own (#32151)', () => { +describe('the artifact door keeps each namespace\'s agent, skill and tool in the metadata service, and the layered read serves each package its own (#32151, #31985)', () => { const ALPHA = 'com.qa.bare.alpha'; const BETA = 'com.qa.bare.beta'; const SOLO_AGENT = 'qa_solo_agent'; const SOLO_SKILL = 'qa_solo_skill'; + const SOLO_TOOL = 'qa_solo_tool'; + const TYPES = ['agent', 'skill', 'tool'] as const; + type SlottedType = (typeof TYPES)[number]; + const SHARED: Record = { agent: AGENT, skill: SKILL, tool: TOOL }; + const SOLO: Record = { agent: SOLO_AGENT, skill: SOLO_SKILL, tool: SOLO_TOOL }; const artifactPackage = (p: 'alpha' | 'beta') => defineStack({ manifest: { id: `com.qa.bare.${p}`, namespace: p, name: `qa_bare_${p}`, version: '1.0.0', type: p === 'alpha' ? 'app' : 'module' }, objects: [item(p)], agents: [agent(p), ...(p === 'alpha' ? [agent(p, SOLO_AGENT)] : [])], skills: [skill(p), ...(p === 'alpha' ? [skill(p, SOLO_SKILL)] : [])], + tools: [tool(p), ...(p === 'alpha' ? [tool(p, SOLO_TOOL)] : [])], } as never); const artifact = composeStacks([artifactPackage('alpha'), artifactPackage('beta')], { manifest: 'preserve' }); @@ -434,8 +486,8 @@ describe('the artifact door keeps each namespace\'s agent and skill in the metad return { status: r.status, code: body?.code?.label, effective: body?.effective?.label, packageId: body?.packageId, body }; }; - it.each(['agent', 'skill'] as const)('%s: `/layers?package=` serves each package\'s own code and effective layer (BASE: both were the package registered last)', async (type) => { - const name = type === 'agent' ? AGENT : SKILL; + it.each(TYPES)('%s: `/layers?package=` serves each package\'s own code and effective layer (BASE: agent and skill served the package registered last; a tool was already served its own)', async (type) => { + const name = SHARED[type]; for (const p of ['alpha', 'beta'] as const) { const read = await layers(type, name, `com.qa.bare.${p}`); expect([read.status, read.code, read.effective, read.packageId], JSON.stringify(read.body).slice(0, 300)) @@ -443,8 +495,8 @@ describe('the artifact door keeps each namespace\'s agent and skill in the metad } }); - it.each(['agent', 'skill'] as const)('%s: the metadata service holds both packages\' items: a read naming each package answers its own, and the read naming none is refused naming both (BASE: every read answered the package registered last)', async (type) => { - const name = type === 'agent' ? AGENT : SKILL; + it.each(TYPES)('%s: the metadata service holds both packages\' items: a read naming each package answers its own, and the read naming none is refused naming both (BASE: every read answered the package registered last)', async (type) => { + const name = SHARED[type]; expect((await metadata.get(type, name, ALPHA))?.label).toBe(`alpha ${type}`); expect((await metadata.get(type, name, BETA))?.label).toBe(`beta ${type}`); expect((await metadata.list(type)).filter((i) => i?.name === name).map((i) => i?.label).sort()).toEqual([`alpha ${type}`, `beta ${type}`]); @@ -453,8 +505,8 @@ describe('the artifact door keeps each namespace\'s agent and skill in the metad for (const holder of [ALPHA, BETA]) expect(String(refused?.message)).toContain(holder); }); - it.each(['agent', 'skill'] as const)('CONTROL — %s: the doors that already resolved by package answer as before: the bare read and the bare layered read refuse naming both, `?package=` serves each package\'s own', async (type) => { - const name = type === 'agent' ? AGENT : SKILL; + it.each(TYPES)('CONTROL — %s: the doors that already resolved by package answer as before: the bare read and the bare layered read refuse naming both, `?package=` serves each package\'s own', async (type) => { + const name = SHARED[type]; for (const path of [`/meta/${type}/${name}`, `/meta/${type}/${name}/layers`]) { const r = await stack.apiAs(admin, 'GET', path); const text = await r.text(); @@ -469,17 +521,17 @@ describe('the artifact door keeps each namespace\'s agent and skill in the metad } }); - it.each(['agent', 'skill'] as const)('%s: a read of the metadata service naming a package that holds no slot of the name answers nothing (BASE: the one holder\'s item, or the survivor of two)', async (type) => { - const solo = type === 'agent' ? SOLO_AGENT : SOLO_SKILL; + it.each(TYPES)('%s: a read of the metadata service naming a package that holds no slot of the name answers nothing (BASE: the one holder\'s item, or the survivor of two)', async (type) => { + const solo = SOLO[type]; expect(await metadata.get(type, solo, BETA), 'one holder').toBeUndefined(); expect(await metadata.getDiagnosed(type, solo, BETA)).toEqual({ data: undefined, degraded: false, errors: [] }); - expect(await metadata.get(type, type === 'agent' ? AGENT : SKILL, 'com.qa.bare.gamma'), 'two holders').toBeUndefined(); + expect(await metadata.get(type, SHARED[type], 'com.qa.bare.gamma'), 'two holders').toBeUndefined(); }); - it.each(['agent', 'skill'] as const)('CONTROL — %s: `/layers?package=` a package that holds no slot is refused 409 naming the holder (D5), for one holder and for two, as before', async (type) => { + it.each(TYPES)('CONTROL — %s: `/layers?package=` a package that holds no slot is refused 409 naming the holder (D5), for one holder and for two, as before', async (type) => { for (const [name, pkg, holders] of [ - [type === 'agent' ? SOLO_AGENT : SOLO_SKILL, BETA, [ALPHA]], - [type === 'agent' ? AGENT : SKILL, 'com.qa.bare.gamma', [ALPHA, BETA]], + [SOLO[type], BETA, [ALPHA]], + [SHARED[type], 'com.qa.bare.gamma', [ALPHA, BETA]], ] as const) { const read = await layers(type, name, pkg); expect([read.status, codeOf(read.body)], JSON.stringify(read.body).slice(0, 300)).toEqual([409, 'RESOURCE_CONFLICT']); @@ -487,8 +539,8 @@ describe('the artifact door keeps each namespace\'s agent and skill in the metad } }); - it.each(['agent', 'skill'] as const)('CONTROL — %s: one holder per name: every read answers the one package\'s item, bare or by its package', async (type) => { - const name = type === 'agent' ? SOLO_AGENT : SOLO_SKILL; + it.each(TYPES)('CONTROL — %s: one holder per name: every read answers the one package\'s item, bare or by its package', async (type) => { + const name = SOLO[type]; expect((await metadata.get(type, name))?.label).toBe(`alpha ${type}`); expect((await metadata.get(type, name, ALPHA))?.label).toBe(`alpha ${type}`); const bare = await layers(type, name); diff --git a/packages/spec/liveness/tool.json b/packages/spec/liveness/tool.json index 7c5ba2a10b3..68092c4c29c 100644 --- a/packages/spec/liveness/tool.json +++ b/packages/spec/liveness/tool.json @@ -1,6 +1,6 @@ { "type": "tool", - "_note": "ToolSchema. Seeded from docs/audits/archive/2026-06/2026-06-toolschema-property-liveness.md. Tool metadata is not an execution entry point — the RUNTIME uses a separate AIToolDefinition, and most props here are live via that same-named surface. ⚠ 2026-08-29: the framing this note carried for years, 'WRITE-ONLY … not metadata read-back', is FALSIFIED and was actively harmful — it is why nobody looked at the renderer. objectui's metadata-admin preview IS a registered consumer of persisted `tool` records (objectui @26896c6, `registerMetadataPreview('tool', ToolPreview)`), and ToolPreview reads ALL SIX props off the stored record: name, label, description, objectName, parameters, outputSchema. So there are TWO live bases on this type, and each row says which one it rests on: the AIToolDefinition surface (behavioural) and the metadata read-back (display, the #7131 rule). `objectName` is the row that turns on the difference — it has NO behavioural reader anywhere and is live on the read-back alone. ⚠ EVIDENCE LIVES MOSTLY IN CLOUD: every `cloud`-attributed path below is the closed `@objectstack/service-ai` / `@objectstack/service-ai-studio` runtime in the CLOUD repo, not git-tracked here — see content/docs/ai for the open/cloud boundary. 2026-08-29 RE-CLOSED against cloud `origin/main@15f55df`, the first pass run from a container that actually had a cloud checkout in reach; three things the old note asserted turned out to be false, and each failed in its own way. (a) It said the framework's own service-ai tree 'is a stale build artifact with no src/'. That was stale twice over and is now simply FALSE — the tree is ABSENT: `git ls-files` matches 0 paths containing service-ai, no such directory exists on disk, and `packages/services/` holds 16 members, none of them service-ai. There is no artifact left to be stale. (b) The cited path prefix was wrong for the CLOUD repo too. Cloud's real layout is `packages/service-ai/…` and `packages/service-ai-studio/…`, never `packages/services/service-ai/…`, so the five citations this file used to carry named a path that exists in NEITHER repo — unfalsifiable pointers, which is exactly what the README says a `live` verdict must never rest on. ⚠ MECHANICAL TRAP for anyone repointing a sibling ledger: `scripts/liveness/evidence.mts` hardcodes only `packages/services/service-ai/` in FOREIGN_PATH_PREFIXES, which is why the WRONG spelling sat green for so long; the REAL cloud path is repo-rooted in shape and is NOT in that list, so an unmarked repoint resolves as LOCAL and fails CI. Every citation of it MUST carry the `cloud` realm marker. The stale spelling and this note's sentence (a) both survive in action.json (3 entries), agent.json (11) and skill.json (8) — filed as #13272. (c) 'the OPEN framework edition does not consume them' is FALSE for `name` and `description`: `packages/mcp` bridges each AIToolDefinition onto an MCP server and reads both. Those two entries now carry framework-local ANCHORED evidence, so CI can falsify them from this checkout — the condition this re-close (commit c19035e97) was run to meet. (d) the write-only claim above, corrected in the same pass once an objectui checkout came into reach. Note the pattern across all four: every one of them was a NEGATIVE claim ('no src', 'not framework code', 'the open edition does not', 'not read back') that no gate could falsify, and three of the four were wrong. The realms named in each `evidenceScope` are the realms actually walked — cloud @15f55df and objectui @26896c6 — and never 'everywhere'. 2026-07-30 (#3896 close-out): the four inert authoring keys (category/permissions/active/builtIn) were REMOVED from ToolSchema — permissions promised an invocation gate nothing enforced, active:false withdrew nothing; strict-rejected with prescriptions (TOOL_RETIRED_KEY_GUIDANCE) and stripped by the tool-inert-authoring-keys-removed conversion. Entries deleted per the requiresConfirmation precedent (#3715).", + "_note": "ToolSchema. Seeded from docs/audits/archive/2026-06/2026-06-toolschema-property-liveness.md. Tool metadata is not an execution entry point — the RUNTIME uses a separate AIToolDefinition, and most props here are live via that same-named surface. ⚠ 2026-08-29: the framing this note carried for years, 'WRITE-ONLY … not metadata read-back', is FALSIFIED and was actively harmful — it is why nobody looked at the renderer. objectui's metadata-admin preview IS a registered consumer of persisted `tool` records (objectui @26896c6, `registerMetadataPreview('tool', ToolPreview)`), and ToolPreview reads ALL SIX props off the stored record: name, label, description, objectName, parameters, outputSchema. So there are TWO live bases on this type, and each row says which one it rests on: the AIToolDefinition surface (behavioural) and the metadata read-back (display, the #7131 rule). `objectName` is the row that turns on the difference — it has NO behavioural reader anywhere and is live on the read-back alone. ⚠ EVIDENCE LIVES MOSTLY IN CLOUD: every `cloud`-attributed path below is the closed `@objectstack/service-ai` / `@objectstack/service-ai-studio` runtime in the CLOUD repo, not git-tracked here — see content/docs/ai for the open/cloud boundary. 2026-08-29 RE-CLOSED against cloud `origin/main@15f55df`, the first pass run from a container that actually had a cloud checkout in reach; three things the old note asserted turned out to be false, and each failed in its own way. (a) It said the framework's own service-ai tree 'is a stale build artifact with no src/'. That was stale twice over and is now simply FALSE — the tree is ABSENT: `git ls-files` matches 0 paths containing service-ai, no such directory exists on disk, and `packages/services/` holds 16 members, none of them service-ai. There is no artifact left to be stale. (b) The cited path prefix was wrong for the CLOUD repo too. Cloud's real layout is `packages/service-ai/…` and `packages/service-ai-studio/…`, never `packages/services/service-ai/…`, so the five citations this file used to carry named a path that exists in NEITHER repo — unfalsifiable pointers, which is exactly what the README says a `live` verdict must never rest on. ⚠ MECHANICAL TRAP for anyone repointing a sibling ledger: `scripts/liveness/evidence.mts` hardcodes only `packages/services/service-ai/` in FOREIGN_PATH_PREFIXES, which is why the WRONG spelling sat green for so long; the REAL cloud path is repo-rooted in shape and is NOT in that list, so an unmarked repoint resolves as LOCAL and fails CI. Every citation of it MUST carry the `cloud` realm marker. The stale spelling and this note's sentence (a) both survive in action.json (3 entries), agent.json (11) and skill.json (8) — filed as #13272. (c) 'the OPEN framework edition does not consume them' is FALSE for `name` and `description`: `packages/mcp` bridges each AIToolDefinition onto an MCP server and reads both. Those two entries now carry framework-local ANCHORED evidence, so CI can falsify them from this checkout — the condition this re-close (commit c19035e97) was run to meet. (d) the write-only claim above, corrected in the same pass once an objectui checkout came into reach. Note the pattern across all four: every one of them was a NEGATIVE claim ('no src', 'not framework code', 'the open edition does not', 'not read back') that no gate could falsify, and three of the four were wrong. The realms named in each `evidenceScope` are the realms actually walked — cloud @15f55df and objectui @26896c6 — and never 'everywhere'. 2026-07-30 (#3896 close-out): the four inert authoring keys (category/permissions/active/builtIn) were REMOVED from ToolSchema — permissions promised an invocation gate nothing enforced, active:false withdrew nothing; strict-rejected with prescriptions (TOOL_RETIRED_KEY_GUIDANCE) and stripped by the tool-inert-authoring-keys-removed conversion. Entries deleted per the requiresConfirmation precedent (#3715). ⚠ PRECONDITION on the first reader of a package `tool` record (ADR-0150 D3, D9; drafted 2026-11-10 with the change that narrows `tool` to one holder per namespace, so two packages of two namespaces may now each hold one tool name). Cloud reading 2026-11-12 on cloud `main@9b50c62e` (issue comment 6837767385, source read, tests excluded, positive control on `skill`): no cloud reader reads a package `tool` record at all. Its four touches of type `tool` are a fixed-name `exists` probe (service-ai) and AI Studio mirroring its built-in definitions INTO metadata and retracting them (service-ai-studio); a skill's `tools[]` resolves by name against the live ToolRegistry of code-defined AIToolDefinitions, never a `tool` record. The epic ruling 6838039881 holds that this meets the epic read 6760270915's condition: no deployment can reach a pick between two holders, because none is read. In this repo the one by-name reader, `/meta/tool/NAME`, already answers by (package, name) and refuses a bare name two packages hold with 409 naming both. The first change that makes package tool records live — a cloud resolver of a skill's `tools` names, or any other reader — needs its own red-line read and MUST resolve a name from the referring item's own package, as a (package, name) key (its own record, else the unique holder in its declared dependency closure), and MUST refuse a name with two holders with 409 naming every candidate; it never takes the first one registered and never reaches a tool outside that closure or one only the environment holds.", "props": { "name": { "status": "live", diff --git a/packages/spec/src/migrations/entries/semantic/18.tool-names-per-namespace.ts b/packages/spec/src/migrations/entries/semantic/18.tool-names-per-namespace.ts new file mode 100644 index 00000000000..e3ddda9e1cb --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.tool-names-per-namespace.ts @@ -0,0 +1,46 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A narrowing of answers, not of any key: ADR-0150 D2/D9 (child B, #31985) +// hold a tool name per namespace, so two packages of two namespaces may each +// ship a tool of one name, and the metadata service stores a tool per +// (package, name). No key is added, removed or re-shaped, so no tombstone and +// no D2 conversion: which holder an in-process caller meant is the caller's +// judgement. The stored row's package column is filled on the package's next +// save, or by the operator's re-runnable row-binding migration; reads are +// right without it. No relevance question: the refusals turn on what two +// installed packages hold, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'tool-names-per-namespace', + surface: + 'A tool name that two packages of two namespaces hold, read or removed in process with no package: the ' + + 'metadata service\'s get, getDiagnosed, unregister, getHistory, diff and rollback for type tool, and ' + + 'DatabaseLoader.delete by name; a read naming a package that holds no slot of the name; and a sys_metadata ' + + 'row of type tool that the database loader wrote before this release (package_id empty)', + replacement: + 'Name the holder: pass the package (get, getDiagnosed, getHistory, diff and rollback with packageId, ' + + 'unregister with packageId, or unregisterPackage for the whole package); over REST add ?package=ID or use ' + + 'the qualified address /api/v1/meta/tool/NS/NAME. A legacy loader row binds to the package its body names ' + + 'on that package\'s next save, or at once through migrateDatabaseLoaderRowPackages from ' + + '@objectstack/metadata/migrations, which is safe to run any number of times and leaves a row whose body ' + + 'names no package as it is.', + reason: + 'Before this release a second package of another namespace was refused 422 NAMESPACE_CONFLICT at install, so ' + + 'a tool name had one package holder per deployment and the metadata service kept one tool per name. Two ' + + 'namespaces\' packages may now each hold the name, and the service keeps each package\'s tool in its own ' + + '(package, name) slot, so a caller naming no package cannot be answered one of them: the read, the removal, ' + + 'the history, the diff and the rollback answer 409 RESOURCE_CONFLICT naming both holders where they answered ' + + 'or removed the item registered or saved last, a read naming a package that holds no slot answers nothing, ' + + 'and a rollback to a version a removed package wrote is refused where it wrote that version into the ' + + 'remaining holder\'s row. The loader writes a row per (package, name) with package_id filled, where it wrote ' + + 'one row per name with the column empty. GET /api/v1/meta/tool/NAME already answered by (package, name) ' + + '(ADR-0150 D3) and is unchanged. A name one package holds answers exactly as before. Measured when the ' + + 'change landed: no first-party caller in this repository reads or removes a tool by name in process.', + acceptanceCriteria: + 'For every tool name the deployment\'s packages hold, list its holders (GET /api/v1/meta/tool/NS/NAME per ' + + 'namespace). Where two packages hold a name, every in-process caller that reads, removes, diffs or rolls ' + + 'back the tool passes the package, and GET /api/v1/meta/tool/NAME?package=ID answers 200 with that holder\'s ' + + 'tool for each holder. After migrateDatabaseLoaderRowPackages, its result lists no tool row left as ' + + 'slot-taken or update-failed; a row left as package-less is the environment\'s own tool.', +}; diff --git a/scripts/adr-anchors/packages__objectql__src__bare-name-one-holder.ts.json b/scripts/adr-anchors/packages__objectql__src__bare-name-one-holder.ts.json index 4f3bc1f90df..56fc9f72892 100644 --- a/scripts/adr-anchors/packages__objectql__src__bare-name-one-holder.ts.json +++ b/scripts/adr-anchors/packages__objectql__src__bare-name-one-holder.ts.json @@ -5,5 +5,5 @@ "ADR-0005", "ADR-0150" ], - "invariant": "ADR-0048 §3.4 retired the per-item cross-package throw because a caller carries its package id. Three families of consumers carry none, so with two holders every caller is served one package's item, picked by registration order: the data family — a field's picklist, an import's mappingName and a dashboard's datasetName — serves the first-registered one; the request family — the endpoint matcher's API, an object-less action's handler and the engine function registry's function, read by a flow script node or an action's target — serves the last-registered one; the flow family — the automation engine's one armed flow per name, the dispatcher's one declared webhook per name, the connector picker's one connector per name and a send's email template bundle — serves the first-registered one (the flow: the lexicographically-first package's, with a warning); the AI family — the agent /meta/agent/NAME serves and the skill an MCP client's prompts/get resolves — serves the first-registered one; and a tool, which joined after the AI family on its own measurement (ADR-0048 P1.10) — /meta/tool/NAME serves the first-registered one, and a skill's tools list, a tool call and an MCP server name a tool by its bare name alone. The maintainer's ruling C on #30798 (phase 1, ADR-0048 addendum 2026-11-06, each family in its own change under #30803, the AI family last) narrows §3.4 for these types: one name, one PACKAGE holder. After the cold boot seals the registry (kernel:bootstrapped), a package bringing a name another installed package or a built-in holds is refused at three doors, naming both holders and the namespace-prefixed rename: the package door (SchemaRegistry.installPackage) and the item seam (SchemaRegistry.registerItem) for the registry types, and the hook binder's bind (bindHooksToEngine in hook-binder.ts, through SchemaRegistry.claimBareNameFunctions) for a function, ahead of every registration it would make. An email template's NAME holds its (name, locale) bundle, so the holder reading strips the registry key's member. ⛔ Never judge the environment catalog — an environment item under a package's name is the ADR-0005 overlay — never judge a type's overridable baseline (OVERRIDABLE_BASELINE_PACKAGES: the email service's built-in templates, which an app's same-named template overrides by contract, so that package neither holds a template name nor is refused one), never let OS_METADATA_COLLISION=warn downgrade the refusal, never judge during the boot (a deployment already holding a clash must still boot: the cold-boot switch decides warn or refuse), and never treat a package that already holds the name as a new holder. ADR-0150 D2/D9 then narrows the rule per type, last, once that type's by-name readers resolve by (package, name), its AI face is derived from the namespace and its stored references carry the package: a type in NAMESPACE_SCOPED_BARE_NAME_TYPES (agent and skill first) keeps one package holder per NAMESPACE, and bareNameHoldersMeet is the one predicate the package door, the item seam and the cold-boot seal ask before two package holders conflict. ⛔ Two holders of different declared namespaces never conflict for such a type; two of one namespace, a holder with no namespace beside any other, two of one shareable namespace and a built-in name still do, with the same refusal; a type not in the set keeps one holder per deployment." + "invariant": "ADR-0048 §3.4 retired the per-item cross-package throw because a caller carries its package id. Three families of consumers carry none, so with two holders every caller is served one package's item, picked by registration order: the data family — a field's picklist, an import's mappingName and a dashboard's datasetName — serves the first-registered one; the request family — the endpoint matcher's API, an object-less action's handler and the engine function registry's function, read by a flow script node or an action's target — serves the last-registered one; the flow family — the automation engine's one armed flow per name, the dispatcher's one declared webhook per name, the connector picker's one connector per name and a send's email template bundle — serves the first-registered one (the flow: the lexicographically-first package's, with a warning); the AI family — the agent /meta/agent/NAME serves and the skill an MCP client's prompts/get resolves — serves the first-registered one; and a tool, which joined after the AI family on its own measurement (ADR-0048 P1.10) — /meta/tool/NAME serves the first-registered one, and a skill's tools list, a tool call and an MCP server name a tool by its bare name alone. The maintainer's ruling C on #30798 (phase 1, ADR-0048 addendum 2026-11-06, each family in its own change under #30803, the AI family last) narrows §3.4 for these types: one name, one PACKAGE holder. After the cold boot seals the registry (kernel:bootstrapped), a package bringing a name another installed package or a built-in holds is refused at three doors, naming both holders and the namespace-prefixed rename: the package door (SchemaRegistry.installPackage) and the item seam (SchemaRegistry.registerItem) for the registry types, and the hook binder's bind (bindHooksToEngine in hook-binder.ts, through SchemaRegistry.claimBareNameFunctions) for a function, ahead of every registration it would make. An email template's NAME holds its (name, locale) bundle, so the holder reading strips the registry key's member. ⛔ Never judge the environment catalog — an environment item under a package's name is the ADR-0005 overlay — never judge a type's overridable baseline (OVERRIDABLE_BASELINE_PACKAGES: the email service's built-in templates, which an app's same-named template overrides by contract, so that package neither holds a template name nor is refused one), never let OS_METADATA_COLLISION=warn downgrade the refusal, never judge during the boot (a deployment already holding a clash must still boot: the cold-boot switch decides warn or refuse), and never treat a package that already holds the name as a new holder. ADR-0150 D2/D9 then narrows the rule per type, last, once that type's by-name readers resolve by (package, name), its AI face is derived from the namespace and its stored references carry the package: a type in NAMESPACE_SCOPED_BARE_NAME_TYPES (agent and skill first, then tool, whose record has no reader but /meta/tool/NAME and no AI face) keeps one package holder per NAMESPACE, and bareNameHoldersMeet is the one predicate the package door, the item seam and the cold-boot seal ask before two package holders conflict. ⛔ Two holders of different declared namespaces never conflict for such a type; two of one namespace, a holder with no namespace beside any other, two of one shareable namespace and a built-in name still do, with the same refusal; a type not in the set keeps one holder per deployment." }