Skip to main content

ExecutionState

Struct ExecutionState 

Source
pub struct ExecutionState {
Show 40 fields pub persistence: Arc<dyn WorkflowPersistence>, pub action_registry: Arc<ActionRegistry>, pub script_env_provider: Arc<dyn ScriptEnvProvider>, pub workflow_run_id: String, pub workflow_name: String, pub run_ctx: Arc<dyn RunContext>, pub extra_plugin_dirs: Vec<String>, pub model: Option<String>, pub exec_config: WorkflowExecConfig, pub inputs: HashMap<String, String>, pub parent_run_id: String, pub depth: u32, pub target_label: Option<String>, pub step_results: HashMap<String, StepResult>, pub contexts: Vec<ContextEntry>, pub position: i64, pub all_succeeded: bool, pub total_cost: f64, pub total_turns: i64, pub total_duration_ms: i64, pub total_input_tokens: i64, pub total_output_tokens: i64, pub total_cache_read_input_tokens: i64, pub total_cache_creation_input_tokens: i64, pub has_llm_metrics: bool, pub last_gate_feedback: Option<String>, pub block_output: Option<String>, pub block_with: Vec<String>, pub resume_ctx: Option<ResumeContext>, pub default_as_identity: Option<String>, pub triggered_by_hook: bool, pub schema_resolver: Option<Arc<dyn Fn(&str) -> Result<OutputSchema> + Send + Sync>>, pub child_runner: Option<Arc<dyn ChildWorkflowRunner>>, pub last_heartbeat_at: Arc<AtomicI64>, pub registry: Arc<ItemProviderRegistry>, pub event_sinks: Arc<[Arc<dyn EventSink>]>, pub cancellation: CancellationToken, pub current_execution_id: Arc<Mutex<Option<(String, String)>>>, pub owner_token: Option<String>, pub lease_generation: Option<i64>,
}
Expand description

Mutable runtime state for a workflow execution — no conductor-core deps.

Fields§

§persistence: Arc<dyn WorkflowPersistence>§action_registry: Arc<ActionRegistry>§script_env_provider: Arc<dyn ScriptEnvProvider>§workflow_run_id: String§workflow_name: String§run_ctx: Arc<dyn RunContext>

Shared per-run context carrying injected variables and working directory. Arc (not Box) because ExecutionState derives Clone for fork_child.

§extra_plugin_dirs: Vec<String>

Extra plugin directories for the executor. Not part of RunContext because Vec<String> doesn’t fit the HashMap<&'static str, String> injected-variables contract, and only executor code reads it.

§model: Option<String>§exec_config: WorkflowExecConfig§inputs: HashMap<String, String>§parent_run_id: String§depth: u32§target_label: Option<String>§step_results: HashMap<String, StepResult>§contexts: Vec<ContextEntry>§position: i64§all_succeeded: bool§total_cost: f64§total_turns: i64§total_duration_ms: i64§total_input_tokens: i64§total_output_tokens: i64§total_cache_read_input_tokens: i64§total_cache_creation_input_tokens: i64§has_llm_metrics: bool§last_gate_feedback: Option<String>§block_output: Option<String>§block_with: Vec<String>§resume_ctx: Option<ResumeContext>§default_as_identity: Option<String>§triggered_by_hook: bool§schema_resolver: Option<Arc<dyn Fn(&str) -> Result<OutputSchema> + Send + Sync>>

Schema resolver callback — (schema_name) → OutputSchema. The host closes over working_dir and repo_path at construction time.

§child_runner: Option<Arc<dyn ChildWorkflowRunner>>

Runner for child workflows (call workflow nodes).

§last_heartbeat_at: Arc<AtomicI64>§registry: Arc<ItemProviderRegistry>§event_sinks: Arc<[Arc<dyn EventSink>]>

Event sinks — slice shared cheaply across sub-workflow states.

§cancellation: CancellationToken

Cancellation token for this run. Checked at each step boundary.

§current_execution_id: Arc<Mutex<Option<(String, String)>>>

The executor label and step_id of the currently executing action, if any. Written by execute_call before dispatch; read by FlowEngine::cancel_run() to fire-and-forget executor.cancel().

§owner_token: Option<String>

Lease token held by this engine instance after a successful acquire_lease(). Used by PRs 3–5 for refresh and generation checks.

§lease_generation: Option<i64>

Implementations§

Source§

impl ExecutionState

Source

pub fn new_heartbeat() -> Arc<AtomicI64>

Create a fresh heartbeat counter, initialized to 0 so the first tick fires immediately.

Source

pub fn expect_lease_generation(&self) -> i64

Read the current lease generation, panicking with a consistent message if the lease was never acquired. Every executor update_step call site requires a generation, and FlowEngine::run/resume is the single entry point that sets it — so a None here is a programmer error in engine construction, not a runtime condition.

Source

pub fn check_cancellation_throttled(&self) -> Result<()>

Throttled heartbeat tick + external cancel check.

Bumps last_heartbeat in persistence at most once every 5 seconds and polls for cross-process cancellation via persistence.is_run_cancelled. On external cancel, sets self.cancellation and returns Err(EngineError::Cancelled).

Callers that own the engine main loop use ? to propagate cancellation up. Wait loops that need to drain in-flight work (parallel, foreach) can call this best-effort and rely on self.cancellation.is_cancelled() for their controlled exit — the cancellation token is set by this helper before the Err is returned.

Without this being called from inside long-running wait loops (parallel blocks, foreach fan-out), the cancellation check is skipped during multi-minute waits — see #2731.

NOTE (#2731/#2796): lease refresh (refresh_lease_loop in flow_engine.rs) is the load-bearing ownership mechanism. detect_stuck_workflow_run_ids falls back to started_at when last_heartbeat is NULL (new runs).

Source

pub fn child_workflow_context(&self) -> ChildWorkflowContext

Project this state into the narrow surface a ChildWorkflowRunner implementation needs to spawn a child run.

Source

pub fn fork_child(&self, cancellation: CancellationToken) -> ExecutionState

Fork a child execution state from this parent.

Copies shared configuration (persistence, registries, workflow identity) and resets all runtime accumulators so the child starts with a clean slate.

Source

pub fn accumulate_metrics( &mut self, cost: Option<f64>, turns: Option<i64>, duration: Option<i64>, input_tokens: Option<i64>, output_tokens: Option<i64>, cache_read: Option<i64>, cache_create: Option<i64>, ) -> bool

Accumulate individual metrics into this execution state.

Returns true if at least one metric was present and added.

Trait Implementations§

Source§

impl Clone for ExecutionState

Source§

fn clone(&self) -> ExecutionState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more