From e7ff8693989564c43baf43e613a3dda7e9ff6bcf Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 22:45:27 +0200 Subject: [PATCH 1/8] Wait out a usage limit and retry, without counting it as a failed run --- CHANGELOG.md | 1 + bin/loop_claude/claude_code/entries.py | 16 +++++++++--- bin/loop_claude/cycle/judge.py | 12 ++++++--- bin/loop_claude/cycle/retry.py | 22 +++++++++++++--- bin/loop_claude/cycle/worker.py | 14 ++++++++--- bin/loop_claude/effects.py | 2 ++ bin/loop_claude/failure.py | 6 +++++ bin/loop_claude/loop/main.py | 4 ++- bin/test_loop_claude.py | 35 +++++++++++++++++++++++--- bin/test_loop_claude_black_box.py | 12 +++++++++ todo.md | 5 ---- 11 files changed, 106 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d75f1bba..8ebbb850 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `loop-claude` waits out a usage limit and retries, without counting it as a failure: 2 minutes past the reset, or every 10 minutes when claude names none. It prints when the next try is due. - Install the `claude-security` plugin (README → Install): larv-review's full security scan now runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. - Every project's `todo.md` takes one shape, and larv-review's gate checks it: one table of items, each scored by the formula and goal weights the file states and held to its bar, an item under the bar dropped unless its Exempt cell says why. `bin/rank_todo.py` ranks the table, and `rank_todo.py --help` shows a valid file. diff --git a/bin/loop_claude/claude_code/entries.py b/bin/loop_claude/claude_code/entries.py index 5c5045b7..c5a2a2b2 100644 --- a/bin/loop_claude/claude_code/entries.py +++ b/bin/loop_claude/claude_code/entries.py @@ -89,6 +89,16 @@ def ends_stream(event: dict) -> bool: return event.get("type") == "result" -# {"type": "result", "structured_output": {"evidence": "...", ...}, ...} -def structured_output(stdout: str) -> object: - return (parse_entry(stdout) or {}).get("structured_output") +# {"type": "result", "api_error_status": 429, "result": "You've hit your session limit · resets 7:40pm (Europe/Stockholm)", ...} +def hit_limit(event: dict) -> bool: + return ends_stream(event) and event.get("api_error_status") == 429 + + +# {"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": 1790790000, ...}} +def rejected_until(event: dict) -> int | None: + """When a usage limit that rejected the request resets, in seconds since the epoch.""" + info = event.get("rate_limit_info") if event.get("type") == "rate_limit_event" else None + if not isinstance(info, dict) or info.get("status") != "rejected": + return None + resets_at = info.get("resetsAt") + return resets_at if isinstance(resets_at, int) and not isinstance(resets_at, bool) else None diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 76e2f1bb..c35d2e10 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -2,11 +2,11 @@ import dataclasses import json import typing -from loop_claude.claude_code.entries import structured_output +from loop_claude.claude_code.entries import hit_limit, parse_entry from loop_claude.cycle.retry import retried from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict from loop_claude.effects import Effects -from loop_claude.failure import Failure +from loop_claude.failure import Failure, Limited from loop_claude.stop import Stop JUDGED_TRANSCRIPT_TAIL = 40000 @@ -63,14 +63,18 @@ def judge(root: str, task: str, premises: str, rendered_transcript: str, model: return retried("judge", lambda: run_judge(root, args, prompt, rendered_transcript, effects), effects) -def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, effects: Effects) -> Verdict | Failure: +def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, effects: Effects) -> Verdict | Failure | Limited: try: proc = effects.claude(args, root, prompt) except OSError as failure: return Failure(f"could not start claude: {failure.strerror}") + reply = parse_entry(proc.stdout) or {} + # The json output names the reset only in prose, such as "resets 7:40pm (Europe/Stockholm)", so the retry polls. + if hit_limit(reply): + return Limited(None) if proc.returncode != 0: return Failure(proc.stderr.strip() or f"the judge exited {proc.returncode}") - verdict = verdict_from(structured_output(proc.stdout)) + verdict = verdict_from(reply.get("structured_output")) if isinstance(verdict, Failure): return Failure(f"{verdict.reason}; it replied: {proc.stdout.strip() or 'nothing'}") if not grounded(verdict.evidence, rendered_transcript): diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 9a4d73b2..73210ce9 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -1,21 +1,37 @@ import sys +import time import typing from loop_claude.effects import Effects -from loop_claude.failure import Failure +from loop_claude.failure import Failure, Limited from loop_claude.stop import Stop T = typing.TypeVar("T") +PAST_RESET = 120 +UNKNOWN_RESET_POLL = 600 -def retried(who: str, attempt: typing.Callable[[], T | Failure], effects: Effects) -> T | Stop: + +def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects) -> T | Stop: failures = 0 while True: - failures += 1 result = attempt() + if isinstance(result, Limited): + due = retry_due(result, effects.now()) + print(f"the {who} hit a usage limit; retrying at {time.strftime('%Y-%m-%d %H:%M', time.localtime(due))}", file=sys.stderr, flush=True) + effects.sleep(due - effects.now()) + continue if not isinstance(result, Failure): return result + failures += 1 if failures == 3: return Stop(1, f"the {who} failed three times running: {result.reason}") print(f"retrying the {who} in a minute: {result.reason}", file=sys.stderr) effects.sleep(60) + + +def retry_due(limited: Limited, now: float) -> float: + # A retry before the reset fails (https://platform.claude.com/docs/en/api/rate-limits), so polling sooner only spends requests. + if limited.resets_at is not None and limited.resets_at + PAST_RESET > now: + return limited.resets_at + PAST_RESET + return now + UNKNOWN_RESET_POLL diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index c23a33cb..5b02ca66 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,25 +1,31 @@ -from loop_claude.claude_code.entries import assistant_parts, ends_stream, parse_entry +from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, parse_entry, rejected_until from loop_claude.claude_code.session import Session from loop_claude.claude_code.transcript import part_line from loop_claude.effects import Effects -from loop_claude.failure import Failure +from loop_claude.failure import Failure, Limited PRINTED_TOOL_INPUT = 160 -def run_worker(root: str, args: list[str], effects: Effects) -> Failure | None: +def run_worker(root: str, args: list[str], effects: Effects) -> Failure | Limited | None: try: proc = effects.stream_claude(args, root) except OSError as failure: return Failure(f"could not start claude: {failure.strerror}") - done = False + done = limited = False + resets: list[int] = [] for raw in proc.lines(): event = parse_entry(raw) or {} done = done or ends_stream(event) + limited = limited or hit_limit(event) + if (resets_at := rejected_until(event)) is not None: + resets.append(resets_at) for part in assistant_parts(event): if line := part_line(part, PRINTED_TOOL_INPUT): print(line, flush=True) code = proc.wait() + if limited: + return Limited(max(resets, default=None)) if code < 0: return Failure(f"claude killed by signal {-code}") if code: diff --git a/bin/loop_claude/effects.py b/bin/loop_claude/effects.py index 8a52d3c5..959c2664 100644 --- a/bin/loop_claude/effects.py +++ b/bin/loop_claude/effects.py @@ -21,6 +21,7 @@ class Effects: execv: typing.Callable[[str, list[str]], None] git: typing.Callable[[list[str], str], subprocess.CompletedProcess[str]] input: typing.Callable[[str], str] + now: typing.Callable[[], float] on_terminal: typing.Callable[[], bool] python: typing.Callable[[list[str]], subprocess.CompletedProcess[str]] sleep: typing.Callable[[float], None] @@ -46,6 +47,7 @@ def system_effects() -> Effects: execv=os.execv, git=lambda args, cwd: subprocess.run(["git", *args], capture_output=True, cwd=cwd, text=True), input=input, + now=time.time, on_terminal=lambda: sys.stdin.isatty() and sys.stdout.isatty(), python=lambda args: subprocess.run([sys.executable, *args], capture_output=True, text=True), sleep=time.sleep, diff --git a/bin/loop_claude/failure.py b/bin/loop_claude/failure.py index 9b46b0b1..8bca78a3 100644 --- a/bin/loop_claude/failure.py +++ b/bin/loop_claude/failure.py @@ -5,3 +5,9 @@ import dataclasses class Failure: """A step failed, and reason says why; its caller decides what follows.""" reason: str + + +@dataclasses.dataclass(frozen=True) +class Limited: + """claude hit a usage limit, which resets at resets_at in seconds since the epoch, or at a time it did not say.""" + resets_at: int | None diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 8939ed85..19d199ae 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -45,7 +45,9 @@ Exit 1, saying why, when: - the worker or the judge fails three times running, retried a minute apart within the cycle. A worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event; a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, - interrupts without a question, or quotes a line the transcript does not hold. + interrupts without a question, or quotes a line the transcript does not hold. A usage limit is + no failure: it is retried 2 minutes past its reset, or every 10 minutes while claude names no + future reset, as the judge's reply never does; stderr says when the next try is due. Exit 2, when the human is needed and cannot answer: - stdin or stdout is not a terminal, when a model must be picked or an interrupt answered diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 69bed5d0..b0a856fb 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -19,12 +19,13 @@ from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished from loop_claude.effects import Effects -from loop_claude.failure import Failure +from loop_claude.failure import Failure, Limited from loop_claude.loop import main, reload from loop_claude.project import checkout, model_choice, premises from loop_claude.stop import Stop CWD = pathlib.Path("/c") +NOW = 1790000000 def assistant(*parts): @@ -54,6 +55,7 @@ class FakeEffects: execv=self.execv, git=lambda args, cwd: self.answer("git", args), input=lambda prompt: self.answer("input", prompt), + now=lambda: NOW, on_terminal=lambda: self.terminal, python=lambda args: self.answer("python", args), sleep=lambda seconds: self.calls.append(("sleep", seconds)), @@ -108,11 +110,12 @@ class Worker: class Streamed: - def __init__(self, code): + def __init__(self, code, *events): self.code = code + self.events = events or ({"type": "result"},) def lines(self): - return [json.dumps({"type": "result"}) + "\n"] + return [json.dumps(event) + "\n" for event in self.events] def wait(self): return self.code @@ -255,6 +258,32 @@ class Retried(unittest.TestCase): self.assertEqual(retry.retried("judge", lambda: Failure("no"), fake.effects()), Stop(1, "the judge failed three times running: no")) self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 60)]) + def test_waits_out_a_usage_limit_without_counting_a_failure(self): + fake = FakeEffects() + results = [Failure("one"), Limited(NOW + 3600), Failure("two"), Limited(None), Limited(NOW - 600), Failure("three")] + self.assertEqual(retry.retried("worker", lambda: results.pop(0), fake.effects()), Stop(1, "the worker failed three times running: three")) + self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 3720), ("sleep", 60), ("sleep", 600), ("sleep", 600)]) + + +class Limits(unittest.TestCase): + def test_the_worker_reports_the_latest_reset_its_stream_names(self): + rejected = [{"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}} for resets_at in (NOW + 60, NOW + 600)] + allowed = {"type": "rate_limit_event", "rate_limit_info": {"status": "allowed", "resetsAt": NOW + 9000}} + limited = {"type": "result", "api_error_status": 429} + fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited), Streamed(1, limited), Streamed(0, rejected[0], {"type": "result"})]) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(NOW + 600)) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None)) + self.assertIsNone(worker.run_worker("/r", [], fake.effects())) + + def test_the_judge_reports_a_limit_whatever_its_exit_code(self): + reply = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit · resets 7:40pm (Europe/Stockholm)"}) + fake = FakeEffects(claude=[ran(reply, code=1, stderr="limited")]) + self.assertEqual(judge.run_judge("/r", [], "", "", fake.effects()), Limited(None)) + + def test_reads_only_a_rejecting_events_whole_seconds(self): + for info, want in [({"status": "rejected", "resetsAt": NOW}, NOW), ({"status": "allowed", "resetsAt": NOW}, None), ({"status": "rejected", "resetsAt": True}, None), ({"status": "rejected"}, None), ("rejected", None)]: + self.assertEqual(entries.rejected_until({"type": "rate_limit_event", "rate_limit_info": info}), want, info) + class Interrupts(unittest.TestCase): def test_stops_off_a_terminal_before_starting_claude(self): diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 2174f736..59d16384 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -390,6 +390,18 @@ class Cycles(unittest.TestCase): self.assertIn("retrying the judge in a minute: the judge returned no reply; it replied: nothing\n", run.stderr) self.assertEqual(run.stderr.strip().splitlines()[-1], 'the judge failed three times running: the judge\'s reply has no evidence of type string; it replied: {"structured_output": {"interrupt": false}}') + def test_waits_out_a_usage_limit_and_retries_without_counting_a_failure(self): + checkout = Checkout(self) + resets_at = int(time.time()) + 3600 + rejected = json.dumps({"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}}) + limited = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit"}) + run = checkout.run([worker(exit=1), worker(stream=f"{rejected}\n{limited}\n", result=False, exit=1), worker(exit=1), worker(), judge(stdout=limited, exit=1), judge()]) + self.assertEqual(run.code, 130) + self.assertEqual(run.roles(), ["worker"] * 4 + ["judge"] * 2 + ["worker"]) + self.assertEqual([round(seconds, -1) for seconds in run.sleeps], [60, 3720, 60, 600]) + self.assertIn(f"the worker hit a usage limit; retrying at {time.strftime('%Y-%m-%d %H:%M', time.localtime(resets_at + 120))}\n", run.stderr) + self.assertIn("the judge hit a usage limit; retrying at ", run.stderr) + def test_retries_the_judge_alone_when_its_verdict_quotes_nothing_in_the_transcript(self): checkout = Checkout(self) run = checkout.run([ diff --git a/todo.md b/todo.md index 9f8e800c..04214525 100644 --- a/todo.md +++ b/todo.md @@ -25,7 +25,6 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | -| 3 | 0.1.0 | | **Wait out a usage limit and retry however long it lasts, without counting it as a failed run.** | 4 | 5 | 9 | 8 | 4 | 23.5 | | 7 | 0.1.0 | decision | **Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice.** | 3 | 4 | 8 | 8 | 4.2 | 19.0 | | 8 | 0.1.0 | | **Judge a cycle on more than the transcript's last 40,000 characters.** | 4 | 5 | 7 | 8 | 4.2 | 15.8 | | 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | @@ -48,10 +47,6 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost 2026-10-02, the human: ai-sandbox is the VM `loop-claude` will run on, hosted on the server bender. bender-infra, the infrastructure-as-code project that manages bender, will back up ai-sandbox's data volume once ai-sandbox is rebuilt. The item waits for the human to say the rebuild has landed. Before writing the README line, check that `~/.claude` lives on that volume and that the backup is private and encrypted at rest. -### 3. Wait out a usage limit and retry however long it lasts, without counting it as a failed run. - -Today a worker or judge that hits a usage limit fails three times a minute apart, and the loop exits 1, so an unattended loop dies at every limit. The transcript line Claude Code writes for it, marked `"error":"rate_limit"`, holds the reset time: `You've hit your session limit · resets 7:40pm (Europe/Stockholm)`. Sleep until 2 minutes past it. The judge runs without a transcript, so find what its JSON reply carries on a limit. Where no reset time can be read, retry every 10 minutes: a retry before the reset fails (https://platform.claude.com/docs/en/api/rate-limits), so polling sooner only spends requests. Print when the next try is due, and update `--help`'s exit 1. - ### 7. Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice. Today it reads only the README's Goals and Audience (`premises.py`) and cannot see an answer recorded in `docs/decisions.md` or `AGENTS.md`, so it can interrupt the human again for a question already answered. Revise the decision "loop-claude: a judge decides each interrupt from the transcript and the README's premises; the worker's own account of which goal settles a choice decides nothing" to match. -- 2.52.0 From 5a481d3ebf8132943c11c477ebabc282a919556c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 22:49:39 +0200 Subject: [PATCH 2/8] Answer the first round: one clock read, the limit's message and time zone on stderr, plainer help and comments --- CHANGELOG.md | 2 +- bin/loop_claude/claude_code/entries.py | 4 ++++ bin/loop_claude/cycle/judge.py | 6 +++--- bin/loop_claude/cycle/retry.py | 15 ++++++++------- bin/loop_claude/cycle/worker.py | 12 +++++++----- bin/loop_claude/failure.py | 3 ++- bin/loop_claude/loop/main.py | 5 +++-- bin/test_loop_claude.py | 12 ++++++------ bin/test_loop_claude_black_box.py | 4 ++-- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ebbb850..cc88bf19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `loop-claude` waits out a usage limit and retries, without counting it as a failure: 2 minutes past the reset, or every 10 minutes when claude names none. It prints when the next try is due. +- `loop-claude` waits out a usage limit and retries, without counting it as a failure: 2 minutes past the reset, or every 10 minutes when claude names none. It prints what claude said about the limit and when the next try is due. - Install the `claude-security` plugin (README → Install): larv-review's full security scan now runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. - Every project's `todo.md` takes one shape, and larv-review's gate checks it: one table of items, each scored by the formula and goal weights the file states and held to its bar, an item under the bar dropped unless its Exempt cell says why. `bin/rank_todo.py` ranks the table, and `rank_todo.py --help` shows a valid file. diff --git a/bin/loop_claude/claude_code/entries.py b/bin/loop_claude/claude_code/entries.py index c5a2a2b2..6bfb73ac 100644 --- a/bin/loop_claude/claude_code/entries.py +++ b/bin/loop_claude/claude_code/entries.py @@ -94,6 +94,10 @@ def hit_limit(event: dict) -> bool: return ends_stream(event) and event.get("api_error_status") == 429 +def limit_said(event: dict) -> str: + return result if isinstance(result := event.get("result"), str) else "claude said nothing more" + + # {"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": 1790790000, ...}} def rejected_until(event: dict) -> int | None: """When a usage limit that rejected the request resets, in seconds since the epoch.""" diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index c35d2e10..06486ba1 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -2,7 +2,7 @@ import dataclasses import json import typing -from loop_claude.claude_code.entries import hit_limit, parse_entry +from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry from loop_claude.cycle.retry import retried from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict from loop_claude.effects import Effects @@ -69,9 +69,9 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, except OSError as failure: return Failure(f"could not start claude: {failure.strerror}") reply = parse_entry(proc.stdout) or {} - # The json output names the reset only in prose, such as "resets 7:40pm (Europe/Stockholm)", so the retry polls. + # The json output names the reset only in prose, such as "resets 7:40pm (Europe/Stockholm)", so the judge's limit carries no reset time. if hit_limit(reply): - return Limited(None) + return Limited(None, limit_said(reply)) if proc.returncode != 0: return Failure(proc.stderr.strip() or f"the judge exited {proc.returncode}") verdict = verdict_from(reply.get("structured_output")) diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 73210ce9..bc0f2ea8 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -17,9 +17,10 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effec while True: result = attempt() if isinstance(result, Limited): - due = retry_due(result, effects.now()) - print(f"the {who} hit a usage limit; retrying at {time.strftime('%Y-%m-%d %H:%M', time.localtime(due))}", file=sys.stderr, flush=True) - effects.sleep(due - effects.now()) + now = effects.now() + wait = limit_wait(result, now) + print(f"the {who} hit a usage limit ({result.said}); retrying at {time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(now + wait))}", file=sys.stderr, flush=True) + effects.sleep(wait) continue if not isinstance(result, Failure): return result @@ -30,8 +31,8 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effec effects.sleep(60) -def retry_due(limited: Limited, now: float) -> float: - # A retry before the reset fails (https://platform.claude.com/docs/en/api/rate-limits), so polling sooner only spends requests. +def limit_wait(limited: Limited, now: float) -> float: + # The limit rejects every request until it resets, so wait for a known reset and poll rarely for an unknown one. if limited.resets_at is not None and limited.resets_at + PAST_RESET > now: - return limited.resets_at + PAST_RESET - return now + UNKNOWN_RESET_POLL + return limited.resets_at + PAST_RESET - now + return UNKNOWN_RESET_POLL diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 5b02ca66..cf830eb0 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,4 +1,4 @@ -from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, parse_entry, rejected_until +from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from loop_claude.claude_code.session import Session from loop_claude.claude_code.transcript import part_line from loop_claude.effects import Effects @@ -12,20 +12,22 @@ def run_worker(root: str, args: list[str], effects: Effects) -> Failure | Limite proc = effects.stream_claude(args, root) except OSError as failure: return Failure(f"could not start claude: {failure.strerror}") - done = limited = False + done = False + limit: str | None = None resets: list[int] = [] for raw in proc.lines(): event = parse_entry(raw) or {} done = done or ends_stream(event) - limited = limited or hit_limit(event) + if hit_limit(event): + limit = limit_said(event) if (resets_at := rejected_until(event)) is not None: resets.append(resets_at) for part in assistant_parts(event): if line := part_line(part, PRINTED_TOOL_INPUT): print(line, flush=True) code = proc.wait() - if limited: - return Limited(max(resets, default=None)) + if limit is not None: + return Limited(max(resets, default=None), limit) if code < 0: return Failure(f"claude killed by signal {-code}") if code: diff --git a/bin/loop_claude/failure.py b/bin/loop_claude/failure.py index 8bca78a3..9c61548a 100644 --- a/bin/loop_claude/failure.py +++ b/bin/loop_claude/failure.py @@ -9,5 +9,6 @@ class Failure: @dataclasses.dataclass(frozen=True) class Limited: - """claude hit a usage limit, which resets at resets_at in seconds since the epoch, or at a time it did not say.""" + """claude hit a usage limit and said so; resets_at is when the limit resets, in seconds since the epoch, or None when claude did not say.""" resets_at: int | None + said: str diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 19d199ae..2f283ab9 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -46,8 +46,9 @@ Exit 1, saying why, when: worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event; a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, interrupts without a question, or quotes a line the transcript does not hold. A usage limit is - no failure: it is retried 2 minutes past its reset, or every 10 minutes while claude names no - future reset, as the judge's reply never does; stderr says when the next try is due. + not a failure: the worker or the judge is retried 2 minutes after the limit resets, or every 10 + minutes while claude names no future reset time. The judge's reply never names one. stderr says + when the next try is due. Exit 2, when the human is needed and cannot answer: - stdin or stdout is not a terminal, when a model must be picked or an interrupt answered diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index b0a856fb..9dc1c59d 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -260,7 +260,7 @@ class Retried(unittest.TestCase): def test_waits_out_a_usage_limit_without_counting_a_failure(self): fake = FakeEffects() - results = [Failure("one"), Limited(NOW + 3600), Failure("two"), Limited(None), Limited(NOW - 600), Failure("three")] + results = [Failure("one"), Limited(NOW + 3600, "limit"), Failure("two"), Limited(None, "limit"), Limited(NOW - 600, "limit"), Failure("three")] self.assertEqual(retry.retried("worker", lambda: results.pop(0), fake.effects()), Stop(1, "the worker failed three times running: three")) self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 3720), ("sleep", 60), ("sleep", 600), ("sleep", 600)]) @@ -269,16 +269,16 @@ class Limits(unittest.TestCase): def test_the_worker_reports_the_latest_reset_its_stream_names(self): rejected = [{"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}} for resets_at in (NOW + 60, NOW + 600)] allowed = {"type": "rate_limit_event", "rate_limit_info": {"status": "allowed", "resetsAt": NOW + 9000}} - limited = {"type": "result", "api_error_status": 429} - fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited), Streamed(1, limited), Streamed(0, rejected[0], {"type": "result"})]) - self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(NOW + 600)) - self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None)) + limited = {"type": "result", "api_error_status": 429, "result": "You've hit your session limit"} + fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited), Streamed(1, {"type": "result", "api_error_status": 429}), Streamed(0, rejected[0], {"type": "result"})]) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(NOW + 600, "You've hit your session limit")) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "claude said nothing more")) self.assertIsNone(worker.run_worker("/r", [], fake.effects())) def test_the_judge_reports_a_limit_whatever_its_exit_code(self): reply = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit · resets 7:40pm (Europe/Stockholm)"}) fake = FakeEffects(claude=[ran(reply, code=1, stderr="limited")]) - self.assertEqual(judge.run_judge("/r", [], "", "", fake.effects()), Limited(None)) + self.assertEqual(judge.run_judge("/r", [], "", "", fake.effects()), Limited(None, "You've hit your session limit · resets 7:40pm (Europe/Stockholm)")) def test_reads_only_a_rejecting_events_whole_seconds(self): for info, want in [({"status": "rejected", "resetsAt": NOW}, NOW), ({"status": "allowed", "resetsAt": NOW}, None), ({"status": "rejected", "resetsAt": True}, None), ({"status": "rejected"}, None), ("rejected", None)]: diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 59d16384..2b3f446a 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -399,8 +399,8 @@ class Cycles(unittest.TestCase): self.assertEqual(run.code, 130) self.assertEqual(run.roles(), ["worker"] * 4 + ["judge"] * 2 + ["worker"]) self.assertEqual([round(seconds, -1) for seconds in run.sleeps], [60, 3720, 60, 600]) - self.assertIn(f"the worker hit a usage limit; retrying at {time.strftime('%Y-%m-%d %H:%M', time.localtime(resets_at + 120))}\n", run.stderr) - self.assertIn("the judge hit a usage limit; retrying at ", run.stderr) + self.assertIn(f"the worker hit a usage limit (You've hit your session limit); retrying at {time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(resets_at + 120))}\n", run.stderr) + self.assertIn("the judge hit a usage limit (You've hit your session limit); retrying at ", run.stderr) def test_retries_the_judge_alone_when_its_verdict_quotes_nothing_in_the_transcript(self): checkout = Checkout(self) -- 2.52.0 From b37b2e91f7ad04c2d7084b08ba323fc5f5d7fd25 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 22:52:16 +0200 Subject: [PATCH 3/8] Answer the second round: the judge's reset is text, one-line limit messages, plainer docstring --- CHANGELOG.md | 2 +- bin/loop_claude/claude_code/entries.py | 3 ++- bin/loop_claude/failure.py | 2 +- bin/loop_claude/loop/main.py | 4 ++-- bin/test_loop_claude.py | 6 ++++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc88bf19..2a0fa47b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `loop-claude` waits out a usage limit and retries, without counting it as a failure: 2 minutes past the reset, or every 10 minutes when claude names none. It prints what claude said about the limit and when the next try is due. +- `loop-claude` waits out a usage limit and retries, without counting it as a failure: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. It prints what claude said about the limit and when the next try is due. - Install the `claude-security` plugin (README → Install): larv-review's full security scan now runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. - Every project's `todo.md` takes one shape, and larv-review's gate checks it: one table of items, each scored by the formula and goal weights the file states and held to its bar, an item under the bar dropped unless its Exempt cell says why. `bin/rank_todo.py` ranks the table, and `rank_todo.py --help` shows a valid file. diff --git a/bin/loop_claude/claude_code/entries.py b/bin/loop_claude/claude_code/entries.py index 6bfb73ac..16c4074e 100644 --- a/bin/loop_claude/claude_code/entries.py +++ b/bin/loop_claude/claude_code/entries.py @@ -95,7 +95,8 @@ def hit_limit(event: dict) -> bool: def limit_said(event: dict) -> str: - return result if isinstance(result := event.get("result"), str) else "claude said nothing more" + said = " ".join(result.split()) if isinstance(result := event.get("result"), str) else "" + return said or "claude gave no message" # {"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": 1790790000, ...}} diff --git a/bin/loop_claude/failure.py b/bin/loop_claude/failure.py index 9c61548a..3d655dc7 100644 --- a/bin/loop_claude/failure.py +++ b/bin/loop_claude/failure.py @@ -9,6 +9,6 @@ class Failure: @dataclasses.dataclass(frozen=True) class Limited: - """claude hit a usage limit and said so; resets_at is when the limit resets, in seconds since the epoch, or None when claude did not say.""" + """claude hit a usage limit; said is claude's message about it, and resets_at is when the limit resets, in seconds since the epoch, or None when unknown.""" resets_at: int | None said: str diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 2f283ab9..d34884b2 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -47,8 +47,8 @@ Exit 1, saying why, when: a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, interrupts without a question, or quotes a line the transcript does not hold. A usage limit is not a failure: the worker or the judge is retried 2 minutes after the limit resets, or every 10 - minutes while claude names no future reset time. The judge's reply never names one. stderr says - when the next try is due. + minutes when the reset time is unknown or past. The judge's reply gives its reset time only as + text, so the judge is always retried every 10 minutes. stderr says when the next try is due. Exit 2, when the human is needed and cannot answer: - stdin or stdout is not a terminal, when a model must be picked or an interrupt answered diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 9dc1c59d..61d0695d 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -270,9 +270,11 @@ class Limits(unittest.TestCase): rejected = [{"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}} for resets_at in (NOW + 60, NOW + 600)] allowed = {"type": "rate_limit_event", "rate_limit_info": {"status": "allowed", "resetsAt": NOW + 9000}} limited = {"type": "result", "api_error_status": 429, "result": "You've hit your session limit"} - fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited), Streamed(1, {"type": "result", "api_error_status": 429}), Streamed(0, rejected[0], {"type": "result"})]) + fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited), Streamed(1, {"type": "result", "api_error_status": 429}), Streamed(1, {"type": "result", "api_error_status": 429, "result": " \n"}), Streamed(1, {"type": "result", "api_error_status": 429, "result": "limit\n resets 7pm"}), Streamed(0, rejected[0], {"type": "result"})]) self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(NOW + 600, "You've hit your session limit")) - self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "claude said nothing more")) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "claude gave no message")) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "claude gave no message")) + self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "limit resets 7pm")) self.assertIsNone(worker.run_worker("/r", [], fake.effects())) def test_the_judge_reports_a_limit_whatever_its_exit_code(self): -- 2.52.0 From 7bf437e75b57b2ea2b4945bf5981804f7dc5c95d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 22:59:21 +0200 Subject: [PATCH 4/8] Answer the architect: a pure worker_outcome, Limited beside the retry, a limit ends a run of failures --- CHANGELOG.md | 2 +- bin/loop_claude/cycle/judge.py | 4 ++-- bin/loop_claude/cycle/retry.py | 12 +++++++++++- bin/loop_claude/cycle/worker.py | 22 ++++++++++++---------- bin/loop_claude/failure.py | 7 ------- bin/loop_claude/loop/main.py | 2 +- bin/test_loop_claude.py | 26 ++++++++++++++++---------- bin/test_loop_claude_black_box.py | 8 ++++---- 8 files changed, 47 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a0fa47b..1ffaca73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `loop-claude` waits out a usage limit and retries, without counting it as a failure: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. It prints what claude said about the limit and when the next try is due. +- `loop-claude` waits out a usage limit and retries, without counting it as a failure, and a limit ends a run of failures: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. It prints what claude said about the limit and when the next try is due. - Install the `claude-security` plugin (README → Install): larv-review's full security scan now runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. - Every project's `todo.md` takes one shape, and larv-review's gate checks it: one table of items, each scored by the formula and goal weights the file states and held to its bar, an item under the bar dropped unless its Exempt cell says why. `bin/rank_todo.py` ranks the table, and `rank_todo.py --help` shows a valid file. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 06486ba1..2152b79f 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -3,10 +3,10 @@ import json import typing from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry -from loop_claude.cycle.retry import retried +from loop_claude.cycle.retry import Limited, retried from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict from loop_claude.effects import Effects -from loop_claude.failure import Failure, Limited +from loop_claude.failure import Failure from loop_claude.stop import Stop JUDGED_TRANSCRIPT_TAIL = 40000 diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index bc0f2ea8..39d3149d 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -1,9 +1,10 @@ +import dataclasses import sys import time import typing from loop_claude.effects import Effects -from loop_claude.failure import Failure, Limited +from loop_claude.failure import Failure from loop_claude.stop import Stop T = typing.TypeVar("T") @@ -12,11 +13,20 @@ PAST_RESET = 120 UNKNOWN_RESET_POLL = 600 +@dataclasses.dataclass(frozen=True) +class Limited: + """claude hit a usage limit; said is claude's message about it, and resets_at is when the limit resets, in seconds since the epoch, or None when unknown.""" + resets_at: int | None + said: str + + def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects) -> T | Stop: failures = 0 while True: result = attempt() if isinstance(result, Limited): + # Hitting the limit proves claude started and reached the API, so the failures before it no longer run on. + failures = 0 now = effects.now() wait = limit_wait(result, now) print(f"the {who} hit a usage limit ({result.said}); retrying at {time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(now + wait))}", file=sys.stderr, flush=True) diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index cf830eb0..f32db6fe 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,8 +1,9 @@ from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from loop_claude.claude_code.session import Session from loop_claude.claude_code.transcript import part_line +from loop_claude.cycle.retry import Limited from loop_claude.effects import Effects -from loop_claude.failure import Failure, Limited +from loop_claude.failure import Failure PRINTED_TOOL_INPUT = 160 @@ -12,27 +13,28 @@ def run_worker(root: str, args: list[str], effects: Effects) -> Failure | Limite proc = effects.stream_claude(args, root) except OSError as failure: return Failure(f"could not start claude: {failure.strerror}") - done = False - limit: str | None = None + result: dict | None = None resets: list[int] = [] for raw in proc.lines(): event = parse_entry(raw) or {} - done = done or ends_stream(event) - if hit_limit(event): - limit = limit_said(event) + if ends_stream(event): + result = event if (resets_at := rejected_until(event)) is not None: resets.append(resets_at) for part in assistant_parts(event): if line := part_line(part, PRINTED_TOOL_INPUT): print(line, flush=True) - code = proc.wait() - if limit is not None: - return Limited(max(resets, default=None), limit) + return worker_outcome(proc.wait(), result, resets) + + +def worker_outcome(code: int, result: dict | None, resets: list[int]) -> Failure | Limited | None: + if result is not None and hit_limit(result): + return Limited(max(resets, default=None), limit_said(result)) if code < 0: return Failure(f"claude killed by signal {-code}") if code: return Failure(f"claude exited {code}") - return None if done else Failure("claude exited 0 without a result event") + return None if result is not None else Failure("claude exited 0 without a result event") def worker_args(task: str, session: Session, model: str, resuming: bool) -> list[str]: diff --git a/bin/loop_claude/failure.py b/bin/loop_claude/failure.py index 3d655dc7..9b46b0b1 100644 --- a/bin/loop_claude/failure.py +++ b/bin/loop_claude/failure.py @@ -5,10 +5,3 @@ import dataclasses class Failure: """A step failed, and reason says why; its caller decides what follows.""" reason: str - - -@dataclasses.dataclass(frozen=True) -class Limited: - """claude hit a usage limit; said is claude's message about it, and resets_at is when the limit resets, in seconds since the epoch, or None when unknown.""" - resets_at: int | None - said: str diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index d34884b2..e23e9700 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -46,7 +46,7 @@ Exit 1, saying why, when: worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event; a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, interrupts without a question, or quotes a line the transcript does not hold. A usage limit is - not a failure: the worker or the judge is retried 2 minutes after the limit resets, or every 10 + not a failure, and ends a run of them: the worker or the judge is retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or past. The judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. stderr says when the next try is due. diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 61d0695d..d935af6e 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -19,7 +19,8 @@ from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished from loop_claude.effects import Effects -from loop_claude.failure import Failure, Limited +from loop_claude.cycle.retry import Limited +from loop_claude.failure import Failure from loop_claude.loop import main, reload from loop_claude.project import checkout, model_choice, premises from loop_claude.stop import Stop @@ -258,11 +259,11 @@ class Retried(unittest.TestCase): self.assertEqual(retry.retried("judge", lambda: Failure("no"), fake.effects()), Stop(1, "the judge failed three times running: no")) self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 60)]) - def test_waits_out_a_usage_limit_without_counting_a_failure(self): + def test_waits_out_a_usage_limit_which_ends_a_run_of_failures(self): fake = FakeEffects() - results = [Failure("one"), Limited(NOW + 3600, "limit"), Failure("two"), Limited(None, "limit"), Limited(NOW - 600, "limit"), Failure("three")] - self.assertEqual(retry.retried("worker", lambda: results.pop(0), fake.effects()), Stop(1, "the worker failed three times running: three")) - self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 3720), ("sleep", 60), ("sleep", 600), ("sleep", 600)]) + results = [Failure("one"), Failure("two"), Limited(NOW + 3600, "limit"), Failure("three"), Limited(None, "limit"), Limited(NOW - 600, "limit"), Failure("four"), Failure("five"), Failure("six")] + self.assertEqual(retry.retried("worker", lambda: results.pop(0), fake.effects()), Stop(1, "the worker failed three times running: six")) + self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 60), ("sleep", 3720), ("sleep", 60), ("sleep", 600), ("sleep", 600), ("sleep", 60), ("sleep", 60)]) class Limits(unittest.TestCase): @@ -270,12 +271,17 @@ class Limits(unittest.TestCase): rejected = [{"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}} for resets_at in (NOW + 60, NOW + 600)] allowed = {"type": "rate_limit_event", "rate_limit_info": {"status": "allowed", "resetsAt": NOW + 9000}} limited = {"type": "result", "api_error_status": 429, "result": "You've hit your session limit"} - fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited), Streamed(1, {"type": "result", "api_error_status": 429}), Streamed(1, {"type": "result", "api_error_status": 429, "result": " \n"}), Streamed(1, {"type": "result", "api_error_status": 429, "result": "limit\n resets 7pm"}), Streamed(0, rejected[0], {"type": "result"})]) + fake = FakeEffects(streams=[Streamed(1, rejected[1], allowed, rejected[0], limited)]) self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(NOW + 600, "You've hit your session limit")) - self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "claude gave no message")) - self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "claude gave no message")) - self.assertEqual(worker.run_worker("/r", [], fake.effects()), Limited(None, "limit resets 7pm")) - self.assertIsNone(worker.run_worker("/r", [], fake.effects())) + + def test_a_limit_outranks_the_exit_code_and_its_message_fits_one_line(self): + def limited(**said): + return {"type": "result", "api_error_status": 429, **said} + self.assertEqual(worker.worker_outcome(-9, limited(result="limit\n resets 7pm"), []), Limited(None, "limit resets 7pm")) + self.assertEqual(worker.worker_outcome(1, limited(result=" \n"), [NOW]), Limited(NOW, "claude gave no message")) + self.assertEqual(worker.worker_outcome(0, limited(), []), Limited(None, "claude gave no message")) + self.assertEqual(worker.worker_outcome(0, None, [NOW]), Failure("claude exited 0 without a result event")) + self.assertIsNone(worker.worker_outcome(0, {"type": "result"}, [NOW])) def test_the_judge_reports_a_limit_whatever_its_exit_code(self): reply = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit · resets 7:40pm (Europe/Stockholm)"}) diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 2b3f446a..8432058f 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -390,15 +390,15 @@ class Cycles(unittest.TestCase): self.assertIn("retrying the judge in a minute: the judge returned no reply; it replied: nothing\n", run.stderr) self.assertEqual(run.stderr.strip().splitlines()[-1], 'the judge failed three times running: the judge\'s reply has no evidence of type string; it replied: {"structured_output": {"interrupt": false}}') - def test_waits_out_a_usage_limit_and_retries_without_counting_a_failure(self): + def test_waits_out_a_usage_limit_which_ends_a_run_of_failures(self): checkout = Checkout(self) resets_at = int(time.time()) + 3600 rejected = json.dumps({"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}}) limited = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit"}) - run = checkout.run([worker(exit=1), worker(stream=f"{rejected}\n{limited}\n", result=False, exit=1), worker(exit=1), worker(), judge(stdout=limited, exit=1), judge()]) + run = checkout.run([worker(exit=1), worker(exit=1), worker(stream=f"{rejected}\n{limited}\n", result=False, exit=1), worker(exit=1), worker(), judge(stdout=limited, exit=1), judge()]) self.assertEqual(run.code, 130) - self.assertEqual(run.roles(), ["worker"] * 4 + ["judge"] * 2 + ["worker"]) - self.assertEqual([round(seconds, -1) for seconds in run.sleeps], [60, 3720, 60, 600]) + self.assertEqual(run.roles(), ["worker"] * 5 + ["judge"] * 2 + ["worker"]) + self.assertEqual([round(seconds, -1) for seconds in run.sleeps], [60, 60, 3720, 60, 600]) self.assertIn(f"the worker hit a usage limit (You've hit your session limit); retrying at {time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(resets_at + 120))}\n", run.stderr) self.assertIn("the judge hit a usage limit (You've hit your session limit); retrying at ", run.stderr) -- 2.52.0 From a5e6e92f2264f378ca18ef9a7a1e7364d222bbc4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 22:59:29 +0200 Subject: [PATCH 5/8] Reflow the help's limit clause; say when a past reset still waits --- bin/loop_claude/loop/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index e23e9700..dff9f349 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -46,9 +46,10 @@ Exit 1, saying why, when: worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event; a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, interrupts without a question, or quotes a line the transcript does not hold. A usage limit is - not a failure, and ends a run of them: the worker or the judge is retried 2 minutes after the limit resets, or every 10 - minutes when the reset time is unknown or past. The judge's reply gives its reset time only as - text, so the judge is always retried every 10 minutes. stderr says when the next try is due. + not a failure, and ends a run of them: the worker or the judge is retried 2 minutes after the + limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. + The judge's reply gives its reset time only as text, so the judge is always retried every 10 + minutes. stderr says when the next try is due. Exit 2, when the human is needed and cannot answer: - stdin or stdout is not a terminal, when a model must be picked or an interrupt answered -- 2.52.0 From 8e8503345b8f638b734b2b97a179d9d691060fc9 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 23:05:17 +0200 Subject: [PATCH 6/8] Answer the audit: Limited in its own module, the retry time's zone injected, file items 37 and 38 --- bin/loop_claude/claude_code/entries.py | 5 +++++ bin/loop_claude/cycle/judge.py | 7 ++++--- bin/loop_claude/cycle/retry.py | 12 ++---------- bin/loop_claude/cycle/worker.py | 2 +- bin/loop_claude/effects.py | 2 ++ bin/loop_claude/limited.py | 8 ++++++++ bin/test_loop_claude.py | 11 ++++++++++- bin/test_loop_claude_black_box.py | 4 +++- todo.md | 12 +++++++++++- 9 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 bin/loop_claude/limited.py diff --git a/bin/loop_claude/claude_code/entries.py b/bin/loop_claude/claude_code/entries.py index 16c4074e..f226a57c 100644 --- a/bin/loop_claude/claude_code/entries.py +++ b/bin/loop_claude/claude_code/entries.py @@ -94,6 +94,11 @@ def hit_limit(event: dict) -> bool: return ends_stream(event) and event.get("api_error_status") == 429 +# {"type": "result", "structured_output": {"evidence": "...", ...}, ...} +def structured_output(result: dict) -> object: + return result.get("structured_output") + + def limit_said(event: dict) -> str: said = " ".join(result.split()) if isinstance(result := event.get("result"), str) else "" return said or "claude gave no message" diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 2152b79f..2c8b481e 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -2,11 +2,12 @@ import dataclasses import json import typing -from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry -from loop_claude.cycle.retry import Limited, retried +from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output +from loop_claude.cycle.retry import retried from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict from loop_claude.effects import Effects from loop_claude.failure import Failure +from loop_claude.limited import Limited from loop_claude.stop import Stop JUDGED_TRANSCRIPT_TAIL = 40000 @@ -74,7 +75,7 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, return Limited(None, limit_said(reply)) if proc.returncode != 0: return Failure(proc.stderr.strip() or f"the judge exited {proc.returncode}") - verdict = verdict_from(reply.get("structured_output")) + verdict = verdict_from(structured_output(reply)) if isinstance(verdict, Failure): return Failure(f"{verdict.reason}; it replied: {proc.stdout.strip() or 'nothing'}") if not grounded(verdict.evidence, rendered_transcript): diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 39d3149d..3723eaf0 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -1,10 +1,9 @@ -import dataclasses import sys -import time import typing from loop_claude.effects import Effects from loop_claude.failure import Failure +from loop_claude.limited import Limited from loop_claude.stop import Stop T = typing.TypeVar("T") @@ -13,13 +12,6 @@ PAST_RESET = 120 UNKNOWN_RESET_POLL = 600 -@dataclasses.dataclass(frozen=True) -class Limited: - """claude hit a usage limit; said is claude's message about it, and resets_at is when the limit resets, in seconds since the epoch, or None when unknown.""" - resets_at: int | None - said: str - - def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects) -> T | Stop: failures = 0 while True: @@ -29,7 +21,7 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effec failures = 0 now = effects.now() wait = limit_wait(result, now) - print(f"the {who} hit a usage limit ({result.said}); retrying at {time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(now + wait))}", file=sys.stderr, flush=True) + print(f"the {who} hit a usage limit ({result.said}); retrying at {effects.local_time(now + wait)}", file=sys.stderr, flush=True) effects.sleep(wait) continue if not isinstance(result, Failure): diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index f32db6fe..dcc642bf 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,9 +1,9 @@ from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from loop_claude.claude_code.session import Session from loop_claude.claude_code.transcript import part_line -from loop_claude.cycle.retry import Limited from loop_claude.effects import Effects from loop_claude.failure import Failure +from loop_claude.limited import Limited PRINTED_TOOL_INPUT = 160 diff --git a/bin/loop_claude/effects.py b/bin/loop_claude/effects.py index 959c2664..0e20ef0e 100644 --- a/bin/loop_claude/effects.py +++ b/bin/loop_claude/effects.py @@ -21,6 +21,7 @@ class Effects: execv: typing.Callable[[str, list[str]], None] git: typing.Callable[[list[str], str], subprocess.CompletedProcess[str]] input: typing.Callable[[str], str] + local_time: typing.Callable[[float], str] now: typing.Callable[[], float] on_terminal: typing.Callable[[], bool] python: typing.Callable[[list[str]], subprocess.CompletedProcess[str]] @@ -47,6 +48,7 @@ def system_effects() -> Effects: execv=os.execv, git=lambda args, cwd: subprocess.run(["git", *args], capture_output=True, cwd=cwd, text=True), input=input, + local_time=lambda seconds: time.strftime("%Y-%m-%d %H:%M %Z", time.localtime(seconds)), now=time.time, on_terminal=lambda: sys.stdin.isatty() and sys.stdout.isatty(), python=lambda args: subprocess.run([sys.executable, *args], capture_output=True, text=True), diff --git a/bin/loop_claude/limited.py b/bin/loop_claude/limited.py new file mode 100644 index 00000000..5ed69bc6 --- /dev/null +++ b/bin/loop_claude/limited.py @@ -0,0 +1,8 @@ +import dataclasses + + +@dataclasses.dataclass(frozen=True) +class Limited: + """claude hit a usage limit; said is claude's message about it, and resets_at is when the limit resets, in seconds since the epoch, or None when unknown.""" + resets_at: int | None + said: str diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index d935af6e..84e6440f 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -1,6 +1,8 @@ import ast +import contextlib import dataclasses import hashlib +import io import json import os import pathlib @@ -19,8 +21,8 @@ from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished from loop_claude.effects import Effects -from loop_claude.cycle.retry import Limited from loop_claude.failure import Failure +from loop_claude.limited import Limited from loop_claude.loop import main, reload from loop_claude.project import checkout, model_choice, premises from loop_claude.stop import Stop @@ -56,6 +58,7 @@ class FakeEffects: execv=self.execv, git=lambda args, cwd: self.answer("git", args), input=lambda prompt: self.answer("input", prompt), + local_time=lambda seconds: f"<{seconds}>", now=lambda: NOW, on_terminal=lambda: self.terminal, python=lambda args: self.answer("python", args), @@ -265,6 +268,12 @@ class Retried(unittest.TestCase): self.assertEqual(retry.retried("worker", lambda: results.pop(0), fake.effects()), Stop(1, "the worker failed three times running: six")) self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 60), ("sleep", 3720), ("sleep", 60), ("sleep", 600), ("sleep", 600), ("sleep", 60), ("sleep", 60)]) + def test_says_what_claude_said_and_when_the_next_try_is_due(self): + results = [Limited(NOW + 3600, "You've hit your session limit"), "done"] + with contextlib.redirect_stderr(io.StringIO()) as said: + retry.retried("judge", lambda: results.pop(0), FakeEffects().effects()) + self.assertEqual(said.getvalue(), f"the judge hit a usage limit (You've hit your session limit); retrying at <{NOW + 3720}>\n") + class Limits(unittest.TestCase): def test_the_worker_reports_the_latest_reset_its_stream_names(self): diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 8432058f..10f69aea 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -1,4 +1,5 @@ import dataclasses +import datetime import hashlib import json import os @@ -392,6 +393,7 @@ class Cycles(unittest.TestCase): def test_waits_out_a_usage_limit_which_ends_a_run_of_failures(self): checkout = Checkout(self) + checkout.env["TZ"] = "UTC" resets_at = int(time.time()) + 3600 rejected = json.dumps({"type": "rate_limit_event", "rate_limit_info": {"status": "rejected", "resetsAt": resets_at}}) limited = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit"}) @@ -399,7 +401,7 @@ class Cycles(unittest.TestCase): self.assertEqual(run.code, 130) self.assertEqual(run.roles(), ["worker"] * 5 + ["judge"] * 2 + ["worker"]) self.assertEqual([round(seconds, -1) for seconds in run.sleeps], [60, 60, 3720, 60, 600]) - self.assertIn(f"the worker hit a usage limit (You've hit your session limit); retrying at {time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(resets_at + 120))}\n", run.stderr) + self.assertIn(f"the worker hit a usage limit (You've hit your session limit); retrying at {datetime.datetime.fromtimestamp(resets_at + 120, datetime.timezone.utc):%Y-%m-%d %H:%M} UTC\n", run.stderr) self.assertIn("the judge hit a usage limit (You've hit your session limit); retrying at ", run.stderr) def test_retries_the_judge_alone_when_its_verdict_quotes_nothing_in_the_transcript(self): diff --git a/todo.md b/todo.md index 04214525..2f04459e 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 37` +`Next ID = 39` | Goal | W | |---|---| @@ -25,7 +25,9 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | +| 37 | 0.1.0 | | **Make README → Install install every plugin `settings.json` enables, or confirm Claude Code installs an enabled plugin itself.** | 1 | 1 | 5 | 7 | 1 | 22.8 | | 7 | 0.1.0 | decision | **Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice.** | 3 | 4 | 8 | 8 | 4.2 | 19.0 | +| 38 | 0.1.0 | | **Make `test_gitignore.py` prove the bench's logs, fixes and clones stay off the remote.** | 1 | 1 | 4 | 6 | 3 | 16.1 | | 8 | 0.1.0 | | **Judge a cycle on more than the transcript's last 40,000 characters.** | 4 | 5 | 7 | 8 | 4.2 | 15.8 | | 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | | 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 | @@ -47,10 +49,18 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost 2026-10-02, the human: ai-sandbox is the VM `loop-claude` will run on, hosted on the server bender. bender-infra, the infrastructure-as-code project that manages bender, will back up ai-sandbox's data volume once ai-sandbox is rebuilt. The item waits for the human to say the rebuild has landed. Before writing the README line, check that `~/.claude` lives on that volume and that the backup is private and encrypted at rest. +### 37. Make README → Install install every plugin `settings.json` enables, or confirm Claude Code installs an enabled plugin itself. + +`settings.json` enables `code-review@claude-plugins-official` and `rust-analyzer-lsp@claude-plugins-official`, and Install names only `claude-security`; `rust-analyzer-lsp` also needs `rust-analyzer` on `PATH`. If an enabled plugin is not installed on its own, a new machine set up from Install lacks both, and the changelog's claim that `settings.json` runs unedited on any machine with Install's prerequisites is false. + ### 7. Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice. Today it reads only the README's Goals and Audience (`premises.py`) and cannot see an answer recorded in `docs/decisions.md` or `AGENTS.md`, so it can interrupt the human again for a question already answered. Revise the decision "loop-claude: a judge decides each interrupt from the transcript and the README's premises; the worker's own account of which goal settles a choice decides nothing" to match. +### 38. Make `test_gitignore.py` prove the bench's logs, fixes and clones stay off the remote. + +Its private-file list lacks `workflow-bench/logs/*.jsonl` (unattended runs' transcripts), `workflow-bench/judge//*/fixes.diff` (private projects' code) and the clones `workflow-bench/--/`. The allowlist ignores them today, but a broader rule such as `!workflow-bench/*` would pass the test and publish them. + ### 8. Judge a cycle on more than the transcript's last 40,000 characters. `judge_prompt` cuts the transcript there. The session spans every cycle of the chunk, so a decision made early in a long run is never judged, and the human is not interrupted for it. Larger chunks make runs longer. -- 2.52.0 From cd3684e720e1ef80bdd2e5eb2a420d27bdc86190 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 23:17:07 +0200 Subject: [PATCH 7/8] Record shipping under the floor at the PR's scores --- docs/decisions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/decisions.md b/docs/decisions.md index e4e4803e..e264030a 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -30,7 +30,7 @@ ## comprehension floor: every dimension and the overall at 7.0 or above, and 0.1.0 waits on it -2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. Valid until the next scoring run, which uses the same four seats. +2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, `todo.md` item 13; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. Valid until the next scoring run, which uses the same four seats. ## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes -- 2.52.0 From 0267de9abb67b430842459c679daa9f2193385f0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 23:19:38 +0200 Subject: [PATCH 8/8] Answer the fourth round: the changelog's timing beside the retry, plainer help, comment and todo wording --- CHANGELOG.md | 2 +- bin/loop_claude/cycle/retry.py | 2 +- bin/loop_claude/loop/main.py | 8 ++++---- docs/decisions.md | 2 +- todo.md | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ffaca73..0a884dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `loop-claude` waits out a usage limit and retries, without counting it as a failure, and a limit ends a run of failures: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. It prints what claude said about the limit and when the next try is due. +- `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Install the `claude-security` plugin (README → Install): larv-review's full security scan now runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. - Every project's `todo.md` takes one shape, and larv-review's gate checks it: one table of items, each scored by the formula and goal weights the file states and held to its bar, an item under the bar dropped unless its Exempt cell says why. `bin/rank_todo.py` ranks the table, and `rank_todo.py --help` shows a valid file. diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 3723eaf0..571df431 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -17,7 +17,7 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effec while True: result = attempt() if isinstance(result, Limited): - # Hitting the limit proves claude started and reached the API, so the failures before it no longer run on. + # Hitting the limit proves claude started and reached the API, so the failures before it stop counting towards three. failures = 0 now = effects.now() wait = limit_wait(result, now) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index dff9f349..a9b593d2 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -46,10 +46,10 @@ Exit 1, saying why, when: worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event; a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, interrupts without a question, or quotes a line the transcript does not hold. A usage limit is - not a failure, and ends a run of them: the worker or the judge is retried 2 minutes after the - limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. - The judge's reply gives its reset time only as text, so the judge is always retried every 10 - minutes. stderr says when the next try is due. + not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes + after the limit resets, or every 10 minutes when the reset time is unknown or more than 2 + minutes past. The judge's reply gives its reset time only as text, so the judge is always + retried every 10 minutes. stderr says when the next try is due. Exit 2, when the human is needed and cannot answer: - stdin or stdout is not a terminal, when a model must be picked or an interrupt answered diff --git a/docs/decisions.md b/docs/decisions.md index e264030a..0a4026aa 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -30,7 +30,7 @@ ## comprehension floor: every dimension and the overall at 7.0 or above, and 0.1.0 waits on it -2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, `todo.md` item 13; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. Valid until the next scoring run, which uses the same four seats. +2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, which `todo.md` item 13 covers; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. Valid until the next scoring run, which uses the same four seats. ## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes diff --git a/todo.md b/todo.md index 2f04459e..41363b0a 100644 --- a/todo.md +++ b/todo.md @@ -25,7 +25,7 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | -| 37 | 0.1.0 | | **Make README → Install install every plugin `settings.json` enables, or confirm Claude Code installs an enabled plugin itself.** | 1 | 1 | 5 | 7 | 1 | 22.8 | +| 37 | 0.1.0 | | **Make README → Install's steps install every plugin `settings.json` enables, or confirm Claude Code installs an enabled plugin itself.** | 1 | 1 | 5 | 7 | 1 | 22.8 | | 7 | 0.1.0 | decision | **Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice.** | 3 | 4 | 8 | 8 | 4.2 | 19.0 | | 38 | 0.1.0 | | **Make `test_gitignore.py` prove the bench's logs, fixes and clones stay off the remote.** | 1 | 1 | 4 | 6 | 3 | 16.1 | | 8 | 0.1.0 | | **Judge a cycle on more than the transcript's last 40,000 characters.** | 4 | 5 | 7 | 8 | 4.2 | 15.8 | @@ -49,7 +49,7 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost 2026-10-02, the human: ai-sandbox is the VM `loop-claude` will run on, hosted on the server bender. bender-infra, the infrastructure-as-code project that manages bender, will back up ai-sandbox's data volume once ai-sandbox is rebuilt. The item waits for the human to say the rebuild has landed. Before writing the README line, check that `~/.claude` lives on that volume and that the backup is private and encrypted at rest. -### 37. Make README → Install install every plugin `settings.json` enables, or confirm Claude Code installs an enabled plugin itself. +### 37. Make README → Install's steps install every plugin `settings.json` enables, or confirm Claude Code installs an enabled plugin itself. `settings.json` enables `code-review@claude-plugins-official` and `rust-analyzer-lsp@claude-plugins-official`, and Install names only `claude-security`; `rust-analyzer-lsp` also needs `rust-analyzer` on `PATH`. If an enabled plugin is not installed on its own, a new machine set up from Install lacks both, and the changelog's claim that `settings.json` runs unedited on any machine with Install's prerequisites is false. @@ -59,7 +59,7 @@ Today it reads only the README's Goals and Audience (`premises.py`) and cannot s ### 38. Make `test_gitignore.py` prove the bench's logs, fixes and clones stay off the remote. -Its private-file list lacks `workflow-bench/logs/*.jsonl` (unattended runs' transcripts), `workflow-bench/judge//*/fixes.diff` (private projects' code) and the clones `workflow-bench/--/`. The allowlist ignores them today, but a broader rule such as `!workflow-bench/*` would pass the test and publish them. +Its private-file list lacks `workflow-bench/logs/*.jsonl` (unattended runs' transcripts), `workflow-bench/judge//*/fixes.diff` (private projects' code) and the clones `workflow-bench/--/`. `.gitignore` keeps them out today, but a broader rule such as `!workflow-bench/*` would pass the test and publish them. ### 8. Judge a cycle on more than the transcript's last 40,000 characters. -- 2.52.0