-
-
Notifications
You must be signed in to change notification settings - Fork 69.1k
[Bug]: safeguard compaction makes LLM API call before checking for real messages — 48 unnecessary calls/day on idle sessions #34935
Description
Bug type
Behavior bug (incorrect output/state without crash)
Summary
With compaction.mode: "safeguard", OpenClaw calls 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 has already been made and billed.
From gateway.err.log, this pattern repeats continuously across every active session:
[compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize. Each cancellation is preceded by a full LLM completion request (~33k prompt tokens, ~45 completion tokens based on OpenRouter activity logs). The check that determines there are "no real messages" happens after the API call, not before it.
Steps to reproduce
- Configure any agent with compaction.mode: "safeguard" and a remote LLM provider
- Set up one or more isolated cron jobs (e.g. daily heartbeat agents)
- Leave the system running idle between scheduled jobs
- Observe: LLM API calls fire every ~30 minutes on all sessions, including sessions with zero conversation content
- Observe gateway.err.log: each call results in the safeguard cancellation message
Expected behavior
Before initiating a compaction request to the LLM provider, the system should check locally whether the session contains real conversation messages. If no real messages exist, compaction should abort immediately with no API call made.
Actual behavior
A full LLM completion request is sent to the remote provider (~33k prompt tokens) regardless of session content. The response is received and billed. Only after the round-trip does the safeguard evaluate the result and cancel and then it logs "cancelling compaction with no real conversation messages to summarize." The API cost is already incurred.
OpenClaw version
2026.3.2
Operating system
macOS 26.3 (25D125)
Install method
npm global
Logs, screenshots, and evidence
gateway.err.log — compaction firing and cancelling every 30 minutes on sessions with no content:
2026-03-04T09:12:03.260Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T09:12:20.814Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T09:42:03.262Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T09:42:31.061Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T10:07:43.134Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T10:12:03.250Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T10:42:03.270Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T11:12:03.265Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T11:42:03.256Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T12:12:03.307Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T12:42:03.284Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T13:12:03.314Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T13:42:03.292Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T14:12:03.296Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
2026-03-04T14:42:03.345Z [compaction-safeguard] Compaction safeguard: cancelling compaction with no real conversation messages to summarize.
30-minute cadence, continuous, system otherwise idle.
---
gateway.err.log — compaction timeout on a session that had no content worth compacting, wasting 10 minutes of execution time:
2026-03-04T11:22:03.276Z [agent/embedded] embedded run timeout: runId=[RUN-ID] sessionId=[SESSION-ID] timeoutMs=600000
2026-03-04T11:22:03.285Z [agent/embedded] using current snapshot: timed out during compaction runId=[RUN-ID] sessionId=[SESSION-ID]
---
OpenRouter activity log — single representative call (one of 396 on this date):
{
"model": "stepfun/step-3.5-flash",
"tokens_prompt": 33593,
"tokens_completion": 45,
"native_tokens_reasoning": 42,
"finish_reason": "stop",
"usage": 0.0036987,
"app": { "title": "OpenClaw" }
}
33k prompt tokens in — 45 tokens out — then discarded. This call pattern repeated 396 times on a single day with the system idle between two scheduled cron jobs.Impact and severity
Severity: Moderate — does not break functionality but causes continuous unnecessary API spend with no user-visible benefit
Frequency: Always — fires every ~30 minutes on every active session, 24/7, regardless of activity
Affected users: Any user running OpenClaw with:
- A remote/paid LLM provider as primary model (OpenRouter, Anthropic, OpenAI, etc.)
- One or more long-running or idle sessions (cron agents, persistent Slack/Telegram sessions, background agents)
- compaction.mode: "safeguard" (the default — users who have never touched this setting are affected without knowing it)
Practical consequence:
- ~48 LLM API calls per day per instance generated with zero productive output
- Each call sends the full session system prompt + context (~33k tokens) to the provider and discards the response
- At Step-3.5-Flash pricing this produced $1.26/day in invisible background spend — roughly $38/month — on a system doing nothing
- Users who switch to a paid model without realizing the compaction issue exists will see immediate unexplained API cost
- Users relying on Hindsight or another external memory system have no workflow reason for in-context compaction at all, they are paying for a system designed to help them that actively works against their cost model
- The community workaround ("adjust compaction settings") does not exist in practice, "off" is not a valid schema value, leaving affected users with no recourse short of patching the binary
Risk: Low data risk, high cost risk at scale. A team running multiple agents (Odie + Piper + subagents) multiplies the call count proportionally.
Additional information
No response