Skip to content

Commit 13ffe1c

Browse files
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)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8GWXHtfAHuZXmmZpkARr4Wi)_ 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`](#37308 (comment)) 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 #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` (#37308, coded refusal, ADR-0112), the tool argument (#37311), record-level return (#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. <details><summary>Local gates at 8a64f99: 21 derived, 21 run, all exit 0</summary> `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: ```text 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. </details> ## 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 #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](https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8979953 commit 13ffe1c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- **Leaves unchanged**: permission-aware retrieval (every object-source hit is re-read as the caller, and a source is searched for a caller only after the exposure and field-level admission of PR #36850); the reap guard of #4672 as landed; the signature and return type of `IKnowledgeService.search`; the settings shape of #33933 (knowledge settings only where the service is mounted), which #37102 keeps: without the capability token there is no knowledge service and no knowledge settings page; the open AI door, which stays MCP-only (cloud ADR-0119 D4).
1818
- **Inputs**: every code and docs text quoted below was read on `objectstack-ai/objectstack` `main` at `254e396a29`, the commit this record's branch starts from. Positions are in [Readings](#readings-taken-at-254e396a29). PR #36823 and PR #36850 are merged and are in that tree; PR #37075 is open and edits §6 of `content/docs/protocol/knowledge.mdx`, so the §6 quotations may move when it lands.
1919
- **Amended** (2026-11-25, [#37097](https://github.com/objectstack-ai/objectstack/issues/37097)): a dated note under the table of [K8](#k8--the-contract-additions-decided-item-by-item) records that the document hash of item 2 covers `organizationId` when the document has one (item 9), with no version bump. The status line above is left as it is.
20+
- **Amended** (2026-11-25, [#37324](https://github.com/objectstack-ai/objectstack/issues/37324)): a second dated note under the table of [K8](#k8--the-contract-additions-decided-item-by-item) gives item 17 its final shape, `AdapterSearchOptions.scope?`: the typed scope the service builds from `scope: [{ object, ids }]`, on the maintainer's ruling of that day, 「也能指定上级对象(制度)」 (record `7168192820` on #37308). The status line above is left as it is.
2021

2122
---
2223

@@ -328,6 +329,22 @@ The epic holds the contract shut until this record merges ("No new adapter-contr
328329
>
329330
> Item 9's first reader, #37097, is built by PR #37256, and this change to item 2 lands with it. The reasoning is contract review [`7157191417`](https://github.com/objectstack-ai/objectstack/pull/37256#issuecomment-7157191417) on that PR (its M1 and S2). The table is left as written; read items 2 and 9 with this note.
330331
332+
> **Note (2026-11-25, [#37324](https://github.com/objectstack-ai/objectstack/issues/37324)) — item 17: the typed scope filter is `AdapterSearchOptions.scope?`, a list of terms the service builds from `scope: [{ object, ids }]` and the adapter applies before it ranks.** Item 17 is accepted with the shape below. Its open question was whether an entry may name a parent object. The maintainer ruled it on 2026-11-25 by choosing option B of the Q3 decision card, verbatim and untranslated: 「也能指定上级对象(制度)」 — 「直接给制度 id 就只在这份制度里搜;前提是知识源把指向制度的字段列为筛选字段,没列就返回空。1 个 PR,略大。」 (ruling record [`7168192820`](https://github.com/objectstack-ai/objectstack/issues/37308#issuecomment-7168192820) on #37308). So 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. A ◆ marks what this note decides past those words, for the approver to accept with it or strike.
333+
>
334+
> - **◆ The member.** `AdapterSearchOptions.scope?: AdapterScopeTerm[]`. A term is `{ kind: 'record', ids: string[] }`, which holds for a document whose `sourceRecordId` is in `ids`, or `{ kind: 'metadata', field: string, ids: string[] }`, which holds for a document whose `metadata[field]` is in `ids` or is a list with an element in `ids`. The adapter is handed terms it can apply, never `{ object, ids }`: turning an object into a field needs the object's definition, and reading that is the platform's (K1).
335+
> - **◆ Absent, present, empty**, read as item 9's `organizationIds` is. Absent: no scope; every document of the source is ranked, as before the member. Present: only the documents some term holds for are ranked, and the filter runs BEFORE ranking, so `topK` is filled from in-scope documents alone. Empty: a list with no term ranks nothing, a term with no `ids` holds for no document, and neither is ever read as "no filter". `organizationIds`, `scope` and the opaque `filter` all apply: a document is ranked only when it passes each one that is present.
336+
> - **How the service builds it**, per source, from `KnowledgeSearchOptions.scope?: Array<{ object: string; ids: string[] }>`. An entry that names the source's own object gives a `record` term. An entry that names another object gives a `metadata` term for the member of the source's `metadataFields` that points at that object, by the object's registered definition. A lookup is stored as a record id, and as a list of them under `multiple: true`, which is why a list is in scope when any element is. With no such member, or no registered definition, the entry does not reach the source. A source no entry reaches is not searched, and a `file` or `http` source answers nothing under a scope.
337+
> - **◆ Four readings the ruling's words leave open.** (1) Several entries that reach one source give several terms, and a document is in scope when any term holds: a scope names a set of records. (2) An entry that names the source's own object is the `record` term and nothing else; a field of that object that points back at it (a `tree` field, a self-lookup) adds no term. (3) Only a `lookup` or a `master_detail` field is a parent link, and the object it points at is the spec's one answer, `packages/spec/src/data/field-value.zod.ts#referenceTargetOf`. A `user` field, whose target is fixed to `sys_user`, is not one: nothing scopes by user today, and it returns by a dated note with its reader. A field assembly withholds (credential-class, `internal`) is not one either: no document carries it. (4) A source that lists two or more such fields pointing at the entry's object is not reached by it, and the service logs that once per source, naming the fields. The other answers: a union of the fields, which answers "inside this policy" with clauses that only cite it through the other field; the first field listed, which gives the order of `metadataFields` a meaning no author wrote; and a key on the entry naming the field, which has no consumer and returns by a dated note with its reader.
338+
> - **What a scope does not reach.** A parent two hops away (policy → chapter → clause) is not covered: only a field of the indexed object itself reaches a parent. A scope entry that reaches no searched source answers no hits, the same empty answer a caller gets when the source is withheld from them, so the answer never tells which of the two it was.
339+
> - **◆ The service's guarantee, whatever the adapter does.** After the adapter answers, the service checks every hit against the terms and drops the ones none holds for. It judges a `record` term on `KnowledgeHit.sourceRecordId` and a `metadata` term on `KnowledgeHit.metadata[field]`, and drops a hit that does not carry the value (fail closed). So an adapter returns the document's metadata on its hits, as `knowledge-memory` does. No capability flag is added: `capabilities.chunks` stays the one flag, and the service learns from the answer. The first time an adapter returns a hit that check drops, the service logs once for that adapter: it does not apply `scope` before ranking, or it returns hits without the document's metadata, and its scoped searches may answer fewer than `topK` (rule 2: nothing is skipped silently).
340+
> - **◆ Judged on the index copy; never an access decision.** The adapter and the service judge the same values, the ones assembly stored with the document, fresh as of the last sync, so an adapter that applies the member loses no hit to the service's check. A document indexed before its source listed the field is in no scope through it until a complete reindex writes it again. Scope narrows and never widens. The access decision stays the permission re-read of the live row, for every hit (`applyPermissionFilter` of `packages/services/service-knowledge/src/knowledge-service.ts#KnowledgeService`).
341+
> - **No new permission question.** Source admission (`packages/services/service-knowledge/src/knowledge-source-admission.ts#admitSourceFields`) already requires every `metadataFields` member an index carries to be queryable by the caller before the source is searched for them; the system identity bypasses it, as it bypasses the re-read. So "that field in ids" is a filter the caller could run on the object's own rows. ◆ The parent row is never read and need not be readable by the caller. How many hits the scope or the permission filter removed is never returned to the caller (K9 rule 6, K10 rule 4); it goes to logs only.
342+
> - **◆ The opaque `filter` stays as it is**, on `AdapterSearchOptions` and on `KnowledgeSearchOptions`: handed through, adapter-specific, and checked by nothing in the service after the adapter answers. The typed scope is never built from it, and the service's check judges the typed scope alone. Its readers in this tree are `knowledge-memory` (`matchesFilter`: metadata equality, before ranking) and `knowledge-ragflow`, which #37004 retires; no caller in this tree passes one, tests aside. Whether it retires is its own card, not this note's.
343+
> - **The suite cases the member lands with** (rule 1; `packages/services/service-knowledge/src/testing.ts#runKnowledgeAdapterContract`). On the adapter, for each term kind: filtered before ranking, so `topK` is filled from in-scope documents; an empty list ranks nothing; without the member every document is ranked, as before. Through a real `KnowledgeService`, over an adapter that ignores the member: no out-of-scope hit is answered, and the service logs once.
344+
> - **Not here.** `KnowledgeSearchOptions.scope` is an option of the service, not a member ("What counts as a member", below). #37308 bounds it, in entries and in ids per entry, with a coded refusal (ADR-0112) before any adapter is called, and states the bounds on the member so that an adapter can rely on them; this note fixes no number. The `scope` argument of `search_knowledge` is row 12, #37311 (K9 rule 2). Record-level return is #37103.
345+
>
346+
> This note adds exactly one member, `AdapterSearchOptions.scope` with its term type, and no other: the list stays closed beyond it (rules 3 and 5). #37308 builds it after this note merges, in one PR: the member, its first reader in `knowledge-memory`, and the suite cases. The code this note cites was read on `main` at `829a45e96c`. The table is left as written; read item 17 with this note.
347+
331348
**What "capabilities" became.** #36990's rule named "capabilities" among the members that waited for this record. Two things answer it. A method that is absent is the capability signal for listing, dropping, status, and the start and end of a build: the service asks whether the method is there. One flag covers what a method cannot say, `capabilities.chunks` (item 5). No wider descriptor is added.
332349

333350
**What counts as a member** (for rule 5 below, and for the epic's "no new adapter-contract member"). A member is anything an adapter author must read to be correct:

0 commit comments

Comments
 (0)