Skip to content

Persistence

techrevati.runtime.persistence

Persistence — SQLite-backed sinks for long-lived sessions.

RingBufferEventSink / RingBufferUsageSink are great for short sessions and tests, but their in-memory deques cap out at DEFAULT_RING_CAPACITY events. A session that runs for hours and emits thousands of events silently drops the oldest entries.

SqliteEventSink and SqliteUsageSink persist to a stdlib sqlite3 database — same zero-dependency constraint as SqliteSaver — with WAL mode so concurrent readers don't block the writer. Use them when you need an event log that survives a process restart, or when the in-memory buffer would otherwise overflow.

Both sinks are write-ahead: emit / record return after the INSERT commits. For throughput-critical scenarios, wrap them in a bounded queue + background-thread flusher; the protocols are kept small so adapters are easy.

SqliteEventSink dataclass

SqliteEventSink(path)

EventSink that persists every event to a sqlite table.

Pass :memory: as path for a short-lived in-process store (still durable for the lifetime of the process). For real durability, pass an on-disk path.

replay

replay(*, limit=None)

Yield every persisted event in insertion order.

SqliteUsageSink dataclass

SqliteUsageSink(path)

UsageSink that persists every recorded turn to a sqlite table.

totals

totals()

Aggregate cost + token totals across every recorded turn.