fabro/lib/components/fabro-store/src/database.rs
Bryan Helmkamp 60b503322c
Delete the legacy run event log, its reducer and its types
Step 4 of the legacy executor deletion, fourth commit: with no writer
and no reader left, the legacy event log goes.

- `fabro-types`: `run_event` (`EventBody`, `RunEvent` and every props
  struct), `EventEnvelope` and the `RunEventDetail*` types are deleted.
  What the projection and the API still use moves out of the event
  vocabulary: `AgentEventProps`, `AgentSessionActivatedProps`,
  `AgentToolsAvailableProps`, `StagePromptProps`, `SessionCapability`
  and the coding event names to `agent_props`; `RunNoticeLevel` and
  `RunNoticeCode` to `notice`; `InterviewOption` beside the question
  types; `RunRunnableSource` beside the run status. `Checkpoint` is
  what Fabro records for a Petri run: `timestamp`, `current_node`,
  `git_commit_sha`; the conclusion's stage summaries derive from the
  projection's stages instead of the checkpoint's node maps.
- `fabro-store`: the Slate bridge (`RunDatabase`, the Slate `Database`,
  `keys`, `record`, `EventPayload`) and the reducer (`run_state`) are
  deleted. `Database` is the blob table and the run summary store over
  one pool; the blob store is SQLite only; the run summary store keeps
  the `runs` row a projector writes and lists, and finds the pull
  request creation candidates over `platform_records`; `build_summary`
  and `projected_usage` live in `run_summary`. The SlateDB dependency
  is gone. Test fixtures build the store from its two SQLite stores.
- `fabro-workflow`: the `event` module (the `Event` enum, its
  conversion, sink, emitter, redaction, stored fields and names),
  `runtime_store`, `StageScope` and the legacy seeding test helpers are
  deleted; the tests that seeded legacy runs read platform records or
  a projection instead.
- `fabro-sandbox` owns `GitRetryReason`.
- The server builds the store without an object store; the legacy
  `POST /runs/{id}/events` tests go, an interrupt answers
  `interrupt_unsupported` in the tests as it does in the handler, and
  the tests that read a run back through the Slate handle read its
  projection or its platform records. The projection folds a block
  that lands while the run is paused as the pause's prior block, and a
  pause or unpause clears the pending control it answers; a control
  request's check-and-append holds a per-run lock so two concurrent
  cancels record one request.
- The CLI's final output is the response of the last stage that
  produced one; the workflow tests read completed nodes from the
  succeeded stages.
- The spec's `RunCheckpoint` carries the three fields the type keeps.

Still failing until the next commits: the CLI tests that seed runs
through `POST /runs/{id}/events` or wait for legacy event names, and
the two Ask Fabro resume tests (the sandbox instance gap).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-18 14:09:17 -04:00

65 lines
2.1 KiB
Rust

//! The run store the server holds: the blob table and the run summary
//! store over one SQLite pool, behind one handle.
//!
//! A run's history is Petri's records (`petri_records`) and Fabro's
//! platform records; its view is the projection the projector commits.
//! This handle carries the two stores every reader of a run reaches, and
//! the run-level operations that span them.
use std::sync::Arc;
use fabro_types::{RunId, RunProjection};
use crate::{BlobStore, PlatformRecordHook, Result, RunSummaryStore};
#[derive(Clone)]
pub struct Database {
blobs: Arc<BlobStore>,
run_summary_store: Arc<RunSummaryStore>,
}
impl std::fmt::Debug for Database {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Database").finish_non_exhaustive()
}
}
impl Database {
#[must_use]
pub fn new(blobs: Arc<BlobStore>, run_summary_store: Arc<RunSummaryStore>) -> Self {
Self {
blobs,
run_summary_store,
}
}
#[must_use]
pub fn run_summary_store(&self) -> Arc<RunSummaryStore> {
Arc::clone(&self.run_summary_store)
}
#[must_use]
pub fn blobs(&self) -> Arc<BlobStore> {
Arc::clone(&self.blobs)
}
/// The run's projection: the one its projector last committed over
/// Petri's records and the platform records, or `None` before the
/// first view pass commits (or for no such run).
pub async fn load_run_projection(&self, run_id: &RunId) -> Result<Option<Arc<RunProjection>>> {
self.run_summary_store.load_petri_projection(run_id).await
}
/// Install the wake-up called after a platform record of a run is
/// committed.
pub fn set_platform_record_hook(&self, hook: PlatformRecordHook) {
self.run_summary_store.set_platform_record_hook(hook);
}
/// Forget the run's row. Its Petri records, platform records and view
/// are the projector's to delete; its blobs are content-addressed and
/// shared.
pub async fn delete_run(&self, run_id: &RunId) -> Result<()> {
self.run_summary_store.delete_canonical(run_id).await
}
}