mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:11:23 +00:00
fix(agents): stabilize overflow compaction retries and session context accounting (openclaw#14102) thanks @vpesh
Verified:
- CI checks for commit 86a7ecb45e
- Rebase conflict resolution for compatibility with latest main
Co-authored-by: vpesh <9496634+vpesh@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
da55d70fb0
commit
957b883082
@@ -112,18 +112,24 @@ export function deriveSessionTotalTokens(params: {
|
||||
cacheWrite?: number;
|
||||
};
|
||||
contextTokens?: number;
|
||||
promptTokens?: number;
|
||||
}): number | undefined {
|
||||
const promptOverride = params.promptTokens;
|
||||
const hasPromptOverride =
|
||||
typeof promptOverride === "number" && Number.isFinite(promptOverride) && promptOverride > 0;
|
||||
const usage = params.usage;
|
||||
if (!usage) {
|
||||
if (!usage && !hasPromptOverride) {
|
||||
return undefined;
|
||||
}
|
||||
const input = usage.input ?? 0;
|
||||
const promptTokens = derivePromptTokens({
|
||||
input: usage.input,
|
||||
cacheRead: usage.cacheRead,
|
||||
cacheWrite: usage.cacheWrite,
|
||||
});
|
||||
let total = promptTokens ?? usage.total ?? input;
|
||||
const input = usage?.input ?? 0;
|
||||
const promptTokens = hasPromptOverride
|
||||
? promptOverride
|
||||
: derivePromptTokens({
|
||||
input: usage?.input,
|
||||
cacheRead: usage?.cacheRead,
|
||||
cacheWrite: usage?.cacheWrite,
|
||||
});
|
||||
let total = promptTokens ?? usage?.total ?? input;
|
||||
if (!(total > 0)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user