Elffuss BraidHub

kikocis/continue public

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

fix: race condition for this.lanceDbIndex being loaded and retrieveEmbeddings accessing it
Changeseta95359706ef42de25c34b528f1684b535200e6634542cddec97853eb422ebfa4
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-17 15:48 +02:00
CommitterGitHub <noreply@github.com> · 2025-07-17 15:48 +02:00
Parentsbc96543ccce6, 195936261ffb

Browse the files at this changeset

1 file changed

modified core/context/retrieval/pipelines/BaseRetrievalPipeline.ts +22 −2
@@ -60,12 +60,13 @@
6060 export default class BaseRetrievalPipeline implements IRetrievalPipeline {
6161 private ftsIndex = new FullTextSearchCodebaseIndex();
6262 private lanceDbIndex: LanceDbIndex | null = null;
63+ private lanceDbInitPromise: Promise<void> | null = null;
6364
6465 constructor(protected readonly options: RetrievalPipelineOptions) {
6566 void this.initLanceDb();
6667 }
6768
68- private async initLanceDb() {
69+ protected async initLanceDb() {
6970 const embedModel = this.options.config.selectedModelByRole.embed;
7071
7172 if (!embedModel) {
@@ -77,6 +78,23 @@
7778 );
7879 }
7980
81+ protected async ensureLanceDbInitialized(): Promise<boolean> {
82+ if (this.lanceDbIndex) {
83+ return true;
84+ }
85+
86+ if (this.lanceDbInitPromise) {
87+ await this.lanceDbInitPromise;
88+ return this.lanceDbIndex !== null;
89+ }
90+
91+ this.lanceDbInitPromise = this.initLanceDb();
92+ await this.lanceDbInitPromise;
93+ this.lanceDbInitPromise = null; // clear after init
94+
95+ return this.lanceDbIndex !== null;
96+ }
97+
8098 private getCleanedTrigrams(
8199 query: RetrievalPipelineRunArguments["query"],
82100 ): string[] {
@@ -163,7 +181,9 @@
163181 input: string,
164182 n: number,
165183 ): Promise<Chunk[]> {
166- if (!this.lanceDbIndex) {
184+ const initialized = await this.ensureLanceDbInitialized();
185+
186+ if (!initialized || !this.lanceDbIndex) {
167187 console.warn(
168188 "LanceDB index not available, skipping embeddings retrieval",
169189 );