From f5569dff2cdf4e150336b50843ed2a8c53a06644 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Tue, 20 Oct 2026 16:17:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=81=20fix:=20Build=20the=20KeyvMongo?= =?UTF-8?q?=20Key=20Index=20Through=20the=20Retrying=20Helper=20(#17282)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api/src/cache/keyvMongo.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/api/src/cache/keyvMongo.ts b/packages/api/src/cache/keyvMongo.ts index fe2330d0cf..34189800ca 100644 --- a/packages/api/src/cache/keyvMongo.ts +++ b/packages/api/src/cache/keyvMongo.ts @@ -1,7 +1,7 @@ import mongoose from 'mongoose'; import { EventEmitter } from 'events'; import { GridFSBucket } from 'mongodb'; -import { logger } from '@librechat/data-schemas'; +import { buildIndexWithRetry, logger } from '@librechat/data-schemas'; import type { Db, ReadPreference, Collection } from 'mongodb'; interface KeyvMongoOptions { @@ -79,7 +79,10 @@ class KeyvMongoCustom extends EventEmitter { /** Every read and upsert filters on `key`; unindexed, each one scans the collection. * Built in the background, and skipped when the deployment disables auto indexing. */ if (mongoose.connection.config?.autoIndex !== false) { - store.createIndex({ key: 1 }).catch((error: unknown) => { + buildIndexWithRetry( + () => store.createIndex({ key: 1 }), + `KeyvMongo "${collection}" key index`, + ).catch((error: unknown) => { logger.warn(`[KeyvMongo] Could not index "${collection}" by key`, error); }); }