From 13f32fc828a388ed7188f0ec6a5e3ed042013a71 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 11:51:21 +0000 Subject: [PATCH] fix(service-knowledge): a source naming an unmounted adapter is logged once at boot The boot build pass no longer adds a warn line for a source whose adapter is not mounted; reportUnmountedAdapters names it once at error. Pinned by a boot-pass test counting every log line that names the source. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP --- ...owledge-unmounted-adapter-one-boot-line.md | 10 ++++++++ .../src/__tests__/knowledge-build.test.ts | 24 +++++++++++++++++++ .../src/knowledge-service.ts | 9 ++++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .changeset/37479-knowledge-unmounted-adapter-one-boot-line.md diff --git a/.changeset/37479-knowledge-unmounted-adapter-one-boot-line.md b/.changeset/37479-knowledge-unmounted-adapter-one-boot-line.md new file mode 100644 index 00000000000..e8234a7f006 --- /dev/null +++ b/.changeset/37479-knowledge-unmounted-adapter-one-boot-line.md @@ -0,0 +1,10 @@ +--- +'@objectstack/service-knowledge': patch +--- + +fix(service-knowledge): a source naming an unmounted adapter is logged once at boot, not twice + +Clause-②: no +Metadata-protocol: none + +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. diff --git a/packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts b/packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts index 65b55814097..c89b617ec4d 100644 --- a/packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts +++ b/packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts @@ -376,6 +376,30 @@ describe('buildSourcesAtBoot — the first build', () => { expect(logger.warn.mock.calls.map((c) => String(c[0])).some((l) => l.includes('redis unreachable'))).toBe(true); }); + it('a source naming an unmounted adapter gets exactly one boot log line: the reading, at error', async () => { + const db = makeEngine(ROWS); + const { adapter, calls } = makeAdapter(); + const { service, logger } = makeService(db.engine, adapter); + service.registerSource(source()); + service.registerSource(source({ name: 'docs', adapter: 'pgvector' })); + + // What the plugin does at kernel:bootstrapped: the first-build pass and the reading. + await service.buildSourcesAtBoot(); + service.reportUnmountedAdapters(); + + const lines = (['debug', 'info', 'warn', 'error'] as const).flatMap((level) => + logger[level].mock.calls.map((c) => [level, String(c[0])] as const), + ); + // Registration's own line names the adapter; past it, one line says the source is unservable. + const boot = lines.filter(([, m]) => m.includes("'docs'")); + expect(boot).toHaveLength(1); + expect(boot[0]?.[0]).toBe('error'); + expect(boot[0]?.[1]).toContain("source 'docs' names adapter 'pgvector', which is not mounted"); + // The mounted source is still built by the same pass. + expect(calls.upserted).toBeGreaterThan(0); + expect(service.buildRecord('kb')).toMatchObject({ status: 'done' }); + }); + it('a source with refresh.onRecordChange: false is left to its external indexer', async () => { const db = makeEngine(ROWS); const { adapter, calls } = makeAdapter(); diff --git a/packages/services/service-knowledge/src/knowledge-service.ts b/packages/services/service-knowledge/src/knowledge-service.ts index 7cccdc9fb0d..ae2e4a6b2e9 100644 --- a/packages/services/service-knowledge/src/knowledge-service.ts +++ b/packages/services/service-knowledge/src/knowledge-service.ts @@ -1345,7 +1345,9 @@ export class KnowledgeService implements IKnowledgeService { * trigger `boot`). A source with `refresh.onRecordChange: false` is left * alone — an external indexer owns its index — and so is one whose state * builds nothing; a state that cannot be read or seen is logged at `warn`, - * once. Resolves when the pass is done; never rejects. Run in the + * once. A source whose adapter is not mounted is skipped without a line: + * {@link reportUnmountedAdapters} names it at boot, so it is said once. + * Resolves when the pass is done; never rejects. Run in the * background by `KnowledgeServicePlugin`, so the boot never waits for it. */ async buildSourcesAtBoot(): Promise { @@ -1383,6 +1385,11 @@ export class KnowledgeService implements IKnowledgeService { logger?.debug?.(`[knowledge] source '${entry.face}': refresh.onRecordChange is false, so an external indexer owns its index; it is not built ${when}.`); return; } + // A source whose adapter is not mounted is named once at boot, at + // `error`, by the boot's reading (`reportUnmountedAdapters`); the pass + // adds no second line for it. On reload no reading runs, so the line + // below is the one that names it. + if (trigger === 'boot' && !this.adapters.has(entry.handed.adapter)) return; const reading = await this.readIndexStateOf(entry); if (reading.due) { logger?.info?.(`[knowledge] source '${entry.face}' is built now: ${reading.detail}`);