Repository navigation
Commit 91fc398
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
File tree
- .changeset
- content/docs
- ai
- protocol
- packages
- core/src
- mcp/src
- runtime/src
- services/service-knowledge/src
- __tests__
- spec/src/migrations/entries/semantic
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | | - | |
| 199 | + | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
| |||
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
233 | | - | |
| 234 | + | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
191 | 203 | | |
192 | 204 | | |
193 | 205 | | |
| |||
1283 | 1295 | | |
1284 | 1296 | | |
1285 | 1297 | | |
1286 | | - | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
1287 | 1301 | | |
1288 | 1302 | | |
1289 | 1303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
364 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
365 | 368 | | |
366 | 369 | | |
367 | | - | |
368 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
369 | 389 | | |
370 | 390 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
266 | 274 | | |
267 | 275 | | |
268 | 276 | | |
| |||
295 | 303 | | |
296 | 304 | | |
297 | 305 | | |
298 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
299 | 312 | | |
300 | 313 | | |
301 | 314 | | |
| |||
0 commit comments