From 190d0369010038a111046b14635077a9e6752dbf Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 23 Nov 2026 11:05:17 -0700 Subject: [PATCH] Fix exploration slot and same-maker review explanation --- sisi/routing.py | 17 ++++++++++++----- tests/test_orchestration.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/sisi/routing.py b/sisi/routing.py index d56f98b..ea7f266 100644 --- a/sisi/routing.py +++ b/sisi/routing.py @@ -244,12 +244,14 @@ def choose(candidates, records, availability, kind, difficulty, review_of=None, pool.sort(key=key) choice = pool[0] if pool else None explored = None - if choice is not None and difficulty == 1 and not _pattern_match(choice, prefer): + if (choice is not None and difficulty == 1 and not _pattern_match(choice, prefer) + and _cell(stats, choice["worker"], kind, difficulty)["n"] >= MIN_ATTEMPTS): total = sum(_cell(stats, c["worker"], kind, difficulty)["n"] for c in candidates) - if total >= EXPLORE_EVERY and total % EXPLORE_EVERY == EXPLORE_EVERY - 1: + if total >= EXPLORE_EVERY - 1 and total % EXPLORE_EVERY == EXPLORE_EVERY - 1: thinner = [c for c in pool - if _cell(stats, c["worker"], kind, difficulty)["n"] < MIN_ATTEMPTS - and price_of(c) < price_of(choice)] + if c is not choice + and _cell(stats, c["worker"], kind, difficulty)["n"] < MIN_ATTEMPTS + and price_of(c) <= price_of(choice)] if thinner: thinner.sort(key=key) explored, choice = choice, thinner[0] @@ -311,7 +313,12 @@ def explain_choice(result, kind, difficulty): lines.append("this is an exploration pick: %s was the usual choice, passed over once so a cheaper " "thin-record worker gathers evidence" % result["explored"]) if result.get("author_maker"): - lines.append("it is from a different maker than the author (%s)" % result["author_maker"]) + choice_maker = choice.get("maker") or maker_of(choice.get("model") or choice["worker"]) + if choice_maker != result["author_maker"]: + lines.append("it is from a different maker than the author (%s)" % result["author_maker"]) + else: + lines.append("no worker from a different maker than the author (%s) is available, " + "so the review stays with the same maker" % result["author_maker"]) groups, order = {}, [] for worker, reason in result["passed_over"]: if reason not in groups: diff --git a/tests/test_orchestration.py b/tests/test_orchestration.py index ca961b6..1be15c5 100644 --- a/tests/test_orchestration.py +++ b/tests/test_orchestration.py @@ -252,6 +252,34 @@ class DigestTests(OrchCase): self.assertEqual(got2["count"], 0) +class ExplorationTests(unittest.TestCase): + def test_one_low_stakes_task_in_ten_tries_the_cheaper_thin_worker(self): + """About one difficulty-1 task in ten explores a cheaper thin-record worker.""" + from sisi import routing + cands = [ + {"worker": "tool/alpha-1", "tool": "tool", "model": "alpha-1", "maker": "alpha", + "plan": "per-use", "cost": 5.0, "allowance_pct_left": None, "usable": True, + "aliases": ["tool/alpha-1", "alpha-1"]}, + {"worker": "tool/beta-1", "tool": "tool", "model": "beta-1", "maker": "beta", + "plan": "per-use", "cost": 5.0, "allowance_pct_left": None, "usable": True, + "aliases": ["tool/beta-1", "beta-1"]}, + ] + # Same price: alpha (proven, stronger prior) is the usual pick. Every tenth judged + # attempt for the kind and difficulty, the thin-record beta gets the task instead. + cands[0]["prior_score"] = 90.0 + cands[1]["prior_score"] = 10.0 + records = [{"kind": "attempt", "id": "e%d" % i, "type": "read", "difficulty": 1, + "worker": "tool/alpha-1", "outcome": "accepted", "check": "tests"} + for i in range(9)] + before = routing.choose(cands, records[:-1], {}, "read", 1, now=1000.0) + self.assertEqual(before["choice"]["worker"], "tool/alpha-1") + tenth = routing.choose(cands, records, {}, "read", 1, now=1000.0) + self.assertEqual(tenth["choice"]["worker"], "tool/beta-1") + self.assertEqual(tenth["explored"], "tool/alpha-1") + again = routing.choose(cands, records, {}, "read", 1, now=1000.0) + self.assertEqual(again["choice"]["worker"], "tool/beta-1", "deterministic for one record") + + class GenericTests(unittest.TestCase): def test_no_model_names_or_prices_in_product_files(self): """The product ships no model id, model-family name or price."""