惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
GbyAI
GbyAI
博客园_首页
V
Visual Studio Blog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
腾讯CDC
博客园 - Franky
IT之家
IT之家
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(memory): prevent peer-write loss during reindex · ope...
vincentkoc · 2026-06-16 · via Recent Commits to openclaw:main

@@ -6,12 +6,15 @@ import { DatabaseSync } from "node:sqlite";

66

import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";

77

import {

88

cleanupAgedMemoryReindexTempFiles,

9+

closeMemoryDatabase,

910

openMemoryDatabaseAtPath,

1011

openMemoryReindexTempDatabaseAtPath,

1112

} from "./manager-db.js";

1213

import {

14+

acquireMemoryReindexSwapLock,

1315

acquireMemoryReindexLock,

1416

resolveMemoryReindexLockPath,

17+

tryAcquireMemoryReindexSwapLock,

1518

tryAcquireMemoryReindexLock,

1619

} from "./manager-reindex-lock.js";

1720

@@ -56,15 +59,15 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

56595760

const db = openMemoryDatabaseAtPath(dbPath, false);

5861

expect(db).toBeDefined();

59-

db.close();

62+

closeMemoryDatabase(db);

6063

});

61646265

it("allows creating a new database when allowCreate is true", async () => {

6366

const dbPath = path.join(fixtureRoot, `case-${caseId++}`, "new-index.sqlite");

64676568

const db = openMemoryDatabaseAtPath(dbPath, false, true);

6669

expect(db).toBeDefined();

67-

db.close();

70+

closeMemoryDatabase(db);

68716972

const stat = await fs.stat(dbPath);

7073

expect(stat.size).toBeGreaterThan(0);

@@ -95,7 +98,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

95989699

reindexLock.release();

97100

const db = openMemoryDatabaseAtPath(dbPath, false, true);

98-

db.close();

101+

closeMemoryDatabase(db);

99102

});

100103101104

it("refuses to auto-create an empty database when allowCreate is false", async () => {

@@ -118,7 +121,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

118121119122

const reopen = openMemoryDatabaseAtPath(dbPath, false, false);

120123

expect(reopen).toBeDefined();

121-

reopen.close();

124+

closeMemoryDatabase(reopen);

122125

});

123126124127

it("removes aged orphan reindex temp files before opening the live database", async () => {

@@ -138,7 +141,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

138141

}

139142140143

const db = openMemoryDatabaseAtPath(dbPath, false);

141-

db.close();

144+

closeMemoryDatabase(db);

142145143146

await expectPathMissing(orphanBase);

144147

await expectPathMissing(`${orphanBase}-wal`);

@@ -165,7 +168,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

165168

}

166169167170

const db = openMemoryDatabaseAtPath(dbPath, false);

168-

db.close();

171+

closeMemoryDatabase(db);

169172170173

await expectPathMissing(orphanBase);

171174

await expectPathMissing(`${orphanBase}-journal`);

@@ -188,7 +191,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

188191

await fs.utimes(strandedJournal, old, old);

189192190193

const db = openMemoryDatabaseAtPath(dbPath, false);

191-

db.close();

194+

closeMemoryDatabase(db);

192195193196

await expectPathMissing(strandedJournal);

194197

});

@@ -207,7 +210,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

207210

}

208211209212

const db = openMemoryDatabaseAtPath(dbPath, false);

210-

db.close();

213+

closeMemoryDatabase(db);

211214212215

await expect(fs.access(activeBase)).resolves.toBeUndefined();

213216

await expect(fs.access(`${activeBase}-wal`)).resolves.toBeUndefined();

@@ -233,7 +236,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

233236234237

cleanupAgedMemoryReindexTempFiles(dbPath);

235238

const db = openMemoryDatabaseAtPath(dbPath, false);

236-

db.close();

239+

closeMemoryDatabase(db);

237240238241

await expect(fs.access(activeBase)).resolves.toBeUndefined();

239242

await expect(fs.access(`${activeBase}-wal`)).resolves.toBeUndefined();

@@ -254,7 +257,7 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

254257

await fs.utimes(orphanBase, old, old);

255258256259

const db = openMemoryDatabaseAtPath(dbPath, false, true);

257-

db.close();

260+

closeMemoryDatabase(db);

258261259262

await expect(fs.access(orphanBase)).resolves.toBeUndefined();

260263

});

@@ -275,6 +278,36 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

275278

await expect(fs.access(resolveMemoryReindexLockPath(dbPath))).resolves.toBeUndefined();

276279

});

277280281+

it("blocks an atomic swap while a live memory database is open", async () => {

282+

const dbPath = path.join(fixtureRoot, `case-${caseId++}`, "index.sqlite");

283+

await fs.mkdir(path.dirname(dbPath), { recursive: true });

284+

const seed = new DatabaseSync(dbPath);

285+

seed.close();

286+287+

const db = openMemoryDatabaseAtPath(dbPath, false);

288+

expect(tryAcquireMemoryReindexSwapLock(dbPath)).toBeUndefined();

289+290+

closeMemoryDatabase(db);

291+

const swapLock = acquireMemoryReindexSwapLock(dbPath);

292+

swapLock.release();

293+

});

294+295+

it("blocks a live database open while an atomic swap is active", async () => {

296+

const dbPath = path.join(fixtureRoot, `case-${caseId++}`, "index.sqlite");

297+

await fs.mkdir(path.dirname(dbPath), { recursive: true });

298+

const seed = new DatabaseSync(dbPath);

299+

seed.close();

300+301+

const swapLock = acquireMemoryReindexSwapLock(dbPath);

302+

expect(() => openMemoryDatabaseAtPath(dbPath, false)).toThrow(

303+

/unavailable during a safe reindex swap/,

304+

);

305+

swapLock.release();

306+307+

const db = openMemoryDatabaseAtPath(dbPath, false);

308+

closeMemoryDatabase(db);

309+

});

310+278311

it("does not block database startup when orphan discovery fails", async () => {

279312

const dbPath = path.join(fixtureRoot, `case-${caseId++}`, "index.sqlite");

280313

await fs.mkdir(path.dirname(dbPath), { recursive: true });

@@ -285,6 +318,6 @@ describe("openMemoryDatabaseAtPath readOnly probe", () => {

285318

});

286319287320

const db = openMemoryDatabaseAtPath(dbPath, false);

288-

db.close();

321+

closeMemoryDatabase(db);

289322

});

290323

});