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

This commit was merged in pull request #45.
This commit is contained in:
2026-09-25 18:03:27 +02:00
parent 2062e5c5f1
commit b956228fd1
4 changed files with 47 additions and 15 deletions
+19 -13
View File
@@ -11,9 +11,10 @@ An unfinished chunk resumes the same session next cycle; a finished one starts a
Cycles continue until that interrupt or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary".
Exit 1: no task, not inside a checkout, no premises, claude leaves no transcript, or the worker or
the judge fails three times running. A judge fails when its verdict misses a field or quotes nothing
in the transcript. Exit 2: the human is needed and stdin or stdout is not a terminal, or the
interrupt ended without them typing anything. Rerunning resumes any open session.
the judge fails three times running. A worker fails when claude exits non-zero, is killed, or ends
without a result event; a judge when its verdict misses a field or quotes nothing in the transcript.
Exit 2: the human is needed and stdin or stdout is not a terminal, or the interrupt ended without
them typing anything. Rerunning resumes any open session.
Each project has one session, "A <path> loop-claude", <path> being the checkout relative to ~/code,
or to / outside it, deleted when the chunk finishes. Its transcript is archived under
@@ -262,16 +263,21 @@ 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 {}
code = proc.wait()
if code < 0:
return f"claude killed by signal {-code}"
if code:
return f"claude exited {code}"
return "" if done else "claude exited 0 without a result event"
def judge_prompt(task, premises, transcript):
@@ -328,9 +334,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 +349,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 +383,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"retrying the worker in a minute: {failure}", file=sys.stderr)
time.sleep(60)