mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:11:23 +00:00
fix(session): harden usage accounting and memory flush recovery
This commit is contained in:
@@ -93,8 +93,11 @@ export async function persistSessionUsageUpdate(params: {
|
||||
if (hasUsage) {
|
||||
patch.inputTokens = params.usage?.input ?? 0;
|
||||
patch.outputTokens = params.usage?.output ?? 0;
|
||||
patch.cacheRead = params.usage?.cacheRead ?? 0;
|
||||
patch.cacheWrite = params.usage?.cacheWrite ?? 0;
|
||||
// Cache counters should reflect the latest context snapshot when
|
||||
// available, not accumulated per-call totals across a whole run.
|
||||
const cacheUsage = params.lastCallUsage ?? params.usage;
|
||||
patch.cacheRead = cacheUsage?.cacheRead ?? 0;
|
||||
patch.cacheWrite = cacheUsage?.cacheWrite ?? 0;
|
||||
}
|
||||
// Missing a last-call snapshot (and promptTokens fallback) means
|
||||
// context utilization is stale/unknown.
|
||||
|
||||
Reference in New Issue
Block a user