Skip to main content

JournalStore

Struct JournalStore 

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

JournalStore wraps RunStore with replay semantics.

Thread safety: All public methods take &self (interior mutability via RwLock). The underlying checkpoint data is protected by a single writer lock.

Usage lifecycle: new() → init_run() → cache_agent()* → flush() 或: open() → has_completed()/get_cached() → workflow resume logic

Implementations§

Source§

impl JournalStore

Source

pub fn new(run_dir: &Path) -> Result<Self, JournalError>

Create a new journal store at the given directory. Initializes the underlying RunStore and creates an empty cache index.

Source

pub fn with_event_sender(self, tx: EventSender) -> Self

Attach an event sender for broadcasting journal updates.

Source

pub fn init_run(&self, run_id: RunId, task: &str) -> Result<(), JournalError>

Initialize a new run in the journal.

Source

pub fn init_run_with_meta( &self, run_id: RunId, task: &str, workflow_meta: Value, ) -> Result<(), JournalError>

Initialize a new run with declarative workflow metadata.

Source

pub fn open(&self, run_id: RunId) -> Result<RunCheckpoint, JournalError>

Open an existing run and rebuild the cache index from persisted data.

This is the entry point for --resume. It:

  1. Loads the checkpoint from disk
  2. Rebuilds the in-memory cache_index from agent_results
  3. Returns the checkpoint for the caller to inspect
Source

pub fn cache_agent( &self, cache_key: &AgentCacheKey, agent_id: AgentId, phase_id: PhaseId, status: AgentStatus, output: Value, findings: Vec<Finding>, tokens: TokenUsage, ) -> Result<AgentCacheKey, JournalError>

Cache an agent’s result in the journal.

Called by the scheduler after an agent completes successfully or fails with a non-retryable error. The result is persisted to disk immediately (via append_event → update_from_event → write_checkpoint_to_disk).

Source

pub fn record_result( &self, cache_key: &AgentCacheKey, agent_id: AgentId, phase_id: PhaseId, status: AgentStatus, output: Value, findings: Vec<Finding>, tokens: TokenUsage, )

Record an agent’s output for resume replay, keyed by cache_key.

Unlike [cache_agent], this does not append an AgentDone event, so it never double-counts tokens against the event-driven checkpoint totals. It only upserts the checkpoint entry (preserving cache_key_hash and the structured output) and refreshes the in-memory cache index. Called by the Lua SDK after an agent completes during a live run.

Source

pub fn store(&self) -> Arc<RunStore>

Access the underlying run store (shared persistence engine). Allows the CLI to route the scheduler event stream through the same RunStore instance the journal uses, avoiding split-brain checkpoints.

Source

pub fn append_event(&self, event: &AgentEvent) -> Result<(), JournalError>

Append an event to the underlying run store (event log + checkpoint).

Source

pub fn has_completed(&self, cache_key: &AgentCacheKey) -> bool

Check if an agent with the given cache key has already completed. Used by the Lua SDK’s agent() function before submitting to the scheduler.

Source

pub fn get_cached(&self, cache_key: &AgentCacheKey) -> Option<AgentResultCache>

Get cached result for an agent. Returns None if the agent hasn’t completed yet.

Source

pub fn completed_keys(&self) -> Vec<AgentCacheKey>

Get list of all completed agent cache keys. Useful for debugging and progress reporting.

Source

pub fn get_checkpoint(&self) -> Option<RunCheckpoint>

Get the underlying checkpoint (read-only snapshot).

Source

pub fn flush(&self) -> Result<(), JournalError>

Flush all pending data to disk.

Source

pub fn cancel(&self) -> Result<(), JournalError>

Mark the run as cancelled.

Trait Implementations§

Source§

impl Debug for JournalStore

Source§

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

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

impl JournalCallback for JournalStore

Source§

fn on_agent_done<'life0, 'async_trait>( &'life0 self, agent_id: AgentId, phase_id: PhaseId, status: AgentStatus, output: Value, tokens: TokenUsage, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when an agent completes (success or non-retryable failure).

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