From c5fd556196fea7faf8f1c9b4a8a2e2da9271d849 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 27 Nov 2026 17:29:37 -0700 Subject: [PATCH] Track worker availability from judged `out` verdicts, not table notes A worker judged `out` (with the provider's message) is off the wheel for 6 hours, then tried again: at most 24 h / 6 h = 4 tries a day. A later good or bad verdict puts it back at once. `sisi pick` says when a pick is a retry and names when the first out worker of a class is back; `sisi models` lists who is out and until when. Why: `out until DATE` notes were typed by an agent as a guess, a rebuild copied them across, a good verdict never cleared them, and a date of today did not count, so working workers stayed off the wheel for days. A new table may no longer carry the note (the research brief says so, and recording one is refused); an old table is still read: its note dates from the table's own time and spends itself in 6 hours. --- README.md | 8 ++- canon/core.md | 6 +- sisi/cli.py | 5 +- sisi/faults.py | 2 +- sisi/models.py | 81 ++++++++++++++++++------- tests/test_core.py | 147 ++++++++++++++++++++++++++++++++++++++++----- 6 files changed, 204 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index cd5c619..51dc1e6 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ It routes by a models table: which workers you have, what each is good at, what rebuilds that table when it gets old, and every judged delegation feeds the next research. The lead does not choose the worker: `sisi pick CLASS` spins a wheel over the workers of that class (a capability tier: each model is in exactly one class, so the wheel never mixes tiers; weighted by table order and by the square of the speed ratio), -and a delegation to a worker the wheel did not give is refused. One pick, one delegation. A host that names its models +and a delegation to a worker the wheel did not give is refused. One pick, one delegation. A worker that failed for a +limit is judged `out` with the provider's message: it is off the wheel for 6 hours, then the wheel tries it again (at most +4 times a day), and the pick that hands it out says it is a retry. A host that names its models shortly (Claude Code's `Agent` tool says `sonnet`) may give one whole segment of the picked model id, so name a worker by its full model id (`claude-sonnet-5-5`); anywhere else the name must match whole. @@ -90,8 +92,8 @@ its limits are. | `sisi retro --later …` | The work is not finished yet | | `sisi learn [--project] "…" [--means "…"]` | The person's own words become a rule at once, tagged `[owner]` only when they appear in the person's recent messages in this session. `--means` adds, in the same undoable step, one line saying how the agent will apply it | | `sisi rules` / `sisi rules organize [--record FILE]` / `sisi rules revert` | See the learned rules; have a worker organize them (using known problems, prior attempts, and past drop reasons; an optional `## drops` section can record a reason and matching problem number for any dropped or merged rule, with `none given` recorded when omitted); undo the last rule change made with `learn`, a retro or `organize` (including any drop reasons recorded by that `organize`), in the user list or a project's `.sisi/rules.md` (not the one-time move of old rules; a second `revert` re-applies what the first undid; it declines, changing nothing, when the project file changed since or its folder moved or is gone) | -| `sisi models` / `sisi models research [--record FILE]` | The workers table (the shared baseline table ships with sisi in `canon/models.md`); have a worker rebuild it | -| `sisi judge WORKER good\|bad "…" [--minutes N] [--newest]` | How a delegation went; the minutes are measured from the pick's delegation (or `--minutes N`) and make the wheel favour faster workers. With several of one worker's jobs open, the oldest is judged first, `--newest` the newest | +| `sisi models` / `sisi models research [--record FILE]` | The workers table (the shared baseline table ships with sisi in `canon/models.md`), and each worker that is out with when it is back on the wheel; have a worker rebuild it | +| `sisi judge WORKER good\|bad\|out "…" [--minutes N] [--newest]` | How a delegation went (`out` with the provider's own message when it hit a limit: off the wheel for 6 hours, then tried again); the minutes are measured from the pick's delegation (or `--minutes N`) and make the wheel favour faster workers. With several of one worker's jobs open, the oldest is judged first, `--newest` the newest | | `sisi judge WORKER extend MINUTES "" [--newest]` | Give a late job more time instead of judging it: the job that is past its limit (past twice it first, else past once, else the oldest) gets MINUTES more from now, and its late fault clears | | `sisi direct "…"` | Allow more direct tool calls this turn, with the reason | diff --git a/canon/core.md b/canon/core.md index 816fa8f..1fd932b 100644 --- a/canon/core.md +++ b/canon/core.md @@ -84,9 +84,9 @@ failed or gamed job does to each number it optimizes. For a reported fault, the are an acceptance test. For a replacement, list each behaviour of the old thing as keep, change or drop, with a check for every keep. Always use the newest version of a model within its maker and class. Its report is evidence for you to judge, not a fact to pass on; record how it went with `sisi judge`. When a -worker fails for a limit, a login or a connection, give the same brief to the next one at once: do not -ask the person and do not report it. When session start says the models table is old, start a research -worker in the background to rebuild it. +worker fails for a limit, a login or a connection, judge it `out` with the provider's message (sisi +retries it by itself) and give the same brief to the next one at once: do not ask the person and do +not report it. Rebuild the models table in the background when session start says it is old. ## 6. Report plainly diff --git a/sisi/cli.py b/sisi/cli.py index 0797a10..10ce9bb 100644 --- a/sisi/cli.py +++ b/sisi/cli.py @@ -29,8 +29,9 @@ Delegation the brief for a research worker to rebuild that table; record its answer sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME] the wheel gives you one worker of that class; one pick, one delegation - sisi judge WORKER good|bad WHY | extend MINUTES WHY [--newest] - how a delegation went, or give a running job more time + sisi judge WORKER good|bad|out WHY | extend MINUTES WHY [--newest] + how a delegation went (`out` with the provider's own message when it hit a + limit: sisi tries it again by itself), or give a running job more time sisi direct REASON allow yourself more direct tool calls this turn, with the reason Setting up diff --git a/sisi/faults.py b/sisi/faults.py index 25dc24f..d6d0dd9 100644 --- a/sisi/faults.py +++ b/sisi/faults.py @@ -46,7 +46,7 @@ def add(cwd, text, kind="", flag="", fid=0): if not hit: return None if hit.get("kind", "").startswith("late:") and (flag != "--fixed" or hit["kind"].startswith("late:%s:" % (store.current_session(cwd) or "")[:8])): - raise OSError('#%d is a late worker fault; run `sisi judge WORKER good|bad ""` or `sisi judge WORKER extend MINUTES ""`.' % fid) + raise OSError('#%d is a late worker fault; run `sisi judge WORKER good|bad|out ""` or `sisi judge WORKER extend MINUTES ""`.' % fid) doc["items"] = [f for f in doc["items"] if f["id"] != fid] if flag == "--fixed" else doc["items"] hit.update(state=flag[2:], note=text) elif kind and any(f.get("kind") == kind for f in doc["items"]): diff --git a/sisi/models.py b/sisi/models.py index 90b3c76..0415e4c 100644 --- a/sisi/models.py +++ b/sisi/models.py @@ -13,7 +13,7 @@ ASK_STALE = ("which AI models this machine can delegate work to, what each is go "Only the newest version of each model belongs in the table. A smaller or faster variant is a different model.") EXTRA_SHARED = ("\nThen a second, separately marked section starting on its own line with `=== Shared models ===`, followed by `researched YYYY-MM-DD` on its first line and a baseline ranking table " "(`| model | maker | class | score | released | list price | benchmarks | good at, bad at |`) with one row per model (keyed by model id, never provider route), sorted by class then score descending, " - "holding only shared public facts (no plans, allowances, `out until` dates, judged records, or personal notes).\n") + "holding only shared public facts (no plans, allowances, availability, judged records, or personal notes).\n") RESEARCH = """You are a worker. Do this task yourself; do not delegate it further. @@ -38,8 +38,9 @@ other makers (benchmarks and the maker's own positioning), so that every class h several makers. A model that seems to fit two classes goes in the lower one only if it truly performs at that level, never in both. "how to call it" is exact: the host delegation tool's provider and model id (T3 Code's delegate_task); the host's subagent model name where it has subagents; the full command line with where -the brief goes only for a worker the host's tool cannot reach. A worker that is unavailable carries exactly -`out until YYYY-MM-DD` in its notes. +the brief goes only for a worker the host's tool cannot reach. Do not say in the notes whether a worker is +available: `sisi judge WORKER out ""` takes a worker that hit a limit off the wheel for a while, and +sisi tries it again by itself. Then one line starting "Fallback order:" that says who takes over when a worker is out, level by level. %(extra)s === Shipped baseline table === @@ -199,11 +200,40 @@ def waiting(s): return isinstance(s.get("starts"), dict) and any(isinstance(v, list) and v for v in s["starts"].values()) -def out(r, skip, bad, today): - """Why this worker is off the wheel, "" when it is on.""" - until = [d for d in re.findall(r"out until (\d{4}-\d{2}-\d{2})", " ".join(r).lower()) if d > today] +OUT = 6 * 3600 # a worker judged `out` sits out this long, then the wheel tries it again: 24 h / 6 h = at most 4 tries a day +clock = lambda t: time.strftime("%m-%d %H:%M", time.localtime(t)) +SINCE = "out since %s, back on the wheel at %s" + + +def outs(text, log, written, today=None): + """{worker: (since, why)}: each worker last said to be out, and when. An `out` verdict in the log says it, and any + later verdict takes it back. A table from before `out` verdicts says it with a note, `out until DATE` (DATE today or + later), unless the log holds a verdict for that worker newer than the table (`written`); the note dates from the table.""" + last, today = {}, today or time.strftime("%Y-%m-%d") + for o in log: + try: + last[short(o["model"] if isinstance(o.get("model"), str) and o["model"] else o["worker"])] = ( + time.mktime(time.strptime(o["ts"], "%Y-%m-%dT%H:%M:%S")), o.get("verdict"), str(o.get("why") or "")) + except (KeyError, TypeError, ValueError): + pass # a damaged line is no verdict + gone = {w: (t, why) for w, (t, verdict, why) in last.items() if verdict == "out"} + for r in rows(text): + w, until = short(r[0]), [d for d in re.findall(r"out until (\d{4}-\d{2}-\d{2})", " ".join(r).lower()) if d >= today] + if until and written is not None and not (w in last and last[w][0] >= int(written)): # the log keeps whole seconds + gone[w] = (written, "out until " + until[0]) + return gone + + +def away(): + """`outs` for the table and the log as they are now.""" + return outs(store.read(table()), store.records("outcomes.jsonl"), os.path.getmtime(table()) if os.path.exists(table()) else None) + + +def out(r, skip, bad, gone, now): + """Why this worker is off the wheel, "" when it is on: excluded, the maker of the work under review, or out.""" + since = gone.get(short(r[0])) return ("excluded" if short(r[0]) in skip else "same maker as the work under review" if maker(r) == bad - else "out until " + until[0] if until else "") + else SINCE % (clock(since[0]), clock(since[0] + OUT)) if since and now - since[0] < OUT else "") def median(v): @@ -220,12 +250,13 @@ def speeds(): return {w: v[-10:] for w, v in out.items()} -def choose(text, cls, skip=(), review=None, rand=None, today=None, speed=None): +def choose(text, cls, skip=(), review=None, rand=None, speed=None, gone=None, now=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).""" - table_rows, today = rows(text), today or time.strftime("%Y-%m-%d") + times its speed: the fastest candidate's median minutes over its own, cubed, at least 0.02 (1 with no timed jobs). + 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, today)] + 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 rand is None: @@ -263,14 +294,16 @@ 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 = speeds() - r = choose(text, cls, skip, review, rand, speed=speed) + speed, gone, now = speeds(), away(), time.time() + r = choose(text, cls, skip, review, rand, speed=speed, gone=gone, now=now) 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, "") + first = min((t + OUT for x in mine if (t := gone.get(short(x[0]), (None,))[0]) is not None and now - t < OUT), default=None) print(("sisi pick: every worker of class %s is out or excluded: %s." % (cls, "; ".join( - "%s (%s)" % (x[0], out(x, skip, bad, time.strftime("%Y-%m-%d"))) for x in mine)) if mine - else "sisi pick: the models table has no worker of class %s." % cls) + again) + "%s (%s)" % (x[0], out(x, skip, bad, gone, now)) for x in mine)) if mine + else "sisi pick: the models table has no worker of class %s." % cls) + + (" The first is back on the wheel at %s." % clock(first) if first is not None else "") + again) return 1 sid = store.current_session(cwd) if sid: @@ -284,6 +317,9 @@ def pick(args, cwd=None, rand=None): print("good at, bad at: %s\nnotes: %s" % (r[4], r[5])) t = speed.get(short(r[0])) print("speed: median %g min over %d timed jobs" % (median(t), len(t)) if t else "speed: no timed jobs yet") + if g := gone.get(short(r[0])): # its last verdict was `out`: a retry, so a quick failure is expected and cheap + print("retry: this worker hit a limit at %s: %s; if it fails for the limit again, judge it out again and pick another" % ( + clock(g[0]), g[1][:160] + ("…" if len(g[1]) > 160 else ""))) return 0 @@ -316,8 +352,8 @@ def research_record(answer_file): for r in rows(text): if len(re.findall(r"routine|ordinary|hard", r[2].lower())) != 1: return "each row's \"use for\" must name exactly one of routine, ordinary or hard: | %s |" % " | ".join(r[:6]) - if re.search(r"out (?!until \d{4}-\d{2}-\d{2}(?!\d))(until|till)\b", r[5].lower()): - return "a worker that is out needs exactly `out until YYYY-MM-DD` in its notes: | %s |" % " | ".join(r[:6]) + if re.search(r"\bout (?:until|till)\b", " ".join(r), re.I): # what the wheel would read as a legacy note + return "the table does not say who is out: judge the worker instead (`sisi judge WORKER out \"\"`) and take that out of the row: | %s |" % " | ".join(r[:6]) if len(lines) > 42 or len(text) > 12000: return "the answer is too long (at most 40 rows and 12,000 characters)" if shared and ("|" not in shared or not _shared_date(shared)[0]): @@ -337,7 +373,7 @@ def sync_late(s, cwd, sid, add=True): if not (late2 := late(s, 2)) and not os.path.lexists(os.path.join(store.STATE, "core-faults", store.project_key(cwd) + ".json")): return from . import faults prefix, now, cfg_m = "late:%s:" % sid[:8], time.time(), store.config()["worker_minutes"] - want = {"%s%s@%d" % (prefix, w, int(t)): 'worker %s has run %dm (past 2x %gm limit). Judge it (`sisi judge %s good|bad ""`) or extend (`sisi judge %s extend MINUTES ""`).' % ( + want = {"%s%s@%d" % (prefix, w, int(t)): 'worker %s has run %dm (past 2x %gm limit). Judge it (`sisi judge %s good|bad|out ""`) or extend (`sisi judge %s extend MINUTES ""`).' % ( w, int((now - t) / 60), lim if lim is not None else cfg_m, w, w) for w, t, lim, *_ in late2} try: faults.clear(cwd, prefix, set(want)); add and [faults.add(cwd, text, kind=k) for k, text in want.items()] @@ -345,7 +381,7 @@ def sync_late(s, cwd, sid, add=True): def judge(args, cwd=None): - """`sisi judge WORKER good|bad "" [--minutes N] [--newest] | extend MINUTES "" [--newest]`.""" + """`sisi judge WORKER good|bad|out "" [--minutes N] [--newest] | extend MINUTES "" [--newest]`.""" from . import retro # not at the top: hooks import this module and must stay quick args, newest, minutes, note = [a for a in args if a != "--newest"], "--newest" in args, None, "" if "--minutes" in args: @@ -353,8 +389,8 @@ def judge(args, cwd=None): v, args = (args[i + 1:i + 2] or [""])[0], args[:i] + args[i + 2:] minutes = int(v) if re.fullmatch(r"[1-9]\d{0,3}|10000", v) else 0 ext = len(args) == 4 and args[1] == "extend" and minutes is None and re.fullmatch(r"[1-9]\d{0,3}|10000", args[2]) - if not args or not args[0].strip() or not (ext or (len(args) == 3 and args[1] in ("good", "bad") and minutes != 0)) or len(args[-1].split()) < 3: - print('usage: sisi judge WORKER good|bad "" [--minutes N] [--newest] | extend MINUTES "" [--newest]') + if not args or not args[0].strip() or not (ext or (len(args) == 3 and args[1] in ("good", "bad", "out") and minutes != 0)) or len(args[-1].split()) < 3: + print('usage: sisi judge WORKER good|bad|out "" [--minutes N] [--newest] | extend MINUTES "" [--newest]') return 1 trows = rows(store.read(table())) hits = [r for r in trows if short(r[0]) == short(args[0])] or [r for r in trows if claim({"picked": [short(r[0])]}, args[0], True)] @@ -403,6 +439,9 @@ def run(args, cwd=None): print(text or stale()) if text: print("\n(researched %d days ago)" % age_days()) + 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)) diff --git a/tests/test_core.py b/tests/test_core.py index 200a1ab..83626d0 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -28,6 +28,9 @@ FIXTURE = HEADER + ( "| haiku (Haiku 5.5) | host subagent model `haiku` | ordinary | per use | quick | |\n" "| sonnet (Sonnet 5.5) | host subagent model `sonnet` | hard | per use | everything | |\n" "| opus (Opus 5.5) | host subagent model `opus` | hard | per use | hardest | |\n") +ONE = HEADER + "| alpha | host subagent model `alpha` | routine | free | quick | |\n" # one worker in its class: a pick is sure +TWO = ONE + "| beta | host subagent model `beta` | routine | free | quick | |\n" +LIMIT = "You have hit your usage limit for this model" def tree(): @@ -1697,17 +1700,20 @@ cli.main(["tick"]) sys.path.insert(0, REPO) from sisi import models name = lambda r: r[0].split()[0].lower() + spin = lambda cls, **kw: models.choose(FIXTURE, cls, gone=models.outs(FIXTURE, [], time.time()), **kw) # the table as just written for _ in range(300): - self.assertNotIn("muse-wonder", name(models.choose(FIXTURE, "ordinary", rand=random.random))) # out until 2999 - self.assertNotEqual(name(models.choose(FIXTURE, "ordinary", skip=["zai-coding-plan/glm-5.4"], rand=random.random)), "zai-coding-plan/glm-5.4") - self.assertNotIn("glm", name(models.choose(FIXTURE, "ordinary", review="zai-coding-plan/glm-5.4", rand=random.random))) - self.assertIsNone(models.choose(FIXTURE, "hard", review="sonnet", rand=random.random)) # both are claude - picked = lambda x: name(models.choose(FIXTURE, "ordinary", rand=lambda: x)) + self.assertNotIn("muse-wonder", name(spin("ordinary", rand=random.random))) # its `out until 2999` note is six hours old at most + self.assertNotEqual(name(spin("ordinary", skip=["zai-coding-plan/glm-5.4"], rand=random.random)), "zai-coding-plan/glm-5.4") + self.assertNotIn("glm", name(spin("ordinary", review="zai-coding-plan/glm-5.4", rand=random.random))) + self.assertIsNone(spin("hard", review="sonnet", rand=random.random)) # both are claude + picked = lambda x: name(spin("ordinary", rand=lambda: x)) # four candidates (the expired "out until" is back in), weights 4, 3, 2, 1 of 10 self.assertEqual([picked(x) for x in (0.0, 0.39, 0.4, 0.69, 0.7, 0.89, 0.9, 0.999)], ["zai-coding-plan/glm-5.4"] * 2 + ["zai-coding-plan/glm-5.3-flash"] * 2 + ["muse/muse-ember-1.0"] * 2 + ["haiku"] * 2) - self.assertEqual(name(models.choose(FIXTURE, "ordinary", review="zai-coding-plan/glm-5.4", rand=lambda: 0.0)), "muse/muse-ember-1.0") - self.assertIsNone(models.choose(FIXTURE, "routine", rand=lambda: 0.0)) + self.assertEqual(name(spin("ordinary", review="zai-coding-plan/glm-5.4", rand=lambda: 0.0)), "muse/muse-ember-1.0") + self.assertIsNone(spin("routine", rand=lambda: 0.0)) + later = [name(spin("ordinary", rand=lambda: i / 1000, now=time.time() + 6 * 3600)) for i in range(1000)] + self.assertEqual({w.split("/")[-1] for w in later}, {"glm-5.4", "glm-5.3-flash", "muse-ember-1.0", "haiku", "muse-wonder-1.0"}) # six hours on, the note is spent row = lambda *c: list(c) + [""] * (7 - len(c)) self.assertEqual(models.maker(row("agy", "")), "agy") self.assertEqual(models.maker(row("opencode-go/gpt-6-luna", "`opencode run`")), "gpt") @@ -2619,15 +2625,126 @@ cli.main(["tick"]) self.assertEqual(bash("python3 -c 'print(1)'"), (0, "", "")) # a launcher is not a worker self.assertEqual(bash("echo opencode"), (0, "", "")) - def test_an_out_date_must_be_exact(self): - self.assertIn("out until YYYY-MM-DD", self.sisi("models", "research")[1]) + # a worker judged `out`: off the wheel for six hours, then tried again + + def judged(self, worker, kind, why=LIMIT): + rc, out, _ = self.sisi("judge", worker, kind, why) + self.assertEqual(rc, 0, out) + return out + + def dated(self, *minutes_ago): + """The clock: every verdict so far was given this many minutes ago, oldest first.""" + recs = self.outcomes() + self.assertEqual(len(recs), len(minutes_ago)) + for rec, m in zip(recs, minutes_ago): + at = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(time.time() - m * 60)) + rec.update(ts=at, ended=at) + self.write(os.path.join(self.data, "outcomes.jsonl"), "".join(json.dumps(r, sort_keys=True) + "\n" for r in recs)) + + def picked(self, *args): + """(was a worker handed out, the output).""" + rc, out, _ = self.sisi("pick", *args) + return rc == 0 and "worker:" in out, out + + def test_a_worker_judged_out_is_off_the_wheel_for_six_hours_and_is_then_tried_again(self): + self.table(ONE) + self.assertIn("recorded", self.judged("alpha", "out")) + self.assertEqual((self.outcomes()[-1]["verdict"], self.outcomes()[-1]["why"]), ("out", LIMIT)) + self.dated(5 * 60 + 59) + got, out = self.picked("routine") # 5 h 59 m: still off + self.assertEqual((got, "out since" in out, "back on the wheel at" in out), (False, True, True), out) + self.dated(6 * 60) + got, out = self.picked("routine") # 6 h 00 m: back + self.assertEqual((got, "worker: alpha" in out), (True, True), out) + self.table(TWO) + self.dated(0) + for _ in range(20): # beside a worker that is in: never handed out + self.assertNotEqual(self.picked("routine")[1].split("worker: ")[1].split()[0], "alpha") + + def test_a_second_out_verdict_moves_the_time_the_worker_is_back(self): + self.table(ONE) + self.judged("alpha", "out") # out at 09:00 + self.judged("alpha", "out") # tried at 15:10 and out again + self.dated(12 * 60 + 9, 5 * 60 + 59) # it is 21:09: not back at 15:00 + self.assertEqual(self.picked("routine")[0], False) + self.dated(12 * 60 + 10, 6 * 60) # 21:10 + got, out = self.picked("routine") + self.assertEqual((got, "retry: this worker hit a limit at" in out), (True, True), out) + + def test_a_good_or_bad_verdict_puts_an_out_worker_back_at_once(self): + self.table(ONE) + self.judged("alpha", "out") + self.assertEqual(self.picked("routine")[0], False) + for kind, why in (("good", "did the job in one pass"), ("bad", "gave up after one quick wrong try")): + self.judged("alpha", kind, why) + got, out = self.picked("routine") + self.assertEqual((got, "retry:" in out), (True, False), out) # available, and no retry note + self.judged("alpha", "out") + self.assertEqual(self.picked("routine")[0], False) + + def test_an_old_out_until_note_counts_from_today_and_the_log_and_six_hours_override_it(self): + self.table(ONE.replace("| |", "| out until %s |" % time.strftime("%Y-%m-%d"))) # dated today: out (it used to count only from tomorrow) + self.assertEqual(self.picked("routine")[0], False) + self.judged("alpha", "good", "did the job in one pass") # a newer verdict in the log decides + got, out = self.picked("routine") + self.assertEqual((got, "retry:" in out), (True, False), out) + os.remove(os.path.join(self.data, "outcomes.jsonl")) # no verdict: the note dates from the table + old = time.time() - 6 * 60 * 60 - 1 + os.utime(os.path.join(self.data, "models.md"), (old, old)) # six hours after it was written: back + got, out = self.picked("routine") + self.assertEqual((got, "retry: this worker hit a limit at" in out, "out until" in out), (True, True, True), out) + + def test_pick_names_when_the_first_out_worker_of_a_class_is_back(self): + self.table(TWO) + self.judged("alpha", "out") + self.judged("beta", "out") + self.dated(30, 60) # beta has been out longer: it is back first + got, out = self.picked("routine") + self.assertEqual(got, False, out) + self.assertIn("every worker of class routine is out or excluded: alpha (out since", out) + first = time.mktime(time.strptime("2026-" + out.split("The first is back on the wheel at ")[1][:11], "%Y-%m-%d %H:%M")) + self.assertLess(abs(first - (time.time() + 5 * 3600)), 120) # beta, out for an hour: in five more + + def test_pick_says_a_returning_worker_is_a_retry(self): + self.table(ONE) + self.judged("alpha", "out", LIMIT + ", please try later. " * 30) + self.dated(6 * 60 + 1) + got, out = self.picked("routine") + self.assertEqual(got, True, out) + line = out.split("retry: ")[1].splitlines()[0] + self.assertTrue(line.startswith("this worker hit a limit at "), line) + self.assertIn(LIMIT, line) + self.assertTrue(line.endswith("; if it fails for the limit again, judge it out again and pick another"), line) + self.assertLess(len(line), 300) # the message is shortened + + def test_an_out_verdict_closes_the_job_and_models_says_when_the_worker_is_back(self): + self.table(WORKERS) + self.hook("tick") + self.hook("prompt", prompt="go") + self.done() + self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0) + self.assertEqual(self.tool("Agent", tool_input={"model": "sonnet"})[0], 0) + self.assertEqual(len(self.state()["starts"]["sonnet"]), 1) + rc, out, _ = self.sisi("judge", "sonnet", "out", LIMIT, sid="s1") + self.assertEqual((rc, self.state()["starts"]["sonnet"], self.outcomes()[-1]["verdict"]), (0, [], "out")) + self.assertTrue(out.startswith("recorded: 1 min (job started"), out) + out = self.sisi("models")[1] + self.assertRegex(out, r"\nsonnet: out since \d\d-\d\d \d\d:\d\d, back on the wheel at \d\d-\d\d \d\d:\d\d") + self.assertNotIn("agy: out since", out) + + def test_the_table_no_longer_says_who_is_out(self): + brief = self.sisi("models", "research")[1] + self.assertNotIn("out until", brief) + self.assertIn("sisi judge WORKER out", brief) answer = os.path.join(self.tmp, "table.md") - for notes in ("out till 2999-01-01", "out until next week", "Out Until 2999-1-1"): + clean = HEADER + "| small | host subagent `small` | routine | flat | fast | |\nFallback order: none.\n" + self.write(answer, clean) + self.assertEqual(self.sisi("models", "research", "--record", answer)[0], 0) + for notes in ("out till 2999-01-01", "out until next week", "Out Until 2999-1-1", "out until 2999-01-01"): self.write(answer, HEADER + "| small | host subagent `small` | routine | flat | fast | %s |\nFallback order: none.\n" % notes) rc, out, _ = self.sisi("models", "research", "--record", answer) - self.assertEqual((rc, "| small |" in out), (1, True), notes) - self.write(answer, HEADER + "| small | host subagent `small` | routine | flat | fast | out until 2999-01-01 |\nFallback order: none.\n") - self.assertEqual(self.sisi("models", "research", "--record", answer)[0], 0) + self.assertEqual((rc, "| small |" in out, "sisi judge WORKER out" in out), (1, True, True), notes) # availability is judged, never written + self.assertEqual(self.read(self.data, "models.md").strip(), clean.strip()) def test_a_failed_check_is_counted_even_when_it_is_fixed(self): self.hook("tick") @@ -3661,10 +3778,10 @@ cli.main(["tick"]) def test_the_product_stays_small(self): code = sum(len(self.read(p).splitlines()) for p in glob.glob(os.path.join(REPO, "sisi", "*.py"))) - self.assertLessEqual(code, 2226, "sisi is two loops. If it needs more than this, find the simpler shape.") + self.assertLessEqual(code, 2265, "sisi is two loops. If it needs more than this, find the simpler shape.") rulebook = self.read(REPO, "canon", "core.md") self.assertLess(len(rulebook.splitlines()), 137) - self.assertLessEqual(len(rulebook), 10530) + self.assertLessEqual(len(rulebook), 10561) if __name__ == "__main__":