Skip to content

Commit 73d0240

Browse files
fix(service-knowledge): a source naming an unmounted adapter is logged once at boot (#37951)
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes #37479 Clause-②: no Metadata-protocol: none ## 维护者速读 - 运维人员看启动日志时,一个指向未挂载存储的知识源从两行告警变为一行错误,错误里写明知识源、存储名和可选的已挂载存储;用户无感。 - 属于知识检索平台(AI 检索)史诗,替看启动日志的运维人员去掉重复噪音。 - 出错只会让这条错误多一行或少一行,检索与建索引的行为不变,可直接撤回。 - 无。 ## What changes - `packages/services/service-knowledge/src/knowledge-service.ts` `buildIfDue`: at boot, a source whose adapter is not mounted is skipped by the first-build pass without a line. Before, the pass read its index state, `getAdapter` threw the unmounted-adapter refusal, and the pass logged it at `warn` as "is not built at boot: what the adapter holds could not be read (...)", beside the `error` that `reportUnmountedAdapters` already prints at `kernel:bootstrapped`. Now the boot says it once, at `error`, naming the source, the adapter and the mounted adapters. - On reload (a `knowledge_source` item added while the process runs) nothing changes: no boot reading runs then, so the reload build's `warn` is still the one line that names the source. - Indexing and searching such a source still answer the coded `SERVICE_UNAVAILABLE` 503 (PR #37442); not touched. This is item 1 of the re-scope (card comment 7187970703). Item 2, a publish or `os validate` refusal of an adapter name no deployment can serve, is NOT in this PR: it would narrow what is accepted, and the area decides. Options are in the dev report on the card. That is why this PR says `Part of` and leaves the card open. ## Tests - New pin in `src/__tests__/knowledge-build.test.ts`: with a data engine bound, one mounted source and one naming `pgvector` (not mounted), the boot pass plus the boot reading produce exactly one log line naming `'docs'` across debug/info/warn/error. That line is at `error` and names the adapter as not mounted. The mounted source is still built (`status: 'done'`). - Ablation: with the new guard line replaced by a comment, the pin goes red: `expected [ [ 'warn', …(1) ], [ 'error', …(1) ] ] to have a length of 1 but got 2` (1 failed, 22 passed). With the line restored, the file is green (23 passed). <details><summary>Package test and typecheck (head 13f32fc)</summary> `pnpm --filter @objectstack/service-knowledge test && pnpm --filter @objectstack/service-knowledge typecheck` under the verify lock: `VERDICT command-exit 0`, Test Files 17 passed (17), Tests 529 passed (529). `typecheck` is `tsc --noEmit && pnpm check:test-typecheck`, so the test files are type-checked too. </details> ## Acceptance notes - Item 2 of re-scope 7187970703 (a publish or `os validate` refusal) is closed by area decision D, with no publish-time refusal added. The refusal point is boot: `reportUnmountedAdapters` prints a coded error naming the source and the adapter. `searchWithRefusals` lists such a source as refused (`knowledge-service.ts` near :1882), and index and search answer the coded 503 (PR #37442 and this PR). Options A (save-time admission) and B (a `ragflow` tombstone) stay in the dev report on the card, for a future card. - The claim's file surface pointed at `:372` as "the boot build pass's kept(...) line". On origin/main 73d5e34, `:372` is `dropMetadataSource`'s `kept(...)`, which runs when a source is removed, not at boot. The second boot line comes from `buildIfDue` (the `warn` of an `unreadable` index reading). The fix sits there, and `dropMetadataSource` is not touched. - Public surface: no exported type, export or wire shape changes. No dependent package owes a test. ## Verification Read first: `knowledge-service.ts` `buildIfDue` (the one added guard line), then the new pin. Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-build.test.ts` should show 23 passed. Delete the guard line `if (trigger === 'boot' && !this.adapters.has(entry.handed.adapter)) return;` and the pin fails with 2 lines (warn, error) where it expects 1. <details><summary>Derived gates (local, head 13f32fc): 68 exit 0, 2 NOT MEASURED</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 70 families from the 3 changed paths. All 70 ran; `--ran` with recorded exit codes: "70 derived famil(ies) accounted for — 68 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - NOT MEASURED: `check:dual-build-cjs-loads`, reason: PREREQUISITE NOT MET, it needs every package's `dist/` (a whole-tree build). CI runs it. - NOT MEASURED: `check:type-check-debt`, reason: its re-measure build did not get a turn on the shared verify lock (queue-timeout 99). CI runs it. The package-wide scans (`pnpm lint` and the rest of the farm) are CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0b539b6 commit 73d0240

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/service-knowledge': patch
3+
---
4+
5+
fix(service-knowledge): a source naming an unmounted adapter is logged once at boot, not twice
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
At boot, a knowledge source whose `adapter` names a store nothing mounted was named twice: once at `error` by the boot's reading of unmounted adapters, and once more at `warn` by the first-build pass ("is not built at boot: what the adapter holds could not be read"). The first-build pass now skips such a source without a line, so the one boot line is the `error` that names the source, the adapter and the mounted choices. Nothing else changes: indexing and searching the source still answer `SERVICE_UNAVAILABLE`, and a source loaded while the process runs is still named at `warn` by its reload build, since no boot reading runs then.

‎packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,30 @@ describe('buildSourcesAtBoot — the first build', () => {
376376
expect(logger.warn.mock.calls.map((c) => String(c[0])).some((l) => l.includes('redis unreachable'))).toBe(true);
377377
});
378378

379+
it('a source naming an unmounted adapter gets exactly one boot log line: the reading, at error', async () => {
380+
const db = makeEngine(ROWS);
381+
const { adapter, calls } = makeAdapter();
382+
const { service, logger } = makeService(db.engine, adapter);
383+
service.registerSource(source());
384+
service.registerSource(source({ name: 'docs', adapter: 'pgvector' }));
385+
386+
// What the plugin does at kernel:bootstrapped: the first-build pass and the reading.
387+
await service.buildSourcesAtBoot();
388+
service.reportUnmountedAdapters();
389+
390+
const lines = (['debug', 'info', 'warn', 'error'] as const).flatMap((level) =>
391+
logger[level].mock.calls.map((c) => [level, String(c[0])] as const),
392+
);
393+
// Registration's own line names the adapter; past it, one line says the source is unservable.
394+
const boot = lines.filter(([, m]) => m.includes("'docs'"));
395+
expect(boot).toHaveLength(1);
396+
expect(boot[0]?.[0]).toBe('error');
397+
expect(boot[0]?.[1]).toContain("source 'docs' names adapter 'pgvector', which is not mounted");
398+
// The mounted source is still built by the same pass.
399+
expect(calls.upserted).toBeGreaterThan(0);
400+
expect(service.buildRecord('kb')).toMatchObject({ status: 'done' });
401+
});
402+
379403
it('a source with refresh.onRecordChange: false is left to its external indexer', async () => {
380404
const db = makeEngine(ROWS);
381405
const { adapter, calls } = makeAdapter();

‎packages/services/service-knowledge/src/knowledge-service.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,9 @@ export class KnowledgeService implements IKnowledgeService {
13451345
* trigger `boot`). A source with `refresh.onRecordChange: false` is left
13461346
* alone — an external indexer owns its index — and so is one whose state
13471347
* builds nothing; a state that cannot be read or seen is logged at `warn`,
1348-
* once. Resolves when the pass is done; never rejects. Run in the
1348+
* once. A source whose adapter is not mounted is skipped without a line:
1349+
* {@link reportUnmountedAdapters} names it at boot, so it is said once.
1350+
* Resolves when the pass is done; never rejects. Run in the
13491351
* background by `KnowledgeServicePlugin`, so the boot never waits for it.
13501352
*/
13511353
async buildSourcesAtBoot(): Promise<void> {
@@ -1383,6 +1385,11 @@ export class KnowledgeService implements IKnowledgeService {
13831385
logger?.debug?.(`[knowledge] source '${entry.face}': refresh.onRecordChange is false, so an external indexer owns its index; it is not built ${when}.`);
13841386
return;
13851387
}
1388+
// A source whose adapter is not mounted is named once at boot, at
1389+
// `error`, by the boot's reading (`reportUnmountedAdapters`); the pass
1390+
// adds no second line for it. On reload no reading runs, so the line
1391+
// below is the one that names it.
1392+
if (trigger === 'boot' && !this.adapters.has(entry.handed.adapter)) return;
13861393
const reading = await this.readIndexStateOf(entry);
13871394
if (reading.due) {
13881395
logger?.info?.(`[knowledge] source '${entry.face}' is built now: ${reading.detail}`);

0 commit comments

Comments
 (0)