Answer product-owner round 1: 0 🔴, 3 🟡 (0 misread); check a shell that holds a heavy slot, name the process's command, and judge each shell once
This commit is contained in:
@@ -20,8 +20,12 @@ def verdict(said="stuck", process=8, why="pytest waits on a shell that ignores S
|
||||
return ran(json.dumps({"type": "result", "structured_output": {"verdict": said, "process": process, "why": why}}))
|
||||
|
||||
|
||||
def shell(pid=7, cpu=2.0, started=NOW - 1000, written=NOW - 1000, runs_busy_tool=False, processes=("8 S 2.0 s python3 -m pytest", "9 S 0.0 s sh -c trap '' INT; sleep 999"), output="collected 40 items"):
|
||||
return Shell(pid=pid, started=started, command="bin/run-tests", written=written, runs_busy_tool=runs_busy_tool, cpu=cpu, processes=processes, output=output)
|
||||
def shell(pid=7, cpu=2.0, started=NOW - 1000, written=NOW - 1000, runs_busy_tool=False, processes=("8 S 2.0 s python3 -m pytest", "9 S 0.0 s sh -c trap '' INT; sleep 999"), output="collected 40 items", holds_slot=False):
|
||||
return Shell(pid=pid, started=started, command="bin/run-tests", written=written, runs_busy_tool=runs_busy_tool, cpu=cpu, processes=processes, output=output, holds_slot=holds_slot)
|
||||
|
||||
|
||||
def sign(run, quiet, idle=True):
|
||||
return f"\n - shell 7 has run {run} s and written no output for {quiet} s{', and used no CPU for 300 s' if idle else ''}: bin/run-tests"
|
||||
|
||||
|
||||
class StuckWorkers(unittest.TestCase):
|
||||
@@ -37,16 +41,16 @@ class StuckWorkers(unittest.TestCase):
|
||||
record = archive / stuck_workers.RECORD
|
||||
return streamed, fake, said.getvalue(), failed.getvalue(), record.read_text() if record.exists() else ""
|
||||
|
||||
def test_a_silent_worker_whose_shell_used_no_cpu_since_the_last_check_is_investigated_and_the_verdict_said_and_recorded_without_a_kill(self):
|
||||
streamed, fake, said, _, record = self.worker_with(ASSISTANT, None, None, None, held=[shell()], replies=[verdict(), verdict()])
|
||||
(args, prompt), _ = fake.made("claude")
|
||||
def test_a_silent_worker_whose_shell_used_no_cpu_since_the_last_check_is_investigated_once_and_the_verdict_said_and_recorded_without_a_kill(self):
|
||||
streamed, fake, said, _, record = self.worker_with(ASSISTANT, None, None, None, held=[shell()], replies=[verdict()])
|
||||
[(args, prompt)] = fake.made("claude")
|
||||
self.assertEqual(args[args.index("--model") + 1 :][:3], ["claude-opus-5-5", "--effort", "medium"])
|
||||
self.assertEqual(args[args.index("--tools") + 1], "")
|
||||
self.assertEqual(json.loads(args[args.index("--json-schema") + 1])["properties"]["verdict"]["enum"], ["working", "waiting on a person", "stuck"])
|
||||
self.assertTrue(prompt.endswith("\n\nShell 7: bin/run-tests\nIts processes, as pid, state, CPU and command line:\n8 S 2.0 s python3 -m pytest\n9 S 0.0 s sh -c trap '' INT; sleep 999\nThe end of its output:\ncollected 40 items"))
|
||||
first, second = (f"stuck check: shell 7 has run {run} s, written nothing for {run} s and used no CPU for 300 s: bin/run-tests; a headless claude judged the worker stuck, held by process 8: pytest waits on a shell that ignores SIGINT" for run in (1600, 1900))
|
||||
self.assertEqual(said, f"<{NOW + 600}> {first}\n<{NOW + 900}> {second}\n")
|
||||
self.assertEqual(record, f"- {utc(NOW + 600)} {first}\n- {utc(NOW + 900)} {second}\n")
|
||||
line = "stuck check: a headless claude judged the worker stuck, naming process 8 (python3 -m pytest): pytest waits on a shell that ignores SIGINT" + sign(1600, 1600)
|
||||
self.assertEqual(said, f"<{NOW + 600}> {line}\n")
|
||||
self.assertEqual(record, f"- {utc(NOW + 600)} {line}\n")
|
||||
self.assertEqual(streamed.stopped, [])
|
||||
|
||||
def test_hands_the_investigation_none_for_a_shell_without_processes_or_output(self):
|
||||
@@ -59,7 +63,11 @@ class StuckWorkers(unittest.TestCase):
|
||||
_, fake, said, _, _ = self.worker_with(ASSISTANT, None, held=old, replies=[verdict("working", 7, "the tests still print")])
|
||||
[(_, prompt)] = fake.made("claude")
|
||||
self.assertIn("collected 40 items\n\nShell 10: bin/run-tests\n", prompt)
|
||||
self.assertIn(f"stuck check: shell 7 has run {stuck_workers.OLD + 300} s, written nothing for 10 s: bin/run-tests; shell 10 has run {stuck_workers.OLD + 300} s, written nothing for 10 s: bin/run-tests; a headless claude judged the worker working, held by process 7: the tests still print", said)
|
||||
self.assertIn(f"stuck check: a headless claude judged the worker working, naming process 7 (bin/run-tests): the tests still print{sign(stuck_workers.OLD + 300, 10, idle=False)}{sign(stuck_workers.OLD + 300, 10, idle=False).replace('shell 7', 'shell 10')}\n", said)
|
||||
|
||||
def test_a_shell_holding_a_heavy_slot_is_investigated_and_the_verdict_said_on_one_line_with_each_sign_under_it(self):
|
||||
_, _, said, _, _ = self.worker_with(ASSISTANT, None, None, held=[shell(holds_slot=True)], replies=[verdict(process=99, why="the tests\nhang")])
|
||||
self.assertEqual(said, f"<{NOW + 600}> stuck check: a headless claude judged the worker stuck, naming process 99 (not in the evidence): the tests hang{sign(1600, 1600)}\n")
|
||||
|
||||
def test_a_worker_whose_shells_show_no_sign_is_not_investigated(self):
|
||||
for events, held in (
|
||||
@@ -84,13 +92,13 @@ class StuckWorkers(unittest.TestCase):
|
||||
worker.run_worker("/r", [], {}, pathlib.Path("/archive"), RUNG, dataclasses.replace(fake.effects(), now=lambda: clock[0]))
|
||||
self.assertEqual(fake.made("claude"), [])
|
||||
|
||||
def test_an_investigation_that_fails_or_answers_outside_the_schema_is_said_on_stderr(self):
|
||||
def test_an_investigation_that_fails_or_answers_outside_the_schema_is_said_on_stderr_and_recorded(self):
|
||||
limited = ran(json.dumps({"type": "result", "api_error_status": 429, "result": "You've hit your limit"}))
|
||||
for reply, reason in ((ran(code=1, stderr="no model"), "no model"), (verdict("hung"), "answered outside its schema"), (ran("crashed"), "the stuck check printed no json reply"), (limited, "claude hit a limit: You've hit your limit")):
|
||||
for reply, reason in ((ran(code=1, stderr="no model"), "no model"), (verdict("hung"), "answered outside its schema: {'verdict': 'hung', 'process': 8, 'why': 'pytest waits on a shell that ignores SIGINT'}"), (ran("crashed"), "the stuck check printed no json reply; its last line was: crashed"), (limited, "claude hit a limit: You've hit your limit")):
|
||||
with self.subTest(reason=reason):
|
||||
_, _, said, failed, record = self.worker_with(ASSISTANT, None, None, held=[shell()], replies=[reply])
|
||||
self.assertEqual((said, record), ("", ""))
|
||||
self.assertIn(f"could not judge whether the worker is stuck: {reason}", failed)
|
||||
line = f"stuck check: could not judge whether the worker is stuck: {reason}{sign(1600, 1600)}"
|
||||
self.assertEqual((said, failed, record), ("", f"<{NOW + 600}> {line}\n", f"- {utc(NOW + 600)} {line}\n"))
|
||||
|
||||
def test_a_verdict_that_cannot_be_recorded_is_still_said_and_the_failure_said_on_stderr(self):
|
||||
with tempfile.NamedTemporaryFile() as blocker:
|
||||
|
||||
Reference in New Issue
Block a user