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

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

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
Gate default model-run session pruning · openclaw/opencla...
2026-06-25 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -91,6 +91,8 @@ describe("sessionsCleanupCommand", () => {

9191

mocks.resolveMaintenanceConfig.mockReturnValue({

9292

mode: "warn",

9393

pruneAfterMs: 7 * 24 * 60 * 60 * 1000,

94+

modelRunPruneAfterMs: null,

95+

modelRunPruneAfterConfigured: true,

9496

maxEntries: 500,

9597

resetArchiveRetentionMs: 7 * 24 * 60 * 60 * 1000,

9698

maxDiskBytes: null,

Original file line numberDiff line numberDiff line change

@@ -1689,7 +1689,7 @@ export const FIELD_HELP: Record<string, string> = {

16891689

"session.maintenance.maxEntries":

16901690

"Caps total session entry count retained in the store to prevent unbounded growth over time. Use lower limits for constrained environments, or higher limits when longer history is required.",

16911691

"session.maintenance.modelRunPruneAfter":

1692-

"Retention for short-lived gateway model-run probe sessions (`agent:*:explicit:model-run-<uuid>`). Accepts a duration such as `24h` or `2d`; set `false` to disable model-run-specific cleanup. Default: `24h`.",

1692+

"Retention for short-lived gateway model-run probe sessions (`agent:*:explicit:model-run-<uuid>`). Default: `24h`, but the unset default only runs under session-entry cap pressure. Set a duration such as `24h` or `2d` for normal age-based cleanup, or `false` to disable.",

16931693

"session.maintenance.rotateBytes":

16941694

'Deprecated and ignored. Do not use for `sessions.json` growth control; OpenClaw no longer creates automatic rotation backups, and "openclaw doctor --fix" removes this key.',

16951695

"session.maintenance.resetArchiveRetention":

Original file line numberDiff line numberDiff line change

@@ -30,6 +30,7 @@ import {

3030

capEntryCount,

3131

pruneStaleModelRunEntries,

3232

pruneStaleEntries,

33+

shouldRunModelRunPrune,

3334

type ResolvedSessionMaintenanceConfig,

3435

} from "./store-maintenance.js";

3536

import { loadSessionStore } from "./store.js";

@@ -366,17 +367,18 @@ async function previewStoreCleanup(params: {

366367

})

367368

: 0;

368369

const preserveSessionKeys = collectSessionMaintenancePreserveKeys([params.activeKey]);

369-

const modelRunPruned = pruneStaleModelRunEntries(

370-

previewStore,

371-

params.maintenance.modelRunPruneAfterMs,

372-

{

373-

log: false,

374-

preserveKeys: preserveSessionKeys,

375-

onPruned: ({ key }) => {

376-

modelRunPrunedKeys.add(key);

377-

},

378-

},

379-

);

370+

const modelRunPruned = shouldRunModelRunPrune({

371+

maintenance: params.maintenance,

372+

entryCount: Object.keys(previewStore).length,

373+

})

374+

? pruneStaleModelRunEntries(previewStore, params.maintenance.modelRunPruneAfterMs, {

375+

log: false,

376+

preserveKeys: preserveSessionKeys,

377+

onPruned: ({ key }) => {

378+

modelRunPrunedKeys.add(key);

379+

},

380+

})

381+

: 0;

380382

const pruned = pruneStaleEntries(previewStore, params.maintenance.pruneAfterMs, {

381383

log: false,

382384

preserveKeys: preserveSessionKeys,

Original file line numberDiff line numberDiff line change

@@ -26,6 +26,7 @@ export type ResolvedSessionMaintenanceConfigRuntime = {

2626

pruneAfterMs: number;

2727

maxEntries: number;

2828

modelRunPruneAfterMs: number | null;

29+

modelRunPruneAfterConfigured: boolean;

2930

resetArchiveRetentionMs: number | null;

3031

maxDiskBytes: number | null;

3132

highWaterBytes: number | null;

Original file line numberDiff line numberDiff line change

@@ -35,6 +35,7 @@ import {

3535

capEntryCount,

3636

pruneStaleEntries,

3737

pruneStaleModelRunEntries,

38+

shouldRunModelRunPrune,

3839

shouldRunSessionEntryMaintenance,

3940

type ResolvedSessionMaintenanceConfig,

4041

} from "./store-maintenance.js";

@@ -442,10 +443,17 @@ export function loadSessionStore(

442443

let capped = 0;

443444

if (maintenance.mode === "enforce") {

444445

const preserveSessionKeys = collectSessionMaintenancePreserveKeys();

445-

modelRunPruned = pruneStaleModelRunEntries(store, maintenance.modelRunPruneAfterMs, {

446-

log: false,

447-

preserveKeys: preserveSessionKeys,

448-

});

446+

if (

447+

shouldRunModelRunPrune({

448+

maintenance,

449+

entryCount: beforeCount,

450+

})

451+

) {

452+

modelRunPruned = pruneStaleModelRunEntries(store, maintenance.modelRunPruneAfterMs, {

453+

log: false,

454+

preserveKeys: preserveSessionKeys,

455+

});

456+

}

449457

}

450458

if (maintenance.mode === "enforce" && Object.keys(store).length > maintenance.maxEntries) {

451459

const preserveSessionKeys = collectSessionMaintenancePreserveKeys();

Original file line numberDiff line numberDiff line change

@@ -8,6 +8,7 @@ import {

88

getActiveSessionMaintenanceWarning,

99

pruneStaleModelRunEntries,

1010

pruneStaleEntries,

11+

shouldRunModelRunPrune,

1112

shouldRunSessionEntryMaintenance,

1213

type ResolvedSessionMaintenanceConfig,

1314

type SessionMaintenanceWarning,

@@ -198,16 +199,17 @@ async function applyEnforcedMaintenance(params: {

198199

params.operation.activeSessionKey,

199200

]);

200201

const removedSessionFiles = new Map<string, string | undefined>();

201-

const modelRunPruned = pruneStaleModelRunEntries(

202-

params.operation.store,

203-

params.maintenance.modelRunPruneAfterMs,

204-

{

205-

onPruned: ({ entry }) => {

206-

rememberRemovedSessionFile(removedSessionFiles, entry);

207-

},

208-

preserveKeys: preserveSessionKeys,

209-

},

210-

);

202+

const modelRunPruned = shouldRunModelRunPrune({

203+

maintenance: params.maintenance,

204+

entryCount: params.beforeCount,

205+

})

206+

? pruneStaleModelRunEntries(params.operation.store, params.maintenance.modelRunPruneAfterMs, {

207+

onPruned: ({ entry }) => {

208+

rememberRemovedSessionFile(removedSessionFiles, entry);

209+

},

210+

preserveKeys: preserveSessionKeys,

211+

})

212+

: 0;

211213

const pruned = pruneStaleEntries(params.operation.store, params.maintenance.pruneAfterMs, {

212214

onPruned: ({ entry }) => {

213215

rememberRemovedSessionFile(removedSessionFiles, entry);

Original file line numberDiff line numberDiff line change

@@ -42,6 +42,8 @@ export type ResolvedSessionMaintenanceConfig = {

4242

pruneAfterMs: number;

4343

maxEntries: number;

4444

modelRunPruneAfterMs: number | null;

45+

/** True when modelRunPruneAfter was explicitly set instead of using the pressure-gated default. */

46+

modelRunPruneAfterConfigured: boolean;

4547

resetArchiveRetentionMs: number | null;

4648

maxDiskBytes: number | null;

4749

highWaterBytes: number | null;

@@ -91,7 +93,9 @@ function resolveModelRunPruneAfterMs(maintenance?: SessionMaintenanceConfig): nu

9193

try {

9294

return parseDurationMs(normalized, { defaultUnit: "d" });

9395

} catch {

94-

return DEFAULT_MODEL_RUN_PRUNE_AFTER_MS;

96+

// The schema rejects invalid explicit values. Keep direct resolver callers fail-closed

97+

// rather than silently enabling the default 24h model-run cleanup.

98+

return null;

9599

}

96100

}

97101

@@ -157,6 +161,7 @@ export function resolveMaintenanceConfigFromInput(

157161

pruneAfterMs,

158162

maxEntries: maintenance?.maxEntries ?? DEFAULT_SESSION_MAX_ENTRIES,

159163

modelRunPruneAfterMs: resolveModelRunPruneAfterMs(maintenance),

164+

modelRunPruneAfterConfigured: maintenance?.modelRunPruneAfter !== undefined,

160165

resetArchiveRetentionMs: resolveResetArchiveRetentionMs(maintenance, pruneAfterMs),

161166

maxDiskBytes,

162167

highWaterBytes: resolveHighWaterBytes(maintenance, maxDiskBytes),

@@ -189,16 +194,39 @@ export function shouldRunSessionEntryMaintenance(params: {

189194

return params.entryCount >= resolveSessionEntryMaintenanceHighWater(params.maxEntries);

190195

}

191196
197+

export function shouldRunModelRunPrune(params: {

198+

maintenance: Pick<

199+

ResolvedSessionMaintenanceConfig,

200+

"maxEntries" | "modelRunPruneAfterConfigured" | "modelRunPruneAfterMs"

201+

>;

202+

entryCount: number;

203+

}): boolean {

204+

if (params.maintenance.modelRunPruneAfterMs == null) {

205+

return false;

206+

}

207+

if (params.maintenance.modelRunPruneAfterConfigured) {

208+

return true;

209+

}

210+

return shouldRunSessionEntryMaintenance({

211+

entryCount: params.entryCount,

212+

maxEntries: params.maintenance.maxEntries,

213+

});

214+

}

215+
192216

export function isGatewayModelRunSessionKey(sessionKey: string): boolean {

193-

if (

194-

!/^agent:[^:]+:explicit:model-run-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(

217+

const match =

218+

/^agent:([^:\s]+):explicit:model-run-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.exec(

195219

sessionKey,

196-

)

197-

) {

220+

);

221+

if (!match) {

222+

return false;

223+

}

224+

const agentId = match[1];

225+

if (!agentId || /\s/.test(agentId)) {

198226

return false;

199227

}

200228

const parsed = parseAgentSessionKey(sessionKey);

201-

if (!parsed || !parsed.agentId.trim()) {

229+

if (!parsed || parsed.agentId !== agentId.toLowerCase()) {

202230

return false;

203231

}

204232

const rest = normalizeLowercaseStringOrEmpty(parsed.rest);

Original file line numberDiff line numberDiff line change

@@ -34,6 +34,7 @@ const ENFORCED_MAINTENANCE_OVERRIDE = {

3434

pruneAfterMs: 7 * DAY_MS,

3535

maxEntries: 500,

3636

modelRunPruneAfterMs: DAY_MS,

37+

modelRunPruneAfterConfigured: true,

3738

resetArchiveRetentionMs: 7 * DAY_MS,

3839

maxDiskBytes: null,

3940

highWaterBytes: null,

@@ -170,6 +171,34 @@ describe("Integration: saveSessionStore with pruning", () => {

170171

await fs.writeFile(storePath, JSON.stringify(store), "utf-8");

171172
172173

const cfg = { session: { store: storePath } };

174+

mockLoadConfig.mockReturnValue({

175+

session: {

176+

maintenance: {

177+

mode: "enforce",

178+

pruneAfter: "30d",

179+

maxEntries: 500,

180+

},

181+

},

182+

});

183+

const defaultDryRun = await runSessionsCleanup({

184+

cfg,

185+

opts: { dryRun: true, enforce: true },

186+

targets: [{ agentId: "main", storePath }],

187+

});

188+
189+

expect(defaultDryRun.previewResults[0]?.summary.modelRunPruned).toBe(0);

190+

expect(loadSessionStore(storePath, { skipCache: true })).toHaveProperty(staleModelRun);

191+
192+

mockLoadConfig.mockReturnValue({

193+

session: {

194+

maintenance: {

195+

mode: "enforce",

196+

pruneAfter: "30d",

197+

maxEntries: 500,

198+

modelRunPruneAfter: "24h",

199+

},

200+

},

201+

});

173202

const dryRun = await runSessionsCleanup({

174203

cfg,

175204

opts: { dryRun: true, enforce: true },

@@ -191,6 +220,42 @@ describe("Integration: saveSessionStore with pruning", () => {

191220

expect(loaded).toHaveProperty(recentModelRun);

192221

});

193222
223+

it("saveSessionStore pressure-gates unset default model-run pruning", async () => {

224+

const now = Date.now();

225+

const staleModelRun = "agent:main:explicit:model-run-123e4567-e89b-12d3-a456-426614174020";

226+

const recentModelRun = "agent:main:explicit:model-run-123e4567-e89b-12d3-a456-426614174021";

227+
228+

mockLoadConfig.mockReturnValue({

229+

session: {

230+

maintenance: {

231+

mode: "enforce",

232+

pruneAfter: "30d",

233+

maxEntries: 500,

234+

},

235+

},

236+

});

237+

await saveSessionStore(storePath, {

238+

[staleModelRun]: makeEntry(now - 2 * DAY_MS),

239+

[recentModelRun]: makeEntry(now),

240+

});

241+

expect(loadSessionStore(storePath, { skipCache: true })).toHaveProperty(staleModelRun);

242+
243+

mockLoadConfig.mockReturnValue({

244+

session: {

245+

maintenance: {

246+

mode: "enforce",

247+

pruneAfter: "30d",

248+

maxEntries: 1,

249+

},

250+

},

251+

});

252+

await saveSessionStore(storePath, loadSessionStore(storePath, { skipCache: true }));

253+
254+

const loaded = loadSessionStore(storePath, { skipCache: true });

255+

expect(loaded[staleModelRun]).toBeUndefined();

256+

expect(loaded).toHaveProperty(recentModelRun);

257+

});

258+
194259

it("saveSessionStore prunes stale entries on write", async () => {

195260

applyEnforcedMaintenanceConfig(mockLoadConfig);

196261
Original file line numberDiff line numberDiff line change

@@ -185,6 +185,7 @@ describe("applyFileBackedSessionStoreMaintenance", () => {

185185

pruneAfterMs: 7 * DAY_MS,

186186

maxEntries: 500,

187187

modelRunPruneAfterMs: null,

188+

modelRunPruneAfterConfigured: true,

188189

resetArchiveRetentionMs: null,

189190

maxDiskBytes: null,

190191

highWaterBytes: null,

Original file line numberDiff line numberDiff line change

@@ -261,7 +261,8 @@ export type SessionMaintenanceConfig = {

261261

maxEntries?: number;

262262

/**

263263

* Retention for gateway model-run probe sessions (`agent:*:explicit:model-run-<uuid>`).

264-

* Set `false` to disable model-run-specific cleanup. Default: "24h".

264+

* Unset defaults to "24h" but only runs under session-entry cap pressure;

265+

* setting a duration opts into unconditional age cleanup, and `false` disables.

265266

*/

266267

modelRunPruneAfter?: string | number | false;

267268

/** @deprecated Ignored. Run `openclaw doctor --fix` to remove. */