pub struct SessionJournal { /* private fields */ }Expand description
Thread-safe, append-only, hash-chained session journal.
Create one per session and share it (via Arc<SessionJournal>) with all
guards that need session-aware context.
Implementations§
Source§impl SessionJournal
impl SessionJournal
Sourcepub fn new(session_id: String) -> Self
pub fn new(session_id: String) -> Self
Create a new empty journal for the given session using the DEFAULT process memory budget caps.
Session-aware guards that hold a CONFIGURED process memory budget should
prefer Self::from_memory_budget so lowering journal_entry_cap (or
journal_tool_counts_cap) actually tightens each per-session journal
instead of every caller silently retaining the compiled-in default.
Sourcepub fn from_memory_budget(
session_id: String,
budget: &MemoryBudgetConfig,
) -> Self
pub fn from_memory_budget( session_id: String, budget: &MemoryBudgetConfig, ) -> Self
Create a new empty journal whose entry-ring and distinct-tool-name caps come
from a CONFIGURED process memory budget. Threading the operator’s
chio_kernel::MemoryBudgetConfig (rather than a fresh defaults() read
inside Self::new) means lowering journal_entry_cap /
journal_tool_counts_cap on the process budget actually bounds each
per-session journal, so a multi-session workload stays within the configured
budget instead of every session retaining the default 4096 entries.
Sourcepub fn with_entry_cap(session_id: String, entry_cap: usize) -> Self
pub fn with_entry_cap(session_id: String, entry_cap: usize) -> Self
Create a new empty journal with an explicit entry-ring capacity and the
default distinct-tool-name cap. The entries and tool_sequence rings
are bounded to entry_cap; data_flow stays cumulative and
tool_counts is cumulative but distinct-key bounded.
Sourcepub fn with_caps(
session_id: String,
entry_cap: usize,
tool_counts_cap: usize,
) -> Self
pub fn with_caps( session_id: String, entry_cap: usize, tool_counts_cap: usize, ) -> Self
Create a new empty journal with explicit entry-ring and distinct-tool-name
caps. entry_cap bounds the entries and tool_sequence rings;
tool_counts_cap bounds the number of DISTINCT tool names retained in the
cumulative tool_counts map fail-closed.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Return the session identifier.
Sourcepub fn record(&self, params: RecordParams) -> Result<u64, SessionJournalError>
pub fn record(&self, params: RecordParams) -> Result<u64, SessionJournalError>
Append a new entry to the journal.
The entry is hash-chained to the previous entry. Returns the sequence number of the new entry.
Sourcepub fn data_flow(&self) -> Result<CumulativeDataFlow, SessionJournalError>
pub fn data_flow(&self) -> Result<CumulativeDataFlow, SessionJournalError>
Return a snapshot of the cumulative data flow statistics.
Sourcepub fn snapshot(&self) -> Result<SessionJournalSnapshot, SessionJournalError>
pub fn snapshot(&self) -> Result<SessionJournalSnapshot, SessionJournalError>
Return a coherent snapshot of guard-facing journal state.
The snapshot captures cumulative data flow, tool sequence, tool counts, entry count, and head hash while holding one journal lock. Guards that need more than one view should prefer this method over multiple getters.
Sourcepub fn tool_sequence(&self) -> Result<Vec<String>, SessionJournalError>
pub fn tool_sequence(&self) -> Result<Vec<String>, SessionJournalError>
Return the ordered tool invocation sequence (bounded to the entry cap).
Sourcepub fn tool_counts(&self) -> Result<HashMap<String, u64>, SessionJournalError>
pub fn tool_counts(&self) -> Result<HashMap<String, u64>, SessionJournalError>
Return per-tool invocation counts.
Sourcepub fn tool_counts_len(&self) -> Result<usize, SessionJournalError>
pub fn tool_counts_len(&self) -> Result<usize, SessionJournalError>
Number of DISTINCT tool names currently retained in the cumulative
tool_counts map. Bounded above by the journal’s tool_counts_cap.
Exposed so a telemetry exporter or the kernel’s
bounded-structure registry can observe how close the per-session
distinct-key set is to saturation once the journal is wired into a live
dispatch path.
Sourcepub fn len(&self) -> Result<usize, SessionJournalError>
pub fn len(&self) -> Result<usize, SessionJournalError>
Return the number of entries in the journal.
Sourcepub fn is_empty(&self) -> Result<bool, SessionJournalError>
pub fn is_empty(&self) -> Result<bool, SessionJournalError>
Return whether the journal is empty.
Sourcepub fn entries(&self) -> Result<Vec<JournalEntry>, SessionJournalError>
pub fn entries(&self) -> Result<Vec<JournalEntry>, SessionJournalError>
Return a clone of the retained journal entries (bounded to the entry cap).
Sourcepub fn recent_entries(
&self,
n: usize,
) -> Result<Vec<JournalEntry>, SessionJournalError>
pub fn recent_entries( &self, n: usize, ) -> Result<Vec<JournalEntry>, SessionJournalError>
Return the most recent N entries (or all retained if fewer than N exist).
Sourcepub fn verify_integrity(&self) -> Result<(), SessionJournalError>
pub fn verify_integrity(&self) -> Result<(), SessionJournalError>
Verify the integrity of the hash chain.
Returns Ok(()) if all entries are correctly chained, or an error
indicating where the chain breaks.
Sourcepub fn head_hash(&self) -> Result<String, SessionJournalError>
pub fn head_hash(&self) -> Result<String, SessionJournalError>
Return the exported head hash: the most recent entry hash before any eviction, or (once a prefix has been evicted) a fold of the evicted prefix and the retained tail, so the head stays committed to the full sequence across eviction (or the zero hash if empty).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionJournal
impl RefUnwindSafe for SessionJournal
impl Send for SessionJournal
impl Sync for SessionJournal
impl Unpin for SessionJournal
impl UnsafeUnpin for SessionJournal
impl UnwindSafe for SessionJournal
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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