diff --git a/tests/test_dashboard_breakers.py b/tests/test_dashboard_breakers.py index ddf522fe4..5d57f3dc4 100644 --- a/tests/test_dashboard_breakers.py +++ b/tests/test_dashboard_breakers.py @@ -1,8 +1,10 @@ """Breakers panel (design 9): resolved settings, status snapshots, trips, alerts, run status.""" import json +import os import shutil import subprocess +import sys from pathlib import Path import pytest @@ -532,6 +534,35 @@ def test_large_stale_drops_go_red(): assert guard_alerts(r, T0 + 3600) == [(0, "breaker trainer.policy_age dropped 40% of the groups")] +TIED_ISLANDS = """ +import sys +from yeto.dashboard.reducer import Reducer + +r = Reducer() +for island in (1, 0): + for i in range(12): + t = 1_790_000_000.0 + 60 * i + r.feed({"event": "rl_buffer_stale_skipped", "island_id": island, "time_unix": t, "rollout_id": i, + "stale_groups": 4, "max_policy_age": 2}) + r.feed({"event": "rl_round_trained", "island_id": island, "time_unix": t + 30, "rollout_id": i, + "trained_groups": 6}) +print(r.guard_drop_rates()["trainer.policy_age"]["scope"]) +""" + + +def test_two_islands_with_the_same_drop_rate_name_the_same_island_under_any_hash_seed(): + """The rate shown is the worst scope's; of two scopes with the same ratio the panel + names the same one in every process (string hashes, and so a set's order, change with + PYTHONHASHSEED).""" + root = Path(__file__).resolve().parent.parent + scopes = set() + for seed in range(8): + out = subprocess.run([sys.executable, "-c", TIED_ISLANDS], cwd=root, check=True, capture_output=True, + text=True, env={**os.environ, "PYTHONHASHSEED": str(seed), "PYTHONPATH": str(root)}) + scopes.add(out.stdout.strip()) + assert scopes == {"island 0"} + + def test_drop_rate_warning_and_window(): r = Reducer() trainer_rounds(r, 10, trained=8, stale=1) # 1 of 9: 11 % diff --git a/yeto/dashboard/breakers.py b/yeto/dashboard/breakers.py index e153dd58c..496459ff2 100644 --- a/yeto/dashboard/breakers.py +++ b/yeto/dashboard/breakers.py @@ -308,7 +308,9 @@ def drop_rates(self, window: int, min_total: float) -> dict[str, dict]: (the open sampler round included), when that scope saw at least ``min_total``; ``drop_rounds``: the rounds of the window that dropped anything.""" out: dict[str, dict] = {} - keys = set(self.rounds) | set(self._open) + # In a fixed order: of two scopes with the same ratio the first one is reported, so a + # set's order (string hashes, PYTHONHASHSEED) must not pick it. + keys = sorted(set(self.rounds) | set(self._open), key=lambda key: (str(key[0]), tuple(map(str, key[1])))) for name, scope in keys: rows = list(self.rounds.get((name, scope)) or ()) cur = self._open.get((name, scope))