fix: raise memory sqlite busy timeout

This commit is contained in:
Peter Steinberger
2026-05-08 21:05:30 +01:00
parent 3584a50437
commit 337e7f63aa
3 changed files with 6 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ import {
requireNodeSqlite,
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
export const MEMORY_SQLITE_BUSY_TIMEOUT_MS = 30_000;
export function openMemoryDatabaseAtPath(dbPath: string, allowExtension: boolean): DatabaseSync {
const dir = path.dirname(dbPath);
ensureDir(dir);
@@ -16,7 +18,7 @@ export function openMemoryDatabaseAtPath(dbPath: string, allowExtension: boolean
// busy_timeout is per-connection and resets to 0 on restart.
// Set it on every open so concurrent processes retry instead of
// failing immediately with SQLITE_BUSY.
db.exec("PRAGMA busy_timeout = 5000");
db.exec(`PRAGMA busy_timeout = ${MEMORY_SQLITE_BUSY_TIMEOUT_MS}`);
return db;
}

View File

@@ -4,7 +4,7 @@ import path from "node:path";
import type { DatabaseSync } from "node:sqlite";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { openMemoryDatabaseAtPath } from "./manager-db.js";
import { MEMORY_SQLITE_BUSY_TIMEOUT_MS, openMemoryDatabaseAtPath } from "./manager-db.js";
import {
_createMemorySyncControlConfigForTests,
enqueueMemoryTargetedSessionSync,
@@ -219,7 +219,7 @@ describe("memory manager readonly recovery", () => {
| { busy_timeout?: number; timeout?: number }
| undefined;
const busyTimeout = row?.busy_timeout ?? row?.timeout;
expect(busyTimeout).toBe(5000);
expect(busyTimeout).toBe(MEMORY_SQLITE_BUSY_TIMEOUT_MS);
db.close();
});

View File

@@ -2218,7 +2218,7 @@ export class QmdMemoryManager implements MemorySearchManager {
this.db = new DatabaseSync(this.indexPath, { readOnly: true });
// busy_timeout is per-connection; set it on every open so concurrent
// processes retry instead of failing immediately with SQLITE_BUSY.
// Use a lower value than the write path (5 s) because this read-only
// Use a lower value than the memory write path because this read-only
// connection runs synchronous queries on the main thread via DatabaseSync.
// In WAL mode readers rarely block, so 1 s is a safe upper bound.
this.db.exec("PRAGMA busy_timeout = 1000");