Skip to content

[T-024] Canonical JSON and scenario_hash (golden hashes) #37

Closed

Description

@CodewithJha

Task T-024 · Milestone M2 — Scenario + kinematic2d · Size XS · Priority P0 · Epic #2

Implements FR-SCN-006 · NFR-REP-001

Branch feat/t-024-canonical-json-and-scenario-hash — one task = one branch = one PR (doc 32 §6)

Summary

Implement canonical_json(obj) -> bytes (sorted keys, floats with 12 significant digits) and scenario_hash(space_version, values) = sha256(canonical_json(...))[:16]; wire ScenarioSpace.make_scenario.

Context / motivation

Hashes identify scenarios across runs, replays, regression files and bundles; they must be stable across processes and platforms.

Scope

In scope

  • scenario/hashing.py (or inside materialize.py per doc 05 — choose hashing.py and update doc 05 §3).
  • make_scenario(values) validates bounds/constraints, normalises types, computes hash, returns frozen Scenario.

Implementation guidance

  • Float formatting: format(x, '.12g') then normalise -0 → 0; ints stay ints; NaN/inf rejected.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Acceptance criteria

  • Golden hashes for 5 fixed scenarios committed and identical across OS matrix.
  • Any value change → different hash; key order irrelevant.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/unit/scenario/test_hashing.py with golden values; Hypothesis test for order-independence.

Dependencies

Blocked by: #34 (T-021)

Blocks: #39 (T-026)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/scenario/hashing.py
  • backend/tests/unit/scenario/test_hashing.py

Parallel with T-023/T-025.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-024 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 05 §3 · doc 02 §3.1 · doc 18 §4.1

Requirements: FR-SCN-006 · NFR-REP-001 (traceability: doc 28)

External:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:scenarioScenario space, sampling, scenario filesgood first issueGood for newcomersmilestone:M2M2 — Scenario + kinematic2dpriority:P0Critical path / blocks otherssize:XS< 2 hourstaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions