Storage

Struct Storage 

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

High-level storage handle that encapsulates database and artifact store clients.

Implementations§

Source§

impl Storage

Source

pub async fn connect(config: StorageConfig) -> Result<Self>

Connects to Postgres, applies migrations, and provisions the artifact store.

Source

pub async fn connect_default() -> Result<Self>

Convenience helper for default configuration (env-driven DATABASE_URL).

Source

pub fn pool(&self) -> &Pool<Postgres>

Returns a borrowed connection pool for ad-hoc queries.

Source

pub fn object_store(&self) -> Arc<DynObjectStore>

Returns a handle to the configured object store.

Source

pub fn artifacts(&self) -> Arc<dyn ArtifactStore>

Returns the artifact store abstraction.

Source

pub async fn return_step_to_queue( &self, run_id: Uuid, step_id: Uuid, ) -> Result<()>

Releases a leased step back to the queue without incrementing attempt counters.

Source

pub async fn requeue_expired_leases( &self, limit: i64, ) -> Result<Vec<(Uuid, Uuid)>>

Requeues expired leases back to the queued state and returns affected step IDs.

Source

pub async fn defer_step_to_queue( &self, run_id: Uuid, step_id: Uuid, not_before: DateTime<Utc>, payload: Value, ) -> Result<()>

Source

pub async fn defer_step_to_queue_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, not_before: DateTime<Utc>, payload: Value, ) -> Result<()>

Source

pub async fn schedule_retry_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, attempt: i32, not_before: DateTime<Utc>, error_json: Value, ) -> Result<()>

Source

pub async fn insert_cost_ledger_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, attempt: i32, status: &str, reserved_tokens: i64, reserved_cost: f64, actual_tokens: Option<i64>, actual_cost: Option<f64>, ) -> Result<()>

Source

pub async fn insert_step_attempt_tx( &self, tx: &mut Transaction<'_, Postgres>, attempt: NewStepAttempt, ) -> Result<()>

Source

pub async fn append_run_event_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Option<Uuid>, kind: &str, payload: &Value, ) -> Result<()>

Source

pub async fn trigger_compensation_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, origin_step: Uuid, compensation_step: Uuid, ) -> Result<()>

Source

pub async fn fetch_unpublished_outbox( &self, limit: i64, ) -> Result<Vec<OutboxEvent>>

Returns unpublished outbox events up to limit, ordered by ID.

Source

pub async fn mark_outbox_published(&self, id: i64) -> Result<()>

Marks an outbox row as published by setting published_at to the current timestamp.

Source

pub async fn fetch_outbox_for_run_since( &self, run_id: Uuid, after_id: i64, limit: i64, ) -> Result<Vec<OutboxEvent>>

Returns outbox events for a run that were created after the given id.

Source

pub async fn fetch_last_outbox_event( &self, run_id: Uuid, ) -> Result<Option<OutboxEvent>>

Returns the most recent outbox event for a run, if any.

Source

pub async fn fetch_tap_offset( &self, run_id: Uuid, cursor_id: &str, ) -> Result<Option<i64>>

Fetch the last acknowledged offset for a subscription cursor, if present.

Source

pub async fn upsert_tap_offset( &self, run_id: Uuid, cursor_id: &str, offset: i64, ) -> Result<()>

Advance the stored offset for a subscription cursor.

Source

pub async fn apply_retention_policy( &self, cutoff: DateTime<Utc>, ) -> Result<RetentionStats>

Applies retention policy by scrubbing input/output payloads for stale runs.

Source

pub async fn try_consume_budget( &self, run_id: Uuid, tokens: i64, cost: f64, ) -> Result<BudgetResult>

Attempts to consume the requested budget; returns granted totals or denial.

Source

pub async fn fetch_budget(&self, run_id: Uuid) -> Result<Option<Budget>>

Fetches the current budget totals for a run, if configured.

Source

pub async fn fetch_steps_for_run(&self, run_id: Uuid) -> Result<Vec<Step>>

Returns all step rows for a run ordered by index.

Source

pub async fn mark_step_running( &self, run_id: Uuid, step_id: Uuid, worker_id: &str, input_snapshot: Option<&Value>, provider: Option<&str>, provider_version: Option<&str>, ) -> Result<()>

Marks a leased step as running for the provided worker.

Source

pub async fn update_step_estimate( &self, run_id: Uuid, step_id: Uuid, estimated_tokens: i64, estimated_cost: f64, ) -> Result<()>

Updates the stored budget estimate for a step.

Source

pub async fn update_step_status_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, status: StepStatus, attempt: Option<i32>, output_json: Option<Value>, error_json: Option<Value>, input_snapshot: Option<Value>, output_snapshot: Option<Value>, checkpoint: Option<Value>, provider: Option<&str>, provider_version: Option<&str>, ) -> Result<()>

Updates the status, snapshot metadata, and output fields for a step.

Source

pub async fn fetch_step_attempts_for_run( &self, run_id: Uuid, ) -> Result<Vec<StepAttempt>>

Source

pub async fn update_step_usage_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, actual_tokens: Option<i64>, actual_cost: Option<f64>, ) -> Result<()>

Persists the actual resource usage recorded for a step.

Source

pub async fn reconcile_budget_usage_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, tokens_delta: i64, cost_delta: f64, ) -> Result<()>

Adjusts budget totals based on the difference between reserved and actual usage.

Source

pub async fn insert_run(&self, run: NewRun) -> Result<Uuid>

Inserts a run row with deterministic state materialization.

Source

pub async fn insert_run_with_steps( &self, run: NewRun, steps: &[NewStep], edges: &[(Uuid, Uuid)], ) -> Result<Uuid>

Inserts a run and its associated steps within a single transaction.

Source

pub async fn unlock_successors_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, ) -> Result<Vec<Uuid>>

Decrements dependency counters for successors and queues newly-ready steps.

Source

pub async fn skip_downstream_steps_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, failed_step_id: Uuid, ) -> Result<Vec<Uuid>>

Marks all downstream blocked steps as skipped when a dependency fails.

Source

pub async fn refresh_run_status_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, ) -> Result<(RunStatus, RunStatus)>

Recomputes the run status based on current step outcomes.

Source

pub async fn insert_step(&self, step: NewStep) -> Result<()>

Inserts a step row tied to a run’s DAG.

Source

pub async fn fetch_run(&self, run_id: Uuid) -> Result<Option<Run>>

Fetches a single run record by ID.

Source

pub async fn update_run_input_ctx( &self, run_id: Uuid, input_ctx: Value, ) -> Result<()>

Source

pub async fn update_run_artifact_transparency( &self, run_id: Uuid, artifact_key: &str, transparency: Value, ) -> Result<()>

Updates the transparency receipt embedded in a run-level artifact entry.

Source

pub async fn update_step_artifact_transparency( &self, run_id: Uuid, step_id: Uuid, artifact_key: &str, transparency: Value, ) -> Result<()>

Updates the transparency receipt for a step-level artifact stored in steps.output_json.

Source

pub async fn update_run_input_ctx_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, input_ctx: Value, ) -> Result<()>

Source

pub async fn set_run_status( &self, run_id: Uuid, status: RunStatus, ) -> Result<()>

Source

pub async fn set_run_status_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, status: RunStatus, ) -> Result<()>

Source

pub async fn fetch_run_tenant(&self, run_id: Uuid) -> Result<Option<String>>

Returns the tenant label for the given run, if one is set.

Source

pub async fn enforce_tenant_quota( &self, tenant: &str, tokens: i64, cost: f64, ) -> Result<()>

Ensures the provided tenant does not exceed the configured daily quota.

Source

pub async fn record_billing_usage_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, tokens: i64, cost: f64, ) -> Result<()>

Records billing usage for a run inside an existing transaction.

Source

pub async fn list_recent_runs(&self, limit: i64) -> Result<Vec<Run>>

Lists recent runs ordered by creation time.

Source

pub async fn fetch_run_by_idempotency_key( &self, idempotency_key: &str, ) -> Result<Option<Run>>

Fetches a run by idempotency key if present.

Source

pub async fn upsert_artifact(&self, artifact: NewArtifact) -> Result<()>

Persists artifact metadata while blob bytes live in the object store.

Source

pub async fn enqueue_outbox_event( &self, tx: &mut Transaction<'_, Postgres>, event: NewOutboxEvent, ) -> Result<i64>

Appends an outbox event within an existing transaction for exactly-once delivery.

Source

pub async fn claim_queued_steps( &self, limit: i64, worker_id: &str, ) -> Result<Vec<Step>>

Claims queued steps using FOR UPDATE SKIP LOCKED for safe parallel scheduling.

Source

pub async fn revert_step_to_queue( &self, run_id: Uuid, step_id: Uuid, ) -> Result<()>

Source

pub async fn revert_step_to_queue_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, ) -> Result<()>

Source

pub async fn update_step_spec( &self, run_id: Uuid, step_id: Uuid, spec_json: Value, ) -> Result<()>

Source

pub async fn update_step_spec_tx( &self, tx: &mut Transaction<'_, Postgres>, run_id: Uuid, step_id: Uuid, spec_json: Value, ) -> Result<()>

Source§

impl Storage

Source

pub async fn upsert_eval_scenario( &self, name: &str, description: Option<&str>, spec: Value, ) -> Result<Uuid>

Registers or updates an evaluation scenario definition.

Source

pub async fn fetch_eval_scenario_by_name( &self, name: &str, ) -> Result<Option<EvalScenario>>

Fetches an evaluation scenario by its unique name.

Source

pub async fn list_eval_scenarios(&self) -> Result<Vec<EvalScenario>>

Lists all evaluation scenarios ordered by name.

Source

pub async fn latest_eval_result( &self, scenario_id: Uuid, ) -> Result<Option<EvalResult>>

Returns the latest evaluation result for a scenario, if any.

Source

pub async fn list_eval_results( &self, scenario_id: Uuid, limit: i64, ) -> Result<Vec<EvalResult>>

Lists evaluation results for a scenario, newest first.

Source

pub async fn insert_eval_result( &self, scenario_id: Uuid, run_id: Uuid, outcome: &str, metrics: Value, ) -> Result<EvalResult>

Inserts or replaces an evaluation result for the given scenario/run pair.

Source

pub async fn insert_change_gate( &self, gate: NewChangeGate, ) -> Result<ChangeGate>

Records a ChangeOps gate decision and returns the stored record.

Source

pub async fn update_change_gate_metadata( &self, gate_id: Uuid, metadata: Value, ) -> Result<()>

Replaces the metadata JSON stored for a change gate decision.

Source

pub async fn list_change_gates_for_change( &self, change_id: &str, limit: i64, ) -> Result<Vec<ChangeGate>>

Fetches the latest gate decision for a change id (limited by limit).

Source

pub async fn fetch_change_gate( &self, gate_id: Uuid, ) -> Result<Option<ChangeGate>>

Retrieves a specific gate decision by gate id.

Source

pub async fn enqueue_transparency_job( &self, payload: TransparencyJobPayload, ) -> Result<i64>

Enqueues a transparency job for asynchronous publishing.

Source

pub async fn fetch_pending_transparency_jobs( &self, limit: i64, ) -> Result<Vec<TransparencyJob>>

Returns pending transparency jobs up to the requested limit.

Source

pub async fn fetch_transparency_jobs_by_ids( &self, job_ids: &[i64], ) -> Result<Vec<TransparencyJob>>

Fetches transparency jobs by explicit identifiers.

Source

pub async fn mark_transparency_job_processed( &self, job_id: i64, receipt: Value, ) -> Result<()>

Records a successful transparency job along with the receipt payload.

Source

pub async fn mark_transparency_job_failed( &self, job_id: i64, error: String, ) -> Result<()>

Marks a transparency job failure so the writer can retry later.

Source

pub async fn insert_change_gate_followup( &self, followup: NewChangeGateFollowup, ) -> Result<ChangeGateFollowup>

Records a follow-up acknowledgement for a gate.

Source

pub async fn fetch_change_gate_followups( &self, gate_id: Uuid, ) -> Result<Vec<ChangeGateFollowup>>

Fetches all follow-up records for a gate in chronological order.

Trait Implementations§

Source§

impl Clone for Storage

Source§

fn clone(&self) -> Storage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl RunStore for Storage

Source§

fn insert_run_with_steps<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, new_run: NewRun, steps: &'life1 [NewStep], edges: &'life2 [(Uuid, Uuid)], ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn fetch_run<'life0, 'async_trait>( &'life0 self, run_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<Run>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn fetch_steps_for_run<'life0, 'async_trait>( &'life0 self, run_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Vec<Step>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more