Skip to main content

PolicySnapshot

Struct PolicySnapshot 

Source
pub struct PolicySnapshot {
    pub policy_epoch: u64,
    pub catalog_epoch: u64,
    pub hard_risk_limit_bps: u16,
    pub minimum_confidence_bps: u16,
    pub risk_penalty_multiplier_bps: u16,
    pub latency_penalty_microunits_per_ms: u64,
    /* private fields */
}
Expand description

An immutable snapshot of the decision policy and model catalog.

Create with PolicySnapshot::try_new (validated) or PolicySnapshot::new_unchecked, then call prescribe for each request. The snapshot is Clone and can be shared across threads via Arc.

Fields§

§policy_epoch: u64§catalog_epoch: u64§hard_risk_limit_bps: u16§minimum_confidence_bps: u16§risk_penalty_multiplier_bps: u16§latency_penalty_microunits_per_ms: u64

Implementations§

Source§

impl PolicySnapshot

Source

pub fn new_unchecked( policy_epoch: u64, catalog_epoch: u64, hard_risk_limit_bps: u16, minimum_confidence_bps: u16, risk_penalty_multiplier_bps: u16, latency_penalty_microunits_per_ms: u64, models: Vec<KernelModel>, ) -> Self

Creates a policy snapshot without validation (escape hatch).

§Production guidance

Use try_new for any policy served to real traffic. new_unchecked is for unit tests, fuzz fixtures, and experiments where you call validate yourself or intentionally construct invalid catalogs.

Serving from an unchecked snapshot without a successful validate() is an audit failure.

Source

pub fn new( policy_epoch: u64, catalog_epoch: u64, hard_risk_limit_bps: u16, minimum_confidence_bps: u16, risk_penalty_multiplier_bps: u16, latency_penalty_microunits_per_ms: u64, models: Vec<KernelModel>, ) -> Self

👎Deprecated since 0.3.9:

use PolicySnapshot::try_new for validated snapshots or new_unchecked for tests

Creates a new policy snapshot from a model catalog (alias for new_unchecked).

Source

pub fn models(&self) -> &[KernelModel]

Returns the model catalog.

Source

pub fn validate(&self) -> Result<(), PolicyError>

Validate catalog and basis-point invariants before serving traffic.

Source

pub fn try_new( policy_epoch: u64, catalog_epoch: u64, hard_risk_limit_bps: u16, minimum_confidence_bps: u16, risk_penalty_multiplier_bps: u16, latency_penalty_microunits_per_ms: u64, models: Vec<KernelModel>, ) -> Result<Self, PolicyError>

Build a snapshot and validate the catalog.

Source

pub fn prescribe_batch(&self, inputs: &[KernelInput]) -> Vec<KernelDecision>

Evaluate many inputs. Allocates the output vector only.

Source

pub fn prescribe_with_trace( &self, input: KernelInput, ) -> (KernelDecision, DecisionTrace)

Evaluate input and return decision plus rejection histogram.

Source

pub fn prescribe(&self, input: KernelInput) -> KernelDecision

Evaluate input against the policy and return the optimal decision.

The kernel checks 11 constraint gates per candidate, computes utility as quality_adjusted_value - risk_penalty - cost - latency_penalty, and selects the candidate with the highest positive utility.

If no candidate has positive utility, the request is rejected (fail-closed). The decision also records the counterfactual (second-best) candidate.

This function does not allocate.

Source

pub fn utility_for_model( &self, input: KernelInput, model_id: u32, ) -> Option<i64>

Evaluate utility for a specific catalog model if it passes all constraint gates.

Unlike prescribe, this does not rank candidates — it only answers whether model_id is eligible and what its utility would be.

Trait Implementations§

Source§

impl Clone for PolicySnapshot

Source§

fn clone(&self) -> PolicySnapshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PolicySnapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.