-
-
Notifications
You must be signed in to change notification settings - Fork 57k
Description
Summary
After compaction (both manual /compact and auto-compaction), the totalTokens field in sessions.json is never updated. This causes openclaw sessions and the dashboard to permanently display the pre-compaction token count, even after successful compaction and subsequent agent turns.
Reproduction
- Let a session accumulate to high context usage (e.g. 181k/200k = 91%)
- Run
/compact— agent confirms compaction succeeded (reports ~5%) - Send a follow-up message to trigger a real agent turn
- Run
openclaw sessionsor check the dashboard - Session still shows 181k/200k (91%)
$ openclaw sessions
Kind Key Age Model Tokens (ctx %)
group agent:main:teleg...topic:30 7h ago claude-sonnet-4-5 181k/200k (91%)
Meanwhile the agent itself reports context at ~5% post-compaction.
Expected behavior
totalTokens in the session store should be updated after compaction completes, so that openclaw sessions and the dashboard reflect the actual current context usage.
Root cause (suspected)
The compaction path writes the compacted transcript but does not call back into the session store to update totalTokens. The field is only written during regular agent turn completion, and even then appears to retain the historical high-water mark rather than the current context size.
Related: #5457 (stale token counts in flush logic) — same underlying issue of totalTokens not reflecting actual context.
Environment
- OpenClaw 2026.2.9 (33c75cb)
- macOS Darwin 25.2.0
- Affected models: claude-sonnet-4-5 (200k), claude-opus-4-6 (200k)
- Config:
compaction.mode: "safeguard",contextTokens: 80000