openclaw - 💡(How to fix) Fix Plugin context engines cannot increment /status compaction count [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#49380Fetched 2026-04-08 00:55:45
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Participants
Timeline (top)
commented ×1

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
RAW_BUFFERClick to expand / collapse

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)

extent analysis

Fix Plan

To fix the issue, we will implement Option A (callback): pass notifyCompaction(count?: number) in afterTurn params. This allows the plugin to notify OpenClaw of successful leaf compactions.

Steps:

  • Update the ContextEngine interface to include notifyCompaction in the afterTurn params:
interface ContextEngine {
  // ...
  afterTurn(params: { notifyCompaction: (count?: number) => void }): Promise<void>;
}
  • In the plugin context engine (e.g., mem-engine, lossless-claw), call notifyCompaction after each successful leaf compaction:
class MyContextEngine implements ContextEngine {
  // ...
  async afterTurn({ notifyCompaction }: { notifyCompaction: (count?: number) => void }) {
    // ...
    if (compactionSuccessful) {
      notifyCompaction(1); // or the actual compaction count
    }
  }
}
  • In OpenClaw, update the afterTurn handler to increment the compactionCount when notifyCompaction is called:
class OpenClaw {
  // ...
  async afterTurnHandler(contextEngine: ContextEngine, params: any) {
    // ...
    const notifyCompaction = (count?: number) => {
      if (count !== undefined) {
        this.incrementCompactionCount(count);
      }
    };
    await contextEngine.afterTurn({ notifyCompaction, ...params });
  }
}

Verification

To verify the fix, check the compactionCount displayed by /status after running the plugin context engine with the updated afterTurn implementation. The count should now be incremented correctly after successful leaf compactions.

Extra Tips

  • Make sure to update all affected ContextEngine plugins to use the new notifyCompaction callback.
  • Consider adding logging or monitoring to track the number of successful leaf compactions and verify that the compactionCount is being incremented correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Plugin context engines cannot increment /status compaction count [1 comments, 2 participants]