# In-flight observations are not completion samples

This is Hesela's constructed finite trace, not a device benchmark, a stochastic queue simulation, or an empirical replication of the sources. A lives in [0,10) ms; B and C in [0,1) ms. Full eventual durations are known for every request. No confidence interval or independent sample size is claimed.

## Three declared observation designs

- Select one of the three requests uniformly: full-duration mean 4 ms.
- Pool all active request-time observations uniformly over [0,10): 12 request-ms of exposure; full-duration mean 102/12 = 8.5 ms.
- Select a time uniformly in the nonempty part of [0,10), then one of its active requests uniformly: full-duration mean (4 + 9*10)/10 = 9.4 ms.

These are exact continuous integrals. Real periodic polling only approximates this weighting when its cadence and phase are justified; aliasing can matter. Pooling retains every active operation, so snapshots with higher occupancy contribute more rows. Selecting just one per nonempty snapshot gives each time equal weight.

For complete positive lifetimes d_i, pooled weight is d_i / sum(d), and the mean full duration is sum(d_i^2)/sum(d_i). Integrating age and remaining time separately gives sum(d_i^2)/(2 sum(d_i)) for each: 4.25 ms here, not 8.5 ms. This finite accounting identity requires no iid, Poisson or stationary queue assumption. It is an application derived by Hesela, not an assertion that every queue satisfies a particular renewal model.

A restricted window instead weights request i by the overlap of its lifetime with that window. Cropping this trace to [0,1) gives equal weights and a full-duration mean of 4 ms; elapsed age averages 0.5 ms and remaining time 3.5 ms. In real data the future finish may be unknown, so neither full duration nor remaining time can be reconstructed from the age field alone.

## Sources and limits

Karl Sigman, Introduction to Renewal Theory (2018), sections 1.7-1.8, explains length-biased interval inspection:
https://www.columbia.edu/~ks20/4106-18-Fall/Notes-Renewal-Theory.pdf

Maria Vlasiou, Renewal Processes with Costs and Rewards, author PDF dated 5 October 2018, examples 3-4, pp. 4-6, derives age/excess averages and the occupancy-area identity underlying Little's law:
https://ris.utwente.nl/ws/portalfiles/portal/249488824/10.1002_9780470400531.eorms0722.pdf

Sources accessed 2026-11-19. They establish mathematical results, not storage measurements. The three-request overlap counterexample and its tests are original explanatory arithmetic. No third-party diagrams or source PDFs are redistributed.

## Reproduce

Python 3.10+ standard library only, no random seed:
python3 -B model.py --check
python3 -B -m unittest discover -s . -p test_model.py

Use --write to regenerate results.json. Tests include an independent discrete-midpoint oracle for all 256 pairs with starts 0..3 and lengths 1..4 ms. Integer endpoints make that oracle exact. Additional checks cover cropping, idle time, translation, units, permutations and rejected inputs; tests also run with Python -O.

Repeated appearances of the same request do not create independent completions. Preserve request identifiers and the arrival/completion boundary. This calculation does not infer service time from response time, correct coordinated omission, or recover unknown future completions.

## Exact integration without rescanning every request

For request i with known lifetime [a_i,b_i), clip to [L,U):
l_i = max(a_i,L), u_i = min(b_i,U), e_i = max(0,u_i-l_i).
The pooled denominator is A = sum(e_i), in request-milliseconds.
The pooled full-duration numerator is sum(e_i * (b_i-a_i)).
Nonoverlapping requests receive zero observation weight.

For each positive overlap, its age integral is
e_i * ((l_i-a_i) + (u_i-a_i)) / 2; its remaining-time integral is
e_i * ((b_i-l_i) + (b_i-u_i)) / 2.
Divide the summed integrals by A for the two means.
Their sum equals the pooled mean full duration for any window,
although each need not be half that mean. Keeping the original endpoints
in these formulas is essential: clipping changes exposure, not request age.

For time-first selection, let N(t) count active requests and let B be the
nonempty time in [L,U). Define H(t) as the integral from L to t of 1/N(s)
where N(s)>0, with integrand zero while idle. Request i's unnormalized weight
is H(u_i)-H(l_i) for positive overlap. Its probability is that difference
divided by B. Summing the unnormalized weights gives B: at a busy time,
the N(t) active requests each receive 1/N(t).

The implementation sorts clipped starts and finishes, aggregates their
count changes at equal times, then advances H once between adjacent
endpoints. It never enumerates the active requests on each segment.
At most 2n event keys are needed for n requests. The algorithm uses
O(n log n) endpoint comparisons and O(n) rational arithmetic operations
and storage entries, instead of quadratic rescanning. This is not a
constant-cost bit-complexity claim: exact fractions can have large
numerators and denominators.

All request and window endpoints must be integers or Python Fraction
values; floats and booleans are rejected. Zero-duration lifetimes and
windows with no overlap are rejected. The requests count and
request_mean_full_ms describe **all supplied requests**, even those
outside the window; only the two observation-weighted schemes are
conditioned on overlap. Removing outside requests silently would change
the declared request cohort.

The optimization preserves the existing output fields and results.json
byte for byte. Tests add 1,548 small trace/window cases, rational endpoints,
coincident events, duplicate lifetimes, outside requests and an exact
large-coordinate/tiny-duration check. A Python-line-work regression
rejects the old repeated scan without a machine-speed threshold.
The 4,096-request disjoint trace has independently known uniform weights.

Source sections above were revisited on 2026-11-27. They motivate the
distinction between full lifetime and age/excess; the clipped formulas
and inverse-occupancy sweep here are Hesela's finite-trace derivation.
No renewal-limit theorem is needed for these finite sums.

## Concurrency can reverse the ordering of sampled means

Taking one active request per sampled time does not always exaggerate the
per-request mean. For three concurrent 2 ms requests followed by three
serial 1 ms requests, that mean is 1.5 ms, but time-first selection gives
1.4 ms. Pooling every active observation gives 5/3 ms. All six complete
lifetimes are known; no request is censored or removed.

The distinction is how observation time is allocated. The three long requests
share two milliseconds, while the three short requests occupy three separate
milliseconds. Time-first selection assigns the long group probability 2/5,
below its request-cohort share of 1/2. Pooled observations instead assign it
6/9 of the request-time exposure.

### Which mean is larger?

Let E_B mean a uniform continuous average over the nonempty portion of the
window. Let N(t) be active-request count and M(t) the arithmetic mean **full
eventual duration** of the active requests. Set M(t) only where N(t)>0.
Then, directly from the two sampling designs,

- time-first mean = E_B[M];
- pooled mean = E_B[N M] / E_B[N];
- pooled minus time-first = Cov_B(N,M) / E_B[N].

Here Cov_B(N,M) = E_B[N M] - E_B[N] E_B[M] is an exact finite-time covariance,
not an estimated population covariance or a causal effect of queue depth.
This identity also holds for cropped lifetimes: the active set is clipped,
but the duration attached to each active request is still its full lifetime.
Busy-time conditioning is essential. Idle periods contribute no selections.

Positive covariance makes the pooled mean larger; negative covariance
reverses the ordering. Constant busy-time occupancy is sufficient for equality,
but is not necessary. Zero covariance establishes equality of these **means**,
not equality of every request's selection probability.

### Four exact controls

Intervals below are half-open and all times are milliseconds. Repeated
intervals are distinct requests. The first row retains the original example.

| Trace | Request mean (ms) | Pooled mean (ms) | Time-first mean (ms) | Cov_B(N,M) (request-ms) |
| --- | --- | --- | --- | --- |
| [0,10), [0,1), [0,1) | 4 | 17/2 | 47/5 | -27/25 |
| [0,10), [0,10), [10,11) | 7 | 67/7 | 101/11 | 90/121 |
| Three [0,2), then [2,3), [3,4), [4,5) | 3/2 | 5/3 | 7/5 | 12/25 |
| [0,10), [10,11), [11,12) | 4 | 17/2 | 17/2 | 0 |

[Exact results and traces](selection-results.json) and the
[standard-library calculation](selection.py) expose every denominator,
request probability and busy-time occupancy total. The original
[results.json](results.json) and observe() return contract are unchanged.

The companion calculation tracks active count and the sum of full durations
at each endpoint; it does not scan all requests for each segment. It uses
O(n log n) endpoint comparisons, subject to the same rational bit-size caveat
as the main integration. Its moments are checked against the independently
enumerated midpoint oracle and the per-request integral implementation.

### Interpretation and reproduction

A marginal histogram of complete durations determines the pooled mean when
the full trace is included, but does not determine the time-first mean:
the overlap pattern also matters. Serializing the six requests in the
third row preserves the request and pooled means but raises the time-first
mean from 7/5 to 5/3 ms. This is a constructed rearrangement, not a prediction
that changing a real device's scheduling preserves its request durations.

An observer who knows only current ages cannot calculate M(t). These
equations do not reconstruct unknown completions, estimate a confidence
interval, or justify a universal correction for snapshots. Record the
request cohort, sampling design, window and completion availability before
interpreting latency averages.

This is finite-trace arithmetic derived from the declared designs, not a
new renewal theorem or a counterexample to the inspection paradox. Sigman's
sections 1.6-1.8 concern intervals of a renewal process; Vlasiou's examples
3-4 distinguish age/excess rewards and occupancy-area accounting. Neither
result licenses treating a choice among concurrent requests as an unweighted
request sample. Sources above were checked again on 2026-11-27.

Run from this directory:

```sh
python3 -B selection.py --check
python3 -B -m unittest discover -s . -p test_model.py
python3 -B -O -m unittest discover -s . -p test_model.py
```

Use selection.py --write to regenerate only the companion JSON.

## Periodic polling can miss every request

The continuous calculation above is not automatically the result of a periodic
monitor. Consider four 0.1 ms requests at [0.1,0.2), [1.1,1.2), [2.1,2.2) and
[3.1,3.2), observed within [0,4) ms. Polling every 1 ms at phase 0 sees none.
The same cadence at phase 0.15 sees all four. More repetitions with the same
alignment need not remove this error.

[Exact polling results](polling-results.json), the [counter](polling.py) and
[independent grid tests](test_polling.py) make this caveat executable. Every
interval and the observation window is half-open: a start is included, a
finish is excluded. These tie rules are consequential for deterministic
sampling. Full eventual request durations remain known in these examples.

| Trace | Phase (ms) | Polls | Nonempty polls | Request-observations | Pooled full-duration mean (ms) |
| --- | --- | --- | --- | --- | --- |
| Four short requests | 0 | 4 | 0 | 0 | undefined |
| Four short requests | 3/20 | 4 | 4 | 4 | 1/10 |
| [0,1), [0,1/2) | 1/4 | 1 | 1 | 2 | 3/4 |
| [0,1), [0,1/2) | 3/4 | 1 | 1 | 1 | 1 |

An empty observation set has **undefined latency**, represented by JSON null,
not a latency of zero. Absence from snapshots is not evidence of no requests.

### What a random start fixes, and what it does not

Let the period be h and choose one phase Phi uniformly from [0,h), independently
of the fixed trace. Poll at Phi+k*h for integer k, restricted to [L,U).
Let c_i(Phi) be the number of snapshots containing request i, and e_i its
continuous window overlap. Partitioning the real line into periods gives

E_Phi[c_i] = e_i/h.

Thus h times the total request-observation count is an unbiased estimate of
the continuous request-time exposure for this design. No iid lifetimes or
Poisson arrivals are required. However, counts from different polls are not
independent: the same phase controls the whole grid.

Define X(Phi) = sum_i c_i(Phi)*d_i and Y(Phi) = sum_i c_i(Phi), where d_i is
the full duration. The ratio E[X]/E[Y] equals the continuous pooled mean.
The average of X/Y over random starts need not equal that ratio.

For the two requests [0,1) and [0,1/2), h=1 and window [0,1), every phase
produces one nonempty snapshot. Phases in [0,1/2) give X/Y=3/4 ms; the remaining
half give 1 ms. The mean snapshot ratio is therefore 7/8 ms, while the
continuous pooled mean is (1+1/4)/(1+1/2)=5/6 ms. Their difference is 1/24 ms.
There is no missing-sample conditioning in this example.

For the four-short-request trace, 9/10 of random phases produce no request
observations at all. The exact phase summary reports this undefined
probability separately and conditions its mean of ratios on nonempty
observations. It never silently replaces undefined ratios with zero.

Choosing one uniform active request per nonempty snapshot has its own
denominator: the number of nonempty snapshots, not total request-observations.
The code computes its expected full duration within each snapshot exactly;
it does not draw individual requests. Ratios of phase-averaged totals recover
the corresponding continuous design, but phase-averaged ratios require their
own analysis. In the two-request example, the time-first mean is 7/8 ms under
both the continuous design and uniform phase. That equality is not a general
promise about all windows and traces.

### Counting without enumerating a long polling grid

For a positive clipped overlap [l_i,u_i), the eligible integer indices are

ceil((l_i-Phi)/h) <= k < ceil((u_i-Phi)/h).

Their count is the upper bound minus the lower bound. An endpoint sweep in
integer-index space then counts nonempty snapshots and sums their active
mean durations, without visiting every poll or materializing each active set.
The counter uses O(n log n) comparisons and O(n) arithmetic/storage entries
for n supplied requests, independent of the number of grid points; large
integer and rational bit sizes still cost work.

The exact phase average partitions [0,h) at endpoint residues. Counts and
full-duration sums are constant between these breakpoints; integrating their
constant values is exact, not a Monte Carlo estimate or a coarse phase grid.

Two sweeps avoid recalculating every request for every phase. First, split the
clipped trace into intervals [s,t) with constant active count N and sum D of
full durations. On a busy interval each poll contributes the vector

(N, 1, D, D/N)

to request-observations, nonempty polls, pooled numerator and time-first
numerator. Its poll count at phase zero is ceil(t/h)-ceil(s/h). As phase
increases past s mod h, that count rises by one; at t mod h it falls by one.
Residue-zero changes are already represented by the initial count. Aggregate
all changes at equal residues before evaluating the next open region.

A second sweep in residue order updates the four totals and integrates their
ratios with region-width/h weights. It keeps idle regions, undefined ratios,
clipped exposure and full original durations distinct. Endpoints have zero
probability under continuous uniform phase; deterministic poll() still honors
the stated half-open tie convention.

There are O(n) occupancy segments and residue events. Both sweeps together use
O(n log n) endpoint comparisons and O(n) rational arithmetic/storage entries,
replacing O(n) calls to the whole counter. Exact integer/rational bit costs
remain outside that operation-count bound. The phase_regions field retains
all original endpoint residues, including those of outside-window requests,
for compatibility; such breakpoints can partition regions with equal totals.

Tests compare every output field against a separate per-poll phase enumerator
for 2,025 rational trace/window/period designs. A work-growth test rejects the
previous repeated-scan implementation, and a 4,096-request aligned trace has
closed-form means. Existing polling-results.json remains byte-identical.

Tests compare 1,296 trace/window/grid configurations with an independent
per-poll enumerator and check 108 phase-integral identities against the
continuous model. Controls cover negative coordinates, endpoint ties,
cropping, scaling, no polls, no overlap and a 10^30-poll interval. The latter
checks compressed counting, not real monitoring throughput.

### Evidence and operational scope

Statistics Canada's [systematic sampling guidance](https://www150.statcan.gc.ca/n1/edu/power-pouvoir/ch13/prob/5214899-eng.htm)
describes a random start followed by fixed intervals and warns that periodic
population structure can make possible samples unrepresentative. This is
sampling-design context; the temporal traces and exact calculations above
are Hesela's worked examples, not survey results.

Ronald W. Wolff, [Poisson Arrivals See Time Averages](https://doi.org/10.1287/opre.30.2.223),
Operations Research 30(2), 223-231 (1982), section 1 and Theorem 1, establishes
a long-run equality under Poisson observation and lack of anticipation.
[The original paper](https://www.math.purdue.edu/~peterson/Teaching/532/PASTA.pdf)
also distinguishes an expected-count identity from conditional statements
in Remark 4. Neither result licenses substituting a deterministic polling
grid for the specified observation process or assuming a finite random
ratio is unbiased. The original theorem is not being refuted here.
Both sources were read on 2026-11-27.

The derivation assumes a fixed trace that the monitor does not perturb,
exact timestamps, a declared endpoint convention and known full durations.
Actual timer jitter, dropped observations, clock quantization, polling cost
and unknown future completions require separate treatment. Record those
conditions and the sampling phase before interpreting a snapshot histogram.

From this directory:

```sh
python3 -B polling.py --check
python3 -B -m unittest discover -s . -p 'test_*.py'
python3 -B -O -m unittest discover -s . -p 'test_*.py'
```

Use polling.py --write to regenerate polling-results.json and the exposure-variance
companion below. The existing continuous model, selection companion and all
previous numerical results are retained.

## More aligned polls need not improve relative precision

Repeat the short-request pattern for n periods: request i lives in
[i+1/10,i+1/5) ms for i=0,...,n-1, with window [0,n) and period h=1 ms.
Choose one uniform phase and retain it for every poll. Let Z indicate whether
that phase lies in [1/10,1/5). Then Z is Bernoulli with p=1/10, and the
estimated exposure A_hat=h*sum(c_i) equals n*Z request-ms.

The true exposure is A=n/10 request-ms. Therefore

E[A_hat]=A, Var(A_hat)=9*n^2/100 (request-ms)^2,
Var(A_hat/A)=9.

The estimator is unbiased over random starts, yet its relative standard
deviation is 3 (300%) for every n. The estimate is zero with probability 9/10
and ten times the truth with probability 1/10. A longer aligned trace adds no
new phase information. This is a constructed periodic case, not a claim about
all systematic samples or observed storage workloads.

[Generated exposure-variance results](phase-variance-results.json) use the
same exact phase sweep, independently checked by enumerating ten equal-width
phase regions. The comparison column uses a different design: one fresh,
independent uniform timestamp inside each 1 ms period. Its hit indicators
are independent Bernoulli(1/10), so its variance is 9*n/100 instead.

| Requests / periods | True exposure (request-ms) | Common-phase variance ((request-ms)^2) | Independent-per-period variance ((request-ms)^2) |
| --- | --- | --- | --- |
| 1 | 1/10 | 9/100 | 9/100 |
| 4 | 2/5 | 36/25 | 9/25 |
| 16 | 8/5 | 576/25 | 36/25 |
| 64 | 32/5 | 9216/25 | 144/25 |

Here the common-phase variance is n times the independent-per-period variance.
Ordinary scheduler jitter is not necessarily independent uniform sampling.
The table does not recommend changing a production timer without measuring
cost, timestamp behavior and any effect on the observed workload.

Werner Gautschi's [Some Remarks on Systematic Sampling](https://cs.purdue.edu/homes/wxg/selected_works/appendix/A6.pdf),
Annals of Mathematical Statistics 28 (1957), 385-394, section 1, frames a
systematic sample as selection of a cluster. Its multiple-start construction
samples distinct starts without replacement; it is not the independent
per-period timestamp design used in this table.

Li-Chun Zhang's [On Some Common Practices of Systematic Sampling](https://www.scb.se/contentassets/ca21efb41fee47d293bbee5bf7be7fb3/on-some-common-practices-of-systematic-sampling.pdf),
Journal of Official Statistics 24(4) (2008), 557-569, section 1, distinguishes
variance for a fixed ordering from variance averaged over population models
or permutations. A favorable average over hypothetical orderings does not
establish precision for one particular trace. Both primary papers were
consulted on 2026-11-27; the temporal construction above is Hesela's arithmetic.

The calculated variance requires the complete fixed trace and the declared
randomization. It is not an estimator of uncertainty from one partially seen
trace, and it is not a confidence interval. Keep the sampling unit, phase
dependence and denominator explicit before treating poll counts as an
independent sample size. These results concern exposure, not latency variance.

## Keeping each request once still favors long overlaps

Removing repeated sightings changes the sampling unit from request-observations
to distinct request identities. It does not make every request equally likely
to appear. For the same fixed trace and common uniform phase, let e_i be
request i's positive overlap with the observation window. Its inclusion
probability is

pi_i = P(c_i > 0) = min(1, e_i/h).

This is Hesela's interval calculation: an overlap shorter than one period
covers e_i/h of the phase circle; an overlap at least h contains a grid point
for every phase. Use the **clipped overlap**, not the full eventual lifetime.
A long request that barely intersects the window can still have small pi_i.

The target cohort here is the set of distinct requests with positive window
overlap, not arrivals or completions within the window. Requests wholly outside
have pi_i=0 and are explicitly excluded. Each supplied trace row denotes its
own request identity; equal timestamp pairs do not make two requests identical.

For selected identities S, define the inverse-inclusion totals

N_hat = sum(i in S) 1/pi_i,
D_hat = sum(i in S) d_i/pi_i.

Since E[1(i in S)]=pi_i, these totals have expectations N and sum(d_i) for this
cohort, without assuming independent request selections. Count each identity
once, not once per poll. For a request observed three times with pi_i=1,
its count contribution is 1, not 3.

This is an application of Horvitz and Thompson's
[original total estimator](https://doi.org/10.1080/01621459.1952.10483446),
JASA 47(260), 663-685 (1952), equation (6), p. 669.
Their pp. 670-672 distinguish positive individual inclusion from positive
pair inclusion needed by the stated unbiased variance estimator, and discuss
the zero-pair-probability problem for systematic sampling. Positive pi_i alone
does not justify an independent-sample standard error.

### An unbiased total is not an unbiased ratio

Reuse requests [0,1) and [0,1/2), window [0,1), and h=1 ms.
Their inclusion probabilities are 1 and 1/2; the cohort mean is 3/4 ms.
[Generated distinct-request results](inclusion-results.json) and
[independent controls](test_inclusion.py) use the existing [counter](polling.py).

| Phase region (ms) | Unique sample mean (ms) | N_hat | D_hat (ms) | D_hat/N_hat (ms) | D_hat/N (ms) |
| --- | --- | --- | --- | --- | --- |
| [0,1/2) | 3/4 | 3 | 2 | 2/3 | 1 |
| [1/2,1) | 1 | 1 | 1 | 1 | 1/2 |
| Equal-phase expectation | 7/8 | 2 | 3/2 | 5/6 | 3/4 |

Every phase sees at least one request, so these expectations do not condition
away empty samples. The unweighted unique mean averages to 7/8 ms. Weighting
and then normalizing by the **estimated** count gives 5/6 ms, still different
from 3/4 ms. The ratio of the expected totals is 3/4 ms, but that is not the
expectation of their ratio. Normalizing D_hat by an independently known,
fixed N=2 does give an unbiased mean. It requires that extra information.

For an empty sample, the estimated totals are zero and the sample ratios are
undefined. With a nonempty target cohort and independently known N, D_hat/N
is zero on that outcome; retaining such outcomes is part of its unconditional
unbiasedness. It does not mean that no requests occurred or their latency was
zero. With an empty target cohort, even the target mean is undefined.

The code is a complete-trace demonstration, not a deployable correction from
ages alone. Selected requests need known start/finish times and window overlap;
missing completions or a phase correlated with the trace invalidate the stated
calculation. Small inclusion probabilities also produce large weights.
[Zong, Zhu and Zou (2019), section 2](https://www150.statcan.gc.ca/n1/pub/12-001-x/2019001/article/00007/02-eng.htm)
discuss that variance issue; their section 4 treats ratio estimation separately.
We do not implement their modified estimator or claim their asymptotic results
for this trace. These are exact constructed examples, not device measurements.
