diff --git a/openclaw/index.ts b/openclaw/index.ts index 7fd1535a0..4c18a89bd 100644 --- a/openclaw/index.ts +++ b/openclaw/index.ts @@ -41,6 +41,7 @@ type Mem0Config = { vectorStore?: { provider: string; config: Record }; llm?: { provider: string; config: Record }; historyDbPath?: string; + disableHistory?: boolean; }; // Shared userId: string; @@ -132,7 +133,10 @@ class PlatformProvider implements Mem0Provider { private async ensureClient(): Promise { if (this.client) return; if (this.initPromise) return this.initPromise; - this.initPromise = this._init(); + this.initPromise = this._init().catch((err) => { + this.initPromise = null; + throw err; + }); return this.initPromise; } @@ -225,7 +229,10 @@ class OSSProvider implements Mem0Provider { private async ensureMemory(): Promise { if (this.memory) return; if (this.initPromise) return this.initPromise; - this.initPromise = this._init(); + this.initPromise = this._init().catch((err) => { + this.initPromise = null; + throw err; + }); return this.initPromise; } @@ -246,9 +253,30 @@ class OSSProvider implements Mem0Provider { config.historyDbPath = dbPath; } + if (this.ossConfig?.disableHistory) { + config.disableHistory = true; + } + if (this.customPrompt) config.customPrompt = this.customPrompt; - this.memory = new Memory(config); + try { + this.memory = new Memory(config); + } catch (err) { + // If initialization fails (e.g. native SQLite binding resolution under + // jiti), retry with history disabled — the history DB is the most common + // source of native-binding failures and is not required for core + // memory operations. + if (!config.disableHistory) { + console.warn( + "[mem0] Memory initialization failed, retrying with history disabled:", + err instanceof Error ? err.message : err, + ); + config.disableHistory = true; + this.memory = new Memory(config); + } else { + throw err; + } + } } async add(