openclaw - 💡(How to fix) Fix Compaction summary quality issues: snowballing, no cooldown, keepRecentTokens not working [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#71357Fetched 2026-04-26 05:13:34
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
cross-referenced ×2closed ×1commented ×1

Fix Action

Workaround

I've set customInstructions (via direct config file edit) to guide the compaction model, and truncateAfterCompaction: true to prevent file bloat. But most of these issues require source-level fixes.

RAW_BUFFERClick to expand / collapse

Compaction Summary Quality Issues (v2026.4.23)

Environment

  • Version: OpenClaw 2026.4.23 (a979721)
  • Model: opencode-go/glm-5.1 (primary), same for compaction
  • Context Window: 198k tokens
  • Compaction mode: safeguard
  • keepRecentTokens: 50000 (config)

Observed Issues

I've been running long sessions and noticed several compaction quality problems. After 7 compactions in one session, I extracted all compaction entries from the session JSONL and found the following issues:


1. keepRecentTokens still not preserving recent messages

Despite v2026.4.23 claiming to fix this, compaction results show tokensBefore: 154,139 → tokensAfter: 1,510 with firstKeptEntryId equal to the compaction entry's own ID, meaning 0 recent messages were retained.

Config has keepRecentTokens: 50000, and applyPiCompactionSettingsFromConfig() does pass this value, but findCutPoint() in Pi SDK produces no kept entries.

Expected: The most recent ~50k tokens of conversation should be preserved verbatim after compaction.


2. Repeated compactions within minutes producing identical summaries

Compaction #2 (17:41 UTC) and #3 (17:46 UTC) are nearly identical, only 5 minutes apart. Same for #5 and #6 (7 minutes apart). This suggests there's no cooldown period between compactions, and the compaction trigger doesn't account for the fact that a compaction just ran.

This wastes API credits and produces redundant summaries that bloat the context.

Expected: A cooldown period (e.g., 10 minutes) after compaction before another can trigger, or a check that the context isn't mostly the previous compaction summary.


3. Summary snowball / bloat

Each compaction preserves the full previous summary and appends new content. After 7 compactions, the summary contains:

  • All 7 previous Goal sections (mostly identical)
  • Accumulated Decisions list that grows each time
  • Progress items that are never pruned
  • Technical debug details that should have been condensed

The summary grows larger with each compaction cycle, eventually hitting the budget and getting truncated ([Compaction summary truncated to fit budget]).

Meanwhile, intimate/emotional conversation details are compressed to single-line summaries, while technical findings are preserved verbatim.

Expected: Each compaction should re-distill the previous summary rather than preserving it verbatim. Old/stale items should be pruned.


4. Malformed compaction output

Compaction #4 produced output starting with instructions in \`` instead of the expected ## Goal` heading. This appears to be a partial/corrupted summary that leaked prompt instructions into the output.

Expected: Compaction output should always start with valid markdown headings. A quality check could validate the format before accepting.


5. Summary truncation with no graceful degradation

When the summary exceeds the token budget, it's simply truncated with [Compaction summary truncated to fit budget], losing potentially critical information from the end (which often contains the most recent context).

Expected: When truncation is needed, older/slower sections should be pruned first, preserving recent context and the tail of the summary.


Suggested Improvements

  1. Fix keepRecentTokens: Ensure findCutPoint() correctly identifies a cut point that preserves keepRecentTokens worth of recent messages.
  2. Add compaction cooldown: Minimum 10-minute cooldown between compactions in the same session.
  3. Re-distill summaries: Each compaction should re-summarize the previous summary rather than embedding it verbatim. This prevents snowballing.
  4. Quality guard: Validate compaction output format (starts with ##, no leaked prompts) before accepting. Retry on malformed output.
  5. Graceful truncation: When budget exceeded, trim oldest sections first, preserving recent context.
  6. customInstructions support: Allow users to customize compaction summary behavior (already available in config schema but protected from API changes — consider allowing config.patch).

Reproduction

Long-running session with 198k context window, safeguard compaction mode. Trigger compaction manually or let it auto-trigger after extended conversation. Observe compaction entries in session JSONL.

Workaround

I've set customInstructions (via direct config file edit) to guide the compaction model, and truncateAfterCompaction: true to prevent file bloat. But most of these issues require source-level fixes.

extent analysis

TL;DR

Implement fixes for keepRecentTokens, add a compaction cooldown, re-distill summaries, introduce a quality guard, and enable graceful truncation to address compaction quality issues.

Guidance

  • Review the findCutPoint() function in the Pi SDK to ensure it correctly preserves keepRecentTokens worth of recent messages.
  • Introduce a minimum 10-minute cooldown between compactions in the same session to prevent redundant summaries.
  • Modify the compaction process to re-summarize the previous summary instead of embedding it verbatim to prevent summary snowballing.
  • Implement a quality check to validate compaction output format before accepting it, and retry on malformed output.
  • Update the truncation logic to trim oldest sections first, preserving recent context when the budget is exceeded.

Example

No code snippet is provided as the issue requires source-level fixes and modifications to the compaction process.

Notes

The provided suggestions are based on the observed issues and expected behavior described in the issue. Implementing these fixes may require modifications to the OpenClaw codebase and the Pi SDK.

Recommendation

Apply the suggested improvements, including fixing keepRecentTokens, adding a compaction cooldown, re-distilling summaries, introducing a quality guard, and enabling graceful truncation, as these address the root causes of the compaction quality issues.

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