Merge branch 'p5-wheel-bad'

This commit is contained in:
swaits committed 2026-12-01 15:31:28 -07:00
commit 6632a82f77
3 files changed
+85 -32

No files matched your search

+28 -30
View File
@@ -88,20 +88,16 @@ def sync_shared(cwd=None):
def age_days():
try:
return (time.time() - os.path.getmtime(table())) / 86400.0
except OSError:
return None
try: return (time.time() - os.path.getmtime(table())) / 86400.0
except OSError: return None
def stale(mark=None):
"""One line when the table is missing, old, or missed a worker, else ""."""
who = re.sub(r"[^\w./:+-]", "", str(store.read(store.data("models.stale")) if mark is None else mark), flags=re.A)[:80]
if mark is not None and who:
try:
store.write(store.data("models.stale"), who + "\n")
except Exception: # best effort: a refusal never depends on it
pass
try: store.write(store.data("models.stale"), who + "\n")
except Exception: pass # best effort: a refusal never depends on it
age = age_days()
if age is None or age > store.config()["research_days"]:
return "sisi: " + ("there is no models table yet. " if age is None else "the models table is %d days old. " % age) + ASK
@@ -250,26 +246,34 @@ def speeds():
return {w: v[-10:] for w, v in out.items()}
def choose(text, cls, skip=(), review=None, rand=None, speed=None, gone=None, now=None):
def qualities():
"""Each worker's quality factor over its last 10 good/bad outcomes: ((good+1)/(n+2))/((n+1)/(n+2)) = (good+1)/(n+1)."""
out = {}
for o in store.records("outcomes.jsonl"):
w = o["model"] if isinstance(o.get("model"), str) and o["model"].strip() else (o["worker"] if isinstance(o.get("worker"), str) else "")
if o.get("verdict") in ("good", "bad") and w.strip(): out.setdefault(short(w), []).append(o["verdict"] == "good")
return {w: (sum(v[-10:]) + 1) / (len(v[-10:]) + 1) for w, v in out.items()}
def choose(text, cls, skip=(), review=None, rand=None, speed=None, gone=None, now=None, quality=None):
"""One worker of this class, by a wheel weighted by table order (the first of n has weight n, the last 1)
times its speed: the fastest candidate's median minutes over its own, cubed, at least 0.02 (1 with no timed jobs).
times its speed: the fastest candidate's median minutes over its own, cubed, at least 0.02 (1 with no timed jobs),
times its quality factor over its last 10 good/bad outcomes ((good+1)/(n+1), so no bad runs keeps weight 1).
A worker last said out less than OUT seconds ago (`gone`, from `outs`) is not on the wheel."""
table_rows, gone, now = rows(text), gone or {}, now or time.time()
bad = next((maker(r) for r in table_rows if short(r[0]) == short(review)), None) if review else None
left = [r for r in table_rows if r[2].strip().lower() == cls and not out(r, skip, bad, gone, now)]
if not left:
return None
if not left: return None
if rand is None:
import random
rand = random.random
med = {short(r[0]): median(speed[short(r[0])]) for r in left if (speed or {}).get(short(r[0]))}
fast = min(med.values(), default=1)
weights = [w * max(0.02, (fast / med[short(r[0])]) ** 3) if short(r[0]) in med else w for w, r in zip(range(len(left), 0, -1), left)]
fast, qual = min(med.values(), default=1), quality or {}
weights = [w * (max(0.02, (fast / med[short(r[0])]) ** 3) if short(r[0]) in med else 1)
* max(1 / 11, qual.get(short(r[0]), 1)) for w, r in zip(range(len(left), 0, -1), left)]
x = rand() * sum(weights)
for weight, r in zip(weights, left):
x -= weight
if x < 0:
return r
if (x := x - weight) < 0: return r
return left[-1]
@@ -294,8 +298,8 @@ def pick(args, cwd=None, rand=None):
if review is not None and not any(short(r[0]) == short(review) for r in rows(text)):
print("sisi pick: %r is not a worker in the models table; --review-of names the worker whose work is reviewed." % review)
return 1
speed, gone, now = speeds(), away(), time.time()
r = choose(text, cls, skip, review, rand, speed=speed, gone=gone, now=now)
speed, gone, qual, now = speeds(), away(), qualities(), time.time()
r = choose(text, cls, skip, review, rand, speed=speed, gone=gone, now=now, quality=qual)
if not r:
bad = next((maker(x) for x in rows(text) if short(x[0]) == short(review)), None)
again = {"routine": " Choose again from ordinary.", "ordinary": " Choose again from hard."}.get(cls, "")
@@ -422,12 +426,9 @@ def judge(args, cwd=None):
rec = {"ts": iso(now), "ended": iso(now), "worker": args[0], "model": model, "verdict": args[1],
"why": retro.clean(args[2]), "project": os.path.basename(store.project_root(cwd)),
"project_key": store.project_key(cwd)}
if sid:
rec["session_id"] = sid
if began is not None:
rec["started"] = iso(began)
if minutes:
rec["minutes"] = minutes
if sid: rec["session_id"] = sid
if began is not None: rec["started"] = iso(began)
if minutes: rec["minutes"] = minutes
log = store.data("outcomes.jsonl")
store.append(log, json.dumps(rec, sort_keys=True))
ok = store.commit("delegation judged", log)
@@ -444,11 +445,8 @@ def run(args, cwd=None):
gone, now, listed = away(), time.time(), {short(r[0]) for r in rows(text)}
if sitting := sorted((t, w) for w, (t, _) in gone.items() if w in listed and now - t < OUT):
print("\nOff the wheel now:\n" + "\n".join("%s: %s" % (w, SINCE % (clock(t), clock(t + OUT))) for t, w in sitting))
recent = outcomes(15)
if recent:
print("\nHow recent delegations went:\n" + "\n".join(recent))
if stale():
print("\n" + stale())
if recent := outcomes(15): print("\nHow recent delegations went:\n" + "\n".join(recent))
if stale(): print("\n" + stale())
return 0
if args == ["research"]:
return print(research_brief()) or 0