Download src/task_benchmark/types.rs from ElderRyan/lispm-llm: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/ElderRyan/lispm-llm/resolve/main/src/task_benchmark/types.rs
- Command line
-
hf download hf://ElderRyan/lispm-llm/src/task_benchmark/types.rs
-
curl -L -o types.rs https://huggingface.co/ElderRyan/lispm-llm/resolve/main/src/task_benchmark/types.rs
10.6 kB
| //! Typed task fixtures, subprocess results and artifact-bound comparison evidence. | |
| use std::{collections::BTreeMap, path::PathBuf}; | |
| use serde::{Deserialize, Serialize}; | |
| use serde_json::Value; | |
| use thiserror::Error; | |
| /// Explicit failures of fixture validation, inference or the isolated task runner. | |
| pub enum TaskBenchmarkError { | |
| /// Caller cancellation never produces a completed benchmark. | |
| Cancelled, | |
| /// The reviewed task fixture or returned report violates its schema. | |
| Invalid(&'static str), | |
| /// A source changed after its exact bytes were recorded. | |
| Changed(PathBuf), | |
| /// No matching executable could be resolved from the explicit path or PATH. | |
| EmacsNotFound(PathBuf), | |
| /// The bounded child process exceeded the requested deadline. | |
| Timeout(u64), | |
| /// The child process failed rather than returning task outcomes. | |
| RunnerFailed(String), | |
| /// The child exceeded its bounded report or diagnostic output size. | |
| OutputLimit, | |
| /// An expected action is outside the bounded command algebra. | |
| Action( crate::actions::InputError), | |
| /// Numerical infrastructure failed; this is never a model refusal. | |
| Inference( crate::inference::InferenceError), | |
| /// Model loading failed before execution could be measured. | |
| Model( crate::model::ModelError), | |
| /// File access or process management failed. | |
| Io( std::io::Error), | |
| /// JSON input or output failed strict decoding. | |
| Json( serde_json::Error), | |
| } | |
| impl TaskBenchmarkError { | |
| /// Recognize cooperative cancellation without comparing display strings. | |
| pub fn is_cancelled(&self) -> bool { | |
| matches!(self, Self::Cancelled) | |
| } | |
| } | |
| /// A reviewed fixture and its intended program, independent of model predictions. | |
| pub struct TaskCase { | |
| /// Stable unique identity used to correlate a prediction with a result. | |
| pub id: String, | |
| /// Original English request, with quoted literals preserved as data. | |
| pub instruction: String, | |
| /// Name of a fixed fixture and end-state predicate in the reviewed runner. | |
| pub scenario: String, | |
| /// Number of distinct actions required by the reviewed reference program. | |
| pub steps: u8, | |
| /// Typed reference program; the runner checks its goal before scoring predictions. | |
| pub expected: Value, | |
| } | |
| /// Strict portable description of a frozen real-Emacs task suite. | |
| pub struct TaskSuite { | |
| /// Version of the reviewed task schema. | |
| pub format_version: u32, | |
| /// Description of fixture provenance and benchmark exposure. | |
| pub policy: String, | |
| /// Ordered independently initialized task fixtures. | |
| pub tasks: Vec<TaskCase>, | |
| } | |
| /// Explicit executable and runner selection for one bounded child process. | |
| pub struct RunnerOptions { | |
| /// Absolute executable path, or a binary name resolved through PATH. | |
| pub emacs: PathBuf, | |
| /// Reviewed standalone Lisp runner copied to the isolated working directory. | |
| pub runner: PathBuf, | |
| /// Positive wall-clock limit for the complete Emacs child process. | |
| pub timeout_seconds: u64, | |
| } | |
| /// Mutually exclusive outcome of one supported task in its prepared environment. | |
| /// Copying an outcome preserves this immutable classification. | |
| pub enum TaskStatus { | |
| /// The observed final state satisfied the task's goal predicate. | |
| Success, | |
| /// The proposed program executed but its resulting state missed the goal. | |
| WrongState, | |
| /// The model refused a supported request before any action was executed. | |
| Rejected, | |
| /// A permitted action raised a runtime error in the prepared fixture. | |
| ExecutionError, | |
| /// The complete proposal failed the runner's local effects boundary. | |
| BlockedAction, | |
| } | |
| /// Disjoint integer counts; accepted-program precision cannot hide refusals. | |
| pub struct TaskCounts { | |
| /// Number of tasks in this cohort. | |
| pub total: u32, | |
| /// Tasks whose observed final state met the goal. | |
| pub success: u32, | |
| /// Executed programs with incorrect final states. | |
| pub wrong_state: u32, | |
| /// Supported requests refused before execution. | |
| pub rejected: u32, | |
| /// Permitted programs that raised execution errors. | |
| pub execution_error: u32, | |
| /// Proposals rejected by the runner's effects boundary. | |
| pub blocked_action: u32, | |
| } | |
| impl TaskCounts { | |
| /// Count one task outcome after the suite-size limit made overflow impossible. | |
| pub(super) fn observe(&mut self, status: TaskStatus) { | |
| self.total += 1; | |
| match status { | |
| TaskStatus::Success => self.success += 1, | |
| TaskStatus::WrongState => self.wrong_state += 1, | |
| TaskStatus::Rejected => self.rejected += 1, | |
| TaskStatus::ExecutionError => self.execution_error += 1, | |
| TaskStatus::BlockedAction => self.blocked_action += 1, | |
| } | |
| } | |
| /// Compute task success over all requests, including refusals and failures. | |
| pub fn success_rate(&self) -> f64 { | |
| if self.total == 0 { | |
| 0.0 | |
| } else { | |
| f64::from(self.success) / f64::from(self.total) | |
| } | |
| } | |
| /// Require every failure category and supported refusal count to not increase. | |
| pub(super) fn preserves(&self, baseline: &Self) -> bool { | |
| self.total == baseline.total | |
| && self.success >= baseline.success | |
| && self.wrong_state <= baseline.wrong_state | |
| && self.rejected <= baseline.rejected | |
| && self.execution_error <= baseline.execution_error | |
| && self.blocked_action <= baseline.blocked_action | |
| } | |
| } | |
| /// One task's measured outcome, retaining an inspectable final-state witness. | |
| pub struct TaskResult { | |
| /// Stable fixture identity from the frozen input. | |
| pub id: String, | |
| /// Reviewed state fixture and goal name. | |
| pub scenario: String, | |
| /// Required reference-program length, not a model-selected denominator. | |
| pub steps: u8, | |
| /// Exactly one measured result category. | |
| pub status: TaskStatus, | |
| /// Number of predicted actions completed before failure or goal inspection. | |
| pub completed_actions: u8, | |
| /// Human-readable refusal, effects-boundary or execution diagnostic. | |
| pub detail: Option<String>, | |
| /// Fixture-specific final state, or null when nothing was executed. | |
| pub state: Option<Value>, | |
| } | |
| /// The model's proposal or explicit refusal, retained separately from the oracle. | |
| pub struct TaskPrediction { | |
| /// Stable reviewed task identity. | |
| pub id: String, | |
| /// Exact input sent to the model. | |
| pub instruction: String, | |
| /// Typed action program, absent only when inference explicitly refused input. | |
| pub program: Option<Value>, | |
| /// Explicit semantic refusal reason, absent when a proposal was returned. | |
| pub refusal: Option<String>, | |
| } | |
| /// Exact report produced by the standalone Emacs runner. | |
| pub(super) struct RunnerReport { | |
| /// Version of the task runner response schema. | |
| pub format_version: u32, | |
| /// Runtime version returned by the executing Emacs process. | |
| pub emacs_version: String, | |
| /// Number of reference programs whose goal predicates passed before inference scoring. | |
| pub oracle_checked: u32, | |
| /// Runner aggregate, independently recomputed by the Rust boundary. | |
| pub counts: TaskCounts, | |
| /// Results in frozen fixture order. | |
| pub results: Vec<TaskResult>, | |
| } | |
| /// Artifact-bound real-Emacs outcomes, separate from generated-code exact match. | |
| pub struct TaskReport { | |
| /// Version of the persisted task benchmark report. | |
| pub format_version: u32, | |
| /// Exact evaluated SafeTensors bytes. | |
| pub weights_sha256: String, | |
| /// Exact model vocabulary, labels and admission settings. | |
| pub config_sha256: String, | |
| /// Frozen task definitions, including fixture identities and reference programs. | |
| pub tasks_sha256: String, | |
| /// Exact standalone runner source executed in the isolated subprocess. | |
| pub runner_sha256: String, | |
| /// Selected executable bytes, including a launcher if that is the selected binary. | |
| pub emacs_executable_sha256: String, | |
| /// Runtime-reported Emacs version, identical for paired comparisons. | |
| pub emacs_version: String, | |
| /// Task provenance policy, not a claim of independent blind evaluation. | |
| pub policy: String, | |
| /// Every task's reference program passed its goal before scoring. | |
| pub oracle_checked: u32, | |
| /// All-request outcome counts. | |
| pub counts: TaskCounts, | |
| /// Success divided by all tasks; integer counts remain authoritative. | |
| pub success_rate: f64, | |
| /// Separate single-action and two-action cohorts. | |
| pub by_steps: BTreeMap<u8, TaskCounts>, | |
| /// Per-fixture outcomes expose regressions hidden by overall averages. | |
| pub by_scenario: BTreeMap<String, TaskCounts>, | |
| /// Every measured fixture outcome with its state witness. | |
| pub results: Vec<TaskResult>, | |
| /// Model proposals and refusals in the same frozen task order. | |
| pub predictions: Vec<TaskPrediction>, | |
| } | |
| /// Baseline/candidate evidence with a recomputed task nonregression decision. | |
| pub struct TaskComparison { | |
| /// Frozen baseline measured in the same runner and task environment. | |
| pub baseline: TaskReport, | |
| /// Candidate measured independently against identical task definitions. | |
| pub candidate: TaskReport, | |
| /// Overall, per-step and per-scenario task outcomes meet nonregression constraints. | |
| pub eligible: bool, | |
| } | |