From 48b7f4918f532c7db3b7c9814802d538d01b0996 Mon Sep 17 00:00:00 2001 From: CaIon Date: Tue, 7 Jul 2026 13:11:55 +0800 Subject: [PATCH] fix(billing): adjust quota calculation to prevent exceeding int32 limits --- service/text_quota.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service/text_quota.go b/service/text_quota.go index 0d452fba..4f6e4c11 100644 --- a/service/text_quota.go +++ b/service/text_quota.go @@ -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 {