Answer the audit: Limited in its own module, the retry time's zone injected, file items 37 and 38
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
+10
-1
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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/<case>/*/fixes.diff` (private projects' code) and the clones `workflow-bench/<case>-<version>-<n>/`. 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.
|
||||
|
||||
Reference in New Issue
Block a user