Skip to content

Commit c747cf0

Browse files
feat(objectql, core, metadata)!: tool names held per namespace, and the metadata service keeps each package's tool in its own (package, name) slot (ADR-0150 child B) (#33124)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DSL8MNE2jk3FnZEq9DvJJo1)_ epic:#31527#2 · os-elon-musk · session_016WV4d1T8WbNLuRhvuhMHBF ## 维护者速读 - 改了什么:工具(tool)的同名规则从「整个部署只能一个包持有」放宽为「每个命名空间一个」,与 agent、skill、action、邮件模板、flow、picklist 一族、webhook 一致;元数据服务把 tool 按(包,名字)分槽存。本轮在原 PR 基础上合入最新 main,补了一组「无包行 + 两个持有包」的钉子测试,并把升级说明登记成正式的迁移条目。 - 为什么改:ADR-0150 第 14 张 B 卡。专题红线复读(6840825374)给了 HOLD:要求合 main、改两处说法、ADR-0087 不能再写「无需登记」、补一个 tool 的密封类型钉子;本 PR 逐条完成。 - 风险与回滚:BREAKING 只在进程内元数据服务的五个答案(两包同名的 tool 不带包名读取、删除、历史/比较/回滚由「最后一个」改为 409 点名两包),本仓第一方调用方 0;HTTP 与 MCP 门不变。同命名空间共有者、无命名空间包、base/system/sys、内置名照旧被拒。回滚就是把 `tool` 从两个集合里删掉。 - 先看:`packages/core/src/package-scoped-resolution.ts` 与 `packages/metadata/src/package-slotted-store.ts`(两个集合各加 `tool`,与 webhook 并存)、`packages/spec/src/migrations/entries/semantic/18.tool-names-per-namespace.ts`(新登记的升级条目)、`packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts` 末尾新钉子。 - 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run src/package-scoped-exact-qualifier.test.ts -t tool`,应 12 条全部通过(其中 8 条是新加的 tool:两种注册顺序 × 四种回填状态)。 - 需要你做的:无,席位落地。 Fixes #31985 Supersedes #32895 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 from another declared namespace. Narrowed: `tool` joins `PACKAGE_SLOTTED_STORE_TYPES`, so five in-process answers of the metadata service for a tool move from served to refused or empty (rows 5–9 below); first-party callers in this repo 0. Metadata-protocol: added Skills-docs: follow-up #32916 (owed: `content/docs/ai/tools.mdx` and the spec jsdoc still call a tool name globally unique) — otherwise `skills/**` and `content/docs/**` teach no tool rename on a cross-namespace clash, no in-process `get('tool', …)`, no tool history read and no `/layers?package=` read of a tool. **Narrowing: yes** — first-party callers in this repo **0**: no production source calls `get`, `getDiagnosed`, `unregister`, `getHistory`, `diff` or `rollback` with the type `tool`; first-party tool records in `examples/`: 0; on a booted stack no HTTP or MCP door moves from served to refused. The cloud's calls on the metadata service for type `tool` are listed in the cloud reading 6837767385 and carried to the cloud separately (Carried to repo:cloud). > **Draft condition (epic read 6760270915): met, limb (b)**, per the epic ruling 6838039881 on the cloud reading 6837767385 (cloud `main@9b50c62e`): no cloud reader reads a package `tool` record. `packages/spec/liveness/tool.json` names cloud `9b50c62e`, the reading and the ruling, and keeps the rule for the first cloud reader: resolve by the referrer's own `(package, name)`, refuse two holders `409` naming every candidate, never the first registered. > > **Branch.** This thread cannot push `claude/project-thread-cb6zil`, so this is a new draft from `claude/project-thread-w47m4s`, which continues `cb6zil@d39ba13` (every commit kept, never rebased) with `origin/main` merged once. `#32895` is superseded; the seat retires it. ## What this round changes (red-line read 6840825374, verdict HOLD) | Item | What it asked | Done here | |:--|:--|:--| | Must-fix 1 | merge `main`; restate carried path (i), false on `main` since #32741 | `origin/main` `2c98485db` merged once (`c84542096`). Carried path (i) restated in the changeset and below: a package-less stored tool row is no longer grafted onto any holder's slot; what `main` still leaves open is two stored rows each naming a holder (only the last loaded stays) and the in-process layered read (#32914) | | Must-fix 2 | replace "it is not measured here" for the package-less row beside a package tool | Acceptance notes now state the measured answer, and two new pins hold it (below) | | Must-fix 3 / ruling 1 | the ADR-0087 not-required marker does not stand | the changeset now carries `adr-0087: registered tool-names-per-namespace`; the semantic entry `packages/spec/src/migrations/entries/semantic/18.tool-names-per-namespace.ts` names the five in-process answers and the re-runnable row binding (`migrateDatabaseLoaderRowPackages`), with its own `@objectstack/spec` patch changeset, as the picklist family's entry did | | Ruling 2 | `Metadata-protocol: added` stands | unchanged | | Ruling 3 | a tool pin for the sealed-type rule: two holders and a package-less row, both orders, booted and after the hydration | unit: `tool` joins #32741's location-4 loop in `package-scoped-exact-qualifier.test.ts` (4 hydration states × 2 registration orders, plus the one-holder case). Booted: a new dogfood pin saves a package-less row through `PUT /meta/tool/NAME`, then installs two namespaces' packages through install-local in both orders, and reads each exact address plain and layered before and after the read-side hydrator | | Ruling 4 | measure whether #32914 still triggers on `main` after #32741 | the red-line read measured it on the scratch merge: the in-process layered read with a bare name still answers the first-registered holder where the service has no copy. Not re-run here; re-measured by the epic re-read on #33124 (still triggers, both orders); triage kept #32914 at p3 under #32997 (6857956853) | | Ruling 5 | #32692 keeps its scope; the extension goes to a card of its own | filed as #33127; the changeset no longer says #32692 covers every type | | Nits | row 4's FROM, row 11's HTTP face, row 5's undeclared in-process consequence, the dogfood pin title, the open-PR citation, `tool.json`'s date, delta D2/D3 | all corrected (table and notes below; the changeset; the dogfood header and title; `tool.json` reads "drafted 2026-11-10") | The merge resolves four textual conflicts with #32577 (webhook, merged as `e55347d21`), each a union: both `webhook` and `tool` stay in `NAMESPACE_SCOPED_BARE_NAME_TYPES` and `PACKAGE_SLOTTED_STORE_TYPES`, both module-doc paragraphs are kept, and the plural-read pin lists both. ## Moved answers (FROM → TO) FROM is `origin/main`; TO is this head. | # | Surface | FROM | TO | Clause-② arm | Pin | |---|---|---|---|---|---| | 1 | `installPackage` / `registerItem` of a package whose namespace differs from the tool name's holder's | refused `422 NAMESPACE_CONFLICT` naming both holders | installs | widening | ai-family "the narrowing" matrix (`tool`); dogfood third-namespace install | | 2 | cold boot of two namespaces' holders of one tool name | boots with one bare-name warning naming the tool | boots, no warning | widening | ai-family cold-boot pin; dogfood "no bare-name warning" | | 3 | `os migrate stored-references` sealed clashes | listed two namespaces' tool holders | not listed | widening | `stored-references.integration.test.ts` (the connector stays listed) | | 4 | bare read of a tool name two namespaces hold, one disabled | reachable only through a cold-boot sealed clash, where it answered as TO | the enabled holder's; re-enabled, `409` naming both | widening | ai-family "[#31985] one of two namespaces' tool holders disabled", both orders | | 5 | `MetadataManager.get('tool', NAME)` / `getDiagnosed`, no package, two holders | item registered (or saved) last | `409 RESOURCE_CONFLICT` (`ambiguous-in-environment`) naming both | narrowing | metadata #32151 / #32246 SLOTTED pins (`tool`), dogfood artifact-door block | | 6 | `get('tool', NAME, PKG)` / `getDiagnosed`, PKG holds no slot, another does | the stored item | `undefined`; no loader asked | narrowing | metadata #32151 pin, dogfood "answers nothing" | | 7 | `unregister('tool', NAME)` no package, two holders; rollback of a name with two slots' rows | resolves (deleted nothing / overwrote the first row) | `409` naming every holder, before any delete, event or write | narrowing | metadata #32198 / #32246 SLOTTED pins | | 8 | `DatabaseLoader.delete` by name, no package, two holders | deleted the first row | refused | narrowing | metadata #32246 SLOTTED pins | | 9 | `getHistory` / `diff` / `rollback` of a tool name two packages saved, no package; a rollback to a removed package's version | every version of the one row; the version written into the remaining holder's row | `409` naming both; the rollback refused | narrowing | `metadata-history.test.ts` (iterates `PACKAGE_SLOTTED_STORE_TYPES`) | | 10 | `DatabaseLoader.save` of a tool | one row per name, `package_id` empty | one row per `(package, name)`, `package_id` filled; history rows record the package | storage (registered: `tool-names-per-namespace`) | metadata #32246 SLOTTED pins; `migrateDatabaseLoaderRowPackages` pins (`tool`) | | 11 | in-process `list('tool')`, `loadMany` / `loadManyKeyed('tool')` with two holders | the survivor | each package's item | widening | metadata SLOTTED `list` pins; `metadata-manager-keyed-plural-read.test.ts` (`tool` in `UNBUNDLED`). `GET /meta/tool` listed both before and still does (not moved) | | 12 | `GET /meta/tool/NAME/layers?package=PKG`, two holders, artifact boot | PKG's own | unchanged | none (pinned) | dogfood artifact-door `/layers?package=` (`tool`); green with `tool` out of `PACKAGE_SLOTTED_STORE_TYPES` (measured on `cb6zil`) | | 13 | bare `/meta/tool/NAME` on a registry whose `readsByPackage('tool')` is `false` | `getItem`'s first match | `501 NOT_IMPLEMENTED` | narrowing (no in-repo composition) | `package-scoped-exact-qualifier.test.ts` (b) `it.each` over the narrowed set | | 14 | replica convergence on a cluster signal for a tool | the first row the store returns by name | a signal naming a package: that package's row; an unstamped signal of a name bound to two or more packages: a logged stop, ledger entry kept (#32451) | narrowing | `metadata-manager-cluster.test.ts` slotted removal pins (iterate the set) | | 15 | boot priming pass, a package-less stored tool row | stamped with the host's package | left unstamped (#32812's rule for every slotted type): its one holder's customization or the environment's own item; under a two-holder name, no holder's own | narrowing | `database-loader.test.ts` `[#32521]` / `[#32791]` priming pins (iterate the unbundled slotted set) | | 16 | in-process `getMetaItemLayered` with a bare name on an artifact boot (the service keeps both copies) | the holder registered last | `409` naming both, with the service's bare read | narrowing | follows row 5 (the red-line read measured 4 cells); the no-copy case is #32914's | Still refused, each with today's envelope and sentence: a co-owner of the holder's namespace (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), a package with no namespace beside any holder (a disabled one included), two packages of one shareable namespace (`base`, `system`, `sys`), and a built-in name. ## Red lines 1. **Resolution is never loosened.** No reader in this repo resolves a `skill.tools[]` entry from a `tool` record. The one by-name reader of a record, `/meta/tool/NAME`, keeps ADR-0150 D3's order, pinned by child E8's `package-scoped-e8-readers.test.ts` (`tool` in `E8_TYPES`; green at this head, below). Since the last head, `main` added one in-repo reader of `skill.tools[]` (#32880, `skillBindingServed` in `packages/mcp/src/skill-prompts.ts`): it matches each entry against the MCP connection's live served tool names, never a `tool` record, so it reaches no package holder. 2. **Ambiguity is reported, never guessed.** Two served holders of a tool name answer `409` naming both at the bare read, the bare `/layers` and `/published` (both transports) and at the metadata service (rows 5, 7, 8, 9, 16). A package-less row beside two holders is declined at each exact address, so neither holder's address serves it (ruling 3 pins). Two by-order paths remain, both older than this PR and both reached by every narrowed type: the in-process layered read with no service copy (#32914), and two stored rows each naming a holder of one name, where the hydration keeps the last loaded (the second case #32692 names for a webhook; the widening is #33127, ruling 5). 3. **Independently releasable.** Clause-② arms above and in the changeset, every moved answer in the table, `Metadata-protocol: added`, the ADR-0087 registration, and pins that go red under ablation (Tests). ## ADR-0087 `adr-0087: registered tool-names-per-namespace`. The semantic entry records the five in-process answers (row 5–9), the remedy (pass the package; `?package=` or the qualified address over REST), and the row binding a legacy loader row needs (`migrateDatabaseLoaderRowPackages`, re-runnable, or the package's next save). No key is added, removed or re-shaped, so no D2 conversion and no tombstone. Its own changeset `.changeset/31985-tool-names-semantic-entry.md` (`@objectstack/spec` patch, `Clause-②: no`, `Metadata-protocol: none`) is the picklist family's shape (#32513). ## Readings (a)–(d), re-measured on this head - **(a) Face (D6).** No surface in this repo shows a package `tool` record to a model or an MCP client. 336 non-test source files changed between `f770d664` and `origin/main`; none adds a reader of a `tool` record (the one new `tools` reader is #32880's, under red line 1). - **(b) Caller references (D3).** `agent.tools` was removed in spec 17; a skill's `tools[]` is resolved by the cloud runtime, and in this repo only matched against the MCP connection's served tool names (#32880). The "Used by" panel (`findReferencesToMeta`) matches by bare name: over-inclusive, never a missed reference. - **(c) Stored references.** D8 has no `tool` row; S4's report holds 0 `tool` rows. First-party tool records in `examples/`: 0. - **(d) Built-in names.** `PLATFORM_REQUESTED_BARE_NAMES_BY_TYPE` holds `permission` and `email_template` only: tool census **0**. ## Carried to repo:cloud Once tool records stop being inert, or any cloud change first reads a package `tool` record: that reader **must** resolve a name from the referring item's own package (its own record, else the unique holder in its declared dependency closure, ADR-0150 D3), **must** refuse a name two packages hold, naming every candidate, and must never take the first one registered, never reach a tool outside that closure, and never reach a tool only the environment holds. The same obligation is in `packages/spec/liveness/tool.json`. Also carried: the cloud reading 6837767385 lists three cloud calls on the metadata service for type `tool` by bare name with no package (a fixed-name existence probe, and AI Studio's register and retract of its built-in tool mirror). A bare removal of a name two packages hold is now refused `409`, so the mirror's retract can be refused where two namespaces each ship a tool named after a built-in; the refusal fails closed and picks no holder. ## Tests Added this round: - `packages/objectql/src/package-scoped-exact-qualifier.test.ts`: `tool` joins #32741's location-4 loop: two holders × both registration orders × four states (stored, after the read-side hydrator, bare-slot copy stamped `''`, stamped `sys_metadata`): each exact address serves its own, the layered read reports `overlay: null`, the first holder's slot keeps its own; and one holder, before and after the hydrator. - `packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts`: `[#31985] a package-less tool row saved before two namespaces' packages install the name…`: booted showcase, `PUT /meta/tool/NAME` for two names, then install-local of `kappa` (first name), `lambda` (both) and `iota` (second name), so one name is installed in id order and the other in reverse; each exact address, plain and `/layers?package=`, serves its own with `overlay: null`, before and after `GET /meta/tool` (the read-side hydrator); the bare read refuses `409` naming both. The artifact-door `/layers?package=` pin's title and the file header no longer claim a tool was served the last-registered package before (delta D3). Ablation (sealed-type rule, ruling 3), through `scripts/ablation-replace.mjs`: `ProtocolWriteGatesFacet.isSealedManagedItem` (`packages/metadata-protocol/src/protocol-write-gates.ts`) made to answer `false` for `tool` (anchor 1 → 0, blob `b9477b0c` → `d8e19aaf`), metadata-protocol rebuilt, `ablation-dist-preflight` marker present in 2 built files: - `objectql vitest run src/package-scoped-exact-qualifier.test.ts -t tool` → **9 failed**, 3 passed (every new `tool` location-4 case: 8 two-holder cells and the one-holder case). - dogfood `test/bare-name-one-holder-ai-family.dogfood.test.ts` → **1 failed** (the new pin: `expected 409 to be 200` at an exact address), 26 passed. - Restored: blob after restore `b9477b0c` == HEAD, `git diff HEAD` empty, rebuilt, `--absent` preflight: marker absent from all 24 built files, tree clean. The earlier ablations of the two set memberships (predicate: 9 red; store: 1 + 7 red; store under the HTTP layered doors: green, row 12) ran on `cb6zil` and are not repeated: the merge changed neither set's `tool` entry, and the epic read re-ran them (its table). ## Acceptance notes - `NAMESPACE_UNIQUE_TYPES` (child N) still lists `tool`, so a tool's same-namespace co-owner is refused by N's sentence; the tool matrix's rival is a package with no namespace. - **The package-less row beside a package tool (was "not measured here").** Measured at this head: a package-less tool row saved before two namespaces' packages install the name is declined at each holder's exact address, plain and layered (`overlay: null`), before and after the read-side hydrator, in both install orders, and the bare read refuses `409` naming both (the new dogfood pin; the unit pin adds the bare-slot copies). Where AI Studio mounts, its built-in mirror holds such rows (cloud reading 6837767385): a package tool of one of those names is refused at install beside it (the no-namespace pairing, unchanged); two namespaces' tools of such a name would be read as above. - **Carried, by order (red line 2).** (i) The boot hydration: since #32741 it grafts no package-less tool row onto a holder's slot; two stored rows each naming a holder of one name still leave only the last loaded (measured by the epic read on its scratch merge; the second case #32692 names for a webhook; the widening is #33127, ruling 5). (ii) The protocol's in-process layered read with a bare name and no service copy answers the first-registered holder (#32914); both HTTP transports refuse it `409` first. - The fixture's sealed clash rides on `connector`, the last covered type not narrowed. - The platform-provided tool names are not built-ins here; a later change that makes package tool records reach the AI service's registry owns that clash. ## Verification Head `6b16ccaa9` (one text-and-test-loop commit on `49c97977f`: changeset names #33127, review#1 n1/n2; objectql exact-qualifier 243 passed, ablation re-run red then restored, changeset and ADR-0087 gates exit 0; the full runs below are at `49c97977f`) (`origin/main` `2c98485db` merged once in `c84542096`, never a rebase; merged again only on a conflict, a main-caused red, a queue kick, or K ≥ 15 before queuing). The dogfood closure was built first (`pnpm --filter '@objectstack/dogfood^...' build`, lock VERDICT command-exit 0), and `@objectstack/spec` rebuilt after the semantic entry. <details><summary>Package runs</summary> - `@objectstack/objectql` `vitest run src/package-scoped-exact-qualifier.test.ts src/registry-bare-name-one-holder-ai-family.test.ts src/package-scoped-e8-readers.test.ts`: Test Files 3 passed (3), Tests 479 passed (479); `-t tool` on the first file: 12 passed, 228 skipped. - `@objectstack/metadata` `vitest run src/metadata-manager-keyed-plural-read.test.ts src/metadata-manager-match-endpoint.test.ts`: Test Files 2 passed (2), Tests 717 passed (717). - `@objectstack/core` `vitest run src/package-scoped-resolution.test.ts`: Tests 32 passed (32). - `@objectstack/cli` `--project integration src/commands/migrate/stored-references.integration.test.ts`: Tests 12 passed (12). - `@objectstack/dogfood` `test/bare-name-one-holder-ai-family.dogfood.test.ts`: Tests 27 passed (27). - typecheck `@objectstack/core`, `@objectstack/metadata`, `@objectstack/objectql`: 0 errors (test-typecheck ledgers held). </details> <details><summary>Derived gates, lint, dogfood battery</summary> - `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --commands` at `49c97977f` derived 102; each run with its exit captured before any pipe. `check:dual-build-cjs-loads` first exited 3 (PREREQUISITE NOT MET: packages with no `dist/` while the closure build was still landing); re-run, exit 0. `--ran`: **102 derived famil(ies) accounted for — 102 run, 0 NOT-MEASURED**, every recorded exit 0. - `pnpm lint`: exit 0. - Full dogfood battery (`pnpm --filter @objectstack/dogfood test` under `os-verify-lock`, `NODE_OPTIONS=--max-old-space-size=8192`) at `49c97977f`: Test Files 460 passed, 3 skipped (463); Tests 3881 passed, 42 skipped (3923); lock VERDICT command-exit 0. - Change set: 14 files, +421 / -131 against `origin/main`, under the 3000-line human-merge threshold. </details> Not run locally, declared to CI: `test:repo`, the full objectql / metadata / core suites, and the CI-only families outside the derived list. --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4d1T8WbNLuRhvuhMHBF)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4d1T8WbNLuRhvuhMHBF <!-- signed: epic:#31527#2 · os-elon-musk · session_016WV4czFhtRVZNBeHdQA6PW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f054a0b commit c747cf0

14 files changed

Lines changed: 424 additions & 133 deletions
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
'@objectstack/objectql': minor
3+
'@objectstack/core': minor
4+
'@objectstack/metadata': minor
5+
---
6+
7+
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)
8+
9+
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.
10+
Metadata-protocol: added
11+
12+
<!-- adr-0087: registered tool-names-per-namespace -->
13+
14+
**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:
15+
16+
- FROM `get('tool', NAME)` of a two-holder name TO `get('tool', NAME, PKG)`, a package the refusal names.
17+
- 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).
18+
- FROM `unregister('tool', NAME)` of a two-holder name TO `unregister('tool', NAME, { packageId })`, or `unregisterPackage(PKG)`.
19+
- 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.
20+
- FROM `getHistory('tool', NAME)` / `diff('tool', NAME, …)` of a name two packages saved TO the same call with `{ packageId }`, once per package.
21+
22+
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.
23+
24+
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:
25+
26+
- 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.
27+
- `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).
28+
- 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`.
29+
- 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.
30+
31+
Also moved, by the same rules `package-slotted-store.ts` and the replica lane already apply to every type in `PACKAGE_SLOTTED_STORE_TYPES`:
32+
33+
- 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).
34+
- 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).
35+
- 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.
36+
37+
Not moved by this change, and carried (both already reach every narrowed type):
38+
39+
- 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).
40+
- 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.
41+
42+
Unchanged, and still refused with the same `422 NAMESPACE_CONFLICT` envelope and sentence:
43+
44+
- 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;
45+
- a package that declares no namespace, beside any other holder of the name (a disabled one included), and any holder beside it;
46+
- two packages of one shareable namespace (`base`, `system`, `sys`) holding the name;
47+
- a built-in name (none for a tool: the platform requests no tool record by name).
48+
49+
Every covered type not yet narrowed (connector) keeps one package holder per deployment.
50+
51+
`os migrate stored-references` no longer lists two namespaces' holders of one tool name among the sealed clashes: they are not a clash.
52+
53+
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.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
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)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
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.

‎packages/cli/src/commands/migrate/stored-references.integration.test.ts‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
* - C (`m31693c`) declares the picklist `m31693_hue`, which A does not depend on.
1818
*
1919
* A and B also each declare the agent `m31693_helper`, the skill
20-
* `m31693_triage`, the object-less action `m31693_digest` and the email
21-
* template `m31693_notice`: two namespaces' holders of one agent, one skill,
22-
* one object-less action and one email template name, which the one-holder
23-
* rule no longer calls a clash (#31701, #31697, #31699; ADR-0150 D2/D9), so
24-
* the sealed-clash section never lists them; nor the picklist `m31693_tone`
25-
* they both declare (#31700). The clash the seal still records is the tool
26-
* `m31693_lookup` both declare: a tool name is held once per deployment.
20+
* `m31693_triage`, the object-less action `m31693_digest`, the email
21+
* template `m31693_notice` and the tool `m31693_lookup`: two namespaces'
22+
* holders of one agent, one skill, one object-less action, one email template
23+
* and one tool name, which the one-holder rule no longer calls a clash
24+
* (#31701, #31697, #31699, #31985; ADR-0150 D2/D9), so the sealed-clash
25+
* section never lists them; nor the picklist `m31693_tone` they both declare
26+
* (#31700). The clash the seal still records is the connector `m31693_link`
27+
* both declare: a connector name is held once per deployment.
2728
*
2829
* Over a database an older release left: two managed `sys_sharing_rule` rows
2930
* naming `m31693_share` (two holders: ambiguous) and `m31693_only_a` (one
@@ -94,11 +95,9 @@ const rule = (name: string) => ({
9495
accessLevel: 'read', sharedWith: { type: 'user', value: 'u1' }, active: true,
9596
});
9697
const list = (name: string) => ({ name, label: name, options: [{ label: 'One', value: 'one' }] });
97-
/**
98-
* The agent, the skill (#31701), the object-less action (#31697) and the email
99-
* template (#31699) A and B both declare, in their own namespaces; and the
100-
* tool, whose name is still held once per deployment: the sealed clash.
101-
*/
98+
/** The connector A and B both declare: a connector name is still held once per deployment, the sealed clash. */
99+
const link = (tag: string) => ({ name: 'm31693_link', label: `${tag} link`, type: 'api', description: `${tag} link`, enabled: false });
100+
/** 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. */
102101
const ai = (tag: string) => ({
103102
agents: [{ name: 'm31693_helper', label: `${tag} helper`, role: `${tag} role`, instructions: `${tag} helper instructions` }],
104103
skills: [{ name: 'm31693_triage', label: `${tag} triage`, description: `${tag} triage`, instructions: `${tag} triage instructions`, tools: [] }],
@@ -118,6 +117,7 @@ const pkgA = {
118117
}],
119118
sharingRules: [rule('m31693_share'), rule('m31693_only_a')],
120119
picklists: [list('m31693_tone')],
120+
connectors: [link('a')],
121121
...ai('a'),
122122
},
123123
};
@@ -126,6 +126,7 @@ const pkgB = {
126126
id: B, name: 'm31693b', version: '1.0.0', type: 'app', namespace: 'm31693b', dependencies: { [A]: '^1.0.0' },
127127
sharingRules: [rule('m31693_share')],
128128
picklists: [list('m31693_tone')],
129+
connectors: [link('b')],
129130
...ai('b'),
130131
},
131132
};
@@ -306,10 +307,10 @@ describe('os migrate stored-references (the report)', () => {
306307
d8: 'R17', object: 'm31693a_task', field: 'hue', packageId: A, name: 'm31693_hue', reason: 'outside-closure',
307308
candidates: [{ holder: 'package', packageId: C, address: 'm31693c/m31693_hue' }],
308309
}]);
309-
// [#31701, #31697, #31699, #31700] Only the tool: never the agent, the
310-
// skill, the object-less action, the email template and the picklist A
311-
// and B hold in two namespaces.
312-
expect(payload.sealedClashes).toEqual([{ type: 'tool', name: 'm31693_lookup', candidates: [`package "${A}"`, `package "${B}"`] }]);
310+
// [#31701, #31697, #31699, #31700, #31985] Only the connector: never the
311+
// agent, the skill, the object-less action, the email template, the
312+
// picklist and the tool A and B hold in two namespaces.
313+
expect(payload.sealedClashes).toEqual([{ type: 'connector', name: 'm31693_link', candidates: [`package "${A}"`, `package "${B}"`] }]);
313314
// The served platform carries no automation or approvals table here: named, not silently skipped.
314315
expect(payload.tablesNotCarried).toEqual(expect.arrayContaining(['sys_automation_run', 'sys_flow_credential', 'sys_approval_request']));
315316
}, CASE_TIMEOUT_MS);

‎packages/core/src/package-scoped-resolution.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export function isBareNameOneHolderType(type: unknown): type is BareNameOneHolde
137137
* `(package, name)`, and its doors, flow actions and flow endpoints resolve a
138138
* name by package), then the picklist family (#31700): `picklist`,
139139
* `mapping` and `dataset`, the `api` and the engine's `function` registry,
140-
* then `webhook` (#31699 PR 2). A type not listed here keeps one package
141-
* holder per deployment.
140+
* then `webhook` (#31699 PR 2), and `tool` beside the AI family (#31985),
141+
* whose one by-name reader (`/meta/tool/NAME`) resolves by package. A type
142+
* not listed here keeps one package holder per deployment.
142143
*
143144
* Every member but {@link ENGINE_FUNCTION_TYPE} is a metadata type ADR-0150
144145
* addresses by package ({@link PACKAGE_SCOPED_TYPES}). The function registry
@@ -155,6 +156,8 @@ export function isBareNameOneHolderType(type: unknown): type is BareNameOneHolde
155156
export const NAMESPACE_SCOPED_BARE_NAME_TYPES: readonly BareNameOneHolderType[] = Object.freeze([
156157
'agent',
157158
'skill',
159+
// the AI family's third type, in its own change (#31985)
160+
'tool',
158161
'action',
159162
'email_template',
160163
'flow',

‎packages/metadata/src/metadata-manager-keyed-plural-read.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ describe('#14423 item 2 — `MetadataManager.loadManyKeyed`: the plural read und
401401
describe('[#32517] the unscoped plural reads answer every package\'s item of an unbundled by-package type', () => {
402402
const A = 'com.acme.alpha';
403403
const B = 'com.acme.beta';
404-
// [#31699 PR 2] `webhook` joins the slotted set, and so these plural reads.
405-
const UNBUNDLED = ['api', 'agent', 'skill', 'action', 'flow', 'permission', 'picklist', 'mapping', 'dataset', 'webhook'];
404+
// [#31699 PR 2] `webhook` joins the slotted set, and so these plural reads;
405+
// [#31985] `tool` joins with its narrowing.
406+
const UNBUNDLED = ['api', 'agent', 'skill', 'action', 'flow', 'permission', 'picklist', 'mapping', 'dataset', 'webhook', 'tool'];
406407
const NAME = 'shared_item';
407408
const item = (packageId: string | undefined, extra: Record<string, unknown> = {}) => ({
408409
name: NAME,

‎packages/metadata/src/metadata-manager-match-endpoint.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ describe('the in-memory api store keeps one slot per (package, name) (ADR-0150 D
465465
* `(package, name)` for every type whose one-holder rule has narrowed to the
466466
* namespace — `agent` and `skill` (objectql's
467467
* `NAMESPACE_SCOPED_BARE_NAME_TYPES`, #31701; objectql pins that set a subset
468-
* of `PACKAGE_SLOTTED_STORE_TYPES`), `flow` (#31696), and [#31700] the
469-
* picklist family's `picklist`, `mapping` and `dataset` (`api` has its own
470-
* describe above, the object-less `action` its own file). Two packages of two namespaces may each
468+
* of `PACKAGE_SLOTTED_STORE_TYPES`), `flow` (#31696), [#31700] the
469+
* picklist family's `picklist`, `mapping` and `dataset`, and `tool` (#31985)
470+
* (`api` has its own describe above, the object-less `action` its own file). Two packages of two namespaces may each
471471
* install such a name, and the artifact door registers every package body's
472472
* items here through `register(…, { notify: false })`, stamped by
473473
* `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
476476
* answered the survivor.
477477
*/
478478
describe('the in-memory store keeps one slot per (package, name) for every namespace-scoped type (ADR-0150 D4, #32151)', () => {
479-
const NAMESPACE_SCOPED = ['agent', 'skill', 'flow', 'picklist', 'mapping', 'dataset'] as const;
479+
const NAMESPACE_SCOPED = ['agent', 'skill', 'flow', 'picklist', 'mapping', 'dataset', 'tool'] as const;
480480
const A = 'com.acme.alpha';
481481
const B = 'com.acme.beta';
482482
const shipped = (type: string, packageId: string, tag: string, envelope = false) => ({

0 commit comments

Comments
 (0)