Skip to content

docs(adr): ADR-0161 dated note — item 17, the typed scope a search hands its adapter: record ids, or a parent object through a listed lookup - #37329

Merged
os-zhuang merged 1 commit into
mainfrom
claude/project-thread-3zr6fx
Nov 25, 2026
Merged

os-zhuang merged 1 commit into
mainfrom
claude/project-thread-3zr6fx

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #37324

Clause-②: yes
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:用户无感;只在「知识检索平台边界」这份决定记录里加一条带日期的说明,定下「限定范围检索」的接口形状:可以只在指定的几条记录里搜,也可以借知识源列出的查找字段,只在一份上级记录(比如一份制度)下的条款里搜。
  • 为什么做:属于「知识检索平台化」专题第三阶段,记下您刚裁的「也能指定上级对象(制度)」;记录规定适配器契约的新成员要先以带日期的说明写进记录,随后的按范围检索代码卡才能动工。
  • 出错会怎样:说明写错,后面写检索服务和存储适配器的人会照错的做,最坏是限定范围后漏掉结果(权限仍逐条按提问人重读,不会越权);有两处是记录替您定的细节请过目:一类条款若有两个字段都指向同一类制度,按制度限定时这类条款不参与检索并记日志;人员字段不算「上级」;本次只有文档,撤回合并即可。
  • 要你做什么:审后由你本人合并(受治理面,合并即批准),且要排在随后的按范围检索代码改动之前。

What changes

One file under docs/adr/: 0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md, 17 lines added and none removed against main (829a45e9). No schema, no code, no changeset.

K8 item 17 of ADR-0161 ("A typed scope filter") reads "Deferred" with no final shape, and K8 rule 3 says a shape that cannot be built as written changes by "a dated note on this record". This PR is that note. It records the maintainer's ruling on Q3, record 7168192820 on #37308: 「也能指定上级对象(制度)」. #37308 builds the member after this note merges; #37311 (row 12) adds the search_knowledge arguments.

docs/adr/** is Tier H: the maintainer merges this PR; no seat approves, merges or enqueues it.

Two additions, in the form PR #37263 used for the #37097 note:

  1. A second dated note under K8's table, after the service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097 note and before "What "capabilities" became.". The table is left as written.
  2. A second Amended bullet at the end of the header list, pointing at the note. The Status: line is byte-identical, so the generated docs/adr/README.md does not change.

What the note decides. Each ◆ is a shape the note decides past the ruling's words, for the approver to accept with the record or strike:

  • ◆ The member is AdapterSearchOptions.scope?, a list of terms: { kind: 'record', ids } (the document's sourceRecordId in ids) or { kind: 'metadata', field, ids } (the document's metadata[field] in ids, or a list with an element in ids). The adapter gets resolved terms, never { object, ids }: turning an object into a field needs the object's registered definition, which is the platform's (K1).
  • ◆ Absent, present, empty, read as item 9's organizationIds: absent ranks every document as before; present filters BEFORE ranking so topK is filled from in-scope documents; an empty list ranks nothing and is never "no filter". organizationIds, scope and the opaque filter all apply.
  • How the service builds it from KnowledgeSearchOptions.scope (entries of object and ids), per source: the source's own object gives a record term; another object gives a metadata term for the metadataFields member that points at it; no such member, and the entry does not reach the source. A source no entry reaches is not searched; a file or http source answers nothing under a scope.
  • ◆ Four readings the ruling leaves open: (1) several entries reaching one source combine as a union; (2) an own-object entry is the record term only; (3) only lookup and master_detail are parent links, target read through referenceTargetOf; a user field is not one; a withheld field is not one; (4) a source that lists two or more lookups to the entry's object is not reached by it, logged once per source naming the fields.
  • What a scope does not reach: a parent two hops away. An entry that reaches no searched source answers the same empty answer a withheld source gives, so the answer never tells which it was.
  • ◆ The service's guarantee: after the adapter answers, the service drops every hit no term holds for, judging KnowledgeHit.sourceRecordId and KnowledgeHit.metadata[field], fail closed. No capability flag is added (K8 rule 5); the service logs once per adapter the first time its check drops a hit.
  • ◆ Judged on the index copy, never an access decision: the permission re-read of the live row stays the access decision. Source admission already requires every metadataFields member an index carries to be queryable by the caller, so "that field in ids" is a filter the caller could run on the object's own rows; the parent row is never read.
  • ◆ The opaque filter stays as it is, handed through and checked by nothing in the service; whether it retires is its own card.
  • The suite cases the member lands with in runKnowledgeAdapterContract, per term kind, and one through a real KnowledgeService over an adapter that ignores the member.
  • Not here: the bounds on KnowledgeSearchOptions.scope (service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308, coded refusal, ADR-0112), the tool argument (search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311), record-level return (service-knowledge: search returns records, not chunks — granularity and groupBy #37103).

One shape differs from #37324's body words. That body says the member on AdapterSearchOptions is scope: [{ object, ids }]. The note keeps [{ object, ids }] on the service option only and hands the adapter resolved terms, as #37308's item 1 and K8 item 17 itself say ("built by the service from"). The member name is scope on both interfaces, with distinct types.

Tests

No test changes: the diff is one Markdown file. The derived gate families were run at 8a64f99f, the head.

Local gates at 8a64f99: 21 derived, 21 run, all exit 0

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 21 commands from the branch's change set (1 path against merge base 829a45e9). Each was run with its output redirected to a file and its exit code read before any pipe. check:doc-formula-expressions needs @objectstack/formula and @objectstack/lint built: built first under the verify lock, VERDICT command-exit 0.

Command Exit
node scripts/check-adr-links.mjs 0
node scripts/check-adr-links.mjs --self-test 0
node scripts/check-closing-keyword-parity.mjs 0
node scripts/check-closing-keyword-parity.mjs --self-test 0
node scripts/check-comment-mask-corpus.mjs 0
node scripts/ci/plan-test-core-shards.mjs --self-test 0
pnpm --filter @objectstack/lint run check:doc-formula-expressions 0
pnpm check:adr-anchors 0
pnpm check:adr-index 0
pnpm check:adr-symbol-anchors 0
pnpm check:ci-filter-parity 0
pnpm check:closed-ceremony-text 0
pnpm check:cross-package-test-inputs 0
pnpm check:doc-authoring 0
pnpm check:driver-memory-census 0
pnpm check:gitlink-declared 0
pnpm check:nul-bytes 0
pnpm check:pm-governed-merges 0
pnpm check:pm-prior-rulings 0
pnpm check:refd-timer-probe 0
pnpm check:watch-hint-literal 0

Reconciliation, node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran with the exit codes recorded:

Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 21 derived famil(ies) accounted for — 21 run, 0 NOT-MEASURED (a DERIVED zero — all 21 recorded an exit code and none of them is 3).

check:adr-symbol-anchors resolves the note's four path#symbol citations. Outside the derived set and not run locally: the governed-merges audit with workflow-only variables, CI's test-core shard planning steps, and the type-check lanes (the diff touches no TypeScript). CI carries them.

Acceptance notes

  • Two ◆ readings worth the approver's eye, each written as the note's recommendation:
    • Reading (4), two lookups to the same parent: the entry does not reach the source, logged once. The other answers were a union of the fields (answers "inside this policy" with clauses that only cite it through the other field), the first field listed (gives list order a meaning no author wrote), a key on the entry naming the field (no consumer yet), or a refusal (would differ from the withheld-source answer). No source in this tree lists a reference field in metadataFields today, so no measured consumer decides it; empty-now can open later without removing anyone's hits.
    • Reading (3), the user field: excluded as a parent link. The visible cost: Field.lookup('sys_user') is a link while Field.user() is not. Nothing scopes by user today; it returns by a dated note with its reader.
  • The opaque filter has no producer in this tree (the one non-test caller of IKnowledgeService.search, createKnowledgeTools, passes none) and gets no service guarantee. The note leaves it unchanged; whether to retire it is a question for its own card. Noted, not filed: carrier none.
  • Left to service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308's code PR, not decided here: whether the refill after the permission filter also counts hits the scope check removed; whether an empty KnowledgeSearchOptions.scope or an entry with no ids is answered empty or refused (the note fixes only that it never reads as "no scope"); the bound numbers; log levels.
  • No changeset. docs/adr/** publishes nothing; the PR carries skip-changeset.
  • No scripts/adr-anchors entry. pnpm check:adr-anchors exits 0 without one; the code PR anchors the member it lands.

Verification

Read first:

  1. The "Four readings the ruling's words leave open" bullet of the new note, readings (3) and (4): the two places the note goes furthest past the ruling.
  2. The "The service's guarantee, whatever the adapter does" bullet: fail closed on a hit without the document's metadata, and no capability flag.
  3. The "The opaque filter stays as it is" bullet.

Two-minute check: open this PR's Files tab. It shows one file under docs/adr/, +17 −0: one Amended bullet at the end of the header list, and one blockquote between the #37097 note and the paragraph that starts "What "capabilities" became.".


Generated by Claude Code

…nds its adapter (#37324)

A second dated note under the table of K8, and a second Amended bullet in
the header list. The note records the maintainer's ruling on Q3 (ruling
record 7168192820) and gives item 17 its final shape: the member is
AdapterSearchOptions.scope, a list of terms the service builds from
scope: [{ object, ids }] and the adapter applies before it ranks. No
code, no schema, no changeset. The status line is left as it is.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 25, 2026
@github-actions github-actions Bot added size/s documentation Improvements or additions to documentation labels Nov 25, 2026
@objectstack-fleet

objectstack-fleet Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

维护者速读

  • 改了什么:用户无感,只在「知识检索平台边界」这份决定记录里加一条带日期的说明,把「限定范围检索」的接口定下来:可以只在指定的几条记录里搜,也可以直接给一份上级记录(比如一份制度)的 id,只在它名下的条款里搜。
  • 为什么:这是您今天裁的「也能指定上级对象(制度)」;记录规定存储适配器接口的新成员必须先写进记录,随后的按范围检索代码才能动工,这条说明不合并,后面两张代码卡都开不了工。
  • 风险:只有文档,撤回合并即可恢复;说明写错的最坏后果是限定范围后漏结果,不会越权(每条命中仍按提问人的权限重读)。有三处是记录替您定的、您的原话没有覆盖的细节:① 一次给多个范围时取并集;② 只有「查找」和「主从」两类字段算上级,人员字段不算;③ 一类条款若有两个字段都指向同一类制度,按制度限定时这类条款不参与检索、只记日志,用户看到的是「没搜到」。目前没有任何知识源是第 ③ 种情况,以后放开只会多出结果,不会减少。
  • 要你做的:审后由你本人合并(受治理面,合并即批准,也即同意上面三处);若不同意第 ③ 处,在这个 PR 上说一句想要哪种(两个字段都算 / 只认主从字段 / 让调用方点名字段),席位让作者改后再请你合。契约审核结论 PASS 在本评论下半部分,对应提交 8a64f99ffd1d0056e85a3ea9fa233a8b4a12357c。

席位意见:建议按现稿合并。作者交给适配器的是平台换算好的过滤条件(记录 id 或某个筛选字段的 id),不是卡面写的「对象 + id」原样,这与记录第 17 项原文「由服务构建」和裁决记录「过滤条件变成该字段在 ids 内」一致,是卡面措辞不准,不是改了您裁的东西。第 ③ 处是唯一有产品语义分歧的细节,席位推荐现稿的「不参与并记日志」:两个字段取并集会把「只是引用了这份制度」的别处条款算进来,答错比答空更糟;今天零用例,等第一个真实知识源出现再用一条补充说明放开。

席位核对

ACCEPT
Head-sha: 8a64f99ffd1d0056e85a3ea9fa233a8b4a12357c

  1. 形态。 l1-face.mjs --pr 37329 于 2026-11-25T17:18Z 现读:open · draft · base main;首行 Fixes #37324,不绑其他卡;Clause-②: yes · Metadata-protocol: none;Skills-docs: 不欠(kind none、无 narrowing);无 content/docs/releases/ 路径;无 changeset、无空 changeset,未触及任何已发布包,skip-changeset 由 objectstack-fleet[bot] 于 17:13:46Z 随 PR 创建挂上,席位自核 diff 为单个 docs/adr/** Markdown 文件,docs-only 成立。Fixes 判定成立:卡的三项交付(第 17 项下的带日期说明、声明规则 3 与 5 只为这一个成员修订、点名 service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 与 search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311)与两条验收(引裁决 id 与原话、不改记录既有文字)在 diff 里逐项读到。标题与正文如实;正文 What changes 写的 merge-base 829a45e9 与 git merge-base 读数一致。
  2. 前提实测。 git diff origin/main...refs/l1/37329:1 文件,+17 −0,文件面与认领评论 7168526417 申报的唯一路径一致。裁决 7168192820(service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308)逐字比对:说明引的「也能指定上级对象(制度)」与「直接给制度 id 就只在这份制度里搜;前提是知识源把指向制度的字段列为筛选字段,没列就返回空。1 个 PR,略大。」与裁决记录一致。main 上第 17 项仍为 "Deferred",表格与 Status 行在本 diff 中零改动。说明引的代码事实席位在 head 树与 origin/main(fbb62e1c,merge-base 之后 10 个提交,含 feat(service-knowledge)!: one splitter (whole / recursive / markdown, Chinese-aware), the chunk channel and the split key; KnowledgeChunk.metadata and knowledge.chunk_overlap retired #37287)各读一遍,全部成立:referenceTargetOf 对 user 恒答 sys_user(REFERENCE_VALUE_TYPES 含 lookup、master_detail、user、tree);recordToDocument 把 metadataFields 的存储值原样写进 metadata 并跳过凭据类与 internal 字段;admitSourceFields 要求索引携带的每个 metadataFields 成员对调用者可查询;knowledge-memory 的 matchesFilter 在排序前过滤、命中带回文档 metadata;createKnowledgeTools 调 search 不传 filter;仓内无任何知识源把引用字段列进 metadataFields(grep metadataFields,命中仅 spec、服务与其测试)。git merge-tree origin/main refs/l1/37329 无冲突。
  3. 门禁 check-runs(head 8a64f99ffd1d0056e85a3ea9fa233a8b4a12357c,2026-11-25T17:26:39Z 读,全部 completed):49 个 check-run,26 success · 23 skipped(l1-face 于 17:18Z 判为预期 skip,0 unexpected skip)· 0 failed · 0 pending。两个 required 地板 Lint & Repo Gates 与 TypeScript Type Check 均 success;另含 Test Core、Lint · docs & code guards、Lint · repo & tooling gates、Lint · CI, release & engine gates、Lint · PM dispatch-gates、Governed Surface Queue Guard、Check Documentation Links、Check Changeset、PR-body guards,均 success。dev 报告的本地 21 族门禁只证本地子集,不替 check-runs;报告写的短 sha 8a64f99f 与 head.sha 相符。
  4. 接受的偏差。 (a) 适配器成员收到的是服务换算好的 term(record / metadata 两种),不是 ADR-0161 K8 item 17: a dated note fixes the record-scope shape — scope: [{ object, ids }] on search and the adapter filter, a parent object reached through a lookup the source lists in metadataFields #37324 卡面写的 [{ object, ids }] 原样:接受。依据是记录第 17 项原文 "built by the service from scope: [{ object, ids }]"、裁决记录 "the typed filter becomes 'that field in ids', applied before ranking"、service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 第 3 条 "the service builds the typed filter and passes it to the adapter",以及 K1(适配器不读对象定义);卡面是席位自己的简写不准,此处当众认,更正即本条。(b) 说明内 ◆ 所标各项(成员形状、缺席/在场/空三态、四条读法、服务端兜底校验、不新增能力标志、不透明 filter 原样保留)为记录在裁决原话之外自定的形状,照 ADR-0161 Status 行的既有做法标 ◆ 交批准人随合并接受或划掉;其中读法 (4)(两个引用字段指向同一上级对象 ⇒ 该源不被此条目触及并记日志)是唯一产品语义有真实分歧的一项,已写进上方速读,由维护者合并时一并裁。(c) 说明把四件事留给 service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 的代码 PR(权限过滤后的补取是否计入范围校验剔除的命中、服务选项为空或条目无 id 时答空还是拒绝、上限数值、日志级别):接受,四件都不是「适配器作者为了正确必须读」的成员形状(K8 "What counts as a member"),成员一侧的三态已在说明里定死。
  5. 范围外去向 + Skills-docs:。 dev 报告一条范围外发现:不透明 filter 在仓内无生产者、无服务端保证,记为 "noted, not filed · carrier: none";说明写明其去留另立卡。席位照 filing-gate.md 判断是否立卡,不在本 PR 内处理。Skills-docs: 行不欠。契约审核的五条 nit(见下)随 service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 的派发令带给代码卡,不要求改本 PR。
  6. 落地条款。 docs/adr/** 为 governed 面,且说明教授权限行为(Security-touching: yes),不走只增 ADR 的低风险臂:Tier H,维护者本人合并,席位不批、不合、不入队。顺序:本记录置顶落 PR(贴前重读 head.sha 仍为本 head) ⇒ pr_ready ⇒ 同笔挂 pm:awaiting-merge 并交棒请审(PR 作者为 objectstack-fleet[bot],已 assign os-warren)⇒ 卡 ADR-0161 K8 item 17: a dated note fixes the record-scope shape — scope: [{ object, ids }] on search and the adapter filter, a parent object reached through a lookup the source lists in metadataFields #37324 留指针行。合并后 ADR-0161 K8 item 17: a dated note fixes the record-scope shape — scope: [{ object, ids }] on search and the adapter filter, a parent object reached through a lookup the source lists in metadataFields #37324 由 Fixes 自动关闭;service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 的 Blocked-by: #37324 解除,其代码 PR 触 packages/spec/src/contracts/**,另欠一轮达档契约审核。

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 8a64f99ffd1d0056e85a3ea9fa233a8b4a12357c
Local-runs: none
Scope: docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md + none
Security-touching: yes
Rule-change-verified: yes

Face: governed rules text (docs/adr/**), so the tier is CONTRACT_REVIEW_TIER and the full ①–④ is owed. Governing text: ADR-0161 K1 (the boundary), K8 item 17 and item 9, K8 "What counts as a member", K8 rules 1, 2, 3 and 5, K9 rules 2, 3 and 6, K10 rules 2 to 4; ruling record 7168192820 on #37308 (Q3 = B); the dated-note precedent of PR #37263. Code outside the diff was read, not reviewed, at the head tree and at origin/main fbb62e1c.

① Derived judgments

  • The record's earlier text is unchanged. +17 −0. The table row of item 17, the Status line, rules 1 to 5 and the service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097 note are byte-identical; the additions are one Amended header bullet and one blockquote placed after the service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097 note, the form PR docs(adr): ADR-0161 dated note — the document hash covers the organization of a document that has one (K8 items 2 and 9) #37263 used. The note's last sentence says "The table is left as written; read item 17 with this note."
  • The ruling is quoted by id and in the maintainer's words, verbatim against comment 7168192820, and the sentence drawn from it ("an entry names the object a source indexes, or a parent object the source reaches through a lookup field it lists in metadataFields, and a source that lists no such field answers nothing for the entry") restates the ruling record's "What is ruled" without widening it. The two-hop limit the ruling record requires the note to state is stated.
  • One member, as rules 3 and 5 require. The note adds AdapterSearchOptions.scope? with its term type and closes the list again. KnowledgeSearchOptions.scope is an option of the service, which K8 names as "not a member ... scope in row 11", so leaving its bounds and its empty answer to service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 is inside the record. Rule 1 (lands with its first reader and a suite case) and rule 2 (optional; nothing skipped silently) are both carried: the suite cases are named, and an adapter that ignores the member keeps working while the service drops out-of-scope hits and logs once.
  • Resolved terms, not { object, ids }, on the adapter. This is the reading the governing text already holds: item 17 says the typed form is "built by the service from scope: [{ object, ids }]"; the ruling record says "the typed filter becomes 'that field in ids', applied before ranking"; K1 says an adapter "does not read records" and the platform holds "the object's fields". Handing an adapter an object name would require it to read an object definition, which K1 forbids. ADR-0161 K8 item 17: a dated note fixes the record-scope shape — scope: [{ object, ids }] on search and the adapter filter, a parent object reached through a lookup the source lists in metadataFields #37324's body wrote the same list on both interfaces as shorthand; the note corrects the card, not the ruling. Precedent for the form: item 9's organizationIds, a filter the service computes and the adapter applies before ranking, whose absent, present and empty readings the note copies from the member's TSDoc on main.
  • Readings past the ruling's words. (1) union of several entries: the natural reading of a list whose entries already carry ids as a set; seat-reasonable. (2) an own-object entry is the record term only: seat-reasonable. (3) only lookup and master_detail are parent links, target by referenceTargetOf: the ruling record says "a lookup field", and master_detail is the spec's literal parent link; excluding user (target fixed to sys_user) and withheld fields is the narrow reading, and opening it later adds hits and removes none. (4) two reference fields to the same parent: the one reading whose alternatives differ in what a customer sees. The note takes the fail-empty arm, which follows the ruling's own 「没列就返回空」 direction, has no consumer today (no source in the tree lists a reference field in metadataFields), and can open later by a dated note without removing a hit. It is marked ◆ and surfaced to the approver in the PR body and in the seat's 速读, and the PR lands only by the maintainer's own merge, so it reaches him before it takes effect.
  • Security reading. Scope only narrows. The filter is judged on the index copy and the access decision stays the permission re-read of the live row for every hit. admitSourceFields already refuses a caller for whom any carried metadataFields member is not queryable, so "that field in ids" is a filter the caller could run on the object's own rows, and not reading the parent row opens no oracle. An entry that reaches no source and a withheld source give the same empty answer. Counts of removed hits go to logs only (K9 rule 6, K10 rule 4). The service's check fails closed on a hit that carries no value.

② Semver level

None. docs/adr/** publishes nothing; no changeset and skip-changeset are right for this repository. Metadata-protocol: none is right: no key a metadata author writes is added (the parent link is an existing metadataFields member). Clause-②: yes is right as declared: the note fixes the shape of a public contract member, and the declaration is what the claim comment carries. The member itself ships in #37308 as an optional addition to packages/spec/src/contracts/knowledge-adapter.ts with its own declaration and changeset.

③ Boundary flags

  • The dev report's open_questions is empty. Its one out-of-scope finding (the opaque filter has no producer and no service guarantee) is answered by the note itself (unchanged; its own card) and goes to the seat's filing gate.
  • The deliberate difference from the card body is answered in ① and accepted.
  • SQL push-down: the member exists so that an adapter filters before ranking in its own store ("that field in ids" pushes down as an IN on a stored column in a SQL adapter). The service's after-check runs over at most the hits one adapter call returned and materialises no id set beyond the caller's own ids. No finding.
  • Author: the PR's user.login is objectstack-fleet[bot].

④ Design judgment

The change holds against the cited code and against the acceptance scenes of #37308 (20 records, two ids, topK: 5, a full in-scope page; a stub adapter that ignores the member; an unreachable object; an unreadable scoped record). First consumer and execution plan are named: #37308 builds the member with knowledge-memory as first reader and the suite cases in one PR; #37311 adds the tool argument; #37103 is unaffected and already relies on hit metadata for its group value. No must-fix and no should-fix. Nits, none of which blocks this head; each is carried to #37308's dispatch:

  1. nit — "This note adds exactly one member" is exact for keys, but the note also makes returning the document's metadata on a hit a condition for a metadata-term hit to survive the service's check. It is disclosed under ◆ and matches main (knowledge-memory returns it; feat(service-knowledge)!: one splitter (whole / recursive / markdown, Chinese-aware), the chunk channel and the split key; KnowledgeChunk.metadata and knowledge.chunk_overlap retired #37287's text says every adapter stores the document's metadata), so service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 states it on KnowledgeHit.metadata's TSDoc and pins it in the suite.
  2. nit — the note says a value "is in ids" without saying how values compare. service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308 compares ids as strings, as sourceRecordId is stringified at assembly, and pins it.
  3. nit — reading (4) lists four other answers; a fifth, "a master_detail field wins over a lookup to the same object", is not listed. It needs no place now (no consumer); it belongs in the dated note that opens reading (4) with its first reader.
  4. nit — the PR body says the note fixes that an empty KnowledgeSearchOptions.scope never reads as "no scope". The note gives this by construction ("A source no entry reaches is not searched") and not in one sentence; service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308's code PR must hold it whichever of empty answer or refusal it picks.
  5. nit — the Status line says the ◆ points are listed in "Points the rulings do not settle"; this note keeps its ◆ points in place, as an add-only note should. No change asked.

The bound on entries and ids is adapter-facing ("so that an adapter can rely on them") and lands on the member's TSDoc in #37308; that PR touches the published contract and owes its own review at this tier. If #37308 finds any shape here cannot be built as written, K8 rule 3 applies: it stops and the change is another dated note.

Implemented-by: claude/project-thread-3zr6fx
Reviewed-by: session_01JQwxbW5anP6GDaVi5LKi2U

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

Hand-off for approval (Tier H, docs/adr/**): seat record ACCEPT and ## Contract review PASS are in comment 7169539288, both on head 8a64f99ffd1d0056e85a3ea9fa233a8b4a12357c.

  • 要你做的:批准这个 ADR 补充说明(范围检索可以指到上级记录);记录里标了三处「◆」理解请过目,其中一处(一个知识源有两个查找字段指向同一上级时不检索、只记日志)可以划掉改选别的方案。批准后席位负责落地。

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 25, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 25, 2026 18:03
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 13ffe1c Nov 25, 2026
56 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-3zr6fx branch November 25, 2026 18:22
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…ped bucket beside skill and ai_context (objectstack-ai#37330)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8ThLXnc2MYoAdJHGZxSsdaA)_

repo:cloud#1 · os-warren · session_01JQwxbZjKjZ947xtTvgJuHX

Fixes objectstack-ai#37325

Clause-②: no
Metadata-protocol: none

## 维护者速读

-
用户能看到什么变化:用户无感(只改决定记录,不改代码);把你今天定的「按应用+名字区分,都保留」写进记录:两个应用各带的同名知识源都保留、各建各的索引,AI
用「应用前缀-名字」指明是哪一个。
- 为什么做:属于「知识检索平台化」专题;哪些类型按应用区分要先写进记录,后面的实现卡
objectstack-ai#37304(让知识源成为应用包里的一份配置)才能照着做。
- 出错会怎样:记录写偏的话,后面的实现会照着偏的做;这次只有文档,撤回这次合并即可。
- 要你做什么:合并这个
PR,合并就是这条裁定的记录;其中一处超出你的原话、只能由你定:同一个应用前缀下不允许两个应用包带同名知识源(前缀不同的同名知识源照样都保留),不同意就先划掉这一条再合并。

## What changes

Two files under `docs/adr/`: 58 lines added, 1 line changed. No schema,
no code, no changeset.

**ADR-0150** (Accepted) gains a dated addendum. No ruled sentence is
rewritten.

- The status line gains one **Amended** clause, dated 2026-11-25, after
the `ai_context` one. This is the one changed line: the clause is
appended, and nothing before it is edited.
- The D1 table gains one row, marked with the date, after the
`ai_context` row and before bucket 4.
- A new section after the `ai_context` addendum and before D2, "Addendum
(2026-11-25): `knowledge_source` joins bucket 3". It writes the
maintainer's ruling of that day into the record: the knowledge source
type of ADR-0161 K4 is identified by `(package, name)`, in bucket 3
beside `skill` and `ai_context`.

The ruling is quoted with its record id in the status clause, at the
head of the addendum and in the ADR-0161 note: seat record `7168239918`
on the code card, decision card tapped **B 「按应用+名字区分,都保留」** at
2026-11-25T16:34:09Z, against the card's recommendation.

The addendum says, in this order:

1. **The type**, and what D2, D3, D4, D5, D6 and D8 mean for it. A
package's source is spelled `NS-NAME` where its name crosses the AI
face, which is inside `search_knowledge`: the `sources` list of an
answer and the `sourceIds` argument.
2. **The principle, read for this type.** The recommendation read a
source's name under D1's storage half. The ruling did not, so the keys
of a source's index are derived from its identity, as its face is. Three
things that reading does not hide are listed.
3. **The tree today**, measured on `main` at `fbb62e1c`. The type is not
registered and is in none of the four lists. A source reaches the
service through code only. The keys of an index are the bare `id`.
4. **What changes with the bucket**: the service's copy, overlays, owner
stamps, uninstall and the keys of an index.
5. **The readers that move.** It names five and moves none.
6. **The follow-up**, the code card objectstack-ai#37304, after this merge.
7. **Past the ruling's words**: seven points, none decided here. One is
the maintainer's, two follow from text already ruled, and four are left
open for the code card.

**ADR-0161** gains one cross-reference note after point 3 of K4 and
before K5. No sentence of it is changed.

**Not in this PR**, by the card's contract: none of the four lists is
edited, no reader is moved and no store is re-keyed. That is the code
card's work, after this merge.

## Tests

No package is touched, so no package build or test is owed. The checks
that read these two files are the docs gates under Verification.

## Acceptance notes

- **The chain.** This PR is the ruling's record and step 1 of its
execution. The code card objectstack-ai#37304 comes after it and stays open: it takes
the four lists, the readers and the store keying in memory, pgvector and
turso.
- **One decision is the maintainer's alone** (point 1 of "Past the
ruling's words"). The ruling record counts "the `domain:server` four
lists and readers (precedent PR objectstack-ai#37291)" and names none of them. In that
PR the fourth list is `NAMESPACE_UNIQUE_TYPES`: one package holder of a
name inside one namespace, refused at install and in `os validate`. So
"Two packages shipping one source name both work" holds for two
namespaces, and inside one namespace the second is refused. The list's
header reserves a further type to the maintainer. The merge accepts this
point. Struck, two co-owners of a namespace may ship one name, and the
one face they derive is refused at the call.
- **Two points follow from text already ruled** and are no new decision.
A source name takes the name grammar of buckets 2 and 3, which refuses a
`_`-led name that today's `id` pattern admits. And a `409` names only
the sources the tool may search (ADR-0161 K9).
- **Four points are left open for the code card.** Each is stated in the
addendum and decided nowhere in it: what each shape carries (a hit's
`sourceId` and `documentId`, a stored document's `sourceId`, the by-name
members of the service contract); which coordinate a key carries, the
package id or the namespace, and what removes an index left under the
old key; which holder a source registered in code is; and an environment
source under a name a package later ships.
- **The acceptance line of the card**, "The addendum quotes the ruling
comment id and the maintainer's words; earlier text of the record
unchanged". The id and the words are in all three places named above.
ADR-0150's diff has one changed line, the status line, and its old text
is a strict prefix of the new text. Every other old line of both files
survives, in order.
- **The tree moved once during the work.** `main` gained the knowledge
splitter (PR objectstack-ai#37287) under six of the files the addendum anchors. `main`
is merged into the branch (a merge commit, no rebase and no force-push).
Every "today" sentence and every anchor was read again at `fbb62e1c`,
and all hold. The two dated readings name that commit.
- **Overlap.** PR objectstack-ai#37329 adds a dated note under K8 of the same ADR-0161
file. `node scripts/pm/overlap-check.mjs
--branch=claude/project-thread-4uapwf` answered `VERDICT clean exit 0`
at this head, against `origin/main` and that PR's head. Whichever of the
two lands second merges `main`.
- **Line budget.** 58 added and 1 changed; the precedent PR objectstack-ai#37209 was
44 and 1. The difference is the "principle" paragraph, which the
precedent did not need because its ruling followed the recommendation,
and the seven-point list.
- **Citation form.** `check:adr-symbol-anchors` refuses a line anchor
under `docs/adr/`, so the record cites `path#Symbol`, and the line
numbers are in the table under Verification.
- **No changeset.** `docs/adr/` ships in no package, so this PR carries
`skip-changeset`.
- **Tier H.** This PR stays draft. The merge is the maintainer's, and it
is the ruling's record.
- **Shallow checkout.** No claim here is read from history dates.
- **Attribution lines.** The dispatch asked for a commit trailer that
names a model and for the harness's two-line block at the end of this
body. The repository's rules ask for the model-free trailer pair and for
one footer line under a rule, and those are what the commits and this
body carry.
- **Noted, not filed.** ADR-0161's status keyword still reads Proposed
on `main`, and its own status line says the record is in force from the
merge of the PR that carried it. This PR adds one note to that record
and does not touch its status line.

## Verification

**Read first**, by risk:

1. `docs/adr/0150-…-literal-prefix.md`, "Past the ruling's words" at the
end of the addendum (lines 191 to 199). Point 1 is the one decision that
is the maintainer's.
2. The same file, "The principle, read for this type" (line 160): how
D1's storage half reads for a type the ruling placed against the
recommendation.
3. The same file, the D1 table hunk (line 95) and the status line (line
3): one row inserted into a ruled table and one appended clause. Check
that both read as additions and change no ruled text.

**Two-minute check**: run `node scripts/check-adr-symbol-anchors.mjs`.
Expect `4220 anchors across 163 records resolve` and exit 0. Twenty-one
of them are this diff's `path#Symbol` anchors.

<details>
<summary>Measured anchors on main at fbb62e1 (file:line)</summary>

| What the addendum says | Where it is read |
|---|---|
| The type is in no row of the registry; `skill` and `ai_context` open
no environment overlay |
`packages/spec/src/kernel/metadata-plugin.zod.ts:798`
(`DEFAULT_METADATA_TYPE_REGISTRY`), `:1384`, `:1388` |
| The service keeps one slot per (package, name) for listed types |
`packages/spec/src/api/protocol.zod.ts:2753`
(`PACKAGE_SLOTTED_METADATA_TYPES`; `skill` at `:2754`) |
| Any other type is keyed by name alone |
`packages/metadata/src/package-slotted-store.ts:797` (`storeWriteKey`),
`:820` |
| The one rule resolves only its listed types, and throws for a type
outside the list | `packages/core/src/package-scoped-resolution.ts:245`
(`PACKAGE_SCOPED_TYPES`; `skill` at `:270`), `:740`;
`packages/objectql/src/package-scoped-resolver.ts:149` |
| A by-name read consults (package, name) for listed types |
`packages/objectql/src/package-scoped-read.ts:88`
(`PACKAGE_SCOPED_READ_TYPES`; `skill` at `:96`) |
| One package holder of a name inside a namespace; the list is reserved
to the maintainer |
`packages/objectql/src/namespace-co-owner-names.ts:96`
(`NAMESPACE_UNIQUE_TYPES`), `:27` |
| A source reaches the service through code only |
`packages/services/service-knowledge/src/knowledge-service-plugin.ts:91`
(`KnowledgeServicePlugin`), `:44`, `:220` |
| One map by `id`; a second registration replaces the first with a
warning |
`packages/services/service-knowledge/src/knowledge-service.ts:121`
(`KnowledgeService`), `:123`, `:166`, `:168` |
| A document id is the source's `id`, a `:` and the record id |
`packages/services/service-knowledge/src/knowledge-service.ts:1570`
(`documentIdFor`), `:1571` |
| An adapter is handed the whole source |
`packages/spec/src/contracts/knowledge-adapter.ts:33`
(`AdapterContext`), `:35` |
| The one in-tree store keyed by the bare `id` |
`packages/plugins/knowledge-memory/src/index.ts:44`
(`KnowledgeMemoryAdapter`), `:48`, `:55` |
| The push door that takes a document id from a caller |
`packages/spec/src/contracts/knowledge-service.ts:107`
(`IKnowledgeService`), `:127` |
| The tool lists each source by its `id`; a hit shows `sourceId` and
`documentId` |
`packages/services/service-knowledge/src/knowledge-tools.ts:61`
(`SearchKnowledgeSourceSummary`), `:70`, `:72`, `:222` |
| An unknown `sourceIds` entry is refused `NOT_FOUND` |
`packages/services/service-knowledge/src/knowledge-tools.ts:246`
(`createKnowledgeTools`), `:257`, `:260` |
| Today's `id` pattern admits a `_`-led name; the bucket's pattern does
not | `packages/spec/src/ai/knowledge-source.zod.ts:174`
(`KnowledgeSourceSchema`), `:176`;
`packages/spec/src/kernel/address-grammar.ts:68`
(`ROUTER_ADDRESSABLE_NAME_PATTERN`) |
| The one face derivation | `packages/spec/src/ai/face-name.ts:86`
(`deriveAiFaceName`) |
| A skill prompt's name: a face, else a bare name by the one rule |
`packages/mcp/src/skill-prompts.ts:373` (`lookupSkillPrompt`) |
| The owner stamp's judge, and the collections it judges |
`packages/spec/src/kernel/collection-item-owner-stamp.ts:129`
(`judgeCollectionItemOwnerStamp`), `:100` |
| The type's row is not among the served overrides |
`packages/metadata-protocol/src/protocol-package-bindings.ts:388`
(`SEALED_ROW_SERVED_OVERRIDE_TYPES`) |
| Uninstall, the registry's half |
`packages/objectql/src/registry.ts:5328` (`uninstallPackage`) |
| Uninstall, the service's half |
`packages/metadata/src/metadata-manager.ts:2880` (`unregisterPackage`) |

Absence readings at the same commit, each with a positive control:

- `knowledge_source` in the four list files, in
`packages/metadata/src/package-slotted-store.ts` and in the registry's
rows: 0 lines each. Control: `skill` is in the first three lists and in
the registry, at the lines the table gives.
- A stack collection: `knowledgeSources` in
`packages/spec/src/stack.zod.ts`, 0 lines. Control: `aiContexts`, 3
lines.
- `knowledge_source` under `packages/`, `examples/`, `ui/`, `skills/`
and `content/`: 0 files. Control: `ai_context`, 60 files.
- `KnowledgeServicePlugin` or `registerSource` under `examples/`: 0
files. Control: 25 files under `packages/`.
- Tracked paths under `knowledge-pgvector` or `knowledge-turso`: 0.
Control: `packages/plugins/knowledge-memory`, 10 files.
- Before this diff, ADR-0161 named ADR-0150 on 0 lines (control:
ADR-0088, 7 lines), and ADR-0150 held the word "knowledge" on 0 lines
(control: `ai_context`, 6 lines).

</details>

<details>
<summary>Local gates at head 05f35b6: 21 derived, 21 run, all exit
0</summary>

Derived with `node scripts/pm/dispatch-gates.mjs --repo
objectstack-ai/objectstack --commands`, and reconciled with `--ran`:

```
Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 21 derived famil(ies) accounted for — 21 run, 0 NOT-MEASURED (a DERIVED zero — all 21 recorded an exit code and none of them is 3).
```

Each exit code was captured before any pipe:

```
0  node scripts/check-adr-links.mjs                      1225 relative link destination(s) under docs/adr/ resolve
0  node scripts/check-adr-links.mjs --self-test
0  node scripts/check-closing-keyword-parity.mjs         3 parsers agree on all 9 keywords
0  node scripts/check-closing-keyword-parity.mjs --self-test
0  node scripts/check-comment-mask-corpus.mjs            23929 files, 0 disagree, 0 unparseable
0  node scripts/ci/plan-test-core-shards.mjs --self-test
0  pnpm --filter @objectstack/lint run check:doc-formula-expressions
0  pnpm check:adr-anchors                                132 anchored file(s), every governing ADR still referenced
0  pnpm check:adr-index                                  docs/adr/README.md is current, every record parsed
0  pnpm check:adr-symbol-anchors                         4220 anchors across 163 records resolve
0  pnpm check:ci-filter-parity
0  pnpm check:closed-ceremony-text
0  pnpm check:cross-package-test-inputs
0  pnpm check:doc-authoring
0  pnpm check:driver-memory-census
0  pnpm check:gitlink-declared
0  pnpm check:nul-bytes                                  no raw ASCII control bytes
0  pnpm check:pm-governed-merges
0  pnpm check:pm-prior-rulings
0  pnpm check:refd-timer-probe
0  pnpm check:watch-hint-literal
```

`check:doc-formula-expressions` reads the compiled output of
`@objectstack/formula` and `@objectstack/lint`. Those two and their
dependencies were built first on the merged tree, under the shared
verify lock (`VERDICT command-exit 0`).

`docs/adr/README.md` is generated from each record's status keyword.
ADR-0150's keyword stays Accepted and ADR-0161's stays Proposed, so the
index does not change and is not in this diff.

Also at this head: `node scripts/check-commit-card-trailers.mjs --range
origin/main..HEAD` exits 0 over the 3 commits of the branch.

Not measured locally, and CI's to run: the type-check lanes, the `Plan
Test Core shards` job and the governed-merges audit, which take values
only a CI run has.

</details>

---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbZjKjZ947xtTvgJuHX)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue size/s skip-changeset PR has no user-facing published change; bypasses the changeset gate

Projects

None yet

3 participants