MorphIQ Labs ·
Determinism as a Correctness Contract
How Crucible makes reproducibility a testable contract through explicit inputs, shared transition logic and event-sourced replay.
Reproducibility starts with explicit inputs. Event order, time, random seeds and numerical evaluation order all contribute to a trading decision. A runtime can make that decision inspectable by recording its inputs and controlling how state transitions consume them.
Crucible treats determinism as a contract: shared transition logic, explicit effects and repeatable checks connect historical replay with runtime behavior.
The contract
Crucible's core is a state machine. Given a strategy state and an input event , the transition function produces the next state and a list of emitted commands:
The contract is that is a pure function. No clock reads, no RNG without a seeded source, no filesystem, no allocation-order-dependent iteration. Given the same , it must produce the same within the declared implementation, configuration and numerical environment. Equivalence across compilers or platforms requires its own evidence.
That single constraint buys an enormous amount. If is pure, then the entire run is a fold over the event log:
and the final state is a deterministic function of the seed state and the event sequence alone. Replay is not a feature bolted on afterwards. It is the definition of the system.
Event sourcing makes the inputs inspectable
Folding the ordered events reconstructs state from a known seed. The journal therefore provides a concrete record for comparing a session with its replay.
Shared logic makes comparisons meaningful. It does not by itself establish that simulated fills, live execution or external data availability are equivalent. Those boundaries retain their own contracts and qualification.
Making it testable
Three complementary checks make the determinism contract inspectable.
Replay equality
Every recorded session can be replayed. The check is exact:
State is content-addressed — we hash the serialized state — so the assertion is a single 32-byte comparison, not a structural diff. A mismatch fails the build.
Cross-run divergence
The same log is folded twice in the same process and the intermediate states are compared step by step. The first index where
is reported directly. Because the two runs share a process, a divergence here points squarely at hidden global state or iteration-order dependence, not at a serialization round-trip.
Property-based fuzzing
A generator produces random-but-valid event sequences. For each, Crucible asserts that folding the sequence, serializing, deserializing, and folding again yields identical state. These checks exercise command ordering, serialization and floating-point accumulation order across a wider range of valid inputs.
| Check | Checks | Cost |
|---|---|---|
| Replay equality | Drift between record and replay paths | O(events) |
| Cross-run | Global state, iteration-order dependence | O(events) |
| Property fuzzing | Serialization + accumulation consistency | O(cases) |
Measure the cost of the contract
Explicit clocks, stable iteration and fixed reduction order are implementation choices with measurable costs. Evaluate them on the workloads the runtime serves, keeping reproducibility requirements alongside latency and throughput. A performance result needs its build, host and workload recorded with it.
Composition keeps the boundaries explicit
Composed replay also requires component versions, input ordering and time semantics to remain explicit. With multiple strategies, command interleaving becomes another part of the contract. A deterministic reducer is the foundation; end-to-end qualification establishes which composed configurations preserve it.