Spectre.Operation.Runtime (Spectre v0.3.0)

Copy Markdown View Source

Pure transition engine for Work, Vigil and external operational controllers.

Slow execution is deliberately absent from this module. It prepares fenced attempts and reduces their results; Spectre.Instance owns serialization, canonical commit, supervision and scheduling.

The engine is split by concern: Runtime.Contract enforces the code-owned definition, Runtime.Transitions builds loop-state transitions, Runtime.Results reduces Runner results, Runtime.Controls handles the control plane and Runtime.Recovery validates restored checkpoints. This module keeps loop start, attempt preparation, trigger delivery and the public entry points.

Summary

Functions

Advances a pending pause/update/resume sequence once the loop is quiescent.

Applies one correlated Runner result and leaves completion evaluation for the next commit.

Evaluates deterministic completion only after the result transition was committed.

Prepares the next registered operation from committed loop state.

Recovers portable loop state after an Agent restart and invalidates the old epoch.

Commits a durable control request without executing it reentrantly.

Reduces an unexpected DOWN for the currently fenced Runner.

Starts a data-only Work on the same fenced operational runtime.

Applies a correlated timer, event or human trigger to a waiting loop.

Validates a restored loop and its control plane against the current code-owned definition.

Types

env()

@type env() :: map()

event_spec()

@type event_spec() :: %{:type => atom(), optional(:payload) => term()}

pid_action()

Functions

advance_control(loop, control, env)

Advances a pending pause/update/resume sequence once the loop is quiescent.

apply_result(loop, control, result, env)

Applies one correlated Runner result and leaves completion evaluation for the next commit.

evaluate(loop, control, env)

Evaluates deterministic completion only after the result transition was committed.

prepare(loop, control, env)

Prepares the next registered operation from committed loop state.

recover(loop, control, env)

Recovers portable loop state after an Agent restart and invalidates the old epoch.

request_control(loop, control, command, env)

Commits a durable control request without executing it reentrantly.

runner_down(loop, control, spec, reason, env)

Reduces an unexpected DOWN for the currently fenced Runner.

start(kind, controller, input, opts, env)

start_program(program, input, opts, env)

@spec start_program(Spectre.Execution.Program.t(), term(), keyword(), env()) ::
  {:ok, Spectre.Operation.Loop.t(), Spectre.Operation.Control.t(),
   [event_spec()]}
  | {:error, term()}

Starts a data-only Work on the same fenced operational runtime.

trigger(loop, control, trigger, opts, env)

Applies a correlated timer, event or human trigger to a waiting loop.

validate_checkpoint(loop, control, env)

@spec validate_checkpoint(
  Spectre.Operation.Loop.t(),
  Spectre.Operation.Control.t(),
  env()
) ::
  :ok | {:error, term()}

Validates a restored loop and its control plane against the current code-owned definition.