Minimal immutable context for executing a runnable without the full workflow.
Built during the prepare phase and consumed during execute phase. Contains only what's needed for the specific node type being invoked.
Design Goals
- Minimal footprint - Only include data needed for execution
- Immutable - Safe to pass across process boundaries
- Self-contained - No workflow reference, all needed state captured
- Content-addressed - Uses causal ancestry rather than generation counters
Node-Specific Context Fields
Different node types populate different context fields:
- Step:
fan_out_contextfor mapped pipeline tracking - Condition/Conjunction:
satisfied_conditionsfor gate logic - Accumulator:
last_known_statefor stateful operations - Join:
join_contextwith satisfaction tracking - FanOut:
fan_out_contextwith reduce tracking - FanIn:
fan_in_contextwith readiness and sister values - All nodes:
meta_contextfor graph-resolved meta expression values,run_contextfor external runtime values fromcontext/1expressions
Summary
Functions
Returns the after hooks from the context.
Builds a basic context with node hash, input fact, and ancestry depth.
Returns the before hooks from the context.
Returns whether this context has any meta context populated.
Returns whether this context has any run context populated.
Returns whether this context's node is mergeable (parallel-safe).
Returns the meta context map from the context.
Creates a new CausalContext with the given attributes.
Returns the run context map from the context.
Adds fan_in context for reduction coordination.
Adds fan_out context for mapped pipeline tracking.
Adds hooks to the context.
Adds join context for join coordination.
Sets the mergeable flag on the context.
Adds meta context for nodes with meta expression dependencies.
Adds run context for external runtime value injection.
Adds satisfied conditions for conjunction gates.
Adds state context for stateful nodes.
Types
@type t() :: %Runic.Workflow.CausalContext{ ancestry_depth: non_neg_integer(), fan_in_context: map() | nil, fan_out_context: map() | nil, hooks: {list(), list()}, input_fact: Runic.Workflow.Fact.t() | nil, is_state_initialized: boolean(), join_context: map() | nil, last_known_state: term() | nil, mergeable: boolean(), meta_context: map(), node_hash: integer() | nil, run_context: map(), satisfied_conditions: MapSet.t() | nil }
Functions
Returns the after hooks from the context.
@spec basic(integer(), Runic.Workflow.Fact.t(), non_neg_integer()) :: t()
Builds a basic context with node hash, input fact, and ancestry depth.
Returns the before hooks from the context.
Returns whether this context has any meta context populated.
Returns whether this context has any run context populated.
Returns whether this context's node is mergeable (parallel-safe).
Returns the meta context map from the context.
Creates a new CausalContext with the given attributes.
Returns the run context map from the context.
Adds fan_in context for reduction coordination.
Adds fan_out context for mapped pipeline tracking.
Adds hooks to the context.
Adds join context for join coordination.
Sets the mergeable flag on the context.
Components with mergeable: true have CRDT-like properties
(commutative, idempotent, associative) and are safe for parallel
merge without ordering guarantees.
Adds meta context for nodes with meta expression dependencies.
Meta context contains values prepared from :meta_ref edges during the
prepare phase. These values are then available during execution without
requiring workflow access.
Example
context = CausalContext.new(...)
|> CausalContext.with_meta_context(%{cart_state: %{total: 150, items: []}})
Adds run context for external runtime value injection.
Run context contains runtime-scoped values (secrets, tenant IDs, database connections) resolved for a specific component during the prepare phase. Available during execution without requiring workflow access.
Example
context = CausalContext.new()
|> CausalContext.with_run_context(%{api_key: "sk-...", model: "gpt-4"})
Adds satisfied conditions for conjunction gates.
Adds state context for stateful nodes.