Skip to main content

Store

Struct Store 

Source
pub struct Store<L: LogBackend = CanonicalLog> { /* private fields */ }
Expand description

The workspace store — a LogBackend plus the Pipeline that produces its records. The default backend is CanonicalLog (real filesystem); tests and crash-injection harnesses parameterize with their own LogBackend implementation.

Implementations§

Source§

impl Store<CanonicalLog>

Source

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

Open or create a workspace at path. Convenience constructor that wires a real filesystem-backed CanonicalLog.

§Errors
  • StoreError::Log on any filesystem / I/O failure during open, scan, or truncate.
Source

pub fn open_in_workspace( data_root: impl AsRef<Path>, workspace_id: WorkspaceId, ) -> Result<Self, StoreError>

Open or create a workspace-partitioned store under a shared data_root. The log lands at data_root/<workspace_hex>/canonical.log per workspace-model.md § 4.2. Parent directories are created on demand.

Two Stores opened under the same data_root but different WorkspaceId values land in disjoint directories — per spec § 2 the partition is structural, not policy-enforced.

§Errors
Source§

impl<L: LogBackend> Store<L>

Source

pub fn from_backend(log: L) -> Result<Self, StoreError>

Construct a Store over an arbitrary LogBackend. On open, crash-shaped orphan bytes past the last durable CHECKPOINT are truncated (spec § 10 recovery step), non-recoverable tail corruption is rejected without truncation, and SYMBOL_* events from the committed log are replayed into the pipeline’s symbol table so workspace state fully reconstructs across process restarts.

§Errors
Source

pub fn log_len(&self) -> u64

Committed log length in bytes.

Source

pub fn pipeline(&self) -> &Pipeline

Read-only view of the underlying pipeline. Used by callers that want to issue read-path queries (execute_query) or inspect pipeline state without owning the whole store.

Source

pub fn pipeline_mut(&mut self) -> &mut Pipeline

Mutable view of the pipeline. Exposed so tests and downstream callers can call execute_query (which needs &self, not &mut self, but the mut accessor keeps the door open for future read-path methods that do require exclusive borrow).

Source

pub fn commit_batch( &mut self, input: &str, now: ClockTime, ) -> Result<EpisodeId, StoreError>

Compile a batch of agent input and commit it atomically.

The two phases run under the workspace’s single-writer invariant:

  1. Pipeline compiles the input into a Vec<CanonicalRecord>. On pipeline error the pipeline’s in-memory state is already auto-rolled-back (per Pipeline::compile_batch’s clone-on- write contract) and no log bytes have been written.
  2. Records + a CHECKPOINT marker are appended to the log.
  3. The log is fsynced. On success the batch is durable and the new Episode ID is returned; on fsync failure the log is truncated to its pre-batch offset and the pipeline’s in-memory state is restored from a snapshot taken before step 1.
§Errors
  • StoreError::Pipeline if parse / bind / semantic / emit rejected the batch. In-memory state is unchanged; log is untouched.
  • StoreError::Log if the append / sync / truncate sequence failed at any step. In-memory pipeline state is restored to its pre-batch snapshot; log is truncated back to pre-batch.
Source

pub fn commit_batch_with_metadata( &mut self, input: &str, now: ClockTime, metadata: &EpisodeMetadata, ) -> Result<EpisodeId, StoreError>

Commit a batch and attach agent-visible Episode metadata (label, parent_episode, retracts) per episode-semantics.md § 4.2 / § 5. Same commit semantics as Self::commit_batch; when metadata is non-empty, an EpisodeMeta canonical record is emitted immediately before the CHECKPOINT.

§Errors

Same as Self::commit_batch. If metadata.label exceeds the 256-byte cap (spec § 4.3) the commit fails with a StoreError::InvalidEpisodeMetadata before any log writes.

Auto Trait Implementations§

§

impl<L> Freeze for Store<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for Store<L>
where L: RefUnwindSafe,

§

impl<L> Send for Store<L>
where L: Send,

§

impl<L> Sync for Store<L>
where L: Sync,

§

impl<L> Unpin for Store<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for Store<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for Store<L>
where L: UnwindSafe,

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