Skip to content

fix(vm-ranker): keep non-finite scores from panicking ranking sorts - #258

Open
davidchung29 wants to merge 2 commits into
xai-org:mainfrom
davidchung29:fix/vm-ranker-nan-score-ordering
Open

davidchung29 wants to merge 2 commits into
xai-org:mainfrom
davidchung29:fix/vm-ranker-nan-score-ordering

Conversation

@davidchung29

@davidchung29 davidchung29 commented Oct 19, 2026 •

Copy link
Copy Markdown

Closes #253.

TL;DR: In vm-ranker, the service that scores and diversifies For You candidates before home-mixer's selector, one NaN score can crash the request. This fixes its ranking sorts and the shared author_pool_counts sort in xai-value-model so invalid scores are handled safely.

Bug: vm-ranker's sorts treat NaN as equal to every number, which isn't a consistent ordering, so Rust's sort can panic and fail the whole request before it reaches the selector fixed in #204.

Fix: Add compare_scores_desc, which sorts real scores high to low and puts NaN/±inf last, and use it in author_pool_counts, DPP, and the ranker-service debug sort. Normal scores sort the same as before. DPP also now leaves non-finite scores out of its candidate pool, so a +inf score can't take over selection when the pool has spare room. With the #253 repro harness, these sorts no longer panic on NaN input, and new unit tests cover the crash case. Prepared with AI assistance.

@davidchung29
davidchung29 force-pushed the fix/vm-ranker-nan-score-ordering branch from 44fa5a5 to 9c7191f Compare October 19, 2026 18:44
@davidchung29
davidchung29 marked this pull request as ready for review October 20, 2026 14:06

@mangeshraut712 mangeshraut712 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the total order implementation in score_order.rs and the integration across vm-ranker and xai-value-model.

  1. compare_scores_desc correctly defines a strict weak ordering: finite scores are compared via b.partial_cmp(&a) (descending), non-finite scores (NaN, ±Inf) all evaluate as equal to each other, and finite scores strictly precede non-finite scores. This satisfies transitivity of both strict ordering and equivalence, eliminating the panic in slice::sort_by / sort_unstable_by.
  2. In dpp.rs, filtering inputs[i].score.is_finite() up front before slicing top_indices ensures that non-finite scores cannot occupy a slot in the DPP candidate pool when inputs.len() < max_selected_rank.
  3. The comprehensive transitivity matrix test across [f64::MIN, -1.0, -0.0, 0.0, 1.0, f64::MAX, f64::NAN, -f64::NAN, f64::INFINITY, f64::NEG_INFINITY] gives solid regression protection.

Looks solid and ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NaN scores can panic in vm-ranker sorting before the selector

2 participants