Skip to main content

DistributedReasonerV2

Struct DistributedReasonerV2 

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

Enhanced distributed reasoner with real session management, result caching, and cycle-safe peer tracking.

§Design

Each call to start_session creates a DistributedInferenceSession that tracks which peers have been queried and which have replied. Results stream in via record_remote_result. A short-lived LRU-style cache keyed on the goal string avoids redundant network round-trips for recently seen goals.

Implementations§

Source§

impl DistributedReasonerV2

Source

pub fn new(config: DistributedReasonerConfig) -> Self

Construct a new DistributedReasonerV2 with the provided config.

Source

pub fn start_session(&mut self, goal: &str) -> String

Create a new inference session for goal and return its session_id.

The timeout is taken from DistributedReasonerConfig::timeout.

Source

pub fn start_session_with_id(&mut self, goal: &str, session_id: &str)

Create a new inference session with a caller-supplied session_id.

Unlike start_session the UUID is provided by the caller so it can be correlated with an outgoing InferenceRequest. If a session with the same ID already exists it is silently replaced.

Source

pub fn add_session_peer( &mut self, session_id: &str, peer_id: &str, ) -> Result<(), ReasoningError>

Register peer_id as a query target for the given session.

Returns ReasoningError::SessionNotFound when session_id is unknown, ReasoningError::PeerAlreadyRegistered when the peer was already added, and ReasoningError::SessionExpired when the session has timed out.

Source

pub fn record_remote_result( &mut self, session_id: &str, result: RemoteResult, ) -> Result<(), ReasoningError>

Record a RemoteResult for an in-progress session.

The peer is automatically moved from pending_peers to completed_peers if it was registered. Unknown peers are accepted anyway (unsolicited partial results are common in gossip networks).

Source

pub fn mark_peer_responded( &mut self, session_id: &str, peer_id: &str, ) -> Result<(), ReasoningError>

Mark peer_id as having responded (without attaching a result).

Useful for signalling that a peer replied with “no solution”.

Source

pub fn is_session_complete(&self, session_id: &str) -> bool

Returns true when the session has received responses from all registered peers or has exceeded its timeout.

Source

pub fn get_session_results( &mut self, session_id: &str, ) -> Option<Vec<RemoteResult>>

Return all remote results collected for session_id, or None when the session is unknown.

Also consults the goal cache so that repeated queries benefit from previously gathered results.

Source

pub fn cleanup_expired_sessions(&mut self) -> usize

Remove all sessions that have exceeded their timeout.

Returns the number of sessions that were cleaned up.

Source

pub fn evict_stale_cache(&mut self) -> usize

Evict goal-cache entries whose TTL has elapsed.

Called automatically by cleanup_expired_sessions but also available for manual invocation.

Source

pub fn session_stats(&self) -> SessionStats

Produce a snapshot of aggregate statistics over all live sessions.

Source

pub fn session_count(&self) -> usize

Number of currently tracked sessions (active + recently completed).

Source

pub fn gc_sessions(&mut self, max_age_secs: u64) -> usize

Garbage-collect sessions older than max_age_secs.

A session is considered “old” when the wall-clock time since it was started exceeds max_age_secs, regardless of whether it completed normally. Returns the number of sessions that were removed.

Source

pub fn session_metrics(&self) -> SessionMetrics

Return a SessionMetrics snapshot for monitoring purposes.

  • active_sessions — sessions that have not yet completed.
  • completed_sessions — sessions where all peers replied or timed-out.
  • expired_sessions — sessions that exceeded their per-session timeout.
  • avg_peers_per_session — mean number of peers registered per session.
  • avg_latency_ms — mean latency_ms across all RemoteResults.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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