@@ -254,28 +254,37 @@ func evalQuotaRules(
254254 isUpdate bool ,
255255 prevMaxReplicas int32 , // 0 for creates; used by per-agent ceiling check
256256) (bool , string ) {
257- projAgents := committedUsage .UsedAgents + inFlight .agents + delta .agents
258- projGPUs := committedUsage .UsedGPUs + inFlight .gpus + delta .gpus
259- projReplicas := committedUsage .UsedTotalReplicas + inFlight .replicas + delta .replicas
257+ // Reject the math.MaxInt32 sentinel used by gpusForAD to signal overflow.
258+ // If delta.gpus is MaxInt32, the GPU calculation overflowed and we must
259+ // fail closed to prevent undercount-based admission.
260+ if delta .gpus == math .MaxInt32 {
261+ return false , "GPU resource calculation overflowed; request denied"
262+ }
263+
264+ // Perform projection calculations in int64 to prevent overflow, then
265+ // compare against int64-converted quota limits.
266+ projAgents := int64 (committedUsage .UsedAgents ) + int64 (inFlight .agents ) + int64 (delta .agents )
267+ projGPUs := int64 (committedUsage .UsedGPUs ) + int64 (inFlight .gpus ) + int64 (delta .gpus )
268+ projReplicas := int64 (committedUsage .UsedTotalReplicas ) + int64 (inFlight .replicas ) + int64 (delta .replicas )
260269
261270 // For UPDATE requests, only reject when the delta increases a dimension that
262271 // is already at or over quota. If quota was lowered below current usage, the
263272 // existing ADs are already OverQuota (indicated by the TQ condition) — we
264273 // must not block updates that don't make things worse, otherwise finalizer
265274 // removal and spec corrections are deadlocked.
266- if projAgents > quota .MaxAgents && (! isUpdate || delta .agents > 0 ) {
275+ if projAgents > int64 ( quota .MaxAgents ) && (! isUpdate || delta .agents > 0 ) {
267276 return false , fmt .Sprintf (
268277 "would exceed maxAgents (%d): current=%d in-flight=%d delta=%d" ,
269278 quota .MaxAgents , committedUsage .UsedAgents , inFlight .agents , delta .agents ,
270279 )
271280 }
272- if projGPUs > quota .MaxGPUs && (! isUpdate || delta .gpus > 0 ) {
281+ if projGPUs > int64 ( quota .MaxGPUs ) && (! isUpdate || delta .gpus > 0 ) {
273282 return false , fmt .Sprintf (
274283 "would exceed maxGPUs (%d): current=%d in-flight=%d delta=%d" ,
275284 quota .MaxGPUs , committedUsage .UsedGPUs , inFlight .gpus , delta .gpus ,
276285 )
277286 }
278- if projReplicas > quota .MaxTotalReplicas && (! isUpdate || delta .replicas > 0 ) {
287+ if projReplicas > int64 ( quota .MaxTotalReplicas ) && (! isUpdate || delta .replicas > 0 ) {
279288 return false , fmt .Sprintf (
280289 "would exceed maxTotalReplicas (%d): current=%d in-flight=%d delta=%d" ,
281290 quota .MaxTotalReplicas , committedUsage .UsedTotalReplicas , inFlight .replicas , delta .replicas ,
0 commit comments