Fief.Sim (Fief v0.1.0)

Copy Markdown View Source

Per-process hook registry for the determinism seams (implementation.md §10).

The sim seam module (Fief.Seam.Sim) is "real unless hooked": it consults this module and falls through to the real implementations when nothing is bound. Binding is per-process — a fief process joins a simulation by binding hooks in its own process, normally in one line at init via bind/1 with a sim context from Fief.Sim.Scheduler.context/3 (the instance-scoped wiring of build-order M2; Fief.Authority.Local's :sim_clock opt is the narrower clock-only variant).

Test machinery only; in prod builds the seams compile to the real modules and nothing here is consulted.

Summary

Functions

Bind all sim hooks from a sim context map (see Fief.Sim.Scheduler.context/3) — the one discipline line a fief process runs at init to join a simulation. Recognized keys: :clock, :tracer, :rand_seed, plus the transport identity (:scheduler + :sim_id + :node_id together); a missing key leaves that hook unbound (real behavior).

Bind a simulation clock to the calling process: a Fief.Sim.ManualClock server reference, or a {module, handle} provider as returned by Fief.Sim.Scheduler.clock/3.

Bind a checkpoint tracer (see Fief.Seam) to the calling process.

Bind the simulated transport identity to the calling process: {scheduler, sim_id, node_id} — the scheduler that deliveries post into, the scheduler's unique simulation id (name scoping), and this process's simulated node identity (name qualification). See Fief.Seam.Sim.

Reassemble the calling process's bound hooks into a context map bind/1 accepts — how a fief process hands its simulation membership to processes it starts itself (M6: Fief.Key.VnodeImpl captures the agent's context in init/2 and passes it to every Fief.Key.Server). Real-unless-hooked is preserved: capturing in an unhooked process returns %{}, and binding %{} binds nothing. (:rand_seed is not recapturable — a seed is consumed at bind time — and is deliberately absent.)

The calling process's bound simulation clock, or nil.

Bind a deterministic PRNG seed to the calling process.

The calling process's bound checkpoint tracer, or nil.

The calling process's bound transport identity, or nil.

Functions

bind(context)

@spec bind(map()) :: :ok

Bind all sim hooks from a sim context map (see Fief.Sim.Scheduler.context/3) — the one discipline line a fief process runs at init to join a simulation. Recognized keys: :clock, :tracer, :rand_seed, plus the transport identity (:scheduler + :sim_id + :node_id together); a missing key leaves that hook unbound (real behavior).

bind_clock(clock)

@spec bind_clock(GenServer.server() | {module(), term()}) :: :ok

Bind a simulation clock to the calling process: a Fief.Sim.ManualClock server reference, or a {module, handle} provider as returned by Fief.Sim.Scheduler.clock/3.

bind_tracer(tracer)

@spec bind_tracer(pid()) :: :ok

Bind a checkpoint tracer (see Fief.Seam) to the calling process.

bind_transport(transport)

@spec bind_transport({GenServer.server(), term(), term()}) :: :ok

Bind the simulated transport identity to the calling process: {scheduler, sim_id, node_id} — the scheduler that deliveries post into, the scheduler's unique simulation id (name scoping), and this process's simulated node identity (name qualification). See Fief.Seam.Sim.

capture()

@spec capture() :: map()

Reassemble the calling process's bound hooks into a context map bind/1 accepts — how a fief process hands its simulation membership to processes it starts itself (M6: Fief.Key.VnodeImpl captures the agent's context in init/2 and passes it to every Fief.Key.Server). Real-unless-hooked is preserved: capturing in an unhooked process returns %{}, and binding %{} binds nothing. (:rand_seed is not recapturable — a seed is consumed at bind time — and is deliberately absent.)

clock()

@spec clock() :: GenServer.server() | {module(), term()} | nil

The calling process's bound simulation clock, or nil.

seed_rand(seed)

@spec seed_rand(integer()) :: :ok

Bind a deterministic PRNG seed to the calling process.

tracer()

@spec tracer() :: pid() | nil

The calling process's bound checkpoint tracer, or nil.

transport()

@spec transport() :: {GenServer.server(), term(), term()} | nil

The calling process's bound transport identity, or nil.