Skip to main content

MemoryStorage

Struct MemoryStorage 

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

In-memory storage backend. Thread-safe via RwLock.

All data is lost when the process exits. Use SQLite for durable storage.

Implementations§

Source§

impl MemoryStorage

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl CommitStore for MemoryStorage

Source§

fn set_commit_trace( &self, commit_id: &ObjectId, trace: &CommitTrace, ) -> Result<(), StorageError>

Record the trace commit_id was made in. The first record for a commit stands. Backends that don’t keep trace links ignore it.
Source§

fn get_commit_trace( &self, commit_id: &ObjectId, ) -> Result<Option<CommitTrace>, StorageError>

The trace commit_id was made in, if one was recorded.
Source§

fn store_totals(&self) -> Result<Option<StoreTotals>, StorageError>

The store’s totals, for the store gauges. Counting still reads every row’s key, so sample it on a slow interval. Backends that don’t count report None.
Source§

fn get_commit(&self, id: &ObjectId) -> Result<Option<Commit>, StorageError>

Retrieve a commit by its ID.
Source§

fn put_commit(&self, commit: &Commit) -> Result<(), StorageError>

Store a commit.
Source§

fn has_commit(&self, id: &ObjectId) -> Result<bool, StorageError>

Check if a commit exists.
Source§

fn all_commit_ids(&self) -> Result<Vec<ObjectId>, StorageError>

Return the ids of every commit in the store, unordered. Read more
Source§

fn list_commits( &self, from: &ObjectId, limit: usize, ) -> Result<Vec<Commit>, StorageError>

List commits reachable from a given commit, in reverse chronological order. Returns at most limit commits.
Source§

fn list_commits_dag( &self, from: &ObjectId, limit: usize, ) -> Result<CommitWalk, StorageError>

Walk every parent edge from from, not just the first. Read more
Source§

fn history_extract_batch( &self, _batch_size: usize, ) -> Result<usize, StorageError>

Fold the next batch of un-processed commits into the asg_history_* rollup/milestone tables, advancing the stored commits.rowid cursor atomically. Returns the number of commits processed this call — 0 once the extractor has caught up. Idempotent and resumable: the cursor only advances inside the same transaction that writes the rows, so a crash re-processes the batch rather than double-counting it. Bounded memory: at most batch_size commits are held at once.
Source§

fn history_cursor(&self) -> Result<i64, StorageError>

The last commits.rowid folded into the history tables (0 = nothing extracted yet).
Source§

fn history_rollup(&self) -> Result<Vec<HistoryRollupRow>, StorageError>

Read the commit-history rollup, ordered by (day, namespace, agent, intent category).
Source§

fn history_milestones( &self, _limit: usize, ) -> Result<Vec<HistoryMilestoneRow>, StorageError>

Read the milestone timeline in chronological order, most recent first, capped at limit.
Source§

fn history_store_shape(&self) -> Result<StoreShape, StorageError>

Measure the physical shape of the store (Plan A t-003): object/commit counts, total bytes, and per-table bytes when the backend can report them. Backends that can’t return an empty StoreShape.
Source§

fn put_commit_traced( &self, commit: &Commit, trace: Option<&CommitTrace>, ) -> Result<(), StorageError>

Store commit and, when given, the trace it was made in. A backend that can does both in one write, which matters on every commit; the default stores one after the other.
Source§

fn history_is_commit_distilled( &self, _id: &ObjectId, ) -> Result<bool, StorageError>

Whether id’s commit has been folded into the history tables — i.e. its position is at or before the extractor cursor. This is the “already captured” predicate Plan B’s GC checks before pruning a commit’s raw snapshot: a distilled commit’s signal survives in the metric tables. Backends without history report false (nothing distilled → prune nothing on this basis).
Source§

fn history_retained_state_roots(&self) -> Result<Vec<ObjectId>, StorageError>

State roots the GC must keep reachable: the snapshots preserved by recorded milestones (the human-meaningful spine). Distinct, order unspecified.
Source§

fn history_undistilled_commit_count(&self) -> Result<i64, StorageError>

Count commits not yet folded into the history tables — those with a rowid beyond the extractor cursor (Plan B t-002). 0 means the extractor is caught up, so every commit’s signal is distilled and the GC can safely make historical state unmaterializable. Backends without history report 0 (they have no distillation gate).
Source§

fn history_gc_reachability( &self, _roots: &[ObjectId], _batch: usize, ) -> Result<GcReachability, StorageError>

Mark every object reachable from roots (state roots) and report live vs. total object counts — the GC reclaimable estimate (Plan B t-001). Read more
Source§

fn history_gc_sweep( &self, _roots: &[ObjectId], _batch: usize, ) -> Result<GcSweep, StorageError>

Sweep: mark the closure of roots and DELETE every object outside it (Plan B t-003). Destructive; callers gate it (dry-run default, safety predicate). Backends without object storage report an empty sweep. Read more
Source§

fn history_gc_lock_writers(&self) -> Result<(), StorageError>

Take the store’s write lock for a GC sweep, held until history_gc_unlock_writers. (On Postgres it is a lock against a second sweep only; writers are kept safe by the grace period instead, and don’t wait.) Read more
Source§

fn history_gc_unlock_writers(&self, _commit: bool) -> Result<(), StorageError>

Release the lock taken by history_gc_lock_writers, committing the work done under it or rolling it back. A no-op when nothing is held.
Source§

fn gc_pin_root(&self, _key: &str, _root: &ObjectId) -> Result<(), StorageError>

Record root under key as reachable-but-uncommitted (an open speculation’s base or working tree), so a GC sweep — in this process or any other sharing the store — keeps every object it references. Replaces any earlier root for key and refreshes its age.
Source§

fn gc_unpin_root(&self, _key: &str) -> Result<(), StorageError>

Remove the pin recorded by gc_pin_root. A no-op when absent.
Source§

fn gc_pinned_roots( &self, _max_age: Duration, ) -> Result<Vec<ObjectId>, StorageError>

Every pinned root refreshed within max_age. Older pins belong to a process that died with a speculation open, and stop protecting their objects once they expire.
Source§

fn history_unpin_legacy_milestones(&self) -> Result<usize, StorageError>

Stop pinning snapshots whose checkpoint never asked to be pinned. Read more
Source§

fn commit_state_roots_recent_first(&self) -> Result<Vec<ObjectId>, StorageError>

Every commit’s state_root, newest first (insertion order), for the GC retention policy (Plan B t-003) to pick keep-recent + checkpoint-every.
Source§

fn history_vacuum(&self) -> Result<VacuumStats, StorageError>

Compact the store, returning freed pages to the OS (Plan B t-004). A full VACUUM — the sweep frees pages to the freelist, but the file only shrinks after this. Reports bytes before/after. Backends without a file report zeros.
Source§

impl Default for MemoryStorage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl EpochStore for MemoryStorage

Source§

fn create_epoch(&self, epoch: &Epoch) -> Result<(), StorageError>

Insert a newly-created epoch. If an epoch with the same id already exists, implementations may return StorageError::Backend — the repo layer is expected to guard uniqueness.
Source§

fn seal_epoch( &self, id: &str, summary: &str, sealed_at: DateTime<Utc>, sealed_commits: &[ObjectId], seal_hash: &ObjectId, ) -> Result<(), StorageError>

Seal an epoch: flip its status to Sealed, stamp sealed_at, record the seal summary, and persist the set of commits that must remain reachable for seal-violation enforcement (V8). Subsequent set_commit_epoch calls referencing this id must fail with EpochAlreadySealed. seal_hash is the tamper-evident digest over the sealed set; it is persisted, not recomputed on read, so a later walk cannot quietly produce a different answer than the one that was sealed.
Source§

fn assign_epoch_namespace( &self, id: &str, namespace: &str, ) -> Result<bool, StorageError>

Assign a workspace to an epoch that does not have one yet. Read more
Source§

fn list_epochs(&self) -> Result<Vec<Epoch>, StorageError>

List all epochs, most-recent first.
Source§

fn get_epoch(&self, id: &str) -> Result<Option<Epoch>, StorageError>

Fetch a single epoch by id.
Source§

fn archive_epoch(&self, id: &str) -> Result<(), StorageError>

Transition a sealed epoch to Archived. Fails if the epoch is not found or is not in the Sealed state.
Source§

fn set_commit_epoch( &self, commit_id: &ObjectId, epoch_id: &str, ) -> Result<(), StorageError>

Associate a commit with the given epoch. Must reject if the epoch is already sealed.
Source§

impl ObjectStore for MemoryStorage

Source§

fn get_object(&self, id: &ObjectId) -> Result<Option<Object>, StorageError>

Retrieve an object by its ID. Returns None if not found.
Source§

fn put_object(&self, obj: &Object) -> Result<ObjectId, StorageError>

Store an object. Returns its ObjectId (which is its content hash). Storing an object that already exists is a no-op (idempotent).
Source§

fn has_object(&self, id: &ObjectId) -> Result<bool, StorageError>

Check if an object exists in the store.
Source§

fn batch_get_objects( &self, ids: &[ObjectId], ) -> Result<Vec<Option<Object>>, StorageError>

Retrieve multiple objects at once. Returns None for missing objects.
Source§

fn batch_put_objects( &self, objs: &[Object], ) -> Result<Vec<ObjectId>, StorageError>

Store multiple objects at once. Returns their ObjectIds.
Source§

fn leaf_index_is_built( &self, _namespace: &str, _ref_name: &str, ) -> Result<bool, StorageError>

Whether the (namespace, ref) leaf set has been built.
Source§

fn leaf_index_build( &self, _namespace: &str, _ref_name: &str, _entries: &[(String, String)], ) -> Result<(), StorageError>

One-time backfill: replace any existing rows for (namespace, ref) with entries and mark the set built. Called once, from the read path, the first time a ref is searched after the feature is enabled.
Source§

fn leaf_index_apply( &self, _namespace: &str, _ref_name: &str, _removed_paths: &[String], _added: &[(String, String)], ) -> Result<(), StorageError>

Incremental maintenance: for a built (namespace, ref), delete the rows at removed_paths and insert added (path, value) rows. A no-op if the set has not been built (the backfill will pick up the new state). Called from the write path as a ref advances.
Substring-search the built leaves of (namespace, ref). Ok(None) means the set is not built / backend has no index (caller falls back to the tree walk); Ok(Some(..)) is authoritative (possibly empty), capped at limit.
Source§

fn leaf_index_tracks_roots(&self) -> bool

Whether this backend records the state root of each built set, through leaf_index_root, leaf_index_build_at and leaf_index_advance.
Source§

fn leaf_index_root( &self, _namespace: &str, _ref_name: &str, ) -> Result<Option<ObjectId>, StorageError>

The state root the (namespace, ref) set reflects. None when it isn’t built, was built or changed without a root, or the backend doesn’t record roots.
Source§

fn leaf_index_build_at( &self, namespace: &str, ref_name: &str, _root: &ObjectId, entries: &[(String, String)], ) -> Result<(), StorageError>

leaf_index_build from the tree at root, recording root.
Source§

fn leaf_index_advance( &self, namespace: &str, ref_name: &str, _from: &ObjectId, _to: &ObjectId, removed_paths: &[String], added: &[(String, String)], ) -> Result<bool, StorageError>

Move the set from the tree at from to the tree at to, by the leaf diff between them, only if it is at from. Returns whether it moved. A backend that doesn’t record roots applies the diff unconditionally, as leaf_index_apply, and returns true.
Source§

impl RefStore for MemoryStorage

Source§

fn create_namespace(&self, namespace: &Namespace) -> Result<(), StorageError>

Create a namespace. Returns NamespaceAlreadyExists if it already exists — callers that want idempotent creation should check first or ignore that variant.
Source§

fn list_namespaces(&self) -> Result<Vec<Namespace>, StorageError>

List all known namespaces.
Source§

fn get_ref( &self, namespace: &Namespace, name: &str, ) -> Result<Option<ObjectId>, StorageError>

Get the commit ID a ref points to. Returns None if the ref doesn’t exist. Returns NamespaceNotFound if the namespace doesn’t exist.
Source§

fn set_ref( &self, namespace: &Namespace, name: &str, target: ObjectId, ) -> Result<(), StorageError>

Set a ref to point to a commit. Creates the ref if it doesn’t exist but the namespace must already exist. Returns NamespaceNotFound if the namespace hasn’t been created yet.
Source§

fn cas_ref( &self, namespace: &Namespace, name: &str, expected: ObjectId, new: ObjectId, ) -> Result<bool, StorageError>

Atomic compare-and-swap on a ref. Updates the ref only if it currently points to expected. Returns true if the swap succeeded, false if the current value didn’t match expected. Returns NamespaceNotFound if the namespace doesn’t exist.
Source§

fn create_ref( &self, namespace: &Namespace, name: &str, target: ObjectId, ) -> Result<bool, StorageError>

Create a ref only if no ref of that name exists yet. Returns true if it was created, false if one already existed (left untouched). Returns NamespaceNotFound if the namespace doesn’t exist. Read more
Source§

fn cas_delete_ref( &self, namespace: &Namespace, name: &str, expected: ObjectId, ) -> Result<bool, StorageError>

Delete a ref only if it still points to expected. Returns true if it was deleted, false if it was absent or pointed elsewhere. Returns NamespaceNotFound if the namespace doesn’t exist. Read more
Source§

fn list_refs( &self, namespace: &Namespace, prefix: &str, ) -> Result<Vec<(String, ObjectId)>, StorageError>

List all refs in namespace whose name starts with prefix. Returns NamespaceNotFound if the namespace doesn’t exist.
Source§

fn delete_ref( &self, namespace: &Namespace, name: &str, ) -> Result<bool, StorageError>

Delete a ref. Returns true if the ref existed. Returns NamespaceNotFound if the namespace doesn’t exist.
Source§

fn delete_namespace(&self, namespace: &Namespace) -> Result<bool, StorageError>

Delete a namespace and all its refs. Returns true if the namespace existed and was deleted, false if it was not found. The “default” namespace cannot be deleted and returns InvalidOperation.
Source§

impl ReminderStore for MemoryStorage

Source§

fn save(&self, reminder: &Reminder) -> Result<(), ReminderError>

Persist a new reminder. The id field is already populated by CreateReminder::into_reminder().
Source§

fn get(&self, id: &str) -> Result<Option<Reminder>, ReminderError>

Retrieve a reminder by ID.
Source§

fn update(&self, reminder: &Reminder) -> Result<(), ReminderError>

Overwrite the full reminder record (used after in-place mutations).
Source§

fn update_if_unchanged( &self, expected: &Reminder, new: &Reminder, ) -> Result<bool, ReminderError>

Write new only if the stored reminder still equals expected (what the caller read). Returns Ok(false) when it changed in between; the caller re-reads and re-applies. Every lifecycle method is a read-modify-write of the whole record, and an unconditional update silently reverted a concurrent change (a cancel, snooze, or execution record) while both calls returned Ok. Read more
Source§

fn delete(&self, id: &str) -> Result<bool, ReminderError>

Delete a reminder permanently (hard delete, for admin use only; normal cancellation uses update with status: Cancelled).
Source§

fn list(&self, filter: &ReminderFilter) -> Result<Vec<Reminder>, ReminderError>

Return all reminders matching filter, ordered by priority then due_at ascending.
Source§

impl SessionStore for MemoryStorage

Source§

fn create_session(&self, session: &Session) -> Result<(), StorageError>

Insert a newly-created session record.
Source§

fn end_session( &self, id: &str, status: SessionStatus, ended_at: DateTime<Utc>, ) -> Result<(), StorageError>

End a session: update its status and stamp ended_at.
Source§

fn list_sessions( &self, agent_filter: Option<&str>, ) -> Result<Vec<Session>, StorageError>

List sessions, optionally filtered to those belonging to a specific agent id.
Source§

fn get_session(&self, id: &str) -> Result<Option<Session>, StorageError>

Fetch a single session by id.
Source§

fn set_commit_session( &self, commit_id: &ObjectId, session_id: &str, ) -> Result<(), StorageError>

Associate a commit with the given session. Must reject if the session has already ended.
Source§

impl TaintStore for MemoryStorage

Source§

fn create_taint(&self, taint: &Taint) -> Result<(), StorageError>

Insert a freshly-created taint record. Storage must enforce the (path, name, kind) uniqueness invariant among unresolved rows — re-creating a resolved taint with the same triple is allowed (the old one stays as an audit row).
Source§

fn resolve_taint( &self, id: &str, resolved_by: &str, reason: &str, proof: Option<&str>, resolved_at: DateTime<Utc>, ) -> Result<(), StorageError>

Mark the taint with id id as resolved. Returns StorageError::Backend (wrapping AlreadyResolved) if the record is already resolved.
Source§

fn list_taints( &self, path_prefix: Option<&str>, kind: Option<TaintKind>, include_resolved: bool, ) -> Result<Vec<Taint>, StorageError>

List taints, optionally filtered by path prefix + kind + include-resolved flag. Results are most-recently-created first.
Source§

fn check_taint(&self, request_path: &str) -> Result<Vec<Taint>, StorageError>

Return every active taint (unresolved + not expired) whose path matches request_path exactly OR whose path is a propagating ancestor of request_path. The caller feeds the result into agentstategraph_taint::evaluate_access.
Source§

fn get_taint(&self, id: &str) -> Result<Option<Taint>, StorageError>

Fetch a taint by its id. Returns None if missing.
Source§

fn set_taint_commit_id( &self, id: &str, commit_id: &str, ) -> Result<(), StorageError>

Back-patch the commit_id onto a freshly-inserted taint after the repository has written the intent commit. A no-op if the taint is already resolved.

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Storage for T

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