Spectre.GAM.Domain.Recovery.Policy behaviour (Spectre v0.4.0)

Copy Markdown View Source

Optional host checks and incident handling around verified Domain recovery.

Configure recovery_policy: {MyPolicy, options} when starting a Domain. check/2 receives only its identity and the recovered head, after canonical, semantic, Genesis and payload checks. A nil head means no ledger was found: the host can reject bootstrap of a Domain which must already exist.

The host may compare this information against an independently retained witness. A hash chain alone cannot detect a coherently rewritten history or rollback. Checking an older witness against a newer head requires verifying their relationship; merely comparing revision numbers is not sufficient. This callback does not make the host or database tamper-proof.

Optional failed/2 receives startup failures and fatal runtime incidents. Enqueue application-owned quarantine, backup recovery or operator review there. Its result cannot authorize work, replace a projection or suppress the original error. After repair, restart the Domain and run verification again. Never blindly retry an external effect whose Outcome remains ambiguous.

Callbacks run in isolated, monitored processes with recovery_timeout (default 5 seconds). Do not perform a long repair in the callback: arrange it in the application's supervision tree. Notifications are best effort, may be repeated on restart, and are not a durable incident log. Callback failure or timeout cannot turn a failed verification into success.

Managed GAM also supports optional recover/2: return :wait (the default), {:retry, milliseconds} or :memory. Retry re-verifies the existing Domain; memory starts a distinct RAM Domain, never replacing facts in the old one. The host chooses whether losing continuity is acceptable. See the Domain storage guide for AgentServer checkpoint and consent handling.

This is a recovery boundary, not continuous storage monitoring. A running Domain uses its verified prefix and checks new suffixes; it does not reread all historical bytes before every decision. Independent audits and external witness publication remain host responsibilities.

Summary

Functions

Dispatches a bounded incident notification without delaying a failing Domain.

Optional host lifecycle decision; it never replaces or authorizes GAM facts.

Types

config()

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

context()

@type context() :: %{domain_ref: String.t(), head: head() | nil}

head()

@type head() :: %{revision: non_neg_integer(), head_digest: String.t()}

incident()

@type incident() :: %{
  domain_ref: String.t(),
  phase: :startup | :runtime,
  reason: term(),
  last_verified: head() | nil
}

Callbacks

check(context, keyword)

@callback check(
  context(),
  keyword()
) :: :ok | {:error, term()}

failed(incident, keyword)

(optional)
@callback failed(
  incident(),
  keyword()
) :: term()

recover(incident, keyword)

(optional)
@callback recover(
  incident(),
  keyword()
) :: :wait | :memory | {:retry, non_neg_integer()}

Functions

notify_failed(policy, incident, timeout)

@spec notify_failed(config(), incident(), pos_integer()) :: :ok

Dispatches a bounded incident notification without delaying a failing Domain.

recover(policy, incident, timeout)

Optional host lifecycle decision; it never replaces or authorizes GAM facts.