Pin the worker retried within its cycle and reload state without a failure count

This commit is contained in:
2026-09-29 11:01:40 +02:00
parent aefd6e2fb0
commit 6c09cadfa3
2 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ class Verdict(unittest.TestCase):
class LoopState(unittest.TestCase):
def test_stops_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self):
for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r"})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": ""})], [json.dumps({"cycle_number": "3", "failures": 0, "root": "/r", "task": "do it"})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "", "task": "do it"})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": "do it", "turns": 1})]):
for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "root": "/r"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": ""})], [json.dumps({"cycle_number": "3", "root": "/r", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": "do it", "turns": 1})]):
with self.subTest(handed=handed):
self.assertEqual(main.loop_state([main.RELOAD_FLAG, *handed], CWD), Stop(1, f"the reload cannot read the loop's state from {handed}; rerun loop-claude <task>"))
+6 -5
View File
@@ -366,6 +366,8 @@ class Cycles(unittest.TestCase):
self.assertIn("retrying the worker in a minute: claude exited 1", run.stderr)
self.assertIn("claude exited 0 without a result event", run.stderr)
self.assertEqual(run.stderr.strip().splitlines()[-1], "the worker failed three times running: claude killed by signal 9")
self.assertNotIn("=== cycle 2 ===", run.stdout)
self.assertEqual(argument(run.calls[1], "--resume"), argument(run.calls[0], "--session-id"))
run = checkout.run([worker(exit=1), worker(exit=1), worker(), judge(), worker(exit=1), worker(exit=1)])
self.assertEqual(run.code, 130)
@@ -646,17 +648,16 @@ class Reload(unittest.TestCase):
self.assertEqual(run.roles(), ["worker", "judge"] * 4)
self.assertIn("keeping the running script", run.stderr)
reloads = [json.loads(argv[1]) for argv in run.starts if argv[:1] == ["--reloaded"]]
self.assertEqual(reloads, [{"cycle_number": cycle, "failures": 0, "root": str(checkout.root), "task": TASK} for cycle in (2, 3)])
self.assertEqual(reloads, [{"cycle_number": cycle, "root": str(checkout.root), "task": TASK} for cycle in (2, 3)])
self.assertIn("=== cycle 4 ===", run.stdout)
outside = checkout.temp / "outside"
outside.mkdir()
state = {"cycle_number": 3, "failures": 2, "root": str(checkout.root), "task": TASK}
run = checkout.run([worker(exit=1)], argv=["--reloaded", json.dumps(state)], cwd=outside)
self.assertEqual((run.code, run.sleeps), (1, []))
state = {"cycle_number": 3, "root": str(checkout.root), "task": TASK}
run = checkout.run([worker()], argv=["--reloaded", json.dumps(state)], cwd=outside)
self.assertEqual((run.code, run.roles()), (130, ["worker", "judge"]))
self.assertEqual(run.calls[0]["cwd"], str(checkout.root))
self.assertIn("=== cycle 4 ===", run.stdout)
self.assertEqual(run.stderr.strip().splitlines()[-1], "the worker failed three times running: claude exited 1")
run = checkout.run([], argv=["--reloaded", "{}"])
self.assertEqual((run.code, run.calls), (1, []))