Attach a running job to a plan node; honour a provider's stated reset for its whole plan

Fault 36: `sisi pick --node ID --started WORKER` records that a job already
running (a worker sent a message, which no delegation hook sees) does the node;
re-recording a plan keeps a running node whose id and branch are unchanged.

Fault 37: `judge WORKER out` keeps the worker off the wheel until the reset its
message states (ISO time or "resets in ..." span; else 6 h), together with every
worker on the same provider in the models table.

Also: tests/test_models_research.py no longer reads the running agent's
CLAUDE_CODE_ENTRYPOINT.

The line-count cap (test_the_product_stays_small) is left for the join: sisi/
is 3330 lines against 3264.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-12-04 07:03:51 -07:00
1 parent fffb97f522
commit 9fb2a61920
7 files changed
+174 -36

No files matched your search

+40 -1
View File
@@ -3,7 +3,7 @@
Learning: work is done, the retro is forced, its improvement is a rule in the next session, the rules are
organized and the change can be undone. Delegation: the lead is stopped when it should be delegating, and the
models table is researched, read and kept fresh."""
import glob, hashlib, json, os, random, re, shlex, shutil, subprocess, sys, tempfile, time, unittest
import calendar, glob, hashlib, json, os, random, re, shlex, shutil, subprocess, sys, tempfile, time, unittest
from unittest import mock
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -3038,6 +3038,45 @@ cli.main(["tick"])
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)
def test_a_stated_reset_time_keeps_the_whole_plan_off_the_wheel_until_then(self):
"""Fault 37, with the providers' own messages."""
row = "| %s | %s | host subagent model `%s` | %s | flat | work | |\n"
self.table("| worker | provider | how to call it | use for | cost | good at, bad at | notes |\n|---|---|---|---|---|---|---|\n" + "".join(
row % (w, p, w, c) for w, p, c in (("muse-wonder", "Muse Code", "ordinary"), ("muse-ember", "Muse Code", "routine"),
("gemini-4-neon", "Antigravity", "ordinary"), ("gemini-4-hydrogen", "Antigravity", "routine"),
("alpha", "Other", "routine"))))
sys.path.insert(0, REPO)
from sisi import models
stamp = lambda t: time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(t))
utc = lambda s: calendar.timegm(time.strptime(s, "%Y-%m-%dT%H:%M:%S"))
said, reset = utc("2026-12-02T21:33:21"), utc("2026-12-07T00:00:00")
muse = "API error 429: Subscription quota exhausted. Your usage window resets at 2026-12-07T00:00:00Z."
pool = {"muse-wonder": "muse code", "muse-ember": "muse code", "alpha": "other"}
verdict = lambda why, t, w="muse-wonder", kind="out": {"ts": stamp(t), "worker": w, "verdict": kind, "why": why}
for log in ([verdict(muse, said)], [verdict(muse, said), verdict("connection lost again here", said + 60, "muse-ember")]):
gone = models.outs(log, reset - 60, pool)
self.assertEqual(sorted(gone), ["muse-ember", "muse-wonder"])
self.assertEqual({w: g[2] for w, g in gone.items()}, dict.fromkeys(gone, reset)) # a later message with no time shortens nothing
gone = models.outs([verdict(muse, said)], reset - 60, pool)
off = lambda now: models.out(["muse-ember"] + [""] * 8, set(), None, gone, now)
self.assertEqual((off(reset - 60).startswith("out since"), off(reset)), (True, ""))
self.assertEqual(sorted(models.outs([verdict(muse, said), verdict("did it all well", said + 60, "muse-ember", "good")], said + 90, pool)), ["muse-wonder"])
for why, wait in (("Individual quota reached. Resets in 108h11m37s.", 108 * 3600 + 11 * 60 + 37), ("limit hit, resets in 3 days", 3 * 86400),
("Rate limited: try again in 45 minutes", 45 * 60), ("Resets in 4h 14m (shared account quota)", 4 * 3600 + 14 * 60),
(LIMIT, 6 * 3600), ("started 2026-12-30T00:00:00Z and hit a limit", 6 * 3600),
("usage window resets at 2026-11-01T00:00:00Z", 6 * 3600), ("resets in 9000 days", 6 * 3600)):
self.assertEqual(models.outs([verdict(why, said)], said)["muse-wonder"][2] - said, wait, why)
# through the command: the model out and its sibling are both off, long after six hours
self.judged("gemini-4-neon", "out", "Individual quota reached. Resets in 108h11m37s.")
self.dated(108 * 60 + 10)
for cls, args in (("ordinary", ("--not", "muse-wonder")), ("routine", ("--not", "alpha", "--not", "muse-ember"))):
got, out = self.picked(cls, *args)
self.assertEqual((got, "(out since" in out), (False, True), out)
self.assertIn("gemini-4-hydrogen: out since", self.sisi("models")[1])
self.assertEqual(self.picked("routine", "--not", "muse-ember", "--not", "gemini-4-hydrogen")[0], True) # another plan stays on
self.dated(108 * 60 + 12)
self.assertEqual(self.picked("routine", "--not", "alpha", "--not", "muse-ember")[0], True)
def test_pick_says_a_returning_worker_is_a_retry(self):
self.table(ONE)
self.judged("alpha", "out", LIMIT + ", please try later. " * 30)
+4
View File
@@ -58,6 +58,10 @@ class ModelsResearch(unittest.TestCase):
CLAUDE_CONFIG_DIR=os.path.join(self.tmp, "claude"))
for name in ("SISI_SESSION_ID", "CLAUDE_ENV_FILE", "XDG_DATA_HOME", "XDG_STATE_HOME", "CODEX_HOME", "CLAUDE_CODE_ENTRYPOINT"):
self.env.pop(name, None)
hide = mock.patch.dict(os.environ) # in-process calls read os.environ: the harness running this suite must not leak in
hide.start()
self.addCleanup(hide.stop)
os.environ.pop("CLAUDE_CODE_ENTRYPOINT", None)
subprocess.run(["git", "init", "-q", self.data], check=True, capture_output=True, stdin=subprocess.DEVNULL)
def in_process(self, fn, *args):
+33 -7
View File
@@ -142,13 +142,39 @@ class Plan(unittest.TestCase):
self.assertEqual(self.nodes(), {"a": "running"})
self.assertEqual(self.record(PLAN.replace("test a passes", "test a2 passes"))[0], 0)
self.assertEqual(self.nodes(), {"a": "running"}) # a running node keeps its state by id
rc, out, _ = self.record(PLAN.replace("| sisi/a.py |", "| sisi/a2.py |"))
self.assertEqual(rc, 1, out)
self.assertIn("node a is running", out)
self.assertIn("a", self.nodes())
rc, out, _ = self.record(PLAN.replace("| a | routine | - |", "| a2 | routine | - |").replace("| a, b |", "| a2, b |"))
self.assertEqual(rc, 1, out)
self.assertIn("node a is running", out)
self.assertEqual(self.record(PLAN.replace("| sisi/a.py |", "| sisi/a.py, sisi/a2.py |"))[0], 0)
self.assertEqual(self.nodes(), {"a": "running"}) # same id and branch: still running
for changed in (PLAN.replace("| p-a |", "| p-a2 |"), PLAN.replace("| a | routine | - |", "| a2 | routine | - |").replace("| a, b |", "| a2, b |")):
rc, out, _ = self.record(changed)
self.assertEqual(rc, 1, out)
self.assertIn("node a is running", out)
self.assertEqual(self.nodes(), {"a": "running"})
def test_a_job_already_running_is_attached_to_a_node_without_a_delegation(self):
"""Fault 36: a node continued on an existing worker by a message stayed "ready and not started"."""
self.ready_plan()
self.assertEqual(self.sisi("plan", "--done", "b", "done by hand and tested", sid="s1")[0], 0)
attach = lambda node, worker: self.sisi("pick", "--node", node, "--started", worker, sid="s1")
rc, out, _ = attach("c", "gamma")
self.assertEqual((rc, "not ready" in out), (1, True), out)
self.assertIn("ready and not started", self.hook("gate")[1])
self.pick("a") # the wheel said alpha, but the lead sent it to a running agent
rc, out, _ = attach("a", "gate-solver")
self.assertEqual(rc, 0, out)
self.assertEqual(self.nodes()["a"], "running")
self.assertEqual(self.state()["picked"], []) # the pick made for this node is withdrawn
self.assertNotIn("ready and not started", self.hook("gate")[1])
rc, out, _ = attach("a", "gate-solver")
self.assertEqual((rc, "already running" in out), (1, True), out)
self.assertEqual(self.record(PLAN.replace("test a passes", "test a2 passes"))[0], 0)
self.assertEqual(self.nodes()["a"], "running")
rc, out, _ = self.sisi("judge", "gate-solver", "good", "did the node in one pass", "--node", "a", sid="s1")
self.assertEqual(rc, 0, out)
self.assertEqual(self.nodes()["a"], "done")
self.pick("c") # a table worker named shortly is stored as the table names it
self.assertEqual(attach("c", "GAMMA")[0], 0)
self.assertEqual((list(self.state()["starts"]).count("gamma"), self.state()["picked"]), (1, []))
self.assertEqual(self.sisi("judge", "gamma", "good", "did the node in one pass", "--node", "c", sid="s1")[0], 0)
def pick_header(self, node, sid="s1"):
st = self.state(sid)