fix(copilot): add max(0,...) guards to persist_and_record_usage inputs

This commit is contained in:
Zamil Majdy
2026-03-16 06:15:37 +07:00
parent 4a08482aa6
commit acb0d41a35

View File

@@ -42,6 +42,11 @@ async def persist_and_record_usage(
Returns:
The computed total_tokens (prompt + completion; cache excluded).
"""
prompt_tokens = max(0, prompt_tokens)
completion_tokens = max(0, completion_tokens)
cache_read_tokens = max(0, cache_read_tokens)
cache_creation_tokens = max(0, cache_creation_tokens)
if prompt_tokens <= 0 and completion_tokens <= 0:
return 0