Summary
Auto-compaction does not trigger automatically even when the context window is exceeded (observed at 153% = 305k/200k), as long as the Anthropic prompt cache absorbs most tokens.
Environment
- OpenClaw version: 2026.4.12 (1c0672b)
- Model:
anthropic/claude-sonnet-4-6
- Compaction mode:
safeguard
reserveTokensFloor: 30000
Observed behavior
/status output at time of issue:
Model: anthropic/claude-sonnet-4-6
Tokens: 3 in / 140 out
Cache: 100% hit · 305k cached, 99 new
Context: 305k/200k (153%) · Compactions: 0
Context was at 153% of the model window (305k > 200k) with 0 compactions. Auto-compaction should have fired at the contextWindow - reserveTokens threshold (≈170k), but never did. The user had to run /compact manually.
Root cause hypothesis
Pi's compaction threshold check appears to use the new tokens counter (99 in this case) rather than the total context size (305k). When Anthropic's prompt cache absorbs nearly all tokens (100% hit rate), the incoming token count seen by Pi's runtime is near zero, so the threshold contextTokens > contextWindow - reserveTokens is never satisfied — even though the actual context far exceeds the window.
In other words: prompt cache efficiency masks the true context load from the Pi compaction engine.
Expected behavior
Auto-compaction should trigger based on total context window usage (305k/200k), not on the count of non-cached input tokens for the current turn.
Workaround
Manual /compact command. Enabling compaction.notifyUser: true has no effect since compaction never triggers.
Steps to reproduce
- Start a long session with
anthropic/claude-sonnet-4-6 and compaction.mode: safeguard
- Let the session grow until prompt cache hits approach 100%
- Continue the session past the context window limit (200k tokens)
- Observe:
/status shows Context > 100% with Compactions: 0
- Auto-compaction never fires — manual
/compact required
Summary
Auto-compaction does not trigger automatically even when the context window is exceeded (observed at 153% = 305k/200k), as long as the Anthropic prompt cache absorbs most tokens.
Environment
anthropic/claude-sonnet-4-6safeguardreserveTokensFloor: 30000Observed behavior
/statusoutput at time of issue:Context was at 153% of the model window (305k > 200k) with 0 compactions. Auto-compaction should have fired at the
contextWindow - reserveTokensthreshold (≈170k), but never did. The user had to run/compactmanually.Root cause hypothesis
Pi's compaction threshold check appears to use the new tokens counter (99 in this case) rather than the total context size (305k). When Anthropic's prompt cache absorbs nearly all tokens (100% hit rate), the incoming token count seen by Pi's runtime is near zero, so the threshold
contextTokens > contextWindow - reserveTokensis never satisfied — even though the actual context far exceeds the window.In other words: prompt cache efficiency masks the true context load from the Pi compaction engine.
Expected behavior
Auto-compaction should trigger based on total context window usage (305k/200k), not on the count of non-cached input tokens for the current turn.
Workaround
Manual
/compactcommand. Enablingcompaction.notifyUser: truehas no effect since compaction never triggers.Steps to reproduce
anthropic/claude-sonnet-4-6andcompaction.mode: safeguard/statusshows Context > 100% with Compactions: 0/compactrequired