# `ExGAM.Domain.Recovery`
[🔗](https://github.com/elchemista/ex_gam/blob/0.1.0/lib/ex_gam/domain/recovery.ex#L1)

Conservative recovery helpers for a governed Domain.

Recovery loads the canonical ledger, verifies its complete snapshot, and
rebuilds a disposable `ExGAM.Domain.Projection`. It never mints a Grant or
releases executor capability.

An ambiguous append is classified by recomputing the logical batch identity
and consulting the Store's durable identity index. `:not_committed` means
only that the identity was absent at that lookup instant; it is not an
eternal proof that the append can never appear. A sequencer must reload and
retry the same identity conservatively, and must not emit a Grant from that
result alone.

# `append_classification`

```elixir
@type append_classification() ::
  {:committed, ExGAM.Ledger.batch_info()} | :not_committed
```

# `payload_check`

```elixir
@type payload_check() ::
  (ExGAM.Domain.Projection.t(), [String.t()] -&gt; :ok | {:error, term()}) | nil
```

# `classify_ambiguous`

```elixir
@spec classify_ambiguous(
  ExGAM.Ledger.Store.config(),
  ExGAM.Ledger.domain_ref(),
  ExGAM.Ledger.batch_id(),
  [map()],
  non_neg_integer(),
  keyword()
) :: {:ok, append_classification()} | {:error, term()}
```

Classifies an ambiguous append using its stable batch identity.

A matching durable lookup returns `{:ok, {:committed, info}}`. An absent
lookup returns `{:ok, :not_committed}` with the temporal limitation described
in the module documentation. Any mismatched identity or revision metadata is
rejected rather than guessed.

# `confirm_append`

```elixir
@spec confirm_append(
  ExGAM.Ledger.Store.config(),
  ExGAM.Domain.Projection.t(),
  String.t(),
  [map()],
  non_neg_integer(),
  keyword(),
  payload_check()
) :: {:ok, ExGAM.Domain.Projection.t()} | {:error, term()}
```

Advances a verified prefix only after confirming the exact persisted batch.

The Store's durable index must match the reconstructed chain, including its
predecessor and recording time through the head digest. This uses the same
adapter trust boundary as append/ambiguity recovery; it does not prove that
the host's storage is tamper-proof. Startup and independent audit still verify
the full history, rather than trusting this disposable in-memory prefix.

An unavailable or inconsistent index falls back to a verified ledger read.
In particular, an identical retry can have a different requested timestamp:
the original committed timestamp wins and must never be rewritten.

# `recover`

```elixir
@spec recover(ExGAM.Ledger.Store.config(), ExGAM.Ledger.domain_ref(), keyword()) ::
  :not_found | {:ok, ExGAM.Domain.Projection.t()} | {:error, term()}
```

Loads, verifies, and replays one Domain ledger without producing capabilities.

# `recover`

```elixir
@spec recover(
  ExGAM.Ledger.Store.config(),
  ExGAM.Ledger.domain_ref(),
  map(),
  keyword()
) ::
  :not_found | {:ok, ExGAM.Domain.Projection.t()} | {:error, term()}
```

Loads and replays a Domain against the exact Constitution pinned by Genesis.

# `resume`

```elixir
@spec resume(
  ExGAM.Ledger.Store.config(),
  ExGAM.Domain.Projection.t(),
  keyword(),
  payload_check()
) ::
  :not_found | {:ok, ExGAM.Domain.Projection.t()} | {:error, term()}
```

Resumes an in-memory verified prefix using only the newly committed batches.

A changed predecessor or a head behind the cursor is an error, never a reason
to silently replace the trusted prefix. Cold startup still uses `recover/4`.

An optional payload check receives the final verified projection and the
distinct payload references introduced or affected by the recovered suffix. It cannot
replace the projection. Checking at the final head matters when that suffix
also contains a legitimate erasure of one of those payloads.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
