mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend): guard against non-finite cost_usd in persist_and_record_usage
float('inf') and float('nan') do not raise ValueError/TypeError so they
bypass the existing try/except. Passing them to usd_to_microdollars causes
OverflowError at round(inf * 1_000_000). Add math.isfinite(val) and val >= 0
check (matching the same pattern used in baseline/service.py and llm.py)
before assigning cost_float.
This commit is contained in:
@@ -11,6 +11,7 @@ This module extracts that common logic so both paths stay in sync.
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import math
|
||||
import re
|
||||
import threading
|
||||
|
||||
@@ -174,7 +175,9 @@ async def persist_and_record_usage(
|
||||
cost_float = None
|
||||
if cost_usd is not None:
|
||||
try:
|
||||
cost_float = float(cost_usd)
|
||||
val = float(cost_usd)
|
||||
if math.isfinite(val) and val >= 0:
|
||||
cost_float = val
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user