mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:44:59 +00:00
fix(memoryFlush): correct context token accounting for flush gating (#5343)
Merged via squash.
Prepared head SHA: afaa7bae3b
Co-authored-by: jarvis-medmatic <252428873+jarvis-medmatic@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
@@ -79,16 +79,20 @@ export async function updateSessionStoreAfterAgentRun(params: {
|
||||
if (hasNonzeroUsage(usage)) {
|
||||
const input = usage.input ?? 0;
|
||||
const output = usage.output ?? 0;
|
||||
const totalTokens =
|
||||
deriveSessionTotalTokens({
|
||||
usage,
|
||||
contextTokens,
|
||||
promptTokens,
|
||||
}) ?? input;
|
||||
const totalTokens = deriveSessionTotalTokens({
|
||||
usage,
|
||||
contextTokens,
|
||||
promptTokens,
|
||||
});
|
||||
next.inputTokens = input;
|
||||
next.outputTokens = output;
|
||||
next.totalTokens = totalTokens;
|
||||
next.totalTokensFresh = true;
|
||||
if (typeof totalTokens === "number" && Number.isFinite(totalTokens) && totalTokens > 0) {
|
||||
next.totalTokens = totalTokens;
|
||||
next.totalTokensFresh = true;
|
||||
} else {
|
||||
next.totalTokens = undefined;
|
||||
next.totalTokensFresh = false;
|
||||
}
|
||||
next.cacheRead = usage.cacheRead ?? 0;
|
||||
next.cacheWrite = usage.cacheWrite ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user