Spectre.Determinism (Spectre v0.3.3)

Copy Markdown View Source

Replayable port for decision-relevant clock, UUID, and random values.

capture/2 installs a process-local source while a runtime boundary is evaluated and returns the ordered samples beside the boundary result. Those samples can be placed in a portable receipt. Passing them back through :determinism_replay makes every sampled call fail closed on a kind, request, or ordering mismatch.

Monotonic time is intentionally sourceable but not recorded: it measures local durations and mailbox liveness rather than canonical decisions.

Summary

Functions

Installs capture for a long-lived OTP process such as a stream session.

Runs a boundary with deterministic capture or replay enabled.

Returns sourceable monotonic time without adding receipt evidence.

Returns receipt-recorded cryptographic random bytes.

Returns samples captured so far without ending the process-local port.

Returns a sourceable, receipt-recorded wall-clock value.

Types

monotonic_time_unit()

@type monotonic_time_unit() :: System.time_unit() | :native

sample()

@type sample() :: %{
  sequence: pos_integer(),
  kind: atom(),
  request: map(),
  value: term()
}

source()

@type source() :: module() | {module(), keyword()} | nil

Functions

begin_capture(opts)

@spec begin_capture(keyword()) :: :ok

Installs capture for a long-lived OTP process such as a stream session.

capture(opts, callback)

@spec capture(
  keyword(),
  (-> result)
) :: {result, [sample()]}
when result: term()

Runs a boundary with deterministic capture or replay enabled.

monotonic_time(unit \\ :native)

@spec monotonic_time(monotonic_time_unit()) :: integer()

Returns sourceable monotonic time without adding receipt evidence.

random_bytes(count)

@spec random_bytes(non_neg_integer()) :: binary()

Returns receipt-recorded cryptographic random bytes.

samples()

@spec samples() :: [sample()]

Returns samples captured so far without ending the process-local port.

system_time(unit \\ :millisecond)

@spec system_time(System.time_unit()) :: integer()

Returns a sourceable, receipt-recorded wall-clock value.