Undo one succeeded forward step. next_idx is the index for the
recovery row this step writes; it moves on whenever a row was
attempted, and stays put for a step whose command cannot be read.
Resume any unresolved sagas left over from a prior srv-process run.
Returns the number of sagas the recovery layer touched (compensated
or marked failed_compensation).
Map a forward Command to its compensating inverse, given the
recorded step row (which carries the forward commandโs emitted
events in output_json, useful for Create* โ extract-new-id โ
Delete*).
Dispatch a recovery-time compensating command + apply its events
to mstore. Mirrors SagaCtx::compensate but standalone (no live
saga to attach to). Returns the emitted events on success, the
reducerโs error message on rejection.
The inverse ran: record it, then mark the ORIGINAL forward step
compensated so a second crash-recovery startup doesnโt re-replay
its inverse. Idempotent: the UPDATE only fires on rows currently
in succeeded state.
A succeeded forward step with no derivable inverse is a failure to
compensate, not a no-op: the side effect remains on disk while the
saga lifecycle would otherwise be marked compensated, hiding
unresolved state from operators (and from --diag sagas, which
keys on terminal state). Log a recovery row with state failed
for visibility and return the error so the saga ends in
failed_compensation.
Compensate a single unresolved saga. Walks succeeded steps in
reverse, dispatches the inverse of each through the reducer, and
marks the saga compensated on success.
A pending step started but never reached succeeded, failed or
compensated: usually a crash between dispatch and finish_step,
after the reducer and the mstore apply already committed. Such a
saga cannot safely be marked compensated, because side effects
may still be applied; it goes to failed_compensation for operator
review, with the pending step and forward state left in the log.
No forward state to undo and no pending steps: the saga reached
start_saga but either crashed before any step succeeded, or every
step failed cleanly. Mark it compensated to clear it from the
unresolved set.