mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:29:34 +00:00
fix: /status shows incorrect context percentage — totalTokens clamped to contextTokens (#15114) (#15133)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: a489669fc7
Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -70,6 +70,12 @@ export type SessionEntry = {
|
||||
inputTokens?: number;
|
||||
outputTokens?: number;
|
||||
totalTokens?: number;
|
||||
/**
|
||||
* Whether totalTokens reflects a fresh context snapshot for the latest run.
|
||||
* Undefined means legacy/unknown freshness; false forces consumers to treat
|
||||
* totalTokens as stale/unknown for context-utilization displays.
|
||||
*/
|
||||
totalTokensFresh?: boolean;
|
||||
modelProvider?: string;
|
||||
model?: string;
|
||||
contextTokens?: number;
|
||||
@@ -107,6 +113,25 @@ export function mergeSessionEntry(
|
||||
return { ...existing, ...patch, sessionId, updatedAt };
|
||||
}
|
||||
|
||||
export function resolveFreshSessionTotalTokens(
|
||||
entry?: Pick<SessionEntry, "totalTokens" | "totalTokensFresh"> | null,
|
||||
): number | undefined {
|
||||
const total = entry?.totalTokens;
|
||||
if (typeof total !== "number" || !Number.isFinite(total) || total < 0) {
|
||||
return undefined;
|
||||
}
|
||||
if (entry?.totalTokensFresh === false) {
|
||||
return undefined;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
export function isSessionTotalTokensFresh(
|
||||
entry?: Pick<SessionEntry, "totalTokens" | "totalTokensFresh"> | null,
|
||||
): boolean {
|
||||
return resolveFreshSessionTotalTokens(entry) !== undefined;
|
||||
}
|
||||
|
||||
export type GroupKeyResolution = {
|
||||
key: string;
|
||||
channel?: string;
|
||||
|
||||
Reference in New Issue
Block a user