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) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
df79a43925
commit
5ae627b51a
+31
-3
@@ -41,6 +41,7 @@ type Mem0Config = {
|
|||||||
vectorStore?: { provider: string; config: Record<string, unknown> };
|
vectorStore?: { provider: string; config: Record<string, unknown> };
|
||||||
llm?: { provider: string; config: Record<string, unknown> };
|
llm?: { provider: string; config: Record<string, unknown> };
|
||||||
historyDbPath?: string;
|
historyDbPath?: string;
|
||||||
|
disableHistory?: boolean;
|
||||||
};
|
};
|
||||||
// Shared
|
// Shared
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -132,7 +133,10 @@ class PlatformProvider implements Mem0Provider {
|
|||||||
private async ensureClient(): Promise<void> {
|
private async ensureClient(): Promise<void> {
|
||||||
if (this.client) return;
|
if (this.client) return;
|
||||||
if (this.initPromise) return this.initPromise;
|
if (this.initPromise) return this.initPromise;
|
||||||
this.initPromise = this._init();
|
this.initPromise = this._init().catch((err) => {
|
||||||
|
this.initPromise = null;
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
return this.initPromise;
|
return this.initPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +229,10 @@ class OSSProvider implements Mem0Provider {
|
|||||||
private async ensureMemory(): Promise<void> {
|
private async ensureMemory(): Promise<void> {
|
||||||
if (this.memory) return;
|
if (this.memory) return;
|
||||||
if (this.initPromise) return this.initPromise;
|
if (this.initPromise) return this.initPromise;
|
||||||
this.initPromise = this._init();
|
this.initPromise = this._init().catch((err) => {
|
||||||
|
this.initPromise = null;
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
return this.initPromise;
|
return this.initPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,9 +253,30 @@ class OSSProvider implements Mem0Provider {
|
|||||||
config.historyDbPath = dbPath;
|
config.historyDbPath = dbPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.ossConfig?.disableHistory) {
|
||||||
|
config.disableHistory = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.customPrompt) config.customPrompt = this.customPrompt;
|
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(
|
async add(
|
||||||
|
|||||||
Reference in New Issue
Block a user