Skip to main content

gglib_core/domain/benchmark/
events.rs

1//! SSE / channel event enum shared by all benchmark run types.
2
3use serde::{Deserialize, Serialize};
4
5use super::compare::ModelCompareResult;
6use super::perf::ModelPerfResult;
7use super::tune::TuneCandidateResult;
8
9/// Typed event emitted over the mpsc channel (and serialised as SSE to the
10/// browser) during a benchmark run.
11///
12/// Both the CLI renderer and the Axum SSE bridge consume this enum, giving
13/// full feature parity between CLI and web interfaces.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(tag = "type", rename_all = "snake_case")]
16pub enum BenchmarkEvent {
17    /// A model is about to start (position is 1-based).
18    ModelStarted {
19        model_id: i64,
20        model_name: String,
21        position: usize,
22        total: usize,
23    },
24    /// A chunk of generated text for one model (compare runs only).
25    ModelTextDelta { model_id: i64, text: String },
26    /// A model finished successfully.
27    ModelComplete {
28        model_id: i64,
29        result: BenchmarkModelResult,
30    },
31    /// A model failed (e.g. binary not found, OOM).
32    ModelFailed {
33        model_id: i64,
34        model_name: String,
35        error: String,
36    },
37    /// All models finished; the run record is now `Complete`.
38    RunComplete { run_id: i64 },
39    /// The entire run failed (e.g. DB error, abort).
40    RunFailed { error: String },
41
42    /// A tune candidate is about to be evaluated (index is 0-based).
43    TuneCandidateStarted {
44        candidate_index: usize,
45        total: usize,
46    },
47    /// One task finished evaluating for the current tune candidate.
48    TuneTaskComplete {
49        candidate_index: usize,
50        task_id: String,
51        passed: bool,
52    },
53    /// A tune candidate was dropped after the pre-screen round and will not
54    /// run the full task suite.
55    TunePruned {
56        candidate_index: usize,
57        reason: String,
58    },
59    /// A tune candidate finished evaluating (pre-screen or full suite).
60    TuneCandidateComplete { result: TuneCandidateResult },
61
62    /// An agentic-eval arm is about to run its task set.
63    AgenticArmStarted {
64        arm: crate::domain::benchmark::agentic::EvalArm,
65        total_tasks: usize,
66    },
67    /// One task finished under one agentic-eval arm.
68    AgenticTaskComplete {
69        arm: crate::domain::benchmark::agentic::EvalArm,
70        task_id: String,
71        passed: bool,
72    },
73    /// The agentic eval finished; the full A/B report.
74    ///
75    /// Boxed because the report is by far the largest thing this enum carries
76    /// — per-arm scores, a per-axis delta, and a per-task drill-down holding
77    /// every seed's result — and an enum is as large as its widest variant.
78    /// Unboxed, every progress tick sent over this channel would pay for it.
79    AgenticEvalComplete {
80        report: Box<crate::domain::benchmark::agentic::AgenticEvalReport>,
81    },
82}
83
84/// Wraps either a compare or perf result for `BenchmarkEvent::ModelComplete`.
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(tag = "kind", rename_all = "snake_case")]
87pub enum BenchmarkModelResult {
88    /// Result from a compare run.
89    Compare(ModelCompareResult),
90    /// Result from a perf run.
91    Perf(ModelPerfResult),
92}