Skip to main content

SessionJournal

Struct SessionJournal 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn session_id(&self) -> &str

Return the session identifier.

Source

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.

Source

pub fn data_flow(&self) -> Result<CumulativeDataFlow, SessionJournalError>

Return a snapshot of the cumulative data flow statistics.

Source

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.

Source

pub fn tool_sequence(&self) -> Result<Vec<String>, SessionJournalError>

Return the ordered tool invocation sequence (bounded to the entry cap).

Source

pub fn tool_counts(&self) -> Result<HashMap<String, u64>, SessionJournalError>

Return per-tool invocation counts.

Source

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.

Source

pub fn len(&self) -> Result<usize, SessionJournalError>

Return the number of entries in the journal.

Source

pub fn is_empty(&self) -> Result<bool, SessionJournalError>

Return whether the journal is empty.

Source

pub fn entries(&self) -> Result<Vec<JournalEntry>, SessionJournalError>

Return a clone of the retained journal entries (bounded to the entry cap).

Source

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).

Source

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.

Source

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§

Source§

impl Debug for SessionJournal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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