Compare commits

...

10 Commits

Author SHA1 Message Date
lilleman 2556fdace9 Answer prose round 1: 0 🔴, 7 🟡 (0 misread); the decision's scope, the changelog bullet and the prompts read once
CI / tests (pull_request) Successful in 2m30s
2026-11-12 05:30:15 +01:00
lilleman 6817b074bd Answer stability round 1: 0 🔴, 6 🟡 (0 misread); the bench tests only the packages the clone holds, refuses a run that ended in an error, and pins a worker's committed change 2026-11-12 05:30:15 +01:00
lilleman 46436f2ee0 Answer security round 1: 0 🔴, 0 🟡 (0 misread); the bench's worker runs on this repo's own archived commits only 2026-11-12 05:21:37 +01:00
lilleman e1e99645be Pin the advisor bench's argv, kwargs, diff exclusions and failures in its tests 2026-11-12 05:20:39 +01:00
lilleman 45fd66d3ab Test the advisor bench's run, grade, main and rows_of against a throwaway repo, and kill the mutants of its pure functions 2026-11-12 05:18:44 +01:00
lilleman 66b9651d68 Bench the advisor tool on six archived L 1 and L 2 chunks: Sonnet alone passes as often as Opus at medium for less, so workers stay without it
CI / tests (pull_request) Successful in 2m18s
2026-11-12 04:27:48 +01:00
lilleman 7a7dc4b75d Answer prose round 1: 0 🔴, 6 🟡 (0 misread); the decision's judge rule stated once, in the present tense
CI / tests (pull_request) Successful in 2m34s
2026-11-12 03:08:01 +01:00
lilleman 39a8a57b76 Answer stability round 1: 0 🔴, 1 🟡 (0 misread); the taken-in E + I no longer routes the judge 2026-11-12 03:08:01 +01:00
lilleman 58517a0c54 Pick the judge's highest rung with highest()
CI / tests (pull_request) Successful in 2m33s
2026-11-12 02:59:50 +01:00
lilleman c61997f7b7 Run the judge of an Opus 5.5 project on Opus 5.5 at xhigh in every chunk
CI / tests (pull_request) Successful in 2m35s
2026-11-12 02:54:03 +01:00
16 changed files with 625 additions and 58 deletions
+4
View File
@@ -144,11 +144,15 @@
!skills/larv-review/standards/
!skills/larv-review/standards/*.md
!workflow-bench/
!workflow-bench/advisor-judge-prompt.md
!workflow-bench/advisor-run-prompt.md
!workflow-bench/advisor_bench.py
!workflow-bench/bench.py
!workflow-bench/compare-prompt.md
!workflow-bench/compare.py
!workflow-bench/review_git.py
!workflow-bench/run-prompt.md
!workflow-bench/setup.cfg
!workflow-bench/test_advisor_bench.py
!workflow-bench/test_bench.py
!workflow-bench/test_review_git.py
+2 -1
View File
@@ -2,7 +2,8 @@
## Unreleased
- loop-claude no longer runs the judge of an Opus 5.5 project on Fable 5.2: from an E + I of 5 the judge runs on Opus 5.5 at xhigh, since a replay found each Fable 5.2 rung it tried, at low, medium and high, missing an interrupt. `judge-replay` now also replays each rung above the project's that a review climbs to, and reports what each misses.
- Add `workflow-bench/advisor_bench.py`, a bench of the advisor tool on six archived L 1 and L 2 chunks. Sonnet 5.5 alone passed all six, as Opus 5.5 at medium did, for 41% less, and its advisor ran in one of six runs, so workers stay without it.
- loop-claude's judge on an Opus 5.5 project now runs on Opus 5.5 at xhigh in every chunk, never at medium: in replays medium sometimes closed a chunk whose worker had asked a question the README or records answer, where xhigh quoted the answer. The judge never runs on Fable 5.2 either, since each Fable 5.2 rung replayed missed an interrupt. `judge-replay` now also replays each rung above the project's that a review climbs to, and reports what each misses.
## 0.8.0
+1 -1
View File
@@ -1,6 +1,6 @@
# Claude Code configuration
My personal `~/.claude`, version controlled: `CLAUDE.md` and `rules/` for instructions, the words under `CLAUDE.md` → "Vocabulary"; `.claude/rules/` for the rules that load in this repo alone; `agents/` and `skills/`; `principles/` and `skills/larv-review/standards/` for what the reviewer agents hold projects to; `docs/` for decisions and the comprehension history; `settings.json` for the harness and `.claude/settings.json` for the harness inside this repo; `CHANGELOG.md` and `todo.md`; the tools in `bin/`; `workflow-bench/`, the scripts and prompts of the 2026-09-30 bench of larv-review; `reviewer-merge-trials/`, the 2026-11-09 trials of merging reviewers, with their method, results and scripts; `judge-field-trials/`, the 2026-11-11 trials of which facts code could read in place of loop-claude's judge, with their results and scripts; and `presentation/`, a page that explains this setup to newcomers, with the script that prints it to PDF.
My personal `~/.claude`, version controlled: `CLAUDE.md` and `rules/` for instructions, the words under `CLAUDE.md` → "Vocabulary"; `.claude/rules/` for the rules that load in this repo alone; `agents/` and `skills/`; `principles/` and `skills/larv-review/standards/` for what the reviewer agents hold projects to; `docs/` for decisions and the comprehension history; `settings.json` for the harness and `.claude/settings.json` for the harness inside this repo; `CHANGELOG.md` and `todo.md`; the tools in `bin/`; `workflow-bench/`, the scripts and prompts of the 2026-09-30 bench of larv-review and of the 2026-11-12 bench of the advisor tool; `reviewer-merge-trials/`, the 2026-11-09 trials of merging reviewers, with their method, results and scripts; `judge-field-trials/`, the 2026-11-11 trials of which facts code could read in place of loop-claude's judge, with their results and scripts; and `presentation/`, a page that explains this setup to newcomers, with the script that prints it to PDF.
## Goals
+1 -1
View File
@@ -100,7 +100,7 @@ def archived(project_archive: pathlib.Path, transcript_path: str, task: str, out
def judge_of(cycle: Cycle) -> Rung:
"""The judge's rung, which the archive names beside each verdict."""
return judge_rung(cycle.judge_model, cycle.route)
return judge_rung(cycle.judge_model)
def step(cycle: Cycle, state: Active) -> Event | Stop:
+5 -11
View File
@@ -10,7 +10,7 @@ The worker, and the session /talk opens, run on a Route (model_routing/route.py)
import dataclasses
from release_plan.release_standing import chunk_item, LastCut, Next
from model_routing.ladder import climbed, highest, LADDER, position, project_rung, review_floor, Rung, stepped_up, worker_rung
from model_routing.ladder import climbed, highest, LADDER, position, project_rung, Rung, stepped_up, worker_rung
from loop_claude import escalation_mark
from failure import Failure
from loop_claude.verdicts import Interrupt, QuotedAnswer, Unfinished
@@ -137,14 +137,8 @@ def one_rung_up(route: Route, rung: Rung, escalated_at: int) -> Route:
return dataclasses.replace(route, rung=stepped_up(rung), unfinished=0, escalated_at=escalated_at)
def judge_rung(judge_model: str, route: Route) -> Rung:
"""The lowest of the judge model's own rungs at or above the rung a review gets from the route's reviewed_on E + I, counted from the model's cheapest rung. Where that review rung is above all the model's rungs, the model's highest. The worker's rung doesn't change it.
The judge keeps to its model's rungs, since every Fable 5.2 rung judge-replay tried missed an interrupt: docs/decisions.md → `routing: on a model judge-replay covered`. A model off the ladder, or not in JUDGE_REPLAYED, gets no effort flag, so claude runs it at the effort its settings give.
"""
cheapest = project_rung(judge_model)
if cheapest is None or judge_model not in JUDGE_REPLAYED:
def judge_rung(judge_model: str) -> Rung:
"""The highest of the judge model's own rungs: docs/decisions.md → `routing: on a model judge-replay covered`. A model off the ladder, or not in JUDGE_REPLAYED, gets no effort flag, so claude runs it at the effort its settings give."""
if project_rung(judge_model) is None or judge_model not in JUDGE_REPLAYED:
return Rung(judge_model)
floor = position(review_floor(cheapest, route.reviewed_on()))
own = [rung for rung in LADDER if rung.model == judge_model]
return next((rung for rung in own if position(rung) >= floor), own[-1])
return highest(*(rung for rung in LADDER if rung.model == judge_model))
+6 -6
View File
@@ -137,7 +137,7 @@ PREMISES = "# Project\n\n## Goals\n\n1. Work.\n\n## Audience\n\nMe.\n"
TODO = "## Items\n\n| ID | Release | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n| 4 | 0.1.0 | | **Do it.** | 4 | 2 | 3 | 7 | 2 | 1 by 9 | 25 |\n"
# Item 4's L of 2 steps one rung down.
CHEAP = TODO.replace("| 4 | 2 | 3 | 7 |", "| 2 | 1 | 2 | 3 |")
# Item 9 follows CHEAP's item 4, and a worker routed by item 4 may take it in: at L 4 it picks a higher rung for the worker, and at E + I 6 for the judge and the reviewers. At E + I 3, or at L 2, it picks the rung item 4 picks.
# Item 9 follows CHEAP's item 4, and a worker routed by item 4 may take it in: at L 4 it picks a higher rung for the worker, and at E + I 6 for the reviewers. At E + I 3, or at L 2, it picks the rung item 4 picks.
TAKEN_IN_AT_L_4 = CHEAP + "| 9 | 0.1.0 | | **Do more.** | 4 | 1 | 2 | 5 | 2 | 1 by 9 | 20 |\n"
TAKEN_IN_AT_E_PLUS_I_6 = CHEAP + "| 9 | 0.1.0 | | **Do more.** | 2 | 3 | 3 | 6 | 2 | 1 by 9 | 20 |\n"
@@ -528,7 +528,7 @@ class Cycles(unittest.TestCase):
self.assertNotIn("at max effort", "".join(outcomes))
self.assertIn('Verdict: interrupt\n\nA or B?\n\nEvidence:\n> Shall I use A or B?\n\nEscalation:\n> Stability round 2: a 🔴.\n\nJudge: judge-model\nWorker: {"model": "claude-fable-5-2", "effort": "low", "item": 4, "likelihood": 4, "escape_and_impact": 5}\n\n<UTC> Stepped up\n\nWorker: {"model": "claude-fable-5-2", "effort": "medium", "item": 4, "likelihood": 4, "escape_and_impact": 5, "escalated_at": 4}\n', "".join(outcomes))
def test_runs_a_cheap_items_worker_below_the_projects_rung_with_its_reviewers_and_judge_on_it(self):
def test_runs_a_cheap_items_worker_below_the_projects_rung_with_its_reviewers_on_it_and_its_judge_on_the_models_highest(self):
checkout = Checkout(self)
checkout.env["LOOP_CLAUDE_WORKER_MODEL"] = checkout.env["LOOP_CLAUDE_JUDGE_MODEL"] = "claude-opus-5-5"
checkout.commit_plan(CHEAP)
@@ -537,11 +537,11 @@ class Cycles(unittest.TestCase):
first = next(call for call in run.calls if call["role"] == "worker")
self.assertEqual((argument(first, "--model"), argument(first, "--effort")), ("claude-sonnet-5-5", "high"))
ruling = next(call for call in run.calls if call["role"] == "judge")
self.assertEqual((argument(ruling, "--model"), argument(ruling, "--effort")), ("claude-opus-5-5", "medium"))
self.assertIn('Judge: claude-opus-5-5 at medium effort\nWorker: {"model": "claude-sonnet-5-5", "effort": "high", ', "".join(checkout.archived().values()))
self.assertEqual((argument(ruling, "--model"), argument(ruling, "--effort")), ("claude-opus-5-5", "xhigh"))
self.assertIn('Judge: claude-opus-5-5 at xhigh effort\nWorker: {"model": "claude-sonnet-5-5", "effort": "high", ', "".join(checkout.archived().values()))
self.assertIn("Launch each reviewer, each comprehension seat and the security pass's subagent with the Agent tool set to model opus, effort medium, the project's rung.", argument(first, "-p"))
def test_routes_the_judge_and_the_reviewers_on_the_highest_e_plus_i_the_worker_takes_in(self):
def test_routes_the_reviewers_on_the_highest_e_plus_i_the_worker_takes_in_and_keeps_the_judge_on_the_models_highest(self):
checkout = Checkout(self)
checkout.env["LOOP_CLAUDE_WORKER_MODEL"] = checkout.env["LOOP_CLAUDE_JUDGE_MODEL"] = "claude-opus-5-5"
checkout.commit_plan(TAKEN_IN_AT_E_PLUS_I_6)
@@ -551,7 +551,7 @@ class Cycles(unittest.TestCase):
worker(say="next chunk"),
])
self.assertEqual(run.code, 130)
self.assertEqual([(argument(call, "--model"), argument(call, "--effort")) for call in run.calls if call["role"] == "judge"], [("claude-opus-5-5", "medium"), ("claude-opus-5-5", "xhigh"), ("claude-opus-5-5", "medium")])
self.assertEqual([(argument(call, "--model"), argument(call, "--effort")) for call in run.calls if call["role"] == "judge"], [("claude-opus-5-5", "xhigh")] * 3)
workers = [call for call in run.calls if call["role"] == "worker"]
self.assertEqual({argument(call, "--effort") for call in workers}, {"high"})
self.assertIn("Launch each reviewer with the Agent tool set to model fable, effort medium, the rung picked by an item of E + I 6 taken into the chunk.", argument(workers[1], "-p"))
+5 -15
View File
@@ -1133,21 +1133,11 @@ class Routing(unittest.TestCase):
self.assertEqual(routing.next_route(self.OPUS, Route(Rung("claude-opus-5-5", "low")), unfinished()).rung, self.OPUS)
self.assertEqual(routing.next_route(self.OPUS, Route(Rung("claude-opus-5-5", "low")), unfinished(2)).rung, self.OPUS)
def test_runs_the_judge_on_the_lowest_rung_of_its_model_at_or_above_the_one_its_chunks_items_e_plus_i_picks_never_below_the_projects(self):
# E + I 5 and 6 pick Fable 5.2 at low and medium, so the judge runs on Opus 5.5 at xhigh, its model's next rung up.
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, 3, 3, 5)), self.THREE_UP)
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.TWO_UP, 3, 3, 6)), self.THREE_UP)
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.SONNET, 3, 3, 7)), self.THREE_UP)
# E + I 8 picks Fable 5.2 at high, above every Opus 5.5 rung, so the judge runs on Opus 5.5's highest.
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, 3, 3, 8)), self.THREE_UP)
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(Rung("claude-haiku-5-5", "max"), 3, 3, 4)), self.OPUS)
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.ONE_UP)), self.OPUS)
self.assertEqual(routing.judge_rung("judge-model", Route(self.ONE_UP, 3, 3, 5)), Rung("judge-model"))
self.assertEqual(routing.judge_rung("claude-sonnet-5-5", Route(self.ONE_UP, 3, 3, 5)), Rung("claude-sonnet-5-5"))
def test_runs_the_judge_on_the_rung_the_highest_e_plus_i_taken_in_picks(self):
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6)), self.THREE_UP)
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, 3, 3, 4)), self.OPUS)
def test_runs_the_judge_of_a_replayed_model_on_its_models_highest_rung(self):
self.assertEqual(routing.judge_rung("claude-opus-5-5"), self.THREE_UP)
# A model off the ladder, or not replayed, gets no effort flag.
self.assertEqual(routing.judge_rung("judge-model"), Rung("judge-model"))
self.assertEqual(routing.judge_rung("claude-sonnet-5-5"), Rung("claude-sonnet-5-5"))
def test_refuses_a_route_whose_item_has_levels_off_their_scales_or_levels_without_an_item(self):
for item, likelihood, escape_and_impact in ((3, 0, 5), (3, 5, 5), (3, 4, 1), (3, 4, 9), (0, 4, 5), (0, 4, 0), (0, 0, 5)):
+1 -1
View File
@@ -9,7 +9,7 @@ class TakenIn:
items: tuple[int, ...] = ()
# The highest L among them, 0 for none: an escalation steps up from the rung that L picks, and an unfinished verdict also raises the worker to it.
highest_likelihood: int = 0
# The highest E + I among them, 0 for none: after an unfinished verdict, it routes the next cycle's judge and reviewers.
# The highest E + I among them, 0 for none: after an unfinished verdict, it routes the next cycle's reviewers.
highest_escape_and_impact: int = 0
+2 -2
View File
@@ -33,7 +33,7 @@ def levels_fit(item: int, likelihood: int, escape_and_impact: int, escape_and_im
@dataclasses.dataclass(frozen=True)
class Route:
"""A chunk's worker rung and the plan item that picked it, 0 for none. The item's L picked the worker's rung; reviewed_on, the higher of its E + I and the highest E + I the worker took in, picks the reviewers' and the judge's. A route holds only levels that levels_fit, so no rung is picked from a level off its scale.
"""A chunk's worker rung and the plan item that picked it, 0 for none. The item's L picked the worker's rung; reviewed_on, the higher of its E + I and the highest E + I the worker took in, picks the reviewers'. A route holds only levels that levels_fit, so no rung is picked from a level off its scale.
unfinished counts the unfinished verdicts towards the next one-rung step; a reload hands it over with the rung.
"""
@@ -63,7 +63,7 @@ class Route:
return dataclasses.replace(self, escape_and_impact_taken_in=escape_and_impact) if REVIEW_STEPS.get(escape_and_impact, 0) > REVIEW_STEPS.get(self.reviewed_on(), 0) else self
def reviewed_on(self) -> int:
"""The E + I that picks the reviewers' and the judge's rung: the routed item's or the highest taken in, whichever is higher; 0 for neither."""
"""The E + I that picks the reviewers' rung: the routed item's or the highest taken in, whichever is higher; 0 for neither."""
return max(self.escape_and_impact, self.escape_and_impact_taken_in)
def worker_line(self) -> WorkerLine:
+22 -6
View File
@@ -416,6 +416,20 @@ loop-claude's prompt names the rungs a trigger opens, so the worker computes no
Valid while the ladder orders its rungs by competence.
## routing: a worker runs without the advisor tool
2026-11-12, lilleman, settled by the bench below. Serves goal 1.4: a switch that raises cost without raising quality is no saving. Valid while the ladder's L 1 and L 2 workers run on Sonnet 5.5 and the advisor would be Opus 5.5.
`claude -p` calls the advisor. A probe with `--advisor claude-opus-5-5` made one call: it read the whole conversation, 20,187 uncached input tokens, and cost $0.093 beside the worker's $0.036. `workflow-bench/advisor_bench.py` ran six archived chunks of this repo (todo items 290, 251 and 218 at L 1, and 289, 229 and 214 at L 2) once on each of three arms: Sonnet 5.5 at high with the advisor, Sonnet 5.5 at high alone, and Opus 5.5 at medium. A judge on Opus 5.5 at medium, blind to the arm, ruled each run's change against the change that shipped, with the tests of the packages either change touches.
| Arm | Passes | Mean cost | Mean seconds | Runs with an advisor call |
|---|---|---|---|---|
| Sonnet 5.5 with the advisor | 6 of 6 | $0.37 | 286 | 1 of 6 |
| Sonnet 5.5 alone | 6 of 6 | $0.27 | 151 | 0 of 6 |
| Opus 5.5 at medium | 6 of 6 | $0.46 | 197 | 0 of 6 |
Every arm passed every case, so the bench found no quality gap for an advisor to close, and Sonnet alone cost 41% less than Opus at medium. The advisor's one call, in item 214's run, cost $0.72 of that run's $1.24, against $0.41 for Sonnet alone. Anthropic's reported gain (https://claude.com/blog/the-advisor-strategy) came on SWE-bench Multilingual, a harder set than L 1 and L 2 chunks. The bench ran each arm once per case, and its judge is of the worker's own model family, so it shows a direction only. It tested L 1 and L 2 items alone. Workers on items above L 2 run without the advisor too, since nothing shows it pays there, until a bench of such items does.
## routing: a worker whose run ends asking for a higher rung, citing an escalation trigger the judge finds in the transcript, steps one rung up as the judge interrupts or quotes an answer, or next cycle, up to two rungs above the rung its item picks
2026-10-15, lilleman asked for it. Serves goals 1.1 and 1.4: when the hard part is the rest of the chunk, handing it to subagents piece by piece leaves the worker, which reads and checks each of their diffs, on a rung that proved too low. The worker climbs only once its run records a trigger.
@@ -442,7 +456,7 @@ Since 2026-10-16 the reviewers may run above the worker's rung, on the one the h
## routing: loop-claude reads the items a chunk takes from the worker's latest `Chunk items:` line and scores them by `todo.md` as the default branch held it when the cycle started; the judge reports the escalation and whether a release is ready to cut
2026-11-11, claude. Serves goal 1.4 and code health. The judge's reply held three facts beside its verdict: the items the worker took into the chunk, with their highest L and E + I; whether a release was ready to cut; and any escalation the worker asked for. Routing lifts the worker's, the reviewers' and the judge's rungs by the items' levels. Code now reads the items: each chunk's first prompt, and each prompt resuming it, asks the worker for a line opening `Chunk items:`, `bin/loop_claude/cycle/chunk_items.py` reads the latest such line in the worker's own text, and `release_plan.todo_table` scores the items. So the judge's reply is smaller, and every L and E + I that routing reads comes from `todo.md`, through one module.
2026-11-11, claude. Serves goal 1.4 and code health. The judge's reply held three facts beside its verdict: the items the worker took into the chunk, with their highest L and E + I; whether a release was ready to cut; and any escalation the worker asked for. Routing lifts the worker's and the reviewers' rungs by the items' levels. Code now reads the items: each chunk's first prompt, and each prompt resuming it, asks the worker for a line opening `Chunk items:`, `bin/loop_claude/cycle/chunk_items.py` reads the latest such line in the worker's own text, and `release_plan.todo_table` scores the items. So the judge's reply is smaller, and every L and E + I that routing reads comes from `todo.md`, through one module.
The judge field trials (`judge-field-trials/`) read each fact by code over the 709 archived cases. Code was wrong in each of the 39 cases where it and the judge disagreed on an escalation, and read a release ready to cut in 3 of the 31 interrupts that asked about a cut, so the judge keeps both. Workers stated an item with its L and E + I in 413 cases, but also stated items they filed, finished or only mentioned, so the worker writes the items on a line that holds only them, which code reads. Three fresh readers picked its label `Chunk items:`, 3 to 0, because it says the items are the chunk's.
@@ -450,17 +464,19 @@ An item the chunk re-scores on its branch routes on its planned levels until the
Valid while workers write the line when asked, and while `todo.md` on the default branch scores each item a chunk takes.
## routing: on a model judge-replay covered, the judge runs on the lowest of its model's rungs at or above the rung a review would get from the highest E + I among its chunk's items, never below the project's rung
## routing: on a model judge-replay covered, the judge runs on its model's highest rung
2026-10-15, lilleman's plan, settled by the replays below. Serves goals 1.2 and 1.4, under the ladder and steps of `routing: one ladder`.
2026-10-15, lilleman's plan, settled by the replays below. Serves goals 1.1, 1.2 and 1.4, under the ladder and steps of `routing: one ladder`.
On a model listed in `JUDGE_REPLAYED` in `bin/loop_claude/routing.py`, the judge runs on the lowest of its model's own rungs at or above the rung a review would get from the highest E + I among its chunk's items: the routed item and those the worker takes in. Where that rung is above all its model's rungs, it runs on its model's highest. So on an Opus 5.5 project it runs on Opus 5.5 at medium below an E + I of 5, and at xhigh from 5. It never runs below the project's rung, and keeps its rung when the worker steps up. Without an item, it runs on the project's rung. Each archived verdict names the judge's rung on a `Judge:` line.
On a model listed in `JUDGE_REPLAYED` in `bin/loop_claude/routing.py`, the judge runs on its model's highest rung, whatever the chunk's items score: on an Opus 5.5 project, Opus 5.5 at xhigh. It keeps its rung when the worker steps up. Each archived verdict names the judge's rung on a `Judge:` line.
On 2026-10-15, `bin/judge-replay claude-opus-5-5` replayed the latest 15 archived verdicts of each kind from the Opus 5.5 projects, 39 in all. The reference judge, Opus 5.5 at the xhigh effort `settings.json` gave every judge before, reproduced 31 of them. The other 8 may rest on records or judge rules that have changed since; either way no rung is held to them. On the 31, Haiku 5.5 missed 7 at xhigh and 8 at max. That run tried each judge once. 4 of Haiku's misses, 1 at xhigh and 3 at max, misquoted the transcript, which the loop and `judge-replay` now retry; without them it missed 6 and 5. Sonnet 5.5 at high returned another kind on 3 interrupts, and Opus 5.5 at medium missed none. A missed interrupt lets the worker settle a decision that is lilleman's (goal 1.2), so the judge never runs below the project's rung.
Only Opus 5.5 was replayed, so the judge of a project on another model keeps the effort its settings give until `judge-replay` covers that model (goal 1.1). Every routed chunk on record had an item of R + C 9, so the 2026-10-15 replay could not show that the project's rung suffices for harder items, and the judge climbs with the routed item. Since 2026-10-16, lilleman's call, it climbs with the item's E + I, as a review does: the judge checks the worker's decisions as the reviewers check its code, and a decision the judge lets through reaches lilleman, as a defect that review lets through reaches the users (goal 1.2). It runs above the project's rung only on an E + I of 5 or more (goal 1.4). It counts a taken-in item from the next cycle on.
Only Opus 5.5 was replayed, so the judge of a project on another model keeps the effort its settings give until `judge-replay` covers that model (goal 1.1). From 2026-10-16 to 2026-11-12 the judge ran at medium below an E + I of 5 and at xhigh from 5, climbing with the highest E + I among the routed item and those the worker took in, as a review does: lilleman's call, since the judge checks the worker's decisions as the reviewers check its code, and a decision it lets through reaches lilleman, as a defect that review lets through reaches the users (goal 1.2).
On 2026-11-12, `bin/judge-replay claude-opus-5-5` replayed 60 verdicts, 15 of each kind, and also tried each rung above the project's that a review climbs to by E + I. The reference judge reproduced 46. On those 46, Fable 5.2 missed 2 interrupts and 6 other verdicts at low, 1 interrupt and 4 others at medium, and 1 interrupt and 2 others at high. Every Fable 5.2 rung it tried misses an interrupt, so the judge keeps to its own model's rungs (goal 1.2). That rule also keeps it off Fable 5.2 at max, which no replay tried. Between Opus 5.5's two rungs it climbs to xhigh, not back to medium, since a chunk of E + I 5 or more needs a judge above the project's rung, as it needs reviewers above it. Opus 5.5 at medium missed no interrupt, but returned another kind on 4 quoted answers, 3 of them as finished; `todo.md` item 333 weighs that.
On 2026-11-12, `bin/judge-replay claude-opus-5-5` replayed 60 verdicts, 15 of each kind, and also tried each rung above the project's that a review climbs to by E + I. The reference judge reproduced 46. On those 46, Fable 5.2 missed 2 interrupts and 6 other verdicts at low, 1 interrupt and 4 others at medium, and 1 interrupt and 2 others at high. Every Fable 5.2 rung it tried misses an interrupt, so the judge keeps to its own model's rungs (goal 1.2). That rule also keeps it off Fable 5.2 at max, which no replay tried. Opus 5.5 at medium missed no interrupt, but returned another kind on 4 quoted answers, 3 of them as finished.
2026-11-12, claude, raising the judge's floor to xhigh, settled by the reruns below. Serves goal 1.1, at a cost to goal 1.4. Today's records still hold each of the 4 archived quotes, so no case drops out. For fejkdata the quote, `Split a milestone into items in todo.md before starting it`, doesn't plainly answer whether a split changes what release 0.5.0 holds, which is lilleman's choice. That case stays, since xhigh quotes it in 3 of 3 replays. Each case was replayed on today's records and the archived transcript copy. Opus 5.5 at medium returned the quoted answer 7 times in 20: adf-codec 4 of 5 (the fifth as finished), claude-config 3 of 5 (2 finished), plainpages 0 of 5 (5 finished) and fejkdata 0 of 5 (5 unfinished). At xhigh it returned it 9 times in 12: adf-codec 1 of 3 (2 interrupts), claude-config 3 of 3, plainpages 2 of 3 (1 finished) and fejkdata 3 of 3. So the misses persist at medium, and xhigh returns the quote more than twice as often. A quoted answer returned as finished closes a chunk whose worker was asking a question, a quality miss (goal 1.1). xhigh costs more per judge run (goal 1.4); the `Judge cost:` lines of three of the four cases, run at medium, read 0.57 to 0.79. xhigh is not free of misses: it returned a quoted answer as finished once, and as an interrupt twice, which only asks lilleman more.
Valid while the archived verdicts show what a judge should return, and until a new model joins the ladder: replay then.
+34
View File
@@ -1691,3 +1691,37 @@ Read most (opens and searches):
- `bin/model_routing/ladder.py` 3
- `bin/rung_replay/search.py` 3
- `CHANGELOG.md` 2
## Reading cost, chunk 0ded0c4aa0a1, finished 2026-11-12T01:14:37Z
180267 new input tokens before the first commit.
Read most (opens and searches):
- `todo.md` 16
- `skills/larv-review/SKILL.md` 10
- `bin/command_patterns/tally.py` 5
- `README.md` 4
- `bin/command_patterns/main.py` 4
- `skills/comprehension-panel/seat-prompts.md` 4
- `bin/chunk_pr/main.py` 3
- `skills/comprehension-panel/SKILL.md` 3
- `agents/stability-reviewer.md` 2
- `CHANGELOG.md` 1
## Reading cost, chunk 8640ba15252f, finished 2026-11-12T02:12:06Z
82406 new input tokens before the first commit.
Read most (opens and searches):
- `docs/decisions.md` 7
- `bin/loop_claude/routing.py` 4
- `CLAUDE.md` 3
- `README.md` 3
- `bin/loop_claude/test_black_box.py` 3
- `CHANGELOG.md` 2
- `bin/judge_replay/main.py` 2
- `bin/loop_claude/test_loop_claude.py` 2
- `bin/model_routing/route.py` 2
- `todo.md` 2
-14
View File
@@ -13,8 +13,6 @@
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 331 | 0.9.0 | | question | **Reword four decisions to expire when the rungs their replays tested change, not whenever a model joins the ladder.** | 1 | 1 | 1 | 1 | 2 | 1.4 by 2 | 0.9 |
| 333 | 0.9.0 | | decision | **For an Opus 5.5 project's chunks under E + I 5, run the judge on a rung that returns every quoted answer the reference judge reproduces.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 3, 1.2 by 2 | 2.1 |
| 320 | 0.9.0 | | | **Bench a worker below the project's rung with the advisor tool against the same worker alone and the project's rung, and file the switch if it wins.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3, 1.1 by 2 | 2.0 |
| 315 | 0.9.0 | | | **Start each reviewer under `agents/` without `CLAUDE.md`, and hand it the vocabulary, the prose rules and the project's decision titles.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 6 | 2.0 |
| 312 | 0.9.0 | | | **Research the tooling agents read, search and run commands with, and file an item for each tool that cuts tokens a replay shows keep quality.** | 1 | 2 | 1 | 2 | 3 | 1.4 by 3, 1.5 by 2 | 2.0 |
| 325 | 0.9.0 | | | **Give this repo's test suite one command that runs it as README → Test says, prints the failing tests and pytest's summary line, and saves the whole log to a file whose path it prints.** | 3 | 2 | 2 | 5 | 3 | 1.4 by 3, 1.5 by 2 | 2.0 |
@@ -90,18 +88,6 @@ The architect's 🔀 answer on PR #493 (item 292): four decisions expire "when a
Recommendation: reword all four as above. They are decisions the repo held before item 292, so the rewording is lilleman's call.
### 333. For an Opus 5.5 project's chunks under E + I 5, run the judge on a rung that returns every quoted answer the reference judge reproduces.
The judge returns one verdict kind per cycle: finished, unfinished, interrupt, or quoted answer, which answers the worker's question from `README.md` or the records so the worker resumes without lilleman. `routing: on a model judge-replay covered` puts the judge of an Opus 5.5 project on Opus 5.5 at medium, the project's rung, below E + I 5, and at xhigh from 5. It rests on the 2026-10-15 replay, where Opus 5.5 at medium missed none of the 31 verdicts the reference judge, Opus 5.5 at xhigh, reproduced.
On 2026-11-12, `bin/judge-replay claude-opus-5-5` replayed 60 archived verdicts, 15 of each kind, and the reference judge reproduced 46. On those, Opus 5.5 at medium missed no interrupt, but returned another kind on 4 quoted answers: as finished on adf-codec 2026-10-21T20:33:37Z, claude-config 2026-11-08T10:15:04Z and plainpages 2026-11-08T19:55:39Z, and as unfinished on fejkdata 2026-11-10T22:25:50Z. A quoted answer returned as finished closes a chunk whose worker was asking a question (goal 1.1). It is a quality miss, not a decision of lilleman's left unasked. The replay tried each judge call up to three times on failure, but ran once, so some misses may be noise.
Recommended order. First read the 4 cases, and check whether each archived quoted answer still holds against today's `README.md` and records: a quote the records no longer back explains the miss, and that case drops out. Then re-run the project's rung on the cases that remain, a few times each. Only where misses persist, raise the judge's floor below E + I 5 to Opus 5.5 at xhigh in `bin/loop_claude/routing.py`, and record the evidence in that decision. That costs more per cycle (goal 1.4), against the quality goal 1.1 the misses hurt. Moving the judge to another rung changes neither the ladder nor its steps, which `routing: one ladder` reserves for lilleman: that decision says the judge's rung is set by `routing: on a model judge-replay covered`.
### 320. Bench a worker below the project's rung with the advisor tool against the same worker alone and the project's rung, and file the switch if it wins.
Anthropic reports Sonnet 4.6 with an Opus 4.6 advisor scored 2.7 points more on SWE-bench Multilingual at 11.9% less cost than Sonnet alone (the vendor's own run; https://claude.com/blog/the-advisor-strategy). The docs say `/advisor` works with `-p`, but not outright that the advisor is called during a `-p` run, so probe that first. Each advisor call hands the advisor the whole conversation, so count its cost. Bench on `workflow-bench` with archived L 1 and L 2 items: Sonnet with the advisor, Sonnet alone, Opus at medium. lilleman approved on 2026-11-11.
### 315. Start each reviewer under `agents/` without `CLAUDE.md`, and hand it the vocabulary, the prose rules and the project's decision titles.
`omitClaudeMd: true` in an agent's frontmatter (Claude Code 2.1.271 or later) starts it without the user, project and local instruction files. About 77% of `CLAUDE.md` is the worker's: "Working loop", "Working with the codebase", "Git", "Handoffs", "Compact instructions". Over the archive, each 1,000 prefix tokens cost $31 across the six reviewers, so this saves about 1.9% of spend. A reviewer still needs "Vocabulary", "Prose" and the project's decision titles: put the first two in the agent bodies or a `SubagentStart` hook's `additionalContext`, and have `larv-review reviewer-header` print the titles.
+19
View File
@@ -0,0 +1,19 @@
You judge one worker's change to a todo item. You see the item, the change that shipped for it, the worker's change, and the result of the tests of the packages that either change touches, run on the worker's tree. You don't know which model wrote the worker's change.
Rule `pass` where the worker's change does what the item asks, comes with a test that fails without the change, and causes no failing test. Rule `partial` where it does most of the item or lacks that test. Rule `fail` where it misses the item, causes a failing test, or changes unrelated code. The shipped change is one correct answer, not the only one.
{text}
## The shipped change
{reference}
## The worker's change
{diff}
## The tests on the worker's tree
{tests}
Reply with JSON only: {{"verdict": "pass" | "partial" | "fail", "why": "<one sentence>"}}
+10
View File
@@ -0,0 +1,10 @@
You are the worker of one chunk of this repository, a throwaway clone at `{base}`. Implement todo item {item} below as `CLAUDE.md` → "Working loop" says, and stop when it is done and its tests pass.
{text}
## Bench rules
- The clone is yours and has no remote: make no worktree and no branch, open no pull request, don't push anything, run no review pass, and don't edit `todo.md`, `CHANGELOG.md` or `docs/`. Leave your change uncommitted.
- Write the test first where a test can check the change, and see it fail.
- Run the tests as `README.md` → Test says. No human is reachable: where the item leaves a choice open, take your recommendation.
- End with a two-line summary of what you changed.
+204
View File
@@ -0,0 +1,204 @@
#!/usr/bin/env python3
"""Bench the advisor tool on archived chunks: advisor_bench.py <work dir> run|grade <case>-<arm>-<n> ..., then advisor_bench.py <work dir> summary
The question: does a worker below the project's rung, Sonnet 5.5 with Opus 5.5 as its advisor, beat the same
Sonnet alone, or match Opus 5.5 at medium for less? Each case is an archived L 1 or L 2 chunk of this repo
(CASES holds its todo.md item, the commit it started from and the commit it merged at). `run` clones the repo at
the start commit and hands the arm's worker the item's text from todo.md, with the bench rules of
advisor-run-prompt.md in place of loop-claude's prompt. It saves, beside the clone in <work dir>: the claude
stream (.jsonl), the worker's change (.diff) and the result of the tests of the packages that either change touches (.tests).
`grade` has a judge on Opus 5.5 at medium, blind to the arm, rule on the .diff against the merged commit's change
(.verdict); `summary` prints a table per arm.
Run each arm of each case once; the table shows a direction, not a significance.
"""
import concurrent.futures
import dataclasses
import json
import pathlib
import re
import subprocess
import sys
BENCH = pathlib.Path(__file__).resolve().parent
REPO = BENCH.parent
RUN_HEAVY = pathlib.Path.home() / ".claude/bin/run-heavy"
SUITE = ["uvx", "--python", sys.executable, "--with", "pytest-xdist==3.8.0", "pytest==9.2.0", "-n", "4", "-q"]
CASES = {
"290": ("cda45a931", "509804da0"),
"251": ("b74322892", "d13c4fb0d"),
"218": ("62d57344d", "c424fa66a"),
"289": ("034356f34", "62d1f5edd"),
"229": ("e2aca90c9", "2321f4930"),
"214": ("39dd51bb4", "4764d3d52"),
}
@dataclasses.dataclass(frozen=True)
class Arm:
model: str
effort: str
advisor: str | None = None
def flags(self):
return ["--model", self.model, "--effort", self.effort, *(["--advisor", self.advisor] if self.advisor else [])]
ARMS = {
"sonnet-advisor": Arm("claude-sonnet-5-5", "high", "claude-opus-5-5"),
"sonnet": Arm("claude-sonnet-5-5", "high"),
"opus-medium": Arm("claude-opus-5-5", "medium"),
}
VERDICTS = ("pass", "partial", "fail")
JUDGE = Arm("claude-opus-5-5", "medium")
@dataclasses.dataclass(frozen=True)
class Outcome:
cost: float
seconds: float
advisor_calls: int
def item_text(todo, item):
"""The item's heading and detail in todo.md, up to the next item's heading."""
found = re.search(rf"^### {item}\. .*?(?=^### \d+\. |\Z)", todo, re.DOTALL | re.MULTILINE)
if not found:
raise ValueError(f"item {item} has no detail in todo.md")
return found.group().strip()
def read_result(lines):
"""The cost, seconds and advisor calls of a claude stream's first result line, which is the worker's: a background task's notification makes the later ones. The cost counts the advisor's tokens."""
for line in lines:
try:
entry = json.loads(line)
except ValueError:
continue
if entry.get("type") == "result":
if entry.get("is_error"):
raise ValueError(f"the run ended in an error: {entry.get('result')}")
iterations = entry.get("usage", {}).get("iterations", [])
return Outcome(
cost=entry["total_cost_usd"], seconds=entry["duration_ms"] / 1000,
advisor_calls=sum(1 for each in iterations if each.get("type") == "advisor_message"))
raise ValueError("the stream has no result line")
def verdict_of(reply):
"""The verdict in the judge's `claude -p --output-format json` reply."""
found = re.search(r"\{.*\}", json.loads(reply)["result"], re.DOTALL)
if not found:
raise ValueError("the judge's reply has no JSON object")
verdict = json.loads(found.group())["verdict"]
if verdict not in VERDICTS:
raise ValueError(f"the judge's verdict {verdict!r} is none of {VERDICTS}")
return verdict
def split_name(name):
"""The case, arm and run number of a run's name, such as 290-sonnet-advisor-1."""
case, rest = name.split("-", 1)
arm, number = rest.rsplit("-", 1)
return case, arm, number
def suite_targets(changed):
"""The tests to run for a change: the package, or the lone module, under bin/ of each changed file, else all of bin/."""
found = {"/".join(path.split("/")[:2]) for path in changed if path.startswith("bin/")}
return sorted(found) or ["bin"]
def summary(rows):
"""A markdown table with one row per arm, in ARMS' order: its runs, passes, partials, mean cost, mean advisor calls and mean seconds."""
lines = ["| arm | runs | pass | partial | mean cost $ | mean advisor calls | mean seconds |", "|---|---|---|---|---|---|---|"]
for name in ARMS:
own = [row for row in rows if row["arm"] == name]
if own:
passes, partials = (sum(row["verdict"] == kind for row in own) for kind in ("pass", "partial"))
cost, advisor_calls, seconds = (sum(row[key] for row in own) / len(own) for key in ("cost", "advisor_calls", "seconds"))
lines.append(f"| {name} | {len(own)} | {passes} | {partials} | {cost:.2f} | {advisor_calls:.1f} | {seconds:.0f} |")
return "\n".join(lines)
def git(repo, *args):
return subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True, text=True).stdout
def fresh_clone(base, dest):
"""A clone of this repo at base, with no remote to push to."""
subprocess.run(["git", "clone", "-q", "--no-local", str(REPO), str(dest)], check=True)
git(dest, "checkout", "-q", "--detach", base)
git(dest, "remote", "remove", "origin")
def run(work, name):
"""One worker run of <case>-<arm>-<n>; the files it leaves are in the module docstring."""
case, arm, _ = split_name(name)
base = CASES[case][0]
clone = work / name
if clone.exists():
raise ValueError(f"{name} already ran: remove {clone}")
fresh_clone(base, clone)
prompt = (BENCH / "advisor-run-prompt.md").read_text().format(base=base, item=case, text=item_text(git(REPO, "show", f"{base}:todo.md"), case))
with (work / f"{name}.jsonl").open("w") as out:
subprocess.run(
["claude", "-p", prompt, *ARMS[arm].flags(), "--setting-sources", "project", "--permission-mode", "bypassPermissions",
"--no-session-persistence", "--output-format", "stream-json", "--verbose"],
cwd=clone, stdout=out, stderr=subprocess.STDOUT)
read_result((work / f"{name}.jsonl").read_text().splitlines())
git(clone, "add", "--all")
(work / f"{name}.diff").write_text(git(clone, "diff", "--cached", base))
changed = [*git(clone, "diff", "--cached", "--name-only", base).split(), *git(REPO, "diff", "--name-only", base, CASES[case][1]).split()]
targets = [target for target in suite_targets(changed) if (clone / target).exists()] or ["bin"]
tests = subprocess.run([str(RUN_HEAVY), *SUITE, *targets], cwd=clone, capture_output=True, text=True)
(work / f"{name}.tests").write_text(f"exit {tests.returncode}\n{tests.stdout[-1500:]}")
return f"{name}: ran"
def grade(work, name):
"""Have the judge rule on one run's diff, blind to its arm, and save the verdict beside it."""
case = split_name(name)[0]
base, merged = CASES[case]
prompt = (BENCH / "advisor-judge-prompt.md").read_text().format(
text=item_text(git(REPO, "show", f"{base}:todo.md"), case), reference=git(REPO, "diff", base, merged, "--", ".", ":!todo.md", ":!docs", ":!CHANGELOG.md"),
diff=(work / f"{name}.diff").read_text(), tests=(work / f"{name}.tests").read_text())
reply = subprocess.run(
["claude", "-p", prompt, *JUDGE.flags(), "--setting-sources", "", "--no-session-persistence", "--output-format", "json", "--tools", ""],
capture_output=True, text=True, check=True).stdout
verdict = verdict_of(reply)
(work / f"{name}.verdict").write_text(json.dumps({"verdict": verdict, "reply": json.loads(reply)["result"]}))
return f"{name}: {verdict}"
def attempted(step, work, name):
"""step's result line, or a line naming the failure, so one failed run doesn't stop the other runs' results printing."""
try:
return step(work, name)
except (KeyError, ValueError, subprocess.CalledProcessError, OSError) as failure:
return f"{name}: FAILED: {type(failure).__name__}: {failure}"
def rows_of(work):
rows = []
for verdict_file in sorted(work.glob("*.verdict")):
name = verdict_file.stem
try:
outcome = read_result((work / f"{name}.jsonl").read_text().splitlines())
except ValueError as failure:
raise ValueError(f"{name}: {failure}") from failure
rows.append({"arm": split_name(name)[1], "verdict": json.loads(verdict_file.read_text())["verdict"], **dataclasses.asdict(outcome)})
return rows
def main(argv):
work, step, names = pathlib.Path(argv[0]), argv[1], argv[2:]
if step == "summary":
print(summary(rows_of(work)))
return
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
for result in pool.map(lambda name: attempted({"run": run, "grade": grade}[step], work, name), names):
print(result, flush=True)
if __name__ == "__main__":
main(sys.argv[1:])
+309
View File
@@ -0,0 +1,309 @@
import contextlib
import io
import json
import pathlib
import subprocess
import tempfile
import unittest
import unittest.mock
import advisor_bench
TODO = """| table |
## Details
### 7. Do the seventh thing.
Its detail.
### 8. Do the eighth thing.
Another detail.
"""
def result_line(**fields):
return json.dumps({"type": "result", "total_cost_usd": 0.5, "num_turns": 9, "duration_ms": 12000, "usage": {"iterations": []}, **fields})
class Arms(unittest.TestCase):
def test_the_advisor_arm_names_its_model_effort_and_advisor(self):
self.assertEqual(
advisor_bench.ARMS["sonnet-advisor"].flags(), ["--model", "claude-sonnet-5-5", "--effort", "high", "--advisor", "claude-opus-5-5"])
def test_an_arm_without_an_advisor_passes_no_advisor_flag(self):
self.assertEqual(advisor_bench.ARMS["opus-medium"].flags(), ["--model", "claude-opus-5-5", "--effort", "medium"])
self.assertNotIn("--advisor", advisor_bench.ARMS["sonnet"].flags())
class SplitName(unittest.TestCase):
def test_keeps_a_hyphen_in_the_arm(self):
self.assertEqual(advisor_bench.split_name("290-sonnet-advisor-2"), ("290", "sonnet-advisor", "2"))
class SuiteTargets(unittest.TestCase):
def test_names_the_package_of_each_changed_file_under_bin_once(self):
self.assertEqual(
advisor_bench.suite_targets(["bin/rule_hook/rules.py", "bin/rule_hook/test_rule_hook.py", "bin/shell_command.py", "README.md"]),
["bin/rule_hook", "bin/shell_command.py"])
def test_falls_back_to_the_whole_of_bin_where_no_changed_file_is_in_it(self):
self.assertEqual(advisor_bench.suite_targets(["README.md"]), ["bin"])
class ItemText(unittest.TestCase):
def test_reads_the_heading_and_detail_up_to_the_next_item(self):
self.assertEqual(advisor_bench.item_text(TODO, 7), "### 7. Do the seventh thing.\n\nIts detail.")
def test_reads_the_last_item_to_the_end(self):
self.assertEqual(advisor_bench.item_text(TODO, 8), "### 8. Do the eighth thing.\n\nAnother detail.")
def test_refuses_an_item_with_no_detail(self):
with self.assertRaisesRegex(ValueError, "item 9"):
advisor_bench.item_text(TODO, 9)
class ReadResult(unittest.TestCase):
def test_reads_cost_seconds_and_counts_advisor_calls(self):
iterations = [{"type": "message"}, {"type": "advisor_message"}, {"type": "message"}, {"type": "message"}, {"type": "advisor_message"}]
outcome = advisor_bench.read_result(["not json", result_line(usage={"iterations": iterations})])
self.assertEqual(outcome, advisor_bench.Outcome(cost=0.5, seconds=12.0, advisor_calls=2))
def test_reads_the_first_result_where_a_background_task_makes_later_ones(self):
self.assertEqual(advisor_bench.read_result([result_line(total_cost_usd=0.5), result_line(total_cost_usd=2.0)]).cost, 0.5)
def test_counts_no_advisor_call_where_the_run_has_no_iterations(self):
self.assertEqual(advisor_bench.read_result([result_line(usage={})]).advisor_calls, 0)
def test_counts_no_advisor_call_where_the_run_has_no_usage(self):
line = json.dumps({"type": "result", "total_cost_usd": 0.5, "num_turns": 9, "duration_ms": 12000})
self.assertEqual(advisor_bench.read_result([line]).advisor_calls, 0)
def test_refuses_a_run_that_ended_in_an_error(self):
with self.assertRaisesRegex(ValueError, "the run ended in an error: API Error"):
advisor_bench.read_result([result_line(is_error=True, result="API Error")])
def test_refuses_a_stream_with_no_result_line(self):
with self.assertRaises(ValueError) as refused:
advisor_bench.read_result(['{"type": "assistant"}'])
self.assertEqual(str(refused.exception), "the stream has no result line")
class Verdict(unittest.TestCase):
def test_reads_the_verdict_from_a_json_reply(self):
self.assertEqual(advisor_bench.verdict_of(json.dumps({"result": '{"verdict": "partial", "why": "no test"}'})), "partial")
def test_reads_the_verdict_from_a_reply_in_a_code_fence_or_after_prose(self):
for reply in ('```json\n{"verdict": "fail", "why": "x"}\n```', 'Ruling: {"verdict": "fail", "why": "x"} Done.'):
self.assertEqual(advisor_bench.verdict_of(json.dumps({"result": reply})), "fail")
def test_reads_a_verdict_from_a_reply_that_spans_lines(self):
self.assertEqual(advisor_bench.verdict_of(json.dumps({"result": '{\n"verdict": "pass",\n"why": "x"\n}'})), "pass")
def test_refuses_a_reply_with_no_json_object(self):
with self.assertRaises(ValueError) as refused:
advisor_bench.verdict_of(json.dumps({"result": "I cannot rule."}))
self.assertEqual(str(refused.exception), "the judge's reply has no JSON object")
def test_refuses_a_verdict_outside_pass_partial_fail(self):
with self.assertRaisesRegex(ValueError, "verdict"):
advisor_bench.verdict_of(json.dumps({"result": '{"verdict": "great", "why": "x"}'}))
class Summary(unittest.TestCase):
def test_prints_one_row_per_arm_with_passes_and_mean_cost(self):
rows = [
{"arm": "sonnet", "verdict": "pass", "cost": 1.0, "advisor_calls": 0, "seconds": 100.0},
{"arm": "sonnet", "verdict": "fail", "cost": 3.0, "advisor_calls": 0, "seconds": 300.0},
{"arm": "opus-medium", "verdict": "pass", "cost": 4.0, "advisor_calls": 0, "seconds": 200.0},
]
rows.append({"arm": "sonnet-advisor", "verdict": "partial", "cost": 1.0, "advisor_calls": 2, "seconds": 50.0})
self.assertEqual(advisor_bench.summary(rows).splitlines(), [
"| arm | runs | pass | partial | mean cost $ | mean advisor calls | mean seconds |",
"|---|---|---|---|---|---|---|",
"| sonnet-advisor | 1 | 0 | 1 | 1.00 | 2.0 | 50 |",
"| sonnet | 2 | 1 | 0 | 2.00 | 0.0 | 200 |",
"| opus-medium | 1 | 1 | 0 | 4.00 | 0.0 | 200 |",
])
def commit(repo, message):
subprocess.run(["git", "-C", str(repo), "-c", "user.name=bench", "-c", "user.email=bench@example.com", "commit", "-q", "-a", "-m", message], check=True)
class Orchestration(unittest.TestCase):
"""run, grade, main and rows_of, on a throwaway repo, with claude and run-heavy faked.
Case 7 starts at a commit holding bin/pkg/mod.py, and merges a change to bin/pkg/mod.py, a new bin/other/mod.py, and
todo.md, docs and CHANGELOG.md; a later commit then changes bin/pkg/mod.py again and adds bin/later/mod.py, which the judge must not see."""
def setUp(self):
scratch = tempfile.TemporaryDirectory()
self.addCleanup(scratch.cleanup)
root = pathlib.Path(scratch.name)
self.repo, self.work = root / "repo", root / "work"
self.work.mkdir()
subprocess.run(["git", "init", "-q", str(self.repo)], check=True)
base = self.commit({"todo.md": TODO, "bin/pkg/mod.py": "x = 1\n", "docs/notes.md": "a\n", "CHANGELOG.md": "a\n"})
merged = self.commit({"todo.md": TODO + "\nmore\n", "bin/pkg/mod.py": "x = 2\n", "bin/other/mod.py": "z = 1\n", "docs/notes.md": "b\n", "CHANGELOG.md": "b\n"})
self.commit({"bin/pkg/mod.py": "x = 5\n", "bin/later/mod.py": "y = 1\n"})
self.calls = []
real_run = subprocess.run
for patch in (
unittest.mock.patch.object(advisor_bench, "REPO", self.repo), unittest.mock.patch.object(advisor_bench, "CASES", {"7": (base, merged)}),
unittest.mock.patch.object(advisor_bench.subprocess, "run", side_effect=lambda args, **kwargs: self.fake(real_run, args, **kwargs)),
):
patch.start()
self.addCleanup(patch.stop)
self.tests_output = "3 passed\n"
self.worker_result = {}
self.base = base
def commit(self, files):
for path, text in files.items():
(self.repo / path).parent.mkdir(parents=True, exist_ok=True)
(self.repo / path).write_text(text)
subprocess.run(["git", "-C", str(self.repo), "add", "."], check=True)
commit(self.repo, "a commit")
return advisor_bench.git(self.repo, "rev-parse", "HEAD").strip()
def fake(self, real_run, args, **kwargs):
if args[0] == "claude":
self.calls.append((args, kwargs))
if "--tools" in args:
return subprocess.CompletedProcess(args, 0, stdout=json.dumps({"result": '{"verdict": "pass", "why": "ok"}'}), stderr="")
pathlib.Path(kwargs["cwd"], "bin/pkg/mod.py").write_text("x = 3\n")
pathlib.Path(kwargs["cwd"], "bin/pkg/new.py").write_text("n = 1\n")
pathlib.Path(kwargs["cwd"], "bin/third").mkdir()
pathlib.Path(kwargs["cwd"], "bin/third/mod.py").write_text("t = 1\n")
subprocess.run(["git", "-C", str(kwargs["cwd"]), "add", "bin/third"], check=True)
commit(kwargs["cwd"], "the worker commits")
kwargs["stdout"].write(result_line(**self.worker_result) + "\n")
return subprocess.CompletedProcess(args, 0)
if args[0] == str(advisor_bench.RUN_HEAVY):
self.calls.append((args, kwargs))
return subprocess.CompletedProcess(args, 4, stdout=self.tests_output, stderr="")
return real_run(args, **kwargs)
def test_run_clones_at_the_start_commit_and_saves_the_stream_the_diff_and_the_tests(self):
self.assertEqual(advisor_bench.run(self.work, "7-sonnet-advisor-1"), "7-sonnet-advisor-1: ran")
(claude, claude_kwargs), (tests, tests_kwargs) = self.calls
clone = self.work / "7-sonnet-advisor-1"
self.assertEqual((claude_kwargs["cwd"], tests_kwargs["cwd"]), (clone, clone))
self.assertEqual(claude[:2] + claude[3:], [
"claude", "-p", *advisor_bench.ARMS["sonnet-advisor"].flags(), "--setting-sources", "project", "--permission-mode", "bypassPermissions",
"--no-session-persistence", "--output-format", "stream-json", "--verbose"])
self.assertIn("Do the seventh thing.", claude[2])
self.assertIn(f"`{self.base}`", claude[2])
self.assertIn("todo item 7 ", claude[2])
self.assertEqual(tests, [str(advisor_bench.RUN_HEAVY), *advisor_bench.SUITE, "bin/pkg", "bin/third"])
self.assertEqual((tests_kwargs["capture_output"], tests_kwargs["text"]), (True, True))
self.assertEqual(claude_kwargs["stdout"].name, str(self.work / "7-sonnet-advisor-1.jsonl"))
self.assertEqual(claude_kwargs["stderr"], subprocess.STDOUT)
self.assertEqual(advisor_bench.git(clone, "remote"), "")
self.assertEqual(advisor_bench.git(clone, "rev-parse", "HEAD~").strip(), self.base)
self.assertEqual(json.loads((self.work / "7-sonnet-advisor-1.jsonl").read_text())["total_cost_usd"], 0.5)
diff = (self.work / "7-sonnet-advisor-1.diff").read_text()
self.assertIn("-x = 1\n+x = 3\n", diff)
self.assertIn("+++ b/bin/pkg/new.py", diff)
self.assertIn("+++ b/bin/third/mod.py", diff)
self.assertEqual((self.work / "7-sonnet-advisor-1.tests").read_text(), "exit 4\n3 passed\n")
def test_run_tests_all_of_bin_where_no_touched_package_is_in_the_clone(self):
with unittest.mock.patch.object(advisor_bench, "suite_targets", return_value=["bin/absent"]):
advisor_bench.run(self.work, "7-sonnet-1")
self.assertEqual(self.calls[1][0][-1:], ["bin"])
def test_run_refuses_a_run_that_ended_in_an_error_before_it_tests(self):
self.worker_result = {"is_error": True, "result": "API Error"}
with self.assertRaisesRegex(ValueError, "API Error"):
advisor_bench.run(self.work, "7-sonnet-1")
self.assertEqual(len(self.calls), 1)
self.assertFalse((self.work / "7-sonnet-1.tests").exists())
def test_run_keeps_the_last_1500_characters_of_the_tests(self):
self.tests_output = "a" * 2000 + "b" * 1500
advisor_bench.run(self.work, "7-sonnet-1")
self.assertEqual((self.work / "7-sonnet-1.tests").read_text(), "exit 4\n" + "b" * 1500)
def test_run_refuses_a_name_that_already_ran(self):
advisor_bench.run(self.work, "7-sonnet-1")
with self.assertRaisesRegex(ValueError, "7-sonnet-1 already ran: remove .*7-sonnet-1"):
advisor_bench.run(self.work, "7-sonnet-1")
def test_a_clone_of_a_missing_repo_fails(self):
with unittest.mock.patch.object(advisor_bench, "REPO", self.work / "missing"), self.assertRaises(subprocess.CalledProcessError):
advisor_bench.fresh_clone(self.base, self.work / "clone")
def test_git_fails_where_git_does(self):
with self.assertRaises(subprocess.CalledProcessError):
advisor_bench.git(self.repo, "rev-parse", "no-such-revision")
def test_grade_saves_the_verdict_and_shows_the_judge_both_changes_but_not_the_arm(self):
advisor_bench.run(self.work, "7-sonnet-advisor-1")
self.calls.clear()
self.assertEqual(advisor_bench.grade(self.work, "7-sonnet-advisor-1"), "7-sonnet-advisor-1: pass")
((judge, kwargs),) = self.calls
self.assertEqual(judge[:2] + judge[3:], [
"claude", "-p", *advisor_bench.JUDGE.flags(), "--setting-sources", "", "--no-session-persistence", "--output-format", "json", "--tools", ""])
self.assertEqual((kwargs["capture_output"], kwargs["text"], kwargs["check"]), (True, True, True))
prompt = judge[2]
self.assertIn("Do the seventh thing.", prompt)
self.assertIn("-x = 1\n+x = 2\n", prompt)
self.assertIn("+++ b/bin/other/mod.py", prompt)
for left_out in ("x = 5", "later", "docs/notes.md", "CHANGELOG.md", "todo.md"):
self.assertNotIn(left_out, prompt)
self.assertIn("+x = 3", prompt)
self.assertIn("3 passed", prompt)
self.assertNotIn("sonnet", prompt)
self.assertEqual(
json.loads((self.work / "7-sonnet-advisor-1.verdict").read_text()),
{"verdict": "pass", "reply": '{"verdict": "pass", "why": "ok"}'})
def test_attempted_names_a_failure_in_place_of_raising_it(self):
def step(work, name):
raise KeyError("9")
self.assertEqual(advisor_bench.attempted(step, self.work, "9-sonnet-1"), "9-sonnet-1: FAILED: KeyError: '9'")
def test_attempted_hands_the_step_the_work_dir_and_the_name(self):
self.assertEqual(advisor_bench.attempted(lambda work, name: f"{work.name} {name}", self.work, "9-sonnet-1"), "work 9-sonnet-1")
def test_rows_of_pairs_each_verdict_with_its_runs_outcome(self):
(self.work / "7-sonnet-advisor-1.jsonl").write_text(result_line(total_cost_usd=2.0) + "\n")
(self.work / "7-sonnet-advisor-1.verdict").write_text(json.dumps({"verdict": "fail"}))
(self.work / "7-sonnet-2.jsonl").write_text(result_line() + "\n")
self.assertEqual(advisor_bench.rows_of(self.work), [{"arm": "sonnet-advisor", "verdict": "fail", "cost": 2.0, "seconds": 12.0, "advisor_calls": 0}])
def test_rows_of_names_a_run_whose_stream_has_no_result(self):
(self.work / "7-sonnet-1.jsonl").write_text("")
(self.work / "7-sonnet-1.verdict").write_text(json.dumps({"verdict": "pass"}))
with self.assertRaisesRegex(ValueError, "^7-sonnet-1: the stream has no result line$"):
advisor_bench.rows_of(self.work)
def run_main(self, *argv):
out = io.StringIO()
with contextlib.redirect_stdout(out):
advisor_bench.main([str(self.work), *argv])
return out.getvalue()
def test_main_prints_each_runs_line_though_an_earlier_run_failed(self):
def step(work, name):
if name == "7-a-1":
raise ValueError("no")
return f"{name}: ran"
with unittest.mock.patch.object(advisor_bench, "run", step):
self.assertEqual(self.run_main("run", "7-a-1", "7-b-1"), "7-a-1: FAILED: ValueError: no\n7-b-1: ran\n")
def test_main_grades_on_grade(self):
with unittest.mock.patch.object(advisor_bench, "grade", lambda work, name: f"{work.name} {name}: graded"):
self.assertEqual(self.run_main("grade", "7-a-1"), "work 7-a-1: graded\n")
def test_main_prints_the_work_dirs_summary_on_summary(self):
(self.work / "7-sonnet-1.jsonl").write_text(result_line() + "\n")
(self.work / "7-sonnet-1.verdict").write_text(json.dumps({"verdict": "pass"}))
self.assertIn("| sonnet | 1 | 1 | 0 | 0.50 | 0.0 | 12 |", self.run_main("summary"))
if __name__ == "__main__":
unittest.main()