Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/aien-expert-residency/src/error.rs # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / crates / aien-expert-residency / src / error.rs` 203 lines ยท 7068 bytes Raw Blame History 1 //! Typed errors. Configuration and ledger problems are [`BudgetError`]; 2 //! everything the manager refuses at run time is a [`Refusal`]. 3 4 use core::fmt; 5 6 use crate::budget::Category; 7 use crate::manager::{Phase, SlotId}; 8 9 /// The memory plan or an allocation report does not fit. 10 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 11 pub enum BudgetError { 12 /// A size computation overflowed `u64`. 13 Overflow { what: &'static str }, 14 /// The fixed reservations alone exceed the total memory. 15 Oversubscribed { required: u64, total: u64 }, 16 /// `slot_bytes` is zero. 17 ZeroSlotBytes, 18 /// After the fixed reservations no whole expert slot fits. 19 NoExpertSlots { 20 available_bytes: u64, 21 slot_bytes: u64, 22 }, 23 /// `max_in_flight` is zero, so no fetch could ever start. 24 ZeroInFlight, 25 /// The in-flight byte limit is larger than the staging reservation. 26 InFlightBytesExceedStaging { 27 max_in_flight_bytes: u64, 28 staging_bytes: u64, 29 }, 30 /// The in-flight byte limit is smaller than one slot, so a full-size 31 /// expert could never be fetched. 32 InFlightBytesBelowSlot { 33 max_in_flight_bytes: u64, 34 slot_bytes: u64, 35 }, 36 /// A reported allocation is larger than the ledger reserved for it. 37 AllocationExceedsReservation { 38 category: Category, 39 reserved: u64, 40 actual: u64, 41 }, 42 } 43 44 impl fmt::Display for BudgetError { 45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 46 match self { 47 Self::Overflow { what } => write!(f, "size overflow computing {what}"), 48 Self::Oversubscribed { required, total } => write!( 49 f, 50 "fixed reservations need {required} bytes but only {total} exist" 51 ), 52 Self::ZeroSlotBytes => write!(f, "slot size is zero"), 53 Self::NoExpertSlots { 54 available_bytes, 55 slot_bytes, 56 } => write!( 57 f, 58 "{available_bytes} bytes left after reservations, less than one {slot_bytes}-byte slot" 59 ), 60 Self::ZeroInFlight => write!(f, "max_in_flight is zero"), 61 Self::InFlightBytesExceedStaging { 62 max_in_flight_bytes, 63 staging_bytes, 64 } => write!( 65 f, 66 "in-flight limit {max_in_flight_bytes} exceeds staging reservation {staging_bytes}" 67 ), 68 Self::InFlightBytesBelowSlot { 69 max_in_flight_bytes, 70 slot_bytes, 71 } => write!( 72 f, 73 "in-flight limit {max_in_flight_bytes} is below one slot of {slot_bytes} bytes" 74 ), 75 Self::AllocationExceedsReservation { 76 category, 77 reserved, 78 actual, 79 } => write!( 80 f, 81 "{category:?} allocation {actual} exceeds its reservation {reserved}" 82 ), 83 } 84 } 85 } 86 87 impl std::error::Error for BudgetError {} 88 89 /// Why a fetch did not reach `Ready`. Reported by the caller. 90 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 91 pub enum FailureCause { 92 /// The NVMe read failed, was short or timed out. 93 Read, 94 /// The bytes did not match the content address. 95 DigestMismatch, 96 /// The staging-to-slot copy failed. 97 Copy, 98 /// The GPU visibility fence failed or timed out. 99 GpuFence, 100 /// The fetch was cancelled. 101 Cancelled, 102 } 103 104 /// A run-time refusal. Nothing is changed when one is returned, except the 105 /// refusal counter. 106 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 107 pub enum Refusal { 108 /// Every slot is pinned or in flight; nothing can be evicted. 109 PinnedExhaustion { 110 slots: u32, 111 pinned: u32, 112 in_flight: u32, 113 }, 114 /// The number of fetches in flight is at its limit (backpressure). 115 InFlightLimit { limit: u32 }, 116 /// Starting this fetch would exceed the in-flight byte limit. 117 InFlightBytesLimit { 118 in_flight_bytes: u64, 119 requested: u64, 120 limit: u64, 121 }, 122 /// The object does not fit one slot. 123 ObjectTooLarge { bytes: u64, slot_bytes: u64 }, 124 /// A zero-byte object was requested. 125 ZeroSizedObject, 126 /// The key is already admitted with a different size. 127 SizeMismatch { admitted: u64, requested: u64 }, 128 /// The ticket refers to a slot generation that no longer exists. 129 StaleTicket { slot: SlotId, generation: u64 }, 130 /// The pin refers to a slot generation that no longer exists. 131 StalePin { slot: SlotId, generation: u64 }, 132 /// The step is not allowed from the entry's current phase. 133 WrongPhase { 134 slot: SlotId, 135 expected: Phase, 136 found: Phase, 137 }, 138 /// The pin count of one entry would overflow `u32`. 139 PinOverflow { slot: SlotId }, 140 /// The fetch behind this pin failed; the expert is not resident. 141 FetchFailed { 142 slot: SlotId, 143 generation: u64, 144 cause: FailureCause, 145 }, 146 } 147 148 impl fmt::Display for Refusal { 149 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 150 match self { 151 Self::PinnedExhaustion { 152 slots, 153 pinned, 154 in_flight, 155 } => write!( 156 f, 157 "all {slots} slots busy ({pinned} pinned, {in_flight} in flight)" 158 ), 159 Self::InFlightLimit { limit } => write!(f, "{limit} fetches already in flight"), 160 Self::InFlightBytesLimit { 161 in_flight_bytes, 162 requested, 163 limit, 164 } => write!( 165 f, 166 "{in_flight_bytes} bytes in flight + {requested} would exceed {limit}" 167 ), 168 Self::ObjectTooLarge { bytes, slot_bytes } => { 169 write!(f, "object of {bytes} bytes exceeds slot size {slot_bytes}") 170 } 171 Self::ZeroSizedObject => write!(f, "zero-sized object"), 172 Self::SizeMismatch { 173 admitted, 174 requested, 175 } => write!( 176 f, 177 "key admitted with {admitted} bytes, requested with {requested}" 178 ), 179 Self::StaleTicket { slot, generation } => { 180 write!(f, "stale ticket for slot {slot} generation {generation}") 181 } 182 Self::StalePin { slot, generation } => { 183 write!(f, "stale pin for slot {slot} generation {generation}") 184 } 185 Self::WrongPhase { 186 slot, 187 expected, 188 found, 189 } => write!(f, "slot {slot}: expected {expected:?}, found {found:?}"), 190 Self::PinOverflow { slot } => write!(f, "slot {slot}: pin count overflow"), 191 Self::FetchFailed { 192 slot, 193 generation, 194 cause, 195 } => write!( 196 f, 197 "fetch for slot {slot} generation {generation} failed: {cause:?}" 198 ), 199 } 200 } 201 } 202 203 impl std::error::Error for Refusal {}