/** * Watermark-aware hash-chain verification for the event log. * * Split out from `event-log.ts` so the (intricate) concurrent-compaction retry * logic lives on its own. Depends only on the shared primitives in * `event-log-shared.ts` and the watermark reader in `event-log-compaction.ts`, * so there is no import cycle with `event-log.ts`. * * @module core/event-log-verify */ import type { Storage } from '../storage/interface.ts'; /** * Result of {@link verifyEventLog}. The `indeterminate` variant keeps * `valid: false` so existing `if (result.valid)` callers never get a false * positive, but signals that verification could not complete because the log * was being compacted concurrently — it is NOT a corruption report (it carries * no `firstInvalidSequence`). */ export type VerifyResult = { valid: true; } | { valid: false; firstInvalidSequence: number; } | { valid: false; indeterminate: true; reason: 'concurrent-compaction'; }; /** * Walk a workflow's event log and verify hash-chain integrity. * * When event-log compaction has truncated the early records, a * {@link EventLogWatermark} at `ev:{id}:watermark` marks where the surviving * chain begins; verification seeds its walk from the watermark's `prevHash` * instead of {@link GENESIS_HASH} so a compacted log does not look broken. * * A compaction can commit concurrently (before or during the scan); to avoid * reporting a *false* chain break, the walk re-reads the watermark on any break * and, only when the watermark has ACTUALLY ADVANCED past the snapshot the * failing pass used, restarts — up to a small bound. A stable break is genuine * corruption. If it never stabilizes, the result is flagged `indeterminate`. * * Corruption cases worth calling out: a watermark pointing at a first surviving * record that is no longer present is reported at `watermark.sequence`; a tail * record lost while the head still points past it is reported at the missing * sequence (the tail is cross-checked against `ev:{id}:head`); and a compacted * log whose watermark was removed (e.g. a code rollback) is reported broken at * the expected genesis sequence rather than silently passing — compaction is * one-way. */ export declare function verifyEventLog(storage: Storage, workflowId: string): Promise;