Skip to main content

PlanRuntime

Struct PlanRuntime 

Source
pub struct PlanRuntime {
    inner: Arc<Mutex<HashMap<String, PlanRun>>>,
}

Fields§

§inner: Arc<Mutex<HashMap<String, PlanRun>>>

Implementations§

Source§

impl PlanRuntime

Source

pub async fn register_plan(&self, plan_id: &str)

Register a plan before execution starts.

If a stale entry with the same id exists it is replaced. Plan ids are UUIDs generated by Pilot, so replacement is only a defensive cleanup path.

Source

pub async fn record_plan_ops(&self, plan: &Plan)

Snapshot a plan’s op list (arena order) so get_plan_status can report the op_ids/descriptions the LLM may target. Called right after register_plan. No-op if the plan is not in the active table.

Source

pub async fn record_op_state(&self, plan_id: &str, op_id: &str, state: u32)

Record the latest observed RTDL state for an op. Called by the execution loop / async poller alongside every node_state event it streams, so get_plan_status reflects live progress. No-op for unknown plans.

Source

pub async fn get_plan_status_builtin( &self, call: &CapabilityCall, ) -> CapabilityCallResult

Apply the get_plan_status builtin: return the plan’s ops as JSON, each with op_id, kind, description, current state, and any armed stop_point. Lets the LLM inspect a running plan before issuing a stop_plan_at (inspect first, then act). Errors when the plan is not in the active table (stale/wrong id, or already finished) — it is a query, so “not found” is an error; use get_all_plans to check liveness.

Source

pub async fn get_all_plans_builtin( &self, call: &CapabilityCall, ) -> CapabilityCallResult

Apply the get_all_plans builtin: list every active RTDL plan with its op count, cancelled flag, and number of armed stop points. Lets the LLM discover which plans are running before inspecting one with get_plan_status. Takes no args.

Source

pub async fn active_plans_json(&self) -> String

Return Executor’s authoritative active-plan table for control-plane observers. Reading this snapshot does not register a query plan.

Source

pub async fn complete_plan(&self, plan_id: &str)

Mark a plan complete, remove it from the active table, and notify waiters.

Source

pub async fn is_cancelled(&self, plan_id: &str) -> bool

Return whether a registered plan has been cancelled.

Source

pub async fn register_or_cancel_async_call( &self, plan_id: &str, call: RunningAsyncCall, self_provider_id: &str, atlas: &mut AtlasClient, ) -> bool

Add one async capability call to the plan’s cancellation set, or cancel it immediately if the plan has already been marked cancelled.

Returns true when the call was registered for normal polling. Returns false when the runtime sent the provider cancel contract instead.

Source

pub async fn unregister_async_call(&self, plan_id: &str, call_id: &str)

Remove an async call once it reaches a terminal state.

Source

pub async fn cancel_async_call_for_plan( &self, plan_id: &str, call_id: &str, self_provider_id: &str, atlas: &mut AtlasClient, )

If a cancelled plan still owns call_id, remove it and send its cancel contract. Calls already claimed by cancel_plan become a no-op here.

Source

pub async fn cancel_plan_builtin( &self, call: &CapabilityCall, self_provider_id: &str, atlas: &mut AtlasClient, ) -> CapabilityCallResult

Apply the cancel_plan builtin.

Cancellation is best-effort: future sequence children are skipped by the executor loop, and currently running async capability calls receive their required <contract_id>/cancel call. Synchronous calls already in progress are allowed to return naturally.

Source

pub async fn cancel_plan_control( &self, plan_id: &str, wait_ms: u64, self_provider_id: &str, atlas: &mut AtlasClient, ) -> (bool, String)

Out-of-band target cancellation used by Pilot meta ops and the legacy builtin wrapper. Returns whether the plan reached terminal state before the deadline plus a stable, idempotent message.

Source

pub async fn stop_plan_at_control( &self, plan_id: &str, op_id: &str, when: &str, ) -> Result<String, String>

Arm a semantic stop boundary without creating a control RTDL tree.

Source

pub async fn stop_plan_at_builtin( &self, call: &CapabilityCall, ) -> CapabilityCallResult

Apply the stop_plan_at builtin: record a stop point so the plan is cancelled when execution reaches the given op.

when selects the phase (on_enter before the op runs, on_complete after it finishes; default on_complete). Setting a stop point on a plan that is no longer active is a SUCCESS no-op — the intent (“don’t run past op X”) is already satisfied, and returning an error would make the planner retry forever (same policy as cancel_plan). The op_id is not validated against the plan’s nodes here; an op_id that never executes simply never fires.

Source

pub async fn should_stop_at( &self, plan_id: &str, op_id: &str, when: StopWhen, ) -> bool

Whether the plan has a stop point on op_id for the given phase. Read by the execution loop at each do node entry and completion.

Source

pub async fn trigger_stop( &self, plan_id: &str, self_provider_id: &str, atlas: &mut AtlasClient, )

Fire a stop point: mark the plan cancelled and best-effort cancel its running async calls — the same teardown cancel_plan performs. After this the execution loop’s is_cancelled checks halt the rest of the plan. No-op if the plan already left the active table.

Source

pub async fn cancel_all_plans( &self, self_provider_id: &str, atlas: &mut AtlasClient, ) -> bool

Cancel every active plan and make best-effort cancel calls for running async work.

Source

pub async fn cancel_all_plans_except( &self, self_provider_id: &str, atlas: &mut AtlasClient, except_plan_id: Option<&str>, wait_ms: u64, ) -> (usize, bool)

Cancel every active plan except an optional control plan and wait for the targets to leave the active table.

Source

async fn begin_cancel(&self, plan_id: &str) -> Result<CancelSnapshot, String>

Mark a plan cancelled and return the state needed by cancel_plan.

This pure runtime step is separated from atlas/MCP cancel calls so tests can cover unknown-plan and cancellation-state behavior without a live atlas server.

Source

async fn begin_cancel_all( &self, except_plan_id: Option<&str>, ) -> CancelAllSnapshot

Mark every active plan cancelled and drain their async cancel sets into one snapshot. Provider cancel calls happen after the runtime lock is released by cancel_all_plans.

Source

async fn wait_until_inactive(&self, plan_id: &str, wait_ms: u64) -> bool

Source

async fn wait_until_all_inactive( &self, plan_ids: &[String], wait_ms: u64, ) -> bool

Poll durable active-table state instead of awaiting Notify, whose notification can race ahead of waiter registration.

Trait Implementations§

Source§

impl Clone for PlanRuntime

Source§

fn clone(&self) -> PlanRuntime

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
Source§

impl Default for PlanRuntime

Source§

fn default() -> PlanRuntime

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> 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> DynClone for T
where T: Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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