fix(compaction): skip LLM API call when no real conversation messages exist#2
Open
195440 wants to merge 1 commit into
Open
fix(compaction): skip LLM API call when no real conversation messages exist#2195440 wants to merge 1 commit into
195440 wants to merge 1 commit into
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 existingno_compactable_entriesreason.Overview
Avoids unnecessary LLM compaction calls by adding an early check in
compactEmbeddedPiSessionDirectto detect sessions with no real conversation messages (user/assistant/toolResult) and returncompacted: falsebefore invokingsession.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.