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 {