Skip to content

Commit f2c813c

Browse files
committed
refactor(memory): simplify memory flush counter
1 parent 731814c commit f2c813c

3 files changed

Lines changed: 10 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +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.
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. Refs #12760, #26145, and #46513. Thanks @Kaspre, @lailoo, @drvoss, @Br1an67, and @dial481.
235235
- Compute plugin callback authorization dynamically [AI]. (#78866) Thanks @pgondhi987.
236236
- fix(active-memory): require admin scope for global toggles [AI]. (#78863) Thanks @pgondhi987.
237237
- Honor owner enforcement for native commands [AI]. (#78864) Thanks @pgondhi987.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ export async function runMemoryFlushIfNeeded(params: {
968968
return result;
969969
},
970970
});
971-
const memoryFlushCompactionCount =
971+
const flushedCompactionCount =
972972
activeSessionEntry?.compactionCount ??
973973
(params.sessionKey ? activeSessionStore?.[params.sessionKey]?.compactionCount : 0) ??
974974
0;
@@ -1001,7 +1001,6 @@ export async function runMemoryFlushIfNeeded(params: {
10011001
});
10021002
}
10031003
}
1004-
// Persist the pre-increment count so the next compaction cycle remains eligible to flush.
10051004
}
10061005
if (params.storePath && params.sessionKey) {
10071006
try {
@@ -1010,7 +1009,7 @@ export async function runMemoryFlushIfNeeded(params: {
10101009
sessionKey: params.sessionKey,
10111010
update: async () => ({
10121011
memoryFlushAt: memoryDeps.now(),
1013-
memoryFlushCompactionCount,
1012+
memoryFlushCompactionCount: flushedCompactionCount,
10141013
}),
10151014
});
10161015
if (updatedEntry) {

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,13 @@ describe("shouldRunMemoryFlush", () => {
300300
softThresholdTokens: 2_000,
301301
};
302302

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);
303+
for (const entry of [
304+
{ totalTokens: 95_000, compactionCount: 1 },
305+
{ totalTokens: 95_000, compactionCount: 2, memoryFlushCompactionCount: 1 },
306+
{ totalTokens: 95_000, compactionCount: 3, memoryFlushCompactionCount: 2 },
307+
]) {
308+
expect(shouldRunMemoryFlush({ entry, ...params })).toBe(true);
309+
}
320310
});
321311

322312
it("ignores stale cached totals", () => {

0 commit comments

Comments
 (0)