chio-http-session
chio-http-session is the per-session audit journal for Chio's guard pipeline:
an in-process, thread-safe, append-only, hash-chained record of tool
invocations, cumulative data flow, and delegation depth for a single session.
Guards hold a SessionJournal per session, append to it on every tool call via
record, and read it back through a single-lock SessionJournalSnapshot.
Despite the shared chio-http-* prefix, this crate is unrelated to
chio-http-core: it defines no HTTP request/response types and no wire
framing. chio-http-core::SessionContext is the mutable, request-scoped
context threaded through HTTP evaluation; chio-http-session::SessionJournal
is the durable, tamper-evident history of invocations that guards such as
chio-guards' advisory, data-flow, and behavioral-sequence guards consult
across the life of a session. Neither type references the other.
Responsibilities
- Append-only, hash-chained record of tool invocations for one session
(
JournalEntry, with a SHA-256entry_hashcomputed over each entry's fields on append). - Cumulative counters for data flow (bytes read/written, invocation count, max delegation depth), tool sequence, per-tool counts, and a consecutive-run streak, all of which survive ring eviction.
- Capacity-bounded
entriesandtool_sequencerings, defaulting to caps sourced fromchio_kernel::MemoryBudgetConfig, with evicted entries folded into a running head hash sohead_hashandverify_integritystill commit to the dropped prefix. - Fail-closed distinct-key cap on
tool_counts: oncetool_counts_capdistinct tool names are held, a previously-unseen name is dropped rather than admitted. - A single-lock
SessionJournalSnapshotgiving guards one coherent read of data flow, tool sequence, tool counts, streak, and head hash. - Rejects empty, padded, or control-character-bearing
tool_name,server_id, oragent_idbefore they reach the hash chain.
Public API
SessionJournal- the thread-safe journal. Constructors:new,from_memory_budget,with_entry_cap,with_caps.SessionJournal::record(RecordParams) -> Result<u64, SessionJournalError>- append one entry, returning its sequence number.SessionJournal::{snapshot, data_flow, tool_sequence, tool_counts, tool_counts_len, len, is_empty, entries, recent_entries, verify_integrity, head_hash, session_id}- read APIs.RecordParams- the append input (tool_name,server_id,agent_id,bytes_read,bytes_written,delegation_depth,allowed).JournalEntry- the persisted entry shape.CumulativeDataFlow-total_bytes_read,total_bytes_written,total_invocations,max_delegation_depth.SessionJournalSnapshot- the guard-facing read view.SessionJournalError-LockPoisoned,InvalidRecordField { field },IntegrityViolation { index, expected, actual }.
Usage
use ;
let journal = new;
journal
.record
.unwrap;
let snapshot = journal.snapshot.unwrap;
assert_eq!;
Testing
cargo test -p chio-http-session
See also
chio-http-core- defines the HTTP-facingSessionContextand request evaluation types; unrelated to this crate despite the shared prefix.chio-guards- the primary consumer; its advisory, data-flow, and behavioral-sequence guards hold anArc<SessionJournal>for session-aware decisions.chio-kernel- suppliesMemoryBudgetConfig, the source of this journal's default entry and tool-count caps.