Skip to main content

WorkflowGuardState

Struct WorkflowGuardState 

Source
pub struct WorkflowGuardState { /* private fields */ }
Expand description

Mutable runtime state tracked by the guard during a workflow execution.

Shared between parent and child workflows via Arc<Mutex<_>> so that limits are enforced globally across the entire run tree.

§Examples

use ironflow_engine::guard::{WorkflowGuardConfig, WorkflowGuardState};

let mut state = WorkflowGuardState::new();
let config = WorkflowGuardConfig::new().with_max_depth(2);

state.record_invocation("workflow-a");
state.record_invocation("workflow-b");
assert!(state.check(&config, "workflow-c").is_err());

Implementations§

Source§

impl WorkflowGuardState

Source

pub fn new() -> Self

Create a fresh guard state for a new workflow execution.

§Examples
use ironflow_engine::guard::WorkflowGuardState;

let state = WorkflowGuardState::new();
assert_eq!(state.depth(), 0);
assert_eq!(state.total_invocations(), 0);
Source

pub fn depth(&self) -> u32

Current sub-workflow nesting depth.

Source

pub fn total_invocations(&self) -> u32

Total workflow invocations so far.

Source

pub fn total_tokens_used(&self) -> u64

Total tokens consumed so far.

Source

pub fn call_chain(&self) -> &[String]

The current call chain (workflow name stack).

Source

pub fn elapsed_secs(&self) -> u64

Seconds elapsed since the workflow started.

Source

pub fn check( &self, config: &WorkflowGuardConfig, target_workflow: &str, ) -> Result<(), WorkflowRejection>

Read-only check: would invoking target_workflow violate any limit?

Does not mutate state. Call this before record_invocation.

§Errors

Returns the specific WorkflowRejection variant that would be violated.

§Examples
use ironflow_engine::guard::{WorkflowGuardConfig, WorkflowGuardState, WorkflowRejection};

let state = WorkflowGuardState::new();
let config = WorkflowGuardConfig::new().with_max_depth(0);

let err = state.check(&config, "child").unwrap_err();
assert!(matches!(err, WorkflowRejection::MaxDepthExceeded { .. }));
Source

pub fn record_invocation(&mut self, target_workflow: &str)

Record that a sub-workflow invocation is starting.

Increments depth and fan-out counter, and pushes the workflow name onto the call chain for cycle detection.

§Examples
use ironflow_engine::guard::WorkflowGuardState;

let mut state = WorkflowGuardState::new();
state.record_invocation("child-workflow");
assert_eq!(state.depth(), 1);
assert_eq!(state.total_invocations(), 1);
assert_eq!(state.call_chain(), &["child-workflow"]);
Source

pub fn record_return(&mut self)

Record that a sub-workflow invocation has returned.

Decrements depth and pops the last entry from the call chain. Safe to call even on failure paths (the guard must never leak depth).

§Examples
use ironflow_engine::guard::WorkflowGuardState;

let mut state = WorkflowGuardState::new();
state.record_invocation("child");
assert_eq!(state.depth(), 1);

state.record_return();
assert_eq!(state.depth(), 0);
assert!(state.call_chain().is_empty());
Source

pub fn record_tokens( &mut self, config: &WorkflowGuardConfig, tokens_used: u64, ) -> Result<u64, WorkflowRejection>

Record tokens consumed by an agent step.

Returns the remaining token budget, or an error if the budget is now exhausted.

§Errors

Returns WorkflowRejection::TokenBudgetExhausted when the cumulative usage exceeds the configured maximum.

§Examples
use ironflow_engine::guard::{WorkflowGuardConfig, WorkflowGuardState, WorkflowRejection};

let mut state = WorkflowGuardState::new();
let config = WorkflowGuardConfig::new().with_max_workflow_tokens(100);

assert!(state.record_tokens(&config, 50).is_ok());
assert!(state.record_tokens(&config, 60).is_err());

Trait Implementations§

Source§

impl Debug for WorkflowGuardState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WorkflowGuardState

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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