Merge pull request #6664 from continuedev/jacob/bug/race-condition-initLanceDb

fix: race condition for this.lanceDbIndex being loaded and retrieveEmbeddings accessing it
This commit is contained in:
Dallin Romney 2025-07-17 15:48:55 +02:00 • committed by GitHub
commit ada6b53fda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,12 +60,13 @@ export interface IRetrievalPipeline {
export default class BaseRetrievalPipeline implements IRetrievalPipeline {
private ftsIndex = new FullTextSearchCodebaseIndex();
private lanceDbIndex: LanceDbIndex | null = null;
private lanceDbInitPromise: Promise<void> | null = null;
constructor(protected readonly options: RetrievalPipelineOptions) {
void this.initLanceDb();
}
private async initLanceDb() {
protected async initLanceDb() {
const embedModel = this.options.config.selectedModelByRole.embed;
if (!embedModel) {
@ -77,6 +78,23 @@ export default class BaseRetrievalPipeline implements IRetrievalPipeline {
);
}
protected async ensureLanceDbInitialized(): Promise<boolean> {
if (this.lanceDbIndex) {
return true;
}
if (this.lanceDbInitPromise) {
await this.lanceDbInitPromise;
return this.lanceDbIndex !== null;
}
this.lanceDbInitPromise = this.initLanceDb();
await this.lanceDbInitPromise;
this.lanceDbInitPromise = null; // clear after init
return this.lanceDbIndex !== null;
}
private getCleanedTrigrams(
query: RetrievalPipelineRunArguments["query"],
): string[] {
@ -163,7 +181,9 @@ export default class BaseRetrievalPipeline implements IRetrievalPipeline {
input: string,
n: number,
): Promise<Chunk[]> {
if (!this.lanceDbIndex) {
const initialized = await this.ensureLanceDbInitialized();
if (!initialized || !this.lanceDbIndex) {
console.warn(
"LanceDB index not available, skipping embeddings retrieval",
);