Skip to main content

WorkingMemory

Struct WorkingMemory 

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

Key-prefixed scratchpad. Stores (k, v) pairs under {scope_prefix}{k} as Episodes on the Episode source field.

Implementations§

Source§

impl WorkingMemory

Source

pub fn new( lunaris: Arc<Lunaris>, scope: Scope, scope_prefix: impl Into<String>, ) -> Self

Construct a new scratchpad bound to scope (RFC 0001 partition key) and scope_prefix (source-key namespace). The two concepts are orthogonal: scope partitions the KV / FT keyspace, while scope_prefix namespaces the source field on each Episode so a single scope can host multiple WorkingMemory instances (e.g., "helios:fs/" vs "chat:user-42/").

Source

pub async fn write(&self, k: &str, v: Value) -> Result<Lsn, LunarisError>

Write (k, v) under {scope_prefix}{k} as an Episode.

Source

pub async fn write_dated( &self, k: &str, v: Value, t_ref: DateTime<Utc>, ) -> Result<Lsn, LunarisError>

Self::write with the payload’s real-world reference time stamped as Episode::t_ref.

t_ref is the date the CONTENT is from (a chat session’s date, a document’s authored date) — distinct from the ingest-time HLC the clock stamps on bt. Graph-ON ingest threads it into the extraction prompt as REFERENCE_TIME so extracted valid_from/valid_to dates are grounded in the content’s timeline instead of the model’s “today” (Mechanism B, 2026-07-29 LME diagnosis).

Source

pub async fn read(&self, k: &str) -> Result<Option<Value>, LunarisError>

Read the value for k scoped under scope_prefix, if present.

Recovers the VERBATIM value from the parent Episode content, NOT from the lossy chunk text (the markdown chunker’s smart-punctuation pass rewrites quotes / dashes and corrupts JSON values — see Self::recover_value).

Source

pub async fn grep( &self, pattern: &str, ) -> Result<Vec<(String, Value)>, LunarisError>

Return all (source, value) pairs whose source starts with {scope_prefix}{pattern}. Values are recovered verbatim from the parent Episode content (see Self::recover_value).

Source

pub async fn consolidate(&self) -> Result<ConsolidationReport, LunarisError>

Phase 9.1 Plan 01 Task 3 — run one consolidation pass scoped to self.scope_prefix.

§Foreign-event preservation

drain_consolidate_events subscribes to CONSOLIDATE_TOPIC and consumes ALL pending events for the scope in one pass — it is not prefix-aware. Without an explicit re-queue step, calling consolidate_scoped(Some(prefix)) on the drained batch silently drops the non-matching (“foreign”) events: they are consumed from the consumer-group queue and never seen by a subsequent pass (ADD task consolidate-prefix-drop).

Fix: after draining, partition events by source.starts_with(scope_prefix). Matching events are forwarded to consolidate_scoped (which therefore receives an already-filtered batch and must NOT double-filter — hence None prefix in the call). Foreign events are re-published verbatim to CONSOLIDATE_TOPIC so that the next consolidate_unfiltered (or the background worker) can pick them up. A publish error on re-queue is loud-not-fatal: the call still returns Ok with the matching report (matching consolidation already happened and its result must not be discarded).

Source

pub async fn consolidate_unfiltered( &self, ) -> Result<ConsolidationReport, LunarisError>

Whole-scope variant of Self::consolidate: drains and consolidates ALL pending events for the scope, ignoring self.scope_prefix.

The drain is scope-wide either way; consolidate_scoped(Some(prefix)) then FILTERS the drained events and the non-matching ones are already consumed from the queue — dropped, not re-queued. Callers that cannot tolerate that loss (e.g. the MCP session-handover, which runs implicitly and must not eat other namespaces’ pending events) use this variant; it consolidates exactly what the background worker would.

Trait Implementations§

Source§

impl Clone for WorkingMemory

Source§

fn clone(&self) -> WorkingMemory

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