Skip to main content

Session

Struct Session 

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

A Lua execution session with domain state tracking.

Each session owns a dedicated Lua VM via _vm_driver. The VM’s OS thread stays alive as long as the driver is held, and exits cleanly when the session is dropped (channel closes → Lua thread drains and exits).

Implementations§

Source§

impl Session

Source

pub fn new( llm_rx: Receiver<LlmRequest>, exec_task: AsyncTask, metrics: ExecutionMetrics, vm_driver: AsyncIsleDriver, ) -> Self

Create a new session.

§Arguments
  • llm_rx — Receiver for LLM requests from the Lua bridge.
  • exec_task — The coroutine execution task handle.
  • metrics — Session metrics (owns the LogSink ring buffer; the bridge reads its log_sink_handle() separately to wire print() / alc.log() into the same ring buffer that metrics.snapshot() exposes via recent_logs in alc_status).
  • vm_driver — Keeps the Lua OS thread alive.
§Returns

A new Session in the Running state.

Source

pub fn snapshot( &self, pending_filter: Option<&PendingFilter>, include_history: bool, ) -> Value

Lightweight snapshot for external observation (alc_status).

Returns session state label and running metrics without consuming or modifying the session.

§Arguments
  • pending_filter — Opt-in projection for the currently pending LLM queries. None emits only pending_queries: N (integer count), preserving the v0.x wire shape for light-weight polling. Some(filter) adds a pending: [...] array projected through the filter’s field flags.
  • include_history — When true, conversation_history (≤10 entries) is included in the metrics output. When false (default), the key is absent. High-frequency polling callers should leave this false to avoid wire bloat.
§Returns

A serde_json::Value snapshot with the following additive fields beyond v0.x:

  • phase — 5-value string derived from ExecutionState: "running", "paused", "completed", "failed", "cancelled". The existing state key is retained for backward compatibility (3-value).
  • started_at — Unix millisecond timestamp when the session was created.
  • last_activity_at — Unix millisecond timestamp of the most recent feed_one. Note: started_at and last_activity_at are wall-clock values while expiry GC uses the monotonic last_active Instant; they may skew slightly on NTP adjustments (acceptable for observability use).
Source

pub fn is_expired(&self, ttl: Duration) -> bool

Returns true if the session has been idle longer than ttl.

Uses saturating_duration_since to avoid panics if the clock drifts backwards (though this is extremely rare with monotonic clocks).

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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
Source§

impl<T> MaybeSend for T
where T: Send,