fix(core): seed genetic/monte_carlo optimizers for reproducible schedules (#963)#1002
Merged
Conversation
…ules (#963) Both strategies drew from the global random module without ever seeding it, so identical input produced a different schedule on every run — at odds with taskdog's "transparent, reproducible algorithms" goal and inherently flaky for any test asserting on their output. Add an optional seed to OptimizeParams and have each strategy seed a local random.Random per run (no global RNG mutation). seed defaults to None, which falls back to a fixed DEFAULT_OPTIMIZATION_SEED so identical input yields an identical schedule; callers can pass an explicit seed to vary results.
There was a problem hiding this comment.
This PR successfully addresses issue #963 by introducing reproducible seeding for genetic and monte_carlo optimization strategies. The implementation is clean and well-structured:
Key Changes:
- Added
seedparameter toOptimizeParamswith default fallback toDEFAULT_OPTIMIZATION_SEED = 0 - Replaced all global
randommodule calls with a localself._rnginstance in both strategies - RNG is seeded per optimization run, ensuring identical input yields identical output
- Comprehensive test coverage validates reproducibility for both explicit and default seeds
Verification:
- All 1109 tests pass
- New tests confirm determinism works as expected
- No global RNG mutation - each run uses its own seeded instance
The changes are minimal, focused, and achieve the stated goal of reproducible schedules without breaking existing functionality. Ready to merge.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
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
The
geneticandmonte_carlooptimization strategies drew from the globalrandommodule without ever seeding it, so identical input produced a different schedule on every run. This is at odds with taskdog's "transparent, reproducible algorithms" goal and makes any test asserting on these strategies' output inherently flaky.Closes #963.
Changes
seed: int | None = NonetoOptimizeParams.DEFAULT_OPTIMIZATION_SEED = 0constant.random.Randomper run (no global RNG mutation) and route everyrandom.sample/choice/random(...)through it.seed=Nonefalls back toDEFAULT_OPTIMIZATION_SEED, so identical input → identical schedule by default; callers can pass an explicit seed to vary results.Scope kept to core: threading
--seedthrough the CLI/server/MCP is intentionally out of scope — the acceptance criterion is reproducible strategy output.Verification
test_optimization_determinism.py: same seed → identical schedule, and default (None) seed → reproducible, parametrized over both strategies.taskdog-coresuite: 1109 passed. ruff + mypy clean. pre-push (make test, vulture) passed.