openclaw - 💡(How to fix) Fix feat(hooks): include compaction summary text in after_compaction hook payload [1 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#61447Fetched 2026-04-08 02:58:31
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Root Cause

Compaction is a lossy operation. Plugins need visibility into what the summary actually contains to:

  • Verify critical context (open assignments, infrastructure state) was preserved
  • Write supplemental memory to daily notes before the session window slides
  • Alert when important facts are dropped

Without this, the after_compaction hook is limited to recording that compaction occurred, not whether it was faithful.

Code Example

export type PluginHookAfterCompactionEvent = {
  sessionKey: string;
  agentId?: string;
  messagesRetained: number;
  messagesDropped: number;
  /** The compaction summary text that was generated, if available */
  summaryText?: string;
  /** Tokens in the summary */
  summaryTokens?: number;
};
RAW_BUFFERClick to expand / collapse

Problem

The after_compaction hook event currently provides basic metadata (session key, message counts) but does not include the actual compaction summary text that was generated.

Plugins that want to audit compaction quality, score signal preservation, or extract key facts from the summary have no way to access this data. The summary is injected inline into the next user message as <summary>...\</summary> context, but is not persisted as a separate tagged message in the session JSONL or passed through the hook.

Use Case

A compact-review plugin that:

  1. Scores signal preservation (did the summary retain infrastructure facts, active assignments, recent decisions?)
  2. Writes a recovery checkpoint to daily notes before context is lost
  3. Alerts when critical facts appear to be dropped

Currently requires parsing the inline <summary> tags from subsequent user messages in the JSONL — fragile and unreliable.

Proposed Change

Extend PluginHookAfterCompactionEvent to include the summary text:

export type PluginHookAfterCompactionEvent = {
  sessionKey: string;
  agentId?: string;
  messagesRetained: number;
  messagesDropped: number;
  /** The compaction summary text that was generated, if available */
  summaryText?: string;
  /** Tokens in the summary */
  summaryTokens?: number;
};

This is a non-breaking addition (optional field). Plugins that don't need it are unaffected.

Why This Matters

Compaction is a lossy operation. Plugins need visibility into what the summary actually contains to:

  • Verify critical context (open assignments, infrastructure state) was preserved
  • Write supplemental memory to daily notes before the session window slides
  • Alert when important facts are dropped

Without this, the after_compaction hook is limited to recording that compaction occurred, not whether it was faithful.

Notes

  • The summary text is already being generated and injected into context — this is just about surfacing it to plugins
  • Could also expose pre-compaction message content for more sophisticated scoring

extent analysis

TL;DR

Extend the PluginHookAfterCompactionEvent type to include the summaryText field to provide plugins with access to the compaction summary.

Guidance

  • Update the PluginHookAfterCompactionEvent type to include the optional summaryText and summaryTokens fields.
  • Verify that the summaryText field is being populated correctly by checking the event data in the after_compaction hook.
  • Test plugins that rely on the after_compaction hook to ensure they can handle the new fields and do not break if the fields are missing.
  • Consider exposing pre-compaction message content for more sophisticated scoring in the future.

Example

export type PluginHookAfterCompactionEvent = {
  sessionKey: string;
  agentId?: string;
  messagesRetained: number;
  messagesDropped: number;
  summaryText?: string;
  summaryTokens?: number;
};

Notes

The proposed change is non-breaking, so plugins that do not need the new fields will be unaffected. However, plugins that do use the new fields should be updated to handle cases where the fields may be missing.

Recommendation

Apply the proposed change to extend the PluginHookAfterCompactionEvent type, as it provides a straightforward solution to the problem and does not introduce any breaking changes.

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