# LRB candidate-sampling boundary
Source-function probe of rank() at upstream commit
9e8b4423383c01c4528deb447f152f0437a37c3a, retrieved 2026-11-19.

Run `python3 verify.py --check` with Python 3 and g++.
Keep harness.cpp, results.json and the upstream directory alongside verify.py.
The source hashes and BSD-2-Clause license are retained.

The original rank() is extracted unchanged. Cache state is constructed, and
LightGBM prediction is replaced by a deterministic test double. Model presence
is injected; no model is trained. This tests candidate-loop control flow only,
not end-to-end simulator reachability, policy quality or CDN performance.

Eight cases run at -O0 and -O2. A two-second subprocess timeout bounds each
probe. Timeout alone is not proof of an infinite loop: the proof is that a set
drawn from n distinct resident keys cannot grow to k when n < k. The original
loop rejects duplicates and requires k distinct candidates before prediction.
No-model and oldest-age >= memory-window branches return before that loop.

A local comparison caps the per-call sample budget at the resident count.
It keeps the exact fallback and full-budget results in these fixtures and
makes the six failing case/optimization combinations reach prediction and
return. This is a proposed local correction, not an upstream merge. Nonempty
residents and positive sample count remain preconditions. It does not prove
all simulator states, native prediction behavior or policy equivalence when
the budget is reduced. Never interpret the two-second bound as a latency result.
