Skip to content

Commit b95eb37

Browse files
committed
fix(qualify): give the box the baseline it cannot have, so the guard judges
Every snapshot in results/ says outcome "seed", baseline_samples 0, drift null - on every box, for every gateway, in every run since the check was written. The box qualification has never once judged anything. The cause is where the history lives. `qualify_history` reads previous observations out of the results directory, which is correct when the engine runs beside the record. In the field it does not: every gateway gets a fresh EC2 instance that fetches its own manifest and the rig and nothing else, so the directory is empty, the baseline is absent, and judging degrades to seeding. A box running well under the field's rate would have seeded a fresh baseline, reported "seed", and had a whole gateway column measured on it. The orchestrator holds what the box cannot, so it now hands it over in OTB_QUALIFY_BASELINE, appended to whatever the directory yields rather than replacing it. The observation is the RIG's own loopback throughput at a fixed concurrency, not the gateway's, so the baseline pools across all gateways rather than per gateway: it is the box being qualified, and the boxes are identical by construction. Median, so one anomalous past box cannot move it. Sized against the real field rather than a guess. Across the 2026-07-28 run the 14 boxes observed 475906 to 509142 rps against a 497862 median - a worst deviation of 4.4% - and the band is 20%, so activating the guard fails no healthy box. The test asserts exactly that: the slowest and fastest real boxes of that field both pass, and 300000 fails. Confirmed RED without the handed baseline: the history comes back empty, which is the seed-forever behaviour the field has had all along.
1 parent cbff1a5 commit b95eb37

2 files changed

Lines changed: 109 additions & 4 deletions

File tree

‎engine/src/suite.rs‎

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,38 @@ fn qualify_box(cfg: &SuiteConfig, history: &[f64]) -> serde_json::Value {
757757
})
758758
}
759759

760-
/// Every previous box-qualification observation this results directory holds.
760+
/// Every previous box-qualification observation available to this run.
761761
///
762-
/// Read from the historical snapshots rather than a side file, so the baseline cannot drift from the
763-
/// runs that produced it: a snapshot IS the record. An unreadable or old-shaped file contributes
764-
/// nothing rather than a zero, which would drag the median toward a value no run ever observed.
762+
/// TWO SOURCES, BECAUSE THE BOX HAS NO HISTORY OF ITS OWN.
763+
///
764+
/// Reading the results directory is right when the engine runs where the record lives. In the field
765+
/// it does not: every gateway gets a FRESH EC2 instance that fetches its own manifest and the rig,
766+
/// and nothing else. That directory is empty there, so the baseline was absent, so the qualification
767+
/// seeded instead of judging - every box, every gateway, every run since the check was written. A
768+
/// box running 30% slow would have seeded a fresh baseline and passed, and its gateway's whole
769+
/// column would have been measured on a rig nothing compared against anything.
770+
///
771+
/// `OTB_QUALIFY_BASELINE` is how the orchestrator hands over what it knows: it holds the history and
772+
/// the box does not. A single observation is enough to judge against - `rolling_baseline` takes the
773+
/// median of what it is given - and the env value is appended to whatever the directory yields
774+
/// rather than replacing it, so running where the record does live still uses the record.
775+
///
776+
/// The observation is the RIG's own loopback throughput at a fixed concurrency, not the gateway's,
777+
/// which is why one pooled baseline across gateways is the right comparison and not a per-gateway
778+
/// one: it is the box being qualified.
765779
fn qualify_history(results_dir: &Path) -> Vec<f64> {
780+
let mut out = qualify_history_on_disk(results_dir);
781+
if let Some(v) = std::env::var("OTB_QUALIFY_BASELINE").ok().and_then(|v| v.trim().parse::<f64>().ok()) {
782+
if v > 0.0 {
783+
out.push(v);
784+
}
785+
}
786+
out
787+
}
788+
789+
/// The part that reads the directory, separated so the env contribution above is testable without a
790+
/// filesystem and this stays a pure function of what is on disk.
791+
fn qualify_history_on_disk(results_dir: &Path) -> Vec<f64> {
766792
let Ok(entries) = std::fs::read_dir(results_dir) else {
767793
return Vec::new();
768794
};
@@ -1685,4 +1711,54 @@ mod tests {
16851711
);
16861712
let _ = std::fs::remove_dir_all(&dir);
16871713
}
1714+
1715+
// THE BOX HAS NO HISTORY, SO THE BASELINE HAS TO BE HANDED TO IT.
1716+
//
1717+
// `qualify_history` read the results directory, which is right where the engine runs beside the
1718+
// record and empty where it actually runs: every gateway gets a fresh EC2 instance carrying its
1719+
// manifest and the rig and nothing else. So the baseline was absent, the qualification seeded
1720+
// instead of judging, and every snapshot in results/ says outcome "seed", baseline_samples 0,
1721+
// drift null - on every box, for every gateway, since the check was written. A guard that always
1722+
// seeds cannot catch the box it exists to catch.
1723+
#[test]
1724+
fn a_handed_baseline_lets_the_box_qualification_actually_judge() {
1725+
let empty = std::path::Path::new("/nonexistent-results-dir-for-this-test");
1726+
// What the field had: nothing on disk, and nothing handed over.
1727+
std::env::remove_var("OTB_QUALIFY_BASELINE");
1728+
assert!(
1729+
qualify_history(empty).is_empty(),
1730+
"with no history the baseline is absent and the qualification can only seed"
1731+
);
1732+
let (outcome, drift) = crate::qualify::judge(
1733+
Measurement::Measured(500_000.0),
1734+
crate::qualify::rolling_baseline(qualify_history(empty)),
1735+
QUALIFY_BAND_PCT,
1736+
crate::qualify::Sense::HigherIsBetter,
1737+
);
1738+
assert_eq!(outcome.token(), "seed");
1739+
assert_eq!(drift.value().copied(), None, "seeding has nothing to drift against");
1740+
1741+
// What the orchestrator can hand over, since it holds the record the box does not.
1742+
std::env::set_var("OTB_QUALIFY_BASELINE", "497862");
1743+
assert_eq!(qualify_history(empty), vec![497_862.0]);
1744+
1745+
// A healthy box - the widest real deviation across the 2026-07-28 field was 4.4% - passes.
1746+
let judge_at = |rps: f64| {
1747+
crate::qualify::judge(
1748+
Measurement::Measured(rps),
1749+
crate::qualify::rolling_baseline(qualify_history(empty)),
1750+
QUALIFY_BAND_PCT,
1751+
crate::qualify::Sense::HigherIsBetter,
1752+
)
1753+
.0
1754+
.token()
1755+
};
1756+
assert_eq!(judge_at(475_906.0), "pass", "the slowest real box of the field must still pass");
1757+
assert_eq!(judge_at(509_142.0), "pass", "and so must the fastest");
1758+
// The box this guard exists for: far enough under that its gateway's whole column would
1759+
// have been measured on a rig nothing compared against anything.
1760+
assert_eq!(judge_at(300_000.0), "fail");
1761+
1762+
std::env::remove_var("OTB_QUALIFY_BASELINE");
1763+
}
16881764
}

‎run-on-ec2.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,35 @@ BENCH_ENGINE_COMMIT="$(git -C "$HERE" rev-parse HEAD 2>/dev/null || echo '')"
257257
if [ -n "$(git -C "$HERE" status --porcelain -- . ':(exclude)results' 2>/dev/null)" ]; then BENCH_ENGINE_DIRTY=1; else BENCH_ENGINE_DIRTY=0; fi
258258
export BENCH_ENGINE_COMMIT BENCH_ENGINE_DIRTY
259259

260+
# THE BOX HAS NO HISTORY, SO THE ORCHESTRATOR HANDS IT ONE.
261+
#
262+
# The engine qualifies its box by driving the mock directly and comparing against a rolling baseline
263+
# of previous observations, which it reads from the results directory. That is right where the engine
264+
# runs beside the record; in the field it does not. Every gateway gets a fresh instance that fetches
265+
# its manifest and the rig and nothing else, so that directory is empty, the baseline is absent, and
266+
# the qualification SEEDS instead of judging - which is what every snapshot in results/ shows, on
267+
# every box, for every gateway, since the check was written. An inert guard: a box running well under
268+
# the field's rate would have seeded a fresh baseline, passed, and had a whole gateway column
269+
# measured on it.
270+
#
271+
# The observation is the RIG's own loopback throughput at a fixed concurrency, not the gateway's, so
272+
# the baseline pools across ALL gateways rather than being per gateway: it is the box being
273+
# qualified, and the boxes are identical by construction. Median, so one anomalous past box cannot
274+
# move it. Empty (and skipped) when there is no history yet, which is exactly the first run.
275+
OTB_QUALIFY_BASELINE="$(
276+
find "$HERE/results/snapshots" -name 'result_*.json' -type f 2>/dev/null \
277+
| xargs -r grep -ho '"observed_rps"[[:space:]]*:[[:space:]]*[0-9.]*' 2>/dev/null \
278+
| sed 's/.*:[[:space:]]*//' \
279+
| sort -n \
280+
| awk '{ v[NR] = $1 } END { if (NR) printf "%.0f", (NR % 2) ? v[(NR + 1) / 2] : (v[NR / 2] + v[NR / 2 + 1]) / 2 }'
281+
)"
282+
if [ -n "$OTB_QUALIFY_BASELINE" ]; then
283+
export OTB_QUALIFY_BASELINE
284+
echo "box qualification baseline: ${OTB_QUALIFY_BASELINE} rps (median of prior observations)"
285+
else
286+
echo "box qualification: no prior observations, this run seeds the baseline"
287+
fi
288+
260289
case "$ARCH" in
261290
arm64|aarch64|graviton)
262291
ARCH=arm64

0 commit comments

Comments
 (0)