Skip to content

[Bug]: Pre-compaction memory flush leaks into main session as user messages and causes compaction loop #54408

Description

@markgong

What happened

pre-compaction memory flush messages that should be silent were injected into the main user session as normal user messages.

After that, compaction started treating those internal flush prompts as conversation content, and the session entered a loop where nearly every new input triggered the same flush/compaction behavior.

Expected behavior

The pre-compaction memory flush should remain an internal/silent turn.
Users should not see the flush prompt in the chat UI or session transcript.
Compaction should continue normally after the flush.

Actual behavior

The following internal prompt appeared directly in the session/chat:

Pre-compaction memory flush. Store durable memories only in memory/YYYY-MM-DD.md ... If nothing to store, reply with NO_REPLY.

Then the session kept hitting compaction with logs like:

Compaction safeguard: no real conversation messages to summarize; writing compaction boundary to suppress re-trigger loop.

Repro notes

  1. Use OpenClaw TUI / main session
  2. Keep chatting until auto-compaction / pre-compaction memory flush triggers
  3. The flush prompt appears in the visible conversation
  4. Continue chatting in the same session
  5. Session gets stuck repeatedly surfacing the internal flush behavior

Environment

  • OpenClaw local gateway
  • TUI main session
  • agents.defaults.compaction.mode = "safeguard"
  • agents.defaults.compaction.memoryFlush.enabled = true

Evidence

The session transcript contains the flush prompt as role: user, repeated multiple times in the same session JSONL.

Gateway logs repeatedly show:

Compaction safeguard: no real conversation messages to summarize; writing compaction boundary to suppress re-trigger loop.

Why this seems like a bug

Docs describe memory flush as a silent turn that should generally resolve to NO_REPLY without being surfaced to the user. In this case, the internal prompt leaked into the visible/main session and then poisoned later compaction.

Temporary workaround

  • abandon the polluted session and start a new one
  • optionally disable agents.defaults.compaction.memoryFlush temporarily

Suggested fix

  • ensure pre-compaction memory flush messages are never persisted into the visible/main transcript as user messages
  • ensure silent/internal turns are excluded from compaction summarization input
  • guard against replay loops when a session already contains leaked internal flush prompts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions