Spectre.GAM.Duty.Derive (Spectre v0.4.0)

Copy Markdown View Source

Pure composition of normative Duty causes from canonical governed facts.

A Duty does not depend on a best-effort opening append having succeeded. Each cause family recomputes stable causes from the replayed ledger, allowing recovery to retain containment and retry materialization idempotently.

This module is the public facade: dedicated modules derive Outcome, disputed-Evidence, Scope-promise, erasure-verifiability, and application marker causes. Spectre.GAM.Duty.Derive.Facts supplies their shared typed prefix view; this module deduplicates causes and converts them into Duty attributes.

Summary

Functions

Returns the stable identity of a derived cause.

Converts a cause into the exact attributes accepted by Spectre.GAM.Duty.new/1.

Returns derived causes which have no durable Duty record yet.

Derives the canonical built-in Duty cause for an ambiguous or contradicted Outcome.

Rechecks one cause against the complete verified prefix.

Returns every distinct Duty cause implied by replayed state at trusted time. Existing Duty records do not erase their cause, so the result remains useful to an auditor. Use missing_openings/2 for recovery materialization.

Types

cause()

@type cause() :: %{
  :cause_key => term(),
  :cause_class => atom() | String.t(),
  :causal_refs => map(),
  optional(atom()) => term()
}

Functions

cause_key(cause)

@spec cause_key(cause() | map()) :: term()

Returns the stable identity of a derived cause.

materialization_attrs(cause, fallback_opened_at)

@spec materialization_attrs(cause(), integer()) :: map()

Converts a cause into the exact attributes accepted by Spectre.GAM.Duty.new/1.

The cause's :required_at becomes :opened_at; the explicit time is only a fallback for an external cause without a canonical timestamp. A delayed append therefore cannot pretend that the historical gap started later.

missing_openings(state, time)

@spec missing_openings(Spectre.GAM.GovernedAct.State.t(), integer()) :: [cause()]

Returns derived causes which have no durable Duty record yet.

Both open and disposed records count as materialized. If an opening append was lost or ambiguous, its key is absent and the same cause is returned again.

outcome_cause(act, attempt, outcome, constitution, recorded_at)

@spec outcome_cause(
  Spectre.GAM.Act.t(),
  Spectre.GAM.Attempt.t(),
  Spectre.GAM.Outcome.t(),
  map(),
  integer()
) :: {:ok, cause()} | {:error, term()}

Derives the canonical built-in Duty cause for an ambiguous or contradicted Outcome.

Both live observation and ledger recovery use this constructor. The cause time is the Outcome's trusted observation time, so delayed materialization cannot rewrite when the Duty became required.

required_cause(state, key, time)

@spec required_cause(Spectre.GAM.GovernedAct.State.t(), term(), integer()) ::
  cause() | nil

Rechecks one cause against the complete verified prefix.

Only the causal sources are selected; proof, counterproof and historical dependencies remain available to the same constructors used by the exhaustive derivation. Existing Duties and the pending frontier are not proof of a cause. In particular, dispute lanes must run together: they merge evidence and choose one canonical cause per Act and counterproof.

required_duties(state, time)

@spec required_duties(Spectre.GAM.GovernedAct.State.t(), integer()) :: [cause()]

Returns every distinct Duty cause implied by replayed state at trusted time. Existing Duty records do not erase their cause, so the result remains useful to an auditor. Use missing_openings/2 for recovery materialization.