Spectre.GAM.Domain.Transaction (Spectre v0.4.0)

Copy Markdown View Source

Durable transaction boundary shared by Domain command workflows.

It performs one exact append, classifies an ambiguous result and advances the disposable projection only from a confirmed durable batch. Conflicts resume from the verified prefix; full replay remains the cold-start recovery path. Conflict policy remains with the calling workflow; this module never replies to callers, schedules work or grants a capability.

Missing derived Duties are repaired through the same append/recovery path so every workflow observes an equivalent governed prefix.

A physical batch is not a new authority boundary. This workflow changes only the supplied logical Domain; sharing a Store or supervisor never merges the identities, Mandates or obligations of independently governed participants.

Summary

Functions

Appends one exact batch and returns the confirmed, Duty-complete projection.

Checks that no derived Duty is waiting to be durably materialized.

Obtains an opaque operational identifier from the configured source.

Recovers and verifies the durable projection without adding repair events.

Recovers verified state and completes any missing derived-Duty batch.

Materializes every Duty required by the current prefix, retrying CAS conflicts.

Reads trusted host time while containing adapter failures.

Returns monotonic ledger time relative to the recovered prefix.

Checks content references carried by a list of canonical event envelopes.

Functions

append_exact(state, batch_id, payloads, recorded_at)

@spec append_exact(
  Spectre.GAM.Domain.Sequencer.State.t(),
  String.t(),
  [map()],
  non_neg_integer()
) :: {:ok, Spectre.GAM.GovernedAct.State.t()} | :conflict | {:error, term()}

Appends one exact batch and returns the confirmed, Duty-complete projection.

Preparation is pure; only the store acknowledgement/recovery establishes durability. :conflict returns control to the command's CAS policy. Failure after a write does not prove that the write was absent, so it remains an error rather than a fabricated previous state or permission to dispatch. This function never mints a Grant or calls an executor.

duties_materialized(projection, now)

@spec duties_materialized(Spectre.GAM.GovernedAct.State.t(), non_neg_integer()) ::
  :ok | {:error, term()}

Checks that no derived Duty is waiting to be durably materialized.

operational_id(state)

@spec operational_id(Spectre.GAM.Domain.Sequencer.State.t()) ::
  {:ok, String.t()} | {:error, term()}

Obtains an opaque operational identifier from the configured source.

recover_verified(state)

@spec recover_verified(Spectre.GAM.Domain.Sequencer.State.t()) ::
  {:ok, Spectre.GAM.GovernedAct.State.t()} | {:error, term()}

Recovers and verifies the durable projection without adding repair events.

recover_with_repair(state)

@spec recover_with_repair(Spectre.GAM.Domain.Sequencer.State.t()) ::
  {:ok, Spectre.GAM.GovernedAct.State.t()} | {:error, term()}

Recovers verified state and completes any missing derived-Duty batch.

repair_missing_duties(state)

@spec repair_missing_duties(Spectre.GAM.Domain.Sequencer.State.t()) ::
  {:ok, Spectre.GAM.GovernedAct.State.t()} | {:error, term()}

Materializes every Duty required by the current prefix, retrying CAS conflicts.

trusted_now(clock)

@spec trusted_now(module()) :: {:ok, non_neg_integer()} | {:error, term()}

Reads trusted host time while containing adapter failures.

trusted_recorded_at(state)

@spec trusted_recorded_at(Spectre.GAM.Domain.Sequencer.State.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}

Returns monotonic ledger time relative to the recovered prefix.

verify_payload_references(payload_store, payloads)

@spec verify_payload_references(term(), [map()]) :: :ok | {:error, term()}

Checks content references carried by a list of canonical event envelopes.