fix(cli): validate ranking flags to avoid silently wrong output#142
Open
SuperMarioYL wants to merge 1 commit into
Open
fix(cli): validate ranking flags to avoid silently wrong output#142SuperMarioYL wants to merge 1 commit into
SuperMarioYL wants to merge 1 commit into
Conversation
A non-positive --top reaches results[:top_n] in rank_models: --top 0 returns no recommendations at all, and a negative value slices from the end (results[:-5]), silently returning a truncated, unrequested subset instead of the count the user asked for. Negative --min-speed and --min-params thresholds are likewise meaningless. Add _validate_ranking_flags to fail fast with a clear error (mirroring the existing --vram / --gpu-index guards), wire it into the recommend and upgrade commands, and clamp top_n in rank_models so direct callers of the public helper never get a truncated ranking from a stray negative count.
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.
What
The ranking/filter flags
--top,--min-speed, and--min-paramswere never validated, so invalid values silently produced misleading output instead of a clear error — unlike--vram,--bandwidth, and--gpu-index, which already fail fast.The motivating case is
--top, which flows straight intoresults[:top_n]inrank_models:--top 0→results[:0]→ no recommendations are shown at all, with no explanation.--top -5→results[:-5]→ slices from the end, silently returning a truncated subset (the lowest-ranked entries dropped) instead of the count the user asked for.Negative
--min-speed/--min-paramsthresholds are meaningless (they turn the filter into a no-op), so they are rejected too.Changes
_validate_ranking_flags()incli.py(--top≥ 1,--min-speed≥ 0,--min-params≥ 0), following the existing_validate_gpu_flagsstyle, and wire it into both the defaultrecommendflow and theupgradecommand (which also exposes--top).top_ninrank_modelstoresults[: max(top_n, 0)]so direct callers of this public helper never get a truncated ranking from a stray negative count.Notes
--context-lengthalready raises on non-positive values viaparse_context_length, so it is intentionally left unchanged.ruff checkandruff format --checkare clean; the full test suite passes locally (the only failure is the pre-existingtest_run_exits_gracefullysmoke test, which needs a workinguv/network and fails identically on an unmodified checkout — unrelated to this change).