用 last-call usage 修正 compaction 后 totalTokens 偏高(PR #15018)
解决 /status 和 dashboard 在压缩后仍显示旧 token 的问题:以最后一次模型调用 usage 作为当前上下文体积,累计 usage 仅用于成本统计。
GITHUBDiscovered 2026-02-13Author shtse8
Prerequisites
- Gateway version includes PR #15018 and can be restarted during a maintenance window.
- You can reproduce token inflation after auto-compaction or manual /compact.
Steps
- Record a baseline by running one tool-heavy conversation and checking current totalTokens value.
- Upgrade to a build containing PR #15018, then restart gateway.
- Trigger manual /compact once and run another tool-heavy turn that can auto-compact.
- Compare persisted session totalTokens before/after compaction and ensure it tracks latest-call usage, not accumulated usage.
- Keep accumulated usage for billing/cost views only and avoid using it for context-window health checks.
Commands
openclaw gateway statusopenclaw gateway restartopenclaw statusVerify
After compaction, totalTokens drops to post-compaction context size and no longer sticks near context max.
Caveats
- If your pipeline depends on custom usage middleware, verify it does not overwrite last-call usage fields(需验证)。
- This fix targets token display/accounting; it does not reduce actual model token spend by itself.
Source attribution
This tip is aggregated from community/public sources and preserved with attribution.
Open original source ↗