Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 12:42:03 +01:00
parent 8ca612b7a4
commit cb3135bc8c
124 changed files with 1437 additions and 793 deletions
+4 -5
View File
@@ -1,5 +1,4 @@
"""The experiment behind review-replay's --omit-claude-md, --bash-ceiling and --read-limit: three replays of a pass's rounds unchanged, one with the change, and the report that holds the one with it to what the others found: docs/decisions.md → `agents/: a reviewer starts without CLAUDE.md only where a replay of its pass missed no more findings than the most an unchanged replay missed`."""
import sys
import typing
from review_replay.changes import Change
@@ -10,8 +9,8 @@ from review_replay.rounds import Round
from model_routing.ladder import Rung
def compared(reviewed: str, project: Rung, chosen: list[Round], change: Change, found_on: typing.Callable[[Round, Change | None], set[int] | Failure | Limited]) -> str | Limited:
"""Replays chosen three times unchanged and once with change, as found_on(round, change or None) finds, and reports the comparison of the rounds no replay failed on; the Limited where claude hit its usage limit."""
def compared(reviewed: str, project: Rung, chosen: list[Round], change: Change, found_on: typing.Callable[[Round, Change | None], set[int] | Failure | Limited], say: typing.Callable[[str], None], at_once: int) -> str | Limited:
"""Replays chosen three times unchanged and once with change, as found_on(round, change or None) finds, and reports the comparison of the rounds no replay failed on; the Limited where claude hit its usage limit. It tells say each round a failed replay leaves out."""
runs: list[list[set[int] | Failure]] = []
for applied in (None, None, None, change):
label = change.changed if applied else change.unchanged
@@ -19,10 +18,10 @@ def compared(reviewed: str, project: Rung, chosen: list[Round], change: Change,
def replay_one(one: Round, _: Rung, applied: Change | None = applied, label: str = label) -> set[int] | Failure | Limited:
found = found_on(one, applied)
if isinstance(found, Failure):
print(f" {one.root} {one.at} {label} failed, so the round is left out: {found.reason}", file=sys.stderr)
say(f" {one.root} {one.at} {label} failed, so the round is left out: {found.reason}")
return found
found: list[set[int] | Failure] | Limited = replayed_on(chosen, project, replay_one, f"{reviewed} rounds {label}")
found: list[set[int] | Failure] | Limited = replayed_on(chosen, project, replay_one, f"{reviewed} rounds {label}", say, at_once)
if isinstance(found, Limited):
return found
runs.append(found)
+13 -12
View File
@@ -67,22 +67,22 @@ none. Exit 1, saying why, on bad arguments, an unreadable archive or models file
round to replay, or a usage limit.
"""
import pathlib
import sys
import typing
from transcript_archive.location import archive_root
from review_replay.rounds import archived_rounds, Round, sample
from rung_replay.archive import archiving, print_report, replay_folder
from rung_replay.command import arguments_or_exit, failed, limited_exit
from rung_replay.archive import archiving, replay_folder
from rung_replay.command import arguments_or_exit, failed, limited_exit, print_report, say
from rung_replay.search import AT_ONCE
from review_replay.changes import Change, CHANGES
from review_replay.replay import codes_found, findings_replayed
from review_replay.change_comparison import compared
from loop_effects.effects import Effects
from review_replay.recall import ENOUGH_ROUNDS, recall_report, recalled
from failure import Failure
from model_routing.ladder import Ladder, Rung
from claude_code.reply import Limited
from model_routing.ladder_file import read_ladder, SHIPPED
from review_replay.recall import recall_report, recalled
from review_rules.review_passes import ReviewedPass, REVIEWERS
TOOL = "review-replay"
@@ -90,7 +90,8 @@ USAGE = f"{TOOL} <pass> <model> [{' | '.join(change.flag for change in CHANGES)}
LATEST = 10
def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, effects: Effects) -> int:
# A test sets the three limits: the fewest rounds a rung is tried on, the rounds replayed at once, and the folder each clone is made in, the system's temporary folder where None.
def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, effects: Effects, *, enough_rounds: int = ENOUGH_ROUNDS, at_once: int = AT_ONCE, scratch: pathlib.Path | None = None) -> int:
# The shipped ladder, not a project's: the replay spans every project on the model.
ladder = read_ladder(SHIPPED)
if isinstance(ladder, Failure):
@@ -105,29 +106,29 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
rounds = archived_rounds(REVIEWERS[reviewed], project.model, archive_root(home, env), home)
if isinstance(rounds, Failure):
return failed(TOOL, rounds.reason)
codes = codes_found(rounds, effects)
codes = codes_found(rounds, effects, say)
if not codes:
return failed(TOOL, f"no archived {reviewed} round of projects on {project.model} in {archive_root(home, env)} holds a 🔴 or 🟡 on code it can find")
chosen = sample(list(codes), LATEST)
folder = replay_folder(archive_root(home, env), TOOL, argv, effects.now())
effects = archiving(effects, folder)
effects = archiving(effects, folder, say)
if change:
report = compared(reviewed, project, chosen, change, lambda found, applied: findings_replayed(found, codes[found], project, project, home, effects, applied))
report = compared(reviewed, project, chosen, change, lambda found, applied: findings_replayed(found, codes[found], project, project, home, effects, applied, scratch), say, at_once)
if isinstance(report, Limited):
return limited_exit(TOOL, report)
print_report(folder, report)
return 0
def replay_one(found: Round, rung: Rung) -> set[int] | Failure | Limited:
matched = findings_replayed(found, codes[found], rung, project, home, effects, None)
matched = findings_replayed(found, codes[found], rung, project, home, effects, None, scratch)
if isinstance(matched, Failure):
print(f" {found.root} {found.at} on {rung} failed: {matched.reason}", file=sys.stderr, flush=True)
say(f" {found.root} {found.at} on {rung} failed: {matched.reason}")
return matched
recall = recalled(chosen, ladder, project, replay_one, f"{reviewed} rounds")
recall = recalled(chosen, ladder, project, replay_one, f"{reviewed} rounds", say, at_once, enough_rounds)
if isinstance(recall, Limited):
return limited_exit(TOOL, recall)
print_report(folder, recall_report(reviewed, project, recall))
print_report(folder, recall_report(reviewed, project, recall, enough_rounds))
return 0
+8 -12
View File
@@ -43,10 +43,6 @@ def candidates(ladder: Ladder, project: Rung) -> list[Rung]:
return lower_efforts + down_from(ladder, project, ladder.rungs[0])[1:]
def enough(rounds: list[Round]) -> bool:
return len(rounds) >= ENOUGH_ROUNDS
def count(found: list[set[int]]) -> int:
return sum(map(len, found))
@@ -72,14 +68,14 @@ def tried(rung: Rung, rounds: list[Round], reference: Reference, found: list[set
return RungRecall(rung, count(found), missed_red, 0 < needed(rounds, reference) <= count(found) and not missed_red)
def recall_report(reviewed: str, project: Rung, recall: Recall) -> str:
def recall_report(reviewed: str, project: Rung, recall: Recall, enough_rounds: int) -> str:
rounds, (first, second) = recall.rounds, recall.reference
lines = [
f"Replayed {len(rounds)} {reviewed} rounds of {project.model} projects, which hold {held(rounds)} 🔴 and 🟡 findings, twice on the project's rung, {project}.",
*([f"Left out {recall.left_out} more, which a replay on the project's rung failed on; stderr says why."] if recall.left_out else []),
]
if not enough(rounds):
return "\n".join([*lines, f"No rung tried: fewer than {ENOUGH_ROUNDS} rounds were replayed on the project's rung without a failure."])
if len(rounds) < enough_rounds:
return "\n".join([*lines, f"No rung tried: fewer than {enough_rounds} rounds were replayed on the project's rung without a failure."])
if needed(rounds, recall.reference) <= 0:
return "\n".join([*lines, "No rung tried: the project's rung found too few of them to hold a rung to."])
lines.append(f"The project's rung found {count(first)} and then {count(second)} of the {held(rounds)}, {percent(mean_share(rounds, recall.reference))} on average, so a rung qualifies finding {needed(rounds, recall.reference)} or more of them, missing no 🔴 that both of its replays found.")
@@ -95,11 +91,11 @@ def percent(fraction: Fraction) -> str:
return f"{float(fraction):.0%}"
def recalled(chosen: list[Round], ladder: Ladder, project: Rung, replay_one: typing.Callable[[Round, Rung], set[int] | Failure | Limited], what: str) -> Recall | Limited:
"""Replays chosen twice on the project's rung, then each candidate, highest first, on the rounds neither of those failed on, until one doesn't qualify."""
def recalled(chosen: list[Round], ladder: Ladder, project: Rung, replay_one: typing.Callable[[Round, Rung], set[int] | Failure | Limited], what: str, say: typing.Callable[[str], None], at_once: int, enough_rounds: int) -> Recall | Limited:
"""Replays chosen twice on the project's rung, then each candidate, highest first, on the rounds neither of those failed on, until one doesn't qualify; no candidate where fewer than enough_rounds rounds are left."""
runs: list[list[set[int] | Failure]] = []
for _ in range(2):
found: list[set[int] | Failure] | Limited = replayed_on(chosen, project, replay_one, what)
found: list[set[int] | Failure] | Limited = replayed_on(chosen, project, replay_one, what, say, at_once)
if isinstance(found, Limited):
return found
runs.append(found)
@@ -112,8 +108,8 @@ def recalled(chosen: list[Round], ladder: Ladder, project: Rung, replay_one: typ
reference[1].append(second)
recalls: list[RungRecall] = []
lowest = None
for rung in candidates(ladder, project) if enough(rounds) and needed(rounds, reference) > 0 else []:
on_rung: list[set[int] | Failure] | Limited = replayed_on(rounds, rung, replay_one, what)
for rung in candidates(ladder, project) if len(rounds) >= enough_rounds and needed(rounds, reference) > 0 else []:
on_rung: list[set[int] | Failure] | Limited = replayed_on(rounds, rung, replay_one, what, say, at_once)
if isinstance(on_rung, Limited):
return on_rung
# A failed replay on a candidate found none, so it lowers that rung's count and never lifts it to what a rung needs.
+9 -9
View File
@@ -4,8 +4,8 @@ import json
import os
import pathlib
import shutil
import sys
import tempfile
import typing
from review_replay.rounds import authored_by, lost_inputs, reviewed_path, Round
from review_replay.changes import Change
@@ -34,12 +34,12 @@ class Code:
base: str
def codes_found(rounds: list[Round], effects: Effects) -> dict[Round, Code]:
"""The code each round reviewed, as code_of finds it; stderr names each round left out, and why."""
def codes_found(rounds: list[Round], effects: Effects, say: typing.Callable[[str], None]) -> dict[Round, Code]:
"""The code each round reviewed, as code_of finds it; say is told each round left out, and why."""
codes = {}
for found in rounds:
if isinstance(code := code_of(found, effects), Failure):
print(f"{found.root} {found.at} is left out: {code.reason}", file=sys.stderr, flush=True)
say(f"{found.root} {found.at} is left out: {code.reason}")
else:
codes[found] = code
return codes
@@ -75,9 +75,9 @@ def commit_log(listed: str) -> list[tuple[str, float]]:
return [(commit, float(authored)) for commit, authored in (line.split() for line in listed.splitlines())]
def findings_replayed(found: Round, code: Code, rung: Rung, project: Rung, home: pathlib.Path, effects: Effects, change: Change | None) -> set[int] | Failure | Limited:
"""The indexes of the round's findings that its replay on rung reports, as claude on the project's rung matches them, or the Failure of the review or the match; where change is given, the replay runs with it, as `launch` says."""
reviewed: str | Failure | Limited = first_reply(lambda: review(found, code, rung, home, effects, change))
def findings_replayed(found: Round, code: Code, rung: Rung, project: Rung, home: pathlib.Path, effects: Effects, change: Change | None, scratch: pathlib.Path | None) -> set[int] | Failure | Limited:
"""The indexes of the round's findings that its replay on rung reports, as claude on the project's rung matches them, or the Failure of the review or the match; where change is given, the replay runs with it, as `launch` says. The clone is made under scratch, or under the system's temporary folder where it is None."""
reviewed: str | Failure | Limited = first_reply(lambda: review(found, code, rung, home, effects, change, scratch))
if isinstance(reviewed, (Failure, Limited)):
return reviewed
return first_reply(lambda: match(found.findings, reviewed, found.root, project, effects))
@@ -91,10 +91,10 @@ class Copies:
# The shell makes and removes the clone itself, and is tested on a temporary home as judge-replay's is.
def review(found: Round, code: Code, rung: Rung, home: pathlib.Path, effects: Effects, change: Change | None) -> str | Failure | Limited:
def review(found: Round, code: Code, rung: Rung, home: pathlib.Path, effects: Effects, change: Change | None, scratch: pathlib.Path | None) -> str | Failure | Limited:
try:
(home / REPORTS).mkdir(mode=0o700, parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="review-replay-", ignore_cleanup_errors=True) as clone, tempfile.TemporaryDirectory(prefix="review-replay-", dir=home / REPORTS, ignore_cleanup_errors=True) as reports:
with tempfile.TemporaryDirectory(prefix="review-replay-", dir=scratch, ignore_cleanup_errors=True) as clone, tempfile.TemporaryDirectory(prefix="review-replay-", dir=home / REPORTS, ignore_cleanup_errors=True) as reports:
return reviewed_in(found, code, rung, Copies(clone, reports), home, effects, change)
except OSError as failure:
return Failure(f"could not prepare the replay: {failure}")
+7 -9
View File
@@ -1,12 +1,11 @@
import contextlib
import io
import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from review_replay.recall import candidates, needed, Recall, recall_report, recalled, tried
from rung_replay.search import AT_ONCE
from review_replay.recall import candidates, ENOUGH_ROUNDS, needed, Recall, recall_report, recalled, tried
from review_replay.rounds import is_red, Round
from model_routing.ladder_file import read_ladder, SHIPPED
from model_routing.ladder import Rung
@@ -44,8 +43,7 @@ class Recalled(unittest.TestCase):
def test_tries_the_rungs_below_where_the_project_rung_needs_one_finding(self):
# Eight findings, of which both replays on the project's rung find one: a share of an eighth, a tenth under which leaves one finding needed.
rounds = [a_round(at, ("🟡 a",)) for at in range(8)]
with contextlib.redirect_stderr(io.StringIO()):
recall = recalled(rounds, LADDER, REFERENCE, lambda one, rung: {0} if one == rounds[0] else set(), "prose rounds")
recall = recalled(rounds, LADDER, REFERENCE, lambda one, rung: {0} if one == rounds[0] else set(), "prose rounds", lambda text: None, AT_ONCE, ENOUGH_ROUNDS)
self.assertEqual(([one.rung for one in recall.tried], recall.lowest), ([LOW, SONNET], SONNET))
@@ -96,7 +94,7 @@ class RecallReport(unittest.TestCase):
rounds, reference = self.EIGHT
low = tried(LOW, rounds, reference, [{0, 1, 2}, {0, 1, 2}] * 4)
sonnet = tried(SONNET, rounds, reference, [{1, 2, 3, 4}, {0}] * 4)
lines = recall_report("prose", REFERENCE, Recall(rounds, reference, 1, [low, sonnet], LOW)).splitlines()
lines = recall_report("prose", REFERENCE, Recall(rounds, reference, 1, [low, sonnet], LOW), ENOUGH_ROUNDS).splitlines()
self.assertEqual(lines, [
"Replayed 8 prose rounds of claude-opus-5-5 projects, which hold 40 🔴 and 🟡 findings, twice on the project's rung, claude-opus-5-5 at medium effort.",
"Left out 1 more, which a replay on the project's rung failed on; stderr says why.",
@@ -108,17 +106,17 @@ class RecallReport(unittest.TestCase):
])
def test_says_why_no_rung_was_tried(self):
few = recall_report("prose", REFERENCE, Recall(ROUNDS, (FIRST, SECOND), 0, [], None)).splitlines()
few = recall_report("prose", REFERENCE, Recall(ROUNDS, (FIRST, SECOND), 0, [], None), ENOUGH_ROUNDS).splitlines()
self.assertEqual(few[1:], ["No rung tried: fewer than 8 rounds were replayed on the project's rung without a failure."])
rounds, _ = self.EIGHT
for reference in (([set()] * 8, [set()] * 8), (TENTH[0] * 4, TENTH[1] * 4)):
too_few = recall_report("prose", REFERENCE, Recall(rounds, reference, 0, [], None)).splitlines()
too_few = recall_report("prose", REFERENCE, Recall(rounds, reference, 0, [], None), ENOUGH_ROUNDS).splitlines()
self.assertEqual(too_few[1:], ["No rung tried: the project's rung found too few of them to hold a rung to."])
def test_names_no_rung_where_none_qualifies(self):
rounds, reference = self.EIGHT
low = tried(LOW, rounds, reference, [{0}, {0}] * 4)
lines = recall_report("prose", REFERENCE, Recall(rounds, reference, 0, [low], None)).splitlines()
lines = recall_report("prose", REFERENCE, Recall(rounds, reference, 0, [low], None), ENOUGH_ROUNDS).splitlines()
self.assertEqual(lines[-2:], ["claude-opus-5-5 at low effort found 8, 20%, and missed no such 🔴: it doesn't qualify.", "Lowest rung that qualifies: none below the project's rung"])
+10 -12
View File
@@ -10,13 +10,12 @@ import subprocess
import sys
import tempfile
import unittest
import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from review_replay.rounds import authored_by, lost_inputs, recorded_findings, reviewed_path, Round, round_from, sample, stamp_seconds
from review_replay import changes, main, recall, replay
from text_files import compressed
from review_replay import changes, main, replay
from text_files.doubles import compress
from project_config.doubles import configured, write_config
from loop_effects.effects import Effects, system_effects
from claude_code.entries import entry_from
@@ -24,7 +23,6 @@ from failure import Failure
from review_rules.reviewer_context import reviewer_context
from review_rules.review_passes import REVIEWERS
from model_routing.ladder import Rung
from rung_replay import search
TOOL = pathlib.Path(__file__).resolve().parents[1] / "review-replay"
REFERENCE = Rung("claude-opus-5-5", "medium")
@@ -172,7 +170,7 @@ class Match(unittest.TestCase):
self.asked.append((args, cwd, prompt))
return subprocess.CompletedProcess(args, 0, stdout, "")
return replay.match(("🔴 a", "🟡 b"), "the other report", "/code/p", REFERENCE, dataclasses.replace(system_effects(), claude=claude))
return replay.match(("🔴 a", "🟡 b"), "the other report", "/code/p", REFERENCE, dataclasses.replace(system_effects(pathlib.Path.home(), os.environ), claude=claude))
def test_asks_for_the_numbered_findings_the_other_report_raises_as_json_with_no_tools(self):
self.run_match("{}")
@@ -222,7 +220,7 @@ class Main(unittest.TestCase):
self.write_chunk(key, "c1", "2026-10-14T10:00:00Z")
(self.home / ".claude" / "CLAUDE.md").write_text("## Shared goal\n\nHealth.\n\n## Prose\n\nShort.\n\n## Vocabulary\n\nWords.\n")
# The fixture holds one round.
self.enterContext(unittest.mock.patch.object(recall, "ENOUGH_ROUNDS", 1))
self.limits = {"enough_rounds": 1}
self.reviews = []
self.review_settings = []
self.agents = set()
@@ -270,10 +268,10 @@ class Main(unittest.TestCase):
result = result if "api_error_status" in result else {"type": "result", "structured_output": {"found": [n + 1 for n in result["found"]]}}
return subprocess.CompletedProcess(args, 0, json.dumps(result), "")
effects = Effects(claude=claude, claude_on_terminal=unused, discard_typed=unused, dm=unused, execv=unused, git=system_effects().git, input=unused, local_time=unused, memory=unused, now=lambda: 1790000000.0, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused, timer=unused, tmux=unused, tmux_on_terminal=unused)
effects = Effects(claude=claude, claude_on_terminal=unused, discard_typed=unused, dm=unused, execv=unused, git=system_effects(pathlib.Path.home(), os.environ).git, input=unused, local_time=unused, memory=unused, now=lambda: 1790000000.0, on_terminal=unused, python=unused, replace_file=unused, sleep=unused, stream_claude=unused, timer=unused, tmux=unused, tmux_on_terminal=unused)
out, err = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main.main(argv, env, self.home, effects)
code = main.main(argv, env, self.home, effects, **self.limits)
return code, out.getvalue(), err.getvalue()
def test_keeps_each_reviewer_and_match_run_and_the_printed_report_in_one_folder_of_the_archive(self):
@@ -428,14 +426,14 @@ class Main(unittest.TestCase):
def test_replays_rounds_whose_archived_transcripts_are_compressed(self):
for copy in self.archive.rglob("*.jsonl"):
self.assertIsNone(compressed.compress(copy))
self.assertIsNone(compress(copy))
code, out, err = self.run_main(["stability", "claude-opus-5-5"], lambda rung: {"found": [1] if rung == LOW else [0, 1]})
self.assertEqual(code, 0, err)
self.assertTrue(out.startswith("Replayed 1 stability rounds of claude-opus-5-5 projects,"), out)
def test_copies_a_compressed_report_from_before_the_round_under_its_plain_name(self):
folder = self.review_folder_with_round_1()
self.assertIsNone(compressed.compress(folder / "stability-round-1.md"))
self.assertIsNone(compress(folder / "stability-round-1.md"))
self.set_prompt(f"Review branch x in {self.home}/code/proj-x. Write your report to ~/.local/state/larv-review/code/proj-x/stability-round-2.md; the last round's is ~/.local/state/larv-review/code/proj-x/stability-round-1.md.")
seen = []
@@ -513,7 +511,7 @@ class Main(unittest.TestCase):
(folder / "stability-round-1.md").chmod(0)
self.set_prompt(f"Review branch x in {self.home}/code/proj-x. Write your report to ~/.local/state/larv-review/code/proj-x/stability-round-2.md.")
scratch = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
self.enterContext(unittest.mock.patch.object(tempfile, "tempdir", str(scratch)))
self.limits["scratch"] = scratch
code, _, err = self.run_main(["stability", "claude-opus-5-5"], unused)
self.assertEqual(code, 0, err)
self.assertEqual(self.reviews, [])
@@ -529,7 +527,7 @@ class Main(unittest.TestCase):
def test_leaves_out_a_round_that_either_replay_on_the_project_rung_failed_on(self):
self.write_chunk("proj", "c2", "2026-10-14T10:30:00Z")
self.enterContext(unittest.mock.patch.object(search, "AT_ONCE", 1))
self.limits["at_once"] = 1
# One round at a time, three tries on a round reply with no report: the first replay's on its first round, then the second replay's on its first, after the first replay's two reviews. Every other review replies.
for failing in (range(3), range(2, 5)):
with self.subTest(failing=failing):