Skip to content

Plugin context engines cannot increment /status compaction count #49380

Description

@petersykim

Problem

/status shows 🧹 Compactions: 0 for agents using plugin context engines (e.g. mem-engine, lossless-claw), even after hundreds of successful compactions.

Root Cause

The compactionCount displayed by /status can only be incremented through two paths:

  1. Mid-stream auto-compaction — when the built-in compaction fires during an agent run, autoCompactionCount increments and flows into agentMeta.compactionCount, which updateSessionStoreAfterAgentRun reads. Plugin context engines that own compaction (ownsCompaction: true) bypass this path entirely because their assemble() keeps context within budget, preventing overflow.

  2. /compact slash command or overflow recovery — calls contextEngine.compact(), and if it returns { ok: true, compacted: true }, incrementCompactionCount() fires on the session store. This works, but /new resets compactionCount to 0, and overflow rarely triggers because assemble() handles it proactively.

Neither path captures leaf compactions — the primary compaction mechanism for plugin context engines. These run in afterTurn() (background, fire-and-forget), and the ContextEngine.afterTurn() interface:

  • Returns Promise<void> — return value is ignored by OpenClaw
  • Receives no callback to signal compaction activity
  • Has no access to the session store

Evidence

  • compaction_events table: 1,948 incremental leaf drains, 146 successful compactions
  • Session store: compactionCount: 0 for all plugin-engine sessions
  • main agent (legacy engine): compactionCount: 38 — works because it uses mid-stream auto-compaction

Suggested Fix

Add a compaction notification channel to the afterTurn contract. Options:

Option A (callback): Pass notifyCompaction(count?: number) in afterTurn params. Plugin calls it after each successful leaf/proactive compaction.

Option B (return value): Change afterTurn return type to Promise<void | { compactionCount?: number }>. OpenClaw reads and increments.

Option C (direct read): /status queries the context engine's own compaction tracking (e.g. via a new getStats() method on the ContextEngine interface).

Option A is probably cleanest — minimal contract change, plugin controls granularity.

Affected

  • Any ContextEngine plugin with ownsCompaction: true
  • Known: mem-engine, lossless-claw
  • OpenClaw version: 2026.3.13 (61d171a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions