Skip to content

fix(compaction): skip LLM API call when no real conversation messages exist#2

Open
195440 wants to merge 1 commit into
mainfrom
fix/compaction-early-check
Open

fix(compaction): skip LLM API call when no real conversation messages exist#2
195440 wants to merge 1 commit into
mainfrom
fix/compaction-early-check

Conversation

@195440

@195440 195440 commented Mar 5, 2026

Copy link
Copy Markdown
Owner

With compaction.mode: safeguard, OpenClaw was calling the LLM API every ~30 minutes on all active sessions - including isolated cron sessions that contain no real conversation messages. The safeguard then correctly cancels the compaction, but the API call had already been made and billed.

Add an early local check before calling session.compact() to detect if there are any real conversation messages (user/assistant/toolResult). If none exist, skip compaction entirely without making any LLM API calls.

This reduces unnecessary API calls and associated costs.

Closes openclaw#34935


Note

Low Risk
Low risk: adds a simple early-return guard in the compaction path to avoid calling session.compact() when there are no conversation messages. Main risk is unintentionally skipping compaction for sessions that only contain non-standard roles, but it returns the existing no_compactable_entries reason.

Overview
Avoids unnecessary LLM compaction calls by adding an early check in compactEmbeddedPiSessionDirect to detect sessions with no real conversation messages (user/assistant/toolResult) and return compacted: false before invoking session.compact().

Adds a diagnostic info log for these skipped compactions (reason no_real_messages), reducing billed API calls in safeguard-mode sessions that contain only synthetic/empty history.

Written by Cursor Bugbot for commit cfc5eb3. This will update automatically on new commits. Configure here.

… exist

With compaction.mode: safeguard, OpenClaw was calling the LLM API every
~30 minutes on all active sessions - including isolated cron sessions
that contain no real conversation messages. The safeguard then correctly
cancels the compaction, but the API call had already been made and billed.

Add an early local check before calling session.compact() to detect if
there are any real conversation messages (user/assistant/toolResult).
If none exist, skip compaction entirely without making any LLM API calls.

This reduces unnecessary API calls and associated costs.

Closes openclaw#34935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: safeguard compaction makes LLM API call before checking for real messages — 48 unnecessary calls/day on idle sessions

1 participant