openclaw - 💡(How to fix) Fix Treat auto-compaction as a first-class agent task (route through /compact) to eliminate mid-conversation transcript mutations [4 comments, 3 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#72364Fetched 2026-04-27 05:30:53
View on GitHub
Comments
4
Participants
3
Timeline
7
Reactions
0
Timeline (top)
commented ×4cross-referenced ×2closed ×1

Auto-compaction in 2026.4.24 fires invisibly inside the next-turn prompt-build path. When agents.defaults.compaction.truncateAfterCompaction: true is set, this produces visibly disruptive behavior in long-running channel sessions (especially WebChat-viewed Telegram/Slack DMs): messages render and then disappear mid-conversation as the JSONL is mutated under the live UI. Setting truncateAfterCompaction: false removes the disruption but leaves the bloat-management problem unsolved.

The proposed fix is small and reuses what's already shipped: route auto-compaction through the existing /compact chat-command machinery, triggered post-turn at the soft threshold instead of pre-flight inside prompt-build. No new protocol events, no new client logic.

Root Cause

PropertyAuto (current)/compact (slash command)
WhenPre-flight inside next prompt-buildWhen the user (or system) invokes
UI signalNone — invisibleExisting "agent processing" state
Transcript footprintSilent summary injectionStatus reply visible to user
Race with WebChat history pollYes — root cause of visible jarringNo — same lane as any other turn

Fix Action

Fix / Workaround

  1. Move the soft-threshold check from pre-flight (inside compactEmbeddedPiSession callers) to post-turn (after agent_end fires).
  2. When the threshold is crossed, dispatch /compact via the existing slash-command path with a system-authorized sender (just needs isAuthorizedSender: true on the synthesized command — the handler already supports the gate).
  3. The handler's existing reply ("session compacted, N entries summarized") becomes the visible signal that compaction happened. Users want this — it makes the operation legible.

Several deployments are running with truncateAfterCompaction: false solely to avoid the mid-conversation jarring, knowing they're trading it for unbounded JSONL growth. They patch around it with offline cron jobs that flip truncateAfterCompaction: true overnight, run /compact on oversized sessions, and flip the flag back. The fact that the workaround is literally to invoke /compact programmatically is direct evidence that this issue's proposed change is the right model — operators are already doing it manually because the auto path's UX is broken.

Medium-high. Doesn't break correctness, but the workarounds operators are deploying — disabling auto-compaction outright, scheduling overnight cron jobs to manually invoke /compact — strongly suggest the current design needs revisiting.

Code Example

[compaction] post-compaction truncation removed N entries (sessionKey=...)
RAW_BUFFERClick to expand / collapse

Summary

Auto-compaction in 2026.4.24 fires invisibly inside the next-turn prompt-build path. When agents.defaults.compaction.truncateAfterCompaction: true is set, this produces visibly disruptive behavior in long-running channel sessions (especially WebChat-viewed Telegram/Slack DMs): messages render and then disappear mid-conversation as the JSONL is mutated under the live UI. Setting truncateAfterCompaction: false removes the disruption but leaves the bloat-management problem unsolved.

The proposed fix is small and reuses what's already shipped: route auto-compaction through the existing /compact chat-command machinery, triggered post-turn at the soft threshold instead of pre-flight inside prompt-build. No new protocol events, no new client logic.

Where the current trigger lives

dist/compact-<hash>.js runs compactEmbeddedPiSession(...) synchronously inside the next-turn prompt-build whenever the running context would overflow. The truncation step then fires inside the same window if truncateAfterCompaction: true:

[compaction] post-compaction truncation removed N entries (sessionKey=...)

WebChat polls chat.history on a separate cadence (UI events, periodic refreshes). Mid-truncation polls return the post-truncation state, so messages already rendered into the visible DOM disappear on the next refresh tick. From the user's seat: their conversation is being mutated by an invisible system process while they read it.

Why /compact already has the right UX

/compact is a registered chat command (commands-registry.data-<hash>.js: textAlias: "/compact"). Its handler at commands-handlers.runtime-<hash>.js: handleCompactCommand calls into the same runtime.compactEmbeddedPiSession(...) runtime that auto-compaction uses. The differences are purely lifecycle:

PropertyAuto (current)/compact (slash command)
WhenPre-flight inside next prompt-buildWhen the user (or system) invokes
UI signalNone — invisibleExisting "agent processing" state
Transcript footprintSilent summary injectionStatus reply visible to user
Race with WebChat history pollYes — root cause of visible jarringNo — same lane as any other turn

The slash-command path inherits all the run-state machinery already wired for normal turns: typing indicator, history-poll suppression while busy, atomic refresh on transition to idle. The auto path bypasses all of it.

Suggested change

Relocate the auto-compaction trigger:

  1. Move the soft-threshold check from pre-flight (inside compactEmbeddedPiSession callers) to post-turn (after agent_end fires).
  2. When the threshold is crossed, dispatch /compact via the existing slash-command path with a system-authorized sender (just needs isAuthorizedSender: true on the synthesized command — the handler already supports the gate).
  3. The handler's existing reply ("session compacted, N entries summarized") becomes the visible signal that compaction happened. Users want this — it makes the operation legible.

That's the entire change. The compactEmbeddedPiSession runtime is unchanged. Truncation behavior is unchanged. The slash-command handler is unchanged. The only edits are to who calls /compact and when.

Why this is strictly better than the current pre-flight design

  • Visible to the user: an explicit "compacting…" busy state instead of a mysterious pause and disappearing messages.
  • Reuses existing UI plumbing: no new events, no client changes, no protocol bumps.
  • Atomic from the UI's perspective: WebChat already pauses history polling during agent processing — the truncation finishes before the next poll, so no mid-mutation read.
  • Recoverable in transcript: the /compact reply lands as a normal message — operators can see compaction history just by scrolling.
  • Same correctness guarantees: model context still managed; soft threshold still respected; just with one extra round-trip of latency on the turn that crosses the threshold (acceptable — the user already finished interacting with that turn).

Why operators are working around this today

Several deployments are running with truncateAfterCompaction: false solely to avoid the mid-conversation jarring, knowing they're trading it for unbounded JSONL growth. They patch around it with offline cron jobs that flip truncateAfterCompaction: true overnight, run /compact on oversized sessions, and flip the flag back. The fact that the workaround is literally to invoke /compact programmatically is direct evidence that this issue's proposed change is the right model — operators are already doing it manually because the auto path's UX is broken.

Adjacent issues already filed

  • #72340 — Slack DM native streaming gate (separate code path, separate fix)
  • #72341 — WebChat cumulative-card duplication on text-between-tools blocks (client-side, separate fix)

This issue (compaction-as-agent-task) is independent of both.

Severity

Medium-high. Doesn't break correctness, but the workarounds operators are deploying — disabling auto-compaction outright, scheduling overnight cron jobs to manually invoke /compact — strongly suggest the current design needs revisiting.

extent analysis

TL;DR

Relocate the auto-compaction trigger to post-turn, utilizing the existing /compact chat-command machinery to improve visibility and prevent mid-conversation message disappearance.

Guidance

  • Move the soft-threshold check from pre-flight to post-turn, after agent_end fires, to trigger auto-compaction.
  • Dispatch /compact via the existing slash-command path with a system-authorized sender when the threshold is crossed.
  • Leverage the existing /compact handler's reply as a visible signal that compaction has occurred, providing transparency to users.
  • Verify the fix by checking that messages no longer disappear mid-conversation and that the compaction process is visible to users.

Example

No code snippet is provided as the issue suggests reusing existing code paths, specifically the /compact chat-command machinery.

Notes

This solution assumes that the existing /compact handler and its associated machinery are functioning correctly. The proposed change focuses on improving the visibility and timing of auto-compaction, rather than altering its underlying logic.

Recommendation

Apply the workaround by relocating the auto-compaction trigger to post-turn, utilizing the existing /compact chat-command machinery. This approach provides a visible and atomic compaction process, addressing the mid-conversation disruption issue without introducing new protocol events or client logic.

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 Treat auto-compaction as a first-class agent task (route through /compact) to eliminate mid-conversation transcript mutations [4 comments, 3 participants]