Answer architecture round 1: 2 🔴, 8 🟡 (0 misread); split task-bench's benched into phases and its table into one column list, parse each stream once, move do-epic's parking out with pure move and news decisions, share the round summaries, rename scoring_due, and file the version question as item 517
CI / tests (pull_request) Successful in 5m2s

This commit is contained in:
2026-11-23 01:20:55 +01:00
parent 21200cb698
commit 0bf87b736e
29 changed files with 678 additions and 368 deletions
+134 -68
View File
@@ -37,15 +37,15 @@ It prints the base and the head, then a table: a row per bug and side with how m
that finished, of the input, cache-write, cache-read and output tokens, the turns, the wall time, and the reads and searches before
the run first opened the file the bug is in. The median of the reads leaves out a run that never opened that file. Then come a row
per side over every bug, and the head's change against the base. That last row holds the pass count's difference and, for each other
column, the mean over the bugs of each bug's own change, so it isn't the difference of the two rows above it. The last line names the bench's folder: `task-bench` in the
chunk's review folder.
column, the mean over the bugs of each bug's own change, so it isn't the difference of the two rows above it. The last line names
the bench's folder: `task-bench` in the chunk's review folder.
That folder holds each run's result and stream, and digest.md, which says why runs failed in a few kilobytes per bug:
- the table;
- per bug its decoys, the files more than half of its failing runs read that the bug isn't in;
- per bug up to two traces: of a failing run, one that didn't finish or else the one that spent the most tokens, and of the
passing run with the median tokens. A trace has a line per tool call, such as `Read pick.go:120-180` or `Grep "readName" → 4 hits`, and the first 3 lines of what Haiku wrote
between calls.
passing run with the median tokens. A trace has a line per tool call, such as `Read pick.go:120-180` or `Grep "readName" → 4
hits`, and the first 3 lines of what Haiku wrote between calls.
Read a change against the noise. Measured on `fejkdata`, a Go project, with the defaults, a bench of a commit against itself shows,
in 19 cases of 20, an All change under 12% in output tokens, 16% in cache-read tokens and 10% in wall time. On its bugs every run
@@ -79,17 +79,18 @@ import tarfile
import typing
import uuid
from task_bench.digest import Bug, digest, Run
from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN
from task_bench.digest import Bug, counted, digest, Run
from task_bench.plant import bug_at_sides, drawn, killed_mutants, Mutant, place_files, task_text
from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN, WORK
from claude_code.reply import Claude
from task_bench.bench_folder import clear_left, held
from machine_load.slots import CPUS_PER_SLOT
from git_cli.git_repo import default_ref, Git, top
from task_bench.gather import DIGEST, gather, run_claude
from task_bench.plant import drawn, killed_mutants, line_at_head, Mutant, mutated, place_files, task_text
from claude_code.entries import entries_of
from mutate_changes.tool_process import failed, Ran, run_tool
from failure import Failure
from task_bench.figures import figures, Result, SIDES, table, WORK
from task_bench.figures import figures, Result, SIDES, table
from git_cli import git_repo
from review_rules.review_folder import made_review_folder, REPORTS
from larv_review.history_commands import read_places
@@ -117,6 +118,32 @@ class Task:
return f"{self.mutant.path}:{self.mutant.line}:{self.mutant.column} {self.mutant.mutator}"
class Asked(typing.NamedTuple):
"""What the caller asked of a bench: the seed that orders the mutants, how many bugs to plant and how often to run each fix."""
seed: int
bugs: int
runs: int
@dataclasses.dataclass(frozen=True)
class Bench:
"""What a bench's phases share: the checkout, per side its commit and its tree without a bug, what the caller asked, the
containers, the bench's folder and git."""
checkout: str
sides: dict[str, str]
trees: dict[str, str]
asked: Asked
containers: Containers
folder: pathlib.Path
git: Git
class Fixes(typing.NamedTuple):
"""The runs that finished, in the order they ran, and the failure that stopped the bench before the rest, if one did."""
results: list[Result]
stopped: Failure | None
def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure] = read_places, claude: Claude = run_claude) -> int:
"""Runs task-bench with the arguments argv; git, docker and Gremlins run in the environment env, `read` reads what
`larv-review places` prints for the checkout, and `claude` runs the claude that gathers."""
@@ -202,7 +229,7 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
if isinstance(mutants, Failure):
return mutants
try:
found = opened(containers, given["--image"]) or benched(given, checkout, sides, trees, mutants, containers, folder, git)
found = opened(containers, given["--image"]) or benched(Bench(checkout, sides, trees, Asked(int(given["--seed"]), int(given["--bugs"]), int(given["--runs"])), containers, folder, git), mutants)
finally:
closed(containers)
except OSError as failure:
@@ -239,45 +266,74 @@ def archived(commit: str, into: pathlib.Path, checkout: str, git: Git) -> str |
return str(into)
def benched(given: dict[str, str], checkout: str, sides: dict[str, str], trees: dict[str, str], mutants: list[Mutant], containers: Containers, folder: pathlib.Path, git: Git) -> list[str] | Failure:
"""Plants the bugs, runs each fix, writes the results into folder and returns the report."""
for side, tree in trees.items():
ran = tests_in_copy(containers, tree, folder)
def benched(bench: Bench, mutants: list[Mutant]) -> list[str] | Failure:
"""Plants the bugs, runs each fix, writes the results into the bench's folder and returns the report."""
if failure := baseline_failure(bench):
return failure
tasks = planted_tasks(bench, mutants)
if isinstance(tasks, Failure):
return tasks
total = bench.asked.runs * len(tasks) * len(SIDES)
fixes = ran_fixes(bench, tasks, total)
if fixes.stopped and not fixes.results:
return fixes.stopped
names = {task.number: task.named() for task in tasks}
kept(bench, tasks, fixes.results)
if fixes.stopped:
return stopped_report(fixes.stopped, fixes.results, total, names, bench.folder)
return report(bench.sides, names, bench.asked, fixes.results)
def baseline_failure(bench: Bench) -> Failure | None:
"""Why a side's tests don't pass without a planted bug; None where both sides' pass."""
for side, tree in bench.trees.items():
ran = tests_in_copy(bench.containers, tree, bench.folder)
if isinstance(ran, Failure) or ran.code:
return ran if isinstance(ran, Failure) else failed(f"The tests fail at the {side} without a planted bug: the test command", ran)
return None
def planted_tasks(bench: Bench, mutants: list[Mutant]) -> list[Task] | Failure:
"""The mutants that become bugs, in the order the seed draws them, until the bench has as many as asked for."""
tasks: list[Task] = []
for mutant in drawn(mutants, int(given["--seed"])):
if len(tasks) == int(given["--bugs"]):
for mutant in drawn(mutants, bench.asked.seed):
if len(tasks) == bench.asked.bugs:
break
task = planted(len(tasks) + 1, mutant, checkout, sides, trees, containers, folder, git)
task = planted(bench, len(tasks) + 1, mutant)
if isinstance(task, Failure):
return task
tasks += [task] if task else []
if not tasks:
return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.")
return tasks
def ran_fixes(bench: Bench, tasks: list[Task], total: int) -> Fixes:
"""Each task's fix at each side, as many times as asked for, the sides in turn, until a run stops the bench."""
results: list[Result] = []
stopped = None
total = int(given["--runs"]) * len(tasks) * len(SIDES)
for number, task, side in itertools.product(range(1, int(given["--runs"]) + 1), tasks, SIDES):
result = fixed(task, side, number, containers, folder)
for number, task, side in itertools.product(range(1, bench.asked.runs + 1), tasks, SIDES):
result = fixed(task, side, number, bench.containers, bench.folder)
if isinstance(result, Failure):
stopped = result
break
return Fixes(results, result)
results.append(result)
print(f"task-bench: run {len(results)} of {total}, bug {task.number} at the {side}: {'passed' if result.passed else 'not passed'}.", file=sys.stderr)
if stopped and not results:
return stopped
return Fixes(results, None)
def kept(bench: Bench, tasks: list[Task], results: list[Result]) -> None:
"""Writes results.json and the digest into the bench's folder."""
names = {task.number: task.named() for task in tasks}
(folder / "results.json").write_text(json.dumps({"sides": sides, "seed": int(given["--seed"]), "bugs": names, "runs": [recorded(result) for result in results]}, indent="\t") + "\n", encoding="utf-8")
in_a_tree = lambda path: any(pathlib.Path(tree, path).is_file() for tree in trees.values())
(folder / DIGEST).write_text(digest(sides, table(results, names), [digested(task, results, folder) for task in tasks], in_a_tree), encoding="utf-8", errors="replace")
if stopped:
# The runs that finished took hours and tokens, so the bench shows them before it fails.
return Failure("\n".join([stopped.reason, f"task-bench stopped after {len(results)} of {total} runs, which results.json holds in {folder}:", "", *table(results, names)]))
(bench.folder / "results.json").write_text(json.dumps({"sides": bench.sides, "seed": bench.asked.seed, "bugs": names, "runs": [recorded(result) for result in results]}, indent="\t") + "\n", encoding="utf-8")
in_a_tree = lambda path: any(pathlib.Path(tree, path).is_file() for tree in bench.trees.values())
(bench.folder / DIGEST).write_text(digest(bench.sides, table(results, names), [digested(task, results, bench.folder) for task in tasks], in_a_tree), encoding="utf-8", errors="replace")
def report(sides: dict[str, str], names: dict[int, str], asked: Asked, results: list[Result]) -> list[str]:
"""What a finished bench prints: the commits, the bugs named in names, what ran them, and the table."""
ran_on = sorted({f"{found.model} in Claude Code {found.version}" for result in results if (found := result.figures)})
short = [] if len(tasks) == int(given["--bugs"]) else [f"Planted {len(tasks)} of the {given['--bugs']} bugs asked for: no other mutant the tests kill becomes one."]
short = [] if len(names) == asked.bugs else [f"Planted {len(names)} of the {asked.bugs} bugs asked for: no other mutant the tests kill becomes one."]
return [
f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}. {counted(len(tasks), 'bug')}, each run {counted(int(given['--runs']), 'time')} at each side by {' and '.join(ran_on) or 'no run that finished'}.",
f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}. {counted(len(names), 'bug')}, each run {counted(asked.runs, 'time')} at each side by {' and '.join(ran_on) or 'no run that finished'}.",
*short,
"",
*table(results, names),
@@ -285,39 +341,51 @@ def benched(given: dict[str, str], checkout: str, sides: dict[str, str], trees:
]
def planted(number: int, mutant: Mutant, checkout: str, sides: dict[str, str], trees: dict[str, str], containers: Containers, folder: pathlib.Path, git: Git) -> Task | Failure | None:
"""The task of fixing mutant, with its planted tree at each side; None where the mutant doesn't become a bug at one side or the other.
def stopped_report(stopped: Failure, results: list[Result], total: int, names: dict[int, str], folder: pathlib.Path) -> Failure:
"""Why the bench stopped, then the table of the runs that finished: they took hours and tokens, so the bench shows them
before it fails."""
return Failure("\n".join([stopped.reason, f"task-bench stopped after {len(results)} of {total} runs, which results.json holds in {folder}:", "", *table(results, names)]))
The bug is the same change to the same line at both sides, so only the code around it differs between them."""
diff = git("diff", "-U0", "--no-color", "--no-ext-diff", "--no-textconv", sides["base"], sides["head"], "--", mutant.path, cwd=checkout, errors="replace")
def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None:
"""The task of fixing mutant, with its planted tree at each side; None where the mutant doesn't become a bug at one side or the other."""
diff = bench.git("diff", "-U0", "--no-color", "--no-ext-diff", "--no-textconv", bench.sides["base"], bench.sides["head"], "--", mutant.path, cwd=bench.checkout, errors="replace")
if isinstance(diff, Failure):
return diff
at_head = line_at_head(diff, mutant.line)
if at_head is None:
sources = {side: source.read_bytes() if (source := pathlib.Path(tree, mutant.path)).is_file() else None for side, tree in bench.trees.items()}
bugs = bug_at_sides(mutant, diff, sources)
if bugs is None:
return None
planted_trees, messages = {}, {}
for side, placed in (("base", mutant), ("head", mutant._replace(line=at_head))):
source = pathlib.Path(trees[side], mutant.path)
changed = mutated(source.read_bytes(), placed) if source.is_file() else None
if changed is None:
return None
tree = folder / "bugs" / str(number) / side
shutil.rmtree(tree, ignore_errors=True)
shutil.copytree(trees[side], tree, symlinks=True)
(tree / mutant.path).write_bytes(changed)
ran = tests_in_copy(containers, str(tree), folder)
if isinstance(ran, Failure) and not isinstance(ran, TimedOut):
return ran
# Tests that never end under the bug have no message to tell Haiku.
message = None if isinstance(ran, TimedOut) else task_text(ran.output)
if message is None:
return None
for args in (["init", "--quiet"], ["add", "--all", "--force"], COMMIT):
done = git(*args, cwd=str(tree))
if isinstance(done, Failure):
return done
planted_trees[side], messages[side] = str(tree), message
return Task(number, mutant, planted_trees, messages)
trees, messages = {}, {}
for side, changed in bugs.items():
tree = bench.folder / "bugs" / str(number) / side
message = planted_tree(bench, side, tree, mutant.path, changed)
if message is None or isinstance(message, Failure):
return message
trees[side], messages[side] = str(tree), message
return Task(number, mutant, trees, messages)
def planted_tree(bench: Bench, side: str, tree: pathlib.Path, path: str, changed: bytes) -> str | Failure | None:
"""Makes tree a copy of the side's with the file at path holding changed, committed once, and returns what the failing test
prints there; None where it prints no message to tell Haiku."""
shutil.rmtree(tree, ignore_errors=True)
shutil.copytree(bench.trees[side], tree, symlinks=True)
(tree / path).write_bytes(changed)
ran = tests_in_copy(bench.containers, str(tree), bench.folder)
# Tests that never end under the bug have no message.
if isinstance(ran, TimedOut):
return None
if isinstance(ran, Failure):
return ran
message = task_text(ran.output)
if message is None:
return None
for args in (["init", "--quiet"], ["add", "--all", "--force"], COMMIT):
done = bench.git(*args, cwd=str(tree))
if isinstance(done, Failure):
return done
return message
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ran | Failure:
@@ -341,14 +409,16 @@ def fixed(task: Task, side: str, number: int, containers: Containers, folder: pa
attempted = fix_attempted(containers, str(copy), task.messages[side], stream)
if isinstance(attempted, Failure):
return attempted
found = figures(stream.read_bytes(), os.path.join(WORK, task.mutant.path))
raw = stream.read_bytes()
entries = entries_of(raw)
found = figures(raw, entries, os.path.join(WORK, task.mutant.path))
if isinstance(found, Failure):
return found
checked_tree(task.trees[side], str(copy), str(check))
ran = ran_tests(containers, str(check))
if isinstance(ran, Failure) and not isinstance(ran, TimedOut):
return ran
return Result(task.number, side, number, isinstance(ran, Ran) and ran.code == 0, found)
return Result(task.number, side, number, isinstance(ran, Ran) and ran.code == 0, found, tuple(entries))
finally:
shutil.rmtree(copy, ignore_errors=True)
shutil.rmtree(check, ignore_errors=True)
@@ -361,7 +431,7 @@ def stream_of(result: Result, folder: pathlib.Path) -> pathlib.Path:
def digested(task: Task, results: list[Result], folder: pathlib.Path) -> Bug:
"""The bug as the digest tells it, with each of its runs in results. A run that didn't finish has no tokens."""
runs = [Run(stream_of(result, folder).stem, result.passed, found.tokens.context() + found.tokens.output if (found := result.figures) else None, stream_of(result, folder).read_bytes()) for result in results if result.task == task.number]
runs = [Run(stream_of(result, folder).stem, result.passed, found.tokens.context() + found.tokens.output if (found := result.figures) else None, result.entries) for result in results if result.task == task.number]
return Bug(f"{task.number}: {task.named()}", task.mutant.path, task.messages["base"], runs)
@@ -371,7 +441,3 @@ def recorded(result: Result) -> dict:
if not (found := result.figures):
return run
return {**run, "claude_code": found.version, "model": found.model, "tokens": dataclasses.asdict(found.tokens), "turns": found.turns, "seconds": found.seconds, "reads": found.reads}
def counted(count: int, noun: str) -> str:
return f"{count} {noun}{'' if count == 1 else 's'}"