fix(billing): adjust quota calculation to prevent exceeding int32 limits
This commit is contained in:
@@ -165,9 +165,14 @@ func composeTieredTextQuota(relayInfo *relaycommon.RelayInfo, summary textQuotaS
|
||||
}
|
||||
}
|
||||
|
||||
surcharge, clamp := common.QuotaFromDecimalChecked(summary.ToolCallSurchargeQuota)
|
||||
// Saturate the final sum, not just the surcharge: tieredQuota can be near
|
||||
// MaxQuota and adding the surcharge could push the total past the int32
|
||||
// quota policy bound (persisted quota columns are 32-bit).
|
||||
total, clamp := common.QuotaFromDecimalChecked(
|
||||
decimal.NewFromInt(int64(tieredQuota)).Add(summary.ToolCallSurchargeQuota),
|
||||
)
|
||||
noteQuotaClamp(relayInfo, clamp)
|
||||
return tieredQuota + surcharge
|
||||
return total
|
||||
}
|
||||
|
||||
func calculateTextQuotaSummary(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.Usage) textQuotaSummary {
|
||||
|
||||
Reference in New Issue
Block a user