Replay the archived judge verdicts offline through code rules and a classifier trained on the archive
CI / tests (pull_request) Failing after 5m8s

This commit is contained in:
2026-11-17 09:37:40 +01:00
parent 641645c081
commit 155a65117c
7 changed files with 352 additions and 5 deletions
+28 -3
View File
@@ -1,6 +1,6 @@
"""Replay loop-claude's judge on archived verdicts, to find the lowest rung that returns them: docs/decisions.md → `routing: on a model judge-replay covered`.
usage: judge-replay <model>
usage: judge-replay <model> [--offline]
<model> is a project model on the routing ladder this setup ships, such as claude-opus-5-5. The tool replays the
verdicts archived for the projects that ~/.claude/loop-claude-models.json runs on it: the latest
@@ -32,12 +32,18 @@ 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.
"""
import pathlib
import sys
import typing
from transcript_archive.location import archive_root, transcript_of
@@ -45,6 +51,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.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
@@ -61,7 +68,8 @@ from claude_code.transcript import read_transcript
from loop_claude.verdicts import Verdict
TOOL = "judge-replay"
USAGE = f"{TOOL} <model>, a model on the routing ladder"
USAGE = f"{TOOL} <model> [--offline], 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.
REFERENCE_EFFORT = "xhigh"
@@ -72,7 +80,7 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
ladder = read_ladder(SHIPPED)
if isinstance(ladder, Failure):
return failed(TOOL, ladder.reason)
project = arguments_or_exit(TOOL, argv, __doc__, USAGE, lambda argv: model_argument(ladder, argv))
project = arguments_or_exit(TOOL, argv, __doc__, USAGE, lambda argv: model_argument(ladder, [arg for arg in argv if arg != OFFLINE]))
if isinstance(project, int):
return project
cases = archived_cases(project.rung.model, archive_root(home, env), home)
@@ -80,6 +88,8 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
return failed(TOOL, cases.reason)
if not cases:
return failed(TOOL, f"no archived verdicts of projects on {project.rung.model} in {archive_root(home, env)}; run loop-claude on a project on that model first")
if OFFLINE in argv:
return offline(project.rung.model, argv, cases, archive_root(home, env), effects)
cases = sample(cases, PER_KIND)
folder = replay_folder(archive_root(home, env), TOOL, argv, effects.now())
effects = archiving(effects, folder)
@@ -92,6 +102,21 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
return 0
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 = []
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):
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))
return 0
def model_argument(ladder: Ladder, argv: list[str]) -> ProjectRung | None:
"""The project's rung on ladder of the one model argv names; None for any other argv."""
return ladder.project_rung(argv[0]) if len(argv) == 1 else None