Expand description
Sequential allocation leak detection using CUSUM and e-process.
This module monitors per-frame allocation counts/bytes as a time series and detects sustained mean-shift regressions with formal guarantees.
§Mathematical Model
§CUSUM (Cumulative Sum Control Chart)
Tracks one-sided cumulative deviation from a reference mean μ₀:
S_t⁺ = max(0, S_{t-1}⁺ + (x_t − μ₀ − k)) // detect upward shift
S_t⁻ = max(0, S_{t-1}⁻ + (μ₀ − k − x_t)) // detect downward shiftwhere k is the allowance (slack) parameter, typically δ/2 for a
target shift of δ. Alert when S_t⁺ ≥ h or S_t⁻ ≥ h.
CUSUM is quick to detect sustained shifts but is not anytime-valid: it controls ARL (average run length) rather than Type I error.
§E-Process (Anytime-Valid Sequential Test)
Maintains a wealth process over centered residuals r_t = x_t − μ₀:
E_0 = 1
E_t = E_{t-1} × exp(λ × r_t − λ² × σ² / 2)where:
σ²is the assumed variance under H₀λis the betting fraction (adaptive via GRAPA or fixed)
Alert when E_t ≥ 1/α. This provides anytime-valid Type I control:
P(∃t: E_t ≥ 1/α | H₀) ≤ α.
§Dual Detection Strategy
| Detector | Speed | Guarantee | Use |
|---|---|---|---|
| CUSUM | Fast (O(δ) frames) | ARL-based | Quick alerting |
| E-process | Moderate | Anytime-valid α | Formal confirmation |
An alert fires when both detectors agree (reduces false positives) or when the e-process alone exceeds threshold (formal guarantee).
§Failure Modes
| Condition | Behavior | Rationale |
|---|---|---|
σ² = 0 | Clamp to σ²_min | Division by zero guard |
E_t underflow | Clamp to E_MIN | Prevents permanent zero-lock |
E_t overflow | Clamp to E_MAX | Numerical stability |
| No observations | No state change | Idle is not evidence |
Structs§
- Allocation
Budget - Allocation budget monitor with dual CUSUM + e-process detection.
- Budget
Alert - Alert information when a leak/regression is detected.
- Budget
Config - Configuration for the allocation budget monitor.
- Budget
Evidence - Evidence ledger entry for diagnostics.
- Budget
Summary - Diagnostic summary.
- Evidence
Context