fix: resolve variable shadowing in score_organic_jobs that made score cap a no-op#847
Open
Grizouforever wants to merge 1 commit intobackend-developers-ltd:masterfrom
Conversation
… cap a no-op
In `score_organic_jobs`, the loop variable `score` in
`for hotkey, score in batch_scores.items()` shadowed the outer
`score = get_config("DYNAMIC_ORGANIC_JOB_SCORE")` binding.
This caused `min(score, limit * score)` to always equal `score`
(since `limit >= 1` in any meaningful config), so the
`DYNAMIC_SCORE_ORGANIC_JOBS_LIMIT` cap was never applied.
Fix: rename the outer variable to `per_job_score`, compute the cap
once as `cap = per_job_score * limit`, and use `accumulated` as the
loop variable so the names are unambiguous and the cap works correctly.
Also adds 12 unit tests covering the no-cap and capped paths,
including a regression test that would have caught the original bug.
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.
Summary
Fixes #846.
In
score_organic_jobs, the loop variablescoreinfor hotkey, score in batch_scores.items()shadowed the outerscore = get_config("DYNAMIC_ORGANIC_JOB_SCORE")binding. This causedmin(score, limit * score)to always equalscore(becausescorewas already the accumulated total, andlimit >= 1), soDYNAMIC_SCORE_ORGANIC_JOBS_LIMITwas effectively ignored.Changes
validator/app/src/compute_horde_validator/validator/scoring/calculations.pyscore→per_job_scorefor the config valuecap = per_job_score * limitoutside the loopaccumulatedas the loop variable to eliminate the shadowingvalidator/app/src/compute_horde_validator/validator/scoring/tests/test_score_organic_jobs.py(new)limit < 0): empty list, single job, multiple jobs, multiple miners, non-unit scorelimit >= 0): cap applied when exceeding limit, not applied when below, exact limit, non-unit per-job score, zero limit, per-miner independenceTest plan
pytest compute_horde_validator/validator/scoring/tests/test_score_organic_jobs.py)