aa_storage_sqlite_buffer/lib.rs
1//! Local in-process SQLite **event buffer** for Agent Assembly.
2//!
3//! When the upstream NATS/gateway is briefly unreachable, Assembly keeps
4//! emitting governance [`AuditEntry`] records into this buffer instead of
5//! dropping them. Once the connection recovers, the buffer flushes its backlog
6//! — in insertion order — through the upstream [`AuditSink`]. This gives
7//! Assembly **partial
8//! autonomy** so a transient outage never silently loses audit-trail data.
9//!
10//! The buffer is a single SQLite file opened in WAL mode, so a buffered event
11//! survives a process restart and is replayed on the next reconnect.
12//!
13//! ```no_run
14//! use aa_storage_sqlite_buffer::EventBuffer;
15//!
16//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
17//! // Open (or create) a buffer holding at most 10_000 events.
18//! let buffer = EventBuffer::new("/var/lib/agent-assembly/buffer.db", 10_000)?;
19//! # let _ = buffer;
20//! # Ok(())
21//! # }
22//! ```
23
24#![warn(missing_docs)]
25
26mod buffer;
27mod config;
28
29pub use buffer::EventBuffer;
30pub use config::{default_path, SqliteBufferConfig, DEFAULT_CAP};
31
32// Re-export the storage-contract types that appear in this crate's public API
33// so callers reach the buffer and its event/sink types from a single path.
34pub use aa_core::storage::{AuditEntry, AuditSink, Result, StorageError};
35
36/// Counter incremented once per event accepted into the buffer.
37pub const METRIC_EVENTS_BUFFERED: &str = "aa_events_buffered";
38
39/// Counter incremented when the cap is exceeded and an oldest event is evicted.
40pub const METRIC_EVENTS_DROPPED: &str = "aa_events_dropped_total";
41
42/// Counter incremented once per event successfully flushed to the sink.
43pub const METRIC_EVENTS_FLUSHED: &str = "aa_events_flushed_total";