#overcompaction

1 messages · Page 1 of 1 (latest)

dull token
#

Compacted (233k → 4.0k) • Context 4.0k/395k (1%) my current openclaw is over compating, tell me the best confiugration for compaction

ionic geyserBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

barren ermineBOT
#

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 to 80000, 120000, or even 160000 if you want less aggressive compaction.
  • maxHistoryShare: raise toward 0.9 to preserve more history.
  • Avoid a low maxActiveTranscriptBytes; that can make compaction happen for file-size reasons.

Also please paste:

dull token
#

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

barren ermineBOT
#

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: 0 is fine because you explicitly set reserveTokens: 50000. The floor only matters when OpenClaw would otherwise bump a too-low reserve.
  • I’d not disable memoryFlush unless 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 keepRecentTokens to 120000.

And yeah, please still check openclaw --version — compaction behavior is version-sensitive.

dull token
#

what is this recentTurnsPreserve

#

what does memory flush do

barren ermineBOT
#

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".
#

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:

dull token
#

so memoryflush creates a file on system?

barren ermineBOT
#

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

dull token
#

but if i dont enable it compaction still happens memory flush is for later right for a new session?

barren ermineBOT
#

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".