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
impl DistributedReasonerV2
Sourcepub fn new(config: DistributedReasonerConfig) -> Self
pub fn new(config: DistributedReasonerConfig) -> Self
Construct a new DistributedReasonerV2 with the provided config.
Sourcepub fn start_session(&mut self, goal: &str) -> String
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.
Sourcepub fn start_session_with_id(&mut self, goal: &str, session_id: &str)
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.
Sourcepub fn add_session_peer(
&mut self,
session_id: &str,
peer_id: &str,
) -> Result<(), ReasoningError>
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.
Sourcepub fn record_remote_result(
&mut self,
session_id: &str,
result: RemoteResult,
) -> Result<(), ReasoningError>
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).
Sourcepub fn mark_peer_responded(
&mut self,
session_id: &str,
peer_id: &str,
) -> Result<(), ReasoningError>
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”.
Sourcepub fn is_session_complete(&self, session_id: &str) -> bool
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.
Sourcepub fn get_session_results(
&mut self,
session_id: &str,
) -> Option<Vec<RemoteResult>>
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.
Sourcepub fn cleanup_expired_sessions(&mut self) -> usize
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.
Sourcepub fn evict_stale_cache(&mut self) -> usize
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.
Sourcepub fn session_stats(&self) -> SessionStats
pub fn session_stats(&self) -> SessionStats
Produce a snapshot of aggregate statistics over all live sessions.
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Number of currently tracked sessions (active + recently completed).
Sourcepub fn gc_sessions(&mut self, max_age_secs: u64) -> usize
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.
Sourcepub fn session_metrics(&self) -> SessionMetrics
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— meanlatency_msacross allRemoteResults.
Auto Trait Implementations§
impl !RefUnwindSafe for DistributedReasonerV2
impl !UnwindSafe for DistributedReasonerV2
impl Freeze for DistributedReasonerV2
impl Send for DistributedReasonerV2
impl Sync for DistributedReasonerV2
impl Unpin for DistributedReasonerV2
impl UnsafeUnpin for DistributedReasonerV2
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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