Repository navigation
feat(metadata): listPackageBindings reads an item's package from its stored row's package column - #37187
Conversation
Claude-Session: https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs Co-authored-by: Claude <noreply@anthropic.com>
…stored row's column Regenerates the spec contracts api-surface and export-origins snapshots for the new MetadataPackageBinding export, and adds the changeset. Claude-Session: https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 38 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 17 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 179 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 179a77ca83fbe5d1f45bdf31186af1f989a8f9c5 && git checkout 179a77ca83fbe5d1f45bdf31186af1f989a8f9c5
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9ffe37153c59b0b3a64c629b9fc7d4e16e144840 783d58770850e6357437832279c56aebce407de1 && git checkout -B drift-repro 9ffe37153c59b0b3a64c629b9fc7d4e16e144840 && git merge --no-ff 783d58770850e6357437832279c56aebce407de1
node scripts/docs-audit/affected-docs.mjs --json 9ffe37153c59b0b3a64c629b9fc7d4e16e144840
|
Claude-Session: https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs Co-authored-by: Claude <noreply@anthropic.com>
The text merge dropped main's knowledge-adapter rows; regenerated from source. Claude-Session: https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs Co-authored-by: Claude <noreply@anthropic.com>
|
repo:cloud#1 · os-warren · session_01JQwxbXcTgn3UMemcSRTDMs Contract-review-claim: session_01JQwxbXcTgn3UMemcSRTDMs · head 583ad09 · 2026-11-26T01:02Z |
|
repo:cloud#1 · os-warren · session_01JQwxbXcTgn3UMemcSRTDMs Contract reviewServed-tier: PR #37187 for card #37039. Read: the card body and its five comments (triage first touch 7137854671, claim round 1 7150624417, os-dev-report 7151625614, triage knock 7158504687, claim round 2 7179153240; no ruling and no earlier contract-review record among them), the PR body, the ten-file list, the net diff Outside this record, the lane seat's ACCEPT at Check-runs on the head as read at 2026-11-26T01:12Z (pushed about 01:00Z): 67 runs, 26 success, 10 skipped, 31 in progress, 0 failed. Completed green: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Implementing files, against the contract sentence by sentence. S1 (should-fix) — S2 (should-fix) — N1 (nit) — the contract says a row loader that could not be read "leaves items it holds answering N2 (nit) — a N3 (nit) — when both walks lose the same loader, N4 (nit) — N5 (nit) — "and nowhere else" (metadata-service.ts:445) reads broader than the member's own second arm, which binds an item with no row by its registration. The nits may ride the head that closes S1 and S2, or stand as accepted deviations. None changes a verdict. Break attempts that held.
Nothing here is graded above should-fix. S1 and S2 are open on this head and each owes a delta review of its fix. Implemented-by: Independence pair: the review was rendered by an isolated sub-agent served at VERDICT: PASS |
…bound; primitive-body rows no longer fail the read - bindReadRowPackage records the package it writes into the column against the handed-out body, so the primed copy answers the bound package with source 'row' (the cached rows are already invalidated by the update). - A row whose stored body is a JSON primitive is skipped when recording its column, so the type's plural read serves the other rows instead of throwing. - listPackageBindings reads the keyed column without a non-null assertion. - IMetadataService.listPackageBindings jsdoc: a degraded row loader's primed copies still answer 'row'; "nowhere else" narrowed to the body stamp. Claude-Session: https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs Co-authored-by: Claude <noreply@anthropic.com>
…answers the bound package Claude-Session: https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs Co-authored-by: Claude <noreply@anthropic.com>
|
repo:cloud#1 · os-warren · session_01JQwxbXcTgn3UMemcSRTDMs Contract reviewServed-tier: Delta review of PR #37187 for card #37039, by the reviewer of the round-1 record on head S1: closed No must-fix, no should-fix. Outside this record, the lane seat's ACCEPT at Check-runs on the head as read at 2026-11-26T01:25Z (CI had just started): 37 runs so far, 12 success, 9 skipped, 16 in progress, 0 failed. Completed green: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentS1, closed. S2, closed. Every write to
Did the delta introduce anything new? One residual, graded a nit.
N2 and N3 stand as round 1 left them: accepted deviations, N2 a follow-up card candidate. Break attempts on the delta that held.
Nits alone remain. They end the round: N6 and N7 are left as accepted deviations or follow-up cards, since a fix to either moves the head. Implemented-by: Independence pair: the review was rendered by an isolated sub-agent served at VERDICT: PASS |
|
repo:cloud#1 · os-warren · session_01JQwxbXcTgn3UMemcSRTDMs 席位核对ACCEPT · head Checklist (
Accepted deviations / follow-ups (carrier: the area:cloud zone, not filed here): Local deviation: local derived-gate run at 583ad09 was stopped at 82/114 when the fix round started; its non-zero exits were prerequisite gaps (exit 3) or stale local |
|
repo:cloud#1 · os-warren · session_01JQwxbXcTgn3UMemcSRTDMs Landing #37187 at head
State: ACCEPT 7180250767 + |
…ope, by the records a source indexes or by a parent through a listed lookup (objectstack-ai#37342) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8GWXHtfAHuZXmmZpkARr4Wi)_ Fixes objectstack-ai#37308 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:知识检索可以限定范围了:只在指定的几条记录里找,或者只在一份上级记录(比如一份制度)下面的条款里找,返回的前几条结果都来自范围内。 - 为什么做:属于「知识检索平台化」专题第三阶段,按您定的「也能指定上级对象(制度)」实现;之后给 AI 用的检索工具也会接上这个参数。 - 出错会怎样:范围只会缩小结果,不会放宽权限,每条结果仍按提问人的权限重新读取;最坏是限定范围后漏掉结果。没有数据迁移,撤回即可。 - 要你做什么:无需你操作。您已在卡片上同意的安全登记行已在(`d1ca7f01`)。开源向量库那个改动先合并了,本分支已合入主干,并让向量库也按范围过滤(在数据库里先筛再排序);由座位做差量复核后重新排队合并。「按记录返回」已合并并合入本分支;与开源向量库那个改动仍有文字冲突,后合并的一方处理。 ## What changes ADR-0161 K8 item 17, in the shape its dated note of 2026-11-25 (objectstack-ai#37324, merged as `13ffe1c0`) gives it, built in one PR as the note says: the member, its first reader in `knowledge-memory`, and the suite cases. **`@objectstack/spec`** (types only, no metadata key): - `KnowledgeSearchOptions.scope?: Array<{ object: string; ids: string[] }>` (`packages/spec/src/contracts/knowledge-service.ts`): an option of the service, not a contract member. Its TSDoc states the own-object and parent readings, union, absent/empty, and the bounds with the coded refusal. - `AdapterSearchOptions.scope?: AdapterScopeTerm[]` and the exported type `AdapterScopeTerm` (`packages/spec/src/contracts/knowledge-adapter.ts`): `{ kind: 'record', ids }` or `{ kind: 'metadata', field, ids }`. Its TSDoc states absent/present/empty, the AND with `organizationIds` and `filter`, the bounds an adapter can rely on (at most 10 terms, at most 500 ids each, every id a non-empty string), and that the service checks every hit after the answer, so an adapter returns the document's `metadata` on its hits. - Regenerated: `api-surface/contracts.json`, `export-origins/contracts.json` (the new export). **`@objectstack/service-knowledge`**: - New `src/knowledge-search-scope.ts`: - `readSearchScope`: the bounds, `SEARCH_SCOPE_MAX_ENTRIES = 10`, `SEARCH_SCOPE_MAX_IDS = 500`. Past them it throws `code: 'VALIDATION_ERROR'`, `status: 400` (ADR-0112), naming the bound, before anything else in `search` runs. - `scopeTermsFor`: an entry naming the source's object gives a `record` term. An entry naming another object gives a `metadata` term on the one `metadataFields` member that is a `lookup` or `master_detail` field whose `referenceTargetOf` is that object, read from the registered definition. A `user` field, a withheld (credential-class or `internal`) field, a field whose target cannot be read, two or more such fields, no definition, and a `file` / `http` source all give nothing. - `scopeCheck`: the hit check. It judges `sourceRecordId` or `metadata[field]`, compares strings and numbers by `String(v)`, and matches a list when any element matches. Anything else, or no value, fails closed. - `KnowledgeService.search`: - Validates first. - `sourcesInScope` pairs each admitted source with its terms. A source no entry reaches is not searched (debug). The two-lookup ambiguity is logged once per source and object at `warn`, naming the fields. - `searchRound` hands each adapter a copy of its terms and checks every hit after the answer. The first drop for an adapter is logged once at `warn`. - `answered` stays the adapter's own count. - `src/testing.ts` (the contract suite): - New required `implements.scope`. - Adapter-alone cases, run when `implements.scope` is true: a record term filters before ranking (topK 1); a metadata term with a list value returns the document's metadata; the number 7 matches `'7'`; terms are a union; an empty list or a term with no ids ranks nothing; without the member everything is ranked; with `organizationIds`, both apply. - Cases through a real `KnowledgeService` for every adapter: an own-object scope fills topK from in-scope passages; a parent scope works through the listed lookup; an adapter with the member stripped answers no out-of-scope hit, and the service logs once. - `serviceOver` gains `schemas`, `stripScope` and `logger`. **`@objectstack/knowledge-memory`**: applies `scope` after the organization filter and before scoring. It declares `implements.scope: true`. **`@objectstack/knowledge-pgvector`** (landed first, objectstack-ai#37337): applies `scope` in the same inner `WHERE` as the organization filter, before `ORDER BY` / `LIMIT`. A `record` term is `source_record_id = ANY($n::text[])`; a `metadata` term holds when the stored jsonb value of its field is a string or number equal to an id as text, or a list with such an element. Ids and field names are bound parameters only. A scope with no term that has ids answers `[]` before any query. Its live contract run declares `implements.scope: true`. **Docs**: - `content/docs/protocol/knowledge.mdx`: a new "Record scope" section in §5, a pointer in §3.4, the suite sample, and §4.1 / the adapter table naming pgvector's record scope. - `content/docs/ai/knowledge-rag.mdx`: a new "Searching inside chosen records" section. **Changeset**: patch for the four packages, with `Clause-②: yes` and `Metadata-protocol: none`. The change adds no metadata key, and a non-protocol widening ships patch. ## Tests - New `src/__tests__/knowledge-search-scope.test.ts`: bounds (each refusal, and the exact-bound acceptance), term building (each reading of the note), and the hit check. - `src/__tests__/knowledge-service.test.ts`, new describe "search scope (ADR-0161 K8, item 17)": - the card's acceptance: 20 records, two in scope, topK 5, a full page; - an ignoring adapter: no out-of-scope hit, one log; - an unreached object: no adapter asked, empty answer; - an unreadable scoped record yields no hit; - the bounds refuse before any adapter or engine call; - empty scope and empty ids answer nothing; - the two-lookup case logs once; - a numeric lookup value matches its string id; - a parent scope makes no engine call naming the parent object, and an adapter that widens the terms it was handed (more ids, an extra term) still has every out-of-scope hit dropped; every round is handed the service's own terms (review round 1); - a scope with `groupBy`, and one with `granularity: 'record'`, over an adapter that ignores the scope: every round is handed the record term and no out-of-scope record answers (review round 2). - The contract suite runs on `knowledge-memory` and both stubs. - Mutation checks, run locally and reverted: - `knowledge-memory` with its scope filter removed: 7 suite cases fail. - `KnowledgeService` without the after-answer check: 7 cases fail across the stubs and the service tests. - Handing the adapter the live terms, or reading the parent object's definition: the round-1 case fails. - Skipping the scope under `groupBy`, skipping it under record granularity, or the `groupBy` source filter rebuilding its entries without the terms: the round-2 case fails. **Local runs at `760716bc`** (after merging `main` at `98bda0ac`, which brought objectstack-ai#37337): - `pnpm --filter @objectstack/spec build` and `check:generated`: exit 0, after the merge's deferred regeneration of `api-surface/contracts.json` and `export-origins/contracts.json` (`4552e7c4`). - `pnpm --filter @objectstack/service-knowledge typecheck` and `check:test-typecheck`: exit 0. `test`: 13 files, 365 tests passed. - `pnpm --filter @objectstack/knowledge-memory typecheck` and `check:test-typecheck`: exit 0. `test`: 2 files, 56 tests passed. - `pnpm --filter @objectstack/knowledge-pgvector typecheck`: exit 0. `test` against a local PostgreSQL 16 with pgvector, `OS_TEST_POSTGRES_URL` set and `OS_EXPECT_LIVE_DIALECT_MATRIX=1`: 4 files, 67 tests passed, every scope case of the suite among them (record term, metadata term with a list, the number 7, union, empty, absent, with `organizationIds`; through the service: own object, the parent through the listed lookup, the member stripped). With the SQL scope filter removed: 7 of them fail. - `pnpm --filter @objectstack/core test:repo` (the census pin, at `d1ca7f01`): 8 files, 110 tests passed. - **Derived gates at `760716bc`.** `dispatch-gates --commands` derives 119 commands from the 19 changed paths (the 118 before, plus `pnpm check:kernel-hook-pairs`). Each was run at this head with its output in its own file and its exit code read before any pipe. `check:dual-build-cjs-loads` first answered 3 (prerequisite not met: the new `knowledge-pgvector` had no `dist/`); after `pnpm --filter @objectstack/knowledge-pgvector build` it was run again, and the record holds that run. ```text Run reconciliation — 119 derived, 119 run, 0 NOT-MEASURED, 0 UNRUN. ✓ dispatch-gates --ran: 119 derived famil(ies) accounted for — 119 run, 0 NOT-MEASURED (a DERIVED zero — all 119 recorded an exit code and none of them is 3). ``` <details><summary>The 119 commands at <code>760716bc</code></summary> | Command | Exit | |:--|:--| | `node scripts/check-adr-0087-registration.mjs --base origin/main` | 0 | | `node scripts/check-adr-0087-registration.mjs --self-test` | 0 | | `node scripts/check-adr-links.mjs` | 0 | | `node scripts/check-adr-links.mjs --self-test` | 0 | | `node scripts/check-changeset-no-major.mjs --base origin/main` | 0 | | `node scripts/check-closing-keyword-parity.mjs` | 0 | | `node scripts/check-closing-keyword-parity.mjs --self-test` | 0 | | `node scripts/check-comment-mask-adoption.mjs` | 0 | | `node scripts/check-comment-mask-adoption.mjs --self-test` | 0 | | `node scripts/check-comment-mask-corpus.mjs` | 0 | | `node scripts/check-dev-prereqs.mjs --self-test` | 0 | | `node scripts/check-doc-route-spelling.mjs --advisory` | 0 | | `node scripts/check-doc-route-spelling.mjs --self-test` | 0 | | `node scripts/check-docs-section-name.mjs` | 0 | | `node scripts/check-docs-section-name.mjs --self-test` | 0 | | `node scripts/check-dts-emitted.mjs --self-test` | 0 | | `node scripts/check-empty-changeset.mjs --base origin/main` | 0 | | `node scripts/check-empty-changeset.mjs --self-test` | 0 | | `node scripts/check-issue-citations.mjs` | 0 | | `node scripts/check-plugin-teardown-shape.mjs` | 0 | | `node scripts/check-plugin-teardown-shape.mjs --self-test` | 0 | | `node scripts/check-section-landing-index.mjs` | 0 | | `node scripts/check-section-landing-index.mjs --self-test` | 0 | | `node scripts/check-tenant-audit-census.mjs` | 0 | | `node scripts/check-tenant-audit-census.mjs --self-test` | 0 | | `node scripts/ci/assert-turbo-remote-cache.mjs --self-test` | 0 | | `node scripts/ci/plan-test-core-shards.mjs --self-test` | 0 | | `node scripts/ci/prune-turbo-cache.mjs --self-test` | 0 | | `node scripts/ci/snapshot-next.mjs --self-test` | 0 | | `node scripts/docs-audit/check-affected-docs.mjs` | 0 | | `node scripts/docs-audit/check-drift-comment.mjs` | 0 | | `node scripts/pm/check-governed-queue-guard.mjs --self-test` | 0 | | `node scripts/pm/release-rehearsal-clone.mjs --self-test` | 0 | | `node scripts/release-pending-publish.mjs --self-test` | 0 | | `pnpm --filter @objectstack/lint run check:doc-formula-expressions` | 0 | | `pnpm --filter @objectstack/lint run check:doc-security-posture` | 0 | | `pnpm --filter @objectstack/spec run check:api-surface` | 0 | | `pnpm --filter @objectstack/spec run check:authorable-surface` | 0 | | `pnpm --filter @objectstack/spec run check:browser-reachable-entries` | 0 | | `pnpm --filter @objectstack/spec run check:docs` | 0 | | `pnpm --filter @objectstack/spec run check:dual-source-exports` | 0 | | `pnpm --filter @objectstack/spec run check:duration-unit-keys` | 0 | | `pnpm --filter @objectstack/spec run check:empty-state` | 0 | | `pnpm --filter @objectstack/spec run check:entry-nameability` | 0 | | `pnpm --filter @objectstack/spec run check:error-code-provenance` | 0 | | `pnpm --filter @objectstack/spec run check:export-origins` | 0 | | `pnpm --filter @objectstack/spec run check:exported-any` | 0 | | `pnpm --filter @objectstack/spec run check:generated` | 0 | | `pnpm --filter @objectstack/spec run check:liveness` | 0 | | `pnpm --filter @objectstack/spec run check:llms-txt` | 0 | | `pnpm --filter @objectstack/spec run check:skill-examples` | 0 | | `pnpm --filter @objectstack/spec run check:skill-refs` | 0 | | `pnpm --filter @objectstack/spec run check:strictness-ledger` | 0 | | `pnpm --filter @objectstack/spec run check:variant-docs` | 0 | | `pnpm --filter @objectstack/spec run check:yaml-examples` | 0 | | `pnpm check:adr-anchors` | 0 | | `pnpm check:adr-symbol-anchors` | 0 | | `pnpm check:changeset-gate-self-tests` | 0 | | `pnpm check:ci-filter-parity` | 0 | | `pnpm check:closed-ceremony-text` | 0 | | `pnpm check:corpus-claim-drift` | 0 | | `pnpm check:cross-package-test-inputs` | 0 | | `pnpm check:dispatcher-error-vocabulary` | 0 | | `pnpm check:doc-anchors` | 0 | | `pnpm check:doc-authoring` | 0 | | `pnpm check:doc-frontmatter` | 0 | | `pnpm check:docs-audit-scope` | 0 | | `pnpm check:docs-redirects` | 0 | | `pnpm check:docs-single-h1` | 0 | | `pnpm check:docs-spec-enumerations` | 0 | | `pnpm check:docs-transcript-drift` | 0 | | `pnpm check:driver-memory-census` | 0 | | `pnpm check:dts-closure` | 0 | | `pnpm check:engine-double-contract` | 0 | | `pnpm check:error-status-conformance` | 0 | | `pnpm check:gitlink-declared` | 0 | | `pnpm check:init-service-contract` | 0 | | `pnpm check:issue-citations` | 0 | | `pnpm check:kernel-hook-pairs` | 0 | | `pnpm check:keyed-text-bounds` | 0 | | `pnpm check:lean-entry-closure` | 0 | | `pnpm check:logger-receiver-detach` | 0 | | `pnpm check:merge-driver` | 0 | | `pnpm check:nul-bytes` | 0 | | `pnpm check:object-def-param-keys` | 0 | | `pnpm check:objectql-double-limit` | 0 | | `pnpm check:optional-error-sink` | 0 | | `pnpm check:org-identifier` | 0 | | `pnpm check:package-naming` | 0 | | `pnpm check:page-declaration-shape` | 0 | | `pnpm check:platform-object-tenancy-census` | 0 | | `pnpm check:pm-expected-skips` | 0 | | `pnpm check:pm-prior-rulings` | 0 | | `pnpm check:published-files` | 0 | | `pnpm check:published-readme-links` | 0 | | `pnpm check:query-options-erasure` | 0 | | `pnpm check:react-page-adapter-contract` | 0 | | `pnpm check:refd-timer-probe` | 0 | | `pnpm check:registry-log-declared` | 0 | | `pnpm check:rest-log-spy-declared` | 0 | | `pnpm check:role-word` | 0 | | `pnpm check:settings-bind-window` | 0 | | `pnpm check:skill-identifier-liveness` | 0 | | `pnpm check:slot-lookup` | 0 | | `pnpm check:sourcemap-no-sources-content` | 0 | | `pnpm check:spec-docblock-symbol-anchors` | 0 | | `pnpm check:spec-parsed-alias` | 0 | | `pnpm check:startup-registry-verdict` | 0 | | `pnpm check:system-context-census` | 0 | | `pnpm check:test-source-alias` | 0 | | `pnpm check:tier-file-adoption` | 0 | | `pnpm check:type-check-coverage` | 0 | | `pnpm check:type-check-debt` | 0 | | `pnpm check:undeclared-dep-imports` | 0 | | `pnpm check:vendor-version-stamps` | 0 | | `pnpm check:vouch-for-reference-callers` | 0 | | `pnpm check:watch-hint-literal` | 0 | | `pnpm check:where-matcher` | 0 | | `pnpm check:dual-build-cjs-loads` | 0 | </details> Earlier heads ran the 118 then derived, all exit 0: `857a2e20` (after three prerequisites were met) and `ca5a0c11`. ## Acceptance notes **The five points carried from objectstack-ai#37329's contract review:** 1. **Metadata on hits.** The requirement that an adapter return the document's `metadata` is stated on `AdapterSearchOptions.scope` and on `KnowledgeHit.metadata` (`packages/spec/src/ai/knowledge-document.zod.ts`, added in the merge of `main` under the seat's claim amendment, review ruling (b)). It is pinned: the suite's metadata-term case and the parent case through the service both assert `hit.metadata.policy`. 2. **Ids compared as strings.** Pinned on `scopeCheck`, on the adapter in the suite, and through the service (a lookup stored as the number 7 matches `'7'`). Only strings and numbers compare. An object, `null` or a boolean never matches, so `'[object Object]'` cannot be matched by accident. 3. **An empty scope or an entry with no ids.** It is answered empty, never refused and never read as "no scope", and no adapter is asked. Why empty rather than refused: it reads as an empty set reads everywhere else in this contract (`organizationIds: []`). A caller that computes ids (the records on screen, a policy's children) then needs no special case for "none". The tool argument (objectstack-ai#37311) can still refuse at its own door. 4. **Bounds.** 10 entries and 500 ids per entry are stated on both TSDocs and pinned. The 500 ids of one term fit one `IN` list, and a search hands at most 5,000 ids in all. ⚑ This PR owes a ceiling-tier contract review (CONTRACT_REVIEW_TIER) for the new member. 5. **The opaque `filter`.** Finding for the seat to file: `KnowledgeSearchOptions.filter` / `AdapterSearchOptions.filter` has no producer in this tree. The one non-test caller of `IKnowledgeService.search`, `createKnowledgeTools`, passes none, and the service gives it no guarantee after the answer. This PR leaves it unchanged and builds nothing from it. Whether it retires is its own card. Carrier: none · noted, not filed. Dedupe words: knowledge opaque filter, AdapterSearchOptions filter retire, KnowledgeSearchOptions filter producer. **What the note left to this PR, decided here:** - **Refill.** `answered` stays the adapter's own count, so whether a source may hold more is still judged on what it returned. The refill after the permission filter counts records among the hits that passed both checks. - A person's search over an ignoring adapter therefore still reaches in-scope hits through the refill. - The system identity gets one round, and may answer fewer than topK (pinned). - **Log levels.** - An adapter whose hits the check drops: `warn`, once per adapter. It is a deployment defect, and rule 2 says nothing is skipped silently. - Two lookups to one parent: `warn`, once per source and object. It is an authoring defect. - A source a scope does not reach: `debug`, per search, because it is normal under a scope. - Counts appear in logs only, never in the answer. - **Entry shape.** An entry with another key (for example `field`) is refused rather than ignored. A `field` key is the note's deferred alternative, so it fails loud instead of silently reading as something else. An id that is not a non-empty string is refused: the contract types ids as strings, and a stored numeric value still matches its string id. **Surface and overlap:** - Outside the claimed file list: the two generated spec artifacts (`api-surface/contracts.json`, `export-origins/contracts.json`), required by `check:generated` for the new export. - `packages/spec/src/ai/knowledge-document.zod.ts`: one TSDoc sentence, inside the claim as the seat amended it. - `packages/core/src/security/second-object-read-exposure.pin.test.ts`: one `CALLERS` row, kind `not-a-served-read`, for `knowledge-search-scope.ts`, in its own commit `d1ca7f01`, after the maintainer approved it on the card thread (2026-11-25 22:48Z). The census pin requires every caller of `referenceTargetOf` to be classified; the seat's review agrees with the kind. The row cites the service case that a parent-scoped search makes no engine call naming the parent object. Run at `d1ca7f01`: `pnpm --filter @objectstack/core test:repo`, 8 files, 110 tests passed. - No `scripts/adr-anchors` entry: review ruling (c), not owed. - `knowledge-ragflow` does not run the suite and ignores `scope` (objectstack-ai#37004 retires it). The service's check keeps its answers in scope. A parent scope answers nothing from it if its hits carry no metadata. - objectstack-ai#37337 (objectstack-ai#37100, pgvector) merged before this PR's queue run, and `main` is merged again at `93c70347`. `searchWithRefusals` validates the scope first; the admitted sources are filtered by the scope, then by `groupBy`, then planned (`planSearches` carries each source's terms beside its fingerprint, `SearchTarget.scope`), and `searchRound` hands the adapter both `index` and `scope`. The suite's `implements`, the stubs, `knowledge-memory` and the protocol sample declare the generation keys and `scope`. - objectstack-ai#37335 (record-level return) merged first, and `main` was merged into this branch at `67f11a57`. `search()` validates the scope, `groupBy` and `granularity` first, then filters the admitted sources by the scope (`sourcesInScope`) and then by `groupBy` (`sourcesGroupableBy`). Every round of the record-level path goes through `searchRound`, so every round is handed the terms and checked. - `packages/plugins/knowledge-pgvector/**`: inside the claim as the seat widened it after objectstack-ai#37337 landed (objectstack-ai#37308 item 4): the scope filter in `search()`, `implements.scope`, and nothing else. - `overlap-check` at `760716bc`: `main`, objectstack-ai#37265 and objectstack-ai#37187 merge cleanly. ## Verification Read first: 1. `packages/services/service-knowledge/src/knowledge-search-scope.ts`: the whole module (bounds, term building, hit check). 2. `KnowledgeService.search` / `sourcesInScope` / `searchRound` / `checkScope` in `knowledge-service.ts`: the three-line change at the top of `search`, and the check after the answer. 3. The two TSDocs in `packages/spec/src/contracts/`. Two-minute check: run `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-search-scope.test.ts src/__tests__/knowledge-service.test.ts -t scope`. Then open the "search scope" describe and read the acceptance case "20 records, two of them in scope, topK 5". --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm)_ <!-- signed: repo:cloud#1 · os-warren · session_01JQwxbZmjM1KubX3ZAoJPPm --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…record, and the history selector refuses a package that neither holds nor ships the name (objectstack-ai#37423) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8B1Mg5PDzRbxsNX8cyVk17x)_ Fixes objectstack-ai#37130 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — no `skills/` page teaches the protocol's restore doors, the history `?package=` selector or `listPackageBindings` ## 维护者速读 - 用户能看到什么变化:环境管理员在历史版本里恢复或整批撤销时,平台自带的技能等记录不再被改写成旧版本,而是直接收到冲突提示和处理办法;按应用查看历史时,既没存过也没提供该名称的应用会被拒绝,不再串到环境自己的记录上。 - 为什么做:这是「平台技能与应用技能分开存放」(云端技能注册)的收尾,补上协议层的两个恢复入口,并顺带修掉同一读取链上的三处小问题。 - 出错会怎样:受影响的只是在环境里恢复平台自带记录旧版本、或按无关应用查历史的管理员,会收到冲突提示;改动可以直接撤回。 - 要你做什么:无 ## What changes 1. **Card item 1 (R21).** The metadata protocol's `rollbackMetaItem` and the restore limb of `revertCommit` refuse a restore whose row is the platform's own record, with the metadata service's `rollback` refusal: `409 RESOURCE_CONFLICT`, its prescription, nothing written. One rule for the three doors: the refusal that lived privately in `database-loader.ts` is now `refusePlatformRecordRestore(type, name, row)`, exported by `@objectstack/metadata`, asked by `DatabaseLoader.registerRollback` and by `SysMetadataRepository.restoreVersion` when a door passes `refusePlatformRecord: true` (both protocol restore doors do; the two undo writes do not). It is judged on the active row `restoreVersion` itself reads and writes. `revertCommit` puts the refused item in `failed[]` and reverts the commit's other items (ADR-0067 D3 as amended). The prescription now also names the environment's route (R23). 2. **Card item 2.** `historySlotOf` (the history, diff and rollback doors' `?package=` selector) refuses a package that neither holds a row of the name nor ships it with `409 not-held-by-qualifier`, also when the name's package-less row is stored. Before, a read naming such a package fell back to the package-less row and the selector addressed that row. The package-less row is a package's slot only when the package ships the name (ADR-0150 D4). 3. **Card item 3 (R22, R23 nits in code).** `PLATFORM_PROVENANCE`'s doc names all three refused restore doors, words the snapshot rule exactly (the platform's own record's publish snapshot, served as the answer, keeps the mark at its top; a snapshot nested inside the answer never carries it) and names the two undo writes by what they undo. The stranded `storedRowBodyOf` doc comment in `database-loader.ts` sits on its function again. 4. **Folded (a).** `list()` listed a stored row twice after the boot priming pass when its body's `_packageId` stamp differed from its package column. Measured: the loader keys the row by its column, and `register(…, { skipSourceLoader: true })` filed the primed copy under the body's stamp. The fix is in neither `list()` nor the loader: the priming registration files such a stamped body under the column's slot (`MetadataManager.primedRowSlot`), so a primed process answers as an unprimed one does (one listing; a read naming the column's package answers it; the stamp's answers nothing). 5. **Folded (b) N2.** Decision: fail closed. `listPackageBindings` is `degraded`, naming the loader, over a `datasource:` loader that offers no `loadRowBindings`. Reason: such a loader's items answer `registration`, which is not their rows' binding, and the spec contract already tells a gating consumer to treat a degraded answer as unknown, so this needs no contract change. No such loader ships in the tree. 6. **Folded (c) N7.** Cheap fix, no cross-node coordination: `bindReadRowPackage` already re-reads the row; it now records the column as that re-read finds it, so the node whose boot pass lost the race answers the bound package instead of `null` until restart. 7. **R16 re-verified, no code.** `getPublished` applies `carriesPlatformStamp(item)` to the top level only and strips every nested snapshot. Its four pins exist in `database-loader.test.ts` ("getPublished serves the mark on the top level only when the stored item carries it there"). ADR-0010 note, for the weekly ADR revisions card (out of this PR's file surface): the note should say "a restore whose row is the platform's own record is refused (`409 RESOURCE_CONFLICT`) at the metadata service's `rollback` and at the metadata protocol's `rollbackMetaItem` and the restore limb of `revertCommit`", in place of "a rollback whose row is the platform's own record is refused (`409`)". ## Deliberate correction `check-empty-changeset` is red by design on this PR: it rewrites one pending release note it did not add, because this PR made that note false. - Note: `.changeset/37013-platform-skill-own-slot.md` (pending, from objectstack-ai#37021). Corrected at `43a6758f`, three sentences; the rest of the bullet is byte-identical: 1. Before: "…and so do the metadata protocol's save door and its restore doors (`rollbackMetaItem` and the restore limb of `revertCommit`);" After: "…and so do the metadata protocol's save door and its restore doors (`rollbackMetaItem` and the restore limb of `revertCommit`) on every restore whose row is not the platform's own record;" 2. Before: "`rollback` whose row is the platform's own record is refused (`409 RESOURCE_CONFLICT`, naming the fix), with nothing written." After: "A restore whose row is the platform's own record is refused (`409 RESOURCE_CONFLICT`, naming the fix), with nothing written, at all three restore doors: `rollback`, and the metadata protocol's `rollbackMetaItem` and the restore limb of `revertCommit`." 3. Before: "`getPublished` serves it on the answer's top level only when the stored item carries it there, and never inside a publish snapshot;" After: "`getPublished` serves it on the answer's top level only when the stored item carries it there (the platform's own record's publish snapshot, served as the answer, keeps the mark it carries at its top), and never on a snapshot nested inside the answer;" - Confirmation: the same-head contract review record at `CONTRACT_REVIEW_TIER` judges each rewritten sentence (pm-dispatch `references/landing-operations.md`); the seat's ACCEPT points to it. ## Tests Read first (by risk): 1. `packages/metadata-protocol/src/protocol-history-slots.ts` — the `holdsSlot` line: the narrowing every `?package=` history, diff and rollback request passes through. 2. `packages/metadata/src/metadata-manager.ts` — `primedRowSlot`, the key a primed stored row is filed under. 3. `packages/metadata-protocol/src/sys-metadata-repository.ts` — the `refusePlatformRecord` check inside `restoreVersion`. New and changed pins: - `protocol.platform-mark-rollback.test.ts`, new describe: `rollbackMetaItem` refused 409 with the row byte-identical; `revertCommit` puts the item in `failed[]` (code `RESOURCE_CONFLICT`) and reverts the other item; RESTART: a process primed from the rows answers a read naming the one package holder with that holder's item and `getPlatformItem` with the platform's v2. Each was red on `5bf72422` before the door lines (`expected { success: true, …(4) }`, `expected [] to have a length of 1`, `expected 'platform v1' to be 'package rules'`). - `protocol-history-slots.test.ts`: the case that pinned "P does not ship the name … the environment slot" is replaced by its refusal (the branch the ruling removes), plus a two-holder refusal and a `.custom` pair CONTROL. - `protocol-diff-history-slots.33308.test.ts` and the dogfood file `history-diff-two-holders-33308.dogfood.test.ts`: the case that addressed the environment's slot through a package shipping nothing now addresses it through a shipper (unit) or expects the 409 at the history and diff doors (dogfood). - `database-loader.test.ts`: (a) a new `list()` pin, and the objectstack-ai#37039 bindings case now expects `differs` once (it recorded the double listing); N2 and N7 pins. <details><summary>Ablation (each fix line removed, then restored with git checkout)</summary> | Ablated line | Red | |:--|:--| | `refusePlatformRecord: true` at `rollbackMetaItem` | 1: the rollbackMetaItem pin | | `refusePlatformRecord: true` at `revertCommit` | 2: the revertCommit pin and the RESTART pin | | the check in `restoreVersion` | 3: all three door pins | | `holdsSlot = slot !== null && …` back to `slots.includes(slot)` | 3: two selector pins and the 33308 diff case | | `primedRowSlot` not passed to `writeRegistryEntry` | 2: the new `list()` pin and the objectstack-ai#37039 bindings case | | N2 `degraded = true` | 1: the N2 pin | | N7 column record after the re-read | 1: the N7 pin | | `refusePlatformRecordRestore` answering nothing | 2: the service `rollback` pins of objectstack-ai#37013 | </details> <details><summary>Package runs</summary> - `pnpm --filter @objectstack/metadata test` at `abc706ce`: Test Files 83 passed (83), Tests 2808 passed (2808). - `pnpm --filter @objectstack/metadata --filter @objectstack/metadata-protocol typecheck` at `abc706ce`: both Done, exit 0. - `pnpm --filter @objectstack/metadata-protocol test` at `955a3452` (the last commit touching either package before the changeset and the merge of main, which touched neither): Test Files 370 passed, 9 skipped (379); Tests 23440 passed, 45 skipped (23485). Re-run at `abc706ce` under the verify lock: same counts, command exit 0. `pnpm --filter @objectstack/dogfood test` at `abc706ce` under the lock: Test Files 487 passed, 3 skipped (490); Tests 4128 passed, 68 skipped (4196); exit 0. </details> ## Acceptance notes - Declaration: the claim reads `Clause-②: no (narrowing…)`. The diff also widens the public surface (the `refusePlatformRecordRestore` export and the `refusePlatformRecord` option of `restoreVersion`), so it declares `yes (narrowing)`. - The unreleased `.changeset/37013-platform-skill-own-slot.md` still carries two of round 4's texts (R22 c and d: "of a failed batch row write", and the protocol doors reading the mark's one definition) and "never inside a publish snapshot". That file is outside this claim's file surface; carrier: the seat, as a deliberate correction with the next text edit. - Round 4's R21 paragraph also named one more reading (a version the platform registered is attributed to the environment in history, so after the platform withdraws its record under a one-holder name a rollback naming the package can write it into the package's row). Not in this claim's scope and not changed here; carrier: the seat. - objectstack-ai#37187's N3 and N6 were not folded into this card and are untouched. - Reading, not measured end to end: the `GET /meta/:type/:name/published` overlay branch serves a stored row's own body, as round 4 read it; a snapshot nested in that body is served as stored. ## Verification Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol.platform-mark-rollback.test.ts src/protocol-history-slots.test.ts` after building `@objectstack/metadata`; expect 6 and 17 passed, including the three `[objectstack-ai#37130]` door pins and the two `[objectstack-ai#37130]` selector refusals. <details><summary>Local gates at abc706c</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 72 commands; all 72 run, 70 exit 0 at `abc706ce`. Two exit 3 (prerequisite not met, NOT MEASURED; CI runs both): `node scripts/check-plugin-teardown-shape.mjs --self-test` (shallow clone), `pnpm check:dual-build-cjs-loads` (unbuilt packages outside this diff). `pnpm check:type-check-debt` re-run: exit 0. `dispatch-gates --ran`: "72 derived famil(ies) accounted for — 70 run, 2 NOT-MEASURED". `overlap-check --pr=37387`: merges cleanly with origin/main and objectstack-ai#37387. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxba3jmfHtmkWfFXfVTc <!-- signed: repo:cloud#1 · os-warren · session_01JQwxba3jmfHtmkWfFXfVTc --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…nto a package's row, and adopt-orphans leaves the platform's record (objectstack-ai#37640) Fixes objectstack-ai#37604 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — no `skills/` page teaches restoring a platform-registered version, adopting orphans over the platform's record, or `listPackageBindings` ## 维护者速读 - 用户能看到什么变化:平台撤回某个内置记录后,管理员按包回滚(或回退某个包的提交)时,如果选中的是平台自己登记的那个版本,会被明确拒绝并提示改为重新保存;"领养孤儿元数据"不再把平台内置记录划进某个包;其余操作不变。 - 为什么做:这是平台内置技能、智能体、工具那一轮收尾留下的两处边角,防止平台自己的内容被悄悄写进某个包里,变成那个包的东西。 - 出错会怎样:只涉及两个少见的管理操作;被拒绝时什么都不写,本改动可直接撤回。 - 要你做什么:无。 ## What changes **Item 1 — a version the platform registered is never restored into a package's row.** Reproduced on main first (pins red on base, readings below): after the platform withdraws its record of a skill, the name's one remaining holder is the package, a version attributed to the environment counts as that package's slot (`isVersionOf` / `isAddressedVersion`, M1), and a rollback naming the package, or bare, answered `Reverted to version 1 (package=com.acme.crm)` and wrote the platform's body into the package's row. It reproduced at all three restore doors: the metadata service's `rollback`, and the protocol's `rollbackMetaItem` and restore limb of `revertCommit` (the last for a commit that names its package, as `recordPackageCommit` always writes it; that limb passes no `versionOf`, so it reaches this whenever the commit's version is one the platform registered). Route taken: **the loud refusal**, `409 RESOURCE_CONFLICT`, the envelope of `refusePlatformRecordRestore`, nothing written; `revertCommit` lands the item in `failed[]` and still reverts the commit's other items. Judged on the four axes: - real business need: the scenario is the one the platform's withdrawal produces for a name a package also ships (the objectstack-ai#37013 slot model), measured at three doors, not a speculative surface; - long-term soundness: one rule in the producer (`@objectstack/metadata`) that all three doors ask, rather than a per-door filter of which versions a package "wrote"; - keeping AI from writing wrong metadata: a refusal that names the fix ("save it again naming the package") beats a silently narrower version list — an author or agent sees why, and nothing is written behind its back; - no scope growth: no new code, reason value, key or route; `restore only the package's own versions` would have meant re-defining the M1 attribution rule that history reads share, a larger change for the same outcome. The refusal lives in `refusePlatformRecordRestore` as an optional fourth argument (the version's history row, its number, and the package whose row is written). The version is judged by its history row with the one reader below: attributed to no package or to the environment, and its body carries the platform's mark and names no package. A version restored into the package-less row (the environment's own item) is left as before. **Item 2 — adopt-orphans leaves the platform's own record.** Reproduced on main: `reassignOrphanedMetadata` rebound the platform's package-less row to the target package. It now skips a row `isPlatformRecordRow` reads as the platform's record, as it skips an artifact-backed overlay; every other orphan is adopted as before. **N5 — one platform-row reader.** `isPlatformRecordRow(row)` is now exported from `@objectstack/metadata` (`database-loader.ts`): the package column names no package (empty, or the environment's history mark) and the body carries the platform's mark and names no package. `refusePlatformRecordRestore`, the protocol's overlay census (`protocol-diff-delete-load.ts`, whose private copy is deleted — the only edit in that file) and the adoption ask it. Consequence: a package-bound row whose body keeps the mark is no longer refused by the row rule (it was refused, prescribing to name the package already named). **N1** — the refusal's prescription now says re-saving a version's body as the environment's own item "holds until the platform's next registration at boot writes its record back". **N2** — new pins ride `rollbackMetaItem` (named and bare) and `revertCommit` with a commit that names its package. **objectstack-ai#37187 N3** — `listPackageBindings` skips, in its row walk, a loader the list walk already lost: named once in `errors`, reported once, its rows not read a second time. **objectstack-ai#37187 N6** — one doc-comment sentence in `packages/spec/src/contracts/metadata-service.ts`: a primed copy answers its row's column as the registry last knew it (the column the boot priming pass wrote when it bound the row, else the column it was read with). **N3 (objectstack-ai#37423 review) — dropped.** `.changeset/37013-platform-skill-own-slot.md` is no longer pending: the prerelease `chore: version packages (next)` (`33a31dc7`) compiled it into `packages/metadata/CHANGELOG.md` and `packages/metadata-protocol/CHANGELOG.md` and moved it to `.changeset/pre/`. The same holds for the 37130 note that N1 mentions, so N1 changes the runtime message only. A factual fix to a compiled entry belongs in a docs-only PR, not here. N4 needed nothing. Serial constraints: `protocol-save.ts` is untouched; `protocol-diff-delete-load.ts` carries only the shared reader (an import swap and the deleted private copy); `sys-metadata-repository.ts` carries one call-site change. Public surface: `isPlatformRecordRow` (new export) and the optional fourth argument of `refusePlatformRecordRestore`. With the two refusals, that is why this declares `Clause-②: yes (narrowing)`, not the claim's `no`. `Metadata-protocol: none`: no key, accepted value, code or route changes; level `patch`, BREAKING banner and ADR-0087 marker in `.changeset/37604-platform-record-followups.md`. ## Tests - `packages/metadata-protocol/src/protocol.platform-mark-rollback.test.ts`: `rollbackMetaItem` naming the package and bare, and `revertCommit` of a commit naming the package, each asserting `code: RESOURCE_CONFLICT`, `status: 409`, the message's "the platform registered", and the rows byte-identical; plus a control that the package's own version still restores. - `packages/metadata-protocol/src/protocol.adopt-orphans-platform-record.test.ts`: the platform's row stays unbound while the environment orphan beside it is adopted; a control that a package-less row whose body names a package is adopted. - `packages/metadata/src/loaders/database-loader.test.ts`: the service door's `rollback` named and bare after a real `register(..., { origin: 'platform' })` + `unregister(..., { origin: 'platform' })`; N5 reader and refusal envelope pins; the objectstack-ai#37187 N3 pin. <details><summary>Red on base (main 4e10d4b)</summary> - protocol door: 2 failed, `expected { success: true, … } to match object { code: 'RESOURCE_CONFLICT', … }`; received message `Reverted to version 1 (package=com.acme.crm) — type=skill, name=helper [seq=3]`. - adopt-orphans: 1 failed, `expected 'app.base' to be null`. - service door: 2 failed, `expected { name: 'data_explorer', … } to match object { code: 'RESOURCE_CONFLICT', … }`. </details> <details><summary>Ablations (fix committed first; each mutation landed via scripts/ablation-replace.mjs, rebuilt, dist preflight checked, restored to HEAD and rebuilt)</summary> - version refusal disabled: `database-loader.test.ts` 2 failed / 498 passed; protocol files 3 failed / 9 passed (the two `rollbackMetaItem` pins and the `revertCommit` pin). - lost-loader skip disabled: the objectstack-ai#37187 N3 pin failed (1 / 500). - reader's column check removed: the two N5 pins failed (2 / 500). - adopt-orphans filter disabled: the adopt pin failed (1 / 2). </details> <details><summary>Suites after the merge of main (33a31dc)</summary> - `@objectstack/metadata` and `@objectstack/metadata-protocol` typecheck: exit 0 (tree of 478efd8). - `@objectstack/metadata` vitest: Test Files 83 passed, Tests 2814 passed (tree of 478efd8). - `@objectstack/metadata-protocol` vitest: Test Files 371 passed / 9 skipped, Tests 23446 passed / 45 skipped (478efd8). The head d96a1a9 adds one module-top import to the new adopt pin (check:test-source-alias asked for it). - `@objectstack/spec` build + `check:generated`: all 14 generated artifacts up to date. - Local gates (exit 0): check-adr-0087-registration, check-changeset-no-major, check-empty-changeset, check-closing-keyword-parity, check-issue-citations, check:durability-log-level, check:startup-registry-verdict, check:doc-authoring, check:nul-bytes, check:undeclared-dep-imports, check:facade-delegation-only, check:engine-double-contract, check:test-source-alias, check:adr-anchors. NOT MEASURED: check:published-readme-exports (exit 3, workspace not built), check:dev-prereqs (workspace not built). The other derived families run in CI. - Full dogfood battery on the final head: running at PR open; its reading goes to the dispatch report. </details> ## Acceptance notes - The two `.changeset/pre/` notes (37013, 37130) still carry "of a failed batch row write" and the unqualified re-save prescription in the compiled changelogs; not edited here (see N3 above). - Other readers of the same fact remain in `database-loader.ts` (the write path's `platformRow` and the platform withdrawal's `taken`); they read `isPlatformOrigin` off the body alone. They were not N5's pair and are left as they are; whether they should ask the shared reader is not measured here. - `restore only versions the package itself wrote` was the alternative route; not taken, for the reasons above. ## Verification Read first: `packages/metadata/src/loaders/database-loader.ts` (`isPlatformRecordRow`, `refusePlatformRecordRestore`, the `registerRollback` call), `packages/metadata-protocol/src/sys-metadata-repository.ts` (`restoreVersion`'s call), `packages/metadata-protocol/src/protocol-package-commits.ts` (the orphan filter). Two minutes: `pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 src/protocol.platform-mark-rollback.test.ts src/protocol.adopt-orphans-platform-record.test.ts` (after building `@objectstack/metadata`) — expect 12 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q4EjjQkY5yXZrN9BEA3rEK <!-- signed: repo:objectstack#6 · hotlong · session_01Q4EjjQkY5yXZrN9BEA3rEK --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Warren · project thread
Fixes #37039
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
What changes
The contract choice: a new optional member on the metadata service contract, beside
listDiagnosed, rather than an option onlistorquery(both keep their shapes, so every existing caller is unchanged).Contract (
packages/spec/src/contracts/metadata-service.ts):IMetadataService.listPackageBindings?(type)answers{ items: MetadataPackageBinding[]; degraded; errors }. Each item is{ name, data, packageId, source }for one itemlist(type)answers, in its order.source: 'row'means a stored row holds the item andpackageIdis that row's package column (nullwhen the column is empty).source: 'registration'means no stored row holds it andpackageIdis the package its registration files it under (nullfor none). New exportMetadataPackageBinding. Theapi-surfaceandexport-originssnapshots are regenerated.DatabaseLoader (
packages/metadata/src/loaders/database-loader.ts): every row read records its column throughstoredRowColumnPackageId, the column only (empty or thesys_metadatasentinel readsnull).storedRowPackageIdnow calls it before its body fallback, so its behaviour is unchanged. Two new members:loadRowBindings(type):loadManySlots' entries in its order, each withrowPackageId.loadManySlotsnow shares one body (typeRowSlots) with it.rowPackageIdOf(item): the column of the row a plural read handed that very object out from.Both are declared optional on
MetadataLoader;MetadataRowBindingis exported.MetadataManager (
packages/metadata/src/metadata-manager.ts):listPackageBindings(type).readListUncachedis split so the keyed walk (readListKeyed) is shared, andlistedInSlotOrdernow answers keys. An item is a stored row's item when either of these holds:loadManyread from a row. This covers the registry's copy the boot priming pass registers, which is keyed by its body's stamp; awithEntryPackagestamped copy is traced back to its origin.listlists the item by.Otherwise its binding is its registration's: the slot's package for a type stored per
(package, name), else the package its body names.Docs (
content/docs/kernel/contracts/metadata-service.mdx, head f22d3cb): the interface block, alistPackageBindingssection and the types table name the member, after the docs drift check listed the contract page.Behaviour of
list,listDiagnosed,query,loadMany,loadManyKeyedandloadManySlotsis unchanged (the full metadata suite is green).Why
Cloud ADR-0118 D2 states a skill's package binding as the stored row's own. The cloud#4935 build (cloud PR #4967) found no read that returns it:
MetadataManager.queryderivespackageIdfrom item bodies,storedRowPackageIdfalls back to the body stamp, andlist()returns bodies only. A body's_packageIdstamp is whatever the row's author wrote. The column is what the store's write path recorded. How cloud consumes this is cloud#4973, after a pin move.Tests
packages/metadata/src/loaders/database-loader.test.ts, new top-level describe[#37039](7 cases):loadRowBindings: a row whose body stamp (BETA) differs from its column (ALPHA) answers ALPHA. A legacy row with an empty column and a BETA stamp answersnull. A row with neither answersnull. CONTROL: each entry's slot package staysloadManySlots' (ALPHA, BETA, none).loadRowBindingsof a type outside the by-package set (view) reads the column too.skill, after the boot priming pass: every primed row answersrowwith its column. That includesdiffers, whichlistlists twice (once as the registry copy under the BETA slot, once as the row under ALPHA), and both answer ALPHA. The legacy row answersnullwhile its body still carries BETA. Bodies equallist('skill')in order.registrationwith its registered package, ornull.loadRowBindingsthrows makes the answerdegradedwith the error named, and the primed copy still answers its row's column.listPackageBindings('agent')answers the bound package withsource: 'row'in the same process, and a freshloadRowBindingsagrees.skillrow whose stored body is a JSON primitive beside a normal row:loadManyandliststill serve the normal row, as onmain.Local runs (head 07ff6c0; re-run after merging main and after the L2 fix)
pnpm --filter @objectstack/metadata typecheck && pnpm --filter @objectstack/metadata test: VERDICT command-exit 0, Test Files 83 passed (83), Tests 2703 passed (2703).vitest runin packages/metadata: 83 files, 2803 passed. The text merge had dropped main's knowledge-adapter rows from the two contracts snapshots;check:generated --fixregenerated them, and each now equals main plus this PR's one line.null, S2 threwInvalid value used as weak map key) and pass after;vitest runin packages/metadata: 83 files, 2805 passed; metadata typecheck exit 0; speccheck:generated: all 14 up to date.pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated:check:api-surfaceandcheck:export-originsstale (the new export), thencheck:generated --fixregenerated exactly those two; every other gate ✓.dispatch-gates.mjs --commands): 91 commands; 87 exit 0; 4 exit 3 = NOT MEASURED locally (prerequisite missing, not a verdict):check-plugin-teardown-shape.mjs --self-test(shallow clone),@objectstack/lint check:doc-formula-expressions,check:dual-build-cjs-loadsandcheck:lean-entry-closure(no full-workspacedist). CI on 07ff6c0: 58 success, 11 skipped, 0 failed (Lint & Repo Gates,TypeScript Type Check,Test Core10/10,Build Core,Governed Surface Queue Guard,Dogfood Regression Gateand the UI contexts all success).Acceptance notes
list(type)lists a stored row twice when its body's package stamp differs from its column. The boot priming pass registers the row's body under the stamp's slot, and the row loader's item is admitted under the column's slot. This is measured in the manager-level test above and is unchanged here.listPackageBindingsanswers both with the row's column.carrier:the seat decides whether this is a card.bindReadRowPackage), but never from a body that names its package by the_packageIdstamp alone (metadata: measure the 18.3.0 environment rows that carry the host's stamp in their stored body, and decide whether a stamp-removal migration is owed (follow-up of #32791) #32985). So a legacy row whose body carries apackageIdenvelope answers that package as its column, on the boot that binds it and after. A row bound by the stamp alone keeps answeringnull.Verification
Two-minute check:
pnpm --filter @objectstack/metadata exec vitest run src/loaders/database-loader.test.ts -t 37039. Expect 7 passed. Thediffersrow's two entries both readcom.alpha.app, andlegacyreadsnull.Read first:
MetadataManager.listPackageBindingsandreadRowColumnOf(the identity path for primed copies), thenDatabaseLoader.typeRowSlots(theloadManySlotsrefactor).Human Minimum
packages/specholds no runtime logic.pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbXcTgn3UMemcSRTDMs