Skip to main content

Module recovery

Module recovery 

Source

Functionsยง

append_recovery_row ๐Ÿ”’
Write one recovery row; a failed write is logged and recovery goes on.
compensate_step ๐Ÿ”’
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.
compensate_unresolved
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).
derive_inverse_command
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_inverse ๐Ÿ”’
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.
extract_block_id_from_output ๐Ÿ”’
extract_tab_id_from_output ๐Ÿ”’
extract_workspace_id_from_output ๐Ÿ”’
Pull the first WorkspaceCreated.workspace_id from a stepโ€™s emitted events. Used to derive CreateWorkspaceโ€™s inverse.
finish_recovery ๐Ÿ”’
The sagaโ€™s last row: compensated when every inverse worked, an error (which the caller records as failed_compensation) otherwise.
record_inverse_applied ๐Ÿ”’
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.
record_no_inverse ๐Ÿ”’
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.
recover_saga ๐Ÿ”’
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.
reject_pending_steps ๐Ÿ”’
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.
terminate_with_nothing_to_undo ๐Ÿ”’
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.