Skip to main content

Journal

Struct Journal 

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

An append-only, in-memory journal of one run’s RunEvents.

Cheap to clone: clones share the same journal (one Arc layer inside), which is how node closures record model/tool calls into the same journal the executor is writing. Thread-safe; Send + Sync.

The journal stamps every event with its run_id/thread_id, the next sequence number, and a recorded_at read from its own Clock — so events recorded from inside nodes (whose code cannot see the executor’s clock) are still timestamped through the run’s determinism seam.

Implementations§

Source§

impl Journal

Source

pub fn new( run_id: impl Into<String>, thread_id: impl Into<String>, clock: Clock, ) -> Self

A fresh journal for run_id / thread_id, timestamping events from clock.

Source

pub fn from_snapshot(snapshot: JournalSnapshot, clock: Clock) -> Result<Self>

Rebuild a journal from a JournalSnapshot (e.g. a replay fixture).

The head hash is recomputed from the events rather than trusted from the snapshot, so a corrupted or edited fixture is detected here instead of deep inside a replay. Returns None-style failure as a crate::error::RustyError::Serialization when an event fails to serialize (not realistically possible for well-formed snapshots).

Source

pub fn run_id(&self) -> &str

The run this journal records.

Source

pub fn thread_id(&self) -> &str

The thread the run belongs to.

Source

pub fn clock(&self) -> &Clock

The clock events are timestamped from.

Source

pub fn record(&self, draft: EventDraft) -> String

Append one event and return its id ({run_id}:{seq}).

The journal assigns the sequence number and timestamp, promotes oversized payloads into the artifact map (replacing them with PayloadRef::Artifact references), and chains the head hash over the canonical serialization of the appended event.

Source

pub fn events(&self) -> Vec<RunEvent>

The recorded events in sequence order.

Source

pub fn len(&self) -> usize

Number of recorded events.

Source

pub fn is_empty(&self) -> bool

true when nothing has been recorded.

Source

pub fn head_hash(&self) -> String

The current head hash (chained SHA-256 over all recorded events).

Source

pub fn head_ref(&self) -> JournalRef

The journal head as a crate::record::JournalRef, for stamping into checkpoints.

Source

pub fn snapshot(&self) -> JournalSnapshot

A serde-complete export of the journal: every event plus the artifact payloads they reference. The unit a portable replay fixture is built from.

Bytes stay embedded by design: the fixture contract (self-contained, loadable anywhere) outranks the size optimization. Persistence paths that want the optimization use Journal::snapshot_externalized.

Source

pub async fn snapshot_externalized( &self, store: &dyn ArtifactStore, ) -> Result<JournalSnapshot>

Export the journal with its artifact payloads spilled to an external ArtifactStore: the snapshot records content addresses (JournalSnapshot::artifact_refs) instead of embedding bytes.

This is the persistence-path export (R0.7 wave 4): a server rewriting journal snapshots at every checkpoint boundary stores each oversized payload once per content, not once per snapshot — re-puts dedupe on the content address, so artifact-addressed retry traffic is cheap. Load with Journal::from_snapshot_with_store.

Source

pub async fn from_snapshot_with_store( snapshot: JournalSnapshot, store: &dyn ArtifactStore, clock: Clock, ) -> Result<Self>

Rebuild a journal from an externalized snapshot (Journal::snapshot_externalized): every referenced artifact is fetched through store — integrity-verified on read by the store’s contract — and re-embedded, after which the load is the ordinary hash-verified Journal::from_snapshot.

Source

pub fn resolve(&self, payload: &PayloadRef) -> Option<Value>

Resolve a PayloadRef to its value, looking through the artifact map. None for artifact references whose bytes are absent (a truncated snapshot — detectable via Journal::from_snapshot’s hash check).

Source

pub fn record_effect_receipt( &self, receipt: &EffectReceipt, parent: Option<String>, ) -> String

Journal an effect receipt (R0.6 Durable Work): the effect’s own confirmation of an Idempotent side effect, recorded as a RunEventKind::EffectReceipt event with the receipt as its output payload and parent as its causal parent — the task lifecycle event that completed the effect once task lifecycle journaling lands; until then, the run’s journal head is the honest parent (the receipt was caused by everything the run did before the task settled).

Recording here — one canonical shape, as with model/tool calls — is what lets JournalSnapshot::find_effect_receipt serve the receipt during replay instead of re-sending the effect.

Source

pub fn memory(&self, source: MemorySource) -> JournaledMemory

Bind a memory source to this journal (R0.8 Rusty Learn, wave 1): the governed-memory seam. The returned handle journals every read as RunEventKind::MemoryRead (Effect::ReadOnly, with the resolved query plus budget as the request and the assembly as the output) and every write as RunEventKind::MemoryWrite (Effect::Idempotent under the derived key), so exact replay serves the journaled assembly instead of re-querying the store.

Node closures capture the handle exactly the way they capture a Journal clone for recording model and tool calls; causal parentage comes from the invocation’s node-input event id (PARENT_EVENT_KEY).

Trait Implementations§

Source§

impl Clone for Journal

Source§

fn clone(&self) -> Journal

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 Journal

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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