#overcompaction
1 messages · Page 1 of 1 (latest)
Try this as a starting point in ~/.openclaw/openclaw.json:
{
agents: {
defaults: {
compaction: {
mode: "safeguard",
// keep more recent chat verbatim after compaction
keepRecentTokens: 80000,
// don’t compact too early on large-context models
reserveTokens: 32000,
reserveTokensFloor: 32000,
// allow more history to survive safeguard pruning
maxHistoryShare: 0.85,
recentTurnsPreserve: 8,
// good defaults for continuity
identifierPolicy: "strict",
memoryFlush: {
enabled: true,
softThresholdTokens: 8000,
},
// optional: prevents huge active JSONL files, but don’t set maxActiveTranscriptBytes too low
truncateAfterCompaction: true,
maxActiveTranscriptBytes: "100mb",
notifyUser: true,
},
},
},
}
Then restart the gateway.
For your case — 233k → 4k on a 395k context window — I’d especially tune:
keepRecentTokens: raise to80000,120000, or even160000if you want less aggressive compaction.maxHistoryShare: raise toward0.9to preserve more history.- Avoid a low
maxActiveTranscriptBytes; that can make compaction happen for file-size reasons.
Also please paste:
openclaw --version
openclaw status
Compaction behavior has moved around recently, so version matters. Docs: https://docs.openclaw.ai/concepts/compaction and https://docs.openclaw.ai/reference/session-management-compaction
what about this?
keepRecentTokens: 80000,
reserveTokens: 50000,
reserveTokensFloor: 0,
maxHistoryShare: 0.85,
recentTurnsPreserve: 8,
identifierPolicy: "strict",
memoryFlush: { enabled: false, softThresholdTokens: 4000 },
truncateAfterCompaction: true,
maxActiveTranscriptBytes: "100mb",
notifyUser: true
That config is mostly sane 👍 I’d tweak two things:
compaction: {
mode: "safeguard",
keepRecentTokens: 80000,
reserveTokens: 50000,
reserveTokensFloor: 0,
maxHistoryShare: 0.85,
recentTurnsPreserve: 8,
identifierPolicy: "strict",
memoryFlush: { enabled: true, softThresholdTokens: 8000 },
truncateAfterCompaction: true,
maxActiveTranscriptBytes: "100mb",
notifyUser: true
}
Notes:
reserveTokensFloor: 0is fine because you explicitly setreserveTokens: 50000. The floor only matters when OpenClaw would otherwise bump a too-low reserve.- I’d not disable
memoryFlushunless you’re intentionally avoiding file writes. It doesn’t fix over-compaction; it helps preserve important state before compaction. maxActiveTranscriptBytes: "100mb"is reasonable. Don’t set it low, or you’ll trigger compaction based on transcript size instead of token pressure.- If it still compacts too hard, next step is raising
keepRecentTokensto120000.
And yeah, please still check openclaw --version — compaction behavior is version-sensitive.
recentTurnsPreserve is a safeguard-mode compaction knob.
It means: when OpenClaw compacts, it takes the last N recent user/assistant turns and appends them into the compaction summary more directly, instead of relying only on the summarizer to remember them.
So:
recentTurnsPreserve: 8
≈ “Protect the last ~8 user turns, plus their assistant replies, from getting blurred away during compaction.”
Important distinction:
keepRecentTokens: 80000= keep a recent token tail around after compaction.recentTurnsPreserve: 8= make the compaction summary explicitly retain the last 8 conversational turns.- It only really matters with
mode: "safeguard".
Default is 3; max is 12. For your over-compaction case, 8 is reasonable. If summaries are still losing immediate context, try 10–12; otherwise 6–8 is a good balance.
memoryFlush is a pre-compaction safety pass.
Before OpenClaw heavily compacts a long session, it can run a silent internal turn that says basically:
“Save anything important/durable to memory files now, then reply
NO_REPLY.”
So important context can survive even if the chat transcript gets summarized aggressively.
Key points:
- It does not reduce over-compaction directly.
- It helps prevent losing important facts/decisions during compaction.
- It may add a little latency/token use before compaction.
- It can write to the agent workspace/memory files, so disable it only if you don’t want that.
This:
memoryFlush: { enabled: false, softThresholdTokens: 4000 }
means memory flush is off, so softThresholdTokens won’t matter.
For your case I’d use:
memoryFlush: {
enabled: true,
softThresholdTokens: 8000
}
Docs: https://docs.openclaw.ai/reference/session-management-compaction
so memoryflush creates a file on system?
Yes — if enabled, memoryFlush can create or update memory files in the agent’s workspace, not random system files.
Usually that means files like:
<agent workspace>/MEMORY.md
<agent workspace>/memory/*.md
or date/topic-style memory notes depending on how the agent is instructed.
It runs a silent “save important durable context now” turn before compaction. If the workspace is read-only / no-write, it should skip instead of writing.
So:
memoryFlush: { enabled: true }
= “before compaction, let the agent persist important notes to disk.”
memoryFlush: { enabled: false }
= no pre-compaction memory file writes.
If you’re privacy/disk-write sensitive, disabling it is fine. If you care about long-session continuity, I’d keep it on.
Docs: https://docs.openclaw.ai/reference/session-management-compaction
but if i dont enable it compaction still happens memory flush is for later right for a new session?
Yep — compaction still happens without memoryFlush.
Think of them separately:
- Compaction = summarizes the current session so it fits in the model context.
- memoryFlush = optional safety step before compaction that writes durable notes to memory files.
So if you disable it:
memoryFlush: { enabled: false }
OpenClaw will still compact, but it won’t do that extra “save important stuff to memory first” pass.
And yes, memory files can help later turns / future sessions, depending on your agent’s memory setup. But memoryFlush is not required for compaction itself, and it won’t fix the 233k → 4k over-compaction. For that, the important knobs are keepRecentTokens, maxHistoryShare, and mode: "safeguard".