Pipeline.Safety.SafetyManager (pipeline v0.0.1)
View SourceUnified safety management for nested pipeline execution.
Provides a single interface for all safety checks including recursion limits, resource monitoring, and error handling for nested pipeline execution.
Summary
Functions
Perform comprehensive safety checks before executing a nested pipeline.
Clean up resources and perform safety cleanup after execution.
Create execution context for a nested pipeline with safety tracking.
Get default safety configuration.
Handle safety violations and perform appropriate cleanup.
Merge user configuration with defaults.
Monitor ongoing execution and check for safety violations.
Types
@type execution_context() :: %{ nesting_depth: non_neg_integer(), pipeline_id: String.t(), parent_context: execution_context() | nil, step_count: non_neg_integer(), start_time: DateTime.t(), workspace_dir: String.t() | nil }
@type safety_config() :: %{ max_depth: non_neg_integer(), max_total_steps: non_neg_integer(), memory_limit_mb: non_neg_integer(), timeout_seconds: non_neg_integer(), workspace_enabled: boolean(), cleanup_on_error: boolean() }
@type safety_result() :: :ok | {:error, String.t()}
Functions
@spec check_safety(String.t(), execution_context()) :: safety_result()
Perform comprehensive safety checks before executing a nested pipeline.
Parameters
pipeline_id
: The ID of the pipeline about to be executedcontext
: The current execution contextconfig
: Safety configuration (optional)
Returns
:ok
if all safety checks pass{:error, message}
if any safety check fails
Examples
iex> context = %{nesting_depth: 2, pipeline_id: "test", parent_context: nil, step_count: 5, start_time: DateTime.utc_now(), workspace_dir: nil}
iex> Pipeline.Safety.SafetyManager.check_safety("child", context)
:ok
@spec check_safety(String.t(), execution_context(), safety_config()) :: safety_result()
@spec cleanup_execution(execution_context()) :: execution_context()
Clean up resources and perform safety cleanup after execution.
Parameters
context
: Execution context to clean upconfig
: Safety configuration (optional)
Returns
- Cleaned execution context
@spec cleanup_execution(execution_context(), safety_config()) :: execution_context()
@spec create_safe_context(String.t()) :: execution_context()
Create execution context for a nested pipeline with safety tracking.
Parameters
pipeline_id
: The ID of the pipelineparent_context
: The parent execution context (optional)step_count
: Number of steps in the pipeline (default: 0)config
: Safety configuration (optional)
Returns
- New execution context with safety tracking
@spec create_safe_context(String.t(), execution_context() | nil) :: execution_context()
@spec create_safe_context(String.t(), execution_context() | nil, non_neg_integer()) :: execution_context()
@spec create_safe_context( String.t(), execution_context() | nil, non_neg_integer(), safety_config() ) :: execution_context()
@spec default_config() :: safety_config()
Get default safety configuration.
Returns
- Default safety configuration map
@spec handle_safety_violation(String.t(), execution_context()) :: String.t()
Handle safety violations and perform appropriate cleanup.
Parameters
error
: The safety error that occurredcontext
: Current execution contextconfig
: Safety configuration (optional)
Returns
- Formatted error with context information
@spec handle_safety_violation(String.t(), execution_context(), safety_config()) :: String.t()
@spec merge_config(map()) :: safety_config()
Merge user configuration with defaults.
Parameters
user_config
: User-provided configuration (optional)
Returns
- Complete safety configuration
@spec monitor_execution(execution_context()) :: safety_result()
Monitor ongoing execution and check for safety violations.
Parameters
context
: Current execution contextconfig
: Safety configuration (optional)
Returns
:ok
if execution is within safety limits{:error, message}
if safety limits exceeded
@spec monitor_execution(execution_context(), safety_config()) :: safety_result()