Scale wheel weight by recent good/bad quality factor

Multiply each worker's wheel weight by a normalized Laplace quality
factor over its last 10 good/bad verdicts, ((good+1)/(n+2))/((n+1)/(n+2))
= (good+1)/(n+1), ignoring out and extend. Workers with no bad runs keep
their full weight (factor 1.0); workers with all bad runs floor at 1/11
so they remain pickable and picks are never refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-12-01 15:24:09 -07:00
1 parent 5e39baaa30
commit 33ca3d3c4d
3 files changed
+85 -32

No files matched your search

+54
View File
@@ -1982,6 +1982,60 @@ cli.main(["tick"])
wins = [models.choose(table, "ordinary", rand=rng.random, speed={"slow": [45], "fast": [9]})[0] for _ in range(2000)]
self.assertLess(wins.count("slow"), 100) # 2 * the 0.02 floor against 1: about 4%; it was a third
def test_bad_verdicts_lower_wheel_weight_without_dropping_to_zero(self):
sys.path.insert(0, REPO)
from sisi import models
two = HEADER + "| alpha | `alpha \"<brief>\"` | ordinary | flat | x | |\n| beta | `beta \"<brief>\"` | ordinary | flat | x | |\n"
self.table(two)
# Same speed (10 min): alpha has 1 good + 4 bad (factor 2/6 = 1/3; weight 2/3 vs beta's 1 -> 40/60 split); out and extend are ignored.
self.jsonl("outcomes.jsonl",
self.outcome("alpha", "good", 10),
*[self.outcome("alpha", "bad", 10)] * 4,
self.outcome("alpha", "out", 1),
self.outcome("alpha", "extend", 1),
*[self.outcome("beta", "good", 10)] * 5)
picked = []
for i in range(100):
rc, out = self.in_process(models.pick, ["ordinary"], self.proj, lambda i=i: i / 100)
self.assertEqual(rc, 0, out)
picked.append(out.splitlines()[0].split()[1])
self.assertEqual(picked.count("alpha"), 40)
self.assertEqual(picked.count("beta"), 60)
self.assertGreater(picked.count("alpha"), 0)
self.assertLess(picked.count("alpha"), picked.count("beta"))
# 12 straight bad runs: only the last 10 count (factor 1/11, weight 2/11 vs 1 -> 16/84 split, still pickable).
self.jsonl("outcomes.jsonl", *[self.outcome("alpha", "bad", 10)] * 12, *[self.outcome("beta", "good", 10)] * 5)
picked2 = [self.in_process(models.pick, ["ordinary"], self.proj, lambda i=i: i / 100)[1].splitlines()[0].split()[1] for i in range(100)]
self.assertEqual(picked2.count("alpha"), 16)
self.assertGreater(picked2.count("alpha"), 0)
q, _ = self.in_process(models.qualities)
self.assertAlmostEqual(q["alpha"], 1 / 11)
self.assertEqual(q["beta"], 1.0)
# Never refuses a pick even when the sole worker has only bad verdicts.
self.table(HEADER + "| alpha | `alpha \"<brief>\"` | ordinary | flat | x | |\n")
rc, out = self.in_process(models.pick, ["ordinary"], self.proj, lambda: 0.99)
self.assertEqual((rc, out.splitlines()[0].split()[1]), (0, "alpha"))
def test_only_good_runs_keep_old_wheel_weight(self):
sys.path.insert(0, REPO)
from sisi import models
two = HEADER + "| alpha | `alpha \"<brief>\"` | ordinary | flat | x | |\n| beta | `beta \"<brief>\"` | ordinary | flat | x | |\n"
self.table(two)
spin = lambda: [self.in_process(models.pick, ["ordinary"], self.proj, lambda i=i: i / 100)[1].splitlines()[0].split()[1] for i in range(100)]
baseline = spin()
self.assertEqual((baseline.count("alpha"), baseline.count("beta")), (67, 33)) # table order alone: weights 2 and 1
# Only good runs (and 5 older bad runs rolled off the last-10 window, plus ignored out/extend) keep the exact old weight.
self.jsonl("outcomes.jsonl",
*[self.outcome("alpha", "bad", 10)] * 5,
*[self.outcome("alpha", "good", 10)] * 10,
self.outcome("alpha", "out", 1),
self.outcome("alpha", "extend", 1),
*[self.outcome("beta", "good", 10)] * 4)
after = spin()
self.assertEqual((after.count("alpha"), after.count("beta")), (67, 33))
q, _ = self.in_process(models.qualities)
self.assertEqual((q["alpha"], q["beta"]), (1.0, 1.0))
def test_pick_and_models_show_the_minutes(self):
self.table(WORKERS)
self.hook("tick")