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

推荐订阅源

量子位
D
Docker
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
美团技术团队
博客园 - 叶小钗
I
InfoQ
Jina AI
Jina AI
博客园 - 司徒正美
雷峰网
雷峰网
B
Blog
Y
Y Combinator Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Announcements
Recent Announcements
V
V2EX
N
Netflix TechBlog - Medium

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): harden atomic reindex cleanup · openclaw/ope...
steipete · 2026-05-09 · via Recent Commits to openclaw:main

@@ -8,30 +8,48 @@ type MemoryIndexFileOps = {

88

wait: (ms: number) => Promise<void>;

99

};

101011-

type MoveMemoryIndexFilesOptions = {

11+

type MemoryIndexFileOptions = {

1212

fileOps?: MemoryIndexFileOps;

1313

maxRenameAttempts?: number;

1414

renameRetryDelayMs?: number;

15+

maxRemoveAttempts?: number;

16+

removeRetryDelayMs?: number;

1517

};

161819+

type ResolvedMemoryIndexFileOptions = Required<MemoryIndexFileOptions>;

20+1721

const defaultFileOps: MemoryIndexFileOps = {

1822

rename: fs.rename,

1923

rm: fs.rm,

2024

wait: sleep,

2125

};

222623-

const transientRenameErrorCodes = new Set(["EBUSY", "EPERM", "EACCES"]);

27+

const transientFileErrorCodes = new Set(["EBUSY", "EPERM", "EACCES"]);

2428

const defaultMaxRenameAttempts = 6;

2529

const defaultRenameRetryDelayMs = 25;

30+

const defaultMaxRemoveAttempts = 10;

31+

const defaultRemoveRetryDelayMs = 50;

32+33+

function isTransientFileError(err: unknown): boolean {

34+

return transientFileErrorCodes.has((err as NodeJS.ErrnoException).code ?? "");

35+

}

263627-

function isTransientRenameError(err: unknown): boolean {

28-

return transientRenameErrorCodes.has((err as NodeJS.ErrnoException).code ?? "");

37+

function resolveMemoryIndexFileOptions(

38+

options: MemoryIndexFileOptions = {},

39+

): ResolvedMemoryIndexFileOptions {

40+

return {

41+

fileOps: options.fileOps ?? defaultFileOps,

42+

maxRenameAttempts: Math.max(1, options.maxRenameAttempts ?? defaultMaxRenameAttempts),

43+

renameRetryDelayMs: options.renameRetryDelayMs ?? defaultRenameRetryDelayMs,

44+

maxRemoveAttempts: Math.max(1, options.maxRemoveAttempts ?? defaultMaxRemoveAttempts),

45+

removeRetryDelayMs: options.removeRetryDelayMs ?? defaultRemoveRetryDelayMs,

46+

};

2947

}

30483149

async function renameWithRetry(

3250

source: string,

3351

target: string,

34-

options: Required<MoveMemoryIndexFilesOptions>,

52+

options: ResolvedMemoryIndexFileOptions,

3553

): Promise<void> {

3654

for (let attempt = 1; attempt <= options.maxRenameAttempts; attempt++) {

3755

try {

@@ -41,7 +59,7 @@ async function renameWithRetry(

4159

if ((err as NodeJS.ErrnoException).code === "ENOENT") {

4260

return;

4361

}

44-

if (!isTransientRenameError(err) || attempt === options.maxRenameAttempts) {

62+

if (!isTransientFileError(err) || attempt === options.maxRenameAttempts) {

4563

throw err;

4664

}

4765

await options.fileOps.wait(options.renameRetryDelayMs * attempt);

@@ -53,13 +71,9 @@ async function renameWithRetry(

5371

export async function moveMemoryIndexFiles(

5472

sourceBase: string,

5573

targetBase: string,

56-

options: MoveMemoryIndexFilesOptions = {},

74+

options: MemoryIndexFileOptions = {},

5775

): Promise<void> {

58-

const resolvedOptions: Required<MoveMemoryIndexFilesOptions> = {

59-

fileOps: options.fileOps ?? defaultFileOps,

60-

maxRenameAttempts: Math.max(1, options.maxRenameAttempts ?? defaultMaxRenameAttempts),

61-

renameRetryDelayMs: options.renameRetryDelayMs ?? defaultRenameRetryDelayMs,

62-

};

76+

const resolvedOptions = resolveMemoryIndexFileOptions(options);

6377

const suffixes = ["", "-wal", "-shm"];

6478

for (const suffix of suffixes) {

6579

const source = `${sourceBase}${suffix}`;

@@ -68,12 +82,33 @@ export async function moveMemoryIndexFiles(

6882

}

6983

}

708471-

async function removeMemoryIndexFiles(

85+

async function rmWithRetry(path: string, options: ResolvedMemoryIndexFileOptions): Promise<void> {

86+

for (let attempt = 1; attempt <= options.maxRemoveAttempts; attempt++) {

87+

try {

88+

await options.fileOps.rm(path, { force: true });

89+

return;

90+

} catch (err) {

91+

if ((err as NodeJS.ErrnoException).code === "ENOENT") {

92+

return;

93+

}

94+

if (!isTransientFileError(err) || attempt === options.maxRemoveAttempts) {

95+

throw err;

96+

}

97+

await options.fileOps.wait(options.removeRetryDelayMs * attempt);

98+

}

99+

}

100+

throw new Error("rm retry loop exited unexpectedly");

101+

}

102+103+

export async function removeMemoryIndexFiles(

72104

basePath: string,

73-

fileOps: MemoryIndexFileOps = defaultFileOps,

105+

options: MemoryIndexFileOptions = {},

74106

): Promise<void> {

107+

const resolvedOptions = resolveMemoryIndexFileOptions(options);

75108

const suffixes = ["", "-wal", "-shm"];

76-

await Promise.all(suffixes.map((suffix) => fileOps.rm(`${basePath}${suffix}`, { force: true })));

109+

for (const suffix of suffixes) {

110+

await rmWithRetry(`${basePath}${suffix}`, resolvedOptions);

111+

}

77112

}

7811379114

async function swapMemoryIndexFiles(targetPath: string, tempPath: string): Promise<void> {

@@ -92,13 +127,23 @@ export async function runMemoryAtomicReindex<T>(params: {

92127

targetPath: string;

93128

tempPath: string;

94129

build: () => Promise<T>;

130+

beforeTempCleanup?: () => Promise<void> | void;

131+

fileOptions?: MemoryIndexFileOptions;

95132

}): Promise<T> {

96133

try {

97134

const result = await params.build();

98135

await swapMemoryIndexFiles(params.targetPath, params.tempPath);

99136

return result;

100137

} catch (err) {

101-

await removeMemoryIndexFiles(params.tempPath);

138+

try {

139+

await params.beforeTempCleanup?.();

140+

await removeMemoryIndexFiles(params.tempPath, params.fileOptions);

141+

} catch (cleanupErr) {

142+

throw new AggregateError(

143+

[err, cleanupErr],

144+

"memory atomic reindex failed and temp cleanup failed",

145+

);

146+

}

102147

throw err;

103148

}

104149

}