Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/37479-knowledge-unmounted-adapter-one-boot-line.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion packages/services/service-knowledge/src/knowledge-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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}`);
Expand Down
Loading