Give failure one spelling #116

Merged
lilleman merged 2 commits from failure-one-spelling into rebuild 2026-09-28 21:25:30 +02:00
12 changed files with 29 additions and 33 deletions
+3 -3
View File
@@ -5,7 +5,7 @@ from loop_claude.checkout import project_name
from loop_claude.file_writes import make_private, replace_file
from loop_claude.interrupt import interrupt
from loop_claude.judge import judge
from loop_claude.outcome import Continue, Failure, Retry, Stop
from loop_claude.outcome import Continue, Failure, Stop
from loop_claude.session import delete_session, session_for, transcript_file
from loop_claude.transcript import read, render
from loop_claude.worker import run_worker, worker_args
@@ -15,7 +15,7 @@ def run_cycle(root, task, premises, models, paths):
session = session_for(root, paths)
resuming = bool(transcript_file(session))
if failure := run_worker(root, worker_args(task, session, models.worker, resuming)):
return Retry(failure.reason)
return failure
path = transcript_file(session)
if not path:
return Stop(1, f"claude left no transcript for session {session.id}")
@@ -57,6 +57,6 @@ def archive(root, path, note, paths):
if not copy.exists():
for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)):
if failure := replace_file(dest, data):
return Failure(f"could not archive the transcript: {dest}: {failure.strerror}")
return Failure(f"could not archive the transcript: {dest}: {failure.reason}")
print(f"transcript: {copy}", file=sys.stderr)
return None
+3 -1
View File
@@ -1,6 +1,8 @@
import json
import os
from loop_claude.outcome import Failure
def make_private(folder):
mask = os.umask(0o077)
@@ -25,5 +27,5 @@ def replace_file(path, data):
except OSError as failure:
if os.path.exists(staged):
os.remove(staged)
return failure
return Failure(failure.strerror)
return None
+4 -4
View File
@@ -53,14 +53,14 @@ def judge(root, task, premises, transcript, model):
for failures in itertools.count(1):
verdict = run_judge(root, args, prompt)
if isinstance(verdict, Failure):
failure = verdict.reason
reason = verdict.reason
elif reason := incomplete(verdict):
failure = reason
pass
elif not grounded(verdict, transcript):
failure = f"the judge quoted {verdict['evidence']!r}, nothing in the transcript" + (f", for the question: {verdict['question']}" if verdict["interrupt"] else "")
reason = f"the judge quoted {verdict['evidence']!r}, nothing in the transcript" + (f", for the question: {verdict['question']}" if verdict["interrupt"] else "")
else:
return verdict
if stop := stop_or_sleep_a_minute("judge", failures, failure):
if stop := stop_or_sleep_a_minute("judge", failures, reason):
return stop
+3 -3
View File
@@ -39,7 +39,7 @@ import sys
from loop_claude.checkout import checkout_root
from loop_claude.cycle import run_cycle
from loop_claude.models import project_models
from loop_claude.outcome import Continue, Retry, Stop
from loop_claude.outcome import Continue, Failure, Stop
from loop_claude.premises import read_premises
from loop_claude.reload import RELOAD_FLAG, decode_state, exec_if_edited, fingerprint
from loop_claude.retry import stop_or_sleep_a_minute
@@ -81,9 +81,9 @@ def run_loop(argv, env, paths, launcher, cwd):
match run_cycle(state.root, state.task, premises, models, paths):
case Stop() as stop:
return stop
case Retry(failure):
case Failure(reason):
state = dataclasses.replace(state, failures=state.failures + 1)
if stop := stop_or_sleep_a_minute("worker", state.failures, failure):
if stop := stop_or_sleep_a_minute("worker", state.failures, reason):
return stop
case Continue():
state = dataclasses.replace(state, failures=0)
+1 -1
View File
@@ -40,7 +40,7 @@ def project_model(name, paths):
if isinstance(models, Stop):
return models
if failure := replace_json(saved, {**models, name: chosen}, indent="\t", sort_keys=True):
return Stop(1, f"could not save the model in {saved}: {failure.strerror}")
return Stop(1, f"could not save the model in {saved}: {failure.reason}")
print(f"{name} runs on {chosen}", file=sys.stderr)
return chosen
-5
View File
@@ -11,11 +11,6 @@ class Failure:
reason: str
@dataclasses.dataclass(frozen=True)
class Retry:
failure: str
@dataclasses.dataclass(frozen=True)
class Stop:
code: int
+3 -3
View File
@@ -4,8 +4,8 @@ import time
from loop_claude.outcome import Stop
def stop_or_sleep_a_minute(who, failures, failure):
def stop_or_sleep_a_minute(who, failures, reason):
if failures == 3:
return Stop(1, f"the {who} failed three times running: {failure}")
print(f"retrying the {who} in a minute: {failure}", file=sys.stderr)
return Stop(1, f"the {who} failed three times running: {reason}")
print(f"retrying the {who} in a minute: {reason}", file=sys.stderr)
time.sleep(60)
+2 -2
View File
@@ -19,13 +19,13 @@ def human_turns(entries):
def render(entries):
lines = []
for entry in entries:
lines += [line for part in assistant_parts(entry) if (line := said(part))]
lines += [line for part in assistant_parts(entry) if (line := part_line(part))]
if (text := human_text(entry)) is not None:
lines.append("[human] " + text)
return "\n\n".join(lines)
def said(part, limit=400):
def part_line(part, limit=400):
if (text := part_text(part)) and text.strip():
return text
if call := tool_call(part):
+1 -1
View File
@@ -21,6 +21,6 @@ def trust(config, roots):
if not untrusted:
return
if failure := replace_json(config, data, indent=2):
print(f"could not write {config}: {failure.strerror}", file=sys.stderr)
print(f"could not write {config}: {failure.reason}", file=sys.stderr)
return
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
+2 -2
View File
@@ -2,7 +2,7 @@ import subprocess
from loop_claude.claude_code import assistant_parts, ends_stream, parse
from loop_claude.outcome import Failure
from loop_claude.transcript import said
from loop_claude.transcript import part_line
def run_worker(root, args):
@@ -16,7 +16,7 @@ def run_worker(root, args):
event = parse(raw) or {}
done = done or ends_stream(event)
for part in assistant_parts(event):
if line := said(part, 160):
if line := part_line(part, 160):
print(line, flush=True)
code = proc.wait()
if code < 0:
+7 -7
View File
@@ -8,7 +8,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from loop_claude import claude_code, file_writes, judge, main, premises, transcript
from loop_claude.outcome import Stop
from loop_claude.outcome import Failure, Stop
CWD = pathlib.Path("/c")
@@ -58,12 +58,12 @@ class HumanTurns(unittest.TestCase):
]), 3)
class Said(unittest.TestCase):
class PartLine(unittest.TestCase):
def test_renders_text_and_tool_calls_and_nothing_else(self):
self.assertEqual(transcript.said({"type": "text", "text": "hi"}), "hi")
self.assertEqual(transcript.said({"type": "text", "text": " \n"}), "")
self.assertEqual(transcript.said({"type": "tool_use", "name": "Bash", "input": {"command": "x" * 500}}, 20), '[tool Bash] {"command": "xxxxxxx')
self.assertEqual(transcript.said("not a part"), "")
self.assertEqual(transcript.part_line({"type": "text", "text": "hi"}), "hi")
self.assertEqual(transcript.part_line({"type": "text", "text": " \n"}), "")
self.assertEqual(transcript.part_line({"type": "tool_use", "name": "Bash", "input": {"command": "x" * 500}}, 20), '[tool Bash] {"command": "xxxxxxx')
self.assertEqual(transcript.part_line("not a part"), "")
class Parse(unittest.TestCase):
@@ -103,7 +103,7 @@ class ReplaceFile(unittest.TestCase):
def test_removes_what_it_staged_when_the_replace_fails(self):
with tempfile.TemporaryDirectory() as root:
os.mkdir(os.path.join(root, "in-the-way"))
self.assertIsInstance(file_writes.replace_file(os.path.join(root, "in-the-way"), b"data"), IsADirectoryError)
self.assertEqual(file_writes.replace_file(os.path.join(root, "in-the-way"), b"data"), Failure("Is a directory"))
self.assertEqual(os.listdir(root), ["in-the-way"])
-1
View File
@@ -8,7 +8,6 @@ The rebuild lifts every dimension: each item below is one chunk on a worktree ba
The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first:
- **Give failure one spelling: `Failure.reason` and `Retry.failure`, `replace_file`'s raw `OSError`, and `said` named for what it tests.** Keep `LoopState`'s fields: they are main's `--reloaded` state (`docs/decisions.md`).
- **Group `bin/loop_claude/`'s 18 flat modules, and move `principles/review-findings.md` beside larv-review.** Two seats; `claude_code.py` is the first group.
- **Show the judge a reply the human sends while claude works.** Claude Code 2.1.284 writes it as an `"attachment"` entry, which `render` drops, so the judge can rule on a question the human already answered during an interrupt.
- **Score `rebuild` with the four-seat panel at 7.0 or above on every dimension and the overall, none below the last run, and open its PR into main for the human.** ⚠️ Leave that PR ready and unmerged: only the human merges it, after approving the whole rebuild. A dimension under the floor gets its places filed above this item.