Skip to main content

SqliteAgentStore

Struct SqliteAgentStore 

Source
pub struct SqliteAgentStore { /* private fields */ }
Expand description

Cloneable handle to the single-owner SQLite Tokio actor implementing allen_store::AgentStore.

Cloning this handle shares the same bounded command channel to the single actor task. When all clones are dropped, the channel closes and the actor exits cleanly after finishing any in-flight transaction.

Implementations§

Source§

impl SqliteAgentStore

Source

pub async fn connect_and_migrate( config: SqliteStoreConfig, ) -> Result<Self, StoreError>

Opens the SQLite database described by config, spawns the single-owner Tokio actor, and verifies or applies all append-only SQL migrations before returning.

Creates missing parent directories for file-backed paths, enables foreign keys and PRAGMA synchronous = FULL, and verifies SHA-256 checksums for every previously applied migration in schema_migrations.

§Errors

Returns:

  • StoreError::SchemaDrift if an already-applied migration’s name or SHA-256 checksum differs from the compiled migration set.
  • StoreError::Backend if creating parent directories, opening SQLite, applying migrations, or initializing the actor task fails.
§Examples
use allen_store_sqlite::{SqliteAgentStore, SqliteStoreConfig};

let store = SqliteAgentStore::connect_and_migrate(
    SqliteStoreConfig::try_new(":memory:").unwrap(),
)
.await
.unwrap();
assert!(format!("{store:?}").contains("SqliteAgentStore"));

Trait Implementations§

Source§

impl Clone for SqliteAgentStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CommandStore for SqliteAgentStore

Source§

fn lookup_receipt<'a>( &'a self, tenant_id: &'a TenantId, session_id: &'a SessionId, command_id: &'a CommandId, ) -> BoxFuture<'a, Result<Option<CommandReceipt>, StoreError>>

Looks up a previously committed CommandReceipt for (tenant_id, session_id, command_id). Read more
Source§

fn commit_step<'a>( &'a self, lease: &'a LeaseToken, commit: StepCommit, ) -> BoxFuture<'a, Result<StepCommitResult, StoreError>>

Atomically verifies lease and commit.expected_revision, then persists all entries, leaf pointer updates, epoch bumps, effect journal mutations, spend entries, and the optional command receipt in a single transaction. Read more
Source§

fn list_unknown_effects<'a>( &'a self, tenant_id: &'a TenantId, run_id: &'a RunId, ) -> BoxFuture<'a, Result<Vec<EffectRecord>, StoreError>>

Lists every effect in EffectState::Unknown belonging to (tenant_id, run_id). Read more
Source§

fn list_claimed_effects<'a>( &'a self, tenant_id: &'a TenantId, run_id: &'a RunId, ) -> BoxFuture<'a, Result<Vec<EffectRecord>, StoreError>>

Lists every effect currently in EffectState::Claimed belonging to (tenant_id, run_id). Read more
Source§

impl Debug for SqliteAgentStore

Source§

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

Formats the value using the given formatter. Read more
Source§

impl LeaseStore for SqliteAgentStore

Source§

fn enqueue_run<'a>( &'a self, tenant_id: &'a TenantId, session_id: &'a SessionId, run_id: &'a RunId, pool_name: &'a PoolName, ) -> BoxFuture<'a, Result<(), StoreError>>

Enqueues a new background run in Queued status for workers polling pool_name. Read more
Source§

fn acquire_session_lease<'a>( &'a self, tenant_id: &'a TenantId, session_id: &'a SessionId, owner_id: &'a OwnerId, ttl: Duration, ) -> BoxFuture<'a, Result<LeaseToken, StoreError>>

Acquires or supersedes an exclusive lease on an interactive session for owner_id. Read more
Source§

fn claim_queued_run<'a>( &'a self, owner_id: &'a OwnerId, pool_name: &'a PoolName, ttl: Duration, ) -> BoxFuture<'a, Result<Option<LeaseToken>, StoreError>>

Atomically claims at most one Queued run from pool_name for owner_id with lease lifetime ttl. Read more
Source§

fn reclaim_expired_run<'a>( &'a self, owner_id: &'a OwnerId, pool_name: &'a PoolName, ttl: Duration, ) -> BoxFuture<'a, Result<Option<LeaseToken>, StoreError>>

Atomically claims one expired running lease in pool_name (status = 'running' AND expires_at_ms <= now_ms), advances OwnerFence, updates ownership and expiry to owner_id / ttl, and transitions all Claimed effects on that run to Unknown. Read more
Source§

fn renew_lease<'a>( &'a self, lease: &'a LeaseToken, ttl: Duration, ) -> BoxFuture<'a, Result<LeaseToken, StoreError>>

Extends the expiration timestamp of an active lease by ttl without changing its OwnerFence. Read more
Source§

fn finish_run<'a>( &'a self, lease: &'a LeaseToken, status: TerminalRunStatus, summary_code: Option<&'a str>, ) -> BoxFuture<'a, Result<(), StoreError>>

Marks the leased run with a terminal TerminalRunStatus and optional summary_code, advancing OwnerFence so subsequent calls using lease fail closed with StoreError::StaleFence. Read more
Source§

fn recover_expired_run<'a>( &'a self, tenant_id: &'a TenantId, run_id: &'a RunId, new_owner_id: &'a OwnerId, ttl: Duration, ) -> BoxFuture<'a, Result<(LeaseToken, Vec<EffectRecord>), StoreError>>

Reclaims a specific expired running lease (status = 'running' AND expires_at_ms <= now_ms) for new_owner_id, returning the new LeaseToken and all Claimed effects that transitioned atomically to Unknown. Read more
Source§

fn force_recover_run<'a>( &'a self, tenant_id: &'a TenantId, run_id: &'a RunId, new_owner_id: &'a OwnerId, ttl: Duration, ) -> BoxFuture<'a, Result<LeaseToken, StoreError>>

Forces operator or conformance takeover of a non-terminal (Running or WaitingApproval) run regardless of whether its lease has expired. Read more
Source§

impl SessionStore for SqliteAgentStore

Source§

fn create_session<'a>( &'a self, tenant_id: &'a TenantId, session_id: &'a SessionId, parent_session_id: Option<&'a SessionId>, ) -> BoxFuture<'a, Result<StepCommitResult, StoreError>>

Creates a new empty session at SessionRevision::INITIAL with default ScopeEpochs. Read more
Source§

fn load_branch<'a>( &'a self, tenant_id: &'a TenantId, session_id: &'a SessionId, leaf: Option<&'a EntryId>, ) -> BoxFuture<'a, Result<LoadedBranch, StoreError>>

Loads the ordered root-to-leaf SessionEntry chain for session_id. Read more
Source§

impl SpendStore for SqliteAgentStore

Source§

fn sum_spend_since<'a>( &'a self, tenant_id: &'a TenantId, since_ms: i64, billing_class: Option<BillingClass>, ) -> BoxFuture<'a, Result<MicroUsd, StoreError>>

Sums all spend rows recorded for tenant_id with recorded_at_ms >= since_ms, optionally restricted to a single BillingClass. Read more
Source§

fn sum_run_spend<'a>( &'a self, tenant_id: &'a TenantId, run_id: &'a RunId, ) -> BoxFuture<'a, Result<MicroUsd, StoreError>>

Sums all spend rows recorded for (tenant_id, run_id) across all billing classes. Read more

Auto Trait Implementations§

§

impl Forget for SqliteAgentStore

§

impl Freeze for SqliteAgentStore
where *const ArcInner<Chan<ActorReq, Semaphore>> is !null: Freeze, PhantomData<ArcInner<Chan<ActorReq, Semaphore>>>: Freeze, *const ArcInner<Path> is !null: Freeze, PhantomData<ArcInner<Path>>: Freeze,

§

impl Move for SqliteAgentStore

§

impl RefUnwindSafe for SqliteAgentStore
where Atomic<usize>: RefUnwindSafe, Chan<ActorReq, Semaphore>: RefUnwindSafe,

§

impl Send for SqliteAgentStore
where Arc<Chan<ActorReq, Semaphore>>: Send, Arc<Path>: Send,

§

impl Sync for SqliteAgentStore
where Arc<Chan<ActorReq, Semaphore>>: Sync, Arc<Path>: Sync,

§

impl Unpin for SqliteAgentStore
where Arc<Chan<ActorReq, Semaphore>>: Unpin, Arc<Path>: Unpin,

§

impl UnsafeUnpin for SqliteAgentStore
where *const ArcInner<Chan<ActorReq, Semaphore>> is !null: UnsafeUnpin, PhantomData<ArcInner<Chan<ActorReq, Semaphore>>>: UnsafeUnpin, *const ArcInner<Path> is !null: UnsafeUnpin, PhantomData<ArcInner<Path>>: UnsafeUnpin,

§

impl UnwindSafe for SqliteAgentStore
where Arc<Chan<ActorReq, Semaphore>>: UnwindSafe, Arc<Path>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AgentStore for T

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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