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
impl PlanRuntime
Sourcepub async fn close_admission(&self) -> Result<(), String>
pub async fn close_admission(&self) -> Result<(), String>
Close admission atomically with proving that all plan work has drained.
pub async fn open_admission(&self)
pub fn subscribe_admission(&self) -> Receiver<bool>
pub fn is_accepting_plans(&self) -> bool
Sourcepub async fn register_plan(&self, plan_id: &str) -> Result<(), String>
pub async fn register_plan(&self, plan_id: &str) -> Result<(), String>
Reserve a plan for either execution RPC without replacing an active execution.
Sourcepub async fn record_stream_node(&self, plan_id: &str, node: &RtdlNode) -> bool
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.
Sourcepub async fn record_plan_ops(&self, plan: &Plan)
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.
pub async fn context(&self, plan_id: &str) -> ExecutionContext
Sourcepub async fn record_op_state(&self, plan_id: &str, op_id: &str, state: u32)
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.
Sourcepub async fn get_plan_status_builtin(
&self,
call: &CapabilityCall,
) -> CapabilityCallResult
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.
Sourcepub async fn get_all_plans_builtin(
&self,
call: &CapabilityCall,
) -> CapabilityCallResult
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.
Sourcepub async fn active_plans_json(&self) -> String
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.
Sourcepub async fn complete_plan(&self, plan_id: &str) -> bool
pub async fn complete_plan(&self, plan_id: &str) -> bool
Atomically remove a plan, retain cancellation racing with completion, and notify waiters.
Sourcepub async fn is_cancelled(&self, plan_id: &str) -> bool
pub async fn is_cancelled(&self, plan_id: &str) -> bool
Return whether a registered plan has been cancelled.
Sourcepub async fn register_or_cancel_async_call(
&self,
plan_id: &str,
call: RunningAsyncCall,
) -> bool
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.
Sourcepub async fn unregister_async_call(&self, plan_id: &str, call_id: &str)
pub async fn unregister_async_call(&self, plan_id: &str, call_id: &str)
Remove an async call once it reaches a terminal state.
Sourcepub async fn cancel_plan_builtin(
&self,
call: &CapabilityCall,
) -> CapabilityCallResult
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.
Sourcepub async fn cancel_plan_control(
&self,
plan_id: &str,
wait_ms: u64,
) -> (bool, String)
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.
Sourcepub async fn cancel_all_plans(&self) -> bool
pub async fn cancel_all_plans(&self) -> bool
Cancel every active plan and make best-effort cancel calls for running async work.
Sourcepub async fn cancel_all_plans_except(
&self,
except_plan_id: Option<&str>,
wait_ms: u64,
) -> (usize, bool)
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.
Sourceasync fn begin_cancel(&self, plan_id: &str) -> Result<CancelSnapshot, String>
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.
Sourceasync fn begin_cancel_all(
&self,
except_plan_id: Option<&str>,
) -> CancelAllSnapshot
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.
async fn wait_until_inactive(&self, plan_id: &str, wait_ms: u64) -> bool
Sourceasync fn wait_until_all_inactive(
&self,
plan_ids: &[String],
wait_ms: u64,
) -> bool
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
impl Clone for PlanRuntime
Auto Trait Implementations§
impl !RefUnwindSafe for PlanRuntime
impl !UnwindSafe for PlanRuntime
impl Freeze for PlanRuntime
impl Send for PlanRuntime
impl Sync for PlanRuntime
impl Unpin for PlanRuntime
impl UnsafeUnpin for PlanRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].