magicciv/.project/objectives/p1-09-determinism-gate.md
Natalie 24dd3e3f39 feat(@projects/@magic-civilization): add new objectives and units data
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-04-24 16:15:36 -07:00

2.5 KiB

id title priority status scope owner updated_at evidence
p1-09 Determinism gate — same seed produces byte-identical runs p1 done game1 testwright 2026-04-19
src/simulator/crates/mc-ecology/src/engine.rs
src/game/engine/src/autoloads/data_loader.gd
src/simulator/crates/mc-mapgen/tests/determinism.rs
src/simulator/crates/mc-mapgen/tests/_gen_golden.rs
src/game/engine/src/autoloads/game_state.gd

Summary

Determinism is foundational for save/load, replay, bug reproduction, and golden tests. Prior work fixed seed-ingestion (game_state.gd:113-115), migrated HashMap→BTreeMap in several crates, sorted DataLoader enumeration, and pathfinder tiebreakers. Testwright's T1 task landed mc-mapgen/tests/determinism.rs (389 lines) with PCG32 golden vector + seed-stable map generation, now running green in CI.

State as of 2026-04-17 PM: the Rust side of the gate is running. CI enforces cargo test --workspace on every push to main (Stage 1 of .forgejo/workflows/ci.yml), the apricot runner is registered + polling, and T1's determinism vector is green. Two remaining blockers, both tractable:

  1. HashMap iteration audit is no longer abstract. The T2 serde round-trip test (mc-turn/tests/serde_roundtrip.rs) concretely demonstrated that PlayerState.strategic_axes: HashMap<_> and TechState.progress: HashMap<_> produce non-deterministic save output across processes. Fix is HashMap → BTreeMap in mc-turn/src/game_state.rs, scoped to p0-12 (shipwright). The 3 currently-#[ignore]'d T2 tests will flip to passing the moment that change lands.
  2. GUT save/replay test + end-to-end byte-identical turn_stats diff are still both missing. The autoplay smoke stage is advisory right now because turn_stats.jsonl isn't landing reliably on fresh flatpak checkouts — fixing the sandbox path handling in tools/autoplay-batch.sh unblocks the turn_stats equality check.

Acceptance

  • cargo test --workspace green on apricot including mc-mapgen determinism tests (currently 3 fails).
  • Two runs of AUTO_PLAY_SEED=42 AUTO_PLAY_TURN_LIMIT=100 on apricot produce byte-identical turn_stats.jsonl.
  • GUT test exists that replays a saved game and asserts the resulting turn_stats matches the original.
  • CI (when p2-10 lands) blocks any PR that regresses these.
  • No HashMap iteration in any hot path in src/simulator/crates/; grep confirms BTreeMap/BTreeSet or sort-before-iterate.

Non-goals

  • Cross-platform byte-identical (floating point divergence on ARM vs x86 may remain; gate is same-platform).