pub struct AdaptiveStateMachine { /* private fields */ }Expand description
Pure, no_std-compatible state machine implementing Adaptive Kernel Protocol v1.
Enforces single-pending-active gating, fail-closed payload conflict detection, full-snapshot application verification, single-consumption feedback attribution, monotonic recovery versioning, legacy-snapshot permission isolation, and expired-request tombstone safety.
Implementations§
Source§impl AdaptiveStateMachine
impl AdaptiveStateMachine
Sourcepub fn new(
config: AdaptiveConfig,
confirmed_policy: PolicySnapshot,
) -> Result<Self, AdaptiveError>
pub fn new( config: AdaptiveConfig, confirmed_policy: PolicySnapshot, ) -> Result<Self, AdaptiveError>
Creates a new state machine initialized with config and confirmed baseline parameters.
Sourcepub fn from_legacy_snapshot(
snapshot_version: u32,
config: AdaptiveConfig,
confirmed_policy: PolicySnapshot,
) -> Result<Self, AdaptiveError>
pub fn from_legacy_snapshot( snapshot_version: u32, config: AdaptiveConfig, confirmed_policy: PolicySnapshot, ) -> Result<Self, AdaptiveError>
Restores a state machine from a legacy snapshot (e.g. schema v6).
Legacy snapshots never grant AdaptiveMode::Active permission even if
the caller requests active mode; the session stays fail-closed in
AdaptiveMode::Keep until explicitly migrated and re-authorized.
Sourcepub fn export_state(&self) -> AdaptivePersistedState
pub fn export_state(&self) -> AdaptivePersistedState
Exports a serializable snapshot of the state machine for schema v7 persistence.
Sourcepub fn from_persisted_state(
config: AdaptiveConfig,
state: AdaptivePersistedState,
) -> Result<Self, AdaptiveError>
pub fn from_persisted_state( config: AdaptiveConfig, state: AdaptivePersistedState, ) -> Result<Self, AdaptiveError>
Restores a state machine from a durable AdaptivePersistedState.
Active permission is never elevated above the lesser of config.mode
and the persisted active_permission_granted flag.
Sourcepub fn reconcile_journal(input: &JournalRecoveryInput) -> JournalRecoveryAction
pub fn reconcile_journal(input: &JournalRecoveryInput) -> JournalRecoveryAction
Evaluates journal recovery state after an interrupted durable commit.
Sourcepub fn record_expired_tombstone(&mut self, request_id: impl Into<String>)
pub fn record_expired_tombstone(&mut self, request_id: impl Into<String>)
Marks an old request_id as an expired tombstone so it can never be re-executed.
Sourcepub fn confirmed_policy(&self) -> &PolicySnapshot
pub fn confirmed_policy(&self) -> &PolicySnapshot
Returns the currently confirmed policy snapshot.
Sourcepub fn next_candidate_version(&self) -> u64
pub fn next_candidate_version(&self) -> u64
Returns the next candidate policy version that will be allocated.
Sourcepub fn learning_updates(&self) -> u64
pub fn learning_updates(&self) -> u64
Returns the total count of consumed learning updates.
Sourcepub fn checkpoint_count(&self) -> u64
pub fn checkpoint_count(&self) -> u64
Returns the total count of checkpoints created across proposals.
Sourcepub fn active_permission_granted(&self) -> bool
pub fn active_permission_granted(&self) -> bool
Returns whether active adaptation permission is granted for this session.
Sourcepub fn pending_active_proposal_id(&self) -> Option<&str>
pub fn pending_active_proposal_id(&self) -> Option<&str>
Returns the currently pending active proposal identifier, if any.
Sourcepub fn proposal_state(&self, proposal_id: &str) -> Option<ProposalState>
pub fn proposal_state(&self, proposal_id: &str) -> Option<ProposalState>
Returns the current lifecycle state of proposal_id, if tracked.
Sourcepub fn propose(
&mut self,
req: ProposalRequest,
) -> Result<ProposalResponse, AdaptiveError>
pub fn propose( &mut self, req: ProposalRequest, ) -> Result<ProposalResponse, AdaptiveError>
Processes a proposal request with strict idempotency and conflict checking.
Sourcepub fn acknowledge_applied(
&mut self,
receipt: ExecutionReceipt,
) -> Result<PolicySnapshot, AdaptiveError>
pub fn acknowledge_applied( &mut self, receipt: ExecutionReceipt, ) -> Result<PolicySnapshot, AdaptiveError>
Acknowledges that the host applied an active proposal’s exact full snapshot.
Sourcepub fn feedback(
&mut self,
req: FeedbackRequest,
) -> Result<FeedbackReceipt, AdaptiveError>
pub fn feedback( &mut self, req: FeedbackRequest, ) -> Result<FeedbackReceipt, AdaptiveError>
Records external outcome feedback for an applied execution, consuming it at most once.
Sourcepub fn recommend_recovery(
&self,
recovery_params: BTreeMap<String, f64>,
) -> Result<RecoveryRecommendation, AdaptiveError>
pub fn recommend_recovery( &self, recovery_params: BTreeMap<String, f64>, ) -> Result<RecoveryRecommendation, AdaptiveError>
Produces a recovery recommendation that restores recovery_params under a strictly newer version.