Skip to main content

gglib_core/domain/benchmark/
run.rs

1//! Benchmark run metadata: type, lifecycle status, and the run record itself.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// Whether a benchmark run measured inference quality/speed or raw throughput.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS), ts(export))]
10pub enum BenchmarkRunType {
11    /// Prompt-comparison run: N models answer the same prompt.
12    Compare,
13    /// Performance run: `llama-bench` reports raw pp/tg tokens/sec.
14    Perf,
15    /// Tuning run: sweep sampling parameters for one model against an
16    /// agentic tool-calling task suite to find the best-scoring settings.
17    Tune,
18    /// Raw-vs-gglib A/B run: the same agentic task suite twice against one
19    /// model, once with the request pipeline bypassed and once through it.
20    Agentic,
21}
22
23/// Lifecycle state of a benchmark run.
24#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(rename_all = "snake_case")]
26#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS), ts(export))]
27pub enum BenchmarkRunStatus {
28    /// Run is currently in progress.
29    Running,
30    /// Run finished successfully.
31    Complete,
32    /// Run encountered an error or was aborted.
33    Failed,
34}
35
36/// Lightweight record grouping one or more model results under a single run.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS), ts(export))]
39pub struct BenchmarkRun {
40    /// Database ID of the run.
41    #[cfg_attr(feature = "ts-bindings", ts(type = "number"))]
42    pub id: i64,
43    /// Whether this is a compare, perf, or tune run.
44    pub run_type: BenchmarkRunType,
45    /// Current lifecycle state.
46    pub status: BenchmarkRunStatus,
47    /// Ordered list of model IDs that were (or will be) benchmarked.
48    #[cfg_attr(feature = "ts-bindings", ts(type = "Array<number>"))]
49    pub model_ids: Vec<i64>,
50    /// Prompt text used for compare runs (absent for perf/tune runs).
51    pub prompt_text: Option<String>,
52    /// System prompt used for compare runs.
53    pub system_prompt: Option<String>,
54    /// Serialised run configuration (`CompareConfig`, `PerfConfig`, or
55    /// `TuneConfig` JSON).
56    pub config_json: Option<String>,
57    /// The apply record written when this tune run's winner became a model's
58    /// Measured defaults (JSON-serialized `tune::apply::ApplyRecord`).
59    /// `None` on every run that was never applied — which is every run of
60    /// every other type, and most tune runs.
61    #[serde(default)]
62    pub applied_json: Option<String>,
63    /// Error message if the run failed.
64    pub error: Option<String>,
65    /// UTC timestamp when the run was created.
66    pub created_at: DateTime<Utc>,
67    /// UTC timestamp when the run completed or failed.
68    pub completed_at: Option<DateTime<Utc>>,
69}