fix: retain every direct-model usage call

Multiple model invocations in one task could share a call identifier when
a provider omitted or reused its response ID. Database upserts then replaced
earlier tool-round or summary usage, causing cumulative activity totals to
undercount successful calls.

Each completed direct-model invocation now receives a unique local call ID
while retaining the provider ID as diagnostic context. Tool rounds, final
responses, image calls, and repeated compression summaries are therefore
stored independently.

Release note: 修复连续工具调用或上下文摘要可能覆盖前序模型用量的问题;现在每次成功调用都会分别计入运行记录和累计统计。
This commit is contained in:
mesalogo
2026-08-16 01:18:07 +08:00
parent c98fe67f1a
commit 9e6f664e06
2 changed files with 59 additions and 8 deletions
+4 -1
View File
@@ -483,10 +483,13 @@ function createUsageEvent(
if (!usage.reported) {
return undefined
}
const localCallId = `model-call:${randomBytes(16).toString('hex')}`
return {
requestId,
type: 'model-usage',
callId: (usage.callId ?? requestId).slice(0, 256),
callId: usage.callId
? `${localCallId}:${usage.callId}`.slice(0, 256)
: localCallId,
runtime: 'model',
provider,
model: (usage.model ?? fallbackModel).slice(0, 500),