mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-27 15:49:23 -05:00
fix: /status shows too little context when a reply ends on a tool result (#34622)
When a reply ended on a tool result, for example because it was stopped right after a tool returned or the model call after it failed, /status left that result out, since it came back after the model's last reported token count. The result is still sent with the next message and context compaction counts it, so compaction could run while /status showed the chat well under the threshold. /status now counts those results too, the same way the compaction check does. Fixes #34617
This commit is contained in:
1 parent
04cedc89f5
commit
44ca4e78fe
1 file changed
+5
-2
@@ -40,7 +40,10 @@ const usageCheckpoints = new WeakMap<object, number>();
|
||||
|
||||
export const captureUsageCheckpoint = (message: ContextMessage): void => {
|
||||
const usage = message.usage ?? message.info?.usage;
|
||||
if (usage) usageCheckpoints.set(usage, estimateMessagesTokens([message]));
|
||||
// Tool results that end the reply came back after the report.
|
||||
const output = [...(message.output ?? [])] as { type?: string }[];
|
||||
while (output.at(-1)?.type === 'function_call_output') output.pop();
|
||||
if (usage) usageCheckpoints.set(usage, estimateMessagesTokens([{ ...message, output }]));
|
||||
};
|
||||
|
||||
export const estimateUsageGrowth = (message: ContextMessage): number => {
|
||||
@@ -49,7 +52,7 @@ export const estimateUsageGrowth = (message: ContextMessage): number => {
|
||||
const tokens = estimateMessagesTokens([message]);
|
||||
if (!usageCheckpoints.has(usage)) {
|
||||
// shortcut: loaded chats anchor here; persist checkpoints if reloads must retain in-flight estimates.
|
||||
usageCheckpoints.set(usage, tokens);
|
||||
captureUsageCheckpoint(message);
|
||||
}
|
||||
return Math.max(0, tokens - usageCheckpoints.get(usage)!);
|
||||
};
|
||||
Reference in new issue
Block a user