From 453997eb9c24d022cf07fb1570c8688703a58982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=AA=E7=A8=8B=E4=BC=9F?= Date: Sun, 7 Jun 2026 23:35:20 +0800 Subject: [PATCH] fix(cron): count silent-run token usage in settings total A silent (no-op) cron run still makes a full LLM call, but the marker message was persisted via the token-free saveMessage overload, so the settings-page Token total (which aggregates MessageEntity token columns) under-counted cron spend by exactly the silent runs. Carry chatResult's prompt/completion tokens onto the marker message, matching the non-silent branch. Closes #284. --- .../mate/cron/service/CronJobLifecycleService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mateclaw-server/src/main/java/vip/mate/cron/service/CronJobLifecycleService.java b/mateclaw-server/src/main/java/vip/mate/cron/service/CronJobLifecycleService.java index fc3c1168..c12cbe69 100644 --- a/mateclaw-server/src/main/java/vip/mate/cron/service/CronJobLifecycleService.java +++ b/mateclaw-server/src/main/java/vip/mate/cron/service/CronJobLifecycleService.java @@ -211,7 +211,17 @@ public class CronJobLifecycleService { // real content to deliver or to learn from. String marker = i18n != null ? i18n.msg("cron.run.silent") : "(本次定时任务无新内容,已跳过)"; - conversationService.saveMessage(convId, "assistant", marker); + // A silent run still made a full LLM call, so carry its token usage + // onto the marker message — otherwise the settings-page total (which + // aggregates MessageEntity token columns) under-counts cron spend. + if (chatResult != null + && (chatResult.promptTokens() > 0 || chatResult.completionTokens() > 0)) { + conversationService.saveMessage(convId, "assistant", marker, null, "completed", + chatResult.promptTokens(), chatResult.completionTokens(), + chatResult.runtimeModel(), chatResult.runtimeProvider()); + } else { + conversationService.saveMessage(convId, "assistant", marker); + } return; }