Skip to main content

PlanRuntime

Struct PlanRuntime 

Source
pub struct PlanRuntime {
    inner: Arc<Mutex<HashMap<String, PlanRun>>>,
    admission_closed: Sender<bool>,
    changed: Arc<Notify>,
}
Expand description

Shared active-plan state used for progress queries and cancellation.

Fields§

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

Active executions keyed by plan ID, shared across RPC handlers and tasks.

§admission_closed: Sender<bool>

Lifecycle admission flag, updated under the plan lock and observed by idle RPCs.

§changed: Arc<Notify>

Wakes waiters when cancellation is requested or a completed plan is removed.

Implementations§

Source§

impl PlanRuntime

Source

pub async fn close_admission(&self) -> Result<(), String>

Close admission atomically with proving that all plan work has drained.

Source

pub async fn open_admission(&self)

Source

pub fn subscribe_admission(&self) -> Receiver<bool>

Source

pub fn is_accepting_plans(&self) -> bool

Source

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

Reserve a plan for either execution RPC without replacing an active execution.

Source

pub async fn record_stream_node(&self, plan_id: &str, node: &RtdlNode) -> bool

Append metadata atomically with the cancellation check; the first node is the root.

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 context(&self, plan_id: &str) -> ExecutionContext

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, and current state. 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 and cancelled flag. 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) -> bool

Atomically remove a plan, retain cancellation racing with completion, 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, ) -> 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_plan_builtin( &self, call: &CapabilityCall, ) -> 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, ) -> (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 cancel_all_plans(&self) -> bool

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

Source

pub async fn cancel_all_plans_except( &self, 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

Register notification before reading durable state to avoid lost wakeups.

Trait Implementations§

Source§

impl Clone for PlanRuntime

Source§

fn clone(&self) -> Self

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() -> 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> 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: 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
§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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
浙ICP备2023005800号-2 浙公网安备33010902005384号