Skip to main content

StateRuntime

Struct StateRuntime 

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

Preferred entrypoint: owns configuration and metrics.

Implementations§

Source§

impl StateRuntime

Source

pub async fn get_backfill_state(&self) -> Result<BackfillState>

Source

pub async fn try_claim_backfill(&self, lease_seconds: i64) -> Result<bool>

Attempt to claim ownership of rollout metadata backfill.

Returns true when this runtime claimed the backfill worker slot. Returns false if backfill is already complete or currently owned by a non-expired worker.

Source

pub async fn mark_backfill_running(&self) -> Result<()>

Mark rollout metadata backfill as running.

Source

pub async fn checkpoint_backfill(&self, watermark: &str) -> Result<()>

Persist rollout metadata backfill progress.

Source

pub async fn mark_backfill_complete( &self, last_watermark: Option<&str>, ) -> Result<()>

Mark rollout metadata backfill as complete.

Source§

impl StateRuntime

Source§

impl StateRuntime

Source

pub async fn insert_log(&self, entry: &LogEntry) -> Result<()>

Source

pub async fn insert_logs(&self, entries: &[LogEntry]) -> Result<()>

Insert a batch of log entries into the logs table.

Source

pub async fn query_logs(&self, query: &LogQuery) -> Result<Vec<LogRow>>

Query logs with optional filters.

Source

pub async fn query_feedback_logs_for_threads( &self, thread_ids: &[&str], ) -> Result<Vec<u8>>

Query feedback logs for a set of threads, capped to the SQLite retention budget.

Source

pub async fn query_feedback_logs(&self, thread_id: &str) -> Result<Vec<u8>>

Query per-thread feedback logs, capped to the per-thread SQLite retention budget.

Source

pub async fn max_log_id(&self, query: &LogQuery) -> Result<i64>

Return the max log id matching optional filters.

Source§

impl StateRuntime

Source

pub async fn get_remote_control_enrollment( &self, websocket_url: &str, account_id: &str, app_server_client_name: Option<&str>, ) -> Result<Option<RemoteControlEnrollmentRecord>>

Source

pub async fn upsert_remote_control_enrollment( &self, enrollment: &RemoteControlEnrollmentRecord, ) -> Result<()>

Source

pub async fn set_remote_control_enabled( &self, websocket_url: &str, account_id: &str, app_server_client_name: Option<&str>, remote_control_enabled: bool, ) -> Result<u64>

Source

pub async fn delete_remote_control_enrollment( &self, websocket_url: &str, account_id: &str, app_server_client_name: Option<&str>, ) -> Result<u64>

Source§

impl StateRuntime

Source

pub async fn get_thread(&self, id: ThreadId) -> Result<Option<ThreadMetadata>>

Source

pub async fn get_thread_memory_mode( &self, id: ThreadId, ) -> Result<Option<String>>

Source

pub async fn set_thread_preview_if_empty( &self, thread_id: ThreadId, preview: &str, ) -> Result<bool>

Source

pub async fn upsert_thread_spawn_edge( &self, parent_thread_id: ThreadId, child_thread_id: ThreadId, status: DirectionalThreadSpawnEdgeStatus, ) -> Result<()>

Persist or replace the directional parent-child edge for a spawned thread.

Source

pub async fn set_thread_spawn_edge_status( &self, child_thread_id: ThreadId, status: DirectionalThreadSpawnEdgeStatus, ) -> Result<()>

Update the persisted lifecycle status of a spawned thread’s incoming edge.

Source

pub async fn list_thread_spawn_children_with_status( &self, parent_thread_id: ThreadId, status: DirectionalThreadSpawnEdgeStatus, ) -> Result<Vec<ThreadId>>

List direct spawned children of parent_thread_id whose edge matches status.

Source

pub async fn list_thread_spawn_children( &self, parent_thread_id: ThreadId, ) -> Result<Vec<ThreadId>>

List all direct spawned children of parent_thread_id.

Source

pub async fn list_thread_spawn_descendants_with_status( &self, root_thread_id: ThreadId, status: DirectionalThreadSpawnEdgeStatus, ) -> Result<Vec<ThreadId>>

List spawned descendants of root_thread_id whose edges match status.

Descendants are returned breadth-first by depth, then by thread id for stable ordering.

Source

pub async fn list_thread_spawn_descendants( &self, root_thread_id: ThreadId, ) -> Result<Vec<ThreadId>>

List all spawned descendants of root_thread_id.

Descendants are returned breadth-first by depth, then by thread id for stable ordering.

Source

pub async fn find_thread_spawn_child_by_path( &self, parent_thread_id: ThreadId, agent_path: &str, ) -> Result<Option<ThreadId>>

Find a direct spawned child of parent_thread_id by canonical agent path.

Source

pub async fn find_thread_spawn_descendant_by_path( &self, root_thread_id: ThreadId, agent_path: &str, ) -> Result<Option<ThreadId>>

Find a spawned descendant of root_thread_id by canonical agent path.

Source

pub async fn find_rollout_path_by_id( &self, id: ThreadId, archived_only: Option<bool>, ) -> Result<Option<PathBuf>>

Find a rollout path by thread id using the underlying database.

Source

pub async fn find_thread_by_exact_title( &self, title: &str, allowed_sources: &[String], model_providers: Option<&[String]>, archived_only: bool, cwd: Option<&Path>, ) -> Result<Option<ThreadMetadata>>

Find the newest thread whose user-facing title exactly matches title.

Source

pub async fn list_threads( &self, page_size: usize, filters: ThreadFilterOptions<'_>, ) -> Result<ThreadsPage>

List threads using the underlying database.

Source

pub async fn list_threads_by_parent( &self, page_size: usize, parent_thread_id: ThreadId, filters: ThreadFilterOptions<'_>, ) -> Result<ThreadsPage>

List direct children of parent_thread_id using persisted spawn edges.

Source

pub async fn list_threads_by_relation( &self, page_size: usize, relation_filter: ThreadRelationFilter, filters: ThreadFilterOptions<'_>, ) -> Result<ThreadsPage>

List threads matching a persisted spawn-graph relationship.

Source

pub async fn list_thread_ids( &self, limit: usize, anchor: Option<&Anchor>, sort_key: SortKey, allowed_sources: &[String], model_providers: Option<&[String]>, archived_only: bool, ) -> Result<Vec<ThreadId>>

List thread ids using the underlying database (no rollout scanning).

Source

pub async fn upsert_thread(&self, metadata: &ThreadMetadata) -> Result<()>

Insert or replace thread metadata directly.

Source

pub async fn insert_thread_if_absent( &self, metadata: &ThreadMetadata, ) -> Result<bool>

Source

pub async fn set_thread_memory_mode( &self, thread_id: ThreadId, memory_mode: &str, ) -> Result<bool>

Source

pub async fn update_thread_title( &self, thread_id: ThreadId, title: &str, ) -> Result<bool>

Source

pub async fn update_thread_name( &self, thread_id: ThreadId, name: Option<&str>, ) -> Result<bool>

Source

pub async fn touch_thread_updated_at( &self, thread_id: ThreadId, updated_at: DateTime<Utc>, ) -> Result<bool>

Source

pub async fn touch_thread_recency_at( &self, thread_id: ThreadId, recency_at: DateTime<Utc>, ) -> Result<bool>

Source§

impl StateRuntime

Source

pub async fn update_thread_git_info( &self, thread_id: ThreadId, git_sha: Option<Option<&str>>, git_branch: Option<Option<&str>>, git_origin_url: Option<Option<&str>>, ) -> Result<bool>

Source

pub async fn apply_rollout_items( &self, builder: &ThreadMetadataBuilder, items: &[RolloutItem], new_thread_memory_mode: Option<&str>, updated_at_override: Option<DateTime<Utc>>, ) -> Result<()>

Apply rollout items incrementally using the underlying database.

Source

pub async fn mark_archived( &self, thread_id: ThreadId, rollout_path: &Path, archived_at: DateTime<Utc>, ) -> Result<()>

Mark a thread as archived using the underlying database.

Source

pub async fn mark_unarchived( &self, thread_id: ThreadId, rollout_path: &Path, ) -> Result<()>

Mark a thread as unarchived using the underlying database.

Source

pub async fn delete_thread(&self, thread_id: ThreadId) -> Result<u64>

Delete a thread and all associated state by id.

Source

pub async fn delete_threads_strict( &self, thread_ids: &[ThreadId], ) -> Result<u64>

Delete a set of threads and all associated state.

Spawn edges and thread rows are deleted last so a failed delete can be retried with enough state left to rediscover the same spawned subtree.

Source§

impl StateRuntime

Source

pub async fn init( codex_home: PathBuf, default_provider: String, ) -> Result<Arc<Self>>

Initialize the state runtime using the provided Codex home and default provider.

This opens (and migrates) the SQLite databases under codex_home. Logs and paginated thread history live in dedicated files to reduce lock contention with the rest of the state store.

Source

pub fn codex_home(&self) -> &Path

Return the configured Codex home directory for this runtime.

Source

pub fn thread_goals(&self) -> &GoalStore

Source

pub fn memories(&self) -> &MemoryStore

Source

pub async fn close(&self)

Close all SQLite pools and wait for outstanding pool workers to exit.

Source

pub async fn clear_memory_data_in_sqlite_home( sqlite_home: &Path, ) -> Result<bool>

Trait Implementations§

Source§

impl Clone for StateRuntime

Source§

fn clone(&self) -> StateRuntime

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

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> RamaFrom<T> for U
where U: From<T>,

Source§

fn rama_from(value: T) -> U

Source§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

Source§

fn rama_into(self) -> U

Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

Source§

fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>

Source§

impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for T
where U: RamaTryFrom<T, CrateMarker>,

Source§

type Error = <U as RamaTryFrom<T, CrateMarker>>::Error

Source§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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