Repository navigation
feat(service-knowledge): register EMBEDDER_SERVICE from the ai.embedder_* settings when the knowledge service is mounted - #37265
Conversation
…r_* settings Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
… a real boot Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
…s for a restart Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
…olds a saved batch size to the model's documented cap Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
…ed cap; changeset names the export Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 6 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 12 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 285d66db0ed4f811f9046947a8a5c176e23bcc96 && git checkout 285d66db0ed4f811f9046947a8a5c176e23bcc96
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 98bda0ac17dbde835e8be577d7d4238e6cf77201 f6a93ede0566eb2738fffa91bb93b4e88b2236fa && git checkout -B drift-repro 98bda0ac17dbde835e8be577d7d4238e6cf77201 && git merge --no-ff f6a93ede0566eb2738fffa91bb93b4e88b2236fa
node scripts/docs-audit/affected-docs.mjs --json 98bda0ac17dbde835e8be577d7d4238e6cf77201
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Implemented-by: VERDICT: FAIL |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — REWORK · L1 · head
|
… Azure; number keys read from text; boot line names the endpoint host Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
…r keys from text; changeset Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYofJfCPWsxaVYkmaVF Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Implemented-by: VERDICT: PASS |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
Conflict in content/docs/ai/knowledge-rag.mdx resolved by keeping both sections: "Configuring the embedder from Settings" (this branch) and "Splitting documents into passages" (origin/main). Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Reviewed-by: VERDICT: PASS |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Landing · 2026-11-26T00:06Z · head |
… hit's title is the object's display field (objectstack-ai#37301) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8HtXJcvyDnGVcP1BL7DwnBY)_ Fixes objectstack-ai#36993 Fixes objectstack-ai#36994 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在挂了知识库的应用里,一个人能看的记录很少时,AI 检索不再返回空或只剩一两条,而是继续往后找,补满到要的条数;命中结果的标题改为取对象的名称字段(比如客户的「名称」、发票的编号),不再只认名为 title 的字段。 - 为什么做:知识检索平台化专题的第一、四阶段两张卡,同一个文件一起修;「按记录返回」那张卡要在这次的补齐逻辑上继续做。 - 出错会怎样:最坏是检索多读一轮、稍慢,或某条命中没有标题。权限检查只多不少:名称字段对某人不可查时,这个知识源对他不检索;旧索引里的标题还取自名为 title 的字段,所以在索引重建之前,title 字段对某人不可查时同样不检索。可以直接撤回。 - 要你做的:无。 ## What changes **Search refills after the permission filter (objectstack-ai#36993).** `KnowledgeService.search` re-checks every object-source hit as the caller *after* ranking, so a caller who may read few of the matching rows was answered from what was left of `topK` ranked hits. Now: - When the re-check can remove hits (a caller who is not the system identity, with a data engine bound), each `object` source is asked for `topK × SEARCH_FIRST_ROUND_FACTOR` (5). - When the survivors name fewer than `topK` records (several passages of one record count once: an object hit is its source and record id, any other hit its document), every `object` source that answered as many hits as it was asked (the only ones that may hold more) is asked once more, for `topK × SEARCH_REFILL_FACTOR` (20, the cap). That round's answer replaces the source's first-round hits; a source whose refill throws keeps its first-round survivors. At most two rounds; an adapter that caps `topK` answers fewer than asked and is never asked again. - A `file` / `http` source is asked for `topK` once (the re-check never removes its hits). The system identity gets one round of `topK`, no refill. No context: object sources stay unsearched, as before (fail closed). - The answer is still at most `topK` chunk-level hits, sorted by score; `search`'s return type is unchanged (`expectTypeOf` pin). The count the re-check removed is logged at `debug` only, never returned. - The adapter loop moved into a private `searchRound`, unchanged in behaviour (foreign-source hits dropped and warned, a throwing adapter logged and skipped). **A hit's title is the object's display field (objectstack-ai#36994).** `recordToDocument` read `record.title`. Per ADR-0161 K5 ("the title is the object's display field"), it now reads the field `documentTitleField(schema)` names: `resolveDisplayField` (ADR-0079: `nameField`, its deprecated alias, else the derivation), and with no object definition a field named `title`, as before. A withheld field (credential-class or `internal`), an empty value, a value that is not text or a finite number, a definition that resolves no display field, or a `nameField` the definition does not declare gives no title. `resolveRecordDisplayName` is not used: its `Record #id` floor is a UI label. The source admission's field gate (`servedFieldsOf`) asks about the same field through the same `documentTitleField`. So a source whose object's display field the caller may not query is not searched for that caller at all. It also keeps asking about a declared field named `title`, as before: documents indexed under the earlier rule carry that field's value as their title and stay in the index until a complete reindex writes them again, and nothing reindexes at boot. That arm is retired once the index is proven rebuilt under the display-field rule (the recipe hash that names the title rule, ADR-0161 K7, and the rebuild of a stale source, objectstack-ai#37099); the code comment says so. Docs: `content/docs/protocol/knowledge.mdx` states the refill and its cap, and the display-field title (three places that said "the record `title`"); `content/docs/ai/knowledge-rag.mdx` says the same in two sentences. `content/docs/permissions/system-context.mdx` row 46 keys `search` too (it now reads `isSystem`: the system identity skips the over-fetch and the refill), and its generated register is regenerated (`check:system-context-census --write`). ## Tests `packages/services/service-knowledge`: `pnpm test` 8 files / 219 tests passed at 4621738; `pnpm typecheck` exit 0 (incl. `check:test-typecheck`). New pins in `knowledge-service.test.ts` (two top-level describes) and `knowledge-source-admission.test.ts` (one): - 100 hits, the caller may read 5 spread across them → those 5, best first; asked `[s1, 25]` then `[s1, 100]`. - A readable row beyond the cap → fewer than `topK`, never a third round. Enough survivors → no refill. An adapter capping at 10 → asked once. Several sources → only the saturated one refilled. The refill decision counts records: topK 3, one source answers two passages of one readable record, another holds a readable record past its first round that outranks both → it is refilled and answers `[s1-c0, s1-c15, s2-a]`. A failed refill keeps round one. System identity → one round of `topK`, no re-check. No context → only the file source, asked `topK`. A file source beside an object source → asked `topK` once. - Removed count only in the `debug` log; answer and return type unchanged. - Title: explicit `nameField`; derived `name` over `title`; formula (text) and autonumber name fields (a number value → its text); withheld internal / secret name fields; empty, non-text, unresolvable and undeclared-`nameField` cases; no definition → `title`; the event sync and the reindex walk read the definition off the engine. - Field gate: hiding the display field refuses the source even with `title` visible; hiding a declared `title` that is not the display field refuses it too (the adapter returns a stored hit carrying an old-rule title, and the answer is empty); a caller who may query both gets the hit. <details><summary>Ablations: each committed first, mutated through scripts/ablation-replace.mjs, restored to HEAD with git diff HEAD empty</summary> - Refill disabled (`if (false && filtered && kept.length < topK)`): 6 refill tests red, 5 green (the ones that pin "no refill"). - Title back to `record.title`: 5 title tests red. - Field gate back to `title` only: both display-field gate tests red. - Refill decision back to counting hits (`kept.length`): the record-counting test red, 150 green. - The declared-`title` arm deleted from the gate: its refusal pin red, 24 green. </details> ## Acceptance notes - **objectstack-ai#36993 point 2 is applied to the refill decision only.** The answer stays at most `topK` chunk-level hits (`KnowledgeSearchOptions.topK` is "Max number of hits to return"; `search_knowledge` returns "at most `topK`" passages; the card: "what is returned stays chunk-level hits"). Counting records decides whether to refill, and with several sources that changes the answer: another source's refill can outrank a second passage of a record already counted (pinned above). - **The declared `title` arm of the field gate is temporary.** Retire it when the index is proven rebuilt under the display-field rule (ADR-0161 K7 recipe hash, objectstack-ai#37099). - **Title egress** (the question raised on objectstack-ai#36994): ADR-0161 K5 declares the title as the object's display field, so it is sent whether or not the source lists that field among its content fields. It is withheld when the field is credential-class or `internal`. The field-egress declaration of cloud ADR-0119 does not exist yet; when it does, `documentTitleField` is the one place assembly and the gate both read. - The title enters `docHash`, so the first complete reindex after this lands rewrites the documents whose title changed. - Seat 4's objectstack-ai#37287 edits the same file; `scripts/pm/overlap-check.mjs` merges this branch with its head cleanly (the search factors sit beside `LIST_DOCUMENTS_PAGE_SIZE` to stay clear of its new constant). ## Verification Files to read first: `packages/services/service-knowledge/src/knowledge-service.ts` (`search`, `searchRound`, `documentTitle`), `knowledge-source-admission.ts` (`documentTitleField`, `servedFieldsOf`). Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/knowledge-service.test.ts -t refills` — 11 tests pass; the first shows a caller reading 5 of 100 hits getting all 5. <details><summary>Local gate families: the derived list (scripts/pm/dispatch-gates.mjs --commands, 98 commands, derived at ecb0842), run in order; CI runs the full farm</summary> - Rework round (4621738): package test 8 files / 219, typecheck 0, eslint on the four changed source and test files 0, check:doc-anchors 0, check:system-context-census 0, overlap-check clean against origin/main, objectstack-ai#37287 and objectstack-ai#37265. - 79 of 98 run: 76 exit 0; 3 PREREQUISITE NOT MET (not verdicts, NOT MEASURED locally, CI builds them): check-plugin-teardown-shape --self-test (shallow clone cannot reach its pinned fixture commit), spec check:skill-examples (client-react dist not built), check:dual-build-cjs-loads (hono / account dist not built). - The remaining 19 (the repo-wide eslint-backed ratchets onward) were still running when this was written: NOT MEASURED locally; their CI check-runs are the reading. - Also run: package typecheck (exit 0, incl. check:test-typecheck), eslint on the four changed source and test files (exit 0), check:doc-anchors (exit 0), check:system-context-census (exit 0 after row 46 below), scripts/pm/overlap-check.mjs (clean against origin/main, objectstack-ai#37287 and objectstack-ai#37265). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbWqwmAwx7eD4Xf3dv1 --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbWqwmAwx7eD4Xf3dv1)_ <!-- signed: repo:cloud#1 · os-warren · session_01JQwxbWqwmAwx7eD4Xf3dv1 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
… Chinese-aware), the chunk channel and the split key; KnowledgeChunk.metadata and knowledge.chunk_overlap retired (objectstack-ai#37287) repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Fixes objectstack-ai#37098 Clause-②: yes (narrowing) — widens the knowledge contract (the `split` key, `chunks`, `headingPath`, the adapter's `capabilities` and `embedding`, `IEmbedder.maxInputTokens`, the reindex `failed` / `failures`) and narrows two accept sets: `KnowledgeChunk.metadata` is refused, and `knowledge.chunk_overlap` is no longer a key of the `knowledge` settings namespace Metadata-protocol: narrowed Skills-docs: follow-up objectstack-ai#37292 — `skills/objectstack-ai/SKILL.md` does not yet teach `split` or name the two retired keys; that file is governed and outside this claim. `content/docs/protocol/knowledge.mdx` (new §3.5) and `content/docs/ai/knowledge-rag.mdx` document it here. ## 维护者速读 - 用户能看到什么变化:知识检索在建索引时由平台统一把文档切成片段,长制度按章、条切开,中文按句号问号断句,不会切在「3.2 条」「400.50 元」中间,也不切开表格。 - 为什么做:属于「知识检索平台化」专题第二阶段,让每种存储拿到的片段完全一致。 - 出错会怎样:整篇切法下超过模型上限的文档会从检索中移除并报失败,不会被截断;设置页的「片段重叠」一项被移除(它从未生效),片段上一个从未被使用的字段也被移除,写了它的代码会收到带修复说明的报错。 - 要你做什么:无。 ## What changes - **One splitter in the service** (`packages/services/service-knowledge/src/split/`): `whole`, `recursive` (blank line, line break, sentence end, semicolon, character; Chinese-aware sentence rule; tables and list items kept whole while they fit; short pieces merged up to `minChars`), and `markdown` (one section per heading, the heading path embedded at each passage's start and carried as `headingPath`). - **The chunk channel, as ADR-0161 K8 item 5 settled it.** `KnowledgeDocument.chunks?`, `KnowledgeChunk.headingPath?`, and `IKnowledgeAdapter.capabilities?.chunks`. An adapter that declares it gets every document with the service's passages; one that does not keeps receiving whole documents. `indexDocument` refuses caller-supplied `chunks`, as it refuses `docHash`. - **The limit, per ADR-0161 K8 item 6.** `IKnowledgeAdapter.embedding?.maxInputTokens` and `IEmbedder.maxInputTokens?`, read at use, never cached. `embedder-openai` reports its limit from the objectstack-ai#37093 table. A passage keeps `maxChars` (`split.maxChars`, else `knowledge.chunk_target`, else 800) and, when a limit is known, `estimateTokens` within 80% of it (the shared estimate, not forked). - **`whole` over the budget is removed and reported, never truncated.** `reindexSource` gains `failed` and `failures` (at most 20 named). The event sync logs at `error` with source, record id, estimate and limit. `indexDocument` throws. - **The `split` key**, ADR-0161 K8 item 10: `ObjectKnowledgeSource.split?: { strategy, maxChars?, minChars? }`, read by the splitter. - **`knowledge-memory` drops its own chunking.** It declares `capabilities.chunks` and indexes the service's passages as given. - **Settings.** `knowledge.chunk_target` gains its reader, through the `settings` service at use, never at boot. It is now shown for the in-memory adapter too. `knowledge.chunk_overlap` is retired the way the Localization format keys were: removed from the manifest and its 11 translations, `version` 1 to 2, a stored row kept, a write refused `400 UNKNOWN_KEY`. - `docHash` keeps its recipe: the passages are derived from `content` and do not enter it. ## BREAKING - `KnowledgeChunk.metadata`: FROM an optional record, accepted and stripped, TO a `retiredKey()` tombstone (a parse refusal with the prescription; `tsc` types it `never`). Nothing wrote or read it. Fix: delete the key; filter on the document's `metadata`. ADR-0161 K8 item 5, by seat direction 7158283273. - `knowledge.chunk_overlap`: FROM a key of the `knowledge` settings namespace TO no key (not shown or resolved; a write is refused `400 UNKNOWN_KEY`; a stored row is kept). Nothing read it. Fix: stop writing it. Retirement kit, per the `spec-property-retirement` skill, under protocol major 18 (seat ruling A): - the `retiredKey()` tombstone; - `RETIRED_KEYS_BY_MAJOR[18]` row `ai/KnowledgeChunk:metadata`; - D3 `knowledge-chunk-metadata-retired` and its `STEP18_RATIONALE` fragment; - the `[RETIRED]` line in `authorable-surface/ai.json`; - the regenerated reference; - the pin `packages/spec/src/ai/knowledge-document.test.ts`; - the changeset's `adr-0087: registered` marker. No D2 conversion: a chunk is a runtime contract shape, never stored in stack metadata, so `os migrate meta` has no source to rewrite — the `ActionDescriptor.isAsync` disposition. The settings key follows the Localization format keys' retirement: specifier and 11 translations removed, manifest `version: 2`, stored rows kept. ## Tests - `split.test.ts`: six golden files (Chinese regulation with 章/条, a Markdown table, a long unpunctuated run, mixed zh/en with quotes, 「3.2 条」 and 「400.50 元」, a Markdown heading tree), direct assertions of each rule, and a seeded property test. Over 500 random documents with random bounds, no passage's estimate exceeds the budget or the limit, no passage exceeds `maxChars`, and `recursive` loses no text. A `whole` property test runs 200 more. - `contract-stubs.test.ts`: the contract suite against two stubs. One declares no capability and is pinned to receive whole documents, never `chunks`. The other declares `chunks` and stores passages as given. - `testing.ts`: the suite gains the chunk-channel cases. With chunks, the adapter receives exactly `splitDocument`'s passages and a hit is one of them by id and text; `whole` over the budget is removed and reported; caller chunks are refused. Without chunks, whole documents arrive. `knowledge-memory` runs it with `chunks: true`. - `chunk-channel.test.ts`: the event path at `error`; `indexDocument` over the budget; the bounded `failures`; the `maxChars` precedence; the descriptor read at use; and end to end, `chunk_target` saved after boot cuts the next write through the real settings service. - `openai-embedder.test.ts`: the reported limit. `knowledge.manifest.test.ts`: `version` 2 and `chunk_overlap` absent. - `packages/spec/src/ai/knowledge-document.test.ts`: the retired `KnowledgeChunk.metadata` is refused at parse with the prescription (also inside `KnowledgeDocument.chunks`), a chunk without it parses clean, and authoring it is a `@ts-expect-error`. The local readings sit in the os-dev report comment on this PR. ## Acceptance notes - **`KnowledgeChunk.metadata` is retired here** (seat direction 7158283273, option B; registered under protocol major 18 by the seat's ruling A). The claim was re-issued as `Metadata-protocol: narrowed` (7158315677). - **No refinement for `minChars` ≤ `maxChars`.** The published JSON Schema cannot carry it, and the baseline that declares a dropped refinement is outside this claim. A `minChars` above the effective `maxChars` reads as `maxChars`, documented on the key. - **A table that does not fit** is cut between rows, each piece repeating the header. A list item that does not fit is cut as a paragraph. The budget is the hard bound. - **Re-splitting.** `docHash` does not cover passages, so a changed `split`, `chunk_target` or limit re-splits a document only when the document itself changes. The index fingerprint (ADR-0161 K7; objectstack-ai#37100) rebuilds a source on a split change. The docs say so. - **Merged with objectstack-ai#37256** (the organization filter) through `scripts/pm/os-regen-merge.sh`, keeping both sides: - `organizationId` next to `chunks`; - the organization filter before ranking, over the service's passages; - `implements: { listDocuments, chunks, organizationIds }`; - `resolveTenancyPosture` next to `resolveChunkTarget`. - **objectstack-ai#37265 still shares files**, a declared serial constraint: whichever lands second merges main. - Two test pins outside the claim's literal file list moved with the ordered retirement, both deliberate tripwires on the manifest: `settings-visibility-declaration.pin.test.ts` (90 to 87 predicates) and `knowledge.manifest.test.ts`. ## Verification Read first: `packages/services/service-knowledge/src/split/splitter.ts` (the sentence rule, the block-aware merge, the even character cut); `knowledge-service.ts` `prepareDocuments` / `writeSynced` and the walk's failure branch; `packages/spec/src/contracts/knowledge-adapter.ts`. Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/split.test.ts`. Expect 25 passed, then open `src/__tests__/fixtures/split/regulation-zh.tight.golden.json` and see each 章 title leading its own chapter. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYoHKp8EUQtketT9S29)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
…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>
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
Fixes #37094
Clause-②: yes (widening) —
@objectstack/embedder-openaigains one export,documentedMaxBatchSize(model): number | undefinedMetadata-protocol: none
维护者速读
What changes
KnowledgeServicePluginregistersEMBEDDER_SERVICEfrom theai.embedder_*settings (packages/services/service-knowledge/src/knowledge-service-plugin.ts). Read once, atkernel:bootstrapped:infoline, settings not applied. A registration the sync accessor cannot hand out (an async factory) counts as registered too.@objectstack/embedder-openaiembedder for the saved provider. The saved Base URL applies to the custom and Azure providers; every other provider uses its preset endpoint. The boot line names the endpoint host. "Saved" = any layer but the manifest default (source !== 'default', the same readingplugin-emailuses forbranding.workspace_name); anOS_*override counts as saved. "Complete" = the settings page's own Test embedder check (aiTestEmbedderActionHandler), handed only the saved values: reused, not forked.Math.min(saved, documentedMaxBatchSize(model))when the saved model has a documented cap, the saved size as saved otherwise (no saved model, or a model the table does not know).OS_AI_EMBEDDER_DIMENSIONS=256override). Any other saved value is refused:EMBEDDER_SERVICEis theUnconfiguredEmbedder, with awarnboot line naming the key.nonesaved, incomplete, settings service absent, or theainamespace without the embedder keys) → anUnconfiguredEmbedderis registered:embed()(non-empty) anddimensionsrefuse with a message naming the missing settings, where to save them and that a restart is needed. Boot succeeds; nothing is sent. Boot line isinfowhen nothing asked for an embedder,warnwhen saved settings do not build one.descriptiononembedder_providerinai.manifest.ts("Read when the server starts: a saved change to any embedder setting takes effect after the next restart."), and itshelpcopy in all 11 locale bundles. The translations are required by the gate:settings-translation-coverage.test.tsreds a described field with nokeys.KEY.helpin any locale.@objectstack/embedder-openaiexportsdocumentedMaxBatchSize(model): number | undefined(seat direction, issue comment 7156326561): the documented per-request cap, read from the SAME module tableOpenAIEmbedderbatches by. No copy, and the constructor now reads the table through the same function.OpenAIEmbedderis unchanged: an explicitmaxBatchSizeis still used as given, above the cap included (pinned).content/docs/ai/knowledge-rag.mdxgains "Configuring the embedder from Settings".@objectstack/service-knowledge→@objectstack/embedder-openai. Why this side: service-knowledge already depends oncore(plugin contract) andservice-settings(the settings reader and the reused completeness check), so the knowledge plugin needs exactly one new edge; a plugin inembedder-openaiwould needcoreandservice-settings(two edges, a crypto library among the transitive ones) and a host would have to mount it by hand, which is the gap the card is about. Services depending on plugins has precedent (service-storage,service-print,service-automation).embedder-openaidepends only onspec: no cycle.Why
kernel:bootstrapped(the phase measurement)ObjectKernel.bootstrap()/LiteKernel.bootstrap()run everyinit(), then everystart(), thenkernel:readyhandlers in plugin order, thenkernel:bootstrappedonce everykernel:readyhandler has settled (plugin-lifecycle-events.ts). An embedder registered ininit(),start()or anykernel:readyhandler (where a settings-reading provider would register, since the settings engine binds inkernel:ready) is therefore visible atkernel:bootstrapped, regardless of plugin order. Pinned both ways: a host embedder registered atinitand one registered in akernel:readyhandler are each kept. Only a registration inkernel:bootstrapped/kernel:listeningor after boot would collide; the changeset says so. Settings are read afterkernel:readyfor the same reason the settings plugin documents: a read in the pre-bind window answers the default without consulting the store.Cloud reading (cloud-confirm 7159003875 on #37094, read at cloud main
packages/service-ai/src/plugin.ts):service-aiapplies its embedder in akernel:readyhook (bindSettings→applyEmbedder), so its boot-time registration comes before this placeholder exists. Every lateraisettings save callsreplaceService, neverregisterService, so it replaces the placeholder without throwing. A cold boot with a configured provider still logs the existing[AI] Failed to apply embedder settingswarning, as it does on main with nothing registered; the placeholder does not make that worse. No cloud deployment mounts the openKnowledgeServicePluginbesideservice-ai.Tests
New top-level
describein the knowledge+settings harness file (src/__tests__/knowledge-settings-contribution.test.ts), through the real registration path: settings SAVED viaSettingsService.setManyin akernel:readyhandler, provider reached through a stubbed globalfetch, and an adapter that looks upEMBEDDER_SERVICEwhere it embeds. No hand-built embedder.indexDocumentsends onePOST https://api.openai.com/v1/embeddingswith the saved key and model; nothing sent at boot; key in no log lineinit/ atkernel:ready→ same instance kept, zero requests, oneinfolinetext-embedding-v3→ requests of 10, 10, 5 (not one of 25: the default 64 is not a saved value)text-embedding-v3(documented 10) → requests of 10, 10, 5, and the boot line names the saved 64embedder-openai:documentedMaxBatchSizeanswers 10 / 2048 /undefined(unknown, and a prototype key); the embedder with nomaxBatchSizebatches at exactly that value; an explicitmaxBatchSize: 25on a cap-10 model still sends 25indexDocumentand the adapter'ssearchreject namingai.embedder_providerand the restart;KnowledgeService.searchanswers[]and logs that error per source;dimensionsrefuses; zero requests; boot lineinfononesaved → refusal says so; incomplete (provider without key) → the page check's own message, boot linewarnendpoint=api.openai.comOS_AI_EMBEDDER_DIMENSIONS=256(arrives as text) →dimensionsis 256 and the request carriesdimensions: 256OS_AI_EMBEDDER_DIMENSIONS=large→ refused namingai.embedder_dimensions, awarnboot line, zero requestscustomwithout a Base URL), and a provider answering 401Ablations (one-shot,
scripts/ablation-replace.mjs, each mutation landed and restored to blob == HEAD,git diff HEADempty):if (!entry) return undefined;) → 1 failed / 15 passed: exactly "an unsaved batch size on a model with no documented cap is the embedder fallback, not the default 64".Math.minline →savedBatch) → 1 failed / 15 passed: exactly pin (a). The first attempt at this one was a no-op: the replacement text already occurred in the anchor, the tool refused before running, and it was re-run with a distinct replacement.'256'case.'large'case.Acceptance notes
embedder-openai. With no saved model the embedder uses its own default model; no cap is looked up for a model the plugin does not name, so the saved size passes as saved. The field's maximum (2048) equals that default model's documented cap.packages/services/service-knowledge/vitest.config.tsgains one alias for@objectstack/embedder-openai(without itcheck:test-source-aliasreds: the tests would read the embedder'sdist/);pnpm-lock.yamlrecords the new workspace edge.KnowledgeService.searchalready catches a per-source adapter failure, logs it aterrorand answers no hits from that source; with no embedder that logged error is the named reason. Indexing throws it. That catch lives inknowledge-service.ts, outside this card.EMBEDDER_SERVICEyet (knowledge-memoryuses its own sparse vectors;knowledge-ragflowembeds server-side), so in the open edition today the registered embedder is used by custom adapters and by the coming pgvector adapter. TheEMBEDDER_SERVICEdoc comment inpackages/spec/src/contracts/embedder.tsstill says it is "Registered by@objectstack/service-ai"; spec prose was not touched here.Verification
Two-minute check:
pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/knowledge-settings-contribution.test.ts -t 37094→ 16 passed.Read first, by risk:
knowledge-service-plugin.tsprovideEmbedder()andembedderFromSettings(): the phase, the registered check, the saved-vs-default reading, the clamp.UnconfiguredEmbedder: a registered placeholder meansEMBEDDER_SERVICEis never absent once the knowledge service is mounted.embedder-openai/src/index.tsdocumentedMaxBatchSizeand the constructor's use of it.Local readings, head
fa818f4d(service-settings and the dispatch-gates run atf329965b; the later commits touch neither service-settings nor the derived gate set):Package tests, typecheck, derived gates
pnpm --filter @objectstack/embedder-openai test→ 31/31; build +typecheck(tsc +check:test-typecheck) exit 0.pnpm --filter @objectstack/service-knowledge test→ Test Files 8/8, Tests 186/186;typecheckexit 0, 0 errors.pnpm --filter @objectstack/service-settings test→ Test Files 77/77, Tests 1523/1523;typecheckexit 0 (head35c742d2; the later commits do not touch service-settings).node scripts/pm/dispatch-gates.mjs --commands(21 paths): 115 commands, each exit captured before any pipe: 114 exit 0, among themcheck:startup-registry-verdict,check:test-source-alias,check:undeclared-dep-imports,check:workspace-manifest-cycles,check:published-readme-links,check:dual-build-cjs-loads,check:settings-bind-window,check:doc-authoring,check:issue-citations,check:nul-bytes,check:changeset-fixed,check-empty-changeset,check-changeset-no-major,check-adr-0087-registration,check:type-check-coverage.check-plugin-teardown-shape --self-test(shallow clone cannot read its pinned fixture).dispatch-gates --ran: 115 derived, 115 run, 0 unrun.pnpm lint) and dogfood are CI's (no!in the title, no narrowing arm).Signed: repo:objectstack#4 · os-justin · session_01QSeKYofJfCPWsxaVYkmaVF
Provenance
Opened by seat repo:objectstack#4 on the maintainer's authorization in the seat session (「#37094 开 PR 被拦:放行」). The developer's own
pr_createin zone a4-K's dev session was refused twice by a permission check; the dev stopped without retrying and handed the material over. Branchclaude/issue-37094-open-embedder-settings@fa818f4d40749e28de09bbd747e9ca3c829f17ed.Human Minimum
packages/specholds no runtime logic. (spec untouched)pnpm lintpasses. (No formatter ran;pnpm lintwas not run locally — CI's run decides.)main, one pull request.packages/spectouched: n/a.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ