openclaw - ✅(Solved) Fix [Bug] Compaction triggers every ~5 minutes instead of ~30min — compaction loop in OpenClaw 5.5/5.6 (unfixed in hotfix) [1 pull requests, 5 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#78604Fetched 2026-05-07 03:34:46
View on GitHub
Comments
5
Participants
3
Timeline
9
Reactions
3
Author
Timeline (top)
commented ×5cross-referenced ×2mentioned ×1subscribed ×1

Root Cause

Log analysis reveals:

  1. Compaction loop confirmed: 4 compactions in 22 minutes (03:11–03:33 UTC+8)
  2. Smart-extract failures: The MiniMax-M2.7-highspeed model request times out during extract-candidates phase, triggering regex fallback
  3. memory-lancedb-pro self-awareness: The plugin itself detects and logs this as a bug:
    memory-pro: smart-extractor: skipped [cases] OpenClaw 5.5/5.6 compaction bug
  4. preflightCompaction check verbose logs not visible: The detailed compaction trigger reason (token count, byte size, etc.) is logged at logVerbose level, which does not write to the log file, making root cause diagnosis from logs alone impossible
  5. The totalTokens counter may not be resetting properly: The compaction trigger logic in agent-runner.runtime-*.js depends on totalTokensFresh === false || !hasPersistedTotalTokens to skip compaction. If these flags are not being reset after compaction, every subsequent check would fail the condition and trigger compaction again immediately

Fix Action

Fix / Workaround

Bug: Compaction triggers every ~5 minutes instead of ~30 minutes (OpenClaw 5.5/5.6, still unfixed in hotfix)

After upgrading from OpenClaw 5.4 to 5.5 (and persisting after upgrading to 5.6 hotfix), compaction triggers approximately every 5 minutes instead of the expected ~30 minutes. The compaction frequency has not improved after the 5.6 hotfix release.

  • Memory Core (built-in): Disabled — only memory-lancedb-pro is active
  • Session transcript file size: ~666KB at time of analysis (far below 10MB threshold), confirming the trigger is not maxActiveTranscriptBytes
  • The trigger appears to be token-count based: Since transcript bytes are nowhere near 10MB, the trigger is likely the contextWindow - 20000 - 4000 token threshold, possibly not being reset after compaction
  • Session: agent:main:main — main session only, no sub-agents
  • Affected versions: Both 5.5 and 5.6 (hotfix did not fix this issue)

PR fix notes

PR #78619: fix(compaction): ignore transcript metadata bytes for token pressure

Description (problem / solution / changelog)

Summary

  • Problem: stale preflight compaction checks could count whole transcript JSONL byte size as token pressure, including session headers, custom records, and plugin metadata that are not active model context.
  • Why it matters: metadata-heavy sessions could compact every few minutes even when the active context was small and the transcript file was below maxActiveTranscriptBytes, disrupting conversations and wasting model calls.
  • What changed: stale token estimation now prefers latest usage, active-message estimates, and only bytes appended after the latest usage entry; it no longer treats whole raw transcript size as token pressure.
  • What did NOT change (scope boundary): explicit maxActiveTranscriptBytes byte-guard behavior, compaction execution, transcript rotation, memory plugin behavior, provider/model settings, and channel routing are unchanged.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #78604
  • Related #
  • This PR fixes a bug or regression

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: metadata-heavy transcripts should not trigger token-based preflight compaction when active model context is below the threshold and the file is below maxActiveTranscriptBytes.
  • Real environment tested: local OpenClaw checkout on Linux using the production runPreflightCompactionIfNeeded path against a temp OpenClaw session store and transcript.
  • Exact steps or command run after this patch: ran a temp-session OpenClaw preflight script with pnpm exec tsx, using truncateAfterCompaction: true, maxActiveTranscriptBytes: "10mb", stale totalTokensFresh: false, a 450KB custom transcript payload, and MiniMax model/session metadata.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):
openclaw_preflight_compaction_real_setup=ok
session_file_bytes=450198
max_active_transcript_bytes=10485760
token_state_fresh=false
returned_same_entry=true
preflight_compaction_phase_seen=false
compaction_count=0
  • Observed result after fix: OpenClaw returned the same active session entry, did not enter the preflight_compacting phase, and did not increment compaction count.
  • What was not tested: live MiniMax + Feishu WebSocket + memory-lancedb-pro deployment.
  • Before evidence (optional but encouraged): issue #78604 reports OpenClaw 2026.5.6 compacting five times between 03:11:18 and 03:33:28 UTC+8 while the transcript was about 666KB, below a 10MB byte guard.

Root Cause (if applicable)

  • Root cause: the stale preflight token fallback mixed two different signals: model-context token pressure and raw JSONL transcript file size. Whole-file byteSize / 4 could overestimate token pressure because JSONL contains non-context records such as session headers, custom entries, and plugin metadata.
  • Missing detection / guardrail: no regression covered stale token state with a metadata-heavy transcript whose active model context remained small.
  • Contributing context (if known): maxActiveTranscriptBytes is the explicit transcript-size guard. The token path should not implicitly recreate that byte guard by using whole-file bytes as context tokens.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/auto-reply/reply/agent-runner-memory.test.ts
  • Scenario the test should lock in: stale totalTokensFresh: false, 450KB custom metadata payload, small assistant usage, transcript rotation enabled, and maxActiveTranscriptBytes: "10mb" should not trigger preflight compaction.
  • Why this is the smallest reliable guardrail: the bug is in preflight token estimation, so the focused runner-memory test proves the decision without requiring a live provider/channel/plugin setup.
  • Existing test that already covers this (if any): existing tests covered stale usage and content appended after latest usage, but not non-context metadata bytes.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Metadata-heavy sessions should no longer compact every few minutes when active model context is not actually near the token threshold.

Diagram (if applicable)

Before:
stale token state -> whole transcript bytes / 4 -> false token pressure -> repeated compaction

After:
stale token state -> latest usage + active messages + trailing post-usage bytes -> real token pressure decision

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: local Node/pnpm checkout
  • Model/provider: MiniMax metadata in local temp-session proof; no live model call required
  • Integration/channel (if any): preflight compaction/session memory path
  • Relevant config (redacted): truncateAfterCompaction: true, maxActiveTranscriptBytes: "10mb"

Steps

  1. Create a temp OpenClaw session transcript with a large custom metadata record and small assistant usage.
  2. Mark the session entry token state stale with totalTokensFresh: false.
  3. Run the production preflight compaction path with transcript rotation and 10MB byte guard enabled.

Expected

  • Preflight token compaction does not run because active model context is below threshold and the transcript is below the explicit byte guard.

Actual

  • Before this patch, whole raw transcript bytes could contribute to token pressure and trigger compaction.
  • After this patch, copied live output shows preflight_compaction_phase_seen=false and compaction_count=0.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Supplemental checks run:

  • pnpm test src/auto-reply/reply/agent-runner-memory.test.ts
  • pnpm exec oxfmt --check --threads=1 src/auto-reply/reply/agent-runner-memory.ts src/auto-reply/reply/agent-runner-memory.test.ts CHANGELOG.md
  • pnpm changed:lanes --json
  • pnpm check:changed
  • git diff --check

Human Verification (required)

  • Verified scenarios: local production-path preflight run against a temp OpenClaw session store/transcript, focused metadata-heavy stale-token regression, existing conservative post-usage content behavior, formatting, changed-lane type/lint/guards.
  • Edge cases checked: bytes appended after latest usage still count conservatively through trailing-byte accounting.
  • What you did not verify: live MiniMax/Feishu/memory-lancedb-pro deployment.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: underestimating token pressure when usage is stale and transcript content after the latest usage is large.
    • Mitigation: the estimator still includes active-message token estimates and trailing bytes after the latest usage entry.

## Changed files

- `CHANGELOG.md` (modified, +1/-0)
- `src/auto-reply/reply/agent-runner-memory.test.ts` (modified, +128/-0)
- `src/auto-reply/reply/agent-runner-memory.ts` (modified, +50/-27)

Code Example

{
  "truncateAfterCompaction": true,
  "maxActiveTranscriptBytes": "10mb"
}

---

{
  "mode": "cache-ttl",
  "ttl": "1h",
  "keepLastAssistants": 10,
  "softTrimRatio": 0.5,
  "hardClearRatio": 0.7,
  "softTrim": { "maxChars": 10000, "headChars": 3000, "tailChars": 3000 },
  "hardClear": { "enabled": true, "placeholder": "..." }
}

---

[compaction] rotated active transcript after compaction (sessionKey=agent:main:main)

---

memory-pro: smart-extractor: skipped [cases] OpenClaw 5.5/5.6 compaction bug
RAW_BUFFERClick to expand / collapse

Bug: Compaction triggers every ~5 minutes instead of ~30 minutes (OpenClaw 5.5/5.6, still unfixed in hotfix)

Environment

  • OS: Ubuntu 24.04.3 LTS (Noble Numbat) x86_64
  • Kernel: Linux 6.8.0-111-generic
  • Node.js: v22.22.2
  • OpenClaw: 2026.5.6 (c97b9f7)
  • Installation: npm global (/usr/lib/node_modules/openclaw)
  • Plugin: [email protected] (enabled)
  • Built-in memory-core: disabled
  • Model: minimax/MiniMax-M2.7-highspeed (primary), minimax/MiniMax-VL-01 (image)
  • Embedding: SiliconFlow thenlper/gte-large-zh (dimension=1024)
  • Reranker: SiliconFlow BAAI/bge-reranker-v2-m3
  • Channel: Feishu (WebSocket mode)
  • Deployment: PVE VM (LAN IP 192.168.31.21)
  • Launcher: systemd user service

Compaction Config

{
  "truncateAfterCompaction": true,
  "maxActiveTranscriptBytes": "10mb"
}

Context Pruning Config

{
  "mode": "cache-ttl",
  "ttl": "1h",
  "keepLastAssistants": 10,
  "softTrimRatio": 0.5,
  "hardClearRatio": 0.7,
  "softTrim": { "maxChars": 10000, "headChars": 3000, "tailChars": 3000 },
  "hardClear": { "enabled": true, "placeholder": "..." }
}

Bug Description

After upgrading from OpenClaw 5.4 to 5.5 (and persisting after upgrading to 5.6 hotfix), compaction triggers approximately every 5 minutes instead of the expected ~30 minutes. The compaction frequency has not improved after the 5.6 hotfix release.

Observed compaction timeline (from live logs):

Timestamp (UTC+8)Interval from previous
03:11:18
03:16:245 min 6 sec
03:23:036 min 39 sec
03:27:384 min 34 sec
03:33:285 min 50 sec

The compaction events are clearly logged:

[compaction] rotated active transcript after compaction (sessionKey=agent:main:main)

In contrast, with OpenClaw 5.4 on the same system, compaction triggered only once every few hours under normal conversation load.


Impact

  1. Severe UX degradation: Every compaction causes a visible interruption in the conversation, breaking continuity
  2. Smart-extract failures: MiniMax-M2.7-highspeed model request times out during extract-candidates phase, causing zero memories to be persisted via smart capture
  3. Regex fallback produces almost no memories: Only 1 message per cycle is captured, resulting in nearly no memory persistence
  4. Resource waste: Frequent compaction + failed smart-extract attempts waste API calls and CPU cycles

Analysis

Log analysis reveals:

  1. Compaction loop confirmed: 4 compactions in 22 minutes (03:11–03:33 UTC+8)
  2. Smart-extract failures: The MiniMax-M2.7-highspeed model request times out during extract-candidates phase, triggering regex fallback
  3. memory-lancedb-pro self-awareness: The plugin itself detects and logs this as a bug:
    memory-pro: smart-extractor: skipped [cases] OpenClaw 5.5/5.6 compaction bug
  4. preflightCompaction check verbose logs not visible: The detailed compaction trigger reason (token count, byte size, etc.) is logged at logVerbose level, which does not write to the log file, making root cause diagnosis from logs alone impossible
  5. The totalTokens counter may not be resetting properly: The compaction trigger logic in agent-runner.runtime-*.js depends on totalTokensFresh === false || !hasPersistedTotalTokens to skip compaction. If these flags are not being reset after compaction, every subsequent check would fail the condition and trigger compaction again immediately

Steps to Reproduce

  1. Install OpenClaw 5.5 or 5.6
  2. Enable memory-lancedb-pro plugin
  3. Have a normal conversation (~5-10 exchanges within 30 minutes)
  4. Observe compaction triggering every ~5 minutes instead of ~30 minutes

Expected Behavior

With default compaction settings (truncateAfterCompaction: true, maxActiveTranscriptBytes: 10mb), compaction should trigger approximately every 30 minutes under normal conversation load, not every 5 minutes.


Additional Context

  • Memory Core (built-in): Disabled — only memory-lancedb-pro is active
  • Session transcript file size: ~666KB at time of analysis (far below 10MB threshold), confirming the trigger is not maxActiveTranscriptBytes
  • The trigger appears to be token-count based: Since transcript bytes are nowhere near 10MB, the trigger is likely the contextWindow - 20000 - 4000 token threshold, possibly not being reset after compaction
  • Session: agent:main:main — main session only, no sub-agents
  • Affected versions: Both 5.5 and 5.6 (hotfix did not fix this issue)

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 - ✅(Solved) Fix [Bug] Compaction triggers every ~5 minutes instead of ~30min — compaction loop in OpenClaw 5.5/5.6 (unfixed in hotfix) [1 pull requests, 5 comments, 3 participants]