fix(billing): adjust quota calculation to prevent exceeding int32 limits

This commit is contained in:
CaIon
2026-07-07 13:11:55 +08:00
parent 9b93d61b7f
commit 48b7f4918f
+7 -2
View File
@@ -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 {