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: u64Cost penalty per millisecond of p95 latency, in microunits.
No static upper bound — overflow is dynamically guarded by
all_latencies_fit which falls back to i128 arithmetic when
max_p95_latency_ms * latency_penalty_microunits_per_ms would
overflow u64.
Implementations§
Source§impl PolicySnapshot
impl PolicySnapshot
Sourcepub 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
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.
Sourcepub 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
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
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).
Sourcepub fn models(&self) -> &[KernelModel]
pub fn models(&self) -> &[KernelModel]
Returns the model catalog.
Sourcepub fn validate(&self) -> Result<(), PolicyError>
pub fn validate(&self) -> Result<(), PolicyError>
Validate catalog and basis-point invariants before serving traffic.
Sourcepub 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>
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.
Sourcepub fn prescribe_batch(&self, inputs: &[KernelInput]) -> Vec<KernelDecision>
pub fn prescribe_batch(&self, inputs: &[KernelInput]) -> Vec<KernelDecision>
Evaluate many inputs. Allocates the output vector only.
Sourcepub fn prescribe_batch_checked(
&self,
inputs: &[KernelInput],
) -> Result<Vec<KernelDecision>, InputError>
pub fn prescribe_batch_checked( &self, inputs: &[KernelInput], ) -> Result<Vec<KernelDecision>, InputError>
Validate and evaluate many inputs, failing before producing decisions when any request is structurally invalid.
Sourcepub fn prescribe_with_trace(
&self,
input: KernelInput,
) -> (KernelDecision, DecisionTrace)
pub fn prescribe_with_trace( &self, input: KernelInput, ) -> (KernelDecision, DecisionTrace)
Evaluate input and return decision plus rejection histogram.
Sourcepub fn prescribe_with_trace_checked(
&self,
input: KernelInput,
) -> Result<(KernelDecision, DecisionTrace), InputError>
pub fn prescribe_with_trace_checked( &self, input: KernelInput, ) -> Result<(KernelDecision, DecisionTrace), InputError>
Validate input, then evaluate it with an explainability trace.
Sourcepub fn prescribe(&self, input: KernelInput) -> KernelDecision
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.
Sourcepub fn prescribe_checked(
&self,
input: KernelInput,
) -> Result<KernelDecision, InputError>
pub fn prescribe_checked( &self, input: KernelInput, ) -> Result<KernelDecision, InputError>
Validate input, then evaluate it.
This is the recommended API at untrusted Rust boundaries. The unchecked
prescribe path remains available for callers that
have already validated or constructed the input through a safe builder.
Sourcepub fn utility_for_model(
&self,
input: KernelInput,
model_id: u32,
) -> Option<i64>
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
impl Clone for PolicySnapshot
Source§fn clone(&self) -> PolicySnapshot
fn clone(&self) -> PolicySnapshot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more