3.9 KiB
3.9 KiB
Story 7.3: traceability-metadata
Status: review
Story
As a researcher (Robert), I want complete traceability metadata, so that simulations are reproducible.
Acceptance Criteria
- Given a simulation result When accessing metadata Then it includes
solver_version,fluid_backend_version, andinput_hash(SHA-256). - Given a simulation result When checking the
input_hashThen the SHA-256 uniquely identifies the input configuration (System components, topology, and fluid configurations). - Given a simulation result When extracting metadata Then the metadata is available in structured JSON format.
Tasks / Subtasks
- Task 1: Add Dependency and Define Metadata Structs (AC: 1, 3)
- Add
sha2crate to the solver dependencies for SHA-256 hashing. - Define a
SimulationMetadatastruct withsolver_version,fluid_backend_version, andinput_hash. - Derive
SerializeandDeserializeusingserdefor theSimulationMetadatastruct.
- Add
- Task 2: Implement Input Hashing (AC: 2)
- Implement a method on
Systemto generate a canonical byte representation of its configuration (components, parameters, topology). - Compute the SHA-256 hash of this representation to produce the
input_hash.
- Implement a method on
- Task 3: Expose Metadata in Simulation Results (AC: 1)
- Update
ConvergedState(or similar solver output) to includeSimulationMetadata. - Ensure the metadata is populated during the
solveprocess tracking crate version constants.
- Update
- Task 4: Unit and Integration Testing (AC: 1, 2, 3)
- Write unit tests to verify that identical
Systeminputs produce the exact sameinput_hash. - Write unit tests to verify that different
Systeminputs produce differentinput_hashvalues. - Write an integration test to ensure
SimulationMetadataaccurately reflects the solver state and input hash when requested.s
- Write unit tests to verify that identical
Dev Notes
- Architecture Patterns & Constraints:
- Determinism: The hash generated must be absolutely deterministic across platforms (x86, ARM, WASM). Ensure the canonical byte representation is platform-independent (e.g., sorting map keys, explicit endianness for floats if serialized to bytes before hashing).
- JSON Serialization: Use
serde_jsonto output structured JSON representations.
- Source Tree Components to Touch:
crates/solver/Cargo.toml(Addsha2andserde_jsonif needed)crates/solver/src/system.rs(Input hashing logic)crates/solver/src/lib.rs(Updated result structures)
- Testing Standards:
- Test deterministic hashing. Ensure exact input matching generates exactly the same hash.
Project Structure Notes
- Alignment with unified project structure: The changes should mainly reside in the
solvercrate, adding metadata to the simulation output.
References
- [Source: _bmad-output/planning-artifacts/epics.md] - Epic 7, Story 7.3 Requirements & FR37
- [Source: _bmad-output/planning-artifacts/architecture.md] - Error Handling & Serialization
Dev Agent Record
Agent Model Used
BMad Create Story Workflow (Claude 3.5 Sonnet / Antigravity)
Debug Log References
Completion Notes List
- Evaluated
System::generate_canonical_bytesto form a deterministic state snapshot. - Hashed the snapshot with
sha2::Sha256to createinput_hash. - Embedded
SimulationMetadatainsideConvergedStateresults. - Added deterministic hashing tests and integration test.
Change Log
- 2026-02-22: Implemented traceability metadata for solver outputs (Tasks 1-4).
File List
_bmad-output/implementation-artifacts/7-3-traceability-metadata.mdcrates/solver/Cargo.tomlcrates/solver/src/metadata.rscrates/solver/src/system.rscrates/solver/src/solver.rscrates/solver/src/lib.rscrates/components/src/lib.rscrates/solver/tests/traceability.rs