Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }

Implementations§

Source§

impl Store

Source

pub fn open(path: &Path, now_ms: i64) -> Result<Self, StoreError>

Opens (creating if needed) the database and migrates it to the current schema version. The daemon is the only writer; now_ms is injected so decision-adjacent timestamps never read the wall clock here.

Source

pub fn insert_local_project( &self, id: &str, file_path: &str, title: &str, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn upsert_local_project( &self, id: &str, file_path: &str, title: &str, now_ms: i64, ) -> Result<(), StoreError>

Inserts or refreshes a project indexed from a committed file. Startup and reindex call this for every configured project file, so it must tolerate rows that already exist.

Source

pub fn project_exists(&self, id: &str) -> Result<bool, StoreError>

Source

pub fn project(&self, id: &str) -> Result<Option<ProjectRecord>, StoreError>

Source

pub fn insert_local_ticket( &self, id: &str, project_id: &str, file_path: &str, name: &str, blocked_by: &[String], worktree: &str, target: Option<&str>, model: Option<&str>, effort: Option<&str>, flow: &str, state: TicketState, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn update_local_ticket( &self, id: &str, name: &str, blocked_by: &[String], worktree: &str, target: Option<&str>, model: Option<&str>, effort: Option<&str>, flow: &str, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn update_ticket_execution( &self, id: &str, target: Option<&str>, model: Option<&str>, effort: Option<&str>, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn backfill_ticket_targets( &self, default_target: &str, now_ms: i64, ) -> Result<usize, StoreError>

Version-two rows predate target snapshots. Once a repository has a target configuration, persist its default before dispatch can observe those rows.

Source

pub fn ticket(&self, id: &str) -> Result<Option<TicketRecord>, StoreError>

Source

pub fn ticket_by_file( &self, file_path: &str, ) -> Result<Option<TicketRecord>, StoreError>

Source

pub fn tickets(&self) -> Result<Vec<TicketRecord>, StoreError>

Source

pub fn tickets_for_project( &self, project_id: &str, ) -> Result<Vec<TicketRecord>, StoreError>

Source

pub fn ticket_dependencies( &self, ) -> Result<BTreeMap<String, Vec<String>>, StoreError>

Source

pub fn ticket_ids(&self) -> Result<Vec<String>, StoreError>

Source

pub fn local_ticket_files(&self) -> Result<Vec<LocalTicketFile>, StoreError>

Source

pub fn ticket_is_referenced(&self, id: &str) -> Result<bool, StoreError>

Whether run history, a lease, an activation, or another ticket’s blocker list still points at this row; deleting it would then violate a foreign key or orphan run evidence.

Source

pub fn delete_ticket(&self, id: &str) -> Result<(), StoreError>

Source

pub fn mark_ticket_missing( &self, id: &str, now_ms: i64, ) -> Result<(), StoreError>

Stamps a ticket whose committed file has disappeared. The stamp keeps the row out of selection without disturbing its state; an existing stamp is preserved so the deletion clock starts at the first pass.

Source

pub fn clear_ticket_missing( &self, id: &str, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn ticket_state(&self, id: &str) -> Result<Option<String>, StoreError>

Source

pub fn set_ticket_hold( &self, id: &str, state: TicketState, now_ms: i64, ) -> Result<String, StoreError>

Applies the operator-controlled ready/held side-state transition. The conditional update prevents an override from stealing a live claim or rewriting an evidence-derived outcome.

Source

pub fn retry_ticket(&self, id: &str, now_ms: i64) -> Result<String, StoreError>

Returns a failed ticket to the ready queue and starts its attempt counter over. Other states remain evidence-derived and immutable here.

Source

pub fn insert_activation( &self, activation: &NewActivation<'_>, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn insert_activation_filter( &self, activation_id: &str, ticket_id: &str, ) -> Result<(), StoreError>

Source

pub fn queued_dispatchable_activations( &self, ) -> Result<Vec<QueuedActivation>, StoreError>

Queued activations the dispatcher may act on right now, oldest first. Time-gated kinds (at, every, overnight) stay invisible until the scheduler grows clock support.

Source

pub fn select_ready_ticket( &self, activation: &QueuedActivation, ) -> Result<Option<String>, StoreError>

Deterministic ready-work selection within an activation’s scope: oldest registration first, ticket ID as the tiebreak. --only filters apply when the activation has filter rows.

Source

pub fn complete_activation( &self, id: &str, now_ms: i64, ) -> Result<(), StoreError>

Source

pub fn next_run_ordinal(&self) -> Result<i64, StoreError>

Returns the next ordinal for allocating a run ID; runs are never deleted and only the dispatcher allocates.

Source

pub fn mark_run_running( &self, run_id: &str, branch: &str, worktree_path: &str, pid: u32, pid_start_time: Option<i64>, process_group_id: u32, worker_token: &str, worker_socket_path: &str, now_ms: i64, ) -> Result<(), StoreError>

Records a successful launch: the run turns running and carries the worktree, branch, and durable process identity.

Source

pub fn finish_run( &mut self, run_id: &str, ticket_id: &str, exit_code: Option<i32>, outcome: Outcome, evidence: &[EvidenceRecord], stage: Option<&StageRecord>, now_ms: i64, ) -> Result<(), StoreError>

Terminates a run in one transaction: the raw exit and derived outcome land on the run, evidence and stage rows are appended, the lease is freed, and the ticket moves to its terminal state or back to ready when cancellation or recovery releases it.

Source

pub fn record_cancel_requested( &self, run_id: &str, now_ms: i64, ) -> Result<(), StoreError>

Durably records an operator’s cancellation intent, idempotently: the dedupe key makes a repeated cancel a no-op rather than new evidence.

Source

pub fn cancellation_requested(&self, run_id: &str) -> Result<bool, StoreError>

Whether cancellation intent was recorded for the run, so an exit event racing the cancel still resolves to Cancelled.

Source

pub fn insert_note( &self, id: &str, run_id: &str, text: &str, now_ms: i64, ) -> Result<(), StoreError>

Appends a worker’s advisory note. The agent’s only write: it records text against the run and moves nothing.

Source

pub fn notes_for_run(&self, run_id: &str) -> Result<Vec<String>, StoreError>

Notes recorded against one run, in the order they arrived.

Source

pub fn notes_for_project( &self, project_id: &str, ) -> Result<Vec<ProjectNote>, StoreError>

Source

pub fn commit_evidence_for_project( &self, project_id: &str, ) -> Result<Vec<ProjectCommitEvidence>, StoreError>

Source

pub fn next_note_ordinal(&self) -> Result<i64, StoreError>

Source

pub fn run_evidence( &self, run_id: &str, ) -> Result<Vec<(String, String)>, StoreError>

Evidence rows for one run in observation order, as (kind, data_json).

Source

pub fn abort_claim( &mut self, run_id: &str, ticket_id: &str, now_ms: i64, ) -> Result<(), StoreError>

Rolls back a claim whose launch failed before a process existed: the lease is released, the run is closed, and the ticket returns to ready. The consumed attempt is kept as evidence of the try.

Source

pub fn run(&self, id: &str) -> Result<Option<RunRecord>, StoreError>

Source

pub fn active_run_for_ticket( &self, ticket_id: &str, ) -> Result<Option<String>, StoreError>

Source

pub fn active_runs(&self) -> Result<Vec<ActiveRun>, StoreError>

Runs that have started and not yet exited, oldest first.

Source

pub fn queued_ticket_activation( &self, ticket_id: &str, kind: ActivationKind, ) -> Result<Option<String>, StoreError>

Finds a still-queued activation of kind scoped to one ticket, used to keep reposting the same file idempotent.

Source

pub fn next_activation_ordinal(&self) -> Result<i64, StoreError>

Returns the next ordinal for allocating an activation ID. Only the single-threaded dispatcher allocates IDs, so count-plus-one cannot race with itself, and activations are never deleted.

Source

pub fn claim_ticket( &mut self, claim: &ClaimRequest<'_>, now_ms: i64, ) -> Result<ClaimedRun, StoreError>

Claims a ready ticket for one run in a single transaction. The conditional update plus the primary key on leases.ticket_id are the durable guards against a double claim.

Source

pub fn renew_lease( &mut self, ticket_id: &str, run_id: &str, lease_ms: i64, now_ms: i64, ) -> Result<i64, StoreError>

Renews the lease that run_id holds on ticket_id, returning the new expiry. Renewal is strict: an expired lease cannot be renewed, so once recovery treats expiry as “run is lost” a revived run can never resurrect a lease that recovery may be reclaiming.

Source

pub fn paused(&self) -> Result<bool, StoreError>

Source

pub fn set_paused(&self, paused: bool, now_ms: i64) -> Result<(), StoreError>

Source

pub fn ticket_counts(&self) -> Result<TicketCounts, StoreError>

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Sync for Store

§

impl Send for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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