# `Mob.PostMortem.Registry`
[🔗](https://github.com/genericjam/mob/blob/master/lib/mob/post_mortem/registry.ex#L1)

A one-shot record of post-mortem artifacts we have already emitted a
capsule for.

## What it is

A public ETS set keyed by the artifact's `sha256:...` id. `emit_once/2` runs
an emit only for an id not recorded yet, and records it atomically first
(`:ets.insert_new/2`), so two concurrent sweeps on the same dump cannot both
emit. If the emit then fails, the id is forgotten again, so the next sweep
retries it rather than treating a report that never went out as delivered.

Not persistent across BEAM restarts. That is deliberate: a fresh BEAM
should re-emit the dumps it finds on disk, because the recipient of
those capsules (the defect bus + subscribers) is also fresh. Persisting
the seen-set would silence the exact restart-and-look-again pattern
that recovers a defect an earlier BEAM's bus never got to observe.

What does persist is `Mob.PostMortem.Journal`: entries the OS hands over only
once (MetricKit, `ApplicationExitInfo`) are kept there until observed, and a
fresh BEAM re-emits them through this registry like a dump still on disk.

The table is owned by a `Mob.Diag.Store` owner, and the write path never
goes through a GenServer mailbox.

# `count`

```elixir
@spec count() :: non_neg_integer()
```

How many artifact ids are currently recorded.

# `emit_once`

```elixir
@spec emit_once(String.t(), (-&gt; result)) :: [result] when result: term()
```

Run `emit` for `id` unless it was already recorded, and return its result in
a list (empty when skipped or failed).

A failing `emit` is counted as `lost` in `Mob.Diag.health/0` and un-records
`id`, so an artifact still on disk is retried by the next sweep. Never raises.

# `forget`

```elixir
@spec forget(String.t()) :: :ok
```

Forget `id`, so a later sweep emits it again.

# `mark_seen`

```elixir
@spec mark_seen(String.t()) :: boolean()
```

Record `id` if it is not already present.

Returns `true` when this call is the first observation (so the caller
should emit its capsule), `false` when another sweep already recorded it.
If the record itself fails, returns `true`: a duplicate report is better
than a lost one.

# `seen?`

```elixir
@spec seen?(String.t()) :: boolean()
```

True when `id` has been recorded by any prior `mark_seen/1`.

---

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