Skip to content

fix(evolution): validate elitism_count in [0, population_size] at evaluate_and_evolve (PKT-570) - #459

Merged
bugsyhewitt merged 1 commit into
mainfrom
feat/570-elitism-count-validation
Aug 8, 2026
Merged

fix(evolution): validate elitism_count in [0, population_size] at evaluate_and_evolve (PKT-570)#459
bugsyhewitt merged 1 commit into
mainfrom
feat/570-elitism-count-validation

Conversation

@bugsyhewitt

Copy link
Copy Markdown
Owner

Summary

  • Adds a ValueError guard at the top of evaluate_and_evolve (generation.py:66-71) for the cross-field invariant 0 ≤ elitism_count ≤ population_size
  • Three previously silent failure modes are now loud: elitism_count > population_size (evolution stuck, 0 offspring), elitism_count < 0 (pool doubles each generation), elitism_count == population_size remains valid (documented 0-children boundary)
  • Symmetric with the existing _make_selector guard that raises on unknown selection_strategy
  • 3 new tests in TestElitismCountValidation; all 1244 tests pass

Test plan

  • TDD RED: 2/3 new tests failed with "DID NOT RAISE" before implementation
  • TDD GREEN: all 3 new tests pass after 6-line guard added
  • No regressions: full PYTHONPATH=src pytest → 1244 passed, 125 skipped, exit 0
  • Runtime verified: all 4 cases exercised directly (elitism>pop raises, elitism<0 raises, elitism==pop valid, normal valid)
  • Binding review: alienclaw-architect APPROVED, no blocking findings

Files 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

…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>
@bugsyhewitt bugsyhewitt added the auto-merge-ok Binding review passed + ship-gate green — cleared for auto-merge label Aug 8, 2026
@bugsyhewitt
bugsyhewitt merged commit cd3e7b7 into main Aug 8, 2026
7 checks passed
@bugsyhewitt
bugsyhewitt deleted the feat/570-elitism-count-validation branch August 8, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-ok Binding review passed + ship-gate green — cleared for auto-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant