FrankenNumPy

Docs/Evidence

Reading the Evidence Ledger

The EvidenceLedger in fnp-runtime is the audit trail for every runtime decision. If you embed the dual-mode runtime, you get a structured record of which input class hit which code path with what posterior risk. The actual data model (verified against crates/fnp-runtime/src/lib.rs):

pub struct DecisionEvent {
    pub ts_millis: u128,                       // milliseconds since the Unix epoch
    pub mode: RuntimeMode,                     // Strict | Hardened
    pub class: CompatibilityClass,             // KnownCompatible | KnownIncompatible | Unknown
    pub risk_score: f64,                       // log-likelihood ratio of incompatibility
    pub action: DecisionAction,                // Allow | FullValidate | FailClosed (reason travels via `reason_code` below)
    pub posterior_incompatible: f64,           // probability of incompatibility, 0.0..=1.0
    pub expected_loss_allow: f64,              // loss-model term for the Allow branch
    pub expected_loss_full_validate: f64,      // loss-model term for the FullValidate branch
    pub expected_loss_fail_closed: f64,        // loss-model term for the FailClosed branch
    pub selected_expected_loss: f64,           // the minimum of the three (whichever branch we picked)
    pub evidence_terms: Vec<EvidenceTerm>,     // per-evidence log-likelihood-ratio contributions
    pub fixture_id: String,                    // correlates to the fixture, request, or call site
    pub seed: u64,                             // RNG seed in effect (when relevant)
    pub env_fingerprint: String,               // host/CPU/toolchain fingerprint
    pub artifact_refs: Vec<String>,            // pointers to associated artifacts (sidecars, proofs)
    pub reason_code: String,                   // stable slug, mirrors the per-error reason_code() pattern
    pub note: String,                          // free-form annotation
}

pub struct EvidenceTerm {
    pub name: &'static str,                    // e.g. "input.shape_within_bounds"
    pub log_likelihood_ratio: f64,             // negative = pulls toward compatible; positive = toward incompatible
}

EvidenceLedger itself is a thin Vec<DecisionEvent> with record(...), events() -> &[DecisionEvent], and last() methods. EvidenceLedger::new() keeps every event; EvidenceLedger::bounded(capacity) keeps at most capacity of the most recent ones, evicting the oldest half when full, and reports capacity() and the number evicted in dropped(). The Python layer's ledger (fnp_python.get_runtime_decisions()) is bounded at 4,096 events. There is no built-in JSON/JSONL serializer. DecisionEvent derives only Debug + Clone + PartialEq, no serde. Embedders that need on-disk ledgers add their own writer over the public field accessors (the field set is stable across patches).

When you read an event:

  • mode tells you which runtime mode was active. Strict skips most full-validate paths; Hardened opts into them on elevated risk.
  • class is the input classification. Unknown and KnownIncompatible always fail closed; KnownCompatible is the interesting case.
  • action is what we did. Compare against the Runtime Mode Matrix to confirm it matches the policy.
  • risk_score is the caller's risk score in [0, 1] (compared against the threshold by the mode matrix). Higher means more evidence of incompatibility.
  • posterior_incompatible is the audit's posterior probability of incompatibility. Values close to 0 mean "safe accept"; values close to 1 mean "definitely incompatible".
  • expected_loss_{allow, full_validate, fail_closed} are the three actions' expected losses under the loss model; selected_expected_loss is the loss of the action actually taken. The action itself comes from the mode matrix, so a gap between selected_expected_loss and the smallest of the three shows where the policy and the loss model disagree.
  • evidence_terms is the breakdown of the posterior's log-odds: prior_class_log_odds (the class prior) and risk_vs_threshold_llr (the risk score's log-odds minus the threshold's).
  • fixture_id / seed / env_fingerprint / artifact_refs / reason_code are the six fields that the Threat Model section requires every audit entry to carry. note is free-form context.

Override events live in a separate OverrideAuditEvent stream so that explicit human bypasses of a fail-closed gate are auditable distinctly from automatic decisions. An override record's fields are: ts_millis, mode, class, requested_deviation_class, packet_id, requested_by, reason_code, approved: bool, action, audit_ref. The requested_by + audit_ref pair makes the human responsible for each override traceable to a ticket/PR.

For pipelines that need cryptographic non-repudiation, a serialized ledger snapshot can be fed into the same RaptorQ artifact-durability stack (sidecar + scrub + decode proof) so it survives single-symbol loss.


This section in the README on GitHub