@@ -422,21 +422,27 @@ func applyActiveStickiness(ranked []string, activeRelayURLs []string, states []R
422422 }
423423 }
424424
425+ // Active quota boundary: only candidates ranked within the eligible active quota
426+ // (top maxActive in the ranked pool) can exercise stickiness. Candidates demoted
427+ // outside the active quota (e.g. by P2C pressure demotion or saturation tiering)
428+ // cannot be promoted back over healthier candidates.
429+ quotaLen := min (len (ranked ), maxActive )
430+ eligibleQuota := ranked [:quotaLen ]
431+
425432 selected := make ([]string , 0 , len (ranked ))
426- // Layer 1: Retain currently active sticky relays that remain healthy (capped at maxActive)
427- for _ , u := range ranked {
433+ // Layer 1: Retain currently active sticky relays among the eligible quota candidates
434+ for _ , u := range eligibleQuota {
428435 if _ , isActive := activeSet [u ]; isActive {
429436 selected = append (selected , u )
430- if len (selected ) == maxActive {
431- break
432- }
433437 }
434438 }
435- // Layer 2 & Trailing: Append remaining candidates preserving their relative MOLS ranking
436- for _ , u := range ranked {
439+ // Layer 2: Fill remaining quota slots with top-ranked candidates from eligible quota
440+ for _ , u := range eligibleQuota {
437441 if ! slices .Contains (selected , u ) {
438442 selected = append (selected , u )
439443 }
440444 }
445+ // Trailing: Preserve remaining reserve candidates in their ranked order
446+ selected = append (selected , ranked [quotaLen :]... )
441447 return selected
442448}
0 commit comments