verify

suspend fun <P> SagaJournal<P>.verify(runId: RunId, fromSeq: Long = 0, toSeq: Long = Long.MAX_VALUE, pageSize: Int = DEFAULT_VERIFY_PAGE_SIZE): JournalOutcome<VerifyResult>

Verifies the tamper-evident hash chain for runId over entries with seq in [fromSeq, toSeq].

For each entry in the range, the verifier:

  1. Re-encodes the stored entry to its canonical bytes (using the registered payload encoder).

  2. Recomputes SHA-256(canonical bytes).

  3. Compares the recomputed hash to the hash stored in the journal at append time (via HashStoringJournal.getStoredHash). A mismatch at seq N returns VerifyResult.Broken.

Fail-soft policy

This function never throws. All error conditions are returned as VerifyResult.Broken:

  • fromSeq < 0 or toSeq < fromSeqBroken(firstBadSeq = -1, expected = "valid range", actual = ...)

  • No encoder registered (hashing disabled / Hashing.None) → Broken(firstBadSeq = 0, expected = "<unsupported>", actual = "hashing disabled")

  • sagaExecutor not yet called for this journal → Broken(firstBadSeq = 0, expected = "no codec attached", actual = "call sagaExecutor before verify")

  • Malformed stored prevHash (not 64 lowercase hex chars) → Broken(seq, expected = "valid prevHash", actual = "<bad value>")

Pagination

pageSize entries are processed per page. When the range spans more than one page, VerifyResult.Incomplete is returned with the next start seq. Callers can cover the full chain with:

var result: VerifyResult = journal.verify(runId, 0, Long.MAX_VALUE)
while (result is VerifyResult.Incomplete) {
result = journal.verify(runId, result.resumeFromSeq, Long.MAX_VALUE)
}

Return

JournalOutcome.Ok wrapping a VerifyResult, or JournalOutcome.Err if the journal itself fails to return entries (storage error, not a tamper detection).

Parameters

runId

The saga run to verify.

fromSeq

Inclusive start of the seq range (default 0 = beginning of chain).

toSeq

Inclusive end of the seq range (default Long.MAX_VALUE = full chain).

pageSize

Maximum number of entries to read per SagaJournal.since call.