Skip to content

Commit 731814c

Browse files
vincentkocobviyus
authored andcommitted
fix(memory): preserve memory flush compaction count
1 parent 2340e2a commit 731814c

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Docs: https://docs.openclaw.ai
231231
- Docs/Docker: document a local Compose override for Docker Desktop DNS failures in the shared-network `openclaw-cli` sidecar, keeping the default compose setup hardened while unblocking `openclaw plugins install` when users opt in. Fixes #79018. Thanks @Jason-Vaughan.
232232
- Installer: when npm installs `openclaw` outside the parent shell PATH, print follow-up commands with the resolved binary path instead of telling users to run `openclaw` from a shell that will report `command not found`. Fixes #72382. Thanks @jbob762.
233233
- Plugins/runtime: share MIME and JSON Schema helpers across bundled plugins while preserving canonical media MIME inference, browser URL wildcard semantics, migration home-path resolution, QA request-limit responses, and extensionless text file previews.
234+
- Agents/memory flush: persist the pre-increment compaction counter after flush-triggered compaction so consecutive eligible compaction cycles run memoryFlush instead of alternating. Fixes #12590; carries forward #51421 and refs #12760, #26145, and #46513. Thanks @Kaspre, @lailoo, @drvoss, @Br1an67, and @dial481.
234235
- Compute plugin callback authorization dynamically [AI]. (#78866) Thanks @pgondhi987.
235236
- fix(active-memory): require admin scope for global toggles [AI]. (#78863) Thanks @pgondhi987.
236237
- Honor owner enforcement for native commands [AI]. (#78864) Thanks @pgondhi987.

‎src/auto-reply/reply/agent-runner-memory.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe("runMemoryFlushIfNeeded", () => {
180180
};
181181
expect(persisted.main.sessionId).toBe("session-rotated");
182182
expect(persisted.main.compactionCount).toBe(2);
183-
expect(persisted.main.memoryFlushCompactionCount).toBe(2);
183+
expect(persisted.main.memoryFlushCompactionCount).toBe(1);
184184
expect(persisted.main.memoryFlushAt).toBe(1_700_000_000_000);
185185
});
186186

‎src/auto-reply/reply/agent-runner-memory.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,13 +968,13 @@ export async function runMemoryFlushIfNeeded(params: {
968968
return result;
969969
},
970970
});
971-
let memoryFlushCompactionCount =
971+
const memoryFlushCompactionCount =
972972
activeSessionEntry?.compactionCount ??
973973
(params.sessionKey ? activeSessionStore?.[params.sessionKey]?.compactionCount : 0) ??
974974
0;
975975
if (memoryCompactionCompleted) {
976976
const previousSessionId = activeSessionEntry?.sessionId ?? params.followupRun.run.sessionId;
977-
const nextCount = await memoryDeps.incrementCompactionCount({
977+
await memoryDeps.incrementCompactionCount({
978978
cfg: params.cfg,
979979
sessionEntry: activeSessionEntry,
980980
sessionStore: activeSessionStore,
@@ -1001,9 +1001,7 @@ export async function runMemoryFlushIfNeeded(params: {
10011001
});
10021002
}
10031003
}
1004-
if (typeof nextCount === "number") {
1005-
memoryFlushCompactionCount = nextCount;
1006-
}
1004+
// Persist the pre-increment count so the next compaction cycle remains eligible to flush.
10071005
}
10081006
if (params.storePath && params.sessionKey) {
10091007
try {

‎src/auto-reply/reply/reply-state.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,32 @@ describe("shouldRunMemoryFlush", () => {
293293
).toBe(true);
294294
});
295295

296+
it("runs on consecutive compaction cycles when flush records the pre-increment count", () => {
297+
const params = {
298+
contextWindowTokens: 100_000,
299+
reserveTokensFloor: 5_000,
300+
softThresholdTokens: 2_000,
301+
};
302+
303+
expect(
304+
shouldRunMemoryFlush({ entry: { totalTokens: 95_000, compactionCount: 1 }, ...params }),
305+
).toBe(true);
306+
307+
expect(
308+
shouldRunMemoryFlush({
309+
entry: { totalTokens: 95_000, compactionCount: 2, memoryFlushCompactionCount: 1 },
310+
...params,
311+
}),
312+
).toBe(true);
313+
314+
expect(
315+
shouldRunMemoryFlush({
316+
entry: { totalTokens: 95_000, compactionCount: 3, memoryFlushCompactionCount: 2 },
317+
...params,
318+
}),
319+
).toBe(true);
320+
});
321+
296322
it("ignores stale cached totals", () => {
297323
expect(
298324
shouldRunMemoryFlush({

0 commit comments

Comments
 (0)