pub struct Store { /* private fields */ }Implementations§
Source§impl Store
impl Store
Sourcepub fn open(path: &Path, now_ms: i64) -> Result<Self, StoreError>
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.
pub fn insert_local_project( &self, id: &str, file_path: &str, title: &str, now_ms: i64, ) -> Result<(), StoreError>
Sourcepub fn upsert_local_project(
&self,
id: &str,
file_path: &str,
title: &str,
now_ms: i64,
) -> Result<(), StoreError>
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.
pub fn project_exists(&self, id: &str) -> Result<bool, StoreError>
pub fn project(&self, id: &str) -> Result<Option<ProjectRecord>, StoreError>
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>
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>
pub fn update_ticket_execution( &self, id: &str, target: Option<&str>, model: Option<&str>, effort: Option<&str>, now_ms: i64, ) -> Result<(), StoreError>
Sourcepub fn backfill_ticket_targets(
&self,
default_target: &str,
now_ms: i64,
) -> Result<usize, StoreError>
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.
pub fn ticket(&self, id: &str) -> Result<Option<TicketRecord>, StoreError>
pub fn ticket_by_file( &self, file_path: &str, ) -> Result<Option<TicketRecord>, StoreError>
pub fn tickets(&self) -> Result<Vec<TicketRecord>, StoreError>
pub fn tickets_for_project( &self, project_id: &str, ) -> Result<Vec<TicketRecord>, StoreError>
pub fn ticket_dependencies( &self, ) -> Result<BTreeMap<String, Vec<String>>, StoreError>
pub fn ticket_ids(&self) -> Result<Vec<String>, StoreError>
pub fn local_ticket_files(&self) -> Result<Vec<LocalTicketFile>, StoreError>
Sourcepub fn ticket_is_referenced(&self, id: &str) -> Result<bool, StoreError>
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.
pub fn delete_ticket(&self, id: &str) -> Result<(), StoreError>
Sourcepub fn mark_ticket_missing(
&self,
id: &str,
now_ms: i64,
) -> Result<(), StoreError>
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.
pub fn clear_ticket_missing( &self, id: &str, now_ms: i64, ) -> Result<(), StoreError>
pub fn ticket_state(&self, id: &str) -> Result<Option<String>, StoreError>
Sourcepub fn set_ticket_hold(
&self,
id: &str,
state: TicketState,
now_ms: i64,
) -> Result<String, StoreError>
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.
Sourcepub fn retry_ticket(&self, id: &str, now_ms: i64) -> Result<String, StoreError>
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.
pub fn insert_activation( &self, activation: &NewActivation<'_>, now_ms: i64, ) -> Result<(), StoreError>
pub fn insert_activation_filter( &self, activation_id: &str, ticket_id: &str, ) -> Result<(), StoreError>
Sourcepub fn queued_dispatchable_activations(
&self,
) -> Result<Vec<QueuedActivation>, StoreError>
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.
Sourcepub fn select_ready_ticket(
&self,
activation: &QueuedActivation,
) -> Result<Option<String>, StoreError>
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.
pub fn complete_activation( &self, id: &str, now_ms: i64, ) -> Result<(), StoreError>
Sourcepub fn next_run_ordinal(&self) -> Result<i64, StoreError>
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn record_cancel_requested(
&self,
run_id: &str,
now_ms: i64,
) -> Result<(), StoreError>
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.
Sourcepub fn cancellation_requested(&self, run_id: &str) -> Result<bool, StoreError>
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.
Sourcepub fn insert_note(
&self,
id: &str,
run_id: &str,
text: &str,
now_ms: i64,
) -> Result<(), StoreError>
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.
Sourcepub fn notes_for_run(&self, run_id: &str) -> Result<Vec<String>, StoreError>
pub fn notes_for_run(&self, run_id: &str) -> Result<Vec<String>, StoreError>
Notes recorded against one run, in the order they arrived.
pub fn notes_for_project( &self, project_id: &str, ) -> Result<Vec<ProjectNote>, StoreError>
pub fn commit_evidence_for_project( &self, project_id: &str, ) -> Result<Vec<ProjectCommitEvidence>, StoreError>
pub fn next_note_ordinal(&self) -> Result<i64, StoreError>
Sourcepub fn run_evidence(
&self,
run_id: &str,
) -> Result<Vec<(String, String)>, StoreError>
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).
Sourcepub fn abort_claim(
&mut self,
run_id: &str,
ticket_id: &str,
now_ms: i64,
) -> Result<(), StoreError>
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.
pub fn run(&self, id: &str) -> Result<Option<RunRecord>, StoreError>
pub fn active_run_for_ticket( &self, ticket_id: &str, ) -> Result<Option<String>, StoreError>
Sourcepub fn active_runs(&self) -> Result<Vec<ActiveRun>, StoreError>
pub fn active_runs(&self) -> Result<Vec<ActiveRun>, StoreError>
Runs that have started and not yet exited, oldest first.
Sourcepub fn queued_ticket_activation(
&self,
ticket_id: &str,
kind: ActivationKind,
) -> Result<Option<String>, StoreError>
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.
Sourcepub fn next_activation_ordinal(&self) -> Result<i64, StoreError>
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.
Sourcepub fn claim_ticket(
&mut self,
claim: &ClaimRequest<'_>,
now_ms: i64,
) -> Result<ClaimedRun, StoreError>
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.
Sourcepub fn renew_lease(
&mut self,
ticket_id: &str,
run_id: &str,
lease_ms: i64,
now_ms: i64,
) -> Result<i64, StoreError>
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.