Awesome Reviewers

When implementing complex allocation/selection algorithms, require three things in code review:

1) Explicit accounting invariants (no double-count / no negative “available”):

2) Comparator/ordering correctness matches the priority model:

3) Deduplication when items span partitions:

Practical checklist for reviewers:

Example pattern to enforce invariant #3 (dedupe while sorting):

added := cpuset.New()
for _, region := range regions {
  avail := availableSet.In(region)
  // If an entity can be present in multiple regions, remove already-added.
  avail = avail.Difference(added)
  // Now select from avail, then mark as added.
  result = append(result, avail.List()...)
  added = added.Union(avail)
}

If you adopt these rules consistently, most of the failure modes discussed (negative availability, skipped search due to wrong bounds, duplicated spanning items, and wrong “most important” ordering) become unlikely and are much easier to test and reason about.