MorphIQ Labs

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 sts_t and an input event ete_t, the transition function produces the next state and a list of emitted commands:

(st+1,  ct)  =  f(st,  et)(s_{t+1},\; c_t) \;=\; f(s_t,\; e_t)

The contract is that ff is a pure function. No clock reads, no RNG without a seeded source, no filesystem, no allocation-order-dependent iteration. Given the same (st,et)(s_t, e_t), it must produce the same (st+1,ct)(s_{t+1}, c_t) 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 ff is pure, then the entire run is a fold over the event log:

sn  =  (fen−1∘fen−2∘⋯∘fe0)(s0)s_n \;=\; \bigl(f_{e_{n-1}} \circ f_{e_{n-2}} \circ \cdots \circ f_{e_0}\bigr)(s_0)

and the final state sns_n 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:

replay(log)  =!  snrecorded\text{replay}(\text{log}) \;\overset{!}{=}\; s_n^{\text{recorded}}

State is content-addressed — we hash the serialized state sns_n — 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 jj where

sj(1)≠sj(2)s_j^{(1)} \neq s_j^{(2)}

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.

CheckChecksCost
Replay equalityDrift between record and replay pathsO(events)
Cross-runGlobal state, iteration-order dependenceO(events)
Property fuzzingSerialization + accumulation consistencyO(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.