Skip to content

Compaction abort triggers duplicate memory flushes #30115

@codyz123

Description

@codyz123

Bug

When a compaction wait is aborted (e.g. due to context limit pressure), the memory flush fires before compaction completes. The same pre-compaction context then re-triggers another flush on the next cycle, writing identical content to the memory file.

Impact

Over time, MEMORY.md accumulates duplicate entries (we've seen 4-7x duplicates of the same block). This wastes context window space and causes the edit tool to fail (can't find unique text matches when identical blocks exist).

Reproduction

  1. Run a long session that approaches context limits
  2. Compaction triggers but aborts (compaction wait aborted in logs)
  3. Memory flush fires with the pre-compaction context
  4. On next compaction cycle, the same context triggers another identical flush
  5. MEMORY.md now has duplicate entries

Current Workaround

We patched shouldRunMemoryFlush() in the dist JS to add a filesystem sentinel with a 5-minute cooldown (/tmp/openclaw-flush-sentinel). This reduces but doesn't eliminate duplicates, and gets overwritten on every update.

Suggested Fix

Either:

  • Track what context was last flushed (hash or compaction count) and skip if unchanged
  • Don't trigger memory flush on compaction abort — only on successful compaction
  • Add a built-in cooldown/dedup mechanism to the flush pipeline

Environment

  • OpenClaw 2026.2.26
  • Model: claude-opus-4-6
  • Running with reserveTokensFloor: 5000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions