Repository navigation
Commit d316627
feat(service-knowledge): read a source's retrieval mode and refuse a mode its store does not run (#38722)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8QCBjsNDZa4iwo35VN5fKKg)_
Part of #38692
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
知识源声明了检索方式后,搜索就按它执行;没声明的按存储默认。存储不支持所声明的方式时,保存时直接报错并列出可选方式,启动后记一次错误日志,每次搜索都把它列为未检索,绝不悄悄换成别的方式。
- 属于知识管理专题「一期 a:检索方式」。
- 出错会是本该能搜的知识源被拒;未声明方式的知识源行为不变,可直接撤回。
- 无。
## Stack
Base: `main`. #38700 (the facade split) has merged and `main` is merged
in. The spec PR #38720 merged as f576dee and `main` is merged in, so
this diff is the service's own 15 files. The phase-0 ADR note (#38714)
is merged too. Independent of the adapter PRs. The Studio form PR stacks
on this one.
## What changes
- New `knowledge-retrieval-mode.ts`: the effective mode is the source's
`source.retrieval.mode`, else the adapter's
`capabilities.retrieval.default`; an adapter reporting no modes is never
told one.
- The four refusal points for a declared mode the adapter does not list,
never searched another way:
1. save (`admitAuthoredSource`): `400 VALIDATION_ERROR`, listing the
modes the store runs;
2. registration in code (`registerSource`): the same refusal, only when
the adapter already resolves (startup registry reads). A published item
(`registerMetadataSource`, the loader) is not refused there: the loader
runs after every store has started, so a refusal would drop it whole; it
is registered and indexed, and points 3 and 4 refuse it (review M1);
3. once after boot (`reportUnsupportedRetrieval`, called at
`kernel:bootstrapped` beside `reportUnmountedAdapters`), at `error`;
4. every search (`planSearches`): listed in `refused` with
`SERVICE_UNAVAILABLE` (503), the code an unmounted adapter's source
already carries.
- Every search hands the store `AdapterSearchOptions.retrieval` and logs
the mode and its origin at `debug`; the caller's answer carries neither.
- `index_status` entries carry `retrieval` (declared, effective mode,
origin, the store's modes, refused), and the answer lists each mounted
store's modes (`details.adapters`) and the store a source naming none
binds to (`details.defaultAdapter`), the data the Studio form PR reads.
New service member `describeRetrieval`.
- Contract suite: service-level cases for every adapter (a listed mode
is handed through; an unlisted one is refused at registration in code
and at every search, and still indexes; a published item loaded after
its store started is registered, indexes, is named by the boot reading
and is refused on every search).
- Liveness row flips to `live`; protocol doc §3.1 and the save guard;
patch changeset.
## Tests
- New `retrieval-mode-38692.test.ts` (16 cases): resolution, refusal
text, each refusal point, debug log and its absence from the answer,
still indexes, the loader path (a published item with its store already
started), plugin hook, `index_status`.
- `service-knowledge`: 861 passed (26 files, at 1a7ba24); typecheck
clean. `knowledge-memory` 70 passed and `knowledge-turso` contract 110
passed against this head's suite. `knowledge-memory` contract 54 passed;
`knowledge-turso` 110 contract passed; live pgvector contract 55 passed.
- With each adapter PR merged in locally: turso 326 passed, pgvector
against live PostgreSQL 133 passed.
## Acceptance notes
- The per-search refusal code is reused rather than added:
`SERVICE_UNAVAILABLE` (503), the code an unmounted adapter's source
already carries. The ruling and the phase-0 note say only "with its
code"; open question C, confirmed by Warren on 2026-11-30 at 12:40Z
(「同意」): the refusal stays 503.
- Declared `Metadata-protocol: none`: what an author can write was added
by the spec PR; this PR reads it. The save refusal of a mode the store
does not run is the shape the ruling gives the key from birth, in the
same release.
- Facade gate: `knowledge-service.ts` 1681 lines of 1758; both new
members are one-call delegations.
## Verification
- Two-minute check: `pnpm --filter @objectstack/service-knowledge exec
vitest run src/__tests__/retrieval-mode-38692.test.ts` → 16 passed.
- Related local gates (26 of `dispatch-gates.mjs --commands`: docs,
liveness, changeset, facade, error-code, ledger): all green.
## 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.
- [ ] 4. One issue, one branch off an up-to-date `main`, one pull
request. (Stacked: see "Stack" above.)
- [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.
- [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_01JQwxbaASqBozmmj1n5tbUf
<!-- signed: repo:objectstack#2 · os-warren ·
session_01JQwxbaASqBozmmj1n5tbUf -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 59faf74 commit d316627
15 files changed
Lines changed: 876 additions & 23 deletions
File tree
- .changeset
- content/docs/protocol
- packages
- services/service-knowledge/src
- __tests__
- spec/liveness
- state-counts
| 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 | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
| 185 | + | |
| 186 | + | |
187 | 187 | | |
188 | | - | |
189 | | - | |
190 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
191 | 211 | | |
192 | 212 | | |
193 | 213 | | |
| |||
260 | 280 | | |
261 | 281 | | |
262 | 282 | | |
263 | | - | |
| 283 | + | |
| 284 | + | |
264 | 285 | | |
265 | 286 | | |
266 | 287 | | |
| |||
0 commit comments