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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
M
MIT News - Artificial intelligence
量子位
N
Netflix TechBlog - Medium
The Cloudflare Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
B
Blog
博客园_首页
博客园 - Franky
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
H
Help Net Security
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow 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(config): rotate clobber snapshots at cap · openclaw/o...
Kaspre · 2026-05-15 · via Recent Commits to openclaw:main

@@ -13,6 +13,7 @@ type ConfigClobberSnapshotFs = {

1313

readdir(path: string): Promise<string[]>;

1414

rmdir(path: string): Promise<unknown>;

1515

stat(path: string): Promise<{ mtimeMs?: number } | null>;

16+

unlink(path: string): Promise<unknown>;

1617

writeFile(

1718

path: string,

1819

data: string,

@@ -23,6 +24,7 @@ type ConfigClobberSnapshotFs = {

2324

readdirSync(path: string): string[];

2425

rmdirSync(path: string): unknown;

2526

statSync(path: string, options?: { throwIfNoEntry?: boolean }): { mtimeMs?: number } | null;

27+

unlinkSync(path: string): unknown;

2628

writeFileSync(

2729

path: string,

2830

data: string,

@@ -117,28 +119,59 @@ function acquireClobberLockSync(deps: ConfigClobberSnapshotDeps, lockPath: strin

117119

return false;

118120

}

119121120-

async function countClobberedSiblings(

122+

type ClobberedSiblingSnapshot = {

123+

name: string;

124+

path: string;

125+

mtimeMs: number;

126+

};

127+128+

function compareClobberedSiblings(

129+

left: ClobberedSiblingSnapshot,

130+

right: ClobberedSiblingSnapshot,

131+

): number {

132+

return left.mtimeMs - right.mtimeMs || left.name.localeCompare(right.name);

133+

}

134+135+

async function listClobberedSiblings(

121136

deps: ConfigClobberSnapshotDeps,

122137

dir: string,

123138

prefix: string,

124-

): Promise<number> {

139+

): Promise<ClobberedSiblingSnapshot[]> {

125140

try {

126141

const entries = await deps.fs.promises.readdir(dir);

127-

return entries.filter((entry) => entry.startsWith(prefix)).length;

142+

const snapshots: ClobberedSiblingSnapshot[] = [];

143+

for (const entry of entries) {

144+

if (!entry.startsWith(prefix)) {

145+

continue;

146+

}

147+

const snapshotPath = path.join(dir, entry);

148+

const stat = await deps.fs.promises.stat(snapshotPath).catch(() => null);

149+

snapshots.push({ name: entry, path: snapshotPath, mtimeMs: stat?.mtimeMs ?? 0 });

150+

}

151+

return snapshots.toSorted(compareClobberedSiblings);

128152

} catch {

129-

return 0;

153+

return [];

130154

}

131155

}

132156133-

function countClobberedSiblingsSync(

157+

function listClobberedSiblingsSync(

134158

deps: ConfigClobberSnapshotDeps,

135159

dir: string,

136160

prefix: string,

137-

): number {

161+

): ClobberedSiblingSnapshot[] {

138162

try {

139-

return deps.fs.readdirSync(dir).filter((entry) => entry.startsWith(prefix)).length;

163+

const snapshots: ClobberedSiblingSnapshot[] = [];

164+

for (const entry of deps.fs.readdirSync(dir)) {

165+

if (!entry.startsWith(prefix)) {

166+

continue;

167+

}

168+

const snapshotPath = path.join(dir, entry);

169+

const stat = deps.fs.statSync(snapshotPath, { throwIfNoEntry: false });

170+

snapshots.push({ name: entry, path: snapshotPath, mtimeMs: stat?.mtimeMs ?? 0 });

171+

}

172+

return snapshots.toSorted(compareClobberedSiblings);

140173

} catch {

141-

return 0;

174+

return [];

142175

}

143176

}

144177

@@ -152,10 +185,44 @@ function warnClobberCapReached(

152185

}

153186

clobberCapWarnedPaths.add(configPath);

154187

deps.logger.warn(

155-

`Config clobber snapshot cap reached for ${configPath}: ${existing} existing .clobbered.* files; skipping additional forensic snapshots.`,

188+

`Config clobber snapshot cap reached for ${configPath}: ${existing} existing .clobbered.* files; rotating oldest snapshots to preserve the latest forensic copy.`,

156189

);

157190

}

158191192+

async function rotateOldestClobberedSiblings(

193+

deps: ConfigClobberSnapshotDeps,

194+

snapshots: ClobberedSiblingSnapshot[],

195+

): Promise<boolean> {

196+

const deleteCount = Math.max(0, snapshots.length - CONFIG_CLOBBER_SNAPSHOT_LIMIT + 1);

197+

for (const snapshot of snapshots.slice(0, deleteCount)) {

198+

try {

199+

await deps.fs.promises.unlink(snapshot.path);

200+

} catch (error) {

201+

if (!isFsErrorCode(error, "ENOENT")) {

202+

return false;

203+

}

204+

}

205+

}

206+

return true;

207+

}

208+209+

function rotateOldestClobberedSiblingsSync(

210+

deps: ConfigClobberSnapshotDeps,

211+

snapshots: ClobberedSiblingSnapshot[],

212+

): boolean {

213+

const deleteCount = Math.max(0, snapshots.length - CONFIG_CLOBBER_SNAPSHOT_LIMIT + 1);

214+

for (const snapshot of snapshots.slice(0, deleteCount)) {

215+

try {

216+

deps.fs.unlinkSync(snapshot.path);

217+

} catch (error) {

218+

if (!isFsErrorCode(error, "ENOENT")) {

219+

return false;

220+

}

221+

}

222+

}

223+

return true;

224+

}

225+159226

function buildClobberedTargetPath(configPath: string, observedAt: string, attempt: number): string {

160227

const basePath = `${configPath}.clobbered.${formatConfigArtifactTimestamp(observedAt)}`;

161228

return attempt === 0 ? basePath : `${basePath}-${String(attempt).padStart(2, "0")}`;

@@ -173,10 +240,13 @@ export async function persistBoundedClobberedConfigSnapshot(params: {

173240

return null;

174241

}

175242

try {

176-

const existing = await countClobberedSiblings(params.deps, paths.dir, paths.prefix);

177-

if (existing >= CONFIG_CLOBBER_SNAPSHOT_LIMIT) {

178-

warnClobberCapReached(params.deps, params.configPath, existing);

179-

return null;

243+

const existing = await listClobberedSiblings(params.deps, paths.dir, paths.prefix);

244+

if (existing.length >= CONFIG_CLOBBER_SNAPSHOT_LIMIT) {

245+

warnClobberCapReached(params.deps, params.configPath, existing.length);

246+

const rotated = await rotateOldestClobberedSiblings(params.deps, existing);

247+

if (!rotated) {

248+

return null;

249+

}

180250

}

181251

for (let attempt = 0; attempt < CONFIG_CLOBBER_SNAPSHOT_LIMIT; attempt++) {

182252

const targetPath = buildClobberedTargetPath(params.configPath, params.observedAt, attempt);

@@ -210,10 +280,12 @@ export function persistBoundedClobberedConfigSnapshotSync(params: {

210280

return null;

211281

}

212282

try {

213-

const existing = countClobberedSiblingsSync(params.deps, paths.dir, paths.prefix);

214-

if (existing >= CONFIG_CLOBBER_SNAPSHOT_LIMIT) {

215-

warnClobberCapReached(params.deps, params.configPath, existing);

216-

return null;

283+

const existing = listClobberedSiblingsSync(params.deps, paths.dir, paths.prefix);

284+

if (existing.length >= CONFIG_CLOBBER_SNAPSHOT_LIMIT) {

285+

warnClobberCapReached(params.deps, params.configPath, existing.length);

286+

if (!rotateOldestClobberedSiblingsSync(params.deps, existing)) {

287+

return null;

288+

}

217289

}

218290

for (let attempt = 0; attempt < CONFIG_CLOBBER_SNAPSHOT_LIMIT; attempt++) {

219291

const targetPath = buildClobberedTargetPath(params.configPath, params.observedAt, attempt);