aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / spark-harness / src / scheduler / error.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Every way the provisional scheduler refuses an event or a gate query. |
| 17 | |
| 18 | use crate::completion::CompletionError; |
| 19 | use crate::dependency::GraphError; |
| 20 | use crate::execution::{IllegalTransition, TaskState}; |
| 21 | use crate::readiness::{OperationClass, ReadinessLevel, UnknownOperation}; |
| 22 | use std::fmt; |
| 23 | |
| 24 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 25 | pub enum SchedError { |
| 26 | InvalidEvent(String), |
| 27 | UnknownTask(String), |
| 28 | Graph(GraphError), |
| 29 | /// The task can never run: its request exceeds the whole budget. |
| 30 | ExceedsCapacity(String), |
| 31 | /// The event refers to a generation older than the task's current one. |
| 32 | StaleGeneration { |
| 33 | task: String, |
| 34 | submitted: u64, |
| 35 | current: u64, |
| 36 | }, |
| 37 | /// The event refers to a generation the scheduler has not reached. |
| 38 | FutureGeneration { |
| 39 | task: String, |
| 40 | submitted: u64, |
| 41 | current: u64, |
| 42 | }, |
| 43 | /// The task is in a state where this event or query is not allowed. |
| 44 | WrongState { |
| 45 | task: String, |
| 46 | state: TaskState, |
| 47 | action: &'static str, |
| 48 | }, |
| 49 | Transition(IllegalTransition), |
| 50 | LeaseExpired(String), |
| 51 | /// A heartbeat whose beat number is not above the last accepted one |
| 52 | /// for the current lease (a redelivery or a reordered beat). |
| 53 | StaleHeartbeat { |
| 54 | task: String, |
| 55 | beat: u64, |
| 56 | last: u64, |
| 57 | }, |
| 58 | /// The same event id was delivered with a different payload. |
| 59 | EventIdConflict(String), |
| 60 | UnknownOperation(UnknownOperation), |
| 61 | /// The producer's verified readiness does not allow this operation. |
| 62 | NotPermitted { |
| 63 | task: String, |
| 64 | op: OperationClass, |
| 65 | producer: String, |
| 66 | level: ReadinessLevel, |
| 67 | }, |
| 68 | /// The consumer has no binding to the producer (it was not dispatched |
| 69 | /// against it), or the binding is for an older generation. |
| 70 | StaleBinding { |
| 71 | task: String, |
| 72 | producer: String, |
| 73 | detail: String, |
| 74 | }, |
| 75 | /// A producer is not final-verified for its current generation. |
| 76 | ProducerNotFinal { |
| 77 | producer: String, |
| 78 | detail: String, |
| 79 | }, |
| 80 | /// Re-verification from the harness store failed. |
| 81 | Proof { |
| 82 | task: String, |
| 83 | error: CompletionError, |
| 84 | }, |
| 85 | Journal(String), |
| 86 | /// The event would revoke, cancel, fail or re-generate a `Committing` |
| 87 | /// task (`committing`), directly or through `task` upstream of it, or |
| 88 | /// would start a second commit in the same dependency chain. Deliver it |
| 89 | /// again after the commit outcome is recorded. |
| 90 | CommitInProgress { |
| 91 | task: String, |
| 92 | committing: String, |
| 93 | }, |
| 94 | /// A new request key would exceed the task's share of the |
| 95 | /// bound-request table. |
| 96 | BindingsFull { |
| 97 | task: String, |
| 98 | capacity: usize, |
| 99 | }, |
| 100 | } |
| 101 | |
| 102 | impl fmt::Display for SchedError { |
| 103 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 104 | match self { |
| 105 | SchedError::InvalidEvent(m) => write!(f, "invalid event: {m}"), |
| 106 | SchedError::UnknownTask(t) => write!(f, "unknown task '{t}'"), |
| 107 | SchedError::Graph(e) => write!(f, "dependency graph: {e}"), |
| 108 | SchedError::ExceedsCapacity(t) => { |
| 109 | write!(f, "task '{t}' requests more than the whole resource budget") |
| 110 | } |
| 111 | SchedError::StaleGeneration { |
| 112 | task, |
| 113 | submitted, |
| 114 | current, |
| 115 | } => write!( |
| 116 | f, |
| 117 | "stale generation for '{task}': event {submitted}, current {current}" |
| 118 | ), |
| 119 | SchedError::FutureGeneration { |
| 120 | task, |
| 121 | submitted, |
| 122 | current, |
| 123 | } => write!( |
| 124 | f, |
| 125 | "unknown future generation for '{task}': event {submitted}, current {current}" |
| 126 | ), |
| 127 | SchedError::WrongState { |
| 128 | task, |
| 129 | state, |
| 130 | action, |
| 131 | } => write!(f, "task '{task}' is {}; cannot {action}", state.as_str()), |
| 132 | SchedError::Transition(e) => write!(f, "{e}"), |
| 133 | SchedError::LeaseExpired(t) => write!(f, "lease of task '{t}' expired"), |
| 134 | SchedError::StaleHeartbeat { task, beat, last } => write!( |
| 135 | f, |
| 136 | "heartbeat {beat} for task '{task}' is not above the last accepted beat {last}" |
| 137 | ), |
| 138 | SchedError::EventIdConflict(id) => { |
| 139 | write!(f, "event id '{id}' was already used for a different event") |
| 140 | } |
| 141 | SchedError::UnknownOperation(e) => write!(f, "{e}"), |
| 142 | SchedError::NotPermitted { |
| 143 | task, |
| 144 | op, |
| 145 | producer, |
| 146 | level, |
| 147 | } => write!( |
| 148 | f, |
| 149 | "task '{task}' may not run '{}': producer '{producer}' is only {level:?}", |
| 150 | op.as_str() |
| 151 | ), |
| 152 | SchedError::StaleBinding { |
| 153 | task, |
| 154 | producer, |
| 155 | detail, |
| 156 | } => write!(f, "task '{task}' binding to '{producer}': {detail}"), |
| 157 | SchedError::ProducerNotFinal { producer, detail } => { |
| 158 | write!(f, "producer '{producer}' is not final-verified: {detail}") |
| 159 | } |
| 160 | SchedError::Proof { task, error } => { |
| 161 | write!(f, "proof for '{task}' failed re-verification: {error}") |
| 162 | } |
| 163 | SchedError::Journal(m) => write!(f, "journal: {m}"), |
| 164 | SchedError::CommitInProgress { task, committing } => write!( |
| 165 | f, |
| 166 | "task '{committing}' is committing; '{task}' cannot change it until its outcome is recorded" |
| 167 | ), |
| 168 | SchedError::BindingsFull { task, capacity } => write!( |
| 169 | f, |
| 170 | "task '{task}' holds its maximum of {capacity} bound request keys; no new key is bound" |
| 171 | ), |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | impl std::error::Error for SchedError {} |
| 177 | |
| 178 | impl From<GraphError> for SchedError { |
| 179 | fn from(e: GraphError) -> Self { |
| 180 | SchedError::Graph(e) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | impl From<IllegalTransition> for SchedError { |
| 185 | fn from(e: IllegalTransition) -> Self { |
| 186 | SchedError::Transition(e) |
| 187 | } |
| 188 | } |