Say why the worker failed: the exit code, or exit 0 without a result event

This commit is contained in:
2026-09-25 17:58:04 +02:00
parent 2062e5c5f1
commit 5d9cb80912
4 changed files with 35 additions and 12 deletions
+12 -10
View File
@@ -262,16 +262,18 @@ def worker_args(task, name, session_id, resuming):
def run_worker(args):
proc = subprocess.Popen(["claude", *args], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, text=True)
done = {}
done = False
for raw in proc.stdout:
event = parse(raw) or {}
if event.get("type") == "result":
done = event
done = True
elif event.get("type") == "assistant":
for part in event.get("message", {}).get("content", []):
if line := said(part, 160):
print(line, flush=True)
return done if proc.wait() == 0 else {}
if code := proc.wait():
return f"claude exited {code}"
return "" if done else "claude exited 0 without a result event"
def judge_prompt(task, premises, transcript):
@@ -328,9 +330,8 @@ def interrupt(session_id, path, question):
def run_cycle(task, premises, name, session_id):
worked = run_worker(worker_args(task, name, session_id, resuming=session_open(session_id)))
if not worked:
return False
if failure := run_worker(worker_args(task, name, session_id, resuming=session_open(session_id))):
return failure
path = session_file(session_id)
if not path:
sys.exit(f"claude left no transcript for session {session_id}")
@@ -344,7 +345,7 @@ def run_cycle(task, premises, name, session_id):
if verdict["finished"]:
archive(path, f"Task: {task}\n\nVerdict: finished")
end_session(path)
return True
return ""
def reload_if_edited(task, cycle_number, failures):
@@ -378,13 +379,14 @@ def main():
premises = read_premises()
name = session_name()
print(f"\n=== cycle {cycle_number} ===", flush=True)
if run_cycle(task, premises, name, uuid.uuid5(SESSION_NAMESPACE, name)):
failure = run_cycle(task, premises, name, uuid.uuid5(SESSION_NAMESPACE, name))
if not failure:
failures = 0
continue
failures += 1
if failures == 3:
sys.exit("the worker failed three times running")
print("the worker failed - retrying in a minute", file=sys.stderr)
sys.exit(f"the worker failed three times running: {failure}")
print(f"the worker failed: {failure} - retrying in a minute", file=sys.stderr)
time.sleep(60)