← Back to library

用 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
  1. Record a baseline by running one tool-heavy conversation and checking current totalTokens value.
  2. Upgrade to a build containing PR #15018, then restart gateway.
  3. Trigger manual /compact once and run another tool-heavy turn that can auto-compact.
  4. Compare persisted session totalTokens before/after compaction and ensure it tracks latest-call usage, not accumulated usage.
  5. Keep accumulated usage for billing/cost views only and avoid using it for context-window health checks.
Commands
openclaw gateway status
openclaw gateway restart
openclaw status
Verify

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 ↗
Visit original post