Repository navigation
Conversation
The post-rerank pool was sorted with -(score or -inf). A reranker score of 0.0 is valid but falsy, so it collapsed to -inf and sorted behind negative scores; truncating the pool to top-K then kept strictly worse items. This contradicts the same file's _resolve_normal_min_score rule that zero is not absent. Extract the inline key into _reranked_pool_sort_key, which treats only None as missing. The helper is testable; ordering and the node-id tie-breaker are otherwise unchanged.
This was referenced Nov 24, 2026
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_read_oncesorts the post-rerank pool with this inline key:_local_rerank_scorecomes straight from the reranker (float(score)inrerank_items_with_scores/rerank_with_lexical_survival), so0.0is aperfectly valid score. But
0.0 or float("-inf")evaluates to-inf, whichmakes the sort key
+inf: a zero-scored item is pushed behind items withnegative scores. When
ranked_poolis later consumed bycompete_hierarchy_bundle/ truncated to top-K, the strictly worse negativeitems are kept and the better zero-scored one is dropped.
This also contradicts a rule already documented in the same file:
_resolve_normal_min_scoreis explicitly written "without treating zero asabsent".
Reproducing the old inline lambda on three items:
Fix
Extract the inline lambda into a module-level
_reranked_pool_sort_keythattreats only
Noneas missing:The
-inffallback for genuinely unscored items is preserved. Extracting thekey makes the ordering unit-testable; the lambda was buried inside the large
_read_oncemethod.Evidence
tests/test_rerank_pool_sort_order.py(3 cases):test_zero_score_ranks_above_negative_scores:0.0sorts between0.8and-0.3. Onmainthe test cannot even import the helper, and the old inlinelambda produces the wrong order shown above.
test_unscored_item_still_sorts_last: an item with no score keeps the-inffallback and stays last, so the fix does not promote unscored items.test_equal_scores_keep_node_id_order: the node-id tie-breaker is unchanged.With the patch:
3 passed.ruff checkpasses on both changed files.Scope
Pure extraction plus the falsy fix. No public API, config, storage, or
dependency changes; ordering is identical for every score except a genuine
0.0(and the still-last unscored case).