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/aienux/blob/main/crates/aienos-agent-state/src/abi.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. 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 `aienux / crates / aienos-agent-state / src / abi.rs` 92 lines · 3804 bytes Raw Blame History 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 //! AIENOS Agent State ABI (§9). 17 18 use crate::id::{LogicalAgentId, LogicalBranchId}; 19 use crate::incarnation::SequenceId; 20 use core::fmt; 21 use serde::{Deserialize, Serialize}; 22 23 /// Checkpoint cryptographic integrity hash. 24 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] 25 pub struct CheckpointHash(pub [u8; 32]); 26 27 impl fmt::Debug for CheckpointHash { 28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 29 write!(f, "CheckpointHash({:02x}{:02x}...)", self.0[0], self.0[1]) 30 } 31 } 32 33 impl fmt::Display for CheckpointHash { 34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 35 for b in &self.0 { 36 write!(f, "{:02x}", b)?; 37 } 38 Ok(()) 39 } 40 } 41 42 /// Errors occurring during Agent State operations. 43 #[derive(Debug, Clone, PartialEq, Eq)] 44 pub enum StateError { 45 AgentNotFound(LogicalAgentId), 46 BranchNotFound(LogicalBranchId), 47 ParentBranchNotFound(LogicalBranchId), 48 AlreadySuspended(LogicalBranchId), 49 NotSuspended(LogicalBranchId), 50 SerializationError(String), 51 DeserializationError(String), 52 ChecksumMismatch, 53 InvalidCheckpoint(&'static str), 54 ReconstructionFailed(String), 55 } 56 57 impl fmt::Display for StateError { 58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 59 match self { 60 Self::AgentNotFound(id) => write!(f, "Agent not found: {}", id), 61 Self::BranchNotFound(id) => write!(f, "Branch not found: {}", id), 62 Self::ParentBranchNotFound(id) => write!(f, "Parent branch not found: {}", id), 63 Self::AlreadySuspended(id) => write!(f, "Branch already suspended: {}", id), 64 Self::NotSuspended(id) => write!(f, "Branch not suspended: {}", id), 65 Self::SerializationError(msg) => write!(f, "Serialization error: {}", msg), 66 Self::DeserializationError(msg) => write!(f, "Deserialization error: {}", msg), 67 Self::ChecksumMismatch => write!(f, "Checkpoint checksum mismatch"), 68 Self::InvalidCheckpoint(reason) => write!(f, "Invalid checkpoint: {reason}"), 69 Self::ReconstructionFailed(msg) => write!(f, "Physical reconstruction failed: {}", msg), 70 } 71 } 72 } 73 74 /// The Agent State ABI (§9). 75 /// 76 /// Decouples persistent semantic identity from ephemeral execution incarnations. 77 pub trait AgentStateAbi { 78 /// Fork an existing logical branch into an isolated child branch. 79 fn fork_branch(&self, parent: LogicalBranchId) -> Result; 80 81 /// Checkpoint logical agent state to durable storage. 82 fn checkpoint(&self, agent_id: LogicalAgentId) -> Result; 83 84 /// Suspend execution incarnation without mutating logical state. 85 fn suspend(&mut self, branch_id: LogicalBranchId) -> Result<(), StateError>; 86 87 /// Resume execution, re-instantiating physical state via recompute or cache. 88 fn resume(&mut self, branch_id: LogicalBranchId) -> Result; 89 90 /// Reconstruct lost physical state from TokenHistory and EpistemicRefs. 91 fn reconstruct_physical(&mut self, branch_id: LogicalBranchId) -> Result<(), StateError>; 92 }