Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔁 fix: Build the KeyvMongo Key Index Through the Retrying Helper (#17282)

Marco Berettaf5569dff2cdf
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);
});
}