From 5ae627b51a864f2502f8f89b764669ce70de0a8f Mon Sep 17 00:00:00 2001 From: utkarsh240799 Date: Sun, 15 Mar 2026 00:48:12 +0530 Subject: [PATCH] fix(openclaw): add SQLite resilience for OSS mode initialization Fix initPromise poisoning in both PlatformProvider and OSSProvider where a failed init permanently cached the rejected promise, preventing retries. Add disableHistory passthrough so users can opt out of SQLite history storage. Add graceful fallback that auto-retries with history disabled when Memory construction fails (e.g. native binding resolution under jiti). Fixes #4172 Co-Authored-By: Claude Opus 4.6 (1M context) --- openclaw/index.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) 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(