From eccc607c889a5a0f206777ae64921fa05f0cd5ed Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 22:16:29 +0000 Subject: [PATCH] fix(unit_timings): monitoring tiers only rows the both-gates policy calls drift legacy_summaries() sorted unit-test rows into red/yellow by ratio alone (3x / 1.5x), ignoring the configured both-gates policy (thresholds.unit_timings: slow_factor 2.0 AND min_delta_s 2) that each row's own `state` already applies. On 2026-11-15 that made monitoring RED for PyAutoNerves test_config, 0.015 s -> 0.043 s (measured locally at 5 ms on main), and yellow for PyAutoArray JAX tests whose raw CI times sat inside their historical range; every one of those rows said `ok`. A row the policy calls `ok` is now green, whatever its ratio; the 3x / 1.5x factors only tier rows already in `warn`. No threshold, factor or weight changes; the human ruling (option A) is recorded in PyAutoMind draft/bug/pyautoheart/unit_timing_monitoring_ignores_min_delta.md. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016nhQ8RkwYK9RzapmsQRGCj --- heart/checks/unit_timings.py | 20 +++++++++++++------- tests/test_unit_timings.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/heart/checks/unit_timings.py b/heart/checks/unit_timings.py index af390609..952428d2 100644 --- a/heart/checks/unit_timings.py +++ b/heart/checks/unit_timings.py @@ -170,9 +170,12 @@ # The legacy "Unit-test timing" section says "(>3× baseline)" / "(>1.5×)" in its # own summary wording, which it inherited from the dev-box check's rolling -# median. These two constants exist ONLY to keep that wording truthful when the -# section is fed from CI rows; the rows' own advisory `warn` state is the -# both-gates rule above, and nothing here changes it. +# median. These two constants only split rows that ALREADY failed the +# both-gates rule above (their own `warn` state) into the section's red and +# yellow tiers; a row the policy calls `ok` is green, whatever its ratio. Before +# 2026-11-15 the tiers read `ratio` alone, so a 28 ms change on a 15 ms test was +# a "3× regression" and turned monitoring RED while the row itself said ok +# (PyAutoMind draft/bug/pyautoheart/unit_timing_monitoring_ignores_min_delta.md). LEGACY_RED_FACTOR = 3.0 LEGACY_YELLOW_FACTOR = 1.5 @@ -784,12 +787,15 @@ def legacy_summaries( "run_speed_factor": row.get("run_speed_factor", 1.0), "normalized_seconds": row.get("normalized_seconds", row.get("seconds")), } - if ratio > LEGACY_RED_FACTOR: + # One policy: the row's own both-gates state (`slow_factor` AND + # `min_delta_s`, config/repos.yaml) decides whether this is drift at + # all; the legacy factors only tier what it already called `warn`. + if row.get("state") != "warn": + unit["green"].append(entry) + elif ratio > LEGACY_RED_FACTOR: unit["red"].append(entry) - elif ratio > LEGACY_YELLOW_FACTOR: - unit["yellow"].append(entry) else: - unit["green"].append(entry) + unit["yellow"].append(entry) evidence_times = [str(r.get("at")) for r in repos if r.get("at")] evidence_ts = min(evidence_times) if evidence_times else None diff --git a/tests/test_unit_timings.py b/tests/test_unit_timings.py index 3f5ea257..f6a4d195 100644 --- a/tests/test_unit_timings.py +++ b/tests/test_unit_timings.py @@ -532,6 +532,40 @@ def test_the_legacy_unit_buckets_keep_the_sections_wording_truthful(tmp_path): assert unit["yellow_count"] == 1 and unit["red_count"] == 0 +def test_a_large_ratio_under_the_absolute_floor_is_green_not_a_regression(tmp_path): + """2026-11-15: PyAutoNerves test_config 0.015 s -> 0.043 s (3.01x) turned + monitoring RED while its own row said ok; locally it measured 5 ms. The + policy's `min_delta_s` floor decides, the ratio alone never does.""" + side = _sidecar(tmp_path, junit=_junit(_case(time="0.050"))) + roll = ut.aggregate([side], "T", THRESHOLDS, record_prev_rows=_prev_rows(0.015)) + (row,) = roll["tests"] + assert row["state"] == "ok" and row["ratio"] > ut.LEGACY_RED_FACTOR + unit, _ = ut.legacy_summaries(roll, THRESHOLDS) + assert unit["red_count"] == 0 and unit["yellow_count"] == 0 + assert unit["green_count"] == 1 + + +def test_a_slowdown_under_the_slow_factor_is_green_even_past_the_floor(tmp_path): + """1.55x and +5.6 s (a JAX step0 test normalised on a fast runner) is no + drift: under `slow_factor`, whatever the absolute delta.""" + side = _sidecar(tmp_path, junit=_junit(_case(time="15.8"))) + roll = ut.aggregate([side], "T", THRESHOLDS, record_prev_rows=_prev_rows(10.2)) + unit, _ = ut.legacy_summaries(roll, THRESHOLDS) + assert unit["red_count"] == 0 and unit["yellow_count"] == 0 + + +def test_only_rows_that_pass_both_gates_reach_the_red_and_yellow_tiers(tmp_path): + side = _sidecar(tmp_path, junit=_junit(_case(time="2.5"))) + roll = ut.aggregate([side], "T", THRESHOLDS, record_prev_rows=_prev_rows(1.0)) + unit, _ = ut.legacy_summaries(roll, THRESHOLDS) + # 2.5x but only +1.5 s: under the 2 s floor, so not a regression. + assert unit["yellow_count"] == 0 and unit["green_count"] == 1 + side = _sidecar(tmp_path, sub="red", junit=_junit(_case(time="9.0"))) + roll = ut.aggregate([side], "T", THRESHOLDS, record_prev_rows=_prev_rows(2.0)) + unit, _ = ut.legacy_summaries(roll, THRESHOLDS) + assert unit["red_count"] == 1 + + def test_an_unavailable_repo_is_listed_never_counted_as_measured(tmp_path): dead = ut.build_sidecar("RepoB", "libraries", OWNER, [], "T", error="boom") roll = ut.aggregate([_sidecar(tmp_path), dead], "T", THRESHOLDS)