Skip to content

Commit 205f667

Browse files
committed
fix(knowledge): the boot build pass places a source that names no adapter
main's boot pass (#37951) read the source's named adapter; a source that names none is now placed through boundAdapterId, and one that cannot be placed is left to the reading, as an unmounted named one is. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
1 parent 08bc42e commit 205f667

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,29 @@ describe('buildSourcesAtBoot — the first build', () => {
400400
expect(service.buildRecord('kb')).toMatchObject({ status: 'done' });
401401
});
402402

403+
it('[ADR-0161 K4] a source that names no adapter is built at boot on the one it is placed on; one that cannot be placed is left to the reading', async () => {
404+
const db = makeEngine(ROWS);
405+
const { adapter, calls } = makeAdapter();
406+
const { service } = makeService(db.engine, adapter);
407+
const { adapter: other } = makeAdapter();
408+
const { adapter: unnamed } = makeAdapter();
409+
service.registerSource(source({ adapter: undefined }));
410+
411+
await service.buildSourcesAtBoot();
412+
expect(service.adapterIdFor(service.describeSources()[0]!.source)).toBe('memory');
413+
expect(service.buildRecord('kb')).toMatchObject({ trigger: 'boot', status: 'done', result: { ok: true, indexed: 3 } });
414+
expect(calls.upserted).toBe(3);
415+
416+
// A second node where two adapters arrived after the source and none is the deployment's:
417+
// the pass builds nothing for it, and the reading names it.
418+
const second = makeService(db.engine, other);
419+
second.service.registerSource(source({ adapter: undefined }));
420+
second.service.registerAdapter('app_store', unnamed);
421+
await second.service.buildSourcesAtBoot();
422+
expect(second.service.buildRecord('kb')).toBeUndefined();
423+
expect(second.service.reportUnmountedAdapters()).toEqual(['kb']);
424+
});
425+
403426
it('a source with refresh.onRecordChange: false is left to its external indexer', async () => {
404427
const db = makeEngine(ROWS);
405428
const { adapter, calls } = makeAdapter();

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,12 @@ export class KnowledgeService implements IKnowledgeService {
14851485
// A source whose adapter is not mounted is named once at boot, at
14861486
// `error`, by the boot's reading (`reportUnmountedAdapters`); the pass
14871487
// adds no second line for it. On reload no reading runs, so the line
1488-
// below is the one that names it.
1489-
if (trigger === 'boot' && !this.adapters.has(entry.handed.adapter)) return;
1488+
// below is the one that names it. A source that names no adapter and
1489+
// cannot be placed is named by the same reading.
1490+
if (trigger === 'boot') {
1491+
const adapterId = this.boundAdapterId(entry.handed);
1492+
if (adapterId === undefined || !this.adapters.has(adapterId)) return;
1493+
}
14901494
const reading = await this.readIndexStateOf(entry);
14911495
if (reading.due) {
14921496
logger?.info?.(`[knowledge] source '${entry.face}' is built now: ${reading.detail}`);

0 commit comments

Comments
 (0)