# Audit a recording against its replay receipts

Contiguous receipt ordinals alone cannot establish that receipts correspond to a
particular source recording. An offline export investigation can recompute each
record from the source and its prior session:

```sh
moon run cli -- stream-to recording.ndjson receipts.ndjson
moon run cli -- stream-audit recording.ndjson receipts.ndjson
```

Only after both files reach EOF successfully does the command print one JSON
summary: decimal-string `verified`, `previousOrdinal`, `lastOrdinal`, `duplicates`,
and the final state summary. It opens regular UTF-8 input files read-only and
publishes no files. A missing/extra record, bad UTF-8, blank line, malformed JSON
or mismatch exits 2 without a partial success report. Records may use CRLF or
omit the final LF. Both files can exceed 4 MB; each record retains the usual
4 MB UTF-8 limit, chunked decoding and strict parser/state budgets.

For a continuation, supply the same trusted previous receipt used to create it:

```sh
moon run cli -- stream-audit remaining.ndjson next.ndjson last-record.json
```

The source must contain only the continuation. Without a seed, verification
starts with the default empty state and ordinal zero. A nonzero first ordinal
requires its correct prior session. Neither input prefix nor seed authenticity
is inferred. Empty paired streams are valid and leave the prior session intact.

The portable API is `ReplaySession.verify_record(source_line, receipt_json)`.
It recomputes the full expected result, validates the supplied receipt and
compares the ordinal, duplicate count, complete cumulative OTLP output, and
complete logical checkpoint. Untouched series, capacity, all four accumulation
kinds, Gauge pass-through and original metadata are included. JSON object key
order/whitespace is irrelevant; array order and attribute/value content matter.
The returned session is the recomputed one and owns its state; the old session
is reusable after failure. Mismatches identify `/records/N` and a component such
as `/request`, `/duplicates` or `/session/state`.

This verifies correspondence to the source, seed and current deterministic
implementation supplied to the auditor. It is not cryptographic authentication,
an independent accumulation oracle or evidence of downstream delivery. If both
source and receipts are replaced consistently, this audit cannot identify that.
The existing `stream-export` contract is unchanged and does not perform this
paired verification; audit explicitly before exporting when correspondence matters.

Run `moon run checks/stream.mbtx -- moon wasm` for full and continued replay,
missing/extra/reordered/changed receipts, malformed/blank/invalid UTF-8 records,
empty inputs and files above 4 MB. Portable unit tests also exercise all metric
kinds, retries, exact integers, untouched-state/capacity mismatches, metadata,
restore/verification round trips, detached ownership and ordinal overflow.
