mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-13 03:13:41 +08:00
fix(cron): persist token usage to the run row on completion (#263)
finishRunAndPublish updated the run row with status and finished_at but dropped the LLM token usage, so mate_cron_job_run.token_usage stayed NULL and the scheduler history always showed 0. Write the prompt+completion token total (already computed for the assistant message row) to the run row, guarded so non-LLM paths (reminder direct-push with a null ChatResult) leave the column untouched. Closes #262
This commit is contained in:
parent
39b6bdc522
commit
9baef57871
@ -196,10 +196,13 @@ public class CronJobLifecycleService {
|
||||
String convId = conversationId != null ? conversationId : run.getConversationId();
|
||||
String text = result != null && result.getText() != null ? result.getText() : "";
|
||||
|
||||
int totalTokens = chatResult != null
|
||||
? chatResult.promptTokens() + chatResult.completionTokens() : 0;
|
||||
runMapper.update(null, new LambdaUpdateWrapper<CronJobRunEntity>()
|
||||
.eq(CronJobRunEntity::getId, run.getId())
|
||||
.set(CronJobRunEntity::getStatus, "succeeded")
|
||||
.set(CronJobRunEntity::getFinishedAt, LocalDateTime.now()));
|
||||
.set(CronJobRunEntity::getFinishedAt, LocalDateTime.now())
|
||||
.set(totalTokens > 0, CronJobRunEntity::getTokenUsage, totalTokens));
|
||||
|
||||
if (silent) {
|
||||
// No-op run: persist a short marker so the tasks_<wsId>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user