Answer stability round 1: 0 🔴, 5 🟡 (1 misread); keep locks out of compress-archives, count only a search's hits, show an unfinished failing run, and test the walk and the home

This commit is contained in:
2026-11-21 12:18:32 +01:00
parent 27e5014322
commit 101c8a7c3d
12 changed files with 118 additions and 71 deletions
+30 -20
View File
@@ -9,27 +9,29 @@ from claude_code.entries import AssistantTurn, parse_entry, Text, tool_calls, To
from task_bench.figures import HOME, WORK
from reading_cost.measure import reads_of
# How much of the model's text between two calls a trace keeps, and of each line, of a search's pattern or of a shell command.
# A trace keeps the first TEXT_LINES lines of the model's text between two calls, and the first TEXT_WIDTH characters of each.
TEXT_LINES = 3
TEXT_WIDTH = 200
# The characters a trace keeps of a search's pattern and of a shell command's first line.
COMMAND_WIDTH = 120
CUT = " …"
# What Claude Code's Grep and Glob print where nothing matched: "No matches found", "No files found".
NO_HITS = re.compile(r"No \w+ found")
# The lines Claude Code's Grep and Glob print around the hits: "Found 3 files", "No matches found", "No files found",
# "No entries at this offset. …", "[Showing results with pagination = limit: 3]" and "(Showing 100 of 240 matching files; …)".
AROUND_HITS = re.compile(r"Found \d+ .*|No \w+ found.*|No entries at this offset.*|\[Showing .*|\(Showing .*")
class Run(typing.NamedTuple):
"""One run of a bug: the name of its stream's file without the suffix, whether its fix passed, the tokens it spent, none where
"""One run of a bug: the name of its stream's file without the suffix, whether its fix passed, the tokens it spent, None where
it didn't finish, and its stream."""
id: str
passed: bool
tokens: int
tokens: int | None
stream: bytes
class Bug(typing.NamedTuple):
"""A bug as the digest tells it: its number and name, the file the fix changes, what the failing test printed at the base, and
"""A bug as the digest tells it: its number and name, the file the bug is in, what the failing test printed at the base, and
its runs at both sides in the order they ran."""
named: str
@@ -38,9 +40,11 @@ class Bug(typing.NamedTuple):
runs: list[Run]
def digest(table: list[str], bugs: list[Bug], is_file: typing.Callable[[str], bool]) -> str:
"""The digest of a bench: the table of its figures, then each bug. is_file says whether a path in the project names a file."""
return "\n".join(["# task-bench digest", "", *table, *(line for bug in bugs for line in ["", *told(bug, is_file)])]) + "\n"
def digest(sides: dict[str, str], table: list[str], bugs: list[Bug], is_file: typing.Callable[[str], bool]) -> str:
"""The digest of a bench of the commits sides names: where each side's code is, the table of its figures, then each bug.
is_file says whether a path in the project names a file."""
code = f"Base {sides['base']}, head {sides['head']}. A bug's name gives its line at the base. Each side's code without the bugs is in `trees/base` and `trees/head` in the bench's folder."
return "\n".join(["# task-bench digest", "", code, "", *table, *(line for bug in bugs for line in ["", *told(bug, is_file)])]) + "\n"
def told(bug: Bug, is_file: typing.Callable[[str], bool]) -> list[str]:
@@ -50,15 +54,20 @@ def told(bug: Bug, is_file: typing.Callable[[str], bool]) -> list[str]:
if not failing:
found = "No run failed, so the bug has no decoys."
elif not misled:
found = f"No decoys: no file but the one the fix changes was read by more than half the {counted(len(failing), 'failing run')}."
found = f"No decoys: no file but the one the bug is in was read by more than half the {counted(len(failing), 'failing run')}."
else:
found = "Decoys, the files more than half the failing runs read that the fix doesn't change:"
found = "Decoys, the files more than half the failing runs read that the bug isn't in:"
shown: list[tuple[Run, str]] = []
if failing:
shown.append((max(failing, key=lambda run: run.tokens), "the failing run that spent the most tokens"))
if passing:
# A run that didn't finish has no count of its tokens, and searched the longest.
if unfinished := [run for run in failing if run.tokens is None]:
shown.append((unfinished[0], "a failing run that didn't finish"))
elif failing:
most = max(failing, key=lambda run: run.tokens or 0)
shown.append((most, f"the failing run that spent the most tokens, {most.tokens} tokens"))
if finished := sorted((run for run in passing if run.tokens is not None), key=lambda run: run.tokens or 0):
# Of an even count, the lower of the two in the middle, so the trace is a run's own.
shown.append((sorted(passing, key=lambda run: run.tokens)[(len(passing) - 1) // 2], "the passing run with the median tokens"))
median = finished[(len(finished) - 1) // 2]
shown.append((median, f"the passing run with the median tokens, {median.tokens} tokens"))
return [
f"## Bug {bug.named}",
"",
@@ -68,15 +77,16 @@ def told(bug: Bug, is_file: typing.Callable[[str], bool]) -> list[str]:
"",
f"{passed} {found}",
*(["", *(f"- {decoy}" for decoy in misled)] if misled else []),
*(line for run, why in shown for line in ["", f"### {run.id}, {why}, {run.tokens}", "", *trace(run.stream)]),
*(line for run, why in shown for line in ["", f"### {run.id}, {why}", "", *trace(run.stream)]),
]
def decoys(failing: list[bytes], fixed: str, is_file: typing.Callable[[str], bool]) -> list[str]:
"""The files of the project that more than half of the failing runs' streams read, but for fixed, the file the fix changes:
"""The files of the project that more than half of the failing runs' streams read, but for fixed, the file the bug is in:
each with how many runs read it, sorted by name."""
read_by = collections.Counter(path for stream in failing for path in files_read(stream))
return [f"`{path}`, read by {count} of the {counted(len(failing), 'failing run')}" for path, count in sorted(read_by.items()) if count * 2 > len(failing) and path != fixed and is_file(path)]
by = lambda count: "the one failing run" if len(failing) == 1 else f"{count} of the {len(failing)} failing runs"
return [f"`{path}`, read by {by(count)}" for path, count in sorted(read_by.items()) if count * 2 > len(failing) and path != fixed and is_file(path)]
def files_read(stream: bytes) -> set[str]:
@@ -129,8 +139,8 @@ def lines_asked(given: dict) -> str:
def hits(found: str) -> int:
"""The lines a search printed, which name a file or a match each."""
return 0 if NO_HITS.fullmatch(found.strip()) else sum(1 for line in found.splitlines() if line.strip())
"""The lines a search printed that name a file or a match each, without those Claude Code adds around them."""
return sum(1 for line in found.splitlines() if line.strip() and not AROUND_HITS.fullmatch(line.strip()))
def in_project(path: object) -> str: