Expand description
Implements allen_store::AgentStore on local SQLite through a single-owner Tokio
actor that enforces BEGIN IMMEDIATE, PRAGMA synchronous = FULL, and SHA-256
checksummed startup migrations.
§Architecture & Layer Role
Within the Allen Open Agent Infrastructure Standard, allen-store-sqlite is the
single-node Layer 1 persistence backend. Local binaries (the host authority daemon,
allen, and standalone CLI consumers) pair it with allen-runtime for durable
sessions, fenced run leases, effect journals, command deduplication receipts, and
checked integer spend tracking without an external database service. It satisfies
the same allen_store::conformance invariants as allen_store::InMemoryStore and
external custom backends.
§Quick Start
Pass ":memory:" for an isolated in-memory SQLite database (useful in tests) or a
filesystem path for durable on-disk storage:
use allen_store::{CommandStore, LeaseStore, OwnerId, SessionStore, StepCommit};
use allen_store_sqlite::{JournalMode, SqliteAgentStore, SqliteStoreConfig};
use allen_types::ids::{SessionId, SessionRevision, TenantId};
use std::time::Duration;
let cfg = SqliteStoreConfig::try_new(":memory:")
.unwrap()
.with_journal_mode(JournalMode::Wal);
let store = SqliteAgentStore::connect_and_migrate(cfg).await.unwrap();
let tenant = TenantId::try_new("org:local").unwrap();
let session = SessionId::try_new("sess:1").unwrap();
let owner = OwnerId::try_new("node-1").unwrap();
store.create_session(&tenant, &session, None).await.unwrap();
let lease = store
.acquire_session_lease(&tenant, &session, &owner, Duration::from_secs(30))
.await
.unwrap();
let committed = store
.commit_step(&lease, StepCommit::empty(SessionRevision::INITIAL))
.await
.unwrap();
assert_eq!(committed.new_revision, SessionRevision::from_u64(1));§API Guide
SqliteStoreConfig: Validated database path andJournalModeconfiguration.JournalMode: Choice betweenJournalMode::Wal(default) andJournalMode::Delete.SqliteAgentStore: Cheaply cloneable handle to the single-owner SQLite actor implementingallen_store::LeaseStore,allen_store::CommandStore,allen_store::SessionStore,allen_store::SpendStore, andallen_store::AgentStore.
§Durability & Concurrency Invariants
- Enforces
#![forbid(unsafe_code)]. - Owns one
sqlx::SqliteConnectioninside a dedicated Tokio task fed by a boundedmpscchannel (capacity 256), serializing all writes to avoidSQLITE_BUSYcontention across concurrent tasks. - Configures
PRAGMA foreign_keys = ON,PRAGMA synchronous = FULL, a 5-secondbusy_timeout, and the requestedJournalModeon startup. - Runs every mutating operation inside
BEGIN IMMEDIATEwith full rollback onStoreError::StaleFence,StoreError::RevisionConflict,StoreError::TenantMismatch,StoreError::IllegalTransition, orStoreError::DuplicateIdempotencyKey. - Applies append-only SQL migrations tracked in
schema_migrationswith SHA-256 checksums; any modified or mismatched applied migration fails closed on startup withStoreError::SchemaDrift.
Modules§
- durable
durable - Unified durable session persistence backed by
crate::SqliteAgentStore.
Structs§
- Sqlite
Agent Store - Cloneable handle to the single-owner SQLite Tokio actor implementing
allen_store::AgentStore. - Sqlite
Store Config - Validated connection configuration for
SqliteAgentStore::connect_and_migrate.
Enums§
- Journal
Mode - SQLite journal mode configured on the actor’s database connection.