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
impl SyncState
Sourcepub fn transcript(&self, conversation_id: &str) -> Vec<Turn>
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.
Sourcepub fn conversation_ids(&self) -> Vec<String>
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).
Sourcepub fn resume_messages(&self, conversation_id: &str) -> Vec<Message>
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
impl SyncState
Sourcepub fn log_entries(&self, surface_tag: &str) -> Vec<&FoldedRecord>
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).
Sourcepub fn replay<T, F>(&self, surface_tag: &str, init: T, apply: F) -> Twhere
F: FnMut(T, &FoldedRecord) -> T,
pub fn replay<T, F>(&self, surface_tag: &str, init: T, apply: F) -> Twhere
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.
Sourcepub fn intent(&self, agent_id: &str, run_id: &str) -> Option<&FoldedRecord>
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_run
— intent() 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.
Sourcepub fn committed_run(
&self,
agent_id: &str,
run_id: &str,
) -> Option<&FoldedRecord>
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.
Sourcepub fn committed_run_ids(&self, agent_id: &str) -> Vec<&str>
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”.
Sourcepub fn fencing_epoch(&self, agent_id: &str) -> Option<u64>
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.