Answer stability round 1: 0 🔴, 6 🟡; name no rung without evidence, test the prompt's task, premises and records and the replay's edges, and name a copy and its outcomes file in one module

This commit is contained in:
2026-10-15 09:16:11 +02:00
parent 5d49c24397
commit 015e39ae97
13 changed files with 94 additions and 36 deletions
+10 -4
View File
@@ -13,19 +13,22 @@ ran before it was routed. A verdict the reference judge returns another kind on
records and judge rules of its day, so no rung is held to it. It then replays the rest on each rung
from the one the lowest R + C picks up to the model's cheapest rung, cheapest first, and stops at
the first rung that returns all of them. It prints each verdict a rung missed, and the cheapest
rung that missed none.
rung that missed none. A rung it names is the evidence to add the model to JUDGE_REPLAYED in
bin/loop_claude/routing.py, which routes that model's judge, and to record the run in
docs/decisions.md → `routing:`.
Like the loop, it tries a judge three times running before it counts the reply as failed. A
verdict whose project or transcript cannot be read replays as failed too. Exit 1, saying why, on
bad arguments, an unreadable archive or models file, or a usage limit.
bad arguments, an unreadable archive or models file, no archived verdict of the model's projects,
or a usage limit.
"""
import concurrent.futures
import pathlib
import sys
import typing
from transcript_archive.location import archive_root
from transcript_archive.read import archived_outcomes, transcript_of
from transcript_archive.location import archive_root, transcript_of
from transcript_archive.read import archived_outcomes
from judge_replay.replay import Case, case_from, Kind, replayed, report, sample, verdict_kind
from project_key import checkout_of
from loop_claude.effects import Effects
@@ -60,6 +63,9 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
if isinstance(cases, Failure):
print(f"judge-replay: {cases.reason}", file=sys.stderr)
return 1
if not cases:
print(f"judge-replay: no archived verdicts of projects on {argv[0]} in {archive_root(home, env)}; run loop-claude on one first", file=sys.stderr)
return 1
cases = sample(cases, PER_KIND)
reference = Rung(argv[0], REFERENCE_EFFORT)
candidates = list(LADDER[position(picked(anchor, LOWEST_R_PLUS_C)):position(anchor) + 1])
+11 -4
View File
@@ -40,7 +40,10 @@ class Replay:
def case_from(root: str, outcomes: str, transcript: pathlib.Path) -> Case | None:
"""The first verdict an outcomes file holds: the judge ruled on the transcript copy beside it as the copy stands. None when it holds none."""
"""The first verdict an outcomes file holds: the judge ruled on the transcript copy beside it as the copy stands. None when it holds none.
A quoted answer past the cycle's cap is archived as the interrupt it became, so the reference judge's quoted answer sets it aside, holding no rung to it.
"""
task, verdict = task_of(outcomes), first_verdict(outcomes)
if task is None or verdict is None:
return None
@@ -84,8 +87,9 @@ def replayed(cases: list[Case], reference: Rung, candidates: list[Rung], rule_al
return ruled
reproduced = [found for found, kind in zip(cases, ruled) if kind == found.on_record]
unreproduced = [(found, kind) for found, kind in zip(cases, ruled) if kind != found.on_record]
tried = []
for rung in candidates:
tried: list[Tried] = []
# With no verdict to hold a rung to, every rung would miss none.
for rung in candidates if reproduced else []:
ruled = rule_all(reproduced, rung)
if isinstance(ruled, Limited):
return ruled
@@ -104,7 +108,10 @@ def report(model: str, reference: Rung, cases: list[Case], replay: Replay) -> st
]
for tried in replay.tried:
lines += [f"{tried.rung} missed {len(tried.missed)}{':' if tried.missed else '.'}", *missed_lines(tried.missed)]
lines.append(f"Cheapest rung that returns every verdict the reference judge reproduces: {replay.cheapest or 'none up to the project rung'}")
if not replay.tried:
lines.append("No rung tried: the reference judge reproduced no verdict to hold one to.")
else:
lines.append(f"Cheapest rung that returns every verdict the reference judge reproduces: {replay.cheapest or 'none up to the project rung'}")
return "\n".join(lines)
+41 -9
View File
@@ -74,8 +74,13 @@ class Replayed(unittest.TestCase):
self.assertEqual(asked, [(3, REFERENCE), (2, CHEAP), (2, MIDDLE)])
def test_names_no_rung_when_every_candidate_misses_a_verdict(self):
replay = replayed([case("2026-10-14T10:00:00Z", FINISHED)], REFERENCE, [CHEAP], lambda on, rung: [FINISHED] if rung == REFERENCE else [INTERRUPTED])
self.assertIsNone(replay.cheapest)
cases = [case("2026-10-14T10:00:00Z", FINISHED)]
replay = replayed(cases, REFERENCE, [CHEAP], lambda on, rung: [FINISHED] if rung == REFERENCE else [INTERRUPTED])
self.assertEqual(replay, Replay([], [Tried(CHEAP, [(cases[0], INTERRUPTED)])], None))
def test_tries_no_rung_when_the_reference_reproduces_no_verdict(self):
cases = [case("2026-10-14T10:00:00Z", FINISHED)]
self.assertEqual(replayed(cases, REFERENCE, [CHEAP], lambda on, rung: [INTERRUPTED] * len(on)), Replay([(cases[0], INTERRUPTED)], [], None))
def test_stops_at_a_usage_limit(self):
limit = Limited(None, "limit")
@@ -96,7 +101,10 @@ class Report(unittest.TestCase):
"claude-sonnet-5-5 at high effort missed 0.",
"Cheapest rung that returns every verdict the reference judge reproduces: claude-sonnet-5-5 at high effort",
])
self.assertTrue(report("claude-opus-5-5", REFERENCE, cases, Replay([], [Tried(CHEAP, [(cases[1], FINISHED)])], None)).endswith(": none up to the project rung"))
missed_all = report("claude-opus-5-5", REFERENCE, cases, Replay([], [Tried(CHEAP, [(cases[1], FINISHED)])], None)).splitlines()
self.assertEqual(missed_all[1], "The reference judge, claude-opus-5-5 at xhigh effort, reproduced 2.")
self.assertEqual(missed_all[-1], "Cheapest rung that returns every verdict the reference judge reproduces: none up to the project rung")
self.assertEqual(report("claude-opus-5-5", REFERENCE, cases, Replay([(cases[0], UNFINISHED), (cases[1], FINISHED)], [], None)).splitlines()[-1], "No rung tried: the reference judge reproduced no verdict to hold one to.")
def unused(*_):
@@ -110,6 +118,7 @@ class Main(unittest.TestCase):
self.home = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
(self.home / ".claude").mkdir()
(self.home / ".claude" / "loop-claude-models.json").write_text(json.dumps({"proj": "claude-opus-5-5", "other": "claude-sonnet-5-5"}))
(self.home / ".claude" / "CLAUDE.md").write_text("Be kind.\n")
for key, verdicts in (("proj", (FINISHED, INTERRUPTED)), ("other", (FINISHED,))):
(self.home / "code" / key).mkdir(parents=True)
(self.home / "code" / key / "README.md").write_text("# p\n\n## Goals\n\n1. Ship.\n\n## Audience\n\nMe.\n")
@@ -119,11 +128,13 @@ class Main(unittest.TestCase):
(chunk / f"t{n}.jsonl").write_text(json.dumps({"type": "assistant", "message": {"content": [{"type": "text", "text": f"said {verdict}"}]}}) + "\n")
(chunk / f"t{n}.outcomes.md").write_text(f"Task: Do it.\n\n2026-10-14T10:00:0{n}Z {verdict}\n\nEvidence:\n> e\n")
self.calls = []
self.prompts = []
def run_main(self, argv, reply):
def claude(args, cwd, prompt):
self.calls.append((args[args.index("--model") + 1], args[args.index("--effort") + 1], cwd))
result = reply(args[args.index("--model") + 1], "said Verdict: interrupt" in prompt.rsplit("latest last:", 1)[-1])
self.prompts.append(prompt)
result = reply(Rung(args[args.index("--model") + 1], args[args.index("--effort") + 1]), "said Verdict: interrupt" in prompt.rsplit("latest last:", 1)[-1])
return subprocess.CompletedProcess(args, 0, json.dumps(result), "")
effects = Effects(claude=claude, claude_on_terminal=unused, execv=unused, git=unused, input=unused, local_time=unused, now=unused, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused)
@@ -139,8 +150,8 @@ class Main(unittest.TestCase):
def test_replays_the_models_projects_on_the_reference_then_cheapest_first_and_prints_the_rung_that_returns_all(self):
# Haiku misses the interrupt; Sonnet returns both.
def reply(model, interrupted):
return self.verdict(interrupted and model != "claude-haiku-5-5", f"said {INTERRUPTED if interrupted else FINISHED}")
def reply(rung, interrupted):
return self.verdict(interrupted and rung.model != "claude-haiku-5-5", f"said {INTERRUPTED if interrupted else FINISHED}")
code, out, err = self.run_main(["claude-opus-5-5"], reply)
self.assertEqual(code, 0, err)
@@ -148,10 +159,24 @@ class Main(unittest.TestCase):
self.assertEqual([(model, effort) for model, effort, _ in self.calls[::2]], [("claude-opus-5-5", "xhigh"), ("claude-haiku-5-5", "xhigh"), ("claude-haiku-5-5", "max"), ("claude-sonnet-5-5", "high")])
self.assertIn("The reference judge, claude-opus-5-5 at xhigh effort, reproduced 2.", out)
self.assertTrue(out.endswith("returns every verdict the reference judge reproduces: claude-sonnet-5-5 at high effort\n"))
for said in ("The task an agent was given:\nDo it.", "1. Ship.", "From ~/.claude/CLAUDE.md:\nBe kind."):
self.assertIn(said, self.prompts[0])
def test_tries_rungs_up_to_the_models_cheapest_and_names_none_when_all_miss(self):
code, out, _ = self.run_main(["claude-opus-5-5"], lambda rung, interrupted: self.verdict(interrupted and rung == REFERENCE, f"said {INTERRUPTED if interrupted else FINISHED}"))
self.assertEqual(code, 0)
self.assertEqual(self.calls[-1][:2], ("claude-opus-5-5", "medium"))
self.assertTrue(out.endswith(": none up to the project rung\n"))
def test_replays_a_verdict_whose_transcript_is_gone_as_failed(self):
(self.home / ".claude" / "loop-claude-transcripts" / "proj" / "c1" / "t0.jsonl").unlink()
code, out, _ = self.run_main(["claude-opus-5-5"], lambda rung, interrupted: self.verdict(interrupted, f"said {INTERRUPTED}"))
self.assertEqual(code, 0)
self.assertIn("replayed failed: could not read the transcript", out)
def test_tries_up_to_the_models_cheapest_rung_and_retries_a_failed_reply_as_the_loop_does(self):
def reply(model, interrupted):
return self.verdict(interrupted, "not in the transcript" if model != "claude-opus-5-5" else f"said {INTERRUPTED if interrupted else FINISHED}")
def reply(rung, interrupted):
return self.verdict(interrupted, "not in the transcript" if rung.model != "claude-opus-5-5" else f"said {INTERRUPTED if interrupted else FINISHED}")
code, out, _ = self.run_main(["claude-opus-5-5"], reply)
self.assertEqual(code, 0)
@@ -159,14 +184,21 @@ class Main(unittest.TestCase):
self.assertIn("claude-opus-5-5 at medium effort missed 0.", out)
def test_exits_1_on_a_usage_limit_bad_arguments_or_an_unreadable_models_file(self):
code, _, err = self.run_main(["claude-opus-5-5"], lambda model, interrupted: {"type": "result", "api_error_status": 429, "result": "You've hit your limit"})
code, _, err = self.run_main(["claude-opus-5-5"], lambda rung, interrupted: {"type": "result", "api_error_status": 429, "result": "You've hit your limit"})
self.assertEqual(code, 1)
self.assertIn("usage limit: You've hit your limit", err)
for argv in ([], ["off-ladder"], ["claude-opus-5-5", "x"]):
self.assertEqual(self.run_main(argv, unused)[0], 1)
code, _, err = self.run_main(["claude-haiku-5-5"], unused)
self.assertEqual(code, 1)
self.assertIn("no archived verdicts of projects on claude-haiku-5-5", err)
(self.home / ".claude" / "loop-claude-models.json").write_text("[")
self.assertEqual(self.run_main(["claude-opus-5-5"], unused)[0], 1)
def test_prints_the_help(self):
code, out, _ = self.run_main(["-h"], unused)
self.assertEqual((code, out.splitlines()[2]), (0, "usage: judge-replay <model>"))
def test_the_launcher_prints_the_help(self):
ran = subprocess.run([sys.executable, str(TOOL), "--help"], capture_output=True, text=True)
self.assertEqual(ran.returncode, 0)
+4 -3
View File
@@ -47,9 +47,10 @@ todo.md's top item in the next release, skipping an item marked question, picks
counts from the model's cheapest rung, and an R + C of 8 or less picks a rung below it; without
such an item, or with a C missing, the chunk runs on the model's cheapest rung. The worker's first
prompt names the rung and the item, and asks the worker to name each item the chunk takes, with its
R + C. On a model judge-replay has replayed, the judge runs on the rung that item's R + C picks from
the judge's model, never below that model's cheapest rung, whatever rung the worker steps to;
without such an item, on the cheapest rung. When the worker's rung is below the model's cheapest, the prompt also has the worker launch each
R + C. On a model listed in JUDGE_REPLAYED in bin/loop_claude/routing.py, which judge-replay found
returning every verdict on its cheapest rung, the judge runs on the rung that item's R + C picks from
the judge's model. It never runs below that model's cheapest rung, and keeps its rung when the
worker steps up or takes in another item; without such an item, it runs on the cheapest rung. When the worker's rung is below the model's cheapest, the prompt also has the worker launch each
reviewer, each comprehension seat and the security pass in subagents on the cheapest rung. When it
is above, the prompt has the worker launch only each comprehension seat and the security pass on
the cheapest rung. The prompt after each unfinished verdict
+4 -2
View File
@@ -29,12 +29,12 @@ def first_route(anchor: Rung, item: Item | None) -> Route:
def kept(route: Route, anchor: Rung) -> bool:
"""Whether a chunk keeps route: its rung is on the ladder at or above the rung its item's R + C picks from anchor, the project's rung, or anchor itself when no item routed it."""
"""Whether a chunk keeps route: its rung is on the ladder at or above item_rung."""
return highest(route.rung, item_rung(anchor, route)) == route.rung
def item_rung(anchor: Rung, route: Route) -> Rung:
"""The rung the route's item's R + C picks from anchor, the project's rung, or anchor itself when no item routed it."""
"""The rung the route's item's R + C picks from anchor, the project's rung, or anchor itself when no item routed it. The worker may run below anchor; judge_rung lifts it to anchor."""
return picked(anchor, route.risk_and_complexity) if route.item else anchor
@@ -51,6 +51,8 @@ def stepped(anchor: Rung, route: Route, bundled: int) -> Route:
def judge_rung(judge_model: str, route: Route) -> Rung:
"""The rung the route's item picks from the judge model's cheapest rung, never below that rung, whatever rung the worker stepped to.
An item the worker takes in moves the worker's rung but not the judge's, until todo.md item 136 routes the chunk on the item the worker takes.
A model judge-replay has not replayed runs alone, at its settings' effort, as does one off the ladder.
"""
anchor = project_rung(judge_model)
+2
View File
@@ -254,6 +254,8 @@ class Cycles(unittest.TestCase):
self.assertEqual(len(judge_prompts), 2)
self.assertNotIn("the second", judge_prompts[0])
self.assertIn("[human] the second", judge_prompts[1])
self.assertIn("From README.md:\n## Goals", judge_prompts[0])
self.assertIn("The task an agent was given:\nDo it.", judge_prompts[0])
def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self):
answered = judged("quoted", answer="Use *A*.")
+13
View File
@@ -5,6 +5,9 @@ import typing
from claude_code.transcript import first_timestamped_line
from project_key import project_key
# What an outcomes file's name ends with, in place of its transcript copy's .jsonl.
FILE_SUFFIX = ".outcomes.md"
def archive_root(home: pathlib.Path, env: typing.Mapping[str, str]) -> pathlib.Path:
"""Where loop-claude archives every project's chunks."""
@@ -18,3 +21,13 @@ def project_archive(checkout_root: str, home: pathlib.Path, env: typing.Mapping[
def chunk_folder(project_archive: pathlib.Path, transcript: bytes) -> pathlib.Path:
# Each chunk's first timestamped line is its own: a finished chunk's session is deleted, so the next chunk's transcript starts afresh.
return project_archive / hashlib.sha256(first_timestamped_line(transcript)).hexdigest()
def outcomes_of(copy: pathlib.Path) -> pathlib.Path:
"""The outcomes file beside a transcript copy; transcript_of is its inverse."""
return copy.with_suffix(FILE_SUFFIX)
def transcript_of(outcomes: pathlib.Path) -> pathlib.Path:
"""The transcript copy an outcomes file sits beside; outcomes_of is its inverse."""
return outcomes.with_name(outcomes.name.removesuffix(FILE_SUFFIX) + ".jsonl")
-2
View File
@@ -3,8 +3,6 @@ import re
from markdown_text import quoted
from utc_stamp import STAMPED
# What an outcomes file's name ends with, in place of its transcript copy's .jsonl.
FILE_SUFFIX = ".outcomes.md"
TASK = "Task: "
FINISHED = "Verdict: finished"
UNFINISHED = "Verdict: unfinished"
+2 -7
View File
@@ -1,9 +1,9 @@
import dataclasses
import pathlib
from transcript_archive.location import chunk_folder
from transcript_archive.location import chunk_folder, FILE_SUFFIX, transcript_of
from failure import Failure
from transcript_archive.outcomes import FILE_SUFFIX, FINISHED_AT, workers
from transcript_archive.outcomes import FINISHED_AT, workers
@dataclasses.dataclass(frozen=True)
@@ -41,11 +41,6 @@ def chunk_outcomes(folder: pathlib.Path) -> list[pathlib.Path]:
return sorted(folder.glob(f"*{FILE_SUFFIX}"))
def transcript_of(outcomes: pathlib.Path) -> pathlib.Path:
"""The transcript copy an outcomes file sits beside."""
return outcomes.with_name(outcomes.name.removesuffix(FILE_SUFFIX) + ".jsonl")
def read_threads(chunk: FinishedChunk) -> list[bytes] | Failure:
"""The worker's transcript, then each subagent's."""
try:
+3 -3
View File
@@ -3,11 +3,11 @@ import os
import pathlib
import sys
from transcript_archive.location import chunk_folder
from transcript_archive.location import chunk_folder, outcomes_of
from failure import Failure
from transcript_archive.outcomes import FILE_SUFFIX, TASK
from file_writes import make_private, replace_file
from claude_code.session import session_files
from transcript_archive.outcomes import TASK
from utc_stamp import utc
@@ -23,7 +23,7 @@ def archive(project_archive: pathlib.Path, path: str, task: str, outcome: str, a
if sibling != path and (unkept := mirror(pathlib.Path(sibling), folder / "session" / os.path.basename(sibling))):
return unkept
copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl"
outcomes = copy.with_suffix(FILE_SUFFIX)
outcomes = outcomes_of(copy)
stamped = f"{utc(at)} {outcome}"
if copy.exists() and outcomes.exists():
return add_outcome(outcomes, stamped)