Answer prose round 1: 0 🔴, 16 🟡 (0 misread); name the offline deciders and runs, and fix the help, the decision and the docstrings

This commit is contained in:
2026-11-17 10:22:54 +01:00
parent 155a65117c
commit 5f098aa315
6 changed files with 82 additions and 56 deletions
+17 -9
View File
@@ -32,15 +32,22 @@ replays/judge-replay-<model>-<UTC stamp>/ under ~/.claude/loop-claude-transcript
A run's .jsonl file starts with a line holding claude's arguments, working directory, prompt, exit code and
stderr, then holds claude's stream-json output; result.md holds the report.
With --offline it calls no judge. It reads every archived verdict of the model's projects, not a sample, and
replays what code could decide of its kind from the worker's final message: a "?" rule, a decision table and
a classifier trained on the archive (judge_replay/offline.py). It prints, for each, how many verdicts it
decided and how many interrupts it missed, on held-out folds and on the latest fifth.
Like the loop, it tries a judge three times running before it counts the reply as failed. A
verdict whose project, transcript or archived judge run cannot be read replays as failed too. Exit 1, saying why, on
bad arguments, an unreadable archive or models file, no archived verdict of the model's projects,
or a usage limit.
With --offline it doesn't call a judge, so the runs, retries and usage limit above don't apply. It reads every
archived verdict of the model's projects, not a sample. It counts how many of them each of three code
deciders decides from the worker's final message, and how many archived interrupts it decides as another
kind, which are its missed interrupts: a "?" rule, a decision table, and a classifier trained on the archive
(judge_replay/offline.py). The rule and the table run on the whole archive; the table's rows were read from
it, so its run isn't a held-out test. The classifier runs on held-out folds, each tested by a model trained on
the other folds, and on the latest fifth of the verdicts, tested by a model trained on the earlier four
fifths. The report is kept in replays/judge-replay-<model>-offline-<UTC stamp>/result.md. A verdict whose
transcript cannot be read is skipped, and the report counts the skipped. Exit 1, saying why, on bad
arguments, an unreadable archive or models file, no archived verdict of the model's projects, or none with a
transcript that can be read.
"""
import pathlib
import sys
@@ -51,7 +58,7 @@ from transcript_archive.read import archived_outcomes
from rung_replay.archive import archiving, print_report, replay_folder
from rung_replay.command import arguments_or_exit, down_from, failed, limited_exit, projects_on
from loop_claude.cycle.judge import Brief, judge_archived, judge_once
from judge_replay.offline import final_message, METHODS, offline_report, Sample
from judge_replay.offline import final_message, LEARNERS, offline_report, RULES, Sample
from judge_replay.replay import Case, case_from, Kind, report, reproduced, sample, verdict_kind
from transcript_archive.project_key import checkout_of
from loop_effects.effects import Effects
@@ -68,7 +75,7 @@ from claude_code.transcript import read_transcript
from loop_claude.verdicts import Verdict
TOOL = "judge-replay"
USAGE = f"{TOOL} <model> [--offline], a model on the routing ladder"
USAGE = f"{TOOL} <model> [--offline]; <model> is a model on the routing ladder"
OFFLINE = "--offline"
PER_KIND = 15
# The effort settings.json gave every judge before loop-claude routed it; the archived verdicts came from it.
@@ -104,16 +111,17 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
def offline(model: str, argv: list[str], cases: list[Case], root: pathlib.Path, effects: Effects) -> int:
"""Replays the verdicts of cases offline, oldest first, and keeps the report in the archive as a judge replay does."""
samples = []
samples, skipped = [], 0
for found in sorted(cases, key=lambda found: (found.at, found.root, str(found.transcript))):
entries = read_transcript(str(found.transcript))
if isinstance(entries, Failure):
skipped += 1
print(f"{TOOL}: skipped a verdict: {entries.reason}", file=sys.stderr)
else:
samples.append(Sample(found.archived_kind, final_message(entries)))
if not samples:
return failed(TOOL, "no archived verdict has a transcript that can be read")
print_report(replay_folder(root, TOOL, argv, effects.now()), offline_report(model, samples, METHODS))
print_report(replay_folder(root, TOOL, argv, effects.now()), offline_report(model, samples, RULES, LEARNERS, skipped=skipped))
return 0
+26 -16
View File
@@ -86,9 +86,9 @@ def logistic(samples: typing.Sequence[Sample]) -> typing.Callable[[str], float]:
def classifier(samples: typing.Sequence[Sample]) -> Decider:
"""Finished below the lowest chance any interrupt among the samples got when held out, interrupt above the highest chance any other kind got, and the judge's model between.
"""Finished where the chance of an interrupt is below one half and below that of every interrupt among the samples; interrupt where it is at least one half and above that of every other kind; otherwise the judge's model decides.
Each sample's chance is the one a model trained on the other folds of the samples gives it, so the bounds don't rest on how well the model fits what it trained on. A bound is where the samples held no miss; that doesn't promise the next verdict holds none."""
A sample's chance is the one a model trained on the other folds of the samples gives it, so the bounds don't rest on how well the model fits what it trained on. A bound is where the samples held no miss; that doesn't promise the next verdict holds none."""
interrupts = [found for found in samples if found.kind == INTERRUPTED]
if not interrupts or len(interrupts) == len(samples):
return lambda text: None
@@ -105,11 +105,13 @@ def classifier(samples: typing.Sequence[Sample]) -> Decider:
return decide
METHODS: dict[str, Method] = {"a question mark": question_mark, "decision table": decision_table, "classifier": classifier}
# Rules are fixed, and run on the whole archive; a learner trains on samples, and runs on samples it didn't train on.
RULES: dict[str, Method] = {'"?" rule': question_mark, "decision table": decision_table}
LEARNERS: dict[str, Method] = {"classifier": classifier}
def folds_of(samples: typing.Sequence[Sample], count: int) -> list[tuple[list[Sample], list[Sample]]]:
"""count folds of the samples, dealt in turn; each is what to learn from and what to test on, the samples the fold's test leaves out."""
"""count folds of the samples, dealt in turn. Each fold is the samples to learn from, which are all those its test leaves out, and the samples to test on."""
return [([found for place, found in enumerate(samples) if place % count != fold], [found for place, found in enumerate(samples) if place % count == fold]) for fold in range(count)]
@@ -123,18 +125,26 @@ def plain(kind: Kind) -> str:
return kind.removeprefix("Verdict: ")
def offline_report(model: str, samples: typing.Sequence[Sample], methods: typing.Mapping[str, Method], folds: int = FOLDS) -> str:
def offline_report(model: str, samples: typing.Sequence[Sample], rules: typing.Mapping[str, Method], learners: typing.Mapping[str, Method], folds: int = FOLDS, skipped: int = 0) -> str:
"""samples are in the order the verdicts were judged, oldest first, so the latest fifth is the newest verdicts."""
kinds = collections.Counter(found.kind for found in samples)
lines = [f"Replayed {len(samples)} archived verdicts of {model} projects offline, nothing sent to an outside service: {', '.join(f'{count} {plain(kind)}' for kind, count in sorted(kinds.items(), key=lambda each: plain(each[0])))}."]
lines = [f"Replayed {len(samples)} archived verdicts of {model} projects offline, without sending anything to an outside service. The archive gives them as {', '.join(f'{count} {plain(kind)}' for kind, count in sorted(kinds.items(), key=lambda each: plain(each[0])))}."]
if skipped:
lines.append(f"Skipped {skipped} verdicts whose transcript could not be read.")
for name, rule in rules.items():
lines += decided_lines(f"{name}, on the whole archive", evaluate(rule, [], samples), kinds)
split = len(samples) - max(1, len(samples) // LATEST)
for name, method in methods.items():
held_out = sum((evaluate(method, trained, tested) for trained, tested in folds_of(samples, folds)), Counts())
lines += [result_line(f"{name}, on held-out folds", held_out), *decides_lines(name, held_out, kinds)]
lines.append(result_line(f"{name}, on the latest fifth after learning from the rest", evaluate(method, samples[:split], samples[split:])))
for name, learner in learners.items():
held_out = sum((evaluate(learner, trained, tested) for trained, tested in folds_of(samples, folds)), Counts())
lines += decided_lines(f"{name}, on held-out folds", held_out, kinds)
lines.append(result_line(f"{name}, on the latest fifth after learning from the rest", evaluate(learner, samples[:split], samples[split:])))
return "\n".join(lines)
def decided_lines(how: str, found: Counts, kinds: collections.Counter[Kind]) -> list[str]:
return [result_line(how, found), *decides_lines(how, found, kinds)]
def result_line(how: str, found: Counts) -> str:
decided = collections.Counter({kind: sum(count for (_, said), count in found.items() if said == kind) for kind in {said for _, said in found if said}})
missed = sum(count for (archived, said), count in found.items() if archived == INTERRUPTED and said not in (None, INTERRUPTED))
@@ -143,18 +153,18 @@ def result_line(how: str, found: Counts) -> str:
def wrong_kinds(decided: Kind, found: Counts) -> str:
"""The archived kinds a decider returned decided for, where the archive gave another kind."""
"""The kinds the archive gives the verdicts that were decided as decided, where the archive gives another kind than decided."""
wrong = sorted(((plain(archived), count) for (archived, said), count in found.items() if said == decided and archived != decided), key=lambda each: each[0])
return f" (archived {', '.join(f'{kind} {count}' for kind, count in wrong)})" if wrong else ""
return f" (of these, archived {', '.join(f'{kind} {count}' for kind, count in wrong)})" if wrong else ""
def decides_lines(name: str, found: Counts, kinds: collections.Counter[Kind]) -> list[str]:
"""For finished and for unfinished: whether the decider decided it where the archive holds no interrupt, and how much of that kind it got right."""
def decides_lines(how: str, found: Counts, kinds: collections.Counter[Kind]) -> list[str]:
"""For finished and for unfinished that the decider decided at all: whether it decided no archived interrupt as that kind, and how many of the kind it got right."""
lines = []
for kind in (FINISHED, UNFINISHED):
decided = sum(count for (_, said), count in found.items() if said == kind)
if decided and not found[(INTERRUPTED, kind)]:
lines.append(f"{name} decides {plain(kind)} with no missed interrupt: {found[(kind, kind)]} of {kinds[kind]} {plain(kind)}.")
lines.append(f"{how}, decides {plain(kind)} with no missed interrupt: {found[(kind, kind)]} of {kinds[kind]} {plain(kind)}.")
elif decided:
lines.append(f"{name} does not decide {plain(kind)} with no missed interrupt.")
lines.append(f"{how}, does not decide {plain(kind)} with no missed interrupt: it decided {found[(INTERRUPTED, kind)]} archived interrupt(s) as {plain(kind)}.")
return lines
+2 -2
View File
@@ -179,8 +179,8 @@ class Main(unittest.TestCase):
code, out, err = self.run_main(["claude-opus-5-5", "--offline"], unused)
self.assertEqual(code, 0, err)
self.assertEqual(self.calls, [])
self.assertIn("Replayed 2 archived verdicts of claude-opus-5-5 projects offline, nothing sent to an outside service: 1 finished, 1 interrupt.", out)
self.assertIn("a question mark, on held-out folds: decided 2 of 2: finished 2 (archived interrupt 1). Missed interrupts: 1.", out)
self.assertIn("Replayed 2 archived verdicts of claude-opus-5-5 projects offline, without sending anything to an outside service. The archive gives them as 1 finished, 1 interrupt.", out)
self.assertIn("\"?\" rule, on the whole archive: decided 2 of 2: finished 2 (of these, archived interrupt 1). Missed interrupts: 1.", out)
folder = self.home / ".claude" / "loop-claude-transcripts" / "replays" / "judge-replay-claude-opus-5-5-offline-20260921T141320Z"
self.assertEqual((folder / "result.md").read_text(encoding="utf-8"), out)
+22 -14
View File
@@ -7,7 +7,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from transcript_archive.outcomes import ANSWERED, FINISHED, INTERRUPTED, UNFINISHED
from claude_code.entries import AssistantTurn, HumanTurn, Text, ToolCall
from judge_replay.offline import classifier, decision_table, evaluate, final_message, folds_of, METHODS, offline_report, question_mark, Sample
from judge_replay.offline import classifier, decision_table, evaluate, final_message, folds_of, LEARNERS, offline_report, question_mark, RULES, Sample
def turn(*parts):
@@ -56,12 +56,12 @@ class Classifier(unittest.TestCase):
done = [sample(FINISHED, f"merged pull request {n} and removed the worktree, no findings left") for n in range(12)]
return classifier([*asking, *done, *extra])
def test_decides_a_message_like_each_kind_it_learned_and_nothing_else(self):
def test_decides_a_message_like_each_kind_it_learned(self):
decide = self.trained()
self.assertEqual(decide("I recommend option 3; tell me which you want"), INTERRUPTED)
self.assertEqual(decide("merged pull request 99 and removed the worktree, no findings left"), FINISHED)
def test_abstains_on_every_message_where_it_learned_no_interrupt_or_no_other_kind(self):
def test_abstains_where_it_learned_no_interrupt_or_no_other_kind(self):
self.assertIsNone(classifier([sample(FINISHED, "merged")])("merged"))
self.assertIsNone(classifier([sample(INTERRUPTED, "which?")])("which?"))
self.assertIsNone(classifier([])("anything"))
@@ -91,25 +91,33 @@ class Report(unittest.TestCase):
def samples(self):
return [sample(FINISHED, "Merged."), sample(FINISHED, "Merged. Release 1.0.0 is ready to cut."), sample(INTERRUPTED, "I recommend merging."), sample(INTERRUPTED, "Merged.")]
def test_names_each_method_and_counts_what_it_decided_and_missed_by_kind(self):
text = offline_report("claude-opus-5-5", self.samples(), {"decision table": decision_table})
self.assertIn("Replayed 4 archived verdicts of claude-opus-5-5 projects offline, nothing sent to an outside service: 2 finished, 2 interrupt.", text)
self.assertIn("decision table, on held-out folds: decided 3 of 4: finished 2 (archived interrupt 1), interrupt 1. Missed interrupts: 1.", text)
self.assertIn("does not decide finished with no missed interrupt", text)
def test_counts_what_a_rule_decided_on_the_whole_archive_and_missed_by_kind(self):
text = offline_report("claude-opus-5-5", self.samples(), {"decision table": decision_table}, {})
self.assertIn("Replayed 4 archived verdicts of claude-opus-5-5 projects offline, without sending anything to an outside service. The archive gives them as 2 finished, 2 interrupt.", text)
self.assertIn("decision table, on the whole archive: decided 3 of 4: finished 2 (of these, archived interrupt 1), interrupt 1. Missed interrupts: 1.", text)
self.assertIn("decision table, on the whole archive, does not decide finished with no missed interrupt: it decided 1 archived interrupt(s) as finished.", text)
def test_says_a_method_that_decided_a_kind_and_missed_no_interrupt_decides_that_kind(self):
text = offline_report("claude-opus-5-5", [sample(FINISHED, "Merged."), sample(INTERRUPTED, "I recommend merging.")], {"decision table": decision_table})
text = offline_report("claude-opus-5-5", [sample(FINISHED, "Merged."), sample(INTERRUPTED, "I recommend merging.")], {"decision table": decision_table}, {})
self.assertIn("Missed interrupts: 0.", text)
self.assertIn("decides finished with no missed interrupt: 1 of 1 finished", text)
self.assertIn("decision table, on the whole archive, decides finished with no missed interrupt: 1 of 1 finished.", text)
def test_runs_a_method_that_learns_once_for_each_fold_and_once_on_the_latest_fifth(self):
def test_runs_a_learner_once_for_each_fold_and_once_on_the_latest_fifth_and_a_rule_only_on_the_whole_archive(self):
samples = [sample(INTERRUPTED if n % 2 else FINISHED, "I recommend it" if n % 2 else "merged it") for n in range(20)]
text = offline_report("m", samples, {"classifier": classifier}, folds=4)
text = offline_report("m", samples, {"rule": question_mark}, {"classifier": classifier}, folds=4)
self.assertIn("classifier, on held-out folds: decided", text)
self.assertIn("classifier, on the latest fifth after learning from the rest: decided", text)
self.assertIn("rule, on the whole archive: decided 20 of 20", text)
self.assertNotIn("rule, on held-out", text)
self.assertNotIn("rule, on the latest fifth", text)
def test_the_shipped_methods_are_the_one_rule_the_table_and_the_classifier(self):
self.assertEqual(list(METHODS), ["a question mark", "decision table", "classifier"])
def test_counts_the_verdicts_it_skipped_only_where_it_skipped_some(self):
self.assertNotIn("Skipped", offline_report("m", self.samples(), {}, {}))
self.assertIn("Skipped 2 verdicts whose transcript could not be read.", offline_report("m", self.samples(), {}, {}, skipped=2))
def test_the_shipped_methods_are_the_question_mark_rule_the_table_and_the_classifier(self):
self.assertEqual(list(RULES), ['"?" rule', "decision table"])
self.assertEqual(list(LEARNERS), ["classifier"])
if __name__ == "__main__":