diff --git a/.changeset/turso-drop-during-build.md b/.changeset/turso-drop-during-build.md new file mode 100644 index 00000000000..d7295bcfb1e --- /dev/null +++ b/.changeset/turso-drop-during-build.md @@ -0,0 +1,14 @@ +--- +'@objectstack/knowledge-turso': patch +--- + +fix(knowledge-turso): a build that keeps going after `dropSource` cannot bring the dropped source back + +Clause-②: no +Metadata-protocol: none + +`IKnowledgeAdapter.dropSource` removes every generation of a source, "the one under construction included", and afterwards a source registered again under the same key is built from nothing. On the turso store a build of the source that was under way when it was dropped, in another process or in the same one, broke that: its next page found no generation and opened a new active one, and the rest of the walk landed there, so the store served the dropped source again. + +A build's writes, listing and completion now go only to the generation that build began. When that generation is gone, because the source was dropped or another build under another fingerprint replaced it, the call is refused `LOCK_CONFLICT` (409), the same code and status the pgvector store answers, and the build ends; nothing is opened. A completion of such a build is refused the same way (before, it threw an error with no code). The build knows its generation by its number, the time its row was made and its fingerprint, so a later generation that takes the same number after a drop is never taken for it. + +A build that begins after the drop builds the source from nothing, as before. Writes outside a build (event sync) are not fenced. Nothing to migrate. diff --git a/packages/plugins/knowledge-turso/README.md b/packages/plugins/knowledge-turso/README.md index 86f64d6280d..e0cbfccc38d 100644 --- a/packages/plugins/knowledge-turso/README.md +++ b/packages/plugins/knowledge-turso/README.md @@ -39,10 +39,10 @@ On a file the store sets WAL and a busy timeout: without them a second process w ## Tables -- `knowledge_generation` — one row per source and generation: the index fingerprint it was built under, the recipe hash, the vector width, the model, and whether it is active or being built. At most one of each per source, by a unique index. It does not refuse a second builder: a second build under the same fingerprint joins the one under way, and one under another fingerprint replaces it, after which the first builder's writes are refused `KNOWLEDGE_REBUILD_REQUIRED`. No generation mixes two fingerprints. +- `knowledge_generation` — one row per source and generation: the index fingerprint it was built under, the recipe hash, the vector width, the model, and whether it is active or being built. At most one of each per source, by a unique index. It does not refuse a second builder: a second build under the same fingerprint joins the one under way, and one under another fingerprint replaces it, after which the first build's writes, listing and completion are refused `LOCK_CONFLICT` (409) and that build ends; a write outside a build under the replaced fingerprint is refused `KNOWLEDGE_REBUILD_REQUIRED`. No generation mixes two fingerprints. - `knowledge__g` — the passages of one generation of one source, with an `F32_BLOB()` vector column sized for that generation. -`` is the source's index key: its name, or for a source a package ships, the knowledge service's spelling of that package and name (so two packages' sources of one name are two tables). When a source stops being served (its metadata item was removed, or a package now holds its name), the knowledge service calls `dropSource`: the source's generation tables and rows are dropped in one transaction. A table the store did not make under one of those names (an object's table, in a database shared with object tables) is never dropped: the call is refused `SERVICE_UNAVAILABLE`, naming the table, and nothing of the source is removed. +`` is the source's index key: its name, or for a source a package ships, the knowledge service's spelling of that package and name (so two packages' sources of one name are two tables). When a source stops being served (its metadata item was removed, or a package now holds its name), the knowledge service calls `dropSource`: the source's generation tables and rows are dropped in one transaction. A table the store did not make under one of those names (an object's table, in a database shared with object tables) is never dropped: the call is refused `SERVICE_UNAVAILABLE`, naming the table, and nothing of the source is removed. A build of the source under way when it is dropped, in this process or another, is ended: its next write, listing or completion is refused `LOCK_CONFLICT` (409) and opens nothing, so the build never brings the source back. A build that begins after the drop builds the source from nothing. ## Search diff --git a/packages/plugins/knowledge-turso/src/__tests__/acceptance.test.ts b/packages/plugins/knowledge-turso/src/__tests__/acceptance.test.ts index 75c2178714d..14cd3182ef6 100644 --- a/packages/plugins/knowledge-turso/src/__tests__/acceptance.test.ts +++ b/packages/plugins/knowledge-turso/src/__tests__/acceptance.test.ts @@ -429,6 +429,171 @@ for (const kind of ['memory', 'file'] as StoreKind[]) { }); } +/** A build's context: the walk's calls carry `reason: 'reindex'`. */ +const buildCtx = (s: KnowledgeSource, index = FP_A): AdapterContext => ({ source: s, reason: 'reindex', index }); + +/** What the store holds for a source: its generation rows (`n:fingerprint:state`) and its passage tables. */ +async function heldFor(client: Client, s: KnowledgeSource): Promise<{ generations: string[]; tables: string[] }> { + const rows = await client.execute({ + sql: 'SELECT generation, fingerprint, state FROM knowledge_generation WHERE source_id = ? ORDER BY generation', + args: [s.name], + }); + return { + generations: rows.rows.map((r) => `${Number(r.generation)}:${String(r.fingerprint)}:${String(r.state)}`), + tables: await tables(client, `knowledge_${s.name}_g%`), + }; +} + +const NOTHING = { generations: [], tables: [] }; + +for (const kind of ['memory', 'file'] as StoreKind[]) { + describe(`knowledge-turso: a build whose source is dropped while it runs, on ${kind === 'memory' ? ':memory:' : 'a file: URL'}`, () => { + const store = storeOf(kind); + afterAll(() => store.closeAll()); + + /** + * Two adapters over one store, standing for two processes: each keeps its + * own builds; on a file, each has its own connection to the database. + */ + function twoProcesses(embedder: IEmbedder = new FakeEmbedder()) { + const at = store.url(); + const first = store.client(at); + const second = kind === 'file' ? store.client(at) : first; + return { + client: first, + a: new TursoKnowledgeAdapter({ id: 'under_test', client: first, embedder }), + b: new TursoKnowledgeAdapter({ id: 'under_test', client: second, embedder: new FakeEmbedder() }), + }; + } + + const FP_B = { fingerprint: 'fp-test:b', recipeHash: 'rh-test:1' }; + const FP_C = { fingerprint: 'fp-test:c', recipeHash: 'rh-test:1' }; + + const begins = [ + ['beside the active generation', FP_B, true], + ['inside the active generation', FP_A, true], + ['of a source that held nothing', FP_A, false], + ] as const; + const calls = { + write: (a: TursoKnowledgeAdapter, c: AdapterContext) => a.upsert([doc(c.source as KnowledgeSource, '2', 'granite quarry')], c), + list: (a: TursoKnowledgeAdapter, c: AdapterContext) => a.listDocuments(c, { limit: 10 }), + complete: (a: TursoKnowledgeAdapter, c: AdapterContext) => a.completeBuild(c), + } as const; + + for (const [shape, index, seeded] of begins) { + for (const [call, run] of Object.entries(calls)) { + it(`a build ${shape}, then a drop in another process: the build's ${call} is refused LOCK_CONFLICT, nothing is held, and the source builds again from nothing`, async () => { + const { client, a, b } = twoProcesses(); + const s = source(`drop_${seeded ? (index === FP_A ? 'inside' : 'beside') : 'empty'}_${call}`); + if (seeded) await a.upsert([doc(s, '1', 'granite quarry')], ctx(s)); + await a.beginBuild(buildCtx(s, index)); + await b.dropSource(ctx(s)); + + expect(await refusal(run(a, buildCtx(s, index)))).toMatchObject({ code: 'LOCK_CONFLICT', status: 409 }); + expect(await heldFor(client, s)).toEqual(NOTHING); + expect(await b.indexStatus(ctx(s))).toEqual({}); + + // The build ended: one that begins after the drop builds the source from nothing. + await a.beginBuild(buildCtx(s, index)); + await a.upsert([doc(s, '3', 'basalt columns')], buildCtx(s, index)); + await a.completeBuild(buildCtx(s, index)); + expect(await heldFor(client, s)).toEqual({ generations: [`1:${index.fingerprint}:active`], tables: [`knowledge_${s.name}_g1`] }); + const hits = await b.search('basalt', { source: s, topK: 5, index: { fingerprint: index.fingerprint } }); + expect(hits.map((h) => h.documentId)).toEqual([`${s.name}:3`]); + }); + } + } + + it("a drop in the build's own process ends the build the same way", async () => { + const { client, a } = twoProcesses(); + const s = source('drop_same_process'); + await a.upsert([doc(s, '1', 'granite quarry')], ctx(s)); + await a.beginBuild(buildCtx(s, FP_B)); + await a.dropSource(ctx(s)); + expect(await refusal(a.upsert([doc(s, '2', 'marble')], buildCtx(s, FP_B)))).toMatchObject({ code: 'LOCK_CONFLICT', status: 409 }); + expect(await heldFor(client, s)).toEqual(NOTHING); + }); + + it('a page whose embedding was under way when the drop committed is written nowhere', async () => { + let drop: (() => Promise) | undefined; + const embedder = new (class extends FakeEmbedder { + override async embed(texts: string[]): Promise { + const now = drop; + drop = undefined; + if (now) await now(); + return super.embed(texts); + } + })(); + const { client, a, b } = twoProcesses(embedder); + const s = source('drop_while_embedding'); + await a.upsert([doc(s, '1', 'granite quarry')], ctx(s)); + await a.beginBuild(buildCtx(s, FP_B)); + drop = () => b.dropSource(ctx(s)); + expect(await refusal(a.upsert([doc(s, '2', 'marble')], buildCtx(s, FP_B)))).toMatchObject({ code: 'LOCK_CONFLICT', status: 409 }); + expect(drop).toBeUndefined(); + expect(await heldFor(client, s)).toEqual(NOTHING); + }); + + it('a build another process replaced under another fingerprint is ended the same way; the replacing build goes on', async () => { + const { client, a, b } = twoProcesses(); + const s = source('replaced_build'); + await a.upsert([doc(s, '1', 'granite quarry')], ctx(s)); + await a.beginBuild(buildCtx(s, FP_B)); + await b.beginBuild(buildCtx(s, FP_C)); + // The replacing build's generation took the number of the one it replaced. + expect((await heldFor(client, s)).generations).toEqual([`1:${FP_A.fingerprint}:active`, `2:${FP_C.fingerprint}:building`]); + expect(await refusal(a.upsert([doc(s, '2', 'marble')], buildCtx(s, FP_B)))).toMatchObject({ code: 'LOCK_CONFLICT', status: 409 }); + await b.upsert([doc(s, '3', 'basalt columns')], buildCtx(s, FP_C)); + await b.completeBuild(buildCtx(s, FP_C)); + expect(await b.indexStatus(ctx(s))).toEqual({ fingerprint: FP_C.fingerprint, recipeHash: FP_C.recipeHash }); + expect((await b.search('basalt marble', { source: s, topK: 5, index: FP_C })).map((h) => h.documentId)).toEqual([`${s.name}:3`]); + }); + + for (const [label, next, pause] of [ + ['under another fingerprint', FP_C, 0], + ['under the same fingerprint, made later', FP_A, 10], + ] as const) { + it(`a generation that takes a dropped build's number ${label} is never that build's`, async () => { + const { client, a, b } = twoProcesses(); + const s = source(`reused_${next === FP_A ? 'same' : 'other'}`); + await a.beginBuild(buildCtx(s, FP_A)); + await b.dropSource(ctx(s)); + if (pause > 0) await new Promise((resolve) => setTimeout(resolve, pause)); + await b.beginBuild(buildCtx(s, next)); + expect((await heldFor(client, s)).generations).toEqual([`1:${next.fingerprint}:active`]); + expect(await refusal(a.upsert([doc(s, '1', 'marble')], buildCtx(s, FP_A)))).toMatchObject({ code: 'LOCK_CONFLICT', status: 409 }); + expect(await b.listDocuments(buildCtx(s, next), { limit: 10 })).toEqual({ documents: [] }); + }); + } + + it('through KnowledgeService: a walk whose source another process drops after its first page stops, and leaves nothing', async () => { + const { client, a, b } = twoProcesses(); + const s = source('drop_mid_walk'); + const rows = Array.from({ length: 250 }, (_, i) => ({ id: `r${String(i + 1).padStart(4, '0')}`, body: `granite ${i + 1}`, status: 'published' })); + const svc = new KnowledgeService({ dataEngine: rowsEngine(rows) }); + const upsert = a.upsert.bind(a); + let pages = 0; + a.upsert = async (batch, c) => { + await upsert(batch, c); + pages += 1; + if (pages === 1) await b.dropSource(ctx(s)); + }; + svc.registerAdapter('under_test', a); + svc.registerSource(s); + + expect(await svc.reindexSource(s.name)).toMatchObject({ ok: false, indexed: 100 }); + expect(pages).toBe(1); + expect(await heldFor(client, s)).toEqual(NOTHING); + expect(await b.indexStatus(ctx(s))).toEqual({}); + + // Drop-then-build: the next walk builds the source from nothing. + a.upsert = upsert; + expect(await svc.reindexSource(s.name)).toMatchObject({ ok: true, indexed: 250 }); + expect((await heldFor(client, s)).tables).toEqual([`knowledge_${s.name}_g1`]); + }); + }); +} + describe('knowledge-turso without a database or an embedder', () => { it('answers every call SERVICE_UNAVAILABLE in one sentence; the reason is operator text in remedy and healthCheck', async () => { const adapter = new TursoKnowledgeAdapter({ embedder: new FakeEmbedder(), unavailable: 'no native build for win32-arm64' }); diff --git a/packages/plugins/knowledge-turso/src/turso-adapter.ts b/packages/plugins/knowledge-turso/src/turso-adapter.ts index b99f2149b65..34bcda2d6f0 100644 --- a/packages/plugins/knowledge-turso/src/turso-adapter.ts +++ b/packages/plugins/knowledge-turso/src/turso-adapter.ts @@ -88,6 +88,9 @@ const SEARCH_ATTEMPTS = 3; /** The standard ADR-0112 code of a search whose source's index was switched under it on every attempt. */ const CONCURRENT_MODIFICATION = 'CONCURRENT_MODIFICATION'; +/** The standard ADR-0112 code of a build's call refused because the generation it began is gone, as pgvector answers. */ +const LOCK_CONFLICT = 'LOCK_CONFLICT'; + /** The `k` of reciprocal rank fusion: a passage at rank `r` of a leg adds `1 / (k + r)` to its score. */ export const RRF_K = 60; @@ -98,6 +101,24 @@ interface GenerationRow { recipeHash: string | null; dim: number; state: 'active' | 'building'; + /** When the row was made (`created_at`): with the number, what tells a generation from a later one of that number. */ + createdAt: string; +} + +/** + * The generation a build began, as `beginBuild` read it. Generation numbers + * are reused — the next one is the source's highest plus one, so after a drop + * or a replaced build a new generation can take the number again — so the + * build knows its generation by the number, the time its row was made and its + * fingerprint. + */ +type BuildMark = Pick; + +/** Whether `g` is the generation `mark` names: the one the build began, not a later one under its number. */ +function isBuildGeneration(g: GenerationRow | undefined, mark: BuildMark): g is GenerationRow { + return ( + g !== undefined && g.generation === mark.generation && g.createdAt === mark.createdAt && g.fingerprint === mark.fingerprint + ); } /** A source's generations: the active one, and the one under construction. */ @@ -229,7 +250,12 @@ function withTimeout(work: Promise, ms: number, commit = false): Promise IEmbedder | undefined; private readonly queryPrefix: string; private isReady = false; + /** + * The builds this adapter began and has not ended, by source id: the + * generation each one builds into, as begun. A build's writes, listing and + * completion go to that generation and to no other (`writeTarget`). + */ + private readonly builds = new Map(); /** Sources whose legacy table is known to be absent. */ private readonly noLegacy = new Set(); /** Passage tables whose keyword index is known to be complete. */ @@ -382,11 +414,12 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { return this.queued(client, () => this.transaction(async (tx) => { - // The generation may have been switched or abandoned while the embedder - // answered: write only into the one that was planned. + // The generation may have been switched, abandoned or dropped while the + // embedder answered: write only into the one that was planned, never a + // later one under its number (its row made at another time). const still = await tx.execute({ - sql: `SELECT 1 FROM ${quoted(GENERATION_TABLE)} WHERE source_id = ? AND generation = ? AND fingerprint IS ? AND dim = ?`, - args: [sourceId, target.generation, target.fingerprint, target.dim], + sql: `SELECT 1 FROM ${quoted(GENERATION_TABLE)} WHERE source_id = ? AND generation = ? AND fingerprint IS ? AND dim = ? AND created_at = ?`, + args: [sourceId, target.generation, target.fingerprint, target.dim, target.createdAt], }); if (still.rows.length === 0) return { commit: false, value: `${sourceId}#generation-${target.generation}` }; // One request per document (its DELETE and its passages, as one batch @@ -692,29 +725,40 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { assertSourceId(ctx.source.name); const embedder = this.requireEmbedder(); await this.ready(); - await this.queued(client, async () => { - const legacy = await this.hasLegacy(ctx.source.name); - await this.transaction(async (tx) => { - const { active, building } = await this.generations(ctx.source.name, tx); - const fits = (g: GenerationRow | undefined) => - g !== undefined && g.fingerprint === index.fingerprint && g.dim === embedder.dimensions; - // Rebuilt inside the active generation, or the build under way taken up. - if (fits(active) || fits(building)) return { commit: true, value: undefined }; - if (building) { - // A build of another fingerprint left unfinished: replaced, one per source. - await this.dropGenerationTable(tx, ctx.source.name, building.generation); - await tx.execute({ - sql: `DELETE FROM ${quoted(GENERATION_TABLE)} WHERE source_id = ? AND generation = ?`, - args: [ctx.source.name, building.generation], - }); - } - // A source that holds nothing takes the fingerprint as its active one; - // beside an active generation, or a legacy table, it is built aside. - const state = active === undefined && !legacy ? 'active' : 'building'; - await this.openGeneration(tx, ctx.source.name, index.fingerprint, embedder, state); - return { commit: true, value: undefined }; + // The generation taken is the one this build writes into, lists and + // completes; a build that does not begin ends any this adapter had. + try { + await this.queued(client, async () => { + const legacy = await this.hasLegacy(ctx.source.name); + const begun = await this.transaction(async (tx) => { + const { active, building } = await this.generations(ctx.source.name, tx); + const fits = (g: GenerationRow): boolean => g.fingerprint === index.fingerprint && g.dim === embedder.dimensions; + // The build under way taken up, or rebuilt inside the active generation. + if (building !== undefined && fits(building)) return { commit: true, value: building }; + if (active !== undefined && fits(active)) return { commit: true, value: active }; + if (building) { + // A build of another fingerprint left unfinished: replaced, one per source. + await this.dropGenerationTable(tx, ctx.source.name, building.generation); + await tx.execute({ + sql: `DELETE FROM ${quoted(GENERATION_TABLE)} WHERE source_id = ? AND generation = ?`, + args: [ctx.source.name, building.generation], + }); + } + // A source that holds nothing takes the fingerprint as its active one; + // beside an active generation, or a legacy table, it is built aside. + const state = active === undefined && !legacy ? 'active' : 'building'; + return { commit: true, value: await this.openGeneration(tx, ctx.source.name, index.fingerprint, embedder, state) }; + }); + this.builds.set(ctx.source.name, { + generation: begun.generation, + createdAt: begun.createdAt, + fingerprint: begun.fingerprint, + }); }); - }); + } catch (err) { + this.builds.delete(ctx.source.name); + throw err; + } } async completeBuild(ctx: AdapterContext): Promise { @@ -727,6 +771,13 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { await this.transaction(async (tx) => { const { active, building } = await this.generations(ctx.source.name, tx); const t = quoted(GENERATION_TABLE); + // A build this adapter began completes the generation it began and no + // other: gone (the source was dropped, in any process) or replaced by + // another build, it switches, records and drops nothing. + const mine = this.builds.get(ctx.source.name); + const target = + building?.fingerprint === index.fingerprint ? building : active?.fingerprint === index.fingerprint ? active : undefined; + if (mine !== undefined && !isBuildGeneration(target, mine)) throw buildEnded(ctx.source.name); if (building?.fingerprint === index.fingerprint) { if (active) { await this.dropGenerationTable(tx, ctx.source.name, active.generation); @@ -751,7 +802,7 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { return { commit: true, value: undefined }; }); if (legacy) this.noLegacy.add(ctx.source.name); - }); + }).finally(() => this.builds.delete(ctx.source.name)); } /** @@ -761,6 +812,12 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { * releases, when the source still has one. A source it holds nothing for is * no error. A table the store did not make under a generation's name is * refused and nothing is removed (`dropGenerationTable`). + * + * A build of the source under way, in this process or another, does not + * hold the drop back: its generation is dropped with the rest, and its next + * write, listing or completion is refused `LOCK_CONFLICT` and ends it (see + * `writeTarget`), so it never brings the source back. A build that begins + * after the drop builds the source from nothing. */ async dropSource(ctx: AdapterContext): Promise { const client = this.requireClient(); @@ -879,7 +936,7 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { /** The active generation of a source and the one under construction. */ private async generations(sourceId: string, tx?: Transaction): Promise { const found = await (tx ?? this.requireClient()).execute({ - sql: `SELECT generation, fingerprint, recipe_hash, dim, state FROM ${quoted(GENERATION_TABLE)} WHERE source_id = ?`, + sql: `SELECT generation, fingerprint, recipe_hash, dim, state, created_at FROM ${quoted(GENERATION_TABLE)} WHERE source_id = ?`, args: [sourceId], }); const out: SourceGenerations = {}; @@ -890,6 +947,7 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { recipeHash: r.recipe_hash === null ? null : String(r.recipe_hash), dim: Number(r.dim), state: r.state === 'building' ? 'building' : 'active', + createdAt: String(r.created_at), }; out[row.state === 'active' ? 'active' : 'building'] = row; } @@ -1033,7 +1091,9 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { sql: `INSERT INTO ${quoted(GENERATION_TABLE)} (source_id, generation, fingerprint, dim, model, state) VALUES (?, ?, ?, ?, ?, ?)`, args: [sourceId, generation, fingerprint ?? null, embedder.dimensions, embedder.model ?? null, state], }); - return { generation, fingerprint: fingerprint ?? null, recipeHash: null, dim: embedder.dimensions, state }; + // Read back, so the row carries the time it was made (`created_at`): the + // unique indexes hold one row of each state per source, this one. + return (await this.generations(sourceId, tx))[state]!; } /** @@ -1043,6 +1103,13 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { * embedder's width is not the generation's, or — outside a build — when the * source still has a legacy table. A source that holds nothing gets its first * generation (`create`), or none. Runs inside the client's queue. + * + * A call of a build this adapter began (`ctx.reason === 'reindex'`) goes to + * the generation that build began and to no other: when it is no longer + * active or under construction — the source was dropped, by this process or + * another, or another build replaced it — the build is ended and the call + * refused `LOCK_CONFLICT`, so a build never opens a generation and never + * brings a dropped source back. */ private async writeTarget( ctx: AdapterContext, @@ -1056,6 +1123,16 @@ export class TursoKnowledgeAdapter implements IKnowledgeAdapter { if (embedder.dimensions !== g.dim) throw rebuildRequired(sourceId, false); return g; }; + const build = ctx.reason === 'reindex' ? this.builds.get(sourceId) : undefined; + if (build !== undefined) { + const mine = [building, active].find((g) => isBuildGeneration(g, build)); + if (mine === undefined) { + this.builds.delete(sourceId); + throw buildEnded(sourceId); + } + if (fingerprint !== undefined && mine.fingerprint !== fingerprint) throw rebuildRequired(sourceId, false); + return checked(mine); + } if (building !== undefined && fingerprint !== undefined && building.fingerprint === fingerprint) return checked(building); if (active === undefined) { if (await this.hasLegacy(sourceId)) throw rebuildRequired(sourceId, building !== undefined); @@ -1160,6 +1237,26 @@ function rebuildRequired(sourceId: string, building: boolean): Error { }); } +/** + * A build's write, listing or completion refused because the generation the + * build began is gone: the source was dropped, or another build replaced it. + * The same code and status as the pgvector store's. + */ +function buildEnded(sourceId: string): Error { + return Object.assign( + new Error( + `The index this build of knowledge source '${sourceId}' began was dropped or replaced while it ran; this build writes and completes nothing more.`, + ), + { + code: LOCK_CONFLICT, + status: 409, + remedy: + 'The source was removed (its index dropped), or another build of it under another fingerprint replaced this ' + + 'one. Start a reindex again if the source is still served and no build of it is running.', + }, + ); +} + /** * A search whose source's index was switched under it on every attempt: the * store is ready, the search lost a race with a rebuild, and the same search