SquidMesh.Runtime.Compensation (squid_mesh v0.1.0-alpha.6)

Copy Markdown View Source

Executes durable saga compensation for completed workflow steps.

Compensation is intentionally separate from normal failure routing. Forward retries and :error transitions decide whether the workflow can continue. Only after a run reaches terminal failure does the runtime dispatch a compensation job, which walks completed reversible steps in reverse completion order and records each callback result in the original step's recovery metadata.

Summary

Functions

Runs all pending compensation callbacks for a failed run.

Returns whether a failed run has any completed step with compensation pending.

Types

compensation_error()

@type compensation_error() :: {:compensation_failed, [map()]}

Functions

compensate_completed_steps(config, definition, run, failure)

@spec compensate_completed_steps(
  SquidMesh.Config.t(),
  SquidMesh.Workflow.Definition.t(),
  SquidMesh.Run.t(),
  map()
) :: :ok | {:error, compensation_error() | term()}

Runs all pending compensation callbacks for a failed run.

Completed steps are evaluated in reverse completion order. A successful callback stores :completed plus its output under recovery.compensation; a failed callback stores :failed plus the normalized error and returns a structured {:compensation_failed, failures} error after all eligible callbacks have been attempted.

compensation_available?(repo, definition, run_id)

@spec compensation_available?(
  module(),
  SquidMesh.Workflow.Definition.t(),
  Ecto.UUID.t()
) :: boolean()

Returns whether a failed run has any completed step with compensation pending.

The runtime uses this before enqueuing a compensation job so workflows without reversible completed work keep their historical worker-count and dispatch behavior.