Elffuss BraidHub

kikocis/continue public

fix: race condition for this.lanceDbIndex being loaded and retrieveEmbeddings accessing it
Changeset195936261ffb3ca86fdf285dd8471173f7a75d6eea6e69feaccd5c03719cf49c
AuthorJacob Kim <jacob@continue.dev> · 2025-07-16 15:54 -07:00
CommitterJacob Kim <jacob@continue.dev> · 2025-07-16 15:54 -07:00
Parentsd22531502d6c

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 );