Skip to content

fix(core): seed genetic/monte_carlo optimizers for reproducible schedules (#963)#1002

Merged
Kohei-Wada merged 1 commit into
mainfrom
fix/optimizer-seed-963
Jun 6, 2026
Merged

fix(core): seed genetic/monte_carlo optimizers for reproducible schedules (#963)#1002
Kohei-Wada merged 1 commit into
mainfrom
fix/optimizer-seed-963

Conversation

@Kohei-Wada
Copy link
Copy Markdown
Owner

Summary

The genetic and monte_carlo optimization strategies drew from the global random module 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

  • Add seed: int | None = None to OptimizeParams.
  • Add DEFAULT_OPTIMIZATION_SEED = 0 constant.
  • In both strategies, seed a local random.Random per run (no global RNG mutation) and route every random.sample/choice/random(...) through it. seed=None falls back to DEFAULT_OPTIMIZATION_SEED, so identical input → identical schedule by default; callers can pass an explicit seed to vary results.

Scope kept to core: threading --seed through the CLI/server/MCP is intentionally out of scope — the acceptance criterion is reproducible strategy output.

Verification

  • New test_optimization_determinism.py: same seed → identical schedule, and default (None) seed → reproducible, parametrized over both strategies.
  • Confirmed the tests aren't vacuous: different seeds (1 vs 999) produce different orderings, so the RNG genuinely drives output.
  • Full taskdog-core suite: 1109 passed. ruff + mypy clean. pre-push (make test, vulture) passed.

…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.
Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 seed parameter to OptimizeParams with default fallback to DEFAULT_OPTIMIZATION_SEED = 0
  • Replaced all global random module calls with a local self._rng instance 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.

@Kohei-Wada Kohei-Wada merged commit c8d0f62 into main Jun 6, 2026
15 checks passed
@Kohei-Wada Kohei-Wada deleted the fix/optimizer-seed-963 branch June 6, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): genetic/monte_carlo optimizers are non-deterministic (no random seed)

1 participant