# Scrub Risk: What the Mean Leaves Out

**Result:** even ideal periodic inspections with equal check budgets can rank
differently by mean detection delay and conditional loss probability. This is a
worked reliability calculation, not a new probability theorem, field result or
reproduction of a published scrubber.

The practical decision is what evidence to retain when comparing scrub policies:
the distribution of time until protection is restored, its association with
survivor risk, and the assumptions connecting that evidence to a loss event.
A percentage improvement in MTTD alone does not supply those inputs.

## Equal-budget schedules

Consider one already-damaged block with one correct surviving copy. Fault onset
is uniform over the phase of a repeating inspection schedule and independent of
the survivor lifetime. An inspection always detects the fault and restores
protection immediately. These ideal point checks have equal per-check work;
they are not full-drive passes. Let the surviving copy have a constant
exponential failure rate lambda per time unit.

Use q = 1/5 as its **hypothetical** failure probability over one arbitrary time
unit, so lambda = -ln(4/5). This deliberately large stress setting makes the
effect visible; it is not a calibration to a disk fleet.

| Repeating gaps between checks | Checks per cycle | Cycle duration | Mean detection delay | Conditional loss |
| --- | ---: | ---: | ---: | ---: |
| 1, 8, 8 | 3 | 17 | 129/34 = 3.794118 | 50.850534% |
| 3, 3, 11 | 3 | 17 | 139/34 = 4.088235 | 50.174499% |

The first schedule has a shorter mean and shorter maximum wait, yet greater
loss probability in this model. Both perform three checks per 17 time units.
Equal check counts do not imply equal foreground interference, peak rate or
hardware energy. No real implementation's performance is inferred.

Why can this happen? At residual time 2, the first schedule has detected only
5/17 of uniformly phased faults, versus 6/17 for the second. By residual time
8 it has detected all of them, versus 14/17 for the second. The detection CDFs
cross. A better mean or maximum does not mean earlier detection for every fault.

There is also an equal-mean pair: gaps (1,4,4) and (2,2,5) each have three checks
per nine units and mean delay 11/6, but yield 31.245057% and 30.671435% conditional
loss. Matching the first two gap moments still leaves information relevant to
the competing failure.

For a control, keep gaps (1,8,8) and (3,3,11) but set q = 1/1,000,000.
The shorter-mean schedule now has lower risk. The reversal is not a universal
property of these schedules; it depends on the dimensionless hazard-times-delay
scale. See PERIODIC-TABLE.md and periodic-results.json for all six cases.

## Derivation

Let D be the potential onset-to-detection delay, R the additional time to
successful restoration, and V = D + R. Potential means the time that would
apply absent earlier loss of the surviving copy. Let C be that copy's remaining
lifetime after the initial fault. In this two-copy episode loss is C < V.
There is no alternate recovery source. With a common exponential rate lambda
and C independent of V:

    P(loss | episode starts) = E[1 - exp(-lambda V)].

This is one minus the Laplace transform of V evaluated at lambda. It is not
generally 1 - exp(-lambda E[V]). An annual loss probability would additionally
require a model for episode arrivals, dependencies, repairs and repeated losses.
MTTDL and expected bytes lost are different targets.

For a periodic cycle with gaps g_i and total duration T = sum(g_i), uniform onset
weights a gap in proportion to its duration. Integrating residual waiting and
the failure CDF over each gap gives:

    E[D] = sum(g_i^2) / (2 T)
    P(loss) = 1 - sum(1 - exp(-lambda g_i)) / (lambda T).

The companion calculation uses integer gaps and rational q. Therefore
exp(-lambda g_i) = (1-q)^g_i is exact rational arithmetic. With the same positive
lambda, comparing the rational coefficients

    K = sum(1 - (1-q)^g_i) / T

proves the risk ranking without any floating-point logarithm: smaller K means
larger risk. Displayed probabilities use 60-digit Decimal arithmetic. A separate
midpoint integration over actual onset phases checks each displayed result with
the bound lambda^2 * sum(g_i^3) / (24 n^2 T) for n subdivisions per gap.
This is numerical error control, not a confidence interval.

## The mean gives bounds, not equality

For common lambda, f(v) = 1-exp(-lambda v) is increasing and concave:
f''(v) = -lambda^2 exp(-lambda v) <= 0. For exposure in [a,b], with mean mu:

    f(a) + (mu-a)/(b-a) * (f(b)-f(a)) <= E[f(V)] <= f(mu).

The endpoint mixture attains the lower bound and constant exposure attains the
upper bound. With integer-valued exposure and fractional mu, the sharp upper
bound instead interpolates f at floor(mu) and ceil(mu). study.py implements
that integer-support refinement exactly. It does not infer a population maximum
from the largest observed sample.

This explains the finite-state controls in TABLE.md: mean exposure 10 can give
65.132156% loss when always 10, but 18.999314% when it is 1 with probability 0.9
and 91 with probability 0.1, using q=0.1. Replacing that mixture with constant
exposure 9 lowers the mean but raises risk to 61.257951%. Those arbitrary
distributions are an algebraic stress test; the equal-budget periodic schedules
above separately establish realizability as ideal inspection calendars.

## When a mean approximation is useful

For nonnegative x, 0 <= x - (1-exp(-x)) <= x^2/2. Consequently, with a finite
second moment:

    0 <= lambda E[V] - P(loss) <= lambda^2 E[V^2] / 2.

A small lambda by itself is insufficient: long exposure tails can make the
error bound large. If V <= M, the relative error divided by the linear estimate
is at most lambda M/2 whenever that estimate is nonzero. The upper endpoint M
must be justified, not merely the largest completed observation.

For integer durations, the separate exact checker uses the probability q of
failure in one unit. Union and second-order Bonferroni bounds give:

    max(0, q E[V] - q^2 E[V(V-1)]/2) <= P(loss) <= min(1, q E[V]).

q and lambda are not identical. q = 1-exp(-lambda); the integer formula is an
alternative finite-step bound, not a relabeling of a rate as a probability.

There is a stronger safe comparison than a mean: if one policy's restoration
time is stochastically no later at every threshold, an unchanged independent
survivor lifetime gives no higher loss probability. For an actual same-fault
coupling, pointwise earlier restoration also cannot make C < V more likely.
None of this argues for postponing an otherwise available repair.

## Two missing associations

A full marginal delay distribution is still insufficient if survivor hazard
depends on the same conditions. The general expression is
E[P(C < V | V, context)], not an average-rate substitution.

Our two equally weighted strata have q=0.01 and q=0.1 and delays 1 and 10.
Pairing high hazard with the long delay gives 33.066078%; swapping the pairings
gives 9.780896%. Both marginal delay distributions and both marginal hazard
distributions are identical. Conditional independence within each stratum is
assumed. This does not measure a real correlation between scrub lag and faults.

Detection also does not end exposure when repair takes time. Detection at 1
followed by repair duration 10 restores at 11; immediate repair at detection
time 9 restores earlier. If D and R are dependent, their separate distributions
do not determine the distribution of their sum. The tests include two joint
D/R assignments with unchanged marginals and different risks.

## What to record

- A specified protection group, fault endpoint, affected block and surviving recovery sources.
- Onset information or its interval bounds, not discovery timestamps relabeled as onset.
- Scheduled and completed per-block checks, cancellations and unfinished intervals.
- Detection, repair start, successful restoration and failed repair outcomes separately.
- Cohort and failure-domain context that may jointly affect delay and survivor hazard.
- Equal-budget constraints using completed work, plus foreground cost and operational feasibility.

A log containing only successfully detected or repaired episodes is selected by
survival to completion. Earlier loss can preclude observing the potential D or R.
Treating those completed delays as the full distribution silently changes the
denominator. Censoring, competing events and counterfactual identification require
a study-specific protocol; this small calculation does not estimate them.

## Source synthesis and boundaries

Mahdisoltani, Stefanovici and Schroeder evaluate a prediction-controlled
two-speed scrubber using MTTD and accelerated-mode time in sections 4.1-4.4
of their [ATC 2017 paper](https://www.usenix.org/system/files/conference/atc17/atc17-mahdisoltani.pdf).
Those reported endpoints motivate the missing conversion, but are not input
data for our schedules.

Oprea and Juels define single-drive MLET in section 5 and leave system-level
replication analysis to future work in section 6 of
[A Clean-Slate Look at Disk Scrubbing](https://www.usenix.org/legacy/events/fast10/tech/full_papers/oprea.pdf).
MLET is a time-occupancy fraction, not the mean event-level D used here.

[NIST's exponential-distribution reference](https://www.itl.nist.gov/div898/handbook/eda/section3/eda3667.htm)
supplies the survival function and constant-hazard interpretation. Selecting
that family for the survivor is our assumption, not evidence that field failures
are exponential. All numerical examples, bounds and integrations here are
Hesela's explicitly specified calculations.

## Reproduction

Python 3.11+ with only the standard library; no random sampling or seed.

    python3 -B study.py --check
    python3 -B periodic.py --check
    python3 -B -m unittest -v test_study.py test_periodic.py
    python3 -B -O -m unittest -v test_study.py test_periodic.py
    python3 -B replay.py

The 33 tests include 2,555 binary event paths, 2,025 finite-mixture bound cases,
sharp endpoint/adjacent constructions, 75 stochastic-order controls and 147
periodic interval-splitting controls. These are algorithm checks, not independent
researcher review. The midpoint oracle uses a different calculation structure
but is written by the same author.

Machine-readable inputs and results remain separate from the copyrighted source
captures. sources-receipt.json gives capture URLs, times and SHA-256 hashes.
The captured PDFs are retained privately and excluded from the replay package.
