Skip to main content

SyncState

Struct SyncState 

Source
pub struct SyncState {
    pub logs: BTreeMap<String, BTreeMap<String, FoldedRecord>>,
    pub registries: BTreeMap<String, BTreeMap<String, FoldedRecord>>,
    pub intents: BTreeMap<String, IntentAgent>,
}
Expand description

The materialized read model a full op-set folds to. On-disk files (conversations/*.jsonl, declagents.json, …) are projections of this (the proposal’s “files are projections” reframe); B4’s checkpoint is a serialized SyncState at a frontier.

Fields§

§logs: BTreeMap<String, BTreeMap<String, FoldedRecord>>

Grow-only tier: surface tag → stable key → record (union; first-writer-wins on a key collision).

§registries: BTreeMap<String, BTreeMap<String, FoldedRecord>>

Registry tier: surface tag → record id → LWW winner.

§intents: BTreeMap<String, IntentAgent>

Leased execution-intent tier (B5): agent_id → its fenced intent ledger. Folded from crate::oplog::Surface::Intent ops with epoch fencing applied deterministically. #[serde(default)] so a pre-B5 serialized state still parses.

Implementations§

Source§

impl SyncState

Source

pub fn transcript(&self, conversation_id: &str) -> Vec<Turn>

The ordered, role-threaded transcript for one conversation — the causally (hlc, op_id)-ordered Vec<Turn> (B2). This is the raw projection (every folded turn, in order); SyncState::resume_messages is the provider-valid Message view. Turns whose payload names no conversation_id belong to DEFAULT_CONVERSATION; tombstone stubs are skipped. Order-independent of delivery, byte-identical on every device that folded the same op-set.

Source

pub fn conversation_ids(&self) -> Vec<String>

Every conversation id present in the folded state, in stable sorted order (includes DEFAULT_CONVERSATION when unnamed turns exist).

Source

pub fn resume_messages(&self, conversation_id: &str) -> Vec<Message>

Reconstruct the runtime’s multi-turn conversation state: the ordered, provider-valid car_inference_types::Message sequence car-inference’s multi-turn path replays to continue the conversation (B2’s resume bridge). The raw transcript is repaired first, so the result never contains an invalid role adjacency or an orphan/dangling tool exchange. The daemon/memgine adoption is B6.

Source§

impl SyncState

Source

pub fn log_entries(&self, surface_tag: &str) -> Vec<&FoldedRecord>

A grow-only surface’s entries in canonical (hlc, op_id) order — the deterministic total order every device agrees on (used by the routing replay, and the order B2’s transcript materialization will consume).

Source

pub fn replay<T, F>(&self, surface_tag: &str, init: T, apply: F) -> T
where F: FnMut(T, &FoldedRecord) -> T,

Replay an order-sensitive fold (e.g. the routing EMA) over a surface’s canonically-ordered entries: fold(routing) = observations.sorted_by(hlc).fold(empty_store, apply_ema). The apply function is injected — execution (and the EMA itself) stays out of this crate, like the other pure cores.

Source

pub fn intent(&self, agent_id: &str, run_id: &str) -> Option<&FoldedRecord>

The “who holds now” leased intent for a run (terminal-immune, pending-fenced) — NOT the idempotency oracle. None when the agent has no such run, or the run is a pending fenced by a later, higher-epoch holder. A committed run is terminal-immune and stays visible here.

For “did this run already execute?” use SyncState::committed_runintent() can return None/pending for a run that actually committed under a prior epoch, which would cause a double-execution if trusted as the idempotency check.

Source

pub fn committed_run( &self, agent_id: &str, run_id: &str, ) -> Option<&FoldedRecord>

The idempotency oracle (B5): the committed record for a run, if it has ever committed for this agent. Fence-independent and keep-all — unaffected by epoch bumps and by compaction — so this is the correct “did run_id already run?” lookup before dispatching a side effect. None iff no committed intent for (agent_id, run_id) exists.

Source

pub fn committed_run_ids(&self, agent_id: &str) -> Vec<&str>

Every run_id this agent has committed (the keep-all oracle’s keys, with the id: prefix stripped) — for a failover executor scanning “what has already run”.

Source

pub fn fencing_epoch(&self, agent_id: &str) -> Option<u64>

The agent’s current fencing epoch — the max lease epoch its intents carry — or None if it has none. Pending intents below this are fenced.

Trait Implementations§

Source§

impl Clone for SyncState

Source§

fn clone(&self) -> SyncState

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 SyncState

Source§

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

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

impl Default for SyncState

Source§

fn default() -> SyncState

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

impl<'de> Deserialize<'de> for SyncState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for SyncState

Source§

fn eq(&self, other: &SyncState) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SyncState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SyncState

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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