fix(evolution): validate elitism_count in [0, population_size] at evaluate_and_evolve (PKT-570) - #459
Merged
Merged
Conversation
…luate_and_evolve (PKT-570) Three silent failure modes existed when elitism_count was out of range: 0 offspring per generation (elitism_count > population_size), or unbounded pool growth (elitism_count < 0). Guard added at the algorithm boundary, symmetric with the existing _make_selector guard for unknown selection_strategy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
ValueErrorguard at the top ofevaluate_and_evolve(generation.py:66-71) for the cross-field invariant0 ≤ elitism_count ≤ population_sizeelitism_count > population_size(evolution stuck, 0 offspring),elitism_count < 0(pool doubles each generation),elitism_count == population_sizeremains valid (documented 0-children boundary)_make_selectorguard that raises on unknownselection_strategyTestElitismCountValidation; all 1244 tests passTest plan
PYTHONPATH=src pytest→ 1244 passed, 125 skipped, exit 0Files changed
src/alienclaw/evolution/generation.py(+6 lines — guard only)test/evolution/test_generation.py(+25 lines — 3 tests in new class)🤖 Generated with Claude Code