Chapter 14 — Determinism & Data Quality¶
14.1 — Chapter summary¶
⚙ Processes: the
checkerstep (the data-quality validation pass) and the golden-fixture harness (files/scripts/golden_fixture.py— the byte-identical replay verification tool). Both are cross-cutting: they validate every other point's outputs.All PIPE_ outputs (Points 3–7) → checker step data-quality rules (freshness, consistency, row counts, hash checks) → golden-fixture harness snapshot → re-run → diff (byte-identical gate) → PIPE_series_hashes + PIPE_backtest_fingerprints + the diff report
The one-sentence model: determinism means the same inputs + the same pinned planning date produce the byte-identical outputs — the golden-fixture harness enforces it, the checker step validates the data quality, and the guards (pipeline_id fail-loud, the no-wall-clock discipline, approved-archive protection) prevent the common drift sources.
14.2 — The planning-date discipline (the no-wall-clock contract)¶
All business logic uses planning_today() / planning_monday() — never
date.today(). Enforced by the regression scanner:
| Test | What it does |
|---|---|
test_no_wall_clock.py |
Scans every business file for date.today(), naive datetime.now(), SQL CURRENT_DATE, CH now()/today() — and fails |
| The resolution chain | REPLAY_PLANNING_DATE env → scenario.planning_date per pipeline → global default → UTC today (last resort only) |
| What counts as business logic | Archive dates, forecast horizons, allocation anchors, freeze timestamps, MEIO time slices — anything affecting data correctness or partition routing |
| What does NOT | Log timestamps, performance timing, cache TTL, file naming |
14.3 — The golden-fixture harness¶
⚙ Process:
python files/scripts/golden_fixture.py <command>— snapshot/reset-capacity/run/diff. The gate is byte-identical diff.
working recipe:
reset-capacity (zero the used_qty self-reference)
run (--steps indirect-demand,netting,meio,supply,allocation --env MEIO_MC_SEED=42)
snapshot (canonical full-precision TSVs, sorted, run_id normalized)
diff (code version A vs B — byte-identical or explain the delta)
| Command | What it does |
|---|---|
snapshot --out <dir> |
Exports all PIPE_ outputs for (pipeline, latest archive) into canonical TSVs — sorted rows, full precision, run_id normalized |
reset-capacity |
Zeros PIPE_supply_capacity.used_qty — the documented self-referential input that would otherwise alternate between runs |
run |
Re-runs the specified steps with the pinned planning date + seed |
diff <dir1> <dir2> |
The byte-identical gate — any difference is a behavioral change that must be explained |
Determinism sources enforced: Rust extensions rebuilt (stale .pyd shadow
imports), MEIO_MC_SEED env var, per-(item,site) seeded np.random.default_rng,
order IDs renumbered sequentially, BTreeMap ordered iteration everywhere, the netting archive
pinning, the forecast supply_plan archive-pinned reads.
Re-baselining after the supply planner default changed (18 Nov 2026)
The MRP supply engine now plans on the departure clock by default (7.11), so the next supply run of
every MRP scenario differs from the one before it. Golden snapshots taken before the change must be
re-baselined once per tenant (snapshot after a run with the new default). To reproduce a legacy
plan exactly, set the scenario's Lane Timing to Arrival clock (legacy). The read-only harness
python files/scripts/supply_dry_run.py --db <tenant> --pipeline-id N --compare plans both clocks
without writing anything (every write is blocked and counted) and checks each mode twice for
byte-identical output with an input fingerprint.
14.4 — The guards (fail-loud, not fail-safe)¶
| Guard | Meaning |
|---|---|
require_pipeline_id() |
Prevents runners from defaulting to pipeline ID 0 or 1; missing IDs fail loudly at entry. |
| Cascade delete (4.4) | Deleting a pipeline wipes all its data; deleting a referenced scenario is blocked. |
| Approved-archive protection | Buckets with an active result approval are never touched by cleanup or partition drops. |
| Stale-extension guards | V4 MEIO without the rebuilt Rust extension aborts loudly instead of silently using serde defaults. |
| Lane-timing guards | The default supply planner (the departure clock, 7.11) refuses a sub-weekly planning ladder, a horizon other than 52 weeks, a TRANSFER cycle and a stale supply extension before planning anything; the LP solver refuses an explicit departure_clock. Each message names the cause and the remedy. |
| The no-fallbacks doctrine | Enforces one correct code path; there is no silent try-another-thing behavior. |
14.T — Step-by-step test walkthrough¶
Determinism verification (CLI-level).
| # | Where to look / what to click | You should see |
|---|---|---|
| 1 | python files/scripts/golden_fixture.py snapshot --out dirA |
canonical TSVs of every PIPE_ table for (pipeline, latest archive) |
| 2 | reset-capacity → run --steps indirect-demand,netting,meio,supply,allocation --env MEIO_MC_SEED=42 → snapshot --out dirB |
the pinned-seed re-run |
| 3 | diff dirA dirB |
byte-identical — or every delta explained |
| 4 | Call any business endpoint without pipeline_id | HTTP 400 with the guard message (fail-loud) |
| 5 | Pin the planning date → run a step | the archive bucket lands on the pinned Monday, never the wall clock |