Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api_relay_audit/latency_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Given ``count`` successful samples:

count < 3 -> "inconclusive"
mean <= 0 -> "inconclusive"
bimodality detected -> "bimodal"
CV < 0.25 -> "stable"
0.25 <= CV < 0.5 -> "variable"
Expand Down Expand Up @@ -164,6 +165,8 @@ def classify_variance(stats, is_bimodal):
"""
if not stats or stats.get("count", 0) < 3:
return "inconclusive"
if stats.get("mean", 0.0) <= 0:
return "inconclusive"
if is_bimodal:
return "bimodal"
cv = stats.get("cv", 0.0)
Expand Down
14 changes: 12 additions & 2 deletions audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Regenerate after modular audit changes with:
# python3 scripts/build-standalone.py
# CI verifies this generated artifact plus key behavior regressions.
# source_sha256: 6fb11df52ddf05eeab8989ad23f0039c9038f369a0db942427cad02e883e980b
# standalone_body_sha256: badbe213d9e8f5ee25a551fec8cb7a6e82b6253b38c5bcb2e9b62ca58ce57aae
# source_sha256: 9efb15db9395ea199650974647bb458bcd05a81c2efbca3769322c8b87d7a351
# standalone_body_sha256: 55332e36882d1a25938b9b30243e8a0da9340a89b571784bf3eec7f3fd8eca5f
# END GENERATED STANDALONE HEADER

"""
Expand Down Expand Up @@ -4274,6 +4274,7 @@ def run_infra_fingerprint(client):
Given ``count`` successful samples:

count < 3 -> "inconclusive"
mean <= 0 -> "inconclusive"
bimodality detected -> "bimodal"
CV < 0.25 -> "stable"
0.25 <= CV < 0.5 -> "variable"
Expand Down Expand Up @@ -4410,6 +4411,8 @@ def classify_variance(stats, is_bimodal):
"""
if not stats or stats.get("count", 0) < 3:
return "inconclusive"
if stats.get("mean", 0.0) <= 0:
return "inconclusive"
if is_bimodal:
return "bimodal"
cv = stats.get("cv", 0.0)
Expand Down Expand Up @@ -6191,6 +6194,13 @@ def test_latency_variance(client, report, probe_count=10):
f"Latency **stable** (CV={stats['cv']:.2f}). "
"Consistent with a single honest upstream.",
)
elif stats.get("mean", 0.0) <= 0:
report.flag(
"yellow",
"Latency variance **inconclusive**: successful probes measured "
"zero or non-positive latency. This indicates mocked or broken "
"timing infrastructure; re-run in a real network environment.",
)
else: # inconclusive
report.flag(
"yellow",
Expand Down
7 changes: 7 additions & 0 deletions scripts/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,13 @@ def test_latency_variance(client, report, probe_count=10):
f"Latency **stable** (CV={stats['cv']:.2f}). "
"Consistent with a single honest upstream.",
)
elif stats.get("mean", 0.0) <= 0:
report.flag(
"yellow",
"Latency variance **inconclusive**: successful probes measured "
"zero or non-positive latency. This indicates mocked or broken "
"timing infrastructure; re-run in a real network environment.",
)
else: # inconclusive
report.flag(
"yellow",
Expand Down
4 changes: 4 additions & 0 deletions tests/test_latency_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def test_fewer_than_three_samples_inconclusive(self):
stats = summarize_latencies([1.0, 1.1])
assert classify_variance(stats, False) == "inconclusive"

def test_zero_mean_stats_inconclusive(self):
stats = summarize_latencies([0.0, 0.0, 0.0])
assert classify_variance(stats, False) == "inconclusive"

def test_bimodal_takes_precedence(self):
"""Even if the CV is below the stable cutoff, a detected
bimodal distribution wins -- clustering is a stronger
Expand Down
Loading