Calybris Core
A small Rust decision engine for auditable, deterministic policy decisions.
Calybris Core evaluates candidates under hard constraints, selects the highest-utility valid option, and records decisions through tamper-evident primitives.
The first packaged use case is LLM/model routing: choosing between models under budget, latency, risk, quality, provider, and region constraints. The core pattern is domain-neutral — any system that chooses between candidates under constraints can use the same primitives.
Built from three components:
kernel— Integer-only decision kernel. 11 constraint gates, ~115ns per decision. No floating-point, no allocation in the hot path.wal— Hash-chained write-ahead log. SHA-256 or HMAC-SHA256. Generic over anySerializetype.budget— CAS atomic budget engine. Conservation invariant:remaining + reserved + committed = initial.
#![forbid(unsafe_code)] · 37 tests · 6 direct dependencies · Apache-2.0
Quick Start
use *;
let models = vec!;
let snapshot = new;
let decision = snapshot.prescribe;
// decision.action: ExecuteRequested | Substitute | Reject
// decision.selected_model_id: which model was chosen
// decision.expected_utility_microunits: why
Modules
kernel.rs
The kernel scores every candidate model with:
utility = quality_adjusted_value - risk_penalty - cost - latency_penalty
All values are basis points (1/10,000) or microunits (1/1,000,000). The fast path uses u64 with overflow guards; when inputs don't fit, it falls back to u128. Proptest verifies both paths agree on every random input.
Constraints checked per decision: risk ceiling, confidence floor, quality minimum, budget limit, latency cap, capability match, provider mask, region mask, cost, utility sign, optimality.
wal.rs
// Unkeyed — detects accidental corruption
let mut wal = open?;
let entry = wal.append?;
// Keyed — attacker can't forge valid hashes
let mut wal = open_keyed?;
Chain is validated on open. Constant-time comparison (subtle) on keyed WALs. append() writes to the OS buffer; call flush_and_sync() when you need crash durability.
budget.rs
let engine = new;
engine.ensure_tenant;
let = engine.try_reserve;
engine.commit; // surplus refunded
Arc<AtomicI64> per tenant, cloned out before the CAS loop — no mutex held during contention. Lock ordering: reservations → budgets.
Benchmarks
cargo bench
| Benchmark | Time | Notes |
|---|---|---|
| prescribe (22 models) | 115 ns | ~8.6M/sec |
| prescribe (4 models) | 36 ns | |
| prescribe (64 models) | 522 ns | Linear scaling |
| reject (risk gate) | 15 ns | Early exit |
Results from Criterion on one machine. Your numbers will differ.
Tests
cargo test # 37 tests (36 + 1 doc)
cargo test --release # includes latency guard
Includes proptest property-based verification, 100-thread concurrency stress, HMAC chain validation, and WAL fuzz roundtrips.
What This Crate Is Not
This is the open-source decision core. It doesn't include:
- Adaptive routing (Thompson Sampling)
- Policy evolution (counterfactual replay)
- HTTP gateway or API server
- Prompt classification models
Those are part of the proprietary engine. See emirhuseyin.tech/engine for the full architecture.
Contributing
See CONTRIBUTING.md. Issues labeled good first issue are a good starting point.
License
Apache-2.0. See LICENSE.