Start every feature from one committed tree per side, and name the kind of task in each table and digest
CI / tests (pull_request) Successful in 3m44s

This commit is contained in:
2026-11-23 17:08:09 +01:00
parent b053a54989
commit b355a2025c
6 changed files with 43 additions and 39 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ class TaskRuns(typing.NamedTuple):
runs: list[Run] runs: list[Run]
def digest(sides: dict[Side, str], table: list[str], tasks: list[TaskRuns], is_file: typing.Callable[[str], bool], noun: str = "bug") -> str: def digest(sides: dict[Side, str], table: list[str], tasks: list[TaskRuns], is_file: typing.Callable[[str], bool], noun: str) -> str:
"""The digest of a bench of the commits sides names: where each side's code is, the table of its figures, then each task, """The digest of a bench of the commits sides names: where each side's code is, the table of its figures, then each task,
which the digest calls by noun. is_file says whether a path in the project names a file.""" which the digest calls by noun. is_file says whether a path in the project names a file."""
line = " A bug's name gives its line at the base." if noun == "bug" else "" line = " A bug's name gives its line at the base." if noun == "bug" else ""
+25 -25
View File
@@ -1,6 +1,7 @@
"""The features task-bench has Haiku build: each a folder in the project's `bench-tasks` folder, with a spec, a reference patch """The features task-bench has Haiku build: each a folder in the project's `bench-tasks` folder, with a spec, a reference patch
that builds it, and acceptance tests Haiku never sees. A feature counts at the two commits of a bench only where those tests fail that builds it, and acceptance tests Haiku never sees. A feature counts at the two commits of a bench only where those tests fail
at both before it is built, and pass at both with the reference patch.""" at both before it is built, and pass at both with the reference patch."""
import itertools
import pathlib import pathlib
import shutil import shutil
import typing import typing
@@ -86,62 +87,61 @@ def feature_in(folder: pathlib.Path) -> Feature | Failure:
def feature_tasks(bench: Bench, found: list[Feature], folder: pathlib.Path) -> Planned | Failure: def feature_tasks(bench: Bench, found: list[Feature], folder: pathlib.Path) -> Planned | Failure:
"""The task of building each feature of found that counts at the bench's commits, numbered from 1, and a line on each that """The task of building each feature of found that counts at the bench's commits, numbered from 1, and a line on each that
doesn't. A Failure where none counts. folder is where the features are kept.""" doesn't. A Failure where none counts. folder is where the features are kept."""
trees = committed_trees(bench)
if isinstance(trees, Failure):
return trees
tasks: list[Task] = [] tasks: list[Task] = []
passed_over: list[tuple[str, str]] = [] passed_over: list[tuple[str, str]] = []
for feature in found: for feature in found:
task = feature_task(bench, len(tasks) + 1, feature) why = why_passed_over(bench, trees, feature)
if isinstance(task, Failure): if isinstance(why, Failure):
return task return why
if isinstance(task, Task): if why is None:
tasks.append(task) tasks.append(Task(len(tasks) + 1, feature.name, trees, dict.fromkeys(SIDES, feature.spec), acceptance=feature.acceptance))
else: else:
passed_over.append((feature.name, task)) passed_over.append((feature.name, why))
bench.say(f"task-bench: passed over the feature {feature.name}: {task}.") bench.say(f"task-bench: passed over the feature {feature.name}: {why}.")
if not tasks: if not tasks:
return Failure(f"None of the {len(found)} features in {folder} counts. {' '.join(f'{name}: {why}.' for name, why in passed_over)}") return Failure(f"None of the {len(found)} features in {folder} counts. {' '.join(f'{name}: {why}.' for name, why in passed_over)}")
return Planned(tasks, [f"Passed over the feature {name}: {why}." for name, why in passed_over]) return Planned(tasks, [f"Passed over the feature {name}: {why}." for name, why in passed_over])
def feature_task(bench: Bench, number: int, feature: Feature) -> Task | str | Failure: def committed_trees(bench: Bench) -> dict[Side, str] | Failure:
"""The task of building feature, each side's tree committed once; or why the feature doesn't count.""" """A copy of each side's tree, committed once. Every feature starts from it, since a feature adds nothing to the tree Haiku
works in."""
trees: dict[Side, str] = {} trees: dict[Side, str] = {}
for side in SIDES: for side in SIDES:
tree = bench.folder / "features" / str(number) / side tree = bench.folder / "features" / side
# A feature passed over before this one left its trees under the same number.
shutil.rmtree(tree, ignore_errors=True)
copied = on_disk(f"copy the {side}'s tree to {tree}", lambda: shutil.copytree(bench.trees[side], tree, symlinks=True)) copied = on_disk(f"copy the {side}'s tree to {tree}", lambda: shutil.copytree(bench.trees[side], tree, symlinks=True))
if isinstance(copied, Failure): if isinstance(copied, Failure):
return copied return copied
if failure := committed(bench.git, str(tree)): if failure := committed(bench.git, str(tree)):
return failure return failure
passed_over = why_passed_over(bench, str(tree), side, feature)
if passed_over is not None:
return passed_over
trees[side] = str(tree) trees[side] = str(tree)
return Task(number, feature.name, trees, dict.fromkeys(SIDES, feature.spec), acceptance=feature.acceptance) return trees
def why_passed_over(bench: Bench, tree: str, side: Side, feature: Feature) -> str | Failure | None: def why_passed_over(bench: Bench, trees: dict[Side, str], feature: Feature) -> str | Failure | None:
"""Why feature doesn't count at side, whose committed tree is tree; None where it counts. A Failure where the tests could """Why feature doesn't count at the first side where it doesn't, in the committed trees; None where it counts at both. A
not run.""" Failure where the tests could not run."""
def put(copy: str) -> Failure | None: def put(copy: str) -> Failure | None:
return on_disk(f"put {feature.name}'s acceptance tests into {copy}", lambda: with_acceptance(copy, feature.acceptance)) return on_disk(f"put {feature.name}'s acceptance tests into {copy}", lambda: with_acceptance(copy, feature.acceptance))
def built(copy: str) -> Failure | None: def built(copy: str) -> Failure | None:
# git has run in this bench already, so a failure here is the patch's. # git has run in this bench already, so a failure here is the patch's.
applied = bench.git("apply", "--whitespace=nowarn", feature.patch, cwd=copy) applied = bench.git("apply", feature.patch, cwd=copy)
return NotApplied(applied.reason) if isinstance(applied, Failure) else put(copy) return NotApplied(applied.reason) if isinstance(applied, Failure) else put(copy)
for prepare, reference in ((put, ""), (built, " with the reference patch")): for side, (prepare, is_built) in itertools.product(SIDES, ((put, False), (built, True))):
ran = tests_in_copy(bench.containers, tree, bench.folder, prepare) ran = tests_in_copy(bench.containers, trees[side], bench.folder, prepare)
if isinstance(ran, NotApplied): if isinstance(ran, NotApplied):
return f"its reference patch doesn't apply at the {side}" return f"its reference patch doesn't apply at the {side}"
if isinstance(ran, TimedOut): if isinstance(ran, TimedOut):
return f"its acceptance tests don't end{reference} at the {side}" return f"its acceptance tests don't end at the {side}"
if isinstance(ran, Failure): if isinstance(ran, Failure):
return ran return ran
if not reference and ran.code == 0: if not is_built and ran.code == 0:
return f"its acceptance tests pass at the {side} before it is built" return f"its acceptance tests pass at the {side} before it is built"
if reference and ran.code: if is_built and ran.code:
return f"its acceptance tests fail with the reference patch at the {side}" return f"its acceptance tests fail with the reference patch at the {side}"
return None return None
+1 -1
View File
@@ -91,7 +91,7 @@ def reads_before(calls: list[ToolCall], bug_file: str | None) -> int | None:
return None return None
def table(results: list[Result], tasks: dict[int, str], noun: str = "bug") -> list[str]: def table(results: list[Result], tasks: dict[int, str], noun: str) -> list[str]:
"""A row per task and side, under a heading that calls a task by noun, then one per side over every task, then the head's change against the base, as `change` says. Each """A row per task and side, under a heading that calls a task by noun, then one per side over every task, then the head's change against the base, as `change` says. Each
figure is the median over the side's runs that have figures, and Reads over those that opened the bug's file.""" figure is the median over the side's runs that have figures, and Reads over those that opened the bug's file."""
sides = {(task, side): [result for result in results if (result.task, result.side) == (task, side)] for task in tasks for side in SIDES} sides = {(task, side): [result for result in results if (result.task, result.side) == (task, side)] for task in tasks for side in SIDES}
+5 -5
View File
@@ -109,7 +109,7 @@ class DigestTest(unittest.TestCase):
] ]
def test_holds_the_figures_and_per_bug_its_decoys_and_two_traces_picked_by_rule(self): def test_holds_the_figures_and_per_bug_its_decoys_and_two_traces_picked_by_rule(self):
held = digest(SIDES, ["| Bug | Side |", "|---|---|"], [TaskRuns("1: calc.go:4:11 ARITHMETIC_BASE", "calc.go", "Add(1, 2) = -1, want 3", self.runs())], lambda path: True) held = digest(SIDES, ["| Bug | Side |", "|---|---|"], [TaskRuns("1: calc.go:4:11 ARITHMETIC_BASE", "calc.go", "Add(1, 2) = -1, want 3", self.runs())], lambda path: True, "bug")
self.assertEqual(held.splitlines(), [ self.assertEqual(held.splitlines(), [
"# task-bench digest", "# task-bench digest",
"", "",
@@ -140,22 +140,22 @@ class DigestTest(unittest.TestCase):
]) ])
def test_a_bug_every_run_fixed_has_no_decoys_and_one_trace(self): def test_a_bug_every_run_fixed_has_no_decoys_and_one_trace(self):
held = digest(SIDES, [], [TaskRuns("2: a.go:1:1 X", "a.go", "boom", [Run("bug-2-base-1", True, 10, reading("a.go"))])], lambda path: True) held = digest(SIDES, [], [TaskRuns("2: a.go:1:1 X", "a.go", "boom", [Run("bug-2-base-1", True, 10, reading("a.go"))])], lambda path: True, "bug")
self.assertIn("The 1 run passed. No run failed, so the bug has no decoys.", held.splitlines()) self.assertIn("The 1 run passed. No run failed, so the bug has no decoys.", held.splitlines())
self.assertNotIn("failing run that", held) self.assertNotIn("failing run that", held)
self.assertIn("### bug-2-base-1, the passing run with the median tokens, 10 tokens", held.splitlines()) self.assertIn("### bug-2-base-1, the passing run with the median tokens, 10 tokens", held.splitlines())
def test_the_median_is_by_tokens_whatever_the_order_the_runs_ran_in(self): def test_the_median_is_by_tokens_whatever_the_order_the_runs_ran_in(self):
runs = [Run("bug-2-base-1", True, 20, []), Run("bug-2-head-1", True, 10, []), Run("bug-2-base-2", True, 30, [])] runs = [Run("bug-2-base-1", True, 20, []), Run("bug-2-head-1", True, 10, []), Run("bug-2-base-2", True, 30, [])]
self.assertEqual(digest(SIDES, [], [TaskRuns("2: a.go:1:1 X", "a.go", "boom", runs)], lambda path: True).splitlines()[-2:], ["### bug-2-base-1, the passing run with the median tokens, 20 tokens", ""]) self.assertEqual(digest(SIDES, [], [TaskRuns("2: a.go:1:1 X", "a.go", "boom", runs)], lambda path: True, "bug").splitlines()[-2:], ["### bug-2-base-1, the passing run with the median tokens, 20 tokens", ""])
def test_a_run_that_did_not_finish_is_the_failing_trace_and_is_left_out_of_the_median(self): def test_a_run_that_did_not_finish_is_the_failing_trace_and_is_left_out_of_the_median(self):
runs = [Run("bug-4-base-1", False, 900, []), Run("bug-4-head-1", False, None, []), Run("bug-4-base-2", True, None, []), Run("bug-4-head-2", True, 60, [])] runs = [Run("bug-4-base-1", False, 900, []), Run("bug-4-head-1", False, None, []), Run("bug-4-base-2", True, None, []), Run("bug-4-head-2", True, 60, [])]
held = digest(SIDES, [], [TaskRuns("4: a.go:1:1 X", "a.go", "boom", runs)], lambda path: True).splitlines() held = digest(SIDES, [], [TaskRuns("4: a.go:1:1 X", "a.go", "boom", runs)], lambda path: True, "bug").splitlines()
self.assertEqual([line for line in held if line.startswith("###")], ["### bug-4-head-1, a failing run that didn't finish", "### bug-4-head-2, the passing run with the median tokens, 60 tokens"]) self.assertEqual([line for line in held if line.startswith("###")], ["### bug-4-head-1, a failing run that didn't finish", "### bug-4-head-2, the passing run with the median tokens, 60 tokens"])
def test_a_bug_no_run_fixed_shows_the_failing_trace_alone_and_says_where_no_file_misled(self): def test_a_bug_no_run_fixed_shows_the_failing_trace_alone_and_says_where_no_file_misled(self):
held = digest(SIDES, [], [TaskRuns("3: a.go:1:1 X", "a.go", "boom\nat line 2", [Run("bug-3-base-1", False, 10, reading("a.go")), Run("bug-3-head-1", False, 10, reading("a.go"))])], lambda path: True) held = digest(SIDES, [], [TaskRuns("3: a.go:1:1 X", "a.go", "boom\nat line 2", [Run("bug-3-base-1", False, 10, reading("a.go")), Run("bug-3-head-1", False, 10, reading("a.go"))])], lambda path: True, "bug")
self.assertEqual(held.splitlines()[12:16], ["0 of the 2 runs passed. No decoys: no file but the one the bug is in was read by more than half the 2 failing runs.", "", "### bug-3-base-1, the failing run that spent the most tokens, 10 tokens", ""]) self.assertEqual(held.splitlines()[12:16], ["0 of the 2 runs passed. No decoys: no file but the one the bug is in was read by more than half the 2 failing runs.", "", "### bug-3-base-1, the failing run that spent the most tokens, 10 tokens", ""])
self.assertIn(" at line 2", held.splitlines()) self.assertIn(" at line 2", held.splitlines())
# Of two failing runs that spent the same, the first. # Of two failing runs that spent the same, the first.
+5 -1
View File
@@ -184,7 +184,8 @@ class FeatureBenchTest(unittest.TestCase):
def test_fails_where_no_feature_counts_saying_why_each_does_not(self): def test_fails_where_no_feature_counts_saying_why_each_does_not(self):
(self.tasks / "halve/acceptance/halve_test.go").write_text("echo 'never passes'\nexit 1\n") (self.tasks / "halve/acceptance/halve_test.go").write_text("echo 'never passes'\nexit 1\n")
self.assertEqual(self.bench().reason, f"None of the 1 features in {self.tasks} counts. halve: its acceptance tests fail with the reference patch at the base.") feature(self.tasks / "stale", acceptance="exit 0\n", test="stale_test.go")
self.assertEqual(self.bench().reason, f"None of the 2 features in {self.tasks} counts. halve: its acceptance tests fail with the reference patch at the base. stale: its acceptance tests pass at the base before it is built.")
self.assertNotIn(["claude"], [call[-2:-1] for call in map(json.loads, self.log.read_text().splitlines())]) self.assertNotIn(["claude"], [call[-2:-1] for call in map(json.loads, self.log.read_text().splitlines())])
def test_fails_before_any_container_starts_where_the_config_or_the_folder_is_at_fault(self): def test_fails_before_any_container_starts_where_the_config_or_the_folder_is_at_fault(self):
@@ -220,6 +221,9 @@ class OptionsTest(unittest.TestCase):
self.assertEqual(self.options("--tasks", "features")["--tasks"], "features") self.assertEqual(self.options("--tasks", "features")["--tasks"], "features")
self.assertEqual(self.options("--tasks=chores").reason, "--tasks takes bugs or features, not chores") self.assertEqual(self.options("--tasks=chores").reason, "--tasks takes bugs or features, not chores")
def test_features_run_5_times_at_each_side_by_default(self):
self.assertEqual(self.options("--tasks", "features")["--runs"], "5")
def test_the_options_that_choose_bugs_are_refused_with_features(self): def test_the_options_that_choose_bugs_are_refused_with_features(self):
for option in ("--seed", "--bugs", "--prefix"): for option in ("--seed", "--bugs", "--prefix"):
with self.subTest(option=option): with self.subTest(option=option):
+6 -6
View File
@@ -96,7 +96,7 @@ class TableTest(unittest.TestCase):
run(2, "base", 1, False, input_=200, turns=12, seconds=90, reads=4), run(2, "base", 1, False, input_=200, turns=12, seconds=90, reads=4),
run(2, "head", 1, True, input_=100, turns=9, seconds=45, reads=2), run(2, "head", 1, True, input_=100, turns=9, seconds=45, reads=2),
] ]
self.assertEqual(table(results, {1: "calc.go:4:7 CONDITIONALS_NEGATION", 2: "pick.go:9:3 ARITHMETIC_BASE"}), [ self.assertEqual(table(results, {1: "calc.go:4:7 CONDITIONALS_NEGATION", 2: "pick.go:9:3 ARITHMETIC_BASE"}, "bug"), [
"| Bug | Side | Passed | Input | Cache write | Cache read | Output | Turns | Wall, s | Reads |", "| Bug | Side | Passed | Input | Cache write | Cache read | Output | Turns | Wall, s | Reads |",
"|---|---|---|---|---|---|---|---|---|---|", "|---|---|---|---|---|---|---|---|---|---|",
"| 1: calc.go:4:7 CONDITIONALS_NEGATION | base | 2/3 | 200 | 1000 | 5000 | 400 | 12 | 90 | 4 |", "| 1: calc.go:4:7 CONDITIONALS_NEGATION | base | 2/3 | 200 | 1000 | 5000 | 400 | 12 | 90 | 4 |",
@@ -110,14 +110,14 @@ class TableTest(unittest.TestCase):
def test_the_change_is_a_dash_where_the_base_measured_zero_and_signed_where_it_rose(self): def test_the_change_is_a_dash_where_the_base_measured_zero_and_signed_where_it_rose(self):
results = [run(1, "base", 1, True, input_=0, turns=10, seconds=60, reads=0), run(1, "head", 1, False, input_=50, turns=12, seconds=120, reads=2)] results = [run(1, "base", 1, True, input_=0, turns=10, seconds=60, reads=0), run(1, "head", 1, False, input_=50, turns=12, seconds=120, reads=2)]
self.assertEqual(table(results, {1: "calc.go:4:7 ARITHMETIC_BASE"})[-1], "| All | change | -1 | - | 0 % | 0 % | 0 % | +2 | +100 % | +2 |") self.assertEqual(table(results, {1: "calc.go:4:7 ARITHMETIC_BASE"}, "bug")[-1], "| All | change | -1 | - | 0 % | 0 % | 0 % | +2 | +100 % | +2 |")
def test_the_change_is_the_mean_of_the_bugs_own_changes_not_the_change_of_the_pooled_medians(self): def test_the_change_is_the_mean_of_the_bugs_own_changes_not_the_change_of_the_pooled_medians(self):
results = [ results = [
run(1, "base", 1, True, input_=100, turns=10, seconds=60, reads=3), run(1, "head", 1, True, input_=200, turns=14, seconds=90, reads=5), run(1, "base", 1, True, input_=100, turns=10, seconds=60, reads=3), run(1, "head", 1, True, input_=200, turns=14, seconds=90, reads=5),
run(2, "base", 1, True, input_=1000, turns=20, seconds=60, reads=7), run(2, "head", 1, True, input_=1000, turns=20, seconds=60, reads=7), run(2, "base", 1, True, input_=1000, turns=20, seconds=60, reads=7), run(2, "head", 1, True, input_=1000, turns=20, seconds=60, reads=7),
] ]
rows = table(results, {1: "calc.go:4:7 ARITHMETIC_BASE", 2: "pick.go:9:3 ARITHMETIC_BASE"}) rows = table(results, {1: "calc.go:4:7 ARITHMETIC_BASE", 2: "pick.go:9:3 ARITHMETIC_BASE"}, "bug")
self.assertEqual(rows[-3:], [ self.assertEqual(rows[-3:], [
"| All | base | 2/2 | 550 | 1000 | 5000 | 400 | 15 | 60 | 5 |", "| All | base | 2/2 | 550 | 1000 | 5000 | 400 | 15 | 60 | 5 |",
"| All | head | 2/2 | 600 | 1000 | 5000 | 400 | 17 | 75 | 6 |", "| All | head | 2/2 | 600 | 1000 | 5000 | 400 | 17 | 75 | 6 |",
@@ -129,11 +129,11 @@ class TableTest(unittest.TestCase):
run(1, "base", 1, True, input_=0), run(1, "head", 1, True, input_=50), run(1, "base", 1, True, input_=0), run(1, "head", 1, True, input_=50),
run(2, "base", 1, True, input_=100), run(2, "head", 1, True, input_=150), run(2, "base", 1, True, input_=100), run(2, "head", 1, True, input_=150),
] ]
self.assertEqual(table(results, {1: "a.go:1:1 ARITHMETIC_BASE", 2: "b.go:1:1 ARITHMETIC_BASE"})[-1].split(" | ")[3], "+50 %") self.assertEqual(table(results, {1: "a.go:1:1 ARITHMETIC_BASE", 2: "b.go:1:1 ARITHMETIC_BASE"}, "bug")[-1].split(" | ")[3], "+50 %")
def test_a_run_without_figures_counts_as_not_passed_and_a_side_without_any_shows_a_dash(self): def test_a_run_without_figures_counts_as_not_passed_and_a_side_without_any_shows_a_dash(self):
results = [Result(1, "base", 1, False, None), run(1, "head", 1, True)] results = [Result(1, "base", 1, False, None), run(1, "head", 1, True)]
self.assertEqual(table(results, {1: "calc.go:4:7 ARITHMETIC_BASE"})[2:], [ self.assertEqual(table(results, {1: "calc.go:4:7 ARITHMETIC_BASE"}, "bug")[2:], [
"| 1: calc.go:4:7 ARITHMETIC_BASE | base | 0/1 | - | - | - | - | - | - | - |", "| 1: calc.go:4:7 ARITHMETIC_BASE | base | 0/1 | - | - | - | - | - | - | - |",
"| 1: calc.go:4:7 ARITHMETIC_BASE | head | 1/1 | 100 | 1000 | 5000 | 400 | 10 | 60 | 3 |", "| 1: calc.go:4:7 ARITHMETIC_BASE | head | 1/1 | 100 | 1000 | 5000 | 400 | 10 | 60 | 3 |",
"| All | base | 0/1 | - | - | - | - | - | - | - |", "| All | base | 0/1 | - | - | - | - | - | - | - |",
@@ -143,4 +143,4 @@ class TableTest(unittest.TestCase):
def test_the_change_is_a_dash_where_only_the_head_has_no_figures(self): def test_the_change_is_a_dash_where_only_the_head_has_no_figures(self):
results = [run(1, "base", 1, True), Result(1, "head", 1, False, None)] results = [run(1, "base", 1, True), Result(1, "head", 1, False, None)]
self.assertEqual(table(results, {1: "calc.go:4:7 ARITHMETIC_BASE"})[-1], "| All | change | -1 | - | - | - | - | - | - | - |") self.assertEqual(table(results, {1: "calc.go:4:7 ARITHMETIC_BASE"}, "bug")[-1], "| All | change | -1 | - | - | - | - | - | - | - |")