Skip to main content

SqliteStore

Struct SqliteStore 

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

SQLite-backed RunStore. Cheap to clone (wraps a pool).

Implementations§

Source§

impl SqliteStore

Source

pub async fn open(path: impl AsRef<Path>) -> Result<Self, Error>

Open (creating if needed) a database file. Uses WAL, synchronous=NORMAL, foreign keys and a busy timeout, then migrates and refreshes planner statistics (maintenance::optimize).

Source

pub async fn open_in_memory() -> Result<Self, Error>

A private in-memory database (one connection, lives as long as the store). Handy for tests.

Source

pub async fn from_pool(pool: SqlitePool) -> Result<Self, Error>

Use an existing pool (its connection options are kept as given) and apply migrations.

Source

pub fn pool(&self) -> &SqlitePool

Source

pub async fn schema_version(&self) -> Result<i64, Error>

The schema version recorded in the database.

Source

pub async fn append(&self, run_id: RunId, event: &Event) -> Result<i64, Error>

Append one event and return its sequence number. The number is computed inside the insert statement, which SQLite runs under the write lock, so concurrent appends to one run never collide or skip.

Source

pub async fn run_ended(&self, run_id: RunId) -> Result<bool, Error>

Whether the last thing the run journaled was its end. A run that was resumed and then cut short journals something after its pause. A run paused for an answer journals finished with an Interrupted status: that is a pause, not an end, so it is still waiting.

Source

pub async fn events(&self, run_id: RunId) -> Result<Vec<Event>, Error>

The run’s journal in order, decoded.

Source

pub async fn raw_events(&self, run_id: RunId) -> Result<Vec<StoredEvent>, Error>

The run’s journal in order, as stored.

Source

pub async fn upsert_state(&self, state: &RunState) -> Result<(), Error>

Insert or replace the snapshot for state.run_id.

Source

pub async fn state(&self, run_id: RunId) -> Result<Option<RunState>, Error>

The latest snapshot of one run.

Source

pub async fn runs_for_session( &self, session_id: &str, ) -> Result<Vec<RunState>, Error>

Every run of a session, least recently updated first.

Source

pub async fn latest_state_for_session( &self, session_id: &str, ) -> Result<Option<RunState>, Error>

The most recently updated run of a session.

Source

pub async fn interrupted_runs(&self) -> Result<Vec<RunState>, Error>

Runs paused on an interruption (pending set). Settle each with Agent::resume. A child run is not listed: it was started by its parent’s tool call, and an answer reaches it through the parent, whose state holds it. Resuming its own row would run it behind the parent’s back and again when the parent resumes.

Source

pub async fn in_flight_runs(&self) -> Result<Vec<RunState>, Error>

Runs whose last checkpoint was taken mid tool batch (in_flight set): the process stopped while tools ran. Continue each with Agent::run_from, which re-runs idempotent calls and marks the rest indeterminate.

Source

pub async fn clock(&self) -> Result<String, Error>

The store’s clock, in the format its checkpoints are stamped with: a mark to compare later checkpoints against (SqliteStore::unfinished_runs_since).

Source

pub async fn unfinished_runs_since( &self, since: &str, ) -> Result<Vec<RunState>, Error>

Top-level runs that never ended and were last checkpointed at or after since (a SqliteStore::clock mark), each still the latest run of its session: the turns a process stop cut off. A run paused for an answer is listed too; a child run is not (its parent holds it).

Source

pub async fn unfinished_background_runs_since( &self, since: &str, ) -> Result<Vec<RunState>, Error>

Sub-agent runs that never ended, were last checkpointed at or after since and whose parent run has ended: background sub-agents a process stop cut off (a child of a cut-off turn is held by that turn’s run, which has not ended). Oldest checkpoint first.

Source

pub async fn close(&self)

Close the pool, checkpointing the WAL.

Trait Implementations§

Source§

impl Clone for SqliteStore

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 Debug for SqliteStore

Source§

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

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

impl RunStore for SqliteStore

Source§

fn append_event<'life0, 'life1, 'async_trait>( &'life0 self, run_id: RunId, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn save_state<'life0, 'life1, 'async_trait>( &'life0 self, state: &'life1 RunState, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn load_state<'life0, 'async_trait>( &'life0 self, run_id: RunId, ) -> Pin<Box<dyn Future<Output = Result<Option<RunState>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Auto Trait Implementations§

Blanket Implementations§

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