mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:21:39 +00:00
fix(memoryFlush): guard transcript-size forced flush against repeated runs (#32358)
The `forceFlushTranscriptBytes` path (introduced in d729ab21) bypasses the
`memoryFlushCompactionCount` guard that prevents repeated flushes within the
same compaction cycle. Once the session transcript exceeds 2 MB, memory flush
fires on every single message — even when token count is well under the
compaction threshold.
Extract `hasAlreadyFlushedForCurrentCompaction()` from the inline guard in
`shouldRunMemoryFlush` and apply it to both the token-based and the
transcript-size trigger paths.
Fixes #32317
Signed-off-by: HCL <chenglunhu@gmail.com>
This commit is contained in:
@@ -161,11 +161,22 @@ export function shouldRunMemoryFlush(params: {
|
||||
return false;
|
||||
}
|
||||
|
||||
const compactionCount = params.entry.compactionCount ?? 0;
|
||||
const lastFlushAt = params.entry.memoryFlushCompactionCount;
|
||||
if (typeof lastFlushAt === "number" && lastFlushAt === compactionCount) {
|
||||
if (hasAlreadyFlushedForCurrentCompaction(params.entry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when a memory flush has already been performed for the current
|
||||
* compaction cycle. This prevents repeated flush runs within the same cycle —
|
||||
* important for both the token-based and transcript-size–based trigger paths.
|
||||
*/
|
||||
export function hasAlreadyFlushedForCurrentCompaction(
|
||||
entry: Pick<SessionEntry, "compactionCount" | "memoryFlushCompactionCount">,
|
||||
): boolean {
|
||||
const compactionCount = entry.compactionCount ?? 0;
|
||||
const lastFlushAt = entry.memoryFlushCompactionCount;
|
||||
return typeof lastFlushAt === "number" && lastFlushAt === compactionCount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user