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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
C
Check Point Blog
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
Jina AI
Jina AI
博客园 - 【当耐特】
U
Unit 42
月光博客
月光博客
腾讯CDC
Y
Y Combinator Blog
小众软件
小众软件
博客园_首页
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tailwind CSS 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
fix(gateway): cap retained compaction checkpoint bytes · ...
galiniliev · 2026-05-26 · via Recent Commits to openclaw:main

@@ -22,6 +22,7 @@ import { resolveGatewaySessionStoreTarget } from "./session-utils.js";

2222

const log = createSubsystemLogger("gateway/session-compaction-checkpoints");

2323

const MAX_COMPACTION_CHECKPOINTS_PER_SESSION = 25;

2424

export const MAX_COMPACTION_CHECKPOINT_SNAPSHOT_BYTES = 64 * 1024 * 1024;

25+

export const MAX_COMPACTION_CHECKPOINT_RETAINED_BYTES_PER_SESSION = 128 * 1024 * 1024;

25262627

export type CapturedCompactionCheckpointSnapshot = {

2728

sessionId: string;

@@ -34,17 +35,58 @@ type ForkedCompactionCheckpointTranscript = {

3435

sessionFile: string;

3536

};

363737-

function trimSessionCheckpoints(checkpoints: SessionCompactionCheckpoint[] | undefined): {

38+

function checkpointSnapshotPath(checkpoint: SessionCompactionCheckpoint): string | undefined {

39+

return checkpoint.preCompaction.sessionFile?.trim() || undefined;

40+

}

41+42+

function checkpointSnapshotBytes(

43+

checkpoint: SessionCompactionCheckpoint,

44+

snapshotBytesByPath: ReadonlyMap<string, number>,

45+

): number {

46+

const sessionFile = checkpointSnapshotPath(checkpoint);

47+

if (!sessionFile) {

48+

return 0;

49+

}

50+

const bytes = snapshotBytesByPath.get(sessionFile);

51+

return typeof bytes === "number" && Number.isFinite(bytes) && bytes > 0 ? bytes : 0;

52+

}

53+54+

function trimSessionCheckpoints(

55+

checkpoints: SessionCompactionCheckpoint[] | undefined,

56+

snapshotBytesByPath: ReadonlyMap<string, number> = new Map(),

57+

): {

3858

kept: SessionCompactionCheckpoint[] | undefined;

3959

removed: SessionCompactionCheckpoint[];

4060

} {

4161

if (!Array.isArray(checkpoints) || checkpoints.length === 0) {

4262

return { kept: undefined, removed: [] };

4363

}

44-

const kept = checkpoints.slice(-MAX_COMPACTION_CHECKPOINTS_PER_SESSION);

64+

const countTrimmed = checkpoints.slice(-MAX_COMPACTION_CHECKPOINTS_PER_SESSION);

65+

const countRemoved = checkpoints.slice(0, Math.max(0, checkpoints.length - countTrimmed.length));

66+

const keptNewestFirst: SessionCompactionCheckpoint[] = [];

67+

const byteRemovedNewestFirst: SessionCompactionCheckpoint[] = [];

68+

let retainedBytes = 0;

69+

for (let index = countTrimmed.length - 1; index >= 0; index -= 1) {

70+

const checkpoint = countTrimmed[index];

71+

if (!checkpoint) {

72+

continue;

73+

}

74+

const checkpointBytes = checkpointSnapshotBytes(checkpoint, snapshotBytesByPath);

75+

const keepNewestCheckpoint = keptNewestFirst.length === 0;

76+

if (

77+

keepNewestCheckpoint ||

78+

retainedBytes + checkpointBytes <= MAX_COMPACTION_CHECKPOINT_RETAINED_BYTES_PER_SESSION

79+

) {

80+

keptNewestFirst.push(checkpoint);

81+

retainedBytes += checkpointBytes;

82+

} else {

83+

byteRemovedNewestFirst.push(checkpoint);

84+

}

85+

}

86+

const kept = keptNewestFirst.toReversed();

4587

return {

46-

kept,

47-

removed: checkpoints.slice(0, Math.max(0, checkpoints.length - kept.length)),

88+

kept: kept.length > 0 ? kept : undefined,

89+

removed: [...countRemoved, ...byteRemovedNewestFirst.toReversed()],

4890

};

4991

}

5092

@@ -54,6 +96,27 @@ function sessionStoreCheckpoints(

5496

return Array.isArray(entry?.compactionCheckpoints) ? [...entry.compactionCheckpoints] : [];

5597

}

569899+

async function statCheckpointSnapshotBytes(

100+

checkpoints: readonly SessionCompactionCheckpoint[],

101+

): Promise<Map<string, number>> {

102+

const bytesByPath = new Map<string, number>();

103+

await Promise.all(

104+

checkpoints.map(async (checkpoint) => {

105+

const sessionFile = checkpointSnapshotPath(checkpoint);

106+

if (!sessionFile || bytesByPath.has(sessionFile)) {

107+

return;

108+

}

109+

try {

110+

const stat = await fs.stat(sessionFile);

111+

bytesByPath.set(sessionFile, stat.isFile() ? stat.size : 0);

112+

} catch {

113+

bytesByPath.set(sessionFile, 0);

114+

}

115+

}),

116+

);

117+

return bytesByPath;

118+

}

119+57120

export function resolveSessionCompactionCheckpointReason(params: {

58121

trigger?: "budget" | "overflow" | "manual";

59122

timedOut?: boolean;

@@ -443,14 +506,15 @@ export async function persistSessionCompactionCheckpoint(params: {

443506

removed: SessionCompactionCheckpoint[];

444507

}

445508

| undefined;

446-

await updateSessionStore(target.storePath, (store) => {

509+

await updateSessionStore(target.storePath, async (store) => {

447510

const existing = store[target.canonicalKey];

448511

if (!existing?.sessionId) {

449512

return;

450513

}

451514

const checkpoints = sessionStoreCheckpoints(existing);

452515

checkpoints.push(checkpoint);

453-

trimmedCheckpoints = trimSessionCheckpoints(checkpoints);

516+

const snapshotBytesByPath = await statCheckpointSnapshotBytes(checkpoints);

517+

trimmedCheckpoints = trimSessionCheckpoints(checkpoints, snapshotBytesByPath);

454518

store[target.canonicalKey] = {

455519

...existing,

456520

updatedAt: Math.max(existing.updatedAt ?? 0, createdAt),