Zero-latency, #![no_std] closed-loop adaptation kernel and Edgeworth higher-order retry tuner for distributed systems and agentic evaluation pipelines.
Authored by Chanak Karki.
Canonical Online Repository: github.com/darksolitaire9-hub/adapta
- Explain to Me Like I am a 5 Year Old (ELI5)
- Why This Helps LLMs and Humans
- Why adapta?
- Hexagonal Architecture (Ports & Adapters)
- Theoretical Foundations & Academic References
- Quantitative Verification & Guardrails
- Release Cycle & Versioning Strategy
- Security & Zero Data Leakage Guarantee
- Usage Example
- License
Imagine you are waiting for your friend to bring you a toy. Usually, they take 10 seconds. But sometimes, your friend gets distracted by a puppy on the sidewalk and takes 50 seconds!
If you get impatient and always walk away after 15 seconds, you will miss getting your toy whenever puppy days happen! But if you always wait 50 seconds every single time, you waste lots of time standing around when they aren't even distracted.
adapta is like a smart timer watch. It watches how often your friend gets distracted by puppies. When it notices puppy days are happening, it automatically gives your friend a little bit of extra time. When things are quiet again, it goes back to normal. That way, you never walk away too early, but you also never waste time standing around!
-
Deterministic Math & Explicit Guardrails: LLMs struggle with guessing statistical formulas or boundary conditions (like division-by-zero on zero variance). By explicitly tabulating exact mathematical invariants (
$N \ge 15$ ,$\sigma^2 \ge 1\text{e-}12$ , reference moments), LLMs can write evaluation loops and tests without hallucinating thresholds. - Token-Efficient Retrieval: The clear Table of Contents and modular Hexagonal Architecture allow agents to target specific domain ports or adapters during code generation without ingesting massive unorganized codebases.
- Zero-Cognitive-Load Integration: Engineers do not need a PhD in option pricing or self-supervised learning to use
adapta. They can plugAdaptiveLayerdirectly into their Tower/Tokio middleware stacks in 3 lines of code. - Enterprise Patent Safety: By providing dual licensing under MIT and Apache-2.0, legal teams get explicit patent retaliation protection while individual developers retain lightweight MIT freedom.
Standard distributed retry mechanisms and evaluation gates rely on static heuristics: fixed backoff schedules, Gaussian
adapta solves this by bridging online statistical physics and self-supervised representation learning into a zero-allocation, #![no_std] Rust kernel that adapts dynamically to system feedback.
Yes, adapta is designed strictly according to Hexagonal Architecture (Ports and Adapters) principles.
The architecture completely isolates the deterministic mathematical kernel (The Hexagon) from asynchronous network plumbing, I/O runtimes, and application control planes:
graph TD
subgraph Primary Inbound Adapters [Primary Inbound Adapters]
L[tower::Layer / AdaptiveLayer]
S[tower::Service / AdaptiveService]
E[SignalExtractor / LatencyExtractor]
end
subgraph Domain Core Hexagon [Domain Core Hexagon - no_std]
P["Port: AdaptationStrategy<E, O>"]
B[32-Sample Ring Buffer & Statistical Math]
G[Mathematical Guardrails: N >= 15, Var >= 1e-12]
end
subgraph Secondary Outbound Adapters [Secondary Outbound Adapters]
A1[EdgeworthBackoff - Skewness/Kurtosis Tuner]
A2[AdaJepaCorrector - Online Drift Corrector]
end
L -->|wraps| S
S -->|extracts E via| E
E -->|ingests signal into| P
P --- B
B --- G
P <|..| A1
P <|..| A2
At the center of adapta is the #![no_std] domain port:
pub trait AdaptationStrategy<E, O> {
fn observe(&mut self, signal: E);
fn adapt(&self) -> Option<O>;
fn sample_count(&self) -> usize;
}The core operates on fixed-capacity circular buffers without heap allocation, maintaining mathematical invariants independently of std, tokio, or tower.
- Port (
SignalExtractor<Res, Err>): Defines how raw asynchronous results are translated into scalar observation signals. - Adapters (
AdaptiveLayer&AdaptiveService): Implement standardtower::Layerandtower::Servicetraits. They intercept execution futures, measure elapsed time viaInstant::now(), and feed signals into the domain port without acquiring runtime locks during polling.
EdgeworthBackoff: Adapts statistical moments into upstream timeout multipliers.AdaJepaCorrector: Adapts online error gradients into test-time evaluation baselines.
adapta is built upon verifiable academic literature, translating continuous mathematical formulations into discrete, fault-tolerant software primitives:
- Reference: Corrado & Su (2004), "Testing Option Pricing with the Edgeworth Expansion", arXiv:cond-mat/0401192 (DOI/Link).
-
Mechanism: Standard Gaussian timeout models underestimate extreme tail delays in heavy-tailed systems.
EdgeworthBackoffcomputes sample skewness ($g_1$ ) and excess kurtosis ($g_2$ ) over a sliding window of recent latencies to expand safety margins: $$\hat{g}1 = \frac{m_3}{m_2^{3/2}}, \quad \hat{g}2 = \frac{m_4}{m_2^2} - 3$$ $$M = 1.0 + c{\text{skew}} \max(0, \hat{g}1) + c{\text{kurt}} \max(0, \hat{g}2)$$ $$\text{Timeout}{\text{new}} = \text{Timeout}{\text{base}} \times M$$
- Reference: Chanak Karki & AdaJEPA Authors (2026), "AdaJEPA: An Adaptive Latent World Model", arXiv:2606.32026 (DOI/Link).
-
Mechanism: To prevent false-positive regression alarms under benign environmental shift,
AdaJepaCorrectorperforms online 1-step gradient updates on evaluation baselines while enforcing a hard topological bound ($\Delta_{\max}$ ) against terminal invariant violations:$$\mu_{t+1} = \mu_t + \eta (L_t - \mu_t) \quad \text{if } |L_t - \mu_t| < \Delta_{\max}$$
To prevent LLM-generated numerical bugs, division-by-zero (NaN/Inf), or oscillatory collapse, adapta enforces strict mathematical guardrails verified via property-based testing (proptest) and deterministic golden test suites:
| Guardrail Parameter | Threshold Value | Enforcement Behavior |
|---|---|---|
| Minimum Sample Gate ( |
Returns exact base backoff ( |
|
| Zero-Variance Floor ( |
Returns exact base backoff if sample variance drops below NaN or Inf errors. |
|
| Max Drift Ceiling ( |
Immediately terminates evaluation and flags TERMINAL_REGRESSION_FAILURE without adapting baseline if error exceeds threshold. |
|
| Golden Reference Vector |
|
Deterministically verified against exact reference moments: Mean |
adapta follows Semantic Versioning (SemVer 2.0.0) backed by automated GitHub Actions CI/CD workflows:
v0.0.x(Alpha / Dogfooding - Current): Focused on architectural verification,#![no_std]compliance, and internal dogfooding within production environments (rmcpupstream pipelines andbinevalregression loops).v0.1.x(Beta / Feature Freeze): Public API stabilization, concurrency overhead benchmarking under high load, and Tower middleware trait graduation.v1.0.0(Production Release): Full stability guarantees, crates.io publication, and long-term support.
Every push to main triggers comprehensive linting (clippy), formatting checks (rustfmt), property-based tests (proptest), and #![no_std] verification. Pushing a release tag matching v*.*.* automatically triggers our GitHub Actions release pipeline (.github/workflows/release.yml), compiling production binaries and generating documented GitHub Releases.
adapta is built from the ground up for zero-trust execution environments:
-
Scalar-Only Ingestion: The adaptation kernel only observes scalar floating-point metrics (elapsed milliseconds or error scores
$E \in \mathbb{R}$ ). - No Payloads or PII: Request bodies, headers, user identifiers, network URLs, and filesystem paths are never touched, copied, or stored.
- No Telemetry or Logging: The crate contains zero network reporting, zero telemetry, and zero local filesystem writing. It cannot leak internal workspace structures or API secrets.
use adapta::edgeworth::EdgeworthBackoff;
use adapta::AdaptationStrategy;
let mut tuner = EdgeworthBackoff::new(100.0, 0.1, 0.05);
// Ingest latency observations from upstream requests
for latency in [10.0, 12.0, 15.0, 11.0, 10.0, 25.0, 30.0, 12.0, 11.0, 10.0, 10.0, 11.0, 14.0, 50.0, 12.0] {
tuner.observe(latency);
}
// Enforces N >= 15 minimum sample guardrail and computes skewness/kurtosis backoff
if let Some(adjusted_timeout) = tuner.adapt() {
println!("Adjusted upstream timeout: {:.2} ms", adjusted_timeout);
}Licensed under either of MIT License or Apache License, Version 2.0 at your option.
Copyright (c) 2026 Chanak Karki.