Skip to content

Commit 91fc398

Browse files
feat(service-knowledge)!: a knowledge service the runtime mounts holds its sources without an embedder or its deployment store (#38470)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X6jdZukAJaWgnbQHnPWHxMw)_ Refs #38369 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #38475 ## 维护者速读 - 自托管部署如果没配嵌入模型(或部署的知识存储没挂上),知识源现在只列出、不构建、不同步、不检索,智能体工具里也不再出现 `search_knowledge`;启动日志说一次缺了哪一半、怎么补。以前这种部署照样启动构建和同步,工具也列出来,但每次构建和检索都报错。 - 属于知识库检索这条线,执行您对 #38368 的裁决(四点全按推荐 1A 2A 3A 4A)和 ADR-0161 K8 的日期注记"挂载不等于启用"。这是三单中的第一单:先把"不服务"做实;保存时拒绝(第 2 单)和状态/命令行文字(第 3 单)随后各开一单。 - 只影响运行时自动挂载知识服务、且缺嵌入模型或知识存储的部署;配齐两半的部署、以及宿主自己挂载知识服务的部署行为不变;从不阻止启动;出问题可整单撤回。 - 要你做的:批准这次收窄(按审批流程)。 ## What changes The authority is the ADR-0161 K8 dated note on item 12 (PR #38401, 0c1b2ff), with ruling 7248214179 (amendment 7248231750, points 1–4) and build notes 7248592159 (points 1–4). This PR is part 1 of the three serial PRs the card names: items 1–2, ruling points 2–3, build notes 1, 2 and 4. Part 2 (the save refusal: item 3, points 1 and 4, build note 3) and part 3 (items 4–5) follow from `main` after this merges. - **Enabled by configuration, read once at boot** (`packages/services/service-knowledge/src/knowledge-service-plugin.ts`). The capability composition (`packages/core/src/capability-composition.ts`) now passes `runtimeComposed: { declared }` beside `deploymentAdapter`; `declared` is true only when the stack lists `knowledge` in `requires`. With `runtimeComposed` set, the plugin reads at `kernel:bootstrapped`, after every store's `start()` registered its adapter: an embedder is available (another plugin registered one, or the saved `ai.embedder_*` settings build one) and the deployment's store is mounted (an adapter of `deploymentAdapter`'s id is registered). Both ⇒ the boot goes on as today. Either missing ⇒ held. A plugin a host mounts (no `runtimeComposed`) is untouched: it serves from the start, as before. - **Held** (`packages/services/service-knowledge/src/knowledge-service.ts`, `KnowledgeService.settleEnablement`). Every source, whichever store it names (point 2: an application-registered store too), is loaded and listed, and never built, synced, reconciled or searched: the boot build, the reload build, the reconcile pass and its job, the record sync (enqueue, upsert, delete and the queued worker), the predicate-write note and the unmounted-adapter report all return. A dropped source keeps its index (a warn line says no store is called). `search`, `rebuildSource` and `reindexSource` throw `heldSourcesError`: status `503`, code `SERVICE_UNAVAILABLE`, and a message naming the missing half and the fix (build note 2). - **No reap guard and no store call while not enabled** (point 3, build note 1). The lifecycle reap guard used to register at `kernel:ready`, before the reading; the lifecycle service has no unregister. A runtime-composed plugin now registers it only once the reading says enabled. Held, a retention sweep deletes on time and calls no store. - **One boot line**, never a boot refusal (ADR-0078 §4). `info` when only a shipped `knowledge_source` mounted the service and nothing was saved; `warn` when the stack declares `requires: ['knowledge']`, when a saved embedder provider builds nothing (a provider saved without its key), or when the store is not mounted. The embedder's own boot line is not also said when held. - **No tool definition while pending or held** (`KnowledgeService.knowledgeTools()` answers `definitions: []`). HTTP MCP reads the definitions per request, so it lists `search_knowledge` only once enabled. - **stdio** (`packages/mcp/src/plugin.ts`, build note 4). The stdio bridge reads the tool in its own `start()`, before the reading, so a runtime-composed service hands out nothing there. `MCPServerPlugin` now registers `search_knowledge` at `kernel:listening` (after every `kernel:bootstrapped` handler) only when the service then hands out its definition. Fail-closed: an unknown state reads as absent, never listed and then withdrawn. The MCP SDK takes a tool after the transport attached and sends `notifications/tools/list_changed`; skill prompts read the served tools at each listing. A host-mounted service's tool still registers in `start()`, once. - **ADR-0087**: `packages/spec/src/migrations/entries/semantic/19.knowledge-service-held-without-embedder-or-store.ts` (notice only, no D2 conversion: the fix is the deployment's configuration, never the item). The changeset carries `registered` with that id. ### Boot window Between `kernel:ready` and `kernel:bootstrapped` the reading is pending. In that window no tool definition is handed out (fail-closed); a record write's sync behaves as today (it embeds through the stand-in embedder, which refuses). Gating starts when the reading settles. No reap guard registers in that window on a runtime-composed plugin. ### Point 2 measurement None of `@objectstack/verify`'s `harness.required-providers` cases reads as held: every one registers an embedder. The file is unchanged and its 16 cases pass. ### Docs `content/docs/ai/knowledge-rag.mdx`: a "Mounted is not enabled" bullet under *Turning it on* (held state, the boot line and its level, the remedy, host-mounted not held), a clause on the "Nothing is configured" embedder bullet, and one sentence under *The `search_knowledge` tool* (not listed while held; on stdio registered after the reading, with `notifications/tools/list_changed`). `content/docs/protocol/knowledge.mdx`: a "Mounted is not enabled" paragraph after *What mounts the service*, and the reap-guard section says a runtime-composed service registers no guard until it is read as enabled. Added after sibling #38439 (#38351) merged (f19ee34), with `main` merged in first. `skills/objectstack-ai/SKILL.md` is out of scope: follow-up #38475 rewrites its knowledge wording once, from `main`, after part 3. ## Tests - `packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts`, new describe "a runtime-composed knowledge service is enabled by configuration", booted on `LiteKernel` with a store plugin that counts every call (10 cases): held with no embedder saved (one `info` line, zero store calls after writes and a delete); no `search_knowledge` definition, search answers `503 SERVICE_UNAVAILABLE` naming the missing half, rebuild refused; `requires: ['knowledge']` ⇒ `warn`; a provider saved without its key ⇒ `warn` (build note 3's state, read here; its save refusal is part 2); store not mounted ⇒ `warn`; both halves missing named together; point 2 (an application-registered store is held too); controls: enabled through a host-registered embedder and through saved settings (built, definition handed out); a host-mounted plugin builds as before. - `packages/services/service-knowledge/src/__tests__/reap-guard.test.ts` (point 3, build note 1): held ⇒ `registerReapGuard` never called and the retention sweep deletes `k1`, `k2` on time with no store call; control: enabled ⇒ the guard registers for `['task']` after the reading and de-indexes before the delete. - `packages/mcp/src/mcp-knowledge-tools.test.ts` (build note 4): HTTP lists the tool only once enabled (pending, held: absent; host-mounted: listed from the start); stdio through `MCPServerPlugin` with the boot hooks fired by hand: held is never listed and no `list_changed` is sent; enabled registers at `kernel:listening` with `notifications/tools/list_changed` and the same description; host-mounted registers once in `start()`. - `packages/runtime/src/mcp-knowledge-tools-bridge.test.ts`: the runtime bridge reads the definitions per listing (pending and held `[]`, enabled `['search_knowledge']`). - `packages/core/src/capability-composition.test.ts`: `runtimeComposed: { declared }` is passed, `declared` only when the stack lists the token. - `scripts/engine-double-contract.pinned.json` learns the stdio double's `findOne` pin (the double routes through `assertEngineFindOnePredicate`). ## Verification **Final head `4659f2a369`** (`main` merged twice since `72a9cbfb6a`, for #38439 and #38436; plus the docs commit). At that head, under the lock: closure build exit 0; `@objectstack/service-knowledge` `pnpm test` 751 passed; `@objectstack/mcp` `pnpm test` 1655 passed; core 26, runtime 7, verify 16 passed; typecheck exit 0 for service-knowledge, core, mcp and runtime; `check:engine-double-contract`, `check:slot-lookup`, `check-adr-0087-registration` (entry at or above PROTOCOL_MAJOR 19), spec `check:docs`, `check:doc-authoring`, `check-affected-docs`, `check:adr-anchors` exit 0. **Dogfood battery at `4659f2a369`: VERDICT command-exit 0 · Test Files 495 passed, 3 skipped (498) · Tests 4183 passed, 68 skipped (4251) · 0 failed.** CI at `4659f2a369`: 62 check-runs success, 10 skipped, none failed. The readings below were taken at `72a9cbfb6a` and stand where noted. Shared container; every build and test ran through `scripts/pm/os-verify-lock.sh`. <details><summary>Tests and typecheck at 72a9cbf</summary> - Closure build (`pnpm --filter '@objectstack/dogfood^...' --filter '@objectstack/cli...' --filter '@objectstack/lint...' build`): VERDICT command-exit 0. - `@objectstack/service-knowledge` `pnpm test`: Test Files 21 passed, Tests 738 passed; `typecheck` exit 0. - `@objectstack/mcp` `pnpm test`: Test Files 88 passed, Tests 1655 passed; `typecheck` exit 0. - `@objectstack/core` `capability-composition.test.ts`: Tests 26 passed; `typecheck` exit 0. - `@objectstack/runtime` `mcp-knowledge-tools-bridge.test.ts`: Tests 7 passed; `typecheck` exit 0. - `@objectstack/verify` `harness.required-providers.test.ts`: Tests 16 passed (point 2 measurement above; file unchanged). - `@objectstack/cli` `plan.artifact-item-capabilities.test.ts`, `boot-preparation-parity.test.ts`, `migrate-meta-engine-guidance.test.ts`: Tests 44 passed. - `@objectstack/spec` `typecheck` exit 0 (migration registry regenerated with the new entry). - ESLint over every changed `.ts` file: exit 0. </details> <details><summary>Ablation</summary> At `2d6c3dfd` (plugin unchanged since): `scripts/ablation-replace.mjs` replaced `const held = this.settleEnablement(ctx, this.service, embedder);` with `const held = false; void this.settleEnablement;`. The runtime-composed describe went 9 failed / 1 passed (the host-mounted control stayed green). Restored; blob back to HEAD, `git diff HEAD` empty. </details> <details><summary>Dogfood battery at 72a9cbf</summary> `pnpm --filter @objectstack/dogfood test` under the lock: VERDICT command-exit 0 · Test Files 495 passed, 3 skipped (498) · Tests 4183 passed, 68 skipped (4251) · 0 failed. </details> <details><summary>Live positive control (os dev, showcase app)</summary> The showcase mounts `KnowledgeServicePlugin` itself (host-mounted, unchanged by this PR), so for the control its two knowledge plugins and the source's `adapter: 'memory'` were commented out in the worktree only (never committed; restored with `git checkout`), which lets the runtime compose the service with the Turso store. `objectstack dev --seed-admin --log-level info` on a file database, signed in as the seeded admin: - **No embedder saved.** One boot line, `INFO KnowledgeServicePlugin: the knowledge service is not enabled on this deployment: no embedder is configured (no embedder provider is saved — …). Its sources are held: none is built, synced or searched. To enable it, save an embedder provider, then restart. 1 source(s) held: showcase-showcase_task_notes.` (hidden at the default log level, as `info` should be). No build line. `index_status` lists the source with `build: null`. The Knowledge page's rebuild action answers "was not started: [knowledge] the knowledge service is not enabled on this deployment: …". MCP over HTTP: `tools/list` 20 tools, `search_knowledge` absent. - **Embedder saved, restarted.** `PUT /api/settings/ai` saved a `custom` provider pointing at a local OpenAI-compatible stub. The boot registered the embedder, registered the reap guard for `[showcase_task]` after the reading, and built the source: "8 row(s) read, 8 written". MCP `tools/list` 21 tools with `search_knowledge`; a `search_knowledge` call answered hits from `showcase-showcase_task_notes`; the stub logged one call of 8 inputs (build) and one of 1 (search). - The boot also logs `ERROR [knowledge] the start of the build … was not recorded (Duplicate record refused on 'Knowledge Sync State' …)` whenever a build starts, host-mounted or not. That is #38418 (open, seat 1), not this change. - `index_status` still reads the adapter while held (here: `state: unreadable` with the embedder's reason). Saying "not enabled" there, and in `os knowledge status` / `rebuild`, is card item 4, part 3. </details> <details><summary>Gates at 72a9cbf</summary> `dispatch-gates --ran`: 106 derived families accounted for, 105 run with exit 0, 1 NOT MEASURED: `check:dual-build-cjs-loads` exits 3 (no `dist/` for `@objectstack/studio`, `client-react`, `scenarios`, outside this closure); CI runs it. Among them: `check-adr-0087-registration` (1 declared-breaking changeset, `registered knowledge-service-held-without-embedder-or-store`), `check-changeset-no-major`, `check-empty-changeset`, spec `check:upgrade-guide`, `check:spec-changes`, `check:api-surface`, `check:liveness`, `check:engine-double-contract` (after the stdio double's fix), `check:slot-lookup` (after typing the store plugin), `check:error-status-conformance`, `check:type-check-debt`, `check:nul-bytes`. `check-plugin-teardown-shape --self-test` exit 0 after fetching its pinned fixture commit. `overlap-check` before the push: clean against `main` and against #38439, #38435 and #38268 (#38418 has no PR yet). </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5m2rYCwPR3qqhnZDfW <!-- signed: repo:objectstack#5 · os-project-manager · session_01FEkQ5m2rYCwPR3qqhnZDfW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 430bbbf commit 91fc398

14 files changed

Lines changed: 926 additions & 42 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@objectstack/service-knowledge': minor
3+
'@objectstack/core': patch
4+
'@objectstack/mcp': patch
5+
'@objectstack/spec': patch
6+
---
7+
8+
feat(service-knowledge)!: a knowledge service the runtime mounts holds its sources without an embedder or its deployment store
9+
10+
Clause-②: no (narrowing)
11+
Metadata-protocol: narrowed
12+
13+
<!-- adr-0087: registered knowledge-service-held-without-embedder-or-store -->
14+
15+
**BREAKING** for a self-hosted deployment whose knowledge service the runtime mounts (the stack declares `requires: ['knowledge']` or ships a `knowledgeSources` entry) and which, at boot, has no embedder or no deployment knowledge store mounted. Such a deployment used to start its boot build, record sync and reconcile job, list `search_knowledge` on MCP, and answer every build and search with an error from a stand-in embedder; a source on a store the application registered was built and searched with no embedder saved. Mounted is not enabled now (ADR-0161 K8, the dated note on item 12): the service is enabled by configuration, read once at `kernel:bootstrapped`, and without both halves every source is held, whichever store it names.
16+
17+
- **`@objectstack/service-knowledge`.** `KnowledgeServicePlugin` takes `runtimeComposed: { declared }`. When set, the plugin reads the embedder and the deployment store at `kernel:bootstrapped`; without both, `KnowledgeService` holds every source: loaded and listed, never built, synced, reconciled or searched. It hands out no `search_knowledge` definition while the reading is pending or held; `search`, `rebuildSource` and `reindexSource` answer `503` with code `SERVICE_UNAVAILABLE` and a message naming the missing half and the fix; a dropped source keeps its index and no store is called. No lifecycle reap guard registers until the reading is enabled, so a retention sweep deletes rows on time. The boot logs one line: info when only a shipped source mounted the service and nothing was saved, warn when the stack declares `requires: ['knowledge']`, a saved embedder provider builds nothing (a provider saved without its key), or the store is missing. Never a boot refusal.
18+
- **`@objectstack/core`.** The capability composition passes `runtimeComposed: { declared }` with the knowledge service's deployment adapter; `declared` is true only when the stack lists `knowledge` in `requires`.
19+
- **`@objectstack/mcp`.** The stdio transport registers `search_knowledge` at `kernel:listening`, after the reading, only when the service hands out its definition; clients are told by `notifications/tools/list_changed`. A held service is never listed on either transport.
20+
- **`@objectstack/spec`.** The upgrade guide carries the `knowledge-service-held-without-embedder-or-store` entry.
21+
22+
Unchanged: a knowledge service a host mounts itself (`KnowledgeServicePlugin` in `plugins[]`, no `runtimeComposed`) boots, builds and serves as before; a deployment with both halves builds, syncs and serves as before; stored sources are not rewritten or refused.
23+
24+
## FROM → TO
25+
26+
- A deployment with knowledge sources and no embedder → save an embedder provider on the AI settings page (or register an `embedder` service from a plugin), then restart.
27+
- A deployment whose boot says its knowledge store is not mounted → mount that store, then restart.
28+
- An application whose own store embeds without the kernel's embedder → mount `KnowledgeServicePlugin` itself in `plugins[]`.

‎content/docs/ai/knowledge-rag.mdx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Which store is mounted depends on the platform database:
3434
- **Two stores and none the deployment's** (a host that mounts the service and two adapters itself): a source that names no adapter is refused when it is registered or saved — `VALIDATION_ERROR` (400), naming the adapters to choose from.
3535
- **A source naming a store that is not mounted** (a retired store such as `ragflow`, or a typo) is refused when it is saved in Studio, over `PUT /meta/knowledge_source` or through MCP: `VALIDATION_ERROR` (400), naming the source, the adapter and the stores that are mounted. A source that leaves `adapter` out is not refused for it. That save check does not reach a package install, a source registered in code or `os validate`; such a source does not stop the boot: the server logs one error naming the source and the stores that are mounted, and indexing or searching that source answers `SERVICE_UNAVAILABLE` (503) with the same choices; `search_knowledge` lists it in `refused`.
3636
- **The embedder** comes from Settings → AI & Embedder ([below](#configuring-the-embedder-from-settings)).
37+
- **Mounted is not enabled.** A service the runtime mounts this way is enabled by configuration, read once when the server starts: an embedder (one a plugin registered, or a provider saved in Settings → AI & Embedder that builds one) and the deployment's store mounted. Without both, every source is **held**, whichever store it names: it is listed to administrators and never built, synced, reconciled or searched; `search_knowledge` is not listed on MCP (HTTP or stdio); a search or a rebuild answers `SERVICE_UNAVAILABLE` (503) naming what is missing; no reap guard is registered and no store is called, so a retention sweep deletes rows on time. The boot says it once: at `info` when only a shipped source mounted the service and nothing was saved, at `warn` when the stack declares `requires: ['knowledge']`, a saved provider builds no embedder (one saved without its key) or the store is not mounted. The server always starts. To enable it, save an embedder provider (or mount the store the log names), then restart. A service you mount yourself (below) is not held.
3738
- **Another libSQL store** for the `turso` case: save its URL as `turso_url` (and `turso_auth_token` for a managed `libsql://` database) in Settings → Knowledge, then restart. A `file:` URL saved there must name a file inside that same data directory, and a URL carrying a NUL byte or another control character, written out or percent-encoded (`%00`), is refused, as is a token carrying one (a pasted line break counts); either way the store answers `SERVICE_UNAVAILABLE` saying why, and the boot goes on.
3839
- **Where the file is**: `os start --home` and `OS_HOME` move it with the default database, so on a container put `OS_HOME` on a volume and the index survives a redeploy. A database named by URL (`OS_DATABASE_URL`) does not move it.
3940
- **Settings → Knowledge** holds only what the service and its store read: `turso_url` and `turso_auth_token`, which `@objectstack/knowledge-turso` adds to the page where it is the store and reads them, with the "Test connection" check of those two fields (on PostgreSQL the page shows none of the three), and `chunk_target`, the longest passage the splitter cuts. The page names no adapter: a source's store is the one its own `adapter` names, and `os knowledge status` reports it per source. Every search re-checks each hit as the asking user, and no setting turns that off. A PostgreSQL deployment that saved the two Turso keys before the group left the page keeps their rows; the settings service never deletes a stored row. To tidy it up, delete the `knowledge` rows named `turso_url` and `turso_auth_token`, and the `sys_secret` row the `turso_auth_token` row's handle names: without the store no API door clears that key, and the row is a decryptable copy of the token. Nothing requires it.
@@ -195,7 +196,7 @@ An adapter that reads the scope filters before it ranks, so the `topK` hits all
195196

196197
## The `search_knowledge` tool
197198

198-
An AI client searches through one tool, `search_knowledge`, defined once by the knowledge service. The MCP door (HTTP and stdio) and the in-product agent serve that one definition unchanged, so every client is offered the same arguments and gets the same answer. It searches only sources whose `aiExposed` is not `false`, and reads as the person asking.
199+
An AI client searches through one tool, `search_knowledge`, defined once by the knowledge service. The MCP door (HTTP and stdio) and the in-product agent serve that one definition unchanged, so every client is offered the same arguments and gets the same answer. It searches only sources whose `aiExposed` is not `false`, and reads as the person asking. Where the knowledge service is held (no embedder or no store, [above](#turning-it-on-requires-knowledge)), the tool is not listed at all; on stdio it is registered after the boot reads the service as enabled, and a connected client is told by `notifications/tools/list_changed`.
199200

200201
| Argument | What it does |
201202
|:--|:--|
@@ -230,7 +231,7 @@ When `KnowledgeServicePlugin` is mounted beside the settings service, Settings
230231
- **A provider is saved and complete** → an `@objectstack/embedder-openai` embedder for that provider. The saved Base URL applies only to the custom and Azure providers; other providers use their preset endpoint. The boot line names the endpoint host. "Complete" is what the **Test embedder** button checks: a provider, an API key (Ollama excepted) and, for a custom or Azure endpoint, a Base URL.
231232
- **Dimensions and batch size are positive integers**, saved as numbers or set as text through an `OS_*` override (`OS_AI_EMBEDDER_DIMENSIONS=256`). A value that is not a positive integer is refused, with a `warn` at boot and the error below on every use — never silently ignored.
232233
- **The batch size is passed only when you saved it.** Left unsaved (the form shows 64), the embedder sends as many inputs per request as the model's documented cap allows — 10 for DashScope `text-embedding-v3`, 2048 for OpenAI `text-embedding-3-*` — and 10 for a model it does not know. A saved batch size is held to the saved model's documented cap (`documentedMaxBatchSize(model)` from `@objectstack/embedder-openai`): a saved 64 on `text-embedding-v3` sends 10. For a model without a documented cap the saved size is sent as saved.
233-
- **Nothing is configured** — no provider saved, `none` saved, or the saved settings incomplete → the server still boots, and every use of the embedder answers an error naming the missing settings: an adapter that embeds refuses indexing and search with it, and nothing is sent anywhere. Nothing is sent to a provider until you have saved one, and the API key is never logged or put in an error.
234+
- **Nothing is configured** — no provider saved, `none` saved, or the saved settings incomplete → the server still boots, and every use of the embedder answers an error naming the missing settings: an adapter that embeds refuses indexing and search with it, and nothing is sent anywhere. Where the runtime mounted the service (`requires: ['knowledge']` or a shipped source), its sources are held instead ([above](#turning-it-on-requires-knowledge)): nothing is built or searched, and `search_knowledge` is not listed. Nothing is sent to a provider until you have saved one, and the API key is never logged or put in an error.
234235

235236
**A saved change takes effect after a restart** — the page says so under the provider field. There is no hot replacement.
236237

‎content/docs/protocol/knowledge.mdx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ the knowledge service and the deployment's store, exactly as
188188
in `PLATFORM_CAPABILITY_PROVIDERS`). A host that mounts
189189
`KnowledgeServicePlugin` itself keeps its own, and the runtime adds no store.
190190

191+
**Mounted is not enabled** (ADR-0161 K8, the dated note on item 12). A service
192+
the runtime mounted (`runtimeComposed` on the plugin) reads once, at
193+
`kernel:bootstrapped`, whether an embedder is available and whether the
194+
deployment's store is mounted. Without both, every source is held, whichever
195+
store it names: loaded and listed, never built, synced, reconciled or searched;
196+
no `search_knowledge` definition is handed out; `search`, `rebuildSource` and
197+
`reindexSource` answer `503 SERVICE_UNAVAILABLE` naming the missing half; a
198+
removed source keeps its index, and no store is called. The boot logs one line,
199+
`info` when only a shipped source mounted the service and nothing was saved,
200+
`warn` otherwise, and never refuses to start. A change takes effect at the next
201+
restart. A host-mounted service is not read this way and serves from the start.
202+
191203
#### How a source is loaded
192204

193205
The knowledge service reads the published `knowledge_source` items when it
@@ -1283,7 +1295,9 @@ handled at the source rather than after the fact
12831295
For every object a source projects, the plugin registers an ADR-0057
12841296
**reap guard** with the lifecycle service. The sweep hands the guard the
12851297
candidate rows before deleting them; the guard deletes each row's document and
1286-
returns the ids it confirms. Rows it does not confirm stay put. The guarded
1298+
returns the ids it confirms. Rows it does not confirm stay put. A service the runtime mounted registers
1299+
no guard until the boot reads it as enabled (above): a held service guards
1300+
nothing and calls no store, so the sweep deletes its rows on time. The guarded
12871301
set follows the sources: a source added after boot for an object with no
12881302
guard gets one when it is loaded, so a reaped row of that object is
12891303
de-indexed too.

‎packages/core/src/capability-composition.test.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,30 @@ describe("stackItemCapabilities — a stack's items mount their reader", () => {
361361
for (const input of [pg, file]) {
362362
const { argument } = resolveCapabilityArgument('knowledge', input);
363363
const [store] = resolveCapabilityExtras('knowledge', input);
364-
expect(argument).toEqual({ deploymentAdapter: resolveKnowledgeStore(input).store.adapterId });
364+
expect(argument).toEqual({
365+
deploymentAdapter: resolveKnowledgeStore(input).store.adapterId,
366+
runtimeComposed: { declared: false },
367+
});
365368
expect(store?.pkg).toBe(resolveKnowledgeStore(input).store.pkg);
366369
}
367-
expect(resolveCapabilityArgument('knowledge', pg).argument).toEqual({ deploymentAdapter: 'pgvector' });
368-
expect(resolveCapabilityArgument('knowledge', file).argument).toEqual({ deploymentAdapter: 'turso' });
370+
expect(resolveCapabilityArgument('knowledge', pg).argument).toEqual({
371+
deploymentAdapter: 'pgvector',
372+
runtimeComposed: { declared: false },
373+
});
374+
expect(resolveCapabilityArgument('knowledge', file).argument).toEqual({
375+
deploymentAdapter: 'turso',
376+
runtimeComposed: { declared: false },
377+
});
378+
});
379+
380+
it('[ADR-0161 K8, note on item 12] marks the service runtime-composed, declared only when the stack lists the token', () => {
381+
const database = { driver: 'sqlite', url: 'file:/app/.objectstack/data/objectstack.db' };
382+
const argumentOf = (stack: unknown) =>
383+
resolveCapabilityArgument('knowledge', { stack, packageRoot: '/app', database }).argument as {
384+
runtimeComposed: { declared: boolean };
385+
};
386+
// A shipped `knowledge_source` mounts the service (an item token), and is no request for it.
387+
expect(argumentOf({ knowledgeSources: [{ name: 'faq' }] }).runtimeComposed).toEqual({ declared: false });
388+
expect(argumentOf({ requires: ['knowledge'] }).runtimeComposed).toEqual({ declared: true });
369389
});
370390
});

‎packages/core/src/capability-composition.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { PLATFORM_ALWAYS_ON_CAPABILITIES, PLATFORM_CAPABILITY_PROVIDERS } from '
6161
import { readEnvWithDeprecation } from '@objectstack/types';
6262
import { CAPABILITY_PROVIDERS, KNOWLEDGE_STORE_PROVIDERS } from './capability-providers.js';
6363
import type { CapabilityIdentities, KnowledgeStoreSpec } from './capability-providers.js';
64-
import { resolveStackCollection } from './stack-collections.js';
64+
import { resolveStackCollection, stackDeclaredCapabilities } from './stack-collections.js';
6565

6666
type Bag = Record<string, unknown>;
6767

@@ -256,13 +256,21 @@ function providerReader<A extends unknown[]>(
256256
* and on a configuration the schema refuses, an inline secret included.
257257
* - `storage`: the local adapter at {@link resolveStorageLocalRootEnv}'s root,
258258
* else `.objectstack/data/uploads` ({@link resolveStorageCapabilityArg}).
259-
* - `knowledge`: `{ deploymentAdapter }`, the adapter id of the store
259+
* - `knowledge`: `{ deploymentAdapter, runtimeComposed }` — the adapter id of the store
260260
* {@link resolveKnowledgeStore} chooses and {@link resolveCapabilityExtras}
261261
* mounts beside the service — the deployment's-store mark (ADR-0161 K4): a
262262
* source that names no adapter binds to it. A service option, not an
263263
* adapter-contract member; the store itself is told nothing. Read from the
264264
* same {@link CapabilityArgumentInput.database} as the store's choice, so
265-
* the two agree.
265+
* the two agree. Beside it, `runtimeComposed: { declared }`: the service
266+
* was composed by this rule, not mounted by a host, so it is enabled by
267+
* configuration (ADR-0161 K8, the dated note on item 12): at
268+
* `kernel:bootstrapped` it serves only with an embedder and the
269+
* deployment's store, and holds its sources otherwise. `declared` is
270+
* whether the stack lists `requires: ['knowledge']`
271+
* (`stackDeclaredCapabilities`), which raises the not-enabled boot line from
272+
* `info` to `warn`; a stack that mounts the service only by shipping a
273+
* `knowledge_source` leaves it `false`.
266274
* - any other token: no argument.
267275
*
268276
* A throw is the boot's to report: whether it fails the boot or is logged is
@@ -295,7 +303,12 @@ export function resolveCapabilityArgument(token: string, input: CapabilityArgume
295303
return { argument: storage.options, localStorageRoot: storage.localRoot };
296304
}
297305
if (token === 'knowledge') {
298-
return { argument: { deploymentAdapter: resolveKnowledgeStore(input).store.adapterId } };
306+
return {
307+
argument: {
308+
deploymentAdapter: resolveKnowledgeStore(input).store.adapterId,
309+
runtimeComposed: { declared: stackDeclaredCapabilities(input.stack).includes('knowledge') },
310+
},
311+
};
299312
}
300313
return { argument: undefined };
301314
}

0 commit comments

Comments
 (0)