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
63/// Wraps either a compare or perf result for `BenchmarkEvent::ModelComplete`.
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(tag = "kind", rename_all = "snake_case")]
66pub enum BenchmarkModelResult {
67 /// Result from a compare run.
68 Compare(ModelCompareResult),
69 /// Result from a perf run.
70 Perf(ModelPerfResult),
71}